light: Added light sensor C source

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

    * Renamed all files with grovelight to light
    * Replaced all instances of grovelight with light
    * Added C source for light sensor
    * Updated all cmake files
    * Added C example for light sensor
    * Split out light sensor from grove library

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-09 14:10:30 -07:00
parent 0e52ea619b
commit 571f9c9498
25 changed files with 564 additions and 51 deletions

View File

@ -89,7 +89,7 @@ link_directories (${MRAA_LIBDIR})
add_example (hmc5883l)
add_example (groveled)
add_example (groverelay)
add_example (grovelight)
add_example (light)
add_example (grovetemp)
add_example (grovebutton)
add_example (groverotary)

View File

@ -25,14 +25,14 @@
#include <unistd.h>
#include <iostream>
#include "grove.hpp"
#include "light.hpp"
int
main(int argc, char **argv)
{
//! [Interesting]
// Create the light sensor object using AIO pin 0
upm::GroveLight* light = new upm::GroveLight(0);
upm::Light* light = new upm::Light(0);
// Read the input and print both the raw value and a rough lux value,
// waiting one second between readings

View File

@ -99,6 +99,7 @@ add_example (mqx)
add_example (o2)
add_example (emg)
add_example (gsr)
add_example (light)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

86
examples/c/light.c Normal file
View File

@ -0,0 +1,86 @@
/*
* 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 "light.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a light sensor on analog pin A0
light_context sensor = light_init(0);
if (!sensor)
{
printf("light_init() failed.\n");
return -1;
}
// Set the aref, scale, and offset
light_set_aref(sensor, 5.0);
light_set_scale(sensor, 1.0);
light_set_offset(sensor, -.1);
printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n",
light_get_aref(sensor),
light_get_scale(sensor),
light_get_offset(sensor));
// Every half a second, sample the sensor output
while (shouldRun)
{
float normalized = 0.0;
float raw_volts = 0.0;
float lux = 0.0;
light_get_normalized(sensor, &normalized);
light_get_raw_volts(sensor, &raw_volts);
light_get_lux(sensor, &lux);
printf("Normalized output: %0.03f, raw light sensor output: %0.03f v "
"light output: %0.03f lux\n", normalized, raw_volts, lux);
usleep(500000);
}
//! [Interesting]
printf("Exiting\n");
light_close(sensor);
return 0;
}

View File

@ -38,7 +38,7 @@ add_example(Emg emg)
add_example(Gsr gsr)
add_example(GroveLed_multiSample grove)
add_example(GroveLEDSample grove)
add_example(GroveLightSample grove)
add_example(LightSample grove)
add_example(GroveLineFinderSample grovelinefinder)
add_example(GroveMDSample grovemd)
add_example(GroveMoistureSample grovemoisture)

View File

@ -22,10 +22,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class GroveLightSample {
public class LightSample {
public static void main(String args[]) throws InterruptedException {
// ! [Interesting]
upm_grove.GroveLight gl = new upm_grove.GroveLight(2);
upm_grove.Light gl = new upm_grove.Light(2);
while (true) {
float raw_value = gl.raw_value();

View File

@ -26,7 +26,7 @@
var groveSensor = require('jsupm_grove');
// Create the light sensor object using AIO pin 0
var light = new groveSensor.GroveLight(0);
var light = new groveSensor.Light(0);
// Read the input and print both the raw value and a rough lux value,
// waiting one second between readings

View File

@ -24,7 +24,7 @@ import time
import pyupm_grove as grove
# Create the light sensor object using AIO pin 0
light = grove.GroveLight(0)
light = grove.Light(0)
# Read the input and print both the raw value and a rough lux value,
# waiting one second between readings