o2: Added O2 sensor C source

Added the C source for the O2 sensor with necessary changes to cmake,
examples, docs.

    * Renamed all files with groveo2 to o2
    * Replaced all instances of groveo2 with o2
    * Added C source for o2 sensor
    * Updated all cmake files
    * Added C example for o2 sensor

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-07 10:18:06 -07:00
parent fe318a78d2
commit f9878b3fe6
19 changed files with 514 additions and 53 deletions

View File

@ -170,7 +170,7 @@ add_example (otp538u)
add_example (grovecollision)
add_example (groveelectromagnet)
add_example (groveemg)
add_example (groveo2)
add_example (o2)
add_example (grovegsr)
add_example (ina132)
add_example (l298)

View File

@ -24,7 +24,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "groveo2.hpp"
#include "o2.hpp"
using namespace std;
@ -42,8 +42,8 @@ int main(int argc, char **argv)
//! [Interesting]
// The was tested with the O2 Oxygen Concentration Sensor Module
// Instantiate a GroveO2 on analog pin A0
upm::GroveO2 *O2 = new upm::GroveO2(0);
// Instantiate a O2 on analog pin A0
upm::O2 *O2 = new upm::O2(0);
while (shouldRun)
{
cout << "The output voltage is: " << O2->voltageValue() << "mV" << endl;

View File

@ -96,6 +96,7 @@ add_example (hka5)
add_example (dfrorp)
add_example (vdiv)
add_example (mqx)
add_example (o2)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

75
examples/c/o2.c Normal file
View File

@ -0,0 +1,75 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "o2.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a o2 sensor on analog pin A0
o2_context sensor = o2_init(0);
if (!sensor)
{
printf("o2_init() failed.\n");
return -1;
}
// Every half a second, sample the sensor output
while (shouldRun)
{
float raw_volts = 0.0;
float o2_percent = 0.0;
o2_get_raw_volts(sensor, &raw_volts);
o2_get_value(sensor, &o2_percent);
printf("O2 raw volts: %0.03f v, o2: %0.03f %\n",
raw_volts, o2_percent);
usleep(500000);
}
//! [Interesting]
printf("Exiting\n");
o2_close(sensor);
return 0;
}

View File

@ -44,7 +44,7 @@ add_example(GroveMDSample grovemd)
add_example(GroveMoistureSample grovemoisture)
add_example(GroveMQ3 gas)
add_example(GroveMQ9 gas)
add_example(GroveO2Example groveo2)
add_example(O2Example o2)
add_example(GroveQTouch at42qt1070)
add_example(GroveRelaySample grove)
add_example(GroveRotarySample grove)

View File

@ -22,15 +22,15 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_groveo2.GroveO2;
import upm_o2.O2;
public class GroveO2Example {
public class O2Example {
public static void main(String[] args) {
// TODO Auto-generated method stub
//! [Interesting]
// Initializing the Grove O2 sensor on the A) analog pin
GroveO2 o2 = new GroveO2(0);
O2 o2 = new O2(0);
while(true){
System.out.println("The output voltage is: "+o2.voltageValue());

View File

@ -21,15 +21,15 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var groveO2_lib = require("jsupm_groveo2");
var O2_lib = require("jsupm_o2");
// The was tested with the O2 Oxygen Concentration Sensor Module
// Instantiate a GroveO2 on analog pin A0
var groveO2_obj = new groveO2_lib.GroveO2(0);
// Instantiate a O2 on analog pin A0
var O2_obj = new O2_lib.O2(0);
var myInterval = setInterval(function()
{
console.log("The output voltage is: " + roundNum(groveO2_obj.voltageValue(), 5) + "mV");
console.log("The output voltage is: " + roundNum(O2_obj.voltageValue(), 5) + "mV");
}, 100);
function roundNum(num, decimalPlaces)
@ -42,9 +42,9 @@ function roundNum(num, decimalPlaces)
process.on('SIGINT', function()
{
clearInterval(myInterval);
groveO2_obj = null;
groveO2_lib.cleanUp();
groveO2_lib = null;
O2_obj = null;
O2_lib.cleanUp();
O2_lib = null;
console.log("Exiting...");
process.exit(0);
});

View File

@ -22,11 +22,11 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_groveo2 as upmGroveo2
import pyupm_o2 as upmO2
# This was tested with the O2 Oxygen Concentration Sensor Module
# Instantiate a GroveO2 on analog pin A0
myGroveO2 = upmGroveo2.GroveO2(0)
# Instantiate a O2 on analog pin A0
myO2 = upmO2.O2(0)
## Exit handlers ##
@ -34,7 +34,7 @@ myGroveO2 = upmGroveo2.GroveO2(0)
def SIGINTHandler(signum, frame):
raise SystemExit
# This lets you run code on exit, including functions from myGroveO2
# This lets you run code on exit, including functions from myO2
def exitHandler():
print "Exiting"
sys.exit(0)
@ -46,6 +46,6 @@ signal.signal(signal.SIGINT, SIGINTHandler)
while(1):
print "The output voltage is: {0}mV".format(
myGroveO2.voltageValue())
myO2.voltageValue())
time.sleep(.1)