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:
Noel Eck 2017-04-04 13:51:31 -07:00
parent 52879b0b04
commit 96b219d2fb
9 changed files with 128 additions and 157 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -8,44 +8,36 @@
#define EDISON_I2C_BUS 1 // Edison I2C-1
#define DS1808_GPIO_PWR 15 // Edison GP165
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 = 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}