mirror of
https://github.com/eclipse/upm.git
synced 2025-07-08 21:01:11 +03:00
Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
cde747439f | |||
dfc7a710d4 | |||
130cb822e4 | |||
c057fa6708 | |||
c6ad8cb5ee | |||
024b43dfa3 | |||
6667646d32 | |||
e1e9067744 | |||
c4656bf8ba | |||
232089f400 | |||
09144e712b | |||
2d94c2ed90 | |||
91652a2da5 | |||
929244b27a | |||
9a4f0cae0c | |||
402de082d3 | |||
ad275e1d41 | |||
d4559878df | |||
971cb4ab51 | |||
a2698fd560 | |||
11e14a891f | |||
803f9a9838 | |||
7bc9ef0150 | |||
72e8629d72 | |||
cdc33ceb9f | |||
54771e63c1 | |||
fde727b601 | |||
68091dcf43 | |||
1630ebfca4 | |||
1aa748e3d6 | |||
b3991979ad | |||
3eb3a0b825 | |||
9be920dbcd | |||
601d25cebc | |||
c900743f8d | |||
2b4e43281f | |||
630d12d963 | |||
8da9f28157 | |||
aab0c5afe2 | |||
0589f445f0 | |||
d33e7e532e | |||
c63692b5fd | |||
2f31aede0e | |||
33471436bf | |||
ee27485218 | |||
6bc22dcee2 | |||
ae9b8fb13e | |||
1dd5cbb445 | |||
a3a1fdc81b | |||
1f954a8cbf | |||
8f6442e9c7 | |||
f2ad2c5679 | |||
d03de942c5 |
@ -15,7 +15,7 @@ compiler:
|
||||
- clang
|
||||
- gcc
|
||||
install:
|
||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-dev/swig
|
||||
- sudo add-apt-repository --yes ppa:rosmo/swig3.0.7
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y --force-yes -qq swig3.0 git
|
||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||
@ -36,7 +36,7 @@ script:
|
||||
- sudo make install
|
||||
- sudo ldconfig
|
||||
# Build/install UPM
|
||||
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA -DBUILDTESTS=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
|
||||
- cd $UPM_ROOT && mkdir $UPM_BUILD && cd $_ && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDTESTS=ON -DBUILDFTI=ON .. && sudo make install && sudo ldconfig && ctest --output-on-failure -E examplenames_js
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
|
@ -8,13 +8,12 @@ option (BUILDFTI "Build Funtion Table Interface (FTI) in C sensor libraries" OFF
|
||||
option (BUILDSWIGPYTHON "Build swig python modules" ON)
|
||||
option (BUILDSWIGNODE "Build swig node modules" ON)
|
||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||
option (BUILDEXAMPLES "Build C/C++ example binaries" OFF)
|
||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||
option (BUILDEXAMPLES "Build C/C++/JAVA examples" OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (NPM "Generate NPM/GYP tarballs" OFF)
|
||||
option (BUILDTESTS "Generate check-ups for upm" OFF)
|
||||
option (WERROR "Make all warnings into errors." OFF)
|
||||
option (WERROR "Make all warnings into errors." ON)
|
||||
|
||||
# Warn if building in source root
|
||||
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
|
||||
@ -71,6 +70,7 @@ include (CheckCXXCompilerFlag)
|
||||
# This function checks to see if each flag is supported
|
||||
# by the compiler before setting the compile option.
|
||||
function (upm_add_compile_flags compiler)
|
||||
set (_TMP_COMPILER_FLAGS "")
|
||||
# Iterate the flags, check if supported
|
||||
foreach (flag ${ARGN})
|
||||
# Check if this compile flag is supported
|
||||
@ -85,15 +85,17 @@ function (upm_add_compile_flags compiler)
|
||||
endforeach (flag ${ARGN})
|
||||
|
||||
# Set the variable in the parent scope
|
||||
set (CMAKE_${compiler}_FLAGS ${_TMP_COMPILER_FLAGS} PARENT_SCOPE)
|
||||
set (CMAKE_${compiler}_FLAGS "${CMAKE_${compiler}_FLAGS} ${_TMP_COMPILER_FLAGS}" PARENT_SCOPE)
|
||||
endfunction ()
|
||||
|
||||
# Compiler flags common to both C and CXX
|
||||
set (C_CXX_WARNING_FLAGS -Wall)
|
||||
# Enable -Wall
|
||||
# GCC-6 added -Wmisleading-indentation to -Wall, skip these for now
|
||||
set (C_CXX_WARNING_FLAGS -Wall -Wno-misleading-indentation -Wno-strict-aliasing)
|
||||
|
||||
# Errors as warnings?
|
||||
# Warnings as errors?
|
||||
if (WERROR)
|
||||
list (APPEND C_CXX_WARNING_FLAGS -Werror)
|
||||
set (C_CXX_WARNING_FLAGS "-Werror ${C_CXX_WARNING_FLAGS}")
|
||||
message (STATUS "Warnings as errors enabled (-Werror), disable with -DWERROR=off")
|
||||
endif (WERROR)
|
||||
|
||||
@ -136,6 +138,13 @@ if (BUILDSWIGNODE)
|
||||
find_package (Node REQUIRED)
|
||||
endif (BUILDSWIGNODE)
|
||||
|
||||
# Find JAVA/JNI
|
||||
if (BUILDSWIGJAVA)
|
||||
find_package (Java REQUIRED)
|
||||
find_package (JNI REQUIRED)
|
||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
||||
endif (BUILDSWIGJAVA)
|
||||
|
||||
# Find swig if any wrapper is enabled
|
||||
if (BUILDSWIGPYTHON OR BUILDSWIGNODE OR BUILDSWIGJAVA)
|
||||
find_package (SWIG 3.0.5 REQUIRED)
|
||||
@ -184,7 +193,7 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
# If git_describe fails, use a dirty version
|
||||
if (${VERSION} MATCHES -NOTFOUND)
|
||||
set (VERSION "v1.0.0-dirty")
|
||||
set (VERSION "v1.0.2")
|
||||
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
|
||||
"${VERSION}). Check that git is installed and this is a valid git repo.")
|
||||
endif ()
|
||||
@ -378,7 +387,6 @@ endif()
|
||||
|
||||
if (RPM)
|
||||
message (STATUS "RPM packaging enabled for ${DETECTED_ARCH}")
|
||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||
set(CPACK_GENERATOR "RPM")
|
||||
set(CPACK_PACKAGE_NAME "upm")
|
||||
set(upm_PACKAGE_ON_TAG ".")
|
||||
@ -415,7 +423,8 @@ if(BUILDEXAMPLES)
|
||||
endif(BUILDCPP)
|
||||
endif()
|
||||
|
||||
if(BUILDJAVAEXAMPLES)
|
||||
# Build java examples
|
||||
if(BUILDSWIGJAVA AND BUILDEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
|
@ -80,14 +80,10 @@ Building documentation
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDDOC=ON
|
||||
~~~~~~~~~~~~~
|
||||
Build C++ example binaries
|
||||
Build C/C++/JAVA examples
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDEXAMPLES=ON
|
||||
~~~~~~~~~~~~~
|
||||
Build Java examples
|
||||
~~~~~~~~~~~~~
|
||||
-DBUILDJAVAEXAMPLES=ON
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
If you intend to turn on all the options and build everything at once
|
||||
(C++, Java, Node, Python and Documentation) you will have to edit the
|
||||
|
@ -4,6 +4,22 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### v1.0.2
|
||||
|
||||
* Minor cmake changes for Java builds and Java examples are now toggled with
|
||||
the same BUILDEXAMPLES cmake switch
|
||||
* Made some improvements in the utilities class for our C drivers
|
||||
* Fixed issue with some drivers not being usable on subplatforms due to pin
|
||||
numbers using uint8 type
|
||||
* New sensors: ims, ecezo, mb704x, rf22
|
||||
|
||||
### v1.0.1
|
||||
|
||||
* Warnings as errors enabled for C/CXX (fixed warnings from -Wall and others)
|
||||
* Fix for C/CXX compile flag append issue #485
|
||||
* C sensor libraries for: my9221, otp538u, guvas12d, ppd42ns
|
||||
* New sensor: ms5803
|
||||
|
||||
### v1.0.0
|
||||
|
||||
* Added approximately 50 C sources for UPM drivers that can be used on both
|
||||
|
BIN
docs/images/ims.png
Normal file
BIN
docs/images/ims.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
BIN
docs/images/rf22.jpg
Normal file
BIN
docs/images/rf22.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
@ -24,6 +24,7 @@ hcsr04.cxx HCSR04Sample.java hcsr04.js hcsr04.py
|
||||
hm11.cxx HM11Sample.java hm11.js hm11.py
|
||||
hmc5883l.cxx Hmc5883lSample.java hmc5883l.js hmc5883l.py
|
||||
htu21d.cxx HTU21DSample.java htu21d.js htu21d.py
|
||||
ims.cxx IMS_Example.java ims.js ims.py
|
||||
itg3200.cxx Itg3200Sample.java itg3200.js itg3200.py
|
||||
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java jhd1313m1-lcd.js jhd1313m1-lcd.py
|
||||
joystick12.cxx Joystick12Sample.java joystick12.js joystick12.py
|
||||
|
@ -1,3 +1,7 @@
|
||||
# Selectively disable certain warnings for the examples
|
||||
# nrf examples flag -Wtautological-compare
|
||||
set (CXX_DISABLED_WARNINGS -Wno-tautological-compare)
|
||||
|
||||
# Extract module name from non-standard example name
|
||||
macro(get_module_name example_name module_name)
|
||||
string(LENGTH ${example_name} length)
|
||||
@ -32,6 +36,15 @@ macro(add_custom_example example_bin example_src example_module_list)
|
||||
if (found_all_modules)
|
||||
add_executable (${example_bin} ${example_src})
|
||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
# Disable warnings from CXX_DISABLED_WARNINGS
|
||||
foreach(flag ${CXX_DISABLED_WARNINGS})
|
||||
compiler_flag_supported(CXX is_supported ${flag})
|
||||
if (is_supported)
|
||||
target_compile_options(${example_bin} PRIVATE "${flag}")
|
||||
endif(is_supported)
|
||||
endforeach(flag ${CXX_DISABLED_WARNINGS})
|
||||
|
||||
foreach (module ${example_module_list})
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
include_directories (${module_dir})
|
||||
@ -55,11 +68,6 @@ macro(add_example example_name)
|
||||
get_module_name(${example_name} module_name)
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
||||
|
||||
# nrf examples can flag a warning, make sure this isn't an error, currently
|
||||
# this is done for all examples
|
||||
set_source_files_properties(${example_src}
|
||||
PROPERTIES COMPILE_FLAGS -Wno-tautological-compare)
|
||||
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
||||
AND EXISTS ${module_dir}
|
||||
AND IS_DIRECTORY ${module_dir})
|
||||
@ -313,45 +321,51 @@ add_example (hka5)
|
||||
add_example (dfrorp)
|
||||
add_example (dfrec)
|
||||
add_example (sht1x)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
add_example (rf22-server)
|
||||
add_example (rf22-client)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
add_custom_example (groveled-multi-example groveled-multi.cxx grove)
|
||||
add_custom_example (lcm1602-i2c-example lcm1602-i2c.cxx lcd)
|
||||
add_custom_example (lcm1602-parallel-example lcm1602-parallel.cxx lcd)
|
||||
add_custom_example (jhd1313m1-lcd-example jhd1313m1-lcd.cxx lcd)
|
||||
add_custom_example (es08a-example es08a.cxx servo)
|
||||
add_custom_example (ssd1306-oled-example ssd1306-oled.cxx lcd)
|
||||
add_custom_example (ssd1308-oled-example ssd1308-oled.cxx lcd)
|
||||
add_custom_example (ssd1327-oled-example ssd1327-oled.cxx lcd)
|
||||
add_custom_example (sainsmartks-example sainsmartks.cxx lcd)
|
||||
add_custom_example (eboled-example eboled.cxx lcd)
|
||||
add_custom_example (mpu60x0-example mpu60x0.cxx mpu9150)
|
||||
add_custom_example (ak8975-example ak8975.cxx mpu9150)
|
||||
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
||||
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
||||
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
|
||||
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmpx8x;bmp280")
|
||||
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bmp280")
|
||||
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmpx8x;bmp280")
|
||||
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||
add_custom_example (bme280-example bme280.cxx bmp280)
|
||||
add_custom_example (bma250e-example bma250e.cxx bmx055)
|
||||
add_custom_example (bmg160-example bmg160.cxx bmx055)
|
||||
add_custom_example (bmm150-example bmm150.cxx bmx055)
|
||||
add_custom_example (bmc150-example bmc150.cxx bmx055)
|
||||
add_custom_example (bmi055-example bmi055.cxx bmx055)
|
||||
add_custom_example (groveled-multi-example-cxx groveled-multi.cxx grove)
|
||||
add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcd)
|
||||
add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcd)
|
||||
add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx lcd)
|
||||
add_custom_example (es08a-example-cxx es08a.cxx servo)
|
||||
add_custom_example (ssd1306-oled-example-cxx ssd1306-oled.cxx lcd)
|
||||
add_custom_example (ssd1308-oled-example-cxx ssd1308-oled.cxx lcd)
|
||||
add_custom_example (ssd1327-oled-example-cxx ssd1327-oled.cxx lcd)
|
||||
add_custom_example (sainsmartks-example-cxx sainsmartks.cxx lcd)
|
||||
add_custom_example (eboled-example-cxx eboled.cxx lcd)
|
||||
add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
|
||||
add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)
|
||||
add_custom_example (mpu9250-example-cxx mpu9250.cxx mpu9150)
|
||||
add_custom_example (groveledbar-example-cxx groveledbar.cxx my9221)
|
||||
add_custom_example (grovecircularled-example-cxx grovecircularled.cxx my9221)
|
||||
add_custom_example (temperature-sensor-example-cxx temperature-sensor.cxx "si7005;bmpx8x;bmp280")
|
||||
add_custom_example (humidity-sensor-example-cxx humidity-sensor.cxx "si7005;bmp280")
|
||||
add_custom_example (pressure-sensor-example-cxx pressure-sensor.cxx "bmpx8x;bmp280")
|
||||
add_custom_example (co2-sensor-example-cxx co2-sensor.cxx "t6713")
|
||||
add_custom_example (adc-example-cxx adc-sensor.cxx "ads1x15")
|
||||
add_custom_example (light-sensor-example-cxx light-sensor.cxx "si1132;max44009")
|
||||
add_custom_example (light-controller-example-cxx light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||
add_custom_example (bme280-example-cxx bme280.cxx bmp280)
|
||||
add_custom_example (bma250e-example-cxx bma250e.cxx bmx055)
|
||||
add_custom_example (bmg160-example-cxx bmg160.cxx bmx055)
|
||||
add_custom_example (bmm150-example-cxx bmm150.cxx bmx055)
|
||||
add_custom_example (bmc150-example-cxx bmc150.cxx bmx055)
|
||||
add_custom_example (bmi055-example-cxx bmi055.cxx bmx055)
|
||||
if (OPENZWAVE_FOUND)
|
||||
include_directories(${OPENZWAVE_INCLUDE_DIRS})
|
||||
|
||||
add_custom_example (ozwdump-example ozwdump.cxx ozw)
|
||||
add_custom_example (aeotecss6-example aeotecss6.cxx ozw)
|
||||
add_custom_example (aeotecsdg2-example aeotecsdg2.cxx ozw)
|
||||
add_custom_example (aeotecdw2e-example aeotecdw2e.cxx ozw)
|
||||
add_custom_example (aeotecdsb09104-example aeotecdsb09104.cxx ozw)
|
||||
add_custom_example (tzemt400-example tzemt400.cxx ozw)
|
||||
add_custom_example (ozwdump-example-cxx ozwdump.cxx ozw)
|
||||
add_custom_example (aeotecss6-example-cxx aeotecss6.cxx ozw)
|
||||
add_custom_example (aeotecsdg2-example-cxx aeotecsdg2.cxx ozw)
|
||||
add_custom_example (aeotecdw2e-example-cxx aeotecdw2e.cxx ozw)
|
||||
add_custom_example (aeotecdsb09104-example-cxx aeotecdsb09104.cxx ozw)
|
||||
add_custom_example (tzemt400-example-cxx tzemt400.cxx ozw)
|
||||
endif()
|
||||
add_custom_example (nmea_gps_i2c_example-cxx nmea_gps_i2c.cxx nmea_gps)
|
||||
|
@ -23,7 +23,7 @@ void printState(upm::ILightController *lightController)
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int status = 0;
|
||||
upm::ILightController* lightController;
|
||||
upm::ILightController* lightController = nullptr;
|
||||
|
||||
try {
|
||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||
|
81
examples/c++/ecezo.cxx
Normal file
81
examples/c++/ecezo.cxx
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 <upm_utilities.h>
|
||||
#include <ecezo.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
upm::ECEZO *sensor = new upm::ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// upm::ECEZO *sensor = new upm::ECEZO(0, 0x64, true);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
sensor->update();
|
||||
|
||||
cout << "EC "
|
||||
<< sensor->getEC()
|
||||
<< " uS/cm, TDS "
|
||||
<< sensor->getTDS()
|
||||
<< " mg/L, Salinity "
|
||||
<< sensor->getSalinity()
|
||||
<< " PSS-78, SG "
|
||||
<< sensor->getSG()
|
||||
<< endl;
|
||||
|
||||
upm_delay(5);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -33,7 +33,6 @@ bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define GUVAS12D_AREF 5.0
|
||||
#define SAMPLES_PER_QUERY 1024
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
@ -46,8 +45,8 @@ int main()
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// The was tested with the Grove UV Sensor module.
|
||||
// It has a sensing range from between 200-400nm. It's strongest
|
||||
// This was tested with the Grove UV Sensor module.
|
||||
// It has a sensing range from between 240-370nm. It's strongest
|
||||
// response is around 320-360nm.
|
||||
|
||||
// Instantiate a GUVAS12D on analog pin A0
|
||||
@ -57,9 +56,10 @@ int main()
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "AREF: " << GUVAS12D_AREF
|
||||
<< ", Voltage value (higher means more UV): "
|
||||
<< volts->value(GUVAS12D_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
cout << "Volts: " << volts->volts()
|
||||
<< ", Intensity: " << volts->intensity()
|
||||
<< " mW/m^2"
|
||||
<< endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ void sendCommand(upm::HM11* ble, char *cmd)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
char buffer[BUFSIZ];
|
||||
// Instantiate a HM11 BLE Module on UART 0
|
||||
|
||||
upm::HM11* ble = new upm::HM11(0);
|
||||
|
69
examples/c++/ims.cxx
Normal file
69
examples/c++/ims.cxx
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ims.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||
upm::IMS sensor(0);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
std::cout << "Version: "
|
||||
<< sensor.get_version()
|
||||
<< " light: "
|
||||
<< sensor.get_light()
|
||||
<< " moisture: "
|
||||
<< sensor.get_moisture()
|
||||
<< " temp: "
|
||||
<< sensor.get_temperature()
|
||||
<< " C"
|
||||
<< std::endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -48,7 +48,6 @@ main(int argc, char **argv)
|
||||
sensor = new upm::LoL();
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
unsigned char *buffer;
|
||||
//buffer = sensor->getFramebuffer();
|
||||
int x = 0, y = 0;
|
||||
while (!is_running) {
|
||||
|
70
examples/c++/mb704x.cxx
Normal file
70
examples/c++/mb704x.cxx
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 <upm_utilities.h>
|
||||
#include <mb704x.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
upm::MB704X *sensor = new upm::MB704X();
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Range: "
|
||||
<< sensor->getRange()
|
||||
<< " cm"
|
||||
<< endl;
|
||||
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
78
examples/c++/ms5803.cxx
Normal file
78
examples/c++/ms5803.cxx
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ms5803.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MS5803 instance using i2c bus 0 and default address
|
||||
upm::MS5803 *sensor = new upm::MS5803(0);
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid
|
||||
// pin for CS (or -1 if you are using a hw pin you have no control
|
||||
// over, like edison):
|
||||
// MS5803(0, -1, 9);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
cout << "Temperature: "
|
||||
<< sensor->getTemperature()
|
||||
<< " C, "
|
||||
<< "Pressure: "
|
||||
<< sensor->getPressure()
|
||||
<< " mbar"
|
||||
<< endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -80,7 +80,6 @@ Used to test the UART TX characteristic notification
|
||||
static uart_over_ble_t uart_over_ble;
|
||||
static uint8_t uart_buffer[20];
|
||||
static uint8_t uart_buffer_len = 0;
|
||||
static uint8_t dummychar = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
|
@ -45,14 +45,17 @@ int main ()
|
||||
//! [Interesting]
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
upm::PPD42NS* dust = new upm::PPD42NS(8);
|
||||
upm::dustData data;
|
||||
cout << "This program will give readings every 30 seconds until you stop it" << endl;
|
||||
ppd42ns_dust_data data;
|
||||
cout << "This program will give readings every 30 seconds until "
|
||||
<< "you stop it"
|
||||
<< endl;
|
||||
while (shouldRun)
|
||||
{
|
||||
data = dust->getData();
|
||||
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
|
||||
cout << "Ratio: " << data.ratio << endl;
|
||||
cout << "Concentration: " << data.concentration << endl;
|
||||
cout << endl;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
|
72
examples/c++/rf22-client.cxx
Normal file
72
examples/c++/rf22-client.cxx
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Kiveisha Yevgeniy
|
||||
* Copyright (c) 2015-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 <iostream>
|
||||
#include <signal.h>
|
||||
#include "rf22.hpp"
|
||||
|
||||
bool amWorking = true;
|
||||
|
||||
void
|
||||
sig_handler (int signo) {
|
||||
if (signo == SIGINT) {
|
||||
amWorking = false;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
int
|
||||
main (int argc, char ** argv) {
|
||||
// SPI bus 0, CS pin 10, INTR pin 2
|
||||
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
|
||||
|
||||
if (!rf22->init()) {
|
||||
std::cout << "RF22 init failed" << std::endl;
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
uint8_t buf[RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
signal (SIGINT, sig_handler);
|
||||
while (amWorking) {
|
||||
std::cout << "Sending to rf22_server" << std::endl;
|
||||
// Send a message to rf22_server
|
||||
rf22->send(data, sizeof(data));
|
||||
rf22->waitPacketSent();
|
||||
// Now wait for a reply
|
||||
|
||||
rf22->waitAvailableTimeout(1000000);
|
||||
|
||||
if (rf22->recv(buf, &len)) {
|
||||
std::cout << "got response: " << (char*)buf << std::endl;
|
||||
} else {
|
||||
std::cout << "!!! NO RESPONSE !!!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Exit 'rfm22-client'" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
73
examples/c++/rf22-server.cxx
Normal file
73
examples/c++/rf22-server.cxx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Kiveisha Yevgeniy
|
||||
* Copyright (c) 2015-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 <iostream>
|
||||
#include <signal.h>
|
||||
#include "rf22.hpp"
|
||||
|
||||
bool amWorking = true;
|
||||
|
||||
void
|
||||
sig_handler (int signo) {
|
||||
if (signo == SIGINT) {
|
||||
amWorking = false;
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
int
|
||||
main (int argc, char ** argv) {
|
||||
// SPI bus 0, CS pin 10, INTR pin 2
|
||||
upm::RF22* rf22 = new upm::RF22 (0, 10, 2);
|
||||
|
||||
if (!rf22->init()) {
|
||||
std::cout << "RF22 init failed" << std::endl;
|
||||
return 0x1;
|
||||
}
|
||||
|
||||
uint8_t buf[RF22_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
signal (SIGINT, sig_handler);
|
||||
while (amWorking) {
|
||||
// rf22->waitAvailable();
|
||||
rf22->waitAvailableTimeout (500);
|
||||
|
||||
// Should be a message for us now
|
||||
if (rf22->recv(buf, &len)) {
|
||||
std::cout << "got request: " << (char*)buf << std::endl;
|
||||
|
||||
// Send a reply
|
||||
uint8_t data[] = "And hello back to you";
|
||||
rf22->send(data, sizeof(data));
|
||||
rf22->waitPacketSent();
|
||||
} else {
|
||||
// Do whatever you need.
|
||||
}
|
||||
}
|
||||
|
||||
delete rf22;
|
||||
std::cout << "Exit 'rfm22-server'" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
@ -44,8 +44,6 @@ sig_handler(int signo)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
float voltage = 0;
|
||||
|
||||
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
|
||||
sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
upm::TSL2561 *sensor = NULL;
|
||||
int loopCount = 100;
|
||||
|
||||
|
@ -23,7 +23,7 @@ macro(add_custom_example example_bin example_src example_module_list)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
if (MODULE_LIST)
|
||||
list(FIND MODULE_LIST ${module}-c index)
|
||||
list(FIND MODULE_LIST ${module} index)
|
||||
if (${index} EQUAL -1)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
@ -132,6 +132,15 @@ add_example (linefinder)
|
||||
add_example (uln200xa)
|
||||
add_example (mma7660)
|
||||
add_example (buzzer)
|
||||
add_example (ppd42ns)
|
||||
add_example (guvas12d)
|
||||
add_example (otp538u)
|
||||
add_example (button)
|
||||
add_example (my9221)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
@ -139,3 +148,4 @@ add_custom_example (lcm1602-i2c-example-c lcm1602-i2c.c lcm1602)
|
||||
add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602)
|
||||
add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220)
|
||||
add_custom_example (md-stepper-example-c md-stepper.c md)
|
||||
add_custom_example (button_intr-example-c button_intr.c button)
|
||||
|
59
examples/c/button.c
Normal file
59
examples/c/button.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Authors: Abhishek Malik <abhishek.malik@intel.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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "button.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int counter;
|
||||
|
||||
void button_isr(void *arg){
|
||||
counter++;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
counter = 0;
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
button_context dev = button_init(2);
|
||||
|
||||
button_install_isr(dev, MRAA_GPIO_EDGE_RISING, button_isr, NULL);
|
||||
while(1){
|
||||
printf("Interrupts: %d\n", counter);
|
||||
upm_delay(3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
54
examples/c/button_intr.c
Normal file
54
examples/c/button_intr.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Authors: Abhishek Malik <abhishek.malik@intel.com>
|
||||
* Copyright (c) 2014 - 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "button.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "mraa.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
perror("Failed to initialize mraa\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
button_context dev = button_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(button_get_value(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
85
examples/c/ecezo.c
Normal file
85
examples/c/ecezo.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 <upm_utilities.h>
|
||||
#include <ecezo.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
ecezo_context sensor = ecezo_uart_init(0, 9600);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// ecezo_context sensor = ecezo_i2c_init(0, 0x64);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("ecezo_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
if (ecezo_update(sensor))
|
||||
{
|
||||
printf("ecezo_update() failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("EC %f uS/cm, TDS %f mg/L, Salinity %f PSS-78, SG %f\n",
|
||||
ecezo_get_ec(sensor),
|
||||
ecezo_get_tds(sensor),
|
||||
ecezo_get_salinity(sensor),
|
||||
ecezo_get_sg(sensor));
|
||||
}
|
||||
|
||||
upm_delay(5);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
ecezo_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
89
examples/c/guvas12d.c
Normal file
89
examples/c/guvas12d.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <guvas12d.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define GUVAS12D_AREF 5.0
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// This was tested with the Grove UV Sensor module.
|
||||
// It has a sensing range from between 240-370nm. It's strongest
|
||||
// response is around 320-360nm.
|
||||
|
||||
// Instantiate a GUVAS12D on analog pin A0
|
||||
guvas12d_context uv = guvas12d_init(0, GUVAS12D_AREF);
|
||||
|
||||
if (!uv)
|
||||
{
|
||||
printf("guvas12d_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The higher the voltage the more intense the UV radiation.
|
||||
while (shouldRun)
|
||||
{
|
||||
float volts = 0;
|
||||
float intensity = 0;
|
||||
|
||||
if (guvas12d_get_volts(uv, &volts))
|
||||
{
|
||||
printf("guvas12d_get_volts() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (guvas12d_get_intensity(uv, &intensity))
|
||||
{
|
||||
printf("guvas12d_get_intensity() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Volts: %f, Intensity %f mW/m^2\n", volts, intensity);
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
guvas12d_close(uv);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
75
examples/c/ims.c
Normal file
75
examples/c/ims.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ims.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
ims_context* sensor = ims_init(0, IMS_ADDRESS_DEFAULT);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("ims_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Every second, sample the sensor outputs
|
||||
while (shouldRun)
|
||||
{
|
||||
uint16_t version, light, moisture, temp;
|
||||
|
||||
if (ims_get_version(sensor, &version) == UPM_SUCCESS &&
|
||||
ims_get_light(sensor, &light) == UPM_SUCCESS &&
|
||||
ims_get_moisture(sensor, &moisture) == UPM_SUCCESS &&
|
||||
ims_get_temperature(sensor, &temp) == UPM_SUCCESS)
|
||||
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
||||
version, light, moisture, temp/10.0);
|
||||
else
|
||||
break;
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
printf("Exiting\n");
|
||||
ims_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
77
examples/c/mb704x.c
Normal file
77
examples/c/mb704x.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 <upm_utilities.h>
|
||||
#include <mb704x.h>
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor on i2c bus 0, address 112.
|
||||
mb704x_context sensor = mb704x_init(0, 112);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("mb704x_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// this will take about 1 second to complete
|
||||
int range = mb704x_get_range(sensor);
|
||||
if (range < 0)
|
||||
{
|
||||
printf("Error getting range.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Range: %d cm\n", range);
|
||||
}
|
||||
|
||||
upm_delay_ms(500);
|
||||
}
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
mb704x_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
79
examples/c/ms5803.c
Normal file
79
examples/c/ms5803.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "ms5803.h"
|
||||
#include "upm_utilities.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MS5803 on analog I2C bus 0, at the default address
|
||||
ms5803_context sensor = ms5803_init(0, MS5803_DEFAULT_I2C_ADDR, -1);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("ms5803_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Every second, sample the sensor and output the pressure and
|
||||
// temperature
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
if (ms5803_update(sensor))
|
||||
{
|
||||
printf("ms5803_update() failed\n");
|
||||
}
|
||||
|
||||
printf("Temperature: %f C, Pressure = %f mbar\n",
|
||||
ms5803_get_temperature(sensor),
|
||||
ms5803_get_pressure(sensor));
|
||||
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
ms5803_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
89
examples/c/my9221.c
Normal file
89
examples/c/my9221.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <my9221.h>
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
|
||||
// clock. We only use a single instance.
|
||||
my9221_context leds = my9221_init(8, 9, 1);
|
||||
|
||||
if (!leds)
|
||||
{
|
||||
printf("my9221_init() failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// count up
|
||||
printf("Counting up: ");
|
||||
for (int i=0; i<my9221_get_max_leds(leds); i++)
|
||||
{
|
||||
printf("%d ", i);
|
||||
my9221_clear_all(leds);
|
||||
my9221_set_led(leds, i, true);
|
||||
upm_delay_ms(100);
|
||||
}
|
||||
printf("\n");
|
||||
upm_delay_ms(100);
|
||||
|
||||
// count down
|
||||
printf("Counting down: ");
|
||||
for (int i=my9221_get_max_leds(leds) - 1; i>=0; i--)
|
||||
{
|
||||
printf("%d ", i);
|
||||
my9221_clear_all(leds);
|
||||
my9221_set_led(leds, i, true);
|
||||
upm_delay_ms(100);
|
||||
}
|
||||
printf("\n");
|
||||
upm_delay_ms(100);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
my9221_close(leds);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
81
examples/c/otp538u.c
Normal file
81
examples/c/otp538u.c
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
#include <otp538u.h>
|
||||
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define OTP538U_AREF 5.0
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a OTP538U on analog pins A0 and A1
|
||||
// A0 is used for the Ambient Temperature and A1 is used for the
|
||||
// Object temperature.
|
||||
otp538u_context temps = otp538u_init(0, 1, OTP538U_AREF);
|
||||
|
||||
// enable debugging if you would like
|
||||
// otp538u_set_debug(temps, true);
|
||||
|
||||
// Output ambient and object temperatures
|
||||
while (shouldRun)
|
||||
{
|
||||
float ambient = 0, object = 0;
|
||||
|
||||
if (otp538u_get_ambient_temperature(temps, &ambient))
|
||||
printf("otp538u_get_ambient_temperature() failed\n");
|
||||
else if (otp538u_get_object_temperature(temps, &object))
|
||||
printf("otp538u_get_object_temperature() failed\n");
|
||||
else
|
||||
printf("Ambient temp: %f C, Object temp: %f C\n",
|
||||
ambient, object);
|
||||
|
||||
printf("\n");
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
otp538u_close(temps);
|
||||
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
66
examples/c/ppd42ns.c
Normal file
66
examples/c/ppd42ns.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <ppd42ns.h>
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
ppd42ns_context dust = ppd42ns_init(8);
|
||||
|
||||
ppd42ns_dust_data data;
|
||||
printf("This program will give readings every 30 seconds until "
|
||||
"you stop it\n");
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
data = ppd42ns_get_data(dust);
|
||||
printf("Low pulse occupancy: %d\n", data.lowPulseOccupancy);
|
||||
printf("Ratio: %f\n", data.ratio);
|
||||
printf("Concentration: %f\n\n", data.concentration);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
ppd42ns_close(dust);
|
||||
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -156,6 +156,10 @@ add_example(HKA5_Example hka5)
|
||||
add_example(DFRORP_Example dfrorp)
|
||||
add_example(DFREC_Example dfrec)
|
||||
add_example(SHT1X_Example sht1x)
|
||||
add_example(MS5803_Example ms5803)
|
||||
add_example(ECEZO_Example ecezo)
|
||||
add_example(IMS_Example ims)
|
||||
add_example(MB704X_Example mb704x)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
|
60
examples/java/ECEZO_Example.java
Normal file
60
examples/java/ECEZO_Example.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import upm_ecezo.ECEZO;
|
||||
|
||||
public class ECEZO_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
ECEZO sensor = new ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// ECEZO sensor = new ECEZO(0, 0x64, true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
System.out.println("EC "
|
||||
+ sensor.getEC()
|
||||
+ " uS/cm, TDS "
|
||||
+ sensor.getTDS()
|
||||
+ " mg/L, Salinity "
|
||||
+ sensor.getSalinity()
|
||||
+ " PSS-78, SG "
|
||||
+ sensor.getSG());
|
||||
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
* Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015-2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -25,18 +26,20 @@
|
||||
public class GUVAS12DSample {
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
private static final float GUVAS12D_AREF = 5;
|
||||
private static final int SAMPLES_PER_QUERY = 1024;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate a GUVAS12D on analog pin A3
|
||||
upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(3);
|
||||
// Instantiate a GUVAS12D on analog pin A0
|
||||
upm_guvas12d.GUVAS12D volts = new upm_guvas12d.GUVAS12D(0,
|
||||
GUVAS12D_AREF);
|
||||
|
||||
while (true) {
|
||||
float value = volts.value(GUVAS12D_AREF, SAMPLES_PER_QUERY);
|
||||
|
||||
System.out.println("AREF: " + GUVAS12D_AREF
|
||||
+ ", Voltage value (higher means more UV): " + value);
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Volts: "
|
||||
+ volts.volts()
|
||||
+ ", Intensity: "
|
||||
+ volts.intensity()
|
||||
+ " mW/m^2");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
53
examples/java/IMS_Example.java
Normal file
53
examples/java/IMS_Example.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.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.
|
||||
*/
|
||||
|
||||
import upm_ims.IMS;
|
||||
|
||||
public class IMS_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a IMS instance using bus 0 and default i2c address
|
||||
IMS sensor = new IMS((short)0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Version: "
|
||||
+ sensor.get_version()
|
||||
+ " light: "
|
||||
+ sensor.get_light()
|
||||
+ " moisture: "
|
||||
+ sensor.get_moisture()
|
||||
+ " temp: "
|
||||
+ sensor.get_temperature()
|
||||
+ " C");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
48
examples/java/MB704X_Example.java
Normal file
48
examples/java/MB704X_Example.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import upm_mb704x.MB704X;
|
||||
|
||||
public class MB704X_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
MB704X sensor = new MB704X();
|
||||
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Range: "
|
||||
+ sensor.getRange()
|
||||
+ " cm");
|
||||
|
||||
Thread.sleep(500);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
56
examples/java/MS5803_Example.java
Normal file
56
examples/java/MS5803_Example.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import upm_ms5803.MS5803;
|
||||
|
||||
public class MS5803_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a MS5803 instance using bus 0 and default i2c address
|
||||
MS5803 sensor = new MS5803(0);
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// MS5803(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
System.out.println("Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C, Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " mbar");
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ public class PPD42NSSample {
|
||||
// ! [Interesting]
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
|
||||
upm_ppd42ns.dustData data;
|
||||
upm_ppd42ns.ppd42ns_dust_data data;
|
||||
|
||||
System.out.println("This program will give readings every 30 seconds until you stop it");
|
||||
|
||||
|
@ -22,11 +22,11 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
// Load UPM module
|
||||
var upm = require('jsupm_button');
|
||||
|
||||
// Create the button object using GPIO pin 0
|
||||
var button = new groveSensor.Button(0);
|
||||
var button = new upm.Button(0);
|
||||
|
||||
// Read the input and print, waiting one second between readings
|
||||
function readButtonValue() {
|
||||
|
59
examples/javascript/ecezo.js
Normal file
59
examples/javascript/ecezo.js
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_ecezo');
|
||||
|
||||
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
var sensor = new sensorObj.ECEZO(0, 9600, false);
|
||||
|
||||
// For I2C, assuming the device is configured for address 0x64 on
|
||||
// I2C bus 0, you could use something like:
|
||||
//
|
||||
// var sensor = new sensorObj.ECEZO(0, 0x64, true);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
console.log("EC "
|
||||
+ sensor.getEC()
|
||||
+ " uS/cm, TDS "
|
||||
+ sensor.getTDS()
|
||||
+ " mg/L, Salinity "
|
||||
+ sensor.getSalinity()
|
||||
+ " PSS-78, SG "
|
||||
+ sensor.getSG());
|
||||
|
||||
}, 5000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014-2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -24,27 +25,23 @@
|
||||
|
||||
var UVSensor = require('jsupm_guvas12d');
|
||||
|
||||
// Instantiate a UV sensor on analog pin A0
|
||||
var myUVSensor = new UVSensor.GUVAS12D(0);
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
var g_GUVAS12D_AREF = 5.0;
|
||||
var g_SAMPLES_PER_QUERY = 1024;
|
||||
|
||||
// Instantiate a UV sensor on analog pin A0
|
||||
var myUVSensor = new UVSensor.GUVAS12D(0, g_GUVAS12D_AREF);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
var outputStr = "AREF: " + g_GUVAS12D_AREF
|
||||
+ ", Voltage value (higher means more UV): "
|
||||
+ roundNum(myUVSensor.value(g_GUVAS12D_AREF, g_SAMPLES_PER_QUERY), 6);
|
||||
var outputStr = "Volts: "
|
||||
+ myUVSensor.volts()
|
||||
+ ", Intensity: "
|
||||
+ myUVSensor.intensity()
|
||||
+ " mW/m^2";
|
||||
|
||||
console.log(outputStr);
|
||||
}, 1000);
|
||||
|
||||
function roundNum(num, decimalPlaces)
|
||||
{
|
||||
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
|
||||
return (Math.round((num + extraNum) * (Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
|
||||
}
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
|
51
examples/javascript/ims.js
Normal file
51
examples/javascript/ims.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Author: Noel Eck <noel.eck@intel.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.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_ims');
|
||||
|
||||
// Instantiate a IMS instance using bus 0 and default i2c address
|
||||
var sensor = new sensorObj.IMS(0);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Version: "
|
||||
+ sensor.get_version()
|
||||
+ " light: "
|
||||
+ sensor.get_light()
|
||||
+ " moisture: "
|
||||
+ sensor.get_moisture()
|
||||
+ " temp: "
|
||||
+ sensor.get_temperature().toFixed(2)
|
||||
+ " C");
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -22,10 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
// Load UPM module
|
||||
var ledSensor = require('jsupm_led');
|
||||
|
||||
// Create the Grove LED object using GPIO pin 2
|
||||
// Create the LED object using GPIO pin 2
|
||||
var led = new ledSensor.Led(2);
|
||||
|
||||
// Print the name
|
||||
|
47
examples/javascript/mb704x.js
Normal file
47
examples/javascript/mb704x.js
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_mb704x');
|
||||
|
||||
// Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
// address 112)
|
||||
var sensor = new sensorObj.MB704X();
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
console.log("Range: "
|
||||
+ sensor.getRange()
|
||||
+ " cm");
|
||||
|
||||
}, 500);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -22,10 +22,10 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//Load Grove Moisture module
|
||||
//Load UPM module
|
||||
var moisture = require('jsupm_moisture');
|
||||
|
||||
// Instantiate a Grove Moisture sensor on analog pin A0
|
||||
// Instantiate a Moisture sensor on analog pin A0
|
||||
var myMoistureObj = new moisture.Moisture(0);
|
||||
|
||||
// Values (approximate):
|
||||
@ -33,8 +33,7 @@ var myMoistureObj = new moisture.Moisture(0);
|
||||
// 300-600, sensor in humid soil
|
||||
// 600+, sensor in wet soil or submerged in water
|
||||
// Read the value every second and print the corresponding moisture level
|
||||
setInterval(function()
|
||||
{
|
||||
setInterval(function() {
|
||||
var result;
|
||||
var moisture_val = parseInt(myMoistureObj.value());
|
||||
if (moisture_val >= 0 && moisture_val < 300)
|
||||
@ -47,8 +46,7 @@ setInterval(function()
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
process.on('SIGINT', function() {
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
||||
|
53
examples/javascript/ms5803.js
Normal file
53
examples/javascript/ms5803.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_ms5803');
|
||||
|
||||
// Instantiate a MS5803 instance using bus 0 and default i2c address
|
||||
var sensor = new sensorObj.MS5803(0);
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// MS5803(0, -1, 10);
|
||||
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
console.log("Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C, Pressure: "
|
||||
+ sensor.getPressure()
|
||||
+ " mbar");
|
||||
}, 1000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
@ -22,11 +22,11 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var groveSensor = require('jsupm_grove');
|
||||
// Load UPM module
|
||||
var upm = require('jsupm_relay');
|
||||
|
||||
// Create the relay switch object using GPIO pin 0
|
||||
var relay = new groveSensor.Relay(0);
|
||||
var relay = new upm.Relay(0);
|
||||
|
||||
// Close and then open the relay switch 3 times,
|
||||
// waiting one second each time. The LED on the relay switch
|
||||
@ -46,4 +46,3 @@ var waiting = setInterval(function() {
|
||||
i++;
|
||||
if (i == 6) clearInterval(waiting);
|
||||
}, 1000);
|
||||
|
||||
|
@ -22,23 +22,22 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//setup/Initialization
|
||||
var upm_grove = require('jsupm_grove');
|
||||
//initialization
|
||||
var upm = require('jsupm_rotary');
|
||||
|
||||
//setup access analog input Analog pin #0 (A0)
|
||||
var groveRotary = new upm_grove.Rotary(0);
|
||||
var rotary = new upm.Rotary(0);
|
||||
|
||||
loop();
|
||||
|
||||
function loop()
|
||||
{
|
||||
var abs = groveRotary.abs_value();
|
||||
var absdeg = groveRotary.abs_deg();
|
||||
var absrad = groveRotary.abs_rad();
|
||||
function loop() {
|
||||
var abs = rotary.abs_value();
|
||||
var absdeg = rotary.abs_deg();
|
||||
var absrad = rotary.abs_rad();
|
||||
|
||||
var rel = groveRotary.rel_value();
|
||||
var reldeg = groveRotary.rel_deg();
|
||||
var relrad = groveRotary.rel_rad();
|
||||
var rel = rotary.rel_value();
|
||||
var reldeg = rotary.rel_deg();
|
||||
var relrad = rotary.rel_rad();
|
||||
|
||||
//write the knob value to the console in different formats
|
||||
console.log("Abs: " + abs + " " + Math.round(parseInt(absdeg)) + " " + absrad.toFixed(3));
|
||||
|
@ -23,26 +23,24 @@
|
||||
*/
|
||||
|
||||
var voltageDivider = require('jsupm_vdiv');
|
||||
// Instantiate a Grove Voltage Divider sensor on analog pin A0
|
||||
// Instantiate a Voltage Divider sensor on analog pin A0
|
||||
var myVoltageDivider = new voltageDivider.VDiv(0);
|
||||
|
||||
// collect data and output measured voltage according to the setting
|
||||
// of the scaling switch (3 or 10)
|
||||
var val, gain3val, gain10val;
|
||||
function getVoltageInfo()
|
||||
{
|
||||
|
||||
function getVoltageInfo() {
|
||||
val = myVoltageDivider.value(100);
|
||||
gain3val = myVoltageDivider.computedValue(3, val);
|
||||
gain10val = myVoltageDivider.computedValue(10, val);
|
||||
console.log("ADC value: " + val + " Gain 3: " + gain3val
|
||||
+ "v Gain 10: " + gain10val + "v");
|
||||
console.log("ADC value: " + val + " Gain 3: " + gain3val + "v Gain 10: " + gain10val + "v");
|
||||
}
|
||||
|
||||
setInterval(getVoltageInfo, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
process.on('SIGINT', function() {
|
||||
myVoltageDivider = null;
|
||||
voltageDivider.cleanUp();
|
||||
voltageDivider = null;
|
||||
|
@ -22,15 +22,14 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
// Load UPM module
|
||||
var waterSensor = require('jsupm_water');
|
||||
|
||||
// Instantiate a Water sensor on digital pin D2
|
||||
var water = new waterSensor.Water(2);
|
||||
|
||||
// Read whether the sensor is wet/dry, waiting one second between readings
|
||||
function readWaterState()
|
||||
{
|
||||
function readWaterState() {
|
||||
if (water.isWet())
|
||||
console.log("Sensor is wet");
|
||||
else
|
||||
@ -39,8 +38,7 @@ function readWaterState()
|
||||
setInterval(readWaterState, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
process.on('SIGINT', function() {
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
var waterFlow_lib = require('jsupm_wfs');
|
||||
|
||||
// Instantiate a Grove Water Flow Sensor on digital pin D2
|
||||
// Instantiate a Water Flow Sensor on digital pin D2
|
||||
var myWaterFlow_obj = new waterFlow_lib.WFS(2);
|
||||
|
||||
// set the flow counter to 0 and start counting
|
||||
@ -33,8 +33,7 @@ myWaterFlow_obj.startFlowCounter();
|
||||
|
||||
|
||||
var millis, flowCount, fr;
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
var myInterval = setInterval(function() {
|
||||
// we grab these (millis and flowCount) just for display
|
||||
// purposes in this example
|
||||
millis = myWaterFlow_obj.getMillis();
|
||||
@ -53,8 +52,7 @@ var myInterval = setInterval(function()
|
||||
|
||||
|
||||
// When exiting: clear interval and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
process.on('SIGINT', function() {
|
||||
clearInterval(myInterval);
|
||||
myWaterFlow_obj.stopFlowCounter();
|
||||
myWaterFlow_obj = null
|
||||
|
66
examples/python/ecezo.py
Executable file
66
examples/python/ecezo.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python
|
||||
# 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.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_ecezo as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
||||
sensor = sensorObj.ECEZO(0, 9600, False);
|
||||
|
||||
# For I2C, assuming the device is configured for address 0x64 on
|
||||
# I2C bus 0, you could use something like:
|
||||
#
|
||||
# sensor = sensorObj.ECEZO(0, 0x64, True);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
print("EC "
|
||||
+ str(sensor.getEC())
|
||||
+ " uS/cm, TDS "
|
||||
+ str(sensor.getTDS())
|
||||
+ " mg/L, Salinity "
|
||||
+ str(sensor.getSalinity())
|
||||
+ " PSS-78, SG "
|
||||
+ str(sensor.getSG()));
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Zion Orent <zorent@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
# Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015-2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
@ -26,12 +27,11 @@ import time, sys, signal, atexit
|
||||
from upm import pyupm_guvas12d as upmUV
|
||||
|
||||
def main():
|
||||
# Instantiate a UV sensor on analog pin A0
|
||||
myUVSensor = upmUV.GUVAS12D(0);
|
||||
|
||||
# analog voltage, usually 3.3 or 5.0
|
||||
GUVAS12D_AREF = 5.0;
|
||||
SAMPLES_PER_QUERY = 1024;
|
||||
|
||||
# Instantiate a UV sensor on analog pin A0
|
||||
myUVSensor = upmUV.GUVAS12D(0, GUVAS12D_AREF);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
@ -48,10 +48,8 @@ def main():
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while(1):
|
||||
s = ("AREF: {0}, "
|
||||
"Voltage value (higher means more UV): "
|
||||
"{1}".format(GUVAS12D_AREF,
|
||||
myUVSensor.value(GUVAS12D_AREF, SAMPLES_PER_QUERY)))
|
||||
s = ("Volts: {0}, Intensity: {1} mW/m^2".format(myUVSensor.volts(),
|
||||
myUVSensor.intensity()))
|
||||
print(s)
|
||||
time.sleep(1)
|
||||
|
||||
|
44
examples/python/ims.py
Executable file
44
examples/python/ims.py
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Noel Eck <noel.eck@intel.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.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_ims
|
||||
|
||||
def main():
|
||||
# Create an instance of the I2C Moisture Sensor
|
||||
# I2C bus 0, default address = 0x20
|
||||
ims = pyupm_ims.IMS(0)
|
||||
|
||||
print ('I2C moisture sensor example...')
|
||||
while (1):
|
||||
try:
|
||||
print ('Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C' \
|
||||
% (ims.get_version(), ims.get_light(), ims.get_moisture(),
|
||||
ims.get_temperature()))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
56
examples/python/mb704x.py
Executable file
56
examples/python/mb704x.py
Executable file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
# 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.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_mb704x as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a MB704X sensor using default parameters (bus 0,
|
||||
# address 112)
|
||||
sensor = sensorObj.MB704X();
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
print("Range: "
|
||||
+ str(sensor.getRange())
|
||||
+ " cm")
|
||||
|
||||
time.sleep(.5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
58
examples/python/ms5803.py
Executable file
58
examples/python/ms5803.py
Executable file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
# 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.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_ms5803 as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a MS5803 instance using bus 0 and default i2c address
|
||||
sensor = sensorObj.MS5803(0)
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# MS5803(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
print("Temperature:", sensor.getTemperature(), "C,", end=' ')
|
||||
print("Pressure: ", sensor.getPressure(), "mbar")
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
42
include/fti/upm_pressure.h
Normal file
42
include/fti/upm_pressure.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Authors: 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.
|
||||
*/
|
||||
#ifndef UPM_PRESSURE_H_
|
||||
#define UPM_PRESSURE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Pressure function table
|
||||
typedef struct _upm_pressure_ft {
|
||||
upm_result_t (*upm_pressure_set_scale) (void* dev, float scale);
|
||||
upm_result_t (*upm_pressure_set_offset) (void* dev, float offset);
|
||||
upm_result_t (*upm_pressure_get_value) (void* dev, float* value);
|
||||
} upm_pressure_ft;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UPM_PRESSURE_H_ */
|
@ -124,6 +124,7 @@ typedef struct _upm_sensor_ft* (*func_get_upm_sensor_ft)(upm_sensor_t sensor_typ
|
||||
#include <fti/upm_humidity.h>
|
||||
#include <fti/upm_binary.h>
|
||||
#include <fti/upm_rotaryencoder.h>
|
||||
#include <fti/upm_pressure.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Authors:
|
||||
* Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -24,11 +25,13 @@
|
||||
#ifndef UPM_MATH_H_
|
||||
#define UPM_MATH_H_
|
||||
|
||||
#include <upm_platform.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef linux
|
||||
#if defined(UPM_PLATFORM_LINUX) || defined(UPM_PLATFORM_ZEPHYR)
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
|
46
include/upm_platform.h
Normal file
46
include/upm_platform.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Authors: 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.
|
||||
*/
|
||||
|
||||
#ifndef UPM_PLATFORM_H_
|
||||
#define UPM_PLATFORM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(linux)
|
||||
# define UPM_PLATFORM_LINUX (1)
|
||||
#elif defined(CONFIG_BOARD_ARDUINO_101) || \
|
||||
defined(CONFIG_BOARD_ARDUINO_101_SSS) || \
|
||||
defined(CONFIG_BOARD_QUARK_D2000_CRB)
|
||||
# define UPM_PLATFORM_ZEPHYR (1)
|
||||
#else
|
||||
# error "UPM: Unknown Platform!"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UPM_PLATFORM_H_ */
|
@ -1,3 +1,10 @@
|
||||
# Selectively disable certain CXX warnings for SWIG wrappers
|
||||
# SWIG wrappers emit -Wdelete-non-virtual-dtor and -Wunused-function warnings
|
||||
set (SWIG_CXX_DISABLE_WARNINGS -Wno-delete-non-virtual-dtor
|
||||
-Wno-unused-function
|
||||
-Wno-maybe-uninitialized
|
||||
-Wno-strict-aliasing)
|
||||
|
||||
macro (file_to_list readfile outlist)
|
||||
FILE(READ "${readfile}" contents)
|
||||
STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
|
||||
@ -55,9 +62,6 @@ macro (upm_target_link_libraries target_name)
|
||||
endforeach(_library ${ARGN})
|
||||
endmacro (upm_target_link_libraries target_name)
|
||||
|
||||
# Selectively do not emit warnings from the SWIG-generated wrappers
|
||||
set (disabled_flags -Wno-delete-non-virtual-dtor -Wno-unused-function)
|
||||
|
||||
# Create a single swig target for python
|
||||
macro(_upm_swig_python)
|
||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
|
||||
@ -89,13 +93,13 @@ macro(_upm_swig_python)
|
||||
"${PYTHON_INCLUDE_DIRS}")
|
||||
|
||||
# Turn off flags for wrapper
|
||||
foreach(flag ${disabled_flags})
|
||||
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
compiler_flag_supported(CXX is_supported ${flag})
|
||||
if (is_supported)
|
||||
target_compile_options(${python_wrapper_target}
|
||||
PRIVATE "${flag}")
|
||||
endif(is_supported)
|
||||
endforeach(flag ${disabled_flags})
|
||||
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
|
||||
# Add C++ comments to ALL python modules (requires doc build)
|
||||
if (BUILDDOC)
|
||||
@ -180,13 +184,13 @@ macro(upm_swig_node)
|
||||
)
|
||||
|
||||
# Turn off flags for wrapper
|
||||
foreach(flag ${disabled_flags})
|
||||
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
compiler_flag_supported(CXX is_supported ${flag})
|
||||
if (is_supported)
|
||||
target_compile_options(${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||
PRIVATE "${flag}")
|
||||
endif(is_supported)
|
||||
endforeach(flag ${disabled_flags})
|
||||
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
|
||||
set_target_properties (jsupm_${libname} PROPERTIES
|
||||
COMPILE_FLAGS "-DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
|
||||
@ -217,9 +221,6 @@ endmacro(upm_swig_node)
|
||||
macro(upm_swig_java)
|
||||
# Skip if the libname is in the blacklist
|
||||
if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
|
||||
FIND_PACKAGE (JNI REQUIRED)
|
||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
||||
|
||||
include_directories (
|
||||
${JAVA_INCLUDE_PATH}
|
||||
${JAVA_INCLUDE_PATH2}
|
||||
@ -242,13 +243,13 @@ macro(upm_swig_java)
|
||||
)
|
||||
|
||||
# Turn off flags for wrapper
|
||||
foreach(flag ${disabled_flags})
|
||||
foreach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
compiler_flag_supported(CXX is_supported ${flag})
|
||||
if (is_supported)
|
||||
target_compile_options(${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
|
||||
PRIVATE "${flag}")
|
||||
endif(is_supported)
|
||||
endforeach(flag ${disabled_flags})
|
||||
endforeach(flag ${SWIG_CXX_DISABLE_WARNINGS})
|
||||
|
||||
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
|
||||
# Java jar files always need to go under lib/java, regardless of
|
||||
@ -545,12 +546,23 @@ elseif (BUILDSWIGPYTHON)
|
||||
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub")
|
||||
endif (BUILDDOC AND BUILDSWIGPYTHON)
|
||||
|
||||
# Add subdirectories from MODULE_LIST if defined
|
||||
# Example -DMODULE_LIST="dfrph;rotaryencoder"
|
||||
if (MODULE_LIST)
|
||||
set(SUBDIRS ${MODULE_LIST})
|
||||
set(SUBDIRS ${SUBDIRS} upm)
|
||||
else()
|
||||
# Otherwise, add all subdirectories
|
||||
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# If the SUBDIRS list does NOT include the utilities directory, add it since
|
||||
# most sensor library targets depend on utilities
|
||||
if (NOT "${SUBDIRS}" MATCHES utilities)
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/src/utilities)
|
||||
endif()
|
||||
|
||||
# Iterate over each directory in SUBDIRS
|
||||
foreach(subdir ${SUBDIRS})
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/CMakeLists.txt)
|
||||
add_subdirectory(${subdir})
|
||||
|
@ -97,9 +97,9 @@ namespace upm {
|
||||
int value();
|
||||
|
||||
private:
|
||||
mraa::Aio m_aioOUT;
|
||||
mraa::Gpio m_gpioLOPlus;
|
||||
mraa::Gpio m_gpioLOMinus;
|
||||
mraa::Aio m_aioOUT;
|
||||
|
||||
float m_aref;
|
||||
int m_ares;
|
||||
|
@ -3,3 +3,7 @@ set (libdescription "Analog to digital converter")
|
||||
set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx)
|
||||
set (module_hpp ${libname}.hpp ads1115.hpp ads1015.hpp)
|
||||
upm_module_init()
|
||||
compiler_flag_supported(CXX is_supported -Wno-overloaded-virtual)
|
||||
if (is_supported)
|
||||
target_compile_options(${libname} PUBLIC -Wno-overloaded-virtual)
|
||||
endif(is_supported)
|
||||
|
@ -149,7 +149,6 @@ ADS1015::setDelay(){
|
||||
|
||||
ADS1X15::ADSMUXMODE
|
||||
ADS1015::getMuxMode(unsigned int input) {
|
||||
ADS1X15::ADSMUXMODE mode;
|
||||
switch (input) {
|
||||
case 0:
|
||||
return SINGLE_0;
|
||||
|
@ -66,7 +66,7 @@ float ADXRS610::calibrateZeroPoint(unsigned int samples)
|
||||
// The gyro should be in a stable, non-moving state
|
||||
|
||||
float sum = 0;
|
||||
for (int i=0; i<samples; i++)
|
||||
for (unsigned int i=0; i<samples; i++)
|
||||
sum += getDataVolts();
|
||||
|
||||
return sum / samples;
|
||||
|
@ -199,7 +199,12 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
|
||||
tdata[ilen+3] = crc;
|
||||
tdata[ilen+4] = (crc >> 8);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (mraa_i2c_address(m_i2ControlCtx, m_controlAddr) != MRAA_SUCCESS)
|
||||
{
|
||||
fprintf(stdout, "Error, setting i2c address.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int iLoops = 5;
|
||||
mraa_set_priority(HIGH_PRIORITY);
|
||||
do {
|
||||
|
@ -197,7 +197,6 @@ class AM2315 {
|
||||
time_t m_last_time;
|
||||
|
||||
int m_base_priority;
|
||||
pthread_t this_thread;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -831,6 +831,8 @@ string BACNETUTIL::getAllErrorString()
|
||||
return string("UPM Error: ") + getUPMErrorString();
|
||||
break;
|
||||
}
|
||||
|
||||
return string("Internal Error: Unknown ErrorType");
|
||||
}
|
||||
|
||||
string BACNETUTIL::getDeviceDescription()
|
||||
|
@ -210,7 +210,7 @@ unsigned Device_Count(
|
||||
uint32_t Device_Index_To_Instance(
|
||||
unsigned index)
|
||||
{
|
||||
index = index;
|
||||
//index = index;
|
||||
return Object_Instance_Number;
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,6 @@ using namespace std;
|
||||
|
||||
// conversion from fahrenheit to celsius and back
|
||||
|
||||
static float f2c(float f)
|
||||
{
|
||||
return ((f - 32.0) / (9.0 / 5.0));
|
||||
}
|
||||
|
||||
static float c2f(float c)
|
||||
{
|
||||
return (c * (9.0 / 5.0) + 32.0);
|
||||
|
@ -196,7 +196,6 @@ class BMPX8X : public IPressureSensor, public ITemperatureSensor {
|
||||
std::string m_name;
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
mraa::I2c m_i2ControlCtx;
|
||||
|
||||
uint8_t oversampling;
|
||||
|
@ -1418,12 +1418,12 @@ namespace upm {
|
||||
mraa::I2c *m_i2c;
|
||||
mraa::Spi *m_spi;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
mraa::Gpio *m_gpioIntr1;
|
||||
mraa::Gpio *m_gpioIntr2;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
uint8_t m_addr;
|
||||
RESOLUTION_T m_resolution;
|
||||
|
||||
|
@ -1185,12 +1185,12 @@ namespace upm {
|
||||
mraa::I2c *m_i2c;
|
||||
mraa::Spi *m_spi;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
mraa::Gpio *m_gpioIntr1;
|
||||
mraa::Gpio *m_gpioIntr2;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
uint8_t m_addr;
|
||||
|
||||
// SPI chip select
|
||||
|
@ -552,12 +552,12 @@ namespace upm {
|
||||
mraa::I2c *m_i2c;
|
||||
mraa::Spi *m_spi;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
mraa::Gpio *m_gpioIntr;
|
||||
mraa::Gpio *m_gpioDR;
|
||||
|
||||
// spi chip select
|
||||
mraa::Gpio *m_gpioCS;
|
||||
|
||||
uint8_t m_addr;
|
||||
|
||||
OPERATION_MODE_T m_opmode;
|
||||
@ -594,8 +594,6 @@ namespace upm {
|
||||
|
||||
private:
|
||||
bool m_isSPI;
|
||||
// use the FIFO by default?
|
||||
bool m_useFIFO;
|
||||
|
||||
// return a reference to a gpio pin pointer depending on intr
|
||||
mraa::Gpio*& getPin(INTERRUPT_PINS_T intr);
|
||||
|
@ -481,7 +481,7 @@ string BNO055::readCalibrationData()
|
||||
|
||||
void BNO055::writeCalibrationData(string calibData)
|
||||
{
|
||||
if (calibData.size() != calibrationDataNumBytes)
|
||||
if (static_cast<int>(calibData.size()) != calibrationDataNumBytes)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||
+ ": calibData string must be exactly "
|
||||
|
@ -1,5 +1,7 @@
|
||||
upm_mixed_module_init (NAME button
|
||||
DESCRIPTION "Momentary on/off button"
|
||||
C_HDR button.h
|
||||
C_SRC button.c
|
||||
CPP_HDR button.hpp
|
||||
CPP_SRC button.cxx
|
||||
REQUIRES mraa)
|
||||
|
86
src/button/button.c
Normal file
86
src/button/button.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Abhishek Malik <abhishek.malik@intel.com>
|
||||
* Copyright (c) 2014 - 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 "button.h"
|
||||
|
||||
button_context button_init(int pin){
|
||||
// make sure that mraa is initialized
|
||||
int mraa_rv;
|
||||
if((mraa_rv = mraa_init()) != MRAA_SUCCESS){
|
||||
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
button_context dev = (button_context) malloc(sizeof(struct _button_context));
|
||||
|
||||
if (dev == NULL){
|
||||
printf("Unable to allocate space for the sensor structure\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->gpio_pin = pin;
|
||||
|
||||
dev->gpio = mraa_gpio_init(dev->gpio_pin);
|
||||
mraa_gpio_dir(dev->gpio, MRAA_GPIO_IN);
|
||||
dev->isr_installed = false;
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void button_close(button_context dev){
|
||||
mraa_gpio_close(dev->gpio);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t button_get_value(button_context dev, bool* val){
|
||||
int ret = mraa_gpio_read(dev->gpio);
|
||||
|
||||
if(ret > 0)
|
||||
*val = true;
|
||||
else
|
||||
*val = false;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t button_install_isr(button_context dev, mraa_gpio_edge_t edge_level, void (*isr)(void *), void *arg){
|
||||
button_uninstall_isr(dev);
|
||||
|
||||
mraa_gpio_isr(dev->gpio, edge_level, isr, arg);
|
||||
dev->isr_installed = true;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t button_uninstall_isr(button_context dev){
|
||||
if(dev->isr_installed)
|
||||
mraa_gpio_isr_exit(dev->gpio);
|
||||
|
||||
dev->isr_installed = false;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
98
src/button/button.h
Normal file
98
src/button/button.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Authors: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Sarah Knepper <sarah.knepper@intel.com>
|
||||
* Abhishek Malik <abhishek.malik@intel.com>
|
||||
* Copyright (c) 2014 - 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "upm.h"
|
||||
#include "mraa/gpio.h"
|
||||
|
||||
/**
|
||||
* @brief Button library
|
||||
* @defgroup buttonlib libupm-button
|
||||
* @ingroup seeed gpio button gsk
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library buttonlib
|
||||
* @sensor button
|
||||
* @comname Button
|
||||
* @altname Grove Button
|
||||
* @type button
|
||||
* @man seeed
|
||||
* @con gpio
|
||||
* @kit gsk
|
||||
*
|
||||
* @brief API for the Button
|
||||
*
|
||||
* Basic UPM module for the button sensor
|
||||
*
|
||||
* @image html button.jpg
|
||||
* @snippet button.cxx Interesting
|
||||
*/
|
||||
|
||||
typedef struct _button_context {
|
||||
mraa_gpio_context gpio;
|
||||
uint8_t gpio_pin;
|
||||
bool isr_installed;
|
||||
} *button_context;
|
||||
|
||||
/**
|
||||
* button init function
|
||||
*
|
||||
* @param gpio Pin to use
|
||||
*/
|
||||
button_context button_init(int pin);
|
||||
|
||||
/**
|
||||
* button destructor
|
||||
*/
|
||||
void button_close(button_context dev);
|
||||
/**
|
||||
* Gets the value from the GPIO pin
|
||||
*
|
||||
* @return Value from the GPIO pin
|
||||
*/
|
||||
upm_result_t button_get_value(button_context dev, bool* val);
|
||||
/**
|
||||
* Installs an interrupt service routine (ISR) to be called when
|
||||
* the button is activated or deactivated.
|
||||
*
|
||||
* @param fptr Pointer to a function to be called on interrupt
|
||||
* @param arg Pointer to an object to be supplied as an
|
||||
* argument to the ISR.
|
||||
*/
|
||||
upm_result_t button_install_isr(button_context dev, mraa_gpio_edge_t edge_level, void (*isr)(void *), void *arg);
|
||||
/**
|
||||
* Uninstalls the previously installed ISR
|
||||
*
|
||||
*/
|
||||
upm_result_t button_uninstall_isr(button_context);
|
@ -156,13 +156,14 @@ namespace upm {
|
||||
|
||||
|
||||
protected:
|
||||
// temperature and humidity are optional features of this transmitter
|
||||
mraa::Aio *m_aioTemp;
|
||||
mraa::Aio *m_aioHum;
|
||||
|
||||
// CO2 reporting is always supported
|
||||
mraa::Aio m_aioCO2;
|
||||
|
||||
// temperature and humidity are optional features of this transmitter
|
||||
mraa::Aio *m_aioHum;
|
||||
mraa::Aio *m_aioTemp;
|
||||
|
||||
|
||||
private:
|
||||
float m_aref;
|
||||
float m_rResistor;
|
||||
|
9
src/ecezo/CMakeLists.txt
Normal file
9
src/ecezo/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
upm_mixed_module_init (NAME ecezo
|
||||
DESCRIPTION "EC EZO Atlas Scientific EC circuit"
|
||||
C_HDR ecezo.h ecezo_defs.h
|
||||
C_SRC ecezo.c
|
||||
CPP_HDR ecezo.hpp
|
||||
CPP_SRC ecezo.cxx
|
||||
FTI_SRC ecezo_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa)
|
674
src/ecezo/ecezo.c
Normal file
674
src/ecezo/ecezo.c
Normal file
@ -0,0 +1,674 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <upm_utilities.h>
|
||||
|
||||
#include "ecezo.h"
|
||||
|
||||
// "Typical" command completion delay in ms
|
||||
#define CMD_DELAY (350)
|
||||
|
||||
// uncomment for dubugging
|
||||
//#define ECEZO_DEBUG (1)
|
||||
|
||||
// I2C read helper
|
||||
static int readBytes(const ecezo_context dev, uint8_t *buffer, int len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
assert(dev->i2c != NULL);
|
||||
|
||||
bool done = false;
|
||||
int rv;
|
||||
int retries = 10;
|
||||
|
||||
while (!done && (retries-- > 0))
|
||||
{
|
||||
if ((rv = mraa_i2c_read(dev->i2c, buffer, len)) < 0)
|
||||
{
|
||||
printf("%s: mraa_i2c_read(code) failed.\n", __FUNCTION__);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("CODE: %02x\n", buffer[0]);
|
||||
#endif
|
||||
|
||||
if (buffer[0] == 0xff || buffer[0] == 0x02)
|
||||
{
|
||||
// no data available, or error
|
||||
return -1;
|
||||
}
|
||||
else if (buffer[0] == 0x01)
|
||||
{
|
||||
// data is ready
|
||||
done = true;
|
||||
|
||||
// now we need to move the data one byte down so the rest
|
||||
// of this driver can work as-is.
|
||||
memmove(buffer, (buffer + 1), len - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// buffer[0] 0xfe - data is pending. wait and loop again.
|
||||
upm_delay_ms(CMD_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
if (retries <= 0)
|
||||
{
|
||||
printf("%s: timed out waiting for correct response.\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("%s: Got %d bytes\n", __FUNCTION__, rv);
|
||||
|
||||
for (int i=0; i<rv; i++)
|
||||
{
|
||||
printf("%02x (%c) ", buffer[i],
|
||||
isprint(buffer[i]) ? buffer[i] : '@');
|
||||
}
|
||||
printf("\n");
|
||||
#endif // ECEZO_DEBUG
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static upm_result_t generic_init(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// do some generic initialization
|
||||
bool error = false;
|
||||
|
||||
// turn off response (*OK) codes (UART only)
|
||||
if (dev->uart)
|
||||
{
|
||||
if (ecezo_send_command(dev, "Response,0", NULL, 0) < 0)
|
||||
error = true;
|
||||
}
|
||||
|
||||
// turn off continuous sampling
|
||||
if (ecezo_set_continuous(dev, false))
|
||||
error = true;
|
||||
|
||||
// make sure all parameters are enabled
|
||||
if (ecezo_send_command(dev, "O,EC,1", NULL, 0) < 0)
|
||||
error = true;
|
||||
if (ecezo_send_command(dev, "O,TDS,1", NULL, 0) < 0)
|
||||
error = true;
|
||||
if (ecezo_send_command(dev, "O,S,1", NULL, 0) < 0)
|
||||
error = true;
|
||||
if (ecezo_send_command(dev, "O,SG,1", NULL, 0) < 0)
|
||||
error = true;
|
||||
|
||||
if (error)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
else
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
static upm_result_t decode_report(const ecezo_context dev, char *data)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
char *startptr = data;
|
||||
char *endptr = NULL;
|
||||
float val;
|
||||
|
||||
// the format of the data string should be: ec,tds,s,sg
|
||||
|
||||
// ec
|
||||
val = strtof(startptr, &endptr);
|
||||
|
||||
if (startptr == endptr)
|
||||
{
|
||||
// error
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
dev->ec = val;
|
||||
startptr = endptr + 1;
|
||||
|
||||
// tds
|
||||
val = strtof(startptr, &endptr);
|
||||
|
||||
// error
|
||||
if (startptr == endptr)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
dev->tds = val;
|
||||
startptr = endptr + 1;
|
||||
|
||||
// salinity
|
||||
val = strtof(startptr, &endptr);
|
||||
|
||||
// error
|
||||
if (startptr == endptr)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
dev->salinity = val;
|
||||
startptr = endptr + 1;
|
||||
|
||||
// sg
|
||||
val = strtof(startptr, &endptr);
|
||||
|
||||
if (startptr == endptr)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
dev->sg = val;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
static bool ecezo_data_available(const ecezo_context dev, unsigned int millis)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// i2c, we don't support this
|
||||
if (dev->i2c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// uart
|
||||
if (mraa_uart_data_available(dev->uart, millis))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// uart init
|
||||
ecezo_context ecezo_uart_init(unsigned int uart, unsigned int baudrate)
|
||||
{
|
||||
// make sure MRAA is initialized
|
||||
int mraa_rv;
|
||||
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecezo_context dev =
|
||||
(ecezo_context)malloc(sizeof(struct _ecezo_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
// zero out context
|
||||
memset((void *)dev, 0, sizeof(struct _ecezo_context));
|
||||
|
||||
// initialize the MRAA contexts
|
||||
|
||||
// uart, default should be 8N1
|
||||
if (!(dev->uart = mraa_uart_init(uart)))
|
||||
{
|
||||
printf("%s: mraa_uart_init() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_uart_set_baudrate(dev->uart, baudrate))
|
||||
{
|
||||
printf("%s: mraa_uart_set_baudrate() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mraa_uart_set_flowcontrol(dev->uart, false, false);
|
||||
|
||||
if (generic_init(dev))
|
||||
{
|
||||
printf("%s: generic_init() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
// i2c ublox init
|
||||
ecezo_context ecezo_i2c_init(unsigned int bus, uint8_t addr)
|
||||
{
|
||||
// make sure MRAA is initialized
|
||||
int mraa_rv;
|
||||
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ecezo_context dev =
|
||||
(ecezo_context)malloc(sizeof(struct _ecezo_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
// zero out context
|
||||
memset((void *)dev, 0, sizeof(struct _ecezo_context));
|
||||
|
||||
// initialize the MRAA contexts
|
||||
|
||||
if (!(dev->i2c = mraa_i2c_init(bus)))
|
||||
{
|
||||
printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_i2c_address(dev->i2c, addr))
|
||||
{
|
||||
printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (generic_init(dev))
|
||||
{
|
||||
printf("%s: generic_init() failed.\n", __FUNCTION__);
|
||||
ecezo_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void ecezo_close(ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->uart)
|
||||
mraa_uart_stop(dev->uart);
|
||||
if (dev->i2c)
|
||||
mraa_i2c_stop(dev->i2c);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t ecezo_set_continuous(const ecezo_context dev, bool enable)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (enable)
|
||||
rv = ecezo_send_command(dev, "C,1", NULL, 0);
|
||||
else
|
||||
rv = ecezo_send_command(dev, "C,0", NULL, 0);
|
||||
|
||||
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
|
||||
}
|
||||
|
||||
upm_result_t ecezo_set_temperature(const ecezo_context dev, float temp)
|
||||
{
|
||||
char buffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
snprintf(buffer, ECEZO_MAX_BUFFER_LEN, "T,%f", temp);
|
||||
|
||||
int rv = ecezo_send_command(dev, buffer, NULL, 0);
|
||||
|
||||
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
|
||||
}
|
||||
|
||||
upm_result_t ecezo_set_led(const ecezo_context dev, bool enable)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (enable)
|
||||
rv = ecezo_send_command(dev, "L,1", NULL, 0);
|
||||
else
|
||||
rv = ecezo_send_command(dev, "L,0", NULL, 0);
|
||||
|
||||
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
|
||||
}
|
||||
|
||||
upm_result_t ecezo_set_k_value(const ecezo_context dev, float k)
|
||||
{
|
||||
char buffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
// the K value must be between 0.1 and 10.0
|
||||
if (k < 0.1 || k > 10.0)
|
||||
{
|
||||
printf("%s: K value must be between 0.1 and 10.0\n", __FUNCTION__);
|
||||
return UPM_ERROR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
snprintf(buffer, ECEZO_MAX_BUFFER_LEN, "K,%f", k);
|
||||
|
||||
int rv = ecezo_send_command(dev, buffer, NULL, 0);
|
||||
|
||||
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
|
||||
}
|
||||
|
||||
upm_result_t ecezo_set_sleep(const ecezo_context dev, bool enable)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
if (enable)
|
||||
rv = ecezo_send_command(dev, "SLEEP", NULL, 0);
|
||||
else
|
||||
{
|
||||
// "WAKE" isn't a real command, but should wake the device up.
|
||||
// We ignore the return value, as it will likely be an error
|
||||
// anyway.
|
||||
ecezo_send_command(dev, "WAKE", NULL, 0);
|
||||
}
|
||||
|
||||
return ((rv < 0) ? UPM_ERROR_OPERATION_FAILED : UPM_SUCCESS);
|
||||
}
|
||||
|
||||
int ecezo_read(const ecezo_context dev, char *buffer, size_t len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
upm_delay_ms(CMD_DELAY); // delay CMD_DELAY ms to make sure cmd completed
|
||||
|
||||
// i2c
|
||||
if (dev->i2c)
|
||||
{
|
||||
return readBytes(dev, (uint8_t *)buffer, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
// UART
|
||||
int bytesRead = 0;
|
||||
|
||||
while(bytesRead < len)
|
||||
{
|
||||
// we read one byte at a time, exiting when either len is
|
||||
// reached, or a '\r' is found indicating the end of a
|
||||
// sentence. Most commands (except 'R') require a minimum
|
||||
// of 300ms to execute, so we wait up to CMD_DELAY ms after all
|
||||
// data (if any) is read.
|
||||
if (ecezo_data_available(dev, CMD_DELAY))
|
||||
{
|
||||
int br = mraa_uart_read(dev->uart, &buffer[bytesRead], 1);
|
||||
|
||||
if (br <= 0)
|
||||
return br;
|
||||
|
||||
if (buffer[bytesRead] == '\r')
|
||||
{
|
||||
// if we found a CR, replace it with a 0 byte
|
||||
buffer[bytesRead++] = 0;
|
||||
return bytesRead;
|
||||
}
|
||||
bytesRead++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// timed out - ok with responses disabled
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// anything else is an error
|
||||
return -1;
|
||||
}
|
||||
|
||||
upm_result_t ecezo_write(const ecezo_context dev, char *buffer, size_t len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->uart)
|
||||
{
|
||||
if (mraa_uart_write(dev->uart, buffer, len) != len)
|
||||
{
|
||||
printf("%s: mraa_uart_write() failed.\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
if (mraa_i2c_write(dev->i2c, (uint8_t *)buffer, len))
|
||||
{
|
||||
printf("%s: mraa_i2c_write() failed.\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
int ecezo_send_command(const ecezo_context dev, char *cmd, char *buffer,
|
||||
int len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (!cmd)
|
||||
return -1;
|
||||
|
||||
// Our local buffer in case one isn't supplied
|
||||
char localBuffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
// our read buffer ptr
|
||||
char *readBuffer = NULL;
|
||||
|
||||
if (!buffer || !len)
|
||||
{
|
||||
readBuffer = localBuffer;
|
||||
len = ECEZO_MAX_BUFFER_LEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
readBuffer = buffer;
|
||||
}
|
||||
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("Command: %s\n", cmd);
|
||||
#endif // ECEZO_DEBUG
|
||||
|
||||
// our write buffer
|
||||
char writeBuffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
strncpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN);
|
||||
writeBuffer[ECEZO_MAX_BUFFER_LEN - 1] = 0;
|
||||
|
||||
int writelen = strlen(writeBuffer);
|
||||
|
||||
if (dev->uart)
|
||||
{
|
||||
if (strlen(writeBuffer) >= ECEZO_MAX_BUFFER_LEN - 2)
|
||||
{
|
||||
// too big. Should never happen in real life.
|
||||
printf("%s: cmd writeBuffer too big.\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcat(writeBuffer, "\r");
|
||||
}
|
||||
|
||||
// for the uart this will now include the added CR, for I2C, this
|
||||
// will now include the already existing \0 terminator.
|
||||
writelen++;
|
||||
|
||||
// Let the games begin...
|
||||
int retries = 10;
|
||||
|
||||
while (retries-- > 0)
|
||||
{
|
||||
if (ecezo_write(dev, writeBuffer, writelen))
|
||||
{
|
||||
printf("%s: ecezo_write() failed\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we wait up to CMD_DELAY ms for an error response, which should be
|
||||
// more than enough time. No response is also ok, since we
|
||||
// disable the "*OK" response in the init.
|
||||
|
||||
memset((void *)readBuffer, 0, len);
|
||||
int bytesRead = 0;
|
||||
if ((bytesRead = ecezo_read(dev, readBuffer, len)) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// for I2C, we are done at this point
|
||||
if (dev->i2c)
|
||||
break;
|
||||
|
||||
// for UART, we need some more checks
|
||||
if (bytesRead && strstr(readBuffer, "*ER"))
|
||||
{
|
||||
// need to retry the command
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("%s: *ER DETECTED, retry\n", __FUNCTION__);
|
||||
#endif // ECEZO_DEBUG
|
||||
continue;
|
||||
}
|
||||
else if (bytesRead && strchr(readBuffer, '*'))
|
||||
{
|
||||
// Some other diagnostic code, output it.
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("%s: * diagnostic code detected (%s), retry\n",
|
||||
__FUNCTION__, buffer);
|
||||
#endif // ECEZO_DEBUG
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we are done here
|
||||
#if defined(ECEZO_DEBUG)
|
||||
printf("%s: bytesRead = %d\n", __FUNCTION__, bytesRead);
|
||||
#endif // ECEZO_DEBUG
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (retries <= 0)
|
||||
{
|
||||
printf("%s: read timed out and/or and retries exhausted\n",
|
||||
__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
upm_result_t ecezo_update(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// first we send a 'R' command to get a reading (takes a minimum
|
||||
// of 1 second), then we parse out the string values into the
|
||||
// context variables.
|
||||
|
||||
char buffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
// first issue the report command
|
||||
int rv = ecezo_send_command(dev, "R", buffer, ECEZO_MAX_BUFFER_LEN);
|
||||
if (rv == 0)
|
||||
{
|
||||
printf("%s: timed out waiting for data\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
else if (rv < 0)
|
||||
{
|
||||
printf("%s: error retrieving data\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
// decode
|
||||
if (decode_report(dev, buffer))
|
||||
{
|
||||
printf("%s: decode_report() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
float ecezo_get_ec(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return dev->ec;
|
||||
}
|
||||
|
||||
float ecezo_get_tds(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return dev->tds;
|
||||
}
|
||||
|
||||
float ecezo_get_salinity(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return dev->salinity;
|
||||
}
|
||||
|
||||
float ecezo_get_sg(const ecezo_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return dev->sg;
|
||||
}
|
||||
|
||||
upm_result_t ecezo_calibrate(const ecezo_context dev, ECEZO_CALIBRATION_T cal,
|
||||
float ec)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
char cmdBuffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
switch(cal)
|
||||
{
|
||||
case ECEZO_CALIBRATE_CLEAR:
|
||||
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,clear");
|
||||
break;
|
||||
|
||||
case ECEZO_CALIBRATE_DRY:
|
||||
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,dry");
|
||||
break;
|
||||
|
||||
case ECEZO_CALIBRATE_ONE:
|
||||
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,one,%f", ec);
|
||||
break;
|
||||
|
||||
case ECEZO_CALIBRATE_LOW:
|
||||
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,low,%f", ec);
|
||||
break;
|
||||
|
||||
case ECEZO_CALIBRATE_HIGH:
|
||||
snprintf(cmdBuffer, ECEZO_MAX_BUFFER_LEN, "cal,high,%f", ec);
|
||||
break;
|
||||
|
||||
default:
|
||||
// should be able to happen
|
||||
printf("%s: invalid cal parameter\n", __FUNCTION__);
|
||||
return UPM_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return ecezo_send_command(dev, cmdBuffer, NULL, 0);
|
||||
}
|
146
src/ecezo/ecezo.cxx
Normal file
146
src/ecezo/ecezo.cxx
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "ecezo.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
ECEZO::ECEZO(unsigned int bus, unsigned int addrBaud, bool isI2C) :
|
||||
m_ecezo(nullptr)
|
||||
{
|
||||
if (isI2C)
|
||||
m_ecezo = ecezo_i2c_init(bus, addrBaud);
|
||||
else
|
||||
m_ecezo = ecezo_uart_init(bus, addrBaud);
|
||||
|
||||
if (!m_ecezo)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_*_init() failed");
|
||||
}
|
||||
|
||||
ECEZO::~ECEZO()
|
||||
{
|
||||
ecezo_close(m_ecezo);
|
||||
}
|
||||
|
||||
void ECEZO::update()
|
||||
{
|
||||
if (ecezo_update(m_ecezo))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_update() failed");
|
||||
}
|
||||
|
||||
void ECEZO::setTemperature(float temp)
|
||||
{
|
||||
if (ecezo_set_temperature(m_ecezo, temp))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_set_temperature() failed");
|
||||
}
|
||||
|
||||
void ECEZO::setKValue(float k)
|
||||
{
|
||||
if (ecezo_set_k_value(m_ecezo, k))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_set_k_value() failed");
|
||||
}
|
||||
|
||||
void ECEZO::setSleep(bool enable)
|
||||
{
|
||||
if (ecezo_set_sleep(m_ecezo, enable))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_set_sleep() failed");
|
||||
}
|
||||
|
||||
float ECEZO::getEC()
|
||||
{
|
||||
return ecezo_get_ec(m_ecezo);
|
||||
}
|
||||
|
||||
float ECEZO::getTDS()
|
||||
{
|
||||
return ecezo_get_tds(m_ecezo);
|
||||
}
|
||||
|
||||
float ECEZO::getSalinity()
|
||||
{
|
||||
return ecezo_get_salinity(m_ecezo);
|
||||
}
|
||||
|
||||
float ECEZO::getSG()
|
||||
{
|
||||
return ecezo_get_sg(m_ecezo);
|
||||
}
|
||||
|
||||
void ECEZO::calibrate(ECEZO_CALIBRATION_T cal, float ec)
|
||||
{
|
||||
if (ecezo_calibrate(m_ecezo, cal, ec))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_calibrate() failed");
|
||||
}
|
||||
|
||||
void ECEZO::setContinuous(bool enable)
|
||||
{
|
||||
if (ecezo_set_continuous(m_ecezo, enable))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_set_continuous() failed");
|
||||
}
|
||||
|
||||
string ECEZO::sendCommand(string cmd)
|
||||
{
|
||||
char buffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
int rv;
|
||||
|
||||
if ((rv = ecezo_send_command(m_ecezo, (char *)cmd.c_str(),
|
||||
buffer, ECEZO_MAX_BUFFER_LEN)) < 0)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_send_command() failed");
|
||||
|
||||
return string(buffer, rv);
|
||||
}
|
||||
|
||||
string ECEZO::read()
|
||||
{
|
||||
char buffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
int rv;
|
||||
|
||||
if ((rv = ecezo_read(m_ecezo, buffer, ECEZO_MAX_BUFFER_LEN)) < 0)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_read() failed");
|
||||
|
||||
return string(buffer, rv);
|
||||
}
|
||||
|
||||
void ECEZO::write(std::string data)
|
||||
{
|
||||
if (ecezo_write(m_ecezo, (char*)data.data(),
|
||||
data.size()))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": ecezo_write() failed");
|
||||
}
|
267
src/ecezo/ecezo.h
Normal file
267
src/ecezo/ecezo.h
Normal file
@ -0,0 +1,267 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <upm.h>
|
||||
#include <mraa/uart.h>
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#include "ecezo_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file ecezo.h
|
||||
* @library ecezo
|
||||
* @brief C API for the EC-EZO EC Sensor
|
||||
*
|
||||
* @include ecezo.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* Device context
|
||||
*/
|
||||
typedef struct _ecezo_context {
|
||||
mraa_uart_context uart;
|
||||
mraa_i2c_context i2c;
|
||||
|
||||
// our values
|
||||
float ec; // electrical conductivity
|
||||
float tds; // total dissolved solids
|
||||
float salinity;
|
||||
float sg; // specific gravity
|
||||
|
||||
} *ecezo_context;
|
||||
|
||||
/**
|
||||
* ECEZO Initializer for UART operation
|
||||
*
|
||||
* @param uart Specify which uart to use.
|
||||
* @param baudrate Specify the baudrate to use. The device defaults
|
||||
* to 9600 baud, though the datasheet implies the default is 38400.
|
||||
* @return an initialized device context on success, NULL on error.
|
||||
*/
|
||||
ecezo_context ecezo_uart_init(unsigned int uart, unsigned int baudrate);
|
||||
|
||||
/**
|
||||
* ECEZO Initializer for I2C operation
|
||||
*
|
||||
* @param bus Specify which the I2C bus to use.
|
||||
* @param addr Specify the I2C address to use. This is
|
||||
* configurable on the device, so there is no default.
|
||||
* @return an initialized device context on success, NULL on error.
|
||||
*/
|
||||
ecezo_context ecezo_i2c_init(unsigned int bus, uint8_t addr);
|
||||
|
||||
/**
|
||||
* ECEZO sensor close function
|
||||
*/
|
||||
void ecezo_close(ecezo_context dev);
|
||||
|
||||
/**
|
||||
* Query the device for a reading, parse the response, and store
|
||||
* the read values into the device context. This function must be
|
||||
* called prior to calling any function that returns the data,
|
||||
* like ecezo_get_ec().
|
||||
*
|
||||
* @param dev Device context
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_update(const ecezo_context dev);
|
||||
|
||||
/**
|
||||
* For accurate readings, the temperature of the liquid being
|
||||
* measured should be known. This function allows you to specify
|
||||
* the liquid's temperature (in Celsius) so that proper
|
||||
* compensation can take place. How you measure this temperature
|
||||
* is up to you. By default, the device will assume a temperature
|
||||
* of 25C.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param temp The temperature of the liquid being measured
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_set_temperature(const ecezo_context dev, float temp);
|
||||
|
||||
/**
|
||||
* Set the K value of the probe being used. By default, this is
|
||||
* 1.0. Valid values are between 0.1 and 10.0.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param k The K value of the probe
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_set_k_value(const ecezo_context dev, float k);
|
||||
|
||||
/**
|
||||
* Enable or disable Sleep mode.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param enable True to enable sleep mode, false to wake up
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_set_sleep(const ecezo_context dev, bool enable);
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Electrical Conductivity (EC) value
|
||||
* in microsiemens. ecezo_update() must have been called before
|
||||
* calling this function.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @return EC value in microsiemens
|
||||
*/
|
||||
float ecezo_get_ec(const ecezo_context dev);
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Total Dissolved solids (TDS) value.
|
||||
* ecezo_update() must have been called before calling this
|
||||
* function.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @return TDS value
|
||||
*/
|
||||
float ecezo_get_tds(const ecezo_context dev);
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Salinity value. ecezo_update() must
|
||||
* have been called before calling this function.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @return Salinity value
|
||||
*/
|
||||
float ecezo_get_salinity(const ecezo_context dev);
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Specific Gravity (SG) value.
|
||||
* ecezo_update() must have been called before calling this
|
||||
* function.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @return SG value
|
||||
*/
|
||||
float ecezo_get_sg(const ecezo_context dev);
|
||||
|
||||
/**
|
||||
* Specify calibration data for calibrating the device. See the
|
||||
* datasheet for details on how calibration is performed. This
|
||||
* function provides a mechanism for clearing out, and setting
|
||||
* calibration data.
|
||||
*
|
||||
* A simple one point calibration might work as follows:
|
||||
*
|
||||
* 1. CLEAR the calibration data
|
||||
* 2. with a dry probe, set the DRY point.
|
||||
* 3. with the probe immersed in a standardized solution, set the
|
||||
* ONE parameter to the solution's known EC value in microsiemens.
|
||||
*
|
||||
* A two point calibration might work as follows:
|
||||
*
|
||||
* 1. CLEAR the calibration data
|
||||
* 2. with a dry probe, set the DRY point.
|
||||
* 3. with the probe immersed in the lowest EC standardized
|
||||
* solution, set the LOW parameter to the solution's known EC
|
||||
* value in microsiemens.
|
||||
* 4. with the probe immersed in the highest EC standardized
|
||||
* solution, set the HIGH parameter to the solution's known EC
|
||||
* value in microsiemens.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param cal One of the ECEZO_CALIBRATION_T values
|
||||
* @param ec The EC value of the calibration fluid. This
|
||||
* parameter is ignored when cal is either ECEZO_CALIBRATE_CLEAR
|
||||
* or ECEZO_CALIBRATE_DRY.
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_calibrate(const ecezo_context dev,
|
||||
ECEZO_CALIBRATION_T cal,
|
||||
float ec);
|
||||
|
||||
/**
|
||||
* Enable or disable "continuous" operation. In continuous
|
||||
* operation, the device will sample and emit readings every
|
||||
* second. The driver disables this mode by default. If you wish
|
||||
* to use continuous mode, you will be responsible for reading and
|
||||
* parsing the returned data yourself.
|
||||
*
|
||||
* The functionality of this driver depends on continuous mode
|
||||
* being disabled. When disabled, the driver will manually
|
||||
* request a reading when desired via ecezo_update().
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param enable true to enable continuous mode, false to disable.
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t ecezo_set_continuous(const ecezo_context dev, bool enable);
|
||||
|
||||
/**
|
||||
* Directly send a command to the device and optionally get a
|
||||
* response. This is a low level function and should not be
|
||||
* called unless you know what you are doing.
|
||||
*
|
||||
* @param dev Device context
|
||||
* @param cmd command to send to the device. See the datasheet
|
||||
* for valid commands.
|
||||
* @param buffer Optional buffer in which to return any data.
|
||||
* NULL if you are not interested in any returned data.
|
||||
* @param len Length of the buffer, or 0 if you are not interested
|
||||
* in returned data
|
||||
* @return Number of characters read back, 0 if a timeout or no
|
||||
* data, -1 if an error
|
||||
*/
|
||||
int ecezo_send_command(const ecezo_context dev, char *cmd,
|
||||
char *buffer, int len);
|
||||
|
||||
/**
|
||||
* Read character data from the device. This is a low level
|
||||
* function and should not be called unless you know what you are
|
||||
* doing.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param buffer The character buffer to read data into.
|
||||
* @param len The maximum size of the buffer
|
||||
* @return The number of bytes successfully read, or -1 on error
|
||||
*/
|
||||
int ecezo_read(const ecezo_context dev, char *buffer, size_t len);
|
||||
|
||||
/**
|
||||
* Write character data to the device. This is a low level
|
||||
* function and should not be called unless you know what you are
|
||||
* doing.
|
||||
*
|
||||
* @param dev sensor context
|
||||
* @param buffer The character buffer containing data to write.
|
||||
* @param len The number of bytes to write.
|
||||
* @return The number of bytes successfully written, or -1 on error.
|
||||
*/
|
||||
upm_result_t ecezo_write(const ecezo_context dev, char *buffer, size_t len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
238
src/ecezo/ecezo.hpp
Normal file
238
src/ecezo/ecezo.hpp
Normal file
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ecezo.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief API for the EC-EZO EC Sensor
|
||||
* @defgroup ecezo libupm-ecezo
|
||||
* @ingroup uart i2c liquid
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library ecezo
|
||||
* @sensor ecezo
|
||||
* @comname EC-EZO EC Sensor
|
||||
* @type liquid
|
||||
* @man sparkfun
|
||||
* @con uart i2c
|
||||
* @web https://www.sparkfun.com/products/12908
|
||||
*
|
||||
* @brief API for the EC-EZO EC Sensor
|
||||
*
|
||||
* This driver was tested with the Atlas Scientific Electrical
|
||||
* Conductivity kit.
|
||||
*
|
||||
* This device can operate in either UART or I2C modes.
|
||||
*
|
||||
* @snippet ecezo.cxx Interesting
|
||||
*/
|
||||
|
||||
class ECEZO {
|
||||
public:
|
||||
|
||||
/**
|
||||
* ECEZO object constructor. This can use either UART
|
||||
* (default) or I2C communications. For UART, specify the
|
||||
* uart number as the bus parameter, the baudrate as the
|
||||
* addrBaud parameter, and false for the isI2C parameter.
|
||||
*
|
||||
* For I2C, specify the bus parameter, the I2C address as the
|
||||
* addrBaud parameter, and true for the isI2C parameter.
|
||||
*
|
||||
* @param bus Specify which uart or I2C bus to use
|
||||
* @param addrBaud Specify the baudrate if using UART, or the
|
||||
* I2C address of the device if using I2C.
|
||||
* @param isI2C true if using I2C, false if using a UART
|
||||
*/
|
||||
ECEZO(unsigned int bus=0, unsigned int addrBaud=9600,
|
||||
bool isI2C=false);
|
||||
|
||||
/**
|
||||
* ECEZO object destructor
|
||||
*/
|
||||
~ECEZO();
|
||||
|
||||
/**
|
||||
* Query the device for a reading, parse the response, and store
|
||||
* the read values into the device context. This function must be
|
||||
* called prior to calling any function that returns the data,
|
||||
* like getEC().
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* For accurate readings, the temperature of the liquid being
|
||||
* measured should be known. This function allows you to specify
|
||||
* the liquid's temperature (in Celsius) so that proper
|
||||
* compensation can take place. How you measure this temperature
|
||||
* is up to you. By default, the device will assume a temperature
|
||||
* of 25C.
|
||||
*
|
||||
* @param temp The temperature of the liquid being measured
|
||||
* @return UPM result
|
||||
*/
|
||||
void setTemperature(float temp);
|
||||
|
||||
/**
|
||||
* Set the K value of the probe being used. By default, this is
|
||||
* 1.0. Valid values are between 0.1 and 10.0.
|
||||
*
|
||||
* @param k The K value of the probe
|
||||
*/
|
||||
void setKValue(float k);
|
||||
|
||||
/**
|
||||
* Enable or disable Sleep mode.
|
||||
*
|
||||
* @param enable True to enable sleep mode, false to wake up
|
||||
*/
|
||||
void setSleep(bool enable);
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Electrical Conductivity (EC)
|
||||
* value in microsiemens. update() must have been called
|
||||
* before calling this function.
|
||||
*
|
||||
* @return EC value in microsiemens
|
||||
*/
|
||||
float getEC();
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Total Dissolved solids (TDS) value.
|
||||
* update() must have been called before calling this
|
||||
* function.
|
||||
*
|
||||
* @return TDS value
|
||||
*/
|
||||
float getTDS();
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Salinity value. update() must
|
||||
* have been called before calling this function.
|
||||
*
|
||||
* @return Salinity value
|
||||
*/
|
||||
float getSalinity();
|
||||
|
||||
/**
|
||||
* Retrieve the last measured Specific Gravity (SG) value.
|
||||
* update() must have been called before calling this
|
||||
* function.
|
||||
*
|
||||
* @return SG value
|
||||
*/
|
||||
float getSG();
|
||||
|
||||
/**
|
||||
* Specify calibration data for calibrating the device. See the
|
||||
* datasheet for details on how calibration is performed. This
|
||||
* function provides a mechanism for clearing out, and setting
|
||||
* calibration data.
|
||||
*
|
||||
* A simple one point calibration might work as follows:
|
||||
*
|
||||
* 1. CLEAR the calibration data
|
||||
* 2. with a dry probe, set the DRY point.
|
||||
* 3. with the probe immersed in a standardized solution, set the
|
||||
* ONE parameter to the solution's known EC value in microsiemens.
|
||||
*
|
||||
* A two point calibration might work as follows:
|
||||
*
|
||||
* 1. CLEAR the calibration data
|
||||
* 2. with a dry probe, set the DRY point.
|
||||
* 3. with the probe immersed in the lowest EC standardized
|
||||
* solution, set the LOW parameter to the solution's known EC
|
||||
* value in microsiemens.
|
||||
* 4. with the probe immersed in the highest EC standardized
|
||||
* solution, set the HIGH parameter to the solution's known EC
|
||||
* value in microsiemens.
|
||||
*
|
||||
* @param cal One of the ECEZO_CALIBRATION_T values
|
||||
* @param ec The EC value of the calibration fluid. This
|
||||
* parameter is ignored when cal is either ECEZO_CALIBRATE_CLEAR
|
||||
* or ECEZO_CALIBRATE_DRY.
|
||||
*/
|
||||
void calibrate(ECEZO_CALIBRATION_T cal, float ec);
|
||||
|
||||
|
||||
protected:
|
||||
// ecezo device context
|
||||
ecezo_context m_ecezo;
|
||||
|
||||
/**
|
||||
* Enable or disable "continuous" operation. In continuous
|
||||
* operation, the device will sample and emit readings every
|
||||
* second. The driver disables this mode by default. If you wish
|
||||
* to use continuous mode, you will be responsible for reading and
|
||||
* parsing the returned data yourself.
|
||||
*
|
||||
* The functionality of this driver depends on continuous mode
|
||||
* being disabled. When disabled, the driver will manually
|
||||
* request a reading when desired via ecezo_update().
|
||||
*
|
||||
* @param enable true to enable continuous mode, false to disable.
|
||||
*/
|
||||
void setContinuous(bool enable);
|
||||
|
||||
/**
|
||||
* Directly send a command to the device and optionally get a
|
||||
* response. This is a low level function and should not be
|
||||
* called unless you know what you are doing.
|
||||
*
|
||||
* @param cmd a String containing the command to send to the
|
||||
* device. See the datasheet for valid commands.
|
||||
* @return The string response, if any
|
||||
*/
|
||||
std::string sendCommand(std::string cmd);
|
||||
|
||||
/**
|
||||
* Read character data from the device. This is a low level
|
||||
* function and should not be called unless you know what you are
|
||||
* doing.
|
||||
*
|
||||
* @return A string containing the data read back, if any
|
||||
*/
|
||||
std::string read();
|
||||
|
||||
/**
|
||||
* Write character data to the device. This is a low level
|
||||
* function and should not be called unless you know what you are
|
||||
* doing.
|
||||
*
|
||||
* @param data The string containing data to write.
|
||||
*/
|
||||
void write(std::string data);
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
45
src/ecezo/ecezo_defs.h
Normal file
45
src/ecezo/ecezo_defs.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// our maximum buffer size
|
||||
#define ECEZO_MAX_BUFFER_LEN (64)
|
||||
|
||||
// calibration commands
|
||||
typedef enum {
|
||||
ECEZO_CALIBRATE_CLEAR = 0, // clear calibration
|
||||
ECEZO_CALIBRATE_DRY, // cal dry point
|
||||
ECEZO_CALIBRATE_ONE, // single point cal EC value
|
||||
ECEZO_CALIBRATE_LOW, // 2-point cal, LOW EC value
|
||||
ECEZO_CALIBRATE_HIGH // 2-point cal, HIGH EC value
|
||||
} ECEZO_CALIBRATION_T;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
88
src/ecezo/ecezo_fti.c
Normal file
88
src/ecezo/ecezo_fti.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 "ecezo.h"
|
||||
#include "upm_fti.h"
|
||||
|
||||
/**
|
||||
* This file implements the Function Table Interface (FTI) for this sensor
|
||||
*/
|
||||
|
||||
const char upm_ecezo_name[] = "ECEZO";
|
||||
const char upm_ecezo_description[] = "EC-EZO EC sensor";
|
||||
const upm_protocol_t upm_ecezo_protocol[] = {UPM_UART, UPM_I2C};
|
||||
const upm_sensor_t upm_ecezo_category[] = {UPM_EC};
|
||||
|
||||
// forward declarations
|
||||
const void* upm_ecezo_get_ft(upm_sensor_t sensor_type);
|
||||
void* upm_ecezo_init_name();
|
||||
void upm_ecezo_close(void *dev);
|
||||
upm_result_t upm_ecezo_get_value(const void *dev, float *value);
|
||||
|
||||
static const upm_sensor_ft ft =
|
||||
{
|
||||
.upm_sensor_init_name = &upm_ecezo_init_name,
|
||||
.upm_sensor_close = &upm_ecezo_close,
|
||||
};
|
||||
|
||||
static const upm_ec_ft ecft =
|
||||
{
|
||||
.upm_ec_get_value = upm_ecezo_get_value
|
||||
};
|
||||
|
||||
const void* upm_ecezo_get_ft(upm_sensor_t sensor_type)
|
||||
{
|
||||
switch(sensor_type)
|
||||
{
|
||||
case UPM_SENSOR:
|
||||
return &ft;
|
||||
|
||||
case UPM_EC:
|
||||
return &ecft;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void* upm_ecezo_init_name()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void upm_ecezo_close(void *dev)
|
||||
{
|
||||
ecezo_close((ecezo_context)dev);
|
||||
}
|
||||
|
||||
upm_result_t upm_ecezo_get_value(const void *dev, float *value)
|
||||
{
|
||||
upm_result_t rv;
|
||||
|
||||
if ((rv = ecezo_update((ecezo_context)dev)))
|
||||
return rv;
|
||||
|
||||
*value = ecezo_get_ec((ecezo_context)dev);
|
||||
return UPM_SUCCESS;
|
||||
}
|
22
src/ecezo/javaupm_ecezo.i
Normal file
22
src/ecezo/javaupm_ecezo.i
Normal file
@ -0,0 +1,22 @@
|
||||
%module javaupm_ecezo
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
%include "stdint.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
%include "ecezo_defs.h"
|
||||
%include "ecezo.hpp"
|
||||
%{
|
||||
#include "ecezo.hpp"
|
||||
%}
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_ecezo");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
9
src/ecezo/jsupm_ecezo.i
Normal file
9
src/ecezo/jsupm_ecezo.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_ecezo
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%include "ecezo_defs.h"
|
||||
%include "ecezo.hpp"
|
||||
%{
|
||||
#include "ecezo.hpp"
|
||||
%}
|
13
src/ecezo/pyupm_ecezo.i
Normal file
13
src/ecezo/pyupm_ecezo.i
Normal file
@ -0,0 +1,13 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_ecezo
|
||||
%include "../upm.i"
|
||||
%include "std_string.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ecezo_defs.h"
|
||||
%include "ecezo.hpp"
|
||||
%{
|
||||
#include "ecezo.hpp"
|
||||
%}
|
@ -32,7 +32,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
ECS1030::ECS1030 (uint8_t pinNumber) {
|
||||
ECS1030::ECS1030 (int pinNumber) {
|
||||
m_dataPinCtx = mraa_aio_init(pinNumber);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
@ -53,7 +53,6 @@ ECS1030::~ECS1030 () {
|
||||
double
|
||||
ECS1030::getCurrency_A () {
|
||||
int sensorValue = 0;
|
||||
float rLoad = 0;
|
||||
float volt = 0;
|
||||
float rms = 0;
|
||||
|
||||
|
@ -83,7 +83,7 @@ class ECS1030 {
|
||||
*
|
||||
* @param pinNumber Number of the data pin
|
||||
*/
|
||||
ECS1030 (uint8_t pinNumber);
|
||||
ECS1030 (int pinNumber);
|
||||
|
||||
/**
|
||||
* ECS1030 object destructor; basically, it closes the GPIO.
|
||||
|
@ -59,10 +59,10 @@ unsigned int ENC03R::value()
|
||||
|
||||
void ENC03R::calibrate(unsigned int samples)
|
||||
{
|
||||
unsigned int val;
|
||||
int val;
|
||||
float total = 0.0;
|
||||
|
||||
for (int i=0; i<samples; i++)
|
||||
for (unsigned int i=0; i<samples; i++)
|
||||
{
|
||||
val = mraa_aio_read(m_aio);
|
||||
if (val == -1) throw std::out_of_range(std::string(__FUNCTION__) +
|
||||
|
@ -92,7 +92,7 @@ Gas::getSample () {
|
||||
void
|
||||
Gas::printGraph (thresholdContext* ctx, uint8_t resolution) {
|
||||
std::cout << "(" << ctx->runningAverage << ") | ";
|
||||
for (int i = 0; i < ctx->runningAverage / resolution; i++)
|
||||
for (unsigned int i = 0; i < ctx->runningAverage / resolution; i++)
|
||||
std::cout << "*";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
struct thresholdContext {
|
||||
long averageReading;
|
||||
long runningAverage;
|
||||
unsigned long runningAverage;
|
||||
int averagedOver;
|
||||
};
|
||||
|
||||
|
@ -29,8 +29,6 @@
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
static const int defaultDelay = 100; // max wait time for read
|
||||
|
||||
GPRS::GPRS(int uart) :
|
||||
m_uart(uart)
|
||||
{
|
||||
|
@ -315,9 +315,14 @@ and is not meant to be installed anywhere.
|
||||
@brief Honeywell
|
||||
|
||||
|
||||
@defgroup maxim Maxim Integrated
|
||||
@defgroup sparkfun Sparkfun
|
||||
@ingroup byman
|
||||
@brief Maxim Integrated
|
||||
@brief Sparkfun
|
||||
|
||||
|
||||
@defgroup maxbotix MaxBotixs
|
||||
@ingroup byman
|
||||
@brief MaxBotixs
|
||||
|
||||
|
||||
@defgroup meas Measurement Specialties
|
||||
|
@ -29,8 +29,6 @@
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
static const int defaultDelay = 100; // max wait time for read
|
||||
|
||||
GroveGPRS::GroveGPRS(int uart) :
|
||||
m_uart(uart)
|
||||
{
|
||||
|
@ -98,7 +98,6 @@ bool GROVESCAM::dataAvailable(unsigned int millis)
|
||||
timeout.tv_usec = (millis % 1000) * 1000;
|
||||
}
|
||||
|
||||
int nfds;
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user