mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
examples: Cleaned up C examples.
This commit cleans up multiple items with the UPM C example source. * Switch from usleep and sleep to upm_delay* methods * Include a mraa_init and check return value prior to using sensor * All example mains now return * Added include for mraa.h and upm_utilites.h to all examples * Reformatted/removed tabs * Updated author line for the examples I wrote Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
2ccdc3e673
commit
324af8fc92
@ -7,17 +7,26 @@
|
||||
#include <unistd.h>
|
||||
#include "a110x.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
a110x_context dev = a110x_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(a110x_magnet_detected(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
a110x_context dev = a110x_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(a110x_magnet_detected(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "bh1750.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,39 +39,45 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BH1750 sensor on default I2C bus (0), using the
|
||||
// default I2C address (0x23), and setting the mode to highest
|
||||
// resolution, lowest power mode.
|
||||
bh1750_context sensor = bh1750_init(BH1750_DEFAULT_I2C_BUS,
|
||||
BH1750_DEFAULT_I2C_ADDR,
|
||||
BH1750_OPMODE_H2_ONCE);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("bh1750_init() failed.\n");
|
||||
return 1;
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Every second, sample the BH1750 and output the measured lux value
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a BH1750 sensor on default I2C bus (0), using the
|
||||
// default I2C address (0x23), and setting the mode to highest
|
||||
// resolution, lowest power mode.
|
||||
bh1750_context sensor = bh1750_init(BH1750_DEFAULT_I2C_BUS,
|
||||
BH1750_DEFAULT_I2C_ADDR,
|
||||
BH1750_OPMODE_H2_ONCE);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
float lux;
|
||||
|
||||
bh1750_get_lux(sensor, &lux);
|
||||
printf("Detected Light Level (lux): %f\n", lux);
|
||||
sleep(1);
|
||||
printf("bh1750_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// Every second, sample the BH1750 and output the measured lux value
|
||||
|
||||
printf("Exiting\n");
|
||||
while (shouldRun)
|
||||
{
|
||||
float lux;
|
||||
|
||||
bh1750_close(sensor);
|
||||
bh1750_get_lux(sensor, &lux);
|
||||
printf("Detected Light Level (lux): %f\n", lux);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
bh1750_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,16 +7,25 @@
|
||||
#include <unistd.h>
|
||||
#include "collision.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
collision_context dev = collision_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(collision_is_colliding(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
collision_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
collision_context dev = collision_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(collision_is_colliding(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
collision_close(dev);
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrec.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,40 +39,46 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot EC sensor on analog pin A0, with a ds18b20
|
||||
// temperature sensor connected to UART 0, and a device index (for
|
||||
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
||||
// 5.0.
|
||||
dfrec_context sensor = dfrec_init(0, 0, 0, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("dfrec_init() failed.\n");
|
||||
return(1);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun)
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot EC sensor on analog pin A0, with a ds18b20
|
||||
// temperature sensor connected to UART 0, and a device index (for
|
||||
// the ds1820b uart bus) of 0, and an analog reference voltage of
|
||||
// 5.0.
|
||||
dfrec_context sensor = dfrec_init(0, 0, 0, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
dfrec_update(sensor);
|
||||
|
||||
printf("EC = %f ms/cm\n", dfrec_get_ec(sensor));
|
||||
printf("Volts = %f, Temperature = %f C\n",
|
||||
dfrec_get_volts(sensor), dfrec_get_temperature(sensor));
|
||||
printf("\n");
|
||||
|
||||
sleep(2);
|
||||
printf("dfrec_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun)
|
||||
{
|
||||
dfrec_update(sensor);
|
||||
|
||||
printf("Exiting...\n");
|
||||
printf("EC = %f ms/cm\n", dfrec_get_ec(sensor));
|
||||
printf("Volts = %f, Temperature = %f C\n",
|
||||
dfrec_get_volts(sensor), dfrec_get_temperature(sensor));
|
||||
printf("\n");
|
||||
|
||||
dfrec_close(sensor);
|
||||
upm_delay(2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
dfrec_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrorp.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,50 +39,56 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
||||
// reference voltage of 5.0.
|
||||
dfrorp_context sensor = dfrorp_init(0, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("dfrorp_init() failed.\n");
|
||||
return(1);
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// To calibrate:
|
||||
//
|
||||
// Disconnect the sensor probe (but leave the sensor interface board
|
||||
// connected). Then run one of the examples while holding down the
|
||||
// 'calibrate' button on the device. Read the ORP value reported
|
||||
// (it should be fairly small).
|
||||
//
|
||||
// This value is what you should supply to
|
||||
// dfrorp_set_orp_cal_offset(). Then reconnect the probe to the
|
||||
// interface board and you should be ready to go.
|
||||
//
|
||||
// DO NOT press the calibrate button on the interface board while
|
||||
// the probe is attached or you can permanently damage the probe.
|
||||
dfrorp_set_calibration_offset(sensor, 0.97);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// Every second, update and print values
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a DFRobot ORP sensor on analog pin A0 with an analog
|
||||
// reference voltage of 5.0.
|
||||
dfrorp_context sensor = dfrorp_init(0, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
dfrorp_update(sensor);
|
||||
|
||||
printf("ORP = %f mV\n", dfrorp_get_orp(sensor));
|
||||
|
||||
sleep(1);
|
||||
printf("dfrorp_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// To calibrate:
|
||||
//
|
||||
// Disconnect the sensor probe (but leave the sensor interface board
|
||||
// connected). Then run one of the examples while holding down the
|
||||
// 'calibrate' button on the device. Read the ORP value reported
|
||||
// (it should be fairly small).
|
||||
//
|
||||
// This value is what you should supply to
|
||||
// dfrorp_set_orp_cal_offset(). Then reconnect the probe to the
|
||||
// interface board and you should be ready to go.
|
||||
//
|
||||
// DO NOT press the calibrate button on the interface board while
|
||||
// the probe is attached or you can permanently damage the probe.
|
||||
dfrorp_set_calibration_offset(sensor, 0.97);
|
||||
|
||||
printf("Exiting...\n");
|
||||
// Every second, update and print values
|
||||
while (shouldRun)
|
||||
{
|
||||
dfrorp_update(sensor);
|
||||
|
||||
dfrorp_close(sensor);
|
||||
printf("ORP = %f mV\n", dfrorp_get_orp(sensor));
|
||||
|
||||
return 0;
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
dfrorp_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "dfrph.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -61,7 +69,7 @@ int main()
|
||||
printf("Detected volts: %0.03f\n", volts);
|
||||
printf("pH value: %0.03f\n", pH);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "ds18b20.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -38,44 +40,50 @@ void sig_handler(int signo)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Initializing...\n");
|
||||
|
||||
// Instantiate an DS18B20 instance using the uart 0
|
||||
ds18b20_context sensor = ds18b20_init(0);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("ds18b20_init() failed.\n");
|
||||
return(1);
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
printf("Initializing...\n");
|
||||
|
||||
// Instantiate an DS18B20 instance using the uart 0
|
||||
ds18b20_context sensor = ds18b20_init(0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
// update our values for all sensors
|
||||
ds18b20_update(sensor, -1);
|
||||
printf("ds18b20_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i=0; i<ds18b20_devices_found(sensor); i++)
|
||||
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values for all sensors
|
||||
ds18b20_update(sensor, -1);
|
||||
|
||||
int i;
|
||||
for (i=0; i<ds18b20_devices_found(sensor); i++)
|
||||
{
|
||||
printf("Device %02d: Temperature: %f C\n",
|
||||
i, ds18b20_get_temperature(sensor, i));
|
||||
printf("Device %02d: Temperature: %f C\n",
|
||||
i, ds18b20_get_temperature(sensor, i));
|
||||
}
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
|
||||
sleep(2);
|
||||
upm_delay(2);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
printf("Exiting...\n");
|
||||
|
||||
ds18b20_close(sensor);
|
||||
//! [Interesting]
|
||||
ds18b20_close(sensor);
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "emg.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw emg sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "flex.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw flex sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -7,19 +7,28 @@
|
||||
#include <unistd.h>
|
||||
#include "gp2y0a.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
gp2y0a_context dev = gp2y0a_init(14, 5.0);
|
||||
float val;
|
||||
while(1){
|
||||
if(gp2y0a_get_value(dev, 5.0, 20, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %f\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
gp2y0a_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
gp2y0a_context dev = gp2y0a_init(14, 5.0);
|
||||
float val;
|
||||
while(1){
|
||||
if(gp2y0a_get_value(dev, 5.0, 20, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %f\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
gp2y0a_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7,19 +7,28 @@
|
||||
#include <unistd.h>
|
||||
#include "grovemoisture.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
grovemoisture_context dev = grovemoisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(grovemoisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
grovemoisture_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
grovemoisture_context dev = grovemoisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(grovemoisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
grovemoisture_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "gsr.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw gsr sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "hka5.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,42 +39,48 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
hka5_context sensor = hka5_init(0, -1, -1);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("hka5_init() failed.\n");
|
||||
return 1;
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
while (shouldRun)
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
hka5_context sensor = hka5_init(0, -1, -1);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
if (hka5_update(sensor) != UPM_SUCCESS)
|
||||
printf("hka5_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
while (shouldRun)
|
||||
{
|
||||
if (hka5_update(sensor) != UPM_SUCCESS)
|
||||
{
|
||||
printf("hka5_update() failed, exiting.\n");
|
||||
shouldRun = false;
|
||||
printf("hka5_update() failed, exiting.\n");
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
printf("PM 1 : %d ug/m3\n", hka5_get_pm1(sensor));
|
||||
printf("PM 2.5: %d ug/m3\n", hka5_get_pm2_5(sensor));
|
||||
printf("PM 10 : %d ug/m3\n", hka5_get_pm10(sensor));
|
||||
printf("\n");
|
||||
printf("PM 1 : %d ug/m3\n", hka5_get_pm1(sensor));
|
||||
printf("PM 2.5: %d ug/m3\n", hka5_get_pm2_5(sensor));
|
||||
printf("PM 10 : %d ug/m3\n", hka5_get_pm10(sensor));
|
||||
printf("\n");
|
||||
|
||||
sleep(2);
|
||||
upm_delay(2);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
printf("Exiting\n");
|
||||
|
||||
hka5_close(sensor);
|
||||
hka5_close(sensor);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,9 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "joystick12.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +40,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +82,7 @@ int main()
|
||||
joystick12_get_value_y(sensor, &y);
|
||||
|
||||
printf("X: %5.02f Y: %5.02f\n", x, y);
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "ldt0028.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -82,7 +90,7 @@ int main()
|
||||
"adjusted output: %0.03f v\n\n", normalized, raw_volts, volts);
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -7,18 +7,28 @@
|
||||
#include <unistd.h>
|
||||
#include "led.h"
|
||||
|
||||
void main(void)
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
led_context dev = led_init(2);
|
||||
while(1){
|
||||
if(led_on(dev) != UPM_SUCCESS){
|
||||
printf("problem turning the LED on\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
if(led_off(dev) != UPM_SUCCESS){
|
||||
printf("problem turning the LED off\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
led_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
led_context dev = led_init(2);
|
||||
while(1){
|
||||
if(led_on(dev) != UPM_SUCCESS){
|
||||
printf("problem turning the LED on\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
if(led_off(dev) != UPM_SUCCESS){
|
||||
printf("problem turning the LED off\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
led_close(dev);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "light.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw light sensor output: %0.03f v "
|
||||
"light output: %0.03f lux\n", normalized, raw_volts, lux);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -7,19 +7,28 @@
|
||||
#include <unistd.h>
|
||||
#include "loudness.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
loudness_context dev = loudness_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(loudness_get_value(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Loudness Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
loudness_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
loudness_context dev = loudness_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(loudness_get_value(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Loudness Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
loudness_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -5,25 +5,34 @@
|
||||
#include <unistd.h>
|
||||
#include "m24lr64e.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
m24lr64e_context dev = m24lr64e_init(0, M24LR64E_USER_MODE);
|
||||
int addr = M24LR64E_EEPROM_I2C_LENGTH-1;
|
||||
printf("address being accessed: %d\n", addr);
|
||||
uint8_t byte;
|
||||
if(m24lr64e_read_byte(dev, addr, &byte) != UPM_SUCCESS)
|
||||
printf("error while reading value\n");
|
||||
printf("value read from the device: %d\n", byte);
|
||||
byte = ~byte;
|
||||
printf("byte to be written: %d\n", byte);
|
||||
if(m24lr64e_write_byte(dev, addr, byte) != UPM_SUCCESS)
|
||||
printf("error while writing byte to the device\n");
|
||||
uint8_t var;
|
||||
if(m24lr64e_read_byte(dev, addr, &var) != UPM_SUCCESS)
|
||||
printf("error while reading value back\n");
|
||||
printf("new value at %d: %d\n", addr, var);
|
||||
m24lr64e_close(dev);
|
||||
printf("all done!!\n");
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
m24lr64e_context dev = m24lr64e_init(0, M24LR64E_USER_MODE);
|
||||
int addr = M24LR64E_EEPROM_I2C_LENGTH-1;
|
||||
printf("address being accessed: %d\n", addr);
|
||||
uint8_t byte;
|
||||
if(m24lr64e_read_byte(dev, addr, &byte) != UPM_SUCCESS)
|
||||
printf("error while reading value\n");
|
||||
printf("value read from the device: %d\n", byte);
|
||||
byte = ~byte;
|
||||
printf("byte to be written: %d\n", byte);
|
||||
if(m24lr64e_write_byte(dev, addr, byte) != UPM_SUCCESS)
|
||||
printf("error while writing byte to the device\n");
|
||||
uint8_t var;
|
||||
if(m24lr64e_read_byte(dev, addr, &var) != UPM_SUCCESS)
|
||||
printf("error while reading value back\n");
|
||||
printf("new value at %d: %d\n", addr, var);
|
||||
m24lr64e_close(dev);
|
||||
printf("all done!!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "mma7361.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,49 +39,55 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MMA7361 sensor on analog pins A0 (X), A1 (Y) A2
|
||||
// (Z), selftest pin on D2, sleep pin on D3 nd an analog reference
|
||||
// value of 5.0. The freefall pin and the range pin are unused
|
||||
// (-1).
|
||||
mma7361_context sensor = mma7361_init(0, 1, 2, 2, 3, -1, -1, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("mma7361_init() failed.\n");
|
||||
return(1);
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 1.5g (true = 6g)
|
||||
mma7361_set_range(sensor, false);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// Every 10th of a second, update and print values
|
||||
//! [Interesting]
|
||||
|
||||
while (shouldRun)
|
||||
// Instantiate a MMA7361 sensor on analog pins A0 (X), A1 (Y) A2
|
||||
// (Z), selftest pin on D2, sleep pin on D3 nd an analog reference
|
||||
// value of 5.0. The freefall pin and the range pin are unused
|
||||
// (-1).
|
||||
mma7361_context sensor = mma7361_init(0, 1, 2, 2, 3, -1, -1, 5.0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
mma7361_update(sensor);
|
||||
|
||||
float x, y, z;
|
||||
|
||||
mma7361_get_acceleration(sensor, &x, &y, &z);
|
||||
printf("Acceleration x = %f y = %f z = %f\n",
|
||||
x, y, z);
|
||||
|
||||
mma7361_get_volts(sensor, &x, &y, &z);
|
||||
printf("Volts x = %f y = %f z = %f\n\n",
|
||||
x, y, z);
|
||||
|
||||
usleep(100000);
|
||||
printf("mma7361_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// 1.5g (true = 6g)
|
||||
mma7361_set_range(sensor, false);
|
||||
|
||||
printf("Exiting...\n");
|
||||
// Every 10th of a second, update and print values
|
||||
|
||||
mma7361_close(sensor);
|
||||
while (shouldRun)
|
||||
{
|
||||
mma7361_update(sensor);
|
||||
|
||||
return 0;
|
||||
float x, y, z;
|
||||
|
||||
mma7361_get_acceleration(sensor, &x, &y, &z);
|
||||
printf("Acceleration x = %f y = %f z = %f\n",
|
||||
x, y, z);
|
||||
|
||||
mma7361_get_volts(sensor, &x, &y, &z);
|
||||
printf("Volts x = %f y = %f z = %f\n\n",
|
||||
x, y, z);
|
||||
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
mma7361_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,19 +7,27 @@
|
||||
#include <unistd.h>
|
||||
#include "moisture.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
moisture_context dev = moisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(moisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
moisture_close(dev);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
moisture_context dev = moisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(moisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
moisture_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7,24 +7,33 @@
|
||||
#include <unistd.h>
|
||||
#include "mpr121.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
mpr121_context dev = mpr121_init(MPR121_I2C_BUS, MPR121_DEFAULT_I2C_ADDR);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(mpr121_config_an3944(dev) != UPM_SUCCESS){
|
||||
printf("unable to configure device\n");
|
||||
}
|
||||
uint32_t states;
|
||||
while(1){
|
||||
if(mpr121_read_buttons(dev, &states, 0) != UPM_SUCCESS){
|
||||
printf("Error while reading button values\n");
|
||||
}
|
||||
printf("retrieved button states: %d\n", states);
|
||||
upm_delay(1);
|
||||
}
|
||||
mpr121_context dev = mpr121_init(MPR121_I2C_BUS, MPR121_DEFAULT_I2C_ADDR);
|
||||
|
||||
mpr121_close(dev);
|
||||
printf("all done!!\n");
|
||||
if(mpr121_config_an3944(dev) != UPM_SUCCESS){
|
||||
printf("unable to configure device\n");
|
||||
}
|
||||
uint32_t states;
|
||||
while(1){
|
||||
if(mpr121_read_buttons(dev, &states, 0) != UPM_SUCCESS){
|
||||
printf("Error while reading button values\n");
|
||||
}
|
||||
printf("retrieved button states: %d\n", states);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
mpr121_close(dev);
|
||||
printf("all done!!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,20 +7,28 @@
|
||||
#include <unistd.h>
|
||||
#include "mq303a.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main() {
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------- MQ303A EXAMPLE -------- */
|
||||
mq303a_context dev = mq303a_init(0, 15);
|
||||
printf("init done for mq303a\n");
|
||||
int value;
|
||||
mq303a_heater_enable(dev, true);
|
||||
upm_delay(12);
|
||||
while(1){
|
||||
mq303a_get_value(dev, &value);
|
||||
printf("returned value: %d\n", value);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* --------- MQ303A EXAMPLE -------- */
|
||||
mq303a_context dev = mq303a_init(0, 15);
|
||||
printf("init done for mq303a\n");
|
||||
int value;
|
||||
mq303a_heater_enable(dev, true);
|
||||
upm_delay(12);
|
||||
while(1){
|
||||
mq303a_get_value(dev, &value);
|
||||
printf("returned value: %d\n", value);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "mqx.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw mqx sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "nmea_gps.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -39,42 +41,48 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable
|
||||
// pin on D3. If you do not need an enable pin, you can specify -1.
|
||||
nmea_gps_context sensor = nmea_gps_init(0, 9600, 3);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("nmea_gps_init() failed.\n");
|
||||
return 1;
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buffer[bufferLength];
|
||||
int rv = 0;
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun && nmea_gps_data_available(sensor, 5000))
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable
|
||||
// pin on D3. If you do not need an enable pin, you can specify -1.
|
||||
nmea_gps_context sensor = nmea_gps_init(0, 9600, 3);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
|
||||
printf("nmea_gps_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[bufferLength];
|
||||
int rv = 0;
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun && nmea_gps_data_available(sensor, 5000))
|
||||
{
|
||||
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<rv; i++)
|
||||
printf("%c", buffer[i]);
|
||||
int i;
|
||||
for (i=0; i<rv; i++)
|
||||
printf("%c", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldRun)
|
||||
printf("Timed out\n");
|
||||
if (shouldRun)
|
||||
printf("Timed out\n");
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
printf("Exiting\n");
|
||||
|
||||
nmea_gps_close(sensor);
|
||||
nmea_gps_close(sensor);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "nmea_gps.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -33,50 +35,56 @@ const size_t bufferLength = 128;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a NMEA_GPS UBLOX based i2c sensor on i2c bus 0 at
|
||||
// address 0x42
|
||||
nmea_gps_context sensor = nmea_gps_init_ublox_i2c(0, 0x42);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("nmea_gps_init_ublox_i2c() failed.\n");
|
||||
return 1;
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char buffer[bufferLength];
|
||||
int rv = 0;
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a NMEA_GPS UBLOX based i2c sensor on i2c bus 0 at
|
||||
// address 0x42
|
||||
nmea_gps_context sensor = nmea_gps_init_ublox_i2c(0, 0x42);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
if (!nmea_gps_data_available(sensor, 0))
|
||||
usleep(100);
|
||||
else
|
||||
printf("nmea_gps_init_ublox_i2c() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[bufferLength];
|
||||
int rv = 0;
|
||||
|
||||
// loop, dumping NMEA data out as fast as it comes in
|
||||
while (shouldRun)
|
||||
{
|
||||
if (!nmea_gps_data_available(sensor, 0))
|
||||
upm_delay_ms(500);
|
||||
else
|
||||
{
|
||||
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
|
||||
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<rv; i++)
|
||||
printf("%c", buffer[i]);
|
||||
int i;
|
||||
for (i=0; i<rv; i++)
|
||||
printf("%c", buffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
printf("Exiting\n");
|
||||
|
||||
nmea_gps_close(sensor);
|
||||
nmea_gps_close(sensor);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "o2.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -62,7 +70,7 @@ int main()
|
||||
printf("O2 raw volts: %0.03f v, o2: %0.03f %%\n",
|
||||
raw_volts, o2_percent);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -7,29 +7,38 @@
|
||||
#include <unistd.h>
|
||||
#include "es08a.c"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
es08a_context dev = es08a_init(3, ES08A_MIN_PULSE_WIDTH, ES08A_MAX_PULSE_WIDTH);
|
||||
if(dev == NULL){
|
||||
printf("unable to initialize the servo context\n");
|
||||
}
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
es08a_context dev = es08a_init(3, ES08A_MIN_PULSE_WIDTH, ES08A_MAX_PULSE_WIDTH);
|
||||
if(dev == NULL){
|
||||
printf("unable to initialize the servo context\n");
|
||||
}
|
||||
|
||||
if(es08a_set_angle(dev, 180) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 180 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
if(es08a_set_angle(dev, 180) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 180 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
es08a_halt(dev);
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
return 0;
|
||||
es08a_halt(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,52 +26,60 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "sht1x.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a SHT1X sensor using D2 as the clock, and D3 as the
|
||||
// data pin.
|
||||
sht1x_context sensor = sht1x_init(2, 3);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("sht1x_init() failed.\n");
|
||||
return 1;
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun)
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a SHT1X sensor using D2 as the clock, and D3 as the
|
||||
// data pin.
|
||||
sht1x_context sensor = sht1x_init(2, 3);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
if (sht1x_update(sensor))
|
||||
printf("sht1x_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Every 2 seconds, update and print values
|
||||
while (shouldRun)
|
||||
{
|
||||
if (sht1x_update(sensor))
|
||||
{
|
||||
printf("sht1x_update() failed, exiting.\n");
|
||||
break;
|
||||
printf("sht1x_update() failed, exiting.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Temperature: %f C\n", sht1x_get_temperature(sensor));
|
||||
printf("Humidity: %f RH\n", sht1x_get_humidity(sensor));
|
||||
printf("\n");
|
||||
printf("Temperature: %f C\n", sht1x_get_temperature(sensor));
|
||||
printf("Humidity: %f RH\n", sht1x_get_humidity(sensor));
|
||||
printf("\n");
|
||||
|
||||
sleep(2);
|
||||
upm_delay(2);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
printf("Exiting\n");
|
||||
|
||||
sht1x_close(sensor);
|
||||
sht1x_close(sensor);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "slide.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -73,7 +81,7 @@ int main()
|
||||
printf("Normalized output: %0.03f, raw slide sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
@ -7,14 +7,23 @@
|
||||
#include <unistd.h>
|
||||
#include "tsl2561.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
tsl2561_context dev = tsl2561_init(0, TSL2561_Address, GAIN_0X, INTEGRATION_TIME1_101MS);
|
||||
float abc = 0;
|
||||
if(tsl2561_get_lux(dev, &abc) != UPM_SUCCESS){
|
||||
printf("ERROR !! ERROR !! ERROR!!");
|
||||
}
|
||||
printf("value retrieved: %f\n", abc);
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
tsl2561_context dev = tsl2561_init(0, TSL2561_Address, GAIN_0X, INTEGRATION_TIME1_101MS);
|
||||
float abc = 0;
|
||||
if(tsl2561_get_lux(dev, &abc) != UPM_SUCCESS){
|
||||
printf("ERROR !! ERROR !! ERROR!!");
|
||||
}
|
||||
printf("value retrieved: %f\n", abc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -7,17 +7,26 @@
|
||||
#include <unistd.h>
|
||||
#include "ttp223.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
ttp223_context dev = ttp223_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(ttp223_is_pressed(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
ttp223_context dev = ttp223_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(ttp223_is_pressed(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "urm37.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,39 +39,45 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a URM37 sensor on UART 0, with the reset pin on D2
|
||||
urm37_context sensor = urm37_init(0, 2, 0, 0, 0, false);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("urm37_init() failed.\n");
|
||||
return(1);
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Every half a second, sample the URM37 and output the measured
|
||||
// distance in cm.
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a URM37 sensor on UART 0, with the reset pin on D2
|
||||
urm37_context sensor = urm37_init(0, 2, 0, 0, 0, false);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
float distance, temperature;
|
||||
|
||||
urm37_get_distance(sensor, &distance, 0);
|
||||
printf("Detected distance (cm): %f\n", distance);
|
||||
|
||||
urm37_get_temperature(sensor, &temperature);
|
||||
printf("Temperature (C): %f\n\n", temperature);
|
||||
usleep(500000);
|
||||
printf("urm37_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// Every half a second, sample the URM37 and output the measured
|
||||
// distance in cm.
|
||||
|
||||
printf("Exiting\n");
|
||||
while (shouldRun)
|
||||
{
|
||||
float distance, temperature;
|
||||
|
||||
urm37_close(sensor);
|
||||
urm37_get_distance(sensor, &distance, 0);
|
||||
printf("Detected distance (cm): %f\n", distance);
|
||||
|
||||
return 0;
|
||||
urm37_get_temperature(sensor, &temperature);
|
||||
printf("Temperature (C): %f\n\n", temperature);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
urm37_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "urm37.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,37 +39,43 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a URM37 sensor on analog pin A0, reset pin on D2,
|
||||
// trigger pin on D3 with an analog reference voltage of 5.0
|
||||
urm37_context sensor = urm37_init(0, 2, 3, 5.0, 0, true);
|
||||
|
||||
if (!sensor)
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("urm37_init() failed.\n");
|
||||
return(1);
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Every half a second, sample the URM37 and output the measured
|
||||
// distance in cm.
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (shouldRun)
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a URM37 sensor on analog pin A0, reset pin on D2,
|
||||
// trigger pin on D3 with an analog reference voltage of 5.0
|
||||
urm37_context sensor = urm37_init(0, 2, 3, 5.0, 0, true);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
float distance;
|
||||
|
||||
urm37_get_distance(sensor, &distance, 0);
|
||||
printf("Detected distance (cm): %f\n", distance);
|
||||
usleep(500000);
|
||||
printf("urm37_init() failed.\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
// Every half a second, sample the URM37 and output the measured
|
||||
// distance in cm.
|
||||
|
||||
printf("Exiting\n");
|
||||
while (shouldRun)
|
||||
{
|
||||
float distance;
|
||||
|
||||
urm37_close(sensor);
|
||||
urm37_get_distance(sensor, &distance, 0);
|
||||
printf("Detected distance (cm): %f\n", distance);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
return 0;
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
urm37_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Author: Noel Eck <noel.eck@intel.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -26,6 +26,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "vdiv.h"
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
@ -37,6 +39,12 @@ void sig_handler(int signo)
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
@ -61,7 +69,7 @@ int main()
|
||||
printf("Divide SW: %d ADC voltage: %0.03f Sensor voltage: %0.03f\n",
|
||||
vdiv_get_divsw(sensor), raw_volts, computed_volts);
|
||||
|
||||
usleep(500000);
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
Loading…
x
Reference in New Issue
Block a user