mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
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:
parent
52879b0b04
commit
96b219d2fb
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,51 +1,43 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
#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 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user