No Description

hlg150h.cxx 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <iostream>
  5. #include <string>
  6. #include "hlg150h.h"
  7. #define HLG150H_GPIO_RELAY 21
  8. #define HLG150H_GPIO_PWM 22
  9. void printState(upm::ILightController *lightController)
  10. {
  11. if (lightController->isPowered())
  12. {
  13. std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
  14. }
  15. else
  16. {
  17. std::cout << "Light is not powered." << std::endl;
  18. }
  19. }
  20. int main( int argc, char **argv )
  21. {
  22. int status = 0;
  23. upm::ILightController* lightController;
  24. try {
  25. lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
  26. std::cout << "Existing state: "; printState(lightController);
  27. if (argc == 2)
  28. {
  29. std::string arg = argv[1];
  30. int brightness = ::atoi(argv[1]);
  31. if (brightness > 0) {
  32. lightController->setPowerOn();
  33. lightController->setBrightness(brightness);
  34. } else
  35. lightController->setPowerOff();
  36. }
  37. std::cout << "Now: ";printState(lightController);
  38. delete lightController;
  39. } catch (std::exception& e) {
  40. std::cout << "Error: " << e.what() << std::endl;
  41. status = 1;
  42. }
  43. return status;
  44. }