mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +03:00
examples: Added 'Interesting' tag to examples
* Added //! [Interesting] tag to all examples which were missing this * Removed windows CR/LF * Removed pointers from examples since these are not needed. Removed try/catch which seems to be there only to handle failing pointers and return value from main. * Reformatted examples when the formatting was wonky/inconstant. Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user