mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
slide: Added slide potentiometer sensor C source
Added the C source for the flex sensor with necessary changes to cmake, examples, and docs. * Renamed all files with groveslide to slide * Replaced all instances of groveslide with slide * Added C source for slide sensor * Updated all cmake files * Added C example for slide sensor * Split out slide sensor from grove library Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -93,7 +93,7 @@ add_example (light)
|
||||
add_example (grovetemp)
|
||||
add_example (grovebutton)
|
||||
add_example (groverotary)
|
||||
add_example (groveslide)
|
||||
add_example (slide)
|
||||
add_example (buzzer-sound)
|
||||
add_example (nrf24l01-transmitter)
|
||||
add_example (nrf24l01-receiver)
|
||||
|
@ -26,14 +26,14 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "grove.hpp"
|
||||
#include "slide.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main ()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::GroveSlide* slide = new upm::GroveSlide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||
upm::Slide* slide = new upm::Slide(0); // Instantiate new grove slide potentiometer on analog pin A0
|
||||
|
||||
cout << slide->name() << endl;
|
||||
|
@ -103,6 +103,7 @@ add_example (light)
|
||||
add_example (ldt0028)
|
||||
add_example (joystick12)
|
||||
add_example (flex)
|
||||
add_example (slide)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
86
examples/c/slide.c
Normal file
86
examples/c/slide.c
Normal 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 "slide.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a slide sensor on analog pin A0
|
||||
slide_context sensor = slide_init(0);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("slide_init() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the aref, scale, and offset
|
||||
slide_set_aref(sensor, 5.0);
|
||||
slide_set_scale(sensor, 1.0);
|
||||
slide_set_offset(sensor, -.1);
|
||||
printf("aRef: %0.03f scale: %0.03f offset: %0.03f\n\n",
|
||||
slide_get_aref(sensor),
|
||||
slide_get_scale(sensor),
|
||||
slide_get_offset(sensor));
|
||||
|
||||
// Every half a second, sample the sensor output
|
||||
while (shouldRun)
|
||||
{
|
||||
float normalized = 0.0;
|
||||
float raw_volts = 0.0;
|
||||
float volts = 0.0;
|
||||
|
||||
slide_get_normalized(sensor, &normalized);
|
||||
slide_get_raw_volts(sensor, &raw_volts);
|
||||
slide_get_volts(sensor, &volts);
|
||||
|
||||
printf("Normalized output: %0.03f, raw slide sensor output: %0.03f v "
|
||||
"adjusted output: %0.03f v\n", normalized, raw_volts, volts);
|
||||
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
slide_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
@ -49,7 +49,7 @@ add_example(GroveQTouch at42qt1070)
|
||||
add_example(GroveRelaySample grove)
|
||||
add_example(GroveRotarySample grove)
|
||||
add_example(GROVESCAMSample grovescam)
|
||||
add_example(GroveSlideSample grove)
|
||||
add_example(SlideSample grove)
|
||||
add_example(GroveSpeakerSample grovespeaker)
|
||||
add_example(GroveTempSample grove)
|
||||
add_example(VDivSample vdiv)
|
||||
|
@ -22,11 +22,11 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class GroveSlideSample {
|
||||
public class SlideSample {
|
||||
public static void main (String args[]) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate new grove slide potentiometer on analog pin A0
|
||||
upm_grove.GroveSlide slide = new upm_grove.GroveSlide(0);
|
||||
upm_grove.Slide slide = new upm_grove.Slide(0);
|
||||
|
||||
while (true) {
|
||||
float raw_value = slide.raw_value();
|
@ -25,14 +25,14 @@
|
||||
var upm_grove = require('jsupm_grove');
|
||||
|
||||
//setup access analog input Analog pin #0 (A0)
|
||||
var groveSlide = new upm_grove.GroveSlide(0);
|
||||
var Slide = new upm_grove.Slide(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
var raw = groveSlide.raw_value();
|
||||
var volts = groveSlide.voltage_value();
|
||||
var raw = Slide.raw_value();
|
||||
var volts = Slide.voltage_value();
|
||||
|
||||
//write the slider values to the console
|
||||
console.log("Slider Value: " + raw + " = " + volts.toFixed(2) + " V");
|
@ -24,7 +24,7 @@ from time import sleep
|
||||
import pyupm_grove as grove
|
||||
|
||||
# New Grove Slider on AIO pin 0
|
||||
slider = grove.GroveSlide(0)
|
||||
slider = grove.Slide(0)
|
||||
|
||||
# Loop indefinitely
|
||||
while True:
|
Reference in New Issue
Block a user