mirror of
https://github.com/eclipse/upm.git
synced 2025-07-04 19:01:21 +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:
133
src/slide/slide.h
Normal file
133
src/slide/slide.h
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Author:
|
||||
* Copyright (c) 2015 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "upm.h"
|
||||
#include "mraa/aio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* driver context
|
||||
*/
|
||||
typedef struct _slide_context {
|
||||
/* mraa aio pin context */
|
||||
mraa_aio_context aio;
|
||||
/* Analog voltage reference */
|
||||
float m_aRef;
|
||||
/* Scale */
|
||||
float m_scale;
|
||||
/* Offset in sensor units */
|
||||
float m_offset;
|
||||
} *slide_context;
|
||||
|
||||
/**
|
||||
* Initialize analog sensor
|
||||
* @param pin Analog pin
|
||||
* @return sensor context
|
||||
*/
|
||||
slide_context slide_init(int16_t pin);
|
||||
|
||||
/**
|
||||
* Analog sensor destructor
|
||||
* @param sensor context pointer
|
||||
*/
|
||||
void slide_close(slide_context dev);
|
||||
|
||||
/**
|
||||
* Set ADC reference voltage
|
||||
* @param dev sensor context pointer
|
||||
* @param aref ADC reference voltage
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_set_aref(const slide_context dev, float aref);
|
||||
|
||||
/**
|
||||
* Set sensor scale. This scale is applied to the return value:
|
||||
* counts = counts * scale
|
||||
* @param dev sensor context pointer
|
||||
* @param scale count scale value used
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_set_scale(const slide_context dev, float scale);
|
||||
|
||||
/**
|
||||
* Set sensor offset. This offset is applied to the return value:
|
||||
* value = value + offset
|
||||
* @param dev sensor context pointer
|
||||
* @param offset count offset value used
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_set_offset(const slide_context dev, float offset);
|
||||
|
||||
/**
|
||||
* Get sensor aref
|
||||
* @param dev sensor context pointer
|
||||
* @return Sensor ADC reference voltage
|
||||
*/
|
||||
float slide_get_aref(const slide_context dev);
|
||||
|
||||
/**
|
||||
* Get sensor scale
|
||||
* @param dev sensor context pointer
|
||||
* @return Sensor scale
|
||||
*/
|
||||
float slide_get_scale(const slide_context dev);
|
||||
|
||||
/**
|
||||
* Get sensor offset
|
||||
* @param dev sensor context pointer
|
||||
* @return Sensor offset
|
||||
*/
|
||||
float slide_get_offset(const slide_context dev);
|
||||
|
||||
/**
|
||||
* Read normalized value for sensor
|
||||
* @param dev sensor context pointer
|
||||
* @param *value Normalized value (0.0 -> 1.0)
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_get_normalized(const slide_context dev, float *value);
|
||||
|
||||
/**
|
||||
* Read raw voltage from the sensor
|
||||
* @param dev sensor context pointer
|
||||
* @param *value Raw sensor voltage
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_get_raw_volts(const slide_context dev, float *value);
|
||||
|
||||
/**
|
||||
* Read scaled/offset voltage from the sensor
|
||||
* @param dev sensor context pointer
|
||||
* @param *value Adjusted sensor voltage
|
||||
* @return Function result code
|
||||
*/
|
||||
upm_result_t slide_get_volts(const slide_context dev, float *value);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user