From ee8433d92aa6e364366b036564143d3d6f751b73 Mon Sep 17 00:00:00 2001 From: Henry Bruce Date: Fri, 22 Jan 2016 15:41:11 -0800 Subject: [PATCH] Example: lp8860 C++ example Signed-off-by: Henry Bruce Signed-off-by: Abhishek Malik --- examples/c++/CMakeLists.txt | 2 +- examples/c++/lp8860.cxx | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 examples/c++/lp8860.cxx diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 36e3b243..d923dd95 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -243,7 +243,7 @@ add_example (ssd1351) add_example (bme280) add_example (ds1808lc) add_example (hlg150h) -#add_example (lp8860) +add_example (lp8860) #add_example (max44009) #add_example (si1132) #add_example (si7005) diff --git a/examples/c++/lp8860.cxx b/examples/c++/lp8860.cxx new file mode 100644 index 00000000..2a290eae --- /dev/null +++ b/examples/c++/lp8860.cxx @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include "lp8860.h" + +#define EDISON_I2C_BUS 1 // Edison I2C-1 +#define LP8860_GPIO_PWR 45 // Edison GP45 + + +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::LP8860* lightController; + + try { + lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS); + 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; +} + +