2017-04-04 13:51:31 -07:00
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdlib.h>
|
2017-04-04 13:51:31 -07:00
|
|
|
#include <string>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2017-04-04 13:51:31 -07:00
|
|
|
#include "ds1808lc.hpp"
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
|
|
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
2017-04-04 13:51:31 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
2018-09-27 17:33:40 +03:00
|
|
|
printState(upm::DS1808LC& lightController)
|
2016-11-11 10:43:00 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (lightController.isPowered()) {
|
|
|
|
std::cout << "Light is powered, brightness = " << lightController.getBrightness()
|
|
|
|
<< std::endl;
|
|
|
|
} else {
|
2017-04-04 13:51:31 -07:00
|
|
|
std::cout << "Light is not powered." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 10:43:00 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2017-04-04 13:51:31 -07:00
|
|
|
{
|
|
|
|
//! [Interesting]
|
|
|
|
upm::DS1808LC lightController(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << "Existing state: ";
|
|
|
|
printState(lightController);
|
|
|
|
if (argc == 2) {
|
2017-04-04 13:51:31 -07:00
|
|
|
std::string arg = argv[1];
|
|
|
|
int brightness = ::atoi(argv[1]);
|
2017-08-30 15:00:29 -07:00
|
|
|
if (brightness > 0) {
|
2017-04-04 13:51:31 -07:00
|
|
|
lightController.setPowerOn();
|
|
|
|
lightController.setBrightness(brightness);
|
2017-08-30 15:00:29 -07:00
|
|
|
} else
|
2017-04-04 13:51:31 -07:00
|
|
|
lightController.setPowerOff();
|
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << "Now: ";
|
|
|
|
printState(lightController);
|
2017-04-04 13:51:31 -07:00
|
|
|
//! [Interesting]
|
|
|
|
return 0;
|
|
|
|
}
|