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() int main()
{ {
//! [Interesting]
long id = 0; // Sample number long id = 0; // Sample number
string fileName = "./ads1015.data"; // Output filename string fileName = "./ads1015.data"; // Output filename
ofstream f; ofstream f;
@ -97,6 +98,7 @@ int main()
return 1; return 1;
} }
cout << "Wrote " << id << " samples to file: " << fileName << endl; cout << "Wrote " << id << " samples to file: " << fileName << endl;
//! [Interesting]
return 0; return 0;
} }

View File

@ -48,6 +48,7 @@ void stop()
int main() int main()
{ {
//! [Interesting]
long id = 0; // Sample number long id = 0; // Sample number
string fileName = "./ads1115.data"; // Output filename string fileName = "./ads1115.data"; // Output filename
ofstream f; ofstream f;
@ -100,6 +101,7 @@ int main()
return 1; return 1;
} }
cout << "Wrote " << id << " samples to file: " << fileName << endl; cout << "Wrote " << id << " samples to file: " << fileName << endl;
//! [Interesting]
return 0; return 0;
} }

View File

@ -37,6 +37,7 @@ int main()
using namespace std; using namespace std;
using namespace upm; using namespace upm;
int command; int command;
//! [Interesting]
//Select the device you are testing here and adjust case 6 for the correct sample rates. //Select the device you are testing here and adjust case 6 for the correct sample rates.
//upm::ADS1015 *ads = new upm::ADS1015(1); //upm::ADS1015 *ads = new upm::ADS1015(1);
upm::ADS1115 *ads = new upm::ADS1115(1, 0x49); upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
@ -315,6 +316,7 @@ int main()
}while (command != -1 ); }while (command != -1 );
delete ads; delete ads;
//! [Interesting]
return 0; return 0;
} }

View File

@ -1,51 +1,43 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "ds1808lc.hpp" #include "ds1808lc.hpp"
#define EDISON_I2C_BUS 1 // Edison I2C-1 #define EDISON_I2C_BUS 1 // Edison I2C-1
#define DS1808_GPIO_PWR 15 // Edison GP165 #define DS1808_GPIO_PWR 15 // Edison GP165
void printState(upm::ILightController *lightController) void printState(upm::ILightController &lightController)
{ {
if (lightController->isPowered()) if (lightController.isPowered())
{ {
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl; std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
} }
else else
{ {
std::cout << "Light is not powered." << std::endl; std::cout << "Light is not powered." << std::endl;
} }
} }
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
int status = 0; //! [Interesting]
upm::ILightController* lightController = nullptr; upm::DS1808LC lightController(DS1808_GPIO_PWR, EDISON_I2C_BUS);
std::cout << "Existing state: "; printState(lightController);
try { if (argc == 2)
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS); {
std::cout << "Existing state: "; printState(lightController); std::string arg = argv[1];
if (argc == 2) int brightness = ::atoi(argv[1]);
{ if (brightness > 0)
std::string arg = argv[1]; {
int brightness = ::atoi(argv[1]); lightController.setPowerOn();
if (brightness > 0) { lightController.setBrightness(brightness);
lightController->setPowerOn(); }
lightController->setBrightness(brightness); else
} else lightController.setPowerOff();
lightController->setPowerOff(); }
} std::cout << "Now: ";printState(lightController);
std::cout << "Now: ";printState(lightController); //! [Interesting]
} catch (std::exception& e) { return 0;
std::cout << "Error: " << e.what() << std::endl; }
status = 1;
}
delete lightController;
return status;
}

View File

@ -8,44 +8,37 @@
#define HLG150H_GPIO_RELAY 21 #define HLG150H_GPIO_RELAY 21
#define HLG150H_GPIO_PWM 22 #define HLG150H_GPIO_PWM 22
void printState(upm::ILightController *lightController) void printState(upm::ILightController &lightController)
{ {
if (lightController->isPowered()) if (lightController.isPowered())
{ {
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl; std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
} }
else else
{ {
std::cout << "Light is not powered." << std::endl; std::cout << "Light is not powered." << std::endl;
} }
} }
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
int status = 0; //! [Interesting]
upm::ILightController* lightController; 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 { return 0;
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;
} }

View File

@ -9,44 +9,37 @@
#define LP8860_GPIO_PWR 45 // Edison GP45 #define LP8860_GPIO_PWR 45 // Edison GP45
void printState(upm::ILightController *lightController) void printState(upm::ILightController &lightController)
{ {
if (lightController->isPowered()) if (lightController.isPowered())
{ {
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl; std::cout << "Light is powered, brightness = " << lightController.getBrightness() << std::endl;
} }
else else
{ {
std::cout << "Light is not powered." << std::endl; std::cout << "Light is not powered." << std::endl;
} }
} }
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
int status = 0; //! [Interesting]
upm::LP8860* lightController; 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 { return 0;
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;
} }

View File

@ -30,17 +30,13 @@
int main () int main ()
{ {
try { //! [Interesting]
upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS); upm::MAX44009 lightSensor(EDISON_I2C_BUS);
while (true) { while (true) {
float value = lightSensor->getVisibleLux(); float value = lightSensor.getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl; std::cout << "Light level = " << value << " lux" << std::endl;
sleep(1); sleep(1);
} }
delete lightSensor; //! [Interesting]
} catch (std::exception& e) { return 0;
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
} }

View File

@ -30,17 +30,13 @@
int main () int main ()
{ {
try { //! [Interesting]
upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS)); upm::SI1132 lightSensor(mraa_get_sub_platform_id(FT4222_I2C_BUS));
while (true) { while (true) {
float value = lightSensor->getVisibleLux(); float value = lightSensor.getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl; std::cout << "Light level = " << value << " lux" << std::endl;
sleep(1); sleep(1);
} }
delete lightSensor; //! [Interesting]
} catch (std::exception& e) { return 0;
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
} }

View File

@ -30,19 +30,14 @@
int main () int main ()
{ {
//! [Interesting]
upm::T6713 cO2Sensor(mraa_get_sub_platform_id(FT4222_I2C_BUS));
try { while (true) {
upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS)); uint16_t value = cO2Sensor.getPpm();
while (true) { std::cout << "CO2 level = " << value << " ppm" << std::endl;
uint16_t value = cO2Sensor->getPpm(); sleep(1);
std::cout << "CO2 level = " << value << " ppm" << std::endl; }
sleep(1); //! [Interesting]
} return 0;
delete cO2Sensor;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
} }