diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index db04f2fe..50cae99d 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -241,6 +241,7 @@ add_example (apds9930) add_example (kxcjk1013) add_example (ssd1351) add_example (bme280) +add_example (ds1808lc) # 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++/ds1808lc.cxx b/examples/c++/ds1808lc.cxx new file mode 100644 index 00000000..d2267ff8 --- /dev/null +++ b/examples/c++/ds1808lc.cxx @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include "ds1808lc.h" + +#define EDISON_I2C_BUS 1 // Edison I2C-1 +#define DS1808_GPIO_PWR 15 // Edison GP165 + +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::DS1808LC(DS1808_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); + } catch (std::exception& e) { + std::cout << "Error: " << e.what() << std::endl; + status = 1; + } + + delete lightController; + return status; +} + + diff --git a/src/hlg150h/hlg150h.cxx b/src/hlg150h/hlg150h.cxx index 3812393b..d3ed9e3a 100644 --- a/src/hlg150h/hlg150h.cxx +++ b/src/hlg150h/hlg150h.cxx @@ -15,8 +15,6 @@ HLG150H::HLG150H(int pinRelay, int pinPWM) this->pinRelay = pinRelay; isPoweredShadow = false; pwmBrightness = new mraa::Pwm(pinPWM); - if (pwmBrightness == NULL) - UPM_THROW("pwm init failed"); status = pwmBrightness->enable(true); status = pwmBrightness->period_us(PWM_PERIOD); if (status != mraa::SUCCESS)