From dd3e88fa5928ffd96271691ac267eb94b0e92378 Mon Sep 17 00:00:00 2001 From: Henry Bruce Date: Fri, 22 Jan 2016 15:40:34 -0800 Subject: [PATCH] Example: hlg150h C++ example Signed-off-by: Henry Bruce Signed-off-by: Abhishek Malik --- examples/c++/CMakeLists.txt | 6 +++++ examples/c++/hlg150h.cxx | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 examples/c++/hlg150h.cxx diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 50cae99d..36e3b243 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -242,6 +242,12 @@ add_example (kxcjk1013) add_example (ssd1351) add_example (bme280) add_example (ds1808lc) +add_example (hlg150h) +#add_example (lp8860) +#add_example (max44009) +#add_example (si1132) +#add_example (si7005) +#add_example (t6713) # These are special cases where you specify example binary, source file and module(s) include_directories (${PROJECT_SOURCE_DIR}/src) diff --git a/examples/c++/hlg150h.cxx b/examples/c++/hlg150h.cxx new file mode 100644 index 00000000..1e281945 --- /dev/null +++ b/examples/c++/hlg150h.cxx @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include "hlg150h.h" + +#define HLG150H_GPIO_RELAY 21 +#define HLG150H_GPIO_PWM 22 + +void printState(upm::ILightController *lightController) +{ + if (lightController->isPowered()) + { + std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl; + } + else + { + std::cout << "Light is not powered." << std::endl; + } +} + +int main( int argc, char **argv ) +{ + int status = 0; + upm::ILightController* lightController; + + try { + lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM); + std::cout << "Existing state: "; printState(lightController); + if (argc == 2) + { + std::string arg = argv[1]; + int brightness = ::atoi(argv[1]); + if (brightness > 0) { + lightController->setPowerOn(); + lightController->setBrightness(brightness); + } else + lightController->setPowerOff(); + } + std::cout << "Now: ";printState(lightController); + delete lightController; + } catch (std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + status = 1; + } + + return status; +} + +