mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Moisture: Add C Src and Example
Changed from GroveMoisture. Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
0f7bb5573c
commit
1caf805d2b
@ -142,7 +142,7 @@ add_example (adc121c021)
|
||||
add_example (ds1307)
|
||||
add_example (a110x)
|
||||
add_example (gp2y0a)
|
||||
add_example (grovemoisture)
|
||||
add_example (moisture)
|
||||
add_example (groveehr)
|
||||
add_example (ta12200)
|
||||
add_example (grovelinefinder)
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "grovemoisture.hpp"
|
||||
#include "moisture.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -43,8 +43,8 @@ int main ()
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove Moisture sensor on analog pin A0
|
||||
upm::GroveMoisture* moisture = new upm::GroveMoisture(0);
|
||||
// Instantiate a Moisture sensor on analog pin A0
|
||||
upm::Moisture* moisture = new upm::Moisture(0);
|
||||
|
||||
// Values (approximate):
|
||||
// 0-300, sensor in air or dry soil
|
@ -114,6 +114,7 @@ add_example (ttp223)
|
||||
add_example (loudness)
|
||||
add_example (tsl2561)
|
||||
add_example (collision)
|
||||
add_example (moisture)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
25
examples/c/moisture.c
Normal file
25
examples/c/moisture.c
Normal file
@ -0,0 +1,25 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "moisture.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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ add_example(GroveLEDSample grove)
|
||||
add_example(LightSample light)
|
||||
add_example(GroveLineFinderSample grovelinefinder)
|
||||
add_example(GroveMDSample grovemd)
|
||||
add_example(GroveMoistureSample grovemoisture)
|
||||
add_example(MoistureSample moisture)
|
||||
add_example(GroveMQ3 gas)
|
||||
add_example(GroveMQ9 gas)
|
||||
add_example(O2Example o2)
|
||||
|
@ -22,10 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class GroveMoistureSample {
|
||||
public class MoistureSample {
|
||||
public static void main(String args[]) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_grovemoisture.GroveMoisture gm = new upm_grovemoisture.GroveMoisture(1);
|
||||
upm_moisture.Moisture gm = new upm_moisture.Moisture(1);
|
||||
|
||||
while (true) {
|
||||
int moisture_val = gm.value();
|
@ -23,10 +23,10 @@
|
||||
*/
|
||||
|
||||
//Load Grove Moisture module
|
||||
var grove_moisture = require('jsupm_grovemoisture');
|
||||
var moisture = require('jsupm_moisture');
|
||||
|
||||
// Instantiate a Grove Moisture sensor on analog pin A0
|
||||
var myMoistureObj = new grove_moisture.GroveMoisture(0);
|
||||
var myMoistureObj = new moisture.Moisture(0);
|
||||
|
||||
// Values (approximate):
|
||||
// 0-300, sensor in air or dry soil
|
@ -22,10 +22,10 @@
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_grovemoisture as upmMoisture
|
||||
import pyupm_moisture as upmMoisture
|
||||
|
||||
# Instantiate a Grove Moisture sensor on analog pin A0
|
||||
myMoisture = upmMoisture.GroveMoisture(0)
|
||||
myMoisture = upmMoisture.Moisture(0)
|
||||
|
||||
|
||||
## Exit handlers ##
|
@ -1,9 +0,0 @@
|
||||
upm_mixed_module_init (NAME grovemoisture
|
||||
DESCRIPTION "upm grove moisture module"
|
||||
C_HDR moisture.h
|
||||
C_SRC moisture.c
|
||||
CPP_HDR grovemoisture.hpp
|
||||
CPP_SRC grovemoisture.cxx
|
||||
FTI_SRC grovemoisture_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES libmraa)
|
@ -1,8 +0,0 @@
|
||||
%module jsupm_grovemoisture
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "grovemoisture.hpp"
|
||||
%}
|
||||
|
||||
%include "grovemoisture.hpp"
|
9
src/moisture/CMakeLists.txt
Normal file
9
src/moisture/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
upm_mixed_module_init (NAME moisture
|
||||
DESCRIPTION "upm analog moisture module"
|
||||
C_HDR moisture.h
|
||||
C_SRC moisture.c
|
||||
CPP_HDR moisture.hpp
|
||||
CPP_SRC moisture.cxx
|
||||
FTI_SRC moisture_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES libmraa)
|
@ -1,16 +1,16 @@
|
||||
%module javaupm_grovemoisture
|
||||
%module javaupm_moisture
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "grovemoisture.hpp"
|
||||
#include "moisture.hpp"
|
||||
%}
|
||||
|
||||
%include "grovemoisture.hpp"
|
||||
%include "moisture.hpp"
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_grovemoisture");
|
||||
System.loadLibrary("javaupm_moisture");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
8
src/moisture/jsupm_moisture.i
Normal file
8
src/moisture/jsupm_moisture.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_moisture
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "moisture.hpp"
|
||||
%}
|
||||
|
||||
%include "moisture.hpp"
|
@ -25,9 +25,9 @@
|
||||
|
||||
#include "moisture.h"
|
||||
|
||||
grovemoisture_context grovemoisture_init(int pin) {
|
||||
grovemoisture_context dev =
|
||||
(grovemoisture_context) malloc(sizeof(struct _grovemoisture_context));
|
||||
moisture_context moisture_init(int pin) {
|
||||
moisture_context dev =
|
||||
(moisture_context) malloc(sizeof(struct _moisture_context));
|
||||
|
||||
if (dev == NULL) {
|
||||
printf("Unable to allocate memory for device context\n");
|
||||
@ -47,12 +47,12 @@ grovemoisture_context grovemoisture_init(int pin) {
|
||||
return dev;
|
||||
}
|
||||
|
||||
void grovemoisture_close(grovemoisture_context dev) {
|
||||
void moisture_close(moisture_context dev) {
|
||||
mraa_aio_close(dev->aio);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t grovemoisture_get_moisture(grovemoisture_context dev,
|
||||
upm_result_t moisture_get_moisture(moisture_context dev,
|
||||
int* moisture) {
|
||||
|
||||
*moisture = mraa_aio_read(dev->aio);
|
@ -26,23 +26,23 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "grovemoisture.hpp"
|
||||
#include "moisture.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
GroveMoisture::GroveMoisture(int pin)
|
||||
Moisture::Moisture(int pin)
|
||||
{
|
||||
if ( !(m_aio = mraa_aio_init(pin)) )
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init() failed, invalid pin?");
|
||||
}
|
||||
|
||||
GroveMoisture::~GroveMoisture()
|
||||
Moisture::~Moisture()
|
||||
{
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveMoisture::value()
|
||||
int Moisture::value()
|
||||
{
|
||||
return mraa_aio_read(m_aio);
|
||||
}
|
@ -39,10 +39,10 @@ extern "C" {
|
||||
/**
|
||||
* device context
|
||||
*/
|
||||
typedef struct _grovemoisture_context {
|
||||
typedef struct _moisture_context {
|
||||
mraa_aio_context aio;
|
||||
uint16_t analog_pin;
|
||||
} *grovemoisture_context;
|
||||
} *moisture_context;
|
||||
|
||||
/**
|
||||
* Init function
|
||||
@ -50,14 +50,14 @@ typedef struct _grovemoisture_context {
|
||||
* @param pin analog pin number
|
||||
* @return void* pointer to the sensor struct
|
||||
*/
|
||||
grovemoisture_context grovemoisture_init(int pin);
|
||||
moisture_context moisture_init(int pin);
|
||||
|
||||
/**
|
||||
* Close function
|
||||
*
|
||||
* @param dev pointer to the sensor structure
|
||||
*/
|
||||
void grovemoisture_close(grovemoisture_context dev);
|
||||
void moisture_close(moisture_context dev);
|
||||
|
||||
/**
|
||||
* Get Moisture function.
|
||||
@ -66,7 +66,7 @@ void grovemoisture_close(grovemoisture_context dev);
|
||||
* @param moisture pointer that will be used to store the
|
||||
* output value from the sensor
|
||||
*/
|
||||
upm_result_t grovemoisture_get_moisture(grovemoisture_context dev,
|
||||
upm_result_t moisture_get_moisture(moisture_context dev,
|
||||
int* moisture);
|
||||
|
||||
#ifdef __cplusplus
|
@ -28,23 +28,24 @@
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief Grove Moisture Sensor library
|
||||
* @brief Moisture Sensor library
|
||||
* @defgroup grovemoisture libupm-grovemoisture
|
||||
* @ingroup seeed analog liquid eak hak
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library grovemoisture
|
||||
* @sensor grovemoisture
|
||||
* @comname Grove Moisture Sensor
|
||||
* @library moisture
|
||||
* @sensor moisture
|
||||
* @comname Moisture Sensor
|
||||
* @altname Grove Moisture Sensor
|
||||
* @type liquid
|
||||
* @man seeed
|
||||
* @con analog
|
||||
* @kit eak hak
|
||||
*
|
||||
* @brief API for the Grove Moisture Sensor
|
||||
* @brief API for the Moisture Sensor
|
||||
*
|
||||
* UPM module for the Grove Moisture Sensor.
|
||||
* UPM module for the Moisture Sensor.
|
||||
* This sensor can be used to detect the moisture content
|
||||
* of soil or whether there is water around the sensor.
|
||||
* As the moisture content increases, so does the value that is read.
|
||||
@ -52,20 +53,20 @@ namespace upm {
|
||||
* nor to be used outdoors.
|
||||
*
|
||||
* @image html grovemoisture.jpg
|
||||
* @snippet grovemoisture.cxx Interesting
|
||||
* @snippet moisture.cxx Interesting
|
||||
*/
|
||||
class GroveMoisture {
|
||||
class Moisture {
|
||||
public:
|
||||
/**
|
||||
* Grove analog moisture sensor constructor
|
||||
* Analog moisture sensor constructor
|
||||
*
|
||||
* @param pin Analog pin to use
|
||||
*/
|
||||
GroveMoisture(int pin);
|
||||
Moisture(int pin);
|
||||
/**
|
||||
* GroveMoisture destructor
|
||||
* Moisture destructor
|
||||
*/
|
||||
~GroveMoisture();
|
||||
~Moisture();
|
||||
/**
|
||||
* Gets the moisture value from the sensor
|
||||
*
|
@ -30,42 +30,42 @@
|
||||
* This file implements the Function Table Interface (FTI) for this sensor
|
||||
*/
|
||||
|
||||
const char upm_grovemoisture_name[] = "Grove Moisture";
|
||||
const char upm_grovemoisture_description[] = "Analog Grove Moisture Sensor";
|
||||
const upm_protocol_t upm_grovemoisture_protocol[] = {UPM_ANALOG};
|
||||
const upm_sensor_t upm_grovemoisture_category[] = {UPM_MOISTURE};
|
||||
const char upm_moisture_name[] = "Moisture";
|
||||
const char upm_moisture_description[] = "Analog Moisture Sensor";
|
||||
const upm_protocol_t upm_moisture_protocol[] = {UPM_ANALOG};
|
||||
const upm_sensor_t upm_moisture_category[] = {UPM_MOISTURE};
|
||||
|
||||
// forward declarations
|
||||
const void* upm_grovemoisture_get_ft(upm_sensor_t sensor_type);
|
||||
void* upm_grovemoisture_init_name();
|
||||
void upm_grovemoisture_close(void* dev);
|
||||
upm_result_t upm_grovemoisture_get_moisture(void* dev, int* moisture);
|
||||
const void* upm_moisture_get_ft(upm_sensor_t sensor_type);
|
||||
void* upm_moisture_init_name();
|
||||
void upm_moisture_close(void* dev);
|
||||
upm_result_t upm_moisture_get_moisture(void* dev, int* moisture);
|
||||
|
||||
|
||||
const upm_sensor_descriptor_t upm_grovemoisture_get_descriptor (){
|
||||
const upm_sensor_descriptor_t upm_moisture_get_descriptor (){
|
||||
upm_sensor_descriptor_t usd;
|
||||
usd.name = upm_grovemoisture_name;
|
||||
usd.description = upm_grovemoisture_description;
|
||||
usd.name = upm_moisture_name;
|
||||
usd.description = upm_moisture_description;
|
||||
usd.protocol_size = 1;
|
||||
usd.protocol = upm_grovemoisture_protocol;
|
||||
usd.protocol = upm_moisture_protocol;
|
||||
usd.category_size = 1;
|
||||
usd.category = upm_grovemoisture_category;
|
||||
usd.category = upm_moisture_category;
|
||||
return usd;
|
||||
}
|
||||
|
||||
static const upm_sensor_ft ft =
|
||||
{
|
||||
.upm_sensor_init_name = &upm_grovemoisture_init_name,
|
||||
.upm_sensor_close = &upm_grovemoisture_close,
|
||||
.upm_sensor_get_descriptor = &upm_grovemoisture_get_descriptor
|
||||
.upm_sensor_init_name = &upm_moisture_init_name,
|
||||
.upm_sensor_close = &upm_moisture_close,
|
||||
.upm_sensor_get_descriptor = &upm_moisture_get_descriptor
|
||||
};
|
||||
|
||||
static const upm_moisture_ft mft =
|
||||
{
|
||||
.upm_moisture_sensor_get_moisture = &upm_grovemoisture_get_moisture
|
||||
.upm_moisture_sensor_get_moisture = &upm_moisture_get_moisture
|
||||
};
|
||||
|
||||
const void* upm_grovemoisture_get_ft(upm_sensor_t sensor_type){
|
||||
const void* upm_moisture_get_ft(upm_sensor_t sensor_type){
|
||||
if(sensor_type == UPM_MOISTURE){
|
||||
return &mft;
|
||||
}
|
||||
@ -75,14 +75,14 @@ const void* upm_grovemoisture_get_ft(upm_sensor_t sensor_type){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* upm_grovemoisture_init_name(){
|
||||
void* upm_moisture_init_name(){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void upm_grovemoisture_close(void* dev){
|
||||
grovemoisture_close((grovemoisture_context)dev);
|
||||
void upm_moisture_close(void* dev){
|
||||
moisture_close((moisture_context)dev);
|
||||
}
|
||||
|
||||
upm_result_t upm_grovemoisture_get_moisture(void* dev, int* moisture){
|
||||
return grovemoisture_get_moisture((grovemoisture_context)dev, moisture);
|
||||
upm_result_t upm_moisture_get_moisture(void* dev, int* moisture){
|
||||
return moisture_get_moisture((moisture_context)dev, moisture);
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_grovemoisture
|
||||
%module pyupm_moisture
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "grovemoisture.hpp"
|
||||
%include "moisture.hpp"
|
||||
%{
|
||||
#include "grovemoisture.hpp"
|
||||
%}
|
||||
#include "moisture.hpp"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user