mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00

* 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>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <iostream>
|
|
#include <string>
|
|
#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 )
|
|
{
|
|
//! [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;
|
|
}
|