diff --git a/examples/c++/ads1x15-ads1015.cxx b/examples/c++/ads1x15-ads1015.cxx index c519e401..d151fab6 100644 --- a/examples/c++/ads1x15-ads1015.cxx +++ b/examples/c++/ads1x15-ads1015.cxx @@ -49,6 +49,7 @@ void stop() int main() { + //! [Interesting] long id = 0; // Sample number string fileName = "./ads1015.data"; // Output filename ofstream f; @@ -97,6 +98,7 @@ int main() return 1; } cout << "Wrote " << id << " samples to file: " << fileName << endl; + //! [Interesting] return 0; } diff --git a/examples/c++/ads1x15-ads1115.cxx b/examples/c++/ads1x15-ads1115.cxx index a2311e88..835137a8 100644 --- a/examples/c++/ads1x15-ads1115.cxx +++ b/examples/c++/ads1x15-ads1115.cxx @@ -48,6 +48,7 @@ void stop() int main() { + //! [Interesting] long id = 0; // Sample number string fileName = "./ads1115.data"; // Output filename ofstream f; @@ -100,6 +101,7 @@ int main() return 1; } cout << "Wrote " << id << " samples to file: " << fileName << endl; + //! [Interesting] return 0; } diff --git a/examples/c++/ads1x15.cxx b/examples/c++/ads1x15.cxx index c2100fb8..7ff2d0cb 100644 --- a/examples/c++/ads1x15.cxx +++ b/examples/c++/ads1x15.cxx @@ -37,6 +37,7 @@ int main() using namespace std; using namespace upm; int command; + //! [Interesting] //Select the device you are testing here and adjust case 6 for the correct sample rates. //upm::ADS1015 *ads = new upm::ADS1015(1); upm::ADS1115 *ads = new upm::ADS1115(1, 0x49); @@ -315,6 +316,7 @@ int main() }while (command != -1 ); delete ads; + //! [Interesting] return 0; } diff --git a/examples/c++/ds1808lc.cxx b/examples/c++/ds1808lc.cxx index cd403c47..944415d6 100644 --- a/examples/c++/ds1808lc.cxx +++ b/examples/c++/ds1808lc.cxx @@ -1,51 +1,43 @@ -#include -#include -#include -#include -#include -#include "ds1808lc.hpp" - -#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; - } -} - +#include +#include +#include +#include +#include +#include "ds1808lc.hpp" + +#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 = nullptr; - - 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; -} - - + //! [Interesting] + upm::DS1808LC lightController(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); + //! [Interesting] + return 0; +} diff --git a/examples/c++/hlg150h.cxx b/examples/c++/hlg150h.cxx index 43b123cb..d9b3bca4 100644 --- a/examples/c++/hlg150h.cxx +++ b/examples/c++/hlg150h.cxx @@ -8,44 +8,37 @@ #define HLG150H_GPIO_RELAY 21 #define HLG150H_GPIO_PWM 22 -void printState(upm::ILightController *lightController) +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; - } + 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; + //! [Interesting] + upm::HLG150H lightController(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); + //! [Interesting] - 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; + return 0; } - - diff --git a/examples/c++/lp8860.cxx b/examples/c++/lp8860.cxx index 0288986e..48257961 100644 --- a/examples/c++/lp8860.cxx +++ b/examples/c++/lp8860.cxx @@ -9,44 +9,37 @@ #define LP8860_GPIO_PWR 45 // Edison GP45 -void printState(upm::ILightController *lightController) +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; - } + 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; + //! [Interesting] + upm::LP8860 lightController(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); + //! [Interesting] - 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; + return 0; } - - diff --git a/examples/c++/max44009.cxx b/examples/c++/max44009.cxx index bf911cbb..95de4b7d 100644 --- a/examples/c++/max44009.cxx +++ b/examples/c++/max44009.cxx @@ -30,17 +30,13 @@ int main () { - try { - upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS); - while (true) { - float value = lightSensor->getVisibleLux(); - std::cout << "Light level = " << value << " lux" << std::endl; - sleep(1); - } - delete lightSensor; - } catch (std::exception& e) { - std::cerr << e.what() << std::endl; - return 1; - } - return 0; + //! [Interesting] + upm::MAX44009 lightSensor(EDISON_I2C_BUS); + while (true) { + float value = lightSensor.getVisibleLux(); + std::cout << "Light level = " << value << " lux" << std::endl; + sleep(1); + } + //! [Interesting] + return 0; } diff --git a/examples/c++/si1132.cxx b/examples/c++/si1132.cxx index 31d5bdec..ab4062c7 100644 --- a/examples/c++/si1132.cxx +++ b/examples/c++/si1132.cxx @@ -30,17 +30,13 @@ int main () { - try { - upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS)); - while (true) { - float value = lightSensor->getVisibleLux(); - std::cout << "Light level = " << value << " lux" << std::endl; - sleep(1); - } - delete lightSensor; - } catch (std::exception& e) { - std::cerr << e.what() << std::endl; - return 1; - } - return 0; + //! [Interesting] + upm::SI1132 lightSensor(mraa_get_sub_platform_id(FT4222_I2C_BUS)); + while (true) { + float value = lightSensor.getVisibleLux(); + std::cout << "Light level = " << value << " lux" << std::endl; + sleep(1); + } + //! [Interesting] + return 0; } diff --git a/examples/c++/t6713.cxx b/examples/c++/t6713.cxx index c07871ac..81b8512c 100644 --- a/examples/c++/t6713.cxx +++ b/examples/c++/t6713.cxx @@ -30,19 +30,14 @@ int main () { + //! [Interesting] + upm::T6713 cO2Sensor(mraa_get_sub_platform_id(FT4222_I2C_BUS)); - try { - upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS)); - while (true) { - uint16_t value = cO2Sensor->getPpm(); - std::cout << "CO2 level = " << value << " ppm" << std::endl; - sleep(1); - } - delete cO2Sensor; - } catch (std::exception& e) { - std::cerr << e.what() << std::endl; - return 1; - } - return 0; + while (true) { + uint16_t value = cO2Sensor.getPpm(); + std::cout << "CO2 level = " << value << " ppm" << std::endl; + sleep(1); + } + //! [Interesting] + return 0; } -