2016-01-22 15:41:11 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "lp8860.hpp"
|
2016-01-22 15:41:11 -08:00
|
|
|
|
|
|
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
|
|
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
|
|
|
|
|
|
|
|
2017-04-04 13:51:31 -07:00
|
|
|
void printState(upm::ILightController &lightController)
|
2016-01-22 15:41:11 -08:00
|
|
|
{
|
2017-04-04 13:51:31 -07:00
|
|
|
if (lightController.isPowered())
|
|
|
|
{
|
|
|
|
std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Light is not powered." << std::endl;
|
|
|
|
}
|
2016-01-22 15:41:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
2017-04-04 13:51:31 -07:00
|
|
|
//! [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]
|
|
|
|
|
|
|
|
return 0;
|
2016-01-22 15:41:11 -08:00
|
|
|
}
|