mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 20:31:13 +03:00
Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
@ -14,7 +14,7 @@ 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 +71,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 +86,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)
|
||||
|
||||
@ -184,7 +187,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.1-dirty")
|
||||
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 ()
|
||||
|
@ -4,6 +4,13 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### 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
|
||||
|
@ -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,46 @@ add_example (hka5)
|
||||
add_example (dfrorp)
|
||||
add_example (dfrec)
|
||||
add_example (sht1x)
|
||||
add_example (ms5803)
|
||||
|
||||
# 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)
|
||||
|
@ -20,13 +20,13 @@ void printState(upm::ILightController *lightController)
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int status = 0;
|
||||
upm::ILightController* lightController;
|
||||
|
||||
try {
|
||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int status = 0;
|
||||
upm::ILightController* lightController = nullptr;
|
||||
|
||||
try {
|
||||
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||
std::cout << "Existing state: "; printState(lightController);
|
||||
if (argc == 2)
|
||||
{
|
||||
|
@ -33,40 +33,40 @@ 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)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
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
|
||||
// response is around 320-360nm.
|
||||
// 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
|
||||
upm::GUVAS12D *volts = new upm::GUVAS12D(0);
|
||||
|
||||
// The higher the voltage the more intense the UV radiation.
|
||||
// Instantiate a GUVAS12D on analog pin A0
|
||||
upm::GUVAS12D *volts = new upm::GUVAS12D(0);
|
||||
|
||||
while (shouldRun)
|
||||
// The higher the voltage the more intense the UV radiation.
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "AREF: " << GUVAS12D_AREF
|
||||
<< ", Voltage value (higher means more UV): "
|
||||
<< volts->value(GUVAS12D_AREF, SAMPLES_PER_QUERY) << endl;
|
||||
|
||||
sleep(1);
|
||||
cout << "Volts: " << volts->volts()
|
||||
<< ", Intensity: " << volts->intensity()
|
||||
<< " mW/m^2"
|
||||
<< endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete volts;
|
||||
return 0;
|
||||
delete volts;
|
||||
return 0;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void printUsage(char *progname)
|
||||
<< endl;
|
||||
cout << "sent to the module and the response is printed out." << endl;
|
||||
cout << endl;
|
||||
cout << "If no argument is used, then the address and PIN of the module"
|
||||
cout << "If no argument is used, then the address and PIN of the module"
|
||||
<< endl;
|
||||
cout << "are queried and the results printed out." << endl;
|
||||
cout << endl;
|
||||
@ -52,12 +52,12 @@ void sendCommand(upm::HM11* ble, char *cmd)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
ble->writeData(cmd, strlen(cmd));
|
||||
|
||||
|
||||
// wait up to 1 second
|
||||
if (ble->dataAvailable(1000))
|
||||
{
|
||||
memset(buffer, 0, BUFSIZ);
|
||||
|
||||
|
||||
ble->readData(buffer, BUFSIZ - 1);
|
||||
cout << "Returned: " << buffer << endl;
|
||||
}
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
|
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)
|
||||
|
@ -33,31 +33,34 @@ int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [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;
|
||||
while (shouldRun)
|
||||
{
|
||||
data = dust->getData();
|
||||
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
|
||||
cout << "Ratio: " << data.ratio << endl;
|
||||
cout << "Concentration: " << data.concentration << endl;
|
||||
}
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
upm::PPD42NS* dust = new upm::PPD42NS(8);
|
||||
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]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete dust;
|
||||
return 0;
|
||||
delete dust;
|
||||
return 0;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -132,6 +132,13 @@ 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 (button_intr)
|
||||
add_example (my9221)
|
||||
add_example (ms5803)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
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;
|
||||
}
|
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;
|
||||
}
|
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,7 @@ 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_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
|
@ -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
|
||||
@ -23,24 +24,26 @@
|
||||
*/
|
||||
|
||||
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;
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
private static final float GUVAS12D_AREF = 5;
|
||||
|
||||
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);
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// 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);
|
||||
while (true)
|
||||
{
|
||||
System.out.println("Volts: "
|
||||
+ volts.volts()
|
||||
+ ", Intensity: "
|
||||
+ volts.intensity()
|
||||
+ " mW/m^2");
|
||||
|
||||
System.out.println("AREF: " + GUVAS12D_AREF
|
||||
+ ", Voltage value (higher means more UV): " + value);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// ! [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]
|
||||
}
|
||||
}
|
@ -24,22 +24,22 @@
|
||||
|
||||
public class PPD42NSSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
|
||||
upm_ppd42ns.dustData data;
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// Instantiate a dust sensor on GPIO pin D8
|
||||
upm_ppd42ns.PPD42NS dust = new upm_ppd42ns.PPD42NS(8);
|
||||
upm_ppd42ns.ppd42ns_dust_data data;
|
||||
|
||||
System.out.println("This program will give readings every 30 seconds until you stop it");
|
||||
System.out.println("This program will give readings every 30 seconds until you stop it");
|
||||
|
||||
while (true) {
|
||||
data = dust.getData();
|
||||
while (true) {
|
||||
data = dust.getData();
|
||||
|
||||
System.out.println("Low pulse occupancy: " + data.getLowPulseOccupancy());
|
||||
System.out.println("Ratio: " + data.getRatio());
|
||||
System.out.println("Concentration: " + data.getConcentration());
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
System.out.println("Low pulse occupancy: " + data.getLowPulseOccupancy());
|
||||
System.out.println("Ratio: " + data.getRatio());
|
||||
System.out.println("Concentration: " + data.getConcentration());
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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,26 +25,22 @@
|
||||
|
||||
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);
|
||||
console.log(outputStr);
|
||||
}, 1000);
|
||||
var outputStr = "Volts: "
|
||||
+ myUVSensor.volts()
|
||||
+ ", Intensity: "
|
||||
+ myUVSensor.intensity()
|
||||
+ " mW/m^2";
|
||||
|
||||
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));
|
||||
}
|
||||
console.log(outputStr);
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
|
@ -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
|
||||
|
@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 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.
|
||||
*/
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 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.
|
||||
*/
|
||||
|
||||
//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,22 +33,20 @@ 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()
|
||||
{
|
||||
var result;
|
||||
var moisture_val = parseInt(myMoistureObj.value());
|
||||
if (moisture_val >= 0 && moisture_val < 300)
|
||||
result = "Dry";
|
||||
else if (moisture_val >= 300 && moisture_val < 600)
|
||||
result = "Moist";
|
||||
else
|
||||
result = "Wet";
|
||||
console.log("Moisture value: " + moisture_val + ", " + result);
|
||||
setInterval(function() {
|
||||
var result;
|
||||
var moisture_val = parseInt(myMoistureObj.value());
|
||||
if (moisture_val >= 0 && moisture_val < 300)
|
||||
result = "Dry";
|
||||
else if (moisture_val >= 300 && moisture_val < 600)
|
||||
result = "Moist";
|
||||
else
|
||||
result = "Wet";
|
||||
console.log("Moisture value: " + moisture_val + ", " + result);
|
||||
}, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
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,28 +22,27 @@
|
||||
* 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
|
||||
// waiting one second each time. The LED on the relay switch
|
||||
// will light up when the switch is on (closed).
|
||||
// The switch will also make a noise between transitions.
|
||||
var i = 0;
|
||||
var waiting = setInterval(function() {
|
||||
if ( i % 2 == 0 ) {
|
||||
relay.on();
|
||||
if ( relay.isOn() )
|
||||
console.log(relay.name() + " is on");
|
||||
} else {
|
||||
relay.off();
|
||||
if ( relay.isOff() )
|
||||
console.log(relay.name() + " is off");
|
||||
}
|
||||
i++;
|
||||
if ( i == 6) clearInterval(waiting);
|
||||
}, 1000);
|
||||
|
||||
if (i % 2 == 0) {
|
||||
relay.on();
|
||||
if (relay.isOn())
|
||||
console.log(relay.name() + " is on");
|
||||
} else {
|
||||
relay.off();
|
||||
if (relay.isOff())
|
||||
console.log(relay.name() + " is off");
|
||||
}
|
||||
i++;
|
||||
if (i == 6) clearInterval(waiting);
|
||||
}, 1000);
|
||||
|
@ -22,28 +22,27 @@
|
||||
* 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));
|
||||
console.log("Rel: " + rel + " " + Math.round(parseInt(reldeg)) + " " + relrad.toFixed(3));
|
||||
|
||||
//wait 2 s and call function again
|
||||
//wait 2s and call function again
|
||||
setTimeout(loop, 2000);
|
||||
}
|
||||
|
@ -1,51 +1,49 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 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.
|
||||
*/
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2014 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 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()
|
||||
{
|
||||
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");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
setInterval(getVoltageInfo, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
myVoltageDivider = null;
|
||||
voltageDivider.cleanUp();
|
||||
voltageDivider = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
process.on('SIGINT', function() {
|
||||
myVoltageDivider = null;
|
||||
voltageDivider.cleanUp();
|
||||
voltageDivider = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -22,25 +22,23 @@
|
||||
* 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()
|
||||
{
|
||||
if (water.isWet())
|
||||
console.log("Sensor is wet");
|
||||
else
|
||||
console.log("Sensor is dry");
|
||||
function readWaterState() {
|
||||
if (water.isWet())
|
||||
console.log("Sensor is wet");
|
||||
else
|
||||
console.log("Sensor is dry");
|
||||
}
|
||||
setInterval(readWaterState, 1000);
|
||||
|
||||
// Print message when exiting
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
process.on('SIGINT', function() {
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
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,34 +33,32 @@ myWaterFlow_obj.startFlowCounter();
|
||||
|
||||
|
||||
var millis, flowCount, fr;
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
// we grab these (millis and flowCount) just for display
|
||||
// purposes in this example
|
||||
millis = myWaterFlow_obj.getMillis();
|
||||
flowCount = myWaterFlow_obj.flowCounter();
|
||||
var myInterval = setInterval(function() {
|
||||
// we grab these (millis and flowCount) just for display
|
||||
// purposes in this example
|
||||
millis = myWaterFlow_obj.getMillis();
|
||||
flowCount = myWaterFlow_obj.flowCounter();
|
||||
|
||||
fr = myWaterFlow_obj.flowRate();
|
||||
fr = myWaterFlow_obj.flowRate();
|
||||
|
||||
// output milliseconds passed, flow count, and computed flow rate
|
||||
outputStr = "Millis: " + millis + " Flow Count: " + flowCount +
|
||||
" Flow Rate: " + fr + " LPM";
|
||||
console.log(outputStr);
|
||||
// output milliseconds passed, flow count, and computed flow rate
|
||||
outputStr = "Millis: " + millis + " Flow Count: " + flowCount +
|
||||
" Flow Rate: " + fr + " LPM";
|
||||
console.log(outputStr);
|
||||
|
||||
// best to gather data for at least one second for reasonable
|
||||
// results.
|
||||
// best to gather data for at least one second for reasonable
|
||||
// results.
|
||||
}, 2000);
|
||||
|
||||
|
||||
// When exiting: clear interval and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
myWaterFlow_obj.stopFlowCounter();
|
||||
myWaterFlow_obj = null
|
||||
waterFlow_lib.cleanUp();
|
||||
waterFlow_lib = null;
|
||||
process.on('SIGINT', function() {
|
||||
clearInterval(myInterval);
|
||||
myWaterFlow_obj.stopFlowCounter();
|
||||
myWaterFlow_obj = null
|
||||
waterFlow_lib.cleanUp();
|
||||
waterFlow_lib = null;
|
||||
|
||||
console.log("Exiting");
|
||||
process.exit(0);
|
||||
console.log("Exiting");
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -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)
|
||||
|
||||
|
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}"
|
||||
@ -242,13 +246,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 +549,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;
|
||||
|
@ -2,4 +2,8 @@ set (libname "ads1x15")
|
||||
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()
|
||||
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;
|
||||
|
@ -53,7 +53,6 @@ ECS1030::~ECS1030 () {
|
||||
double
|
||||
ECS1030::getCurrency_A () {
|
||||
int sensorValue = 0;
|
||||
float rLoad = 0;
|
||||
float volt = 0;
|
||||
float rms = 0;
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -34,7 +34,6 @@
|
||||
using namespace upm;
|
||||
|
||||
GroveUltraSonic::GroveUltraSonic (uint8_t pin) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "GroveUltraSonic";
|
||||
|
||||
mraa_init();
|
||||
|
@ -48,9 +48,9 @@ GroveVDiv::~GroveVDiv()
|
||||
|
||||
unsigned int GroveVDiv::value(unsigned int samples)
|
||||
{
|
||||
unsigned int sum = 0;
|
||||
int sum = 0;
|
||||
|
||||
for (int i=0; i<samples; i++)
|
||||
for (unsigned int i=0; i<samples; i++)
|
||||
{
|
||||
sum += mraa_aio_read(m_aio);
|
||||
if (sum == -1) return 0;
|
||||
|
@ -1,5 +1,9 @@
|
||||
set (libname "guvas12d")
|
||||
set (libdescription "Guvas12d UV sensor module")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_hpp ${libname}.hpp)
|
||||
upm_module_init()
|
||||
upm_mixed_module_init (NAME guvas12d
|
||||
DESCRIPTION "Guvas12d analog UV sensor"
|
||||
C_HDR guvas12d.h
|
||||
C_SRC guvas12d.c
|
||||
CPP_HDR guvas12d.hpp
|
||||
CPP_SRC guvas12d.cxx
|
||||
FTI_SRC guvas12d_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa)
|
||||
|
128
src/guvas12d/guvas12d.c
Normal file
128
src/guvas12d/guvas12d.c
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <string.h>
|
||||
#include <upm_utilities.h>
|
||||
|
||||
#include "guvas12d.h"
|
||||
|
||||
guvas12d_context guvas12d_init(int pin, float aref)
|
||||
{
|
||||
guvas12d_context dev =
|
||||
(guvas12d_context)malloc(sizeof(struct _guvas12d_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
memset((void *)dev, 0, sizeof(struct _guvas12d_context));
|
||||
|
||||
// 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);
|
||||
guvas12d_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// initialize the MRAA context
|
||||
|
||||
if (!(dev->aio = mraa_aio_init(pin)))
|
||||
{
|
||||
printf("%s: mraa_aio_init failed.\n", __FUNCTION__);
|
||||
guvas12d_close(dev);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->ares = (float)((1 << mraa_aio_get_bit(dev->aio)) - 1);
|
||||
dev->aref = aref;
|
||||
dev->scale = 1.0;
|
||||
dev->offset = 0.0;
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void guvas12d_close(guvas12d_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->aio)
|
||||
mraa_aio_close(dev->aio);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
upm_result_t guvas12d_get_volts(const guvas12d_context dev, float *volts)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
int val;
|
||||
|
||||
val = mraa_aio_read(dev->aio);
|
||||
if (val < 0)
|
||||
{
|
||||
printf("%s: mraa_aio_read() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
*volts = (float)val * (dev->aref / dev->ares);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t guvas12d_get_intensity(const guvas12d_context dev,
|
||||
float *intensity)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
float volts;
|
||||
if (guvas12d_get_volts(dev, &volts))
|
||||
{
|
||||
printf("%s: guvas12d_get_volts() failed\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
// Seeed magic number 307.0
|
||||
*intensity = volts * 307.0;
|
||||
|
||||
*intensity = *intensity * dev->scale + (dev->offset * dev->scale);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
void guvas12d_set_offset(const guvas12d_context dev, float offset)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
dev->offset = offset;
|
||||
}
|
||||
|
||||
void guvas12d_set_scale(const guvas12d_context dev, float scale)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
dev->scale = scale;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* 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
|
||||
@ -31,36 +31,63 @@
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
GUVAS12D::GUVAS12D(int pin)
|
||||
GUVAS12D::GUVAS12D(int pin, float aref) :
|
||||
m_guvas12d(guvas12d_init(pin, aref))
|
||||
{
|
||||
if ( !(m_aio = mraa_aio_init(pin)) )
|
||||
if (!m_guvas12d)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_aio_init() failed, invalid pin?");
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": guvas12d_init() failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GUVAS12D::~GUVAS12D()
|
||||
{
|
||||
mraa_aio_close(m_aio);
|
||||
guvas12d_close(m_guvas12d);
|
||||
}
|
||||
|
||||
float GUVAS12D::value(float aref, unsigned int samples)
|
||||
{
|
||||
int val;
|
||||
unsigned long sum = 0;
|
||||
(void)(samples); // unused, this method is deprecated.
|
||||
|
||||
for (int i=0; i<samples; i++)
|
||||
// this is a hack, but this function should go away anyway
|
||||
if (aref != m_guvas12d->aref)
|
||||
m_guvas12d->aref = aref;
|
||||
|
||||
return volts();
|
||||
}
|
||||
|
||||
float GUVAS12D::volts()
|
||||
{
|
||||
float volts;
|
||||
if (guvas12d_get_volts(m_guvas12d, &volts))
|
||||
{
|
||||
val = mraa_aio_read(m_aio);
|
||||
if (val == -1) return -1;
|
||||
sum += val;
|
||||
usleep(2000);
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": guvas12d_get_volts() failed");
|
||||
}
|
||||
|
||||
sum = sum / samples;
|
||||
float volts = (float)sum * aref / 1024.0;
|
||||
|
||||
return volts;
|
||||
return volts;
|
||||
}
|
||||
|
||||
float GUVAS12D::intensity()
|
||||
{
|
||||
float i;
|
||||
if (guvas12d_get_intensity(m_guvas12d, &i))
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": guvas12d_get_intensity() failed");
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void GUVAS12D::setScale(float scale)
|
||||
{
|
||||
guvas12d_set_scale(m_guvas12d, scale);
|
||||
}
|
||||
|
||||
void GUVAS12D::setOffset(float offset)
|
||||
{
|
||||
guvas12d_set_offset(m_guvas12d, offset);
|
||||
}
|
||||
|
108
src/guvas12d/guvas12d.h
Normal file
108
src/guvas12d/guvas12d.h
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <upm.h>
|
||||
#include <mraa/aio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file guvas12d.h
|
||||
* @library guvas12d
|
||||
* @brief C API for the guvas12d driver
|
||||
*
|
||||
* @include guvas12d.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* Device context
|
||||
*/
|
||||
typedef struct _guvas12d_context {
|
||||
mraa_aio_context aio;
|
||||
|
||||
// ADC reference voltage
|
||||
float aref;
|
||||
// ADC resolution
|
||||
float ares;
|
||||
|
||||
float scale;
|
||||
float offset;
|
||||
} *guvas12d_context;
|
||||
|
||||
/**
|
||||
* GUVA-S12D UV sensor constructor
|
||||
*
|
||||
* @param pin Analog pin to use
|
||||
*/
|
||||
guvas12d_context guvas12d_init(int pin, float aref);
|
||||
|
||||
/**
|
||||
* GUVAS12D destructor
|
||||
*/
|
||||
void guvas12d_close(guvas12d_context dev);
|
||||
|
||||
/**
|
||||
* Gets the voltage value from the sensor
|
||||
*
|
||||
* @param volts Pointer to average voltage reading
|
||||
* @return UPM status.
|
||||
*/
|
||||
upm_result_t guvas12d_get_volts(const guvas12d_context dev, float *volts);
|
||||
|
||||
/**
|
||||
* Gets the illumination intensity in mW/m^2
|
||||
*
|
||||
* @param volts Pointer to average voltage reading
|
||||
* @return UPM status.
|
||||
* @return illumination intensity in mW/m^2
|
||||
*/
|
||||
upm_result_t guvas12d_get_intensity(const guvas12d_context dev,
|
||||
float *intensity);
|
||||
|
||||
/**
|
||||
* Set sensor offset. This offset is applied to the illumination
|
||||
* intensity value before scaling. Default is 0.0.
|
||||
*
|
||||
* @param dev sensor context pointer
|
||||
* @param offset Offset to apply.
|
||||
*/
|
||||
void guvas12d_set_offset(const guvas12d_context dev, float offset);
|
||||
|
||||
/**
|
||||
* Set sensor scale. This offset is applied to the illumination
|
||||
* intensity value before scaling. Default is 1.0.
|
||||
*
|
||||
* @param dev sensor context pointer
|
||||
* @param scale Scale to apply.
|
||||
*/
|
||||
void guvas12d_set_scale(const guvas12d_context dev, float scale);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* 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
|
||||
@ -23,55 +23,96 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <guvas12d.h>
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief GUVA-S12D UV sensor library
|
||||
* @defgroup guvas12d libupm-guvas12d
|
||||
* @ingroup seeed analog light eak
|
||||
*/
|
||||
/**
|
||||
* @brief GUVA-S12D UV sensor library
|
||||
* @defgroup guvas12d libupm-guvas12d
|
||||
* @ingroup seeed analog light eak
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library guvas12d
|
||||
* @sensor guvas12d
|
||||
* @comname Grove UV Sensor
|
||||
* @altname GUVA-S12D UV Sensor
|
||||
* @type light
|
||||
* @man seeed
|
||||
* @con analog
|
||||
* @kit eak
|
||||
*
|
||||
* @brief API for the GUVA-S12D UV Sensor
|
||||
*
|
||||
* UPM module for the GUVA-S12D UV sensor
|
||||
*
|
||||
* @image html guvas12d.jpg
|
||||
* @snippet guvas12d.cxx Interesting
|
||||
*/
|
||||
class GUVAS12D {
|
||||
public:
|
||||
/**
|
||||
* GUVA-S12D UV sensor constructor
|
||||
* @library guvas12d
|
||||
* @sensor guvas12d
|
||||
* @comname Grove UV Sensor
|
||||
* @altname GUVA-S12D UV Sensor
|
||||
* @type light
|
||||
* @man seeed
|
||||
* @con analog
|
||||
* @kit eak
|
||||
*
|
||||
* @param pin Analog pin to use
|
||||
*/
|
||||
GUVAS12D(int pin);
|
||||
/**
|
||||
* GUVAS12D destructor
|
||||
*/
|
||||
~GUVAS12D();
|
||||
/**
|
||||
* Gets the average voltage value from the sensor
|
||||
* @brief API for the GUVA-S12D UV Sensor
|
||||
*
|
||||
* @param aref Reference voltage in use (usually 5.0 V or 3.3 V)
|
||||
* @param samples Number of samples to average over
|
||||
* @return Average voltage reading
|
||||
* UPM module for the GUVA-S12D UV sensor
|
||||
*
|
||||
* @image html guvas12d.jpg
|
||||
* @snippet guvas12d.cxx Interesting
|
||||
*/
|
||||
float value(float aref, unsigned int samples);
|
||||
class GUVAS12D {
|
||||
public:
|
||||
|
||||
private:
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
/**
|
||||
* GUVA-S12D UV sensor constructor
|
||||
*
|
||||
* @param pin Analog pin to use
|
||||
* @param aref Analog reference voltage to use
|
||||
*/
|
||||
GUVAS12D(int pin, float aref=5.0);
|
||||
|
||||
/**
|
||||
* GUVAS12D destructor
|
||||
*/
|
||||
~GUVAS12D();
|
||||
|
||||
/**
|
||||
* @deprecated This method is being replaced by the volts()
|
||||
* and illumination() methods.
|
||||
*
|
||||
* Gets the average voltage value from the sensor
|
||||
*
|
||||
* @param aref Reference voltage in use (usually 5.0 V or 3.3 V)
|
||||
* @param samples Number of samples to average over (currently
|
||||
* ignored)
|
||||
* @return Average voltage reading
|
||||
*
|
||||
*/
|
||||
float value(float aref, unsigned int samples);
|
||||
|
||||
/**
|
||||
* Gets the voltage value from the sensor
|
||||
*
|
||||
* @return Voltage reading
|
||||
*
|
||||
*/
|
||||
float volts();
|
||||
|
||||
/**
|
||||
* Gets the computed illumination intensity from the sensor in
|
||||
* mW/m^2.
|
||||
*
|
||||
* @return Intensity over the sensitive wavelengths in mW/m^2
|
||||
*
|
||||
*/
|
||||
float intensity();
|
||||
|
||||
/**
|
||||
* Set sensor scale. This scale is applied to the intensity value
|
||||
* before the offset is applied. Default is 1.0.
|
||||
*
|
||||
* @param scale Scale to apply.
|
||||
*/
|
||||
void setScale(float scale);
|
||||
|
||||
/**
|
||||
* Set sensor offset. This offset is applied to the intensity
|
||||
* value before scaling. Default is 0.0.
|
||||
*
|
||||
* @param offset Offset to apply.
|
||||
*/
|
||||
void setOffset(float offset);
|
||||
|
||||
private:
|
||||
guvas12d_context m_guvas12d;
|
||||
};
|
||||
}
|
||||
|
119
src/guvas12d/guvas12d_fti.c
Normal file
119
src/guvas12d/guvas12d_fti.c
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "guvas12d.h"
|
||||
#include "fti/upm_sensor.h"
|
||||
#include "fti/upm_voltage.h"
|
||||
|
||||
/**
|
||||
* This file implements the Function Table Interface (FTI) for this sensor
|
||||
*/
|
||||
|
||||
const char upm_guvas12d_name[] = "GUVAS12D";
|
||||
const char upm_guvas12d_description[] = "Analog UV sensor";
|
||||
const upm_protocol_t upm_guvas12d_protocol[] = {UPM_ANALOG};
|
||||
const upm_sensor_t upm_guvas12d_category[] = {UPM_VOLTAGE};
|
||||
|
||||
// forward declarations
|
||||
void* upm_guvas12d_init_str(const char* protocol, const char* params);
|
||||
void upm_guvas12d_close(void* dev);
|
||||
const void* upm_guvas12d_get_ft(upm_sensor_t sensor_type);
|
||||
const upm_sensor_descriptor_t upm_guvas12d_get_descriptor();
|
||||
upm_result_t upm_guvas12d_set_offset(const void* dev, float offset);
|
||||
upm_result_t upm_guvas12d_set_scale(const void* dev, float scale);
|
||||
upm_result_t upm_guvas12d_get_value(const void* dev, float *value);
|
||||
|
||||
/* This sensor implementes 2 function tables */
|
||||
/* 1. Generic base function table */
|
||||
static const upm_sensor_ft ft_gen =
|
||||
{
|
||||
.upm_sensor_init_name = &upm_guvas12d_init_str,
|
||||
.upm_sensor_close = &upm_guvas12d_close,
|
||||
.upm_sensor_get_descriptor = &upm_guvas12d_get_descriptor
|
||||
};
|
||||
|
||||
/* 2. VOLTAGE function table */
|
||||
static const upm_voltage_ft ft_voltage =
|
||||
{
|
||||
.upm_voltage_set_offset = &upm_guvas12d_set_offset,
|
||||
.upm_voltage_set_scale = &upm_guvas12d_set_scale,
|
||||
.upm_voltage_get_value = &upm_guvas12d_get_value
|
||||
};
|
||||
|
||||
const void* upm_guvas12d_get_ft(upm_sensor_t sensor_type)
|
||||
{
|
||||
switch(sensor_type)
|
||||
{
|
||||
case UPM_SENSOR:
|
||||
return &ft_gen;
|
||||
case UPM_VOLTAGE:
|
||||
return &ft_voltage;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void* upm_guvas12d_init_str(const char* protocol, const char* params)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void upm_guvas12d_close(void* dev)
|
||||
{
|
||||
guvas12d_close((guvas12d_context)dev);
|
||||
}
|
||||
|
||||
const upm_sensor_descriptor_t upm_guvas12d_get_descriptor()
|
||||
{
|
||||
/* Fill in the descriptor */
|
||||
upm_sensor_descriptor_t usd;
|
||||
usd.name = upm_guvas12d_name;
|
||||
usd.description = upm_guvas12d_description;
|
||||
usd.protocol_size = 1;
|
||||
usd.protocol = upm_guvas12d_protocol;
|
||||
usd.category_size = 1;
|
||||
usd.category = upm_guvas12d_category;
|
||||
|
||||
return usd;
|
||||
}
|
||||
|
||||
upm_result_t upm_guvas12d_set_offset(const void* dev, float offset)
|
||||
{
|
||||
guvas12d_set_offset((guvas12d_context)dev, offset);
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t upm_guvas12d_set_scale(const void* dev, float scale)
|
||||
{
|
||||
guvas12d_set_scale((guvas12d_context)dev, scale);
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t upm_guvas12d_get_value(const void* dev, float *value)
|
||||
{
|
||||
return guvas12d_get_volts((guvas12d_context)dev, value);
|
||||
}
|
@ -39,7 +39,6 @@
|
||||
using namespace upm;
|
||||
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "HCSR04";
|
||||
|
||||
m_triggerPinCtx = mraa_gpio_init (triggerPin);
|
||||
|
@ -141,11 +141,11 @@ namespace upm {
|
||||
|
||||
|
||||
protected:
|
||||
mraa::Aio m_aioHum;
|
||||
|
||||
// temperature is an optional feature of the humidity transmitter
|
||||
mraa::Aio *m_aioTemp;
|
||||
|
||||
mraa::Aio m_aioHum;
|
||||
|
||||
private:
|
||||
float m_aref;
|
||||
int m_aResTemp;
|
||||
|
@ -31,8 +31,6 @@
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
static const int defaultDelay = 100; // max wait time for read
|
||||
|
||||
HM11::HM11(int uart)
|
||||
{
|
||||
m_ttyFd = -1;
|
||||
@ -82,7 +80,6 @@ bool HM11::dataAvailable(unsigned int millis)
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = millis * 1000;
|
||||
|
||||
int nfds;
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
|
@ -85,7 +85,6 @@ bool HMTRP::dataAvailable(unsigned int millis)
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = millis * 1000;
|
||||
|
||||
int nfds;
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
|
@ -174,7 +174,7 @@ HTU21D::getDewPoint(int bSampleData)
|
||||
int
|
||||
HTU21D::getHumidityData(float* pfHum, float* pfHumTemp, float* pfDewPt)
|
||||
{
|
||||
float fHum = getHumidity(true);
|
||||
getHumidity(true);
|
||||
float fTemp = getTemperature(false);
|
||||
float fDewPt = getDewPoint(false);
|
||||
float fCHum = getCompRH(false);
|
||||
@ -202,15 +202,14 @@ HTU21D::testSensor(void)
|
||||
int iError = 0;
|
||||
float fTemp, fHum;
|
||||
float fTempMax, fTempMin;
|
||||
float fHumMax, fHumMin;
|
||||
float fHumFirst, fTempFirst;
|
||||
float fHumMax = 0.0, fHumMin = 0.0;
|
||||
float fTempFirst;
|
||||
|
||||
fprintf(stdout, "Executing Sensor Test\n" );
|
||||
|
||||
fHum = getHumidity(true);
|
||||
fTemp = getTemperature(false);
|
||||
fTempFirst = fTempMax = fTempMin = fTemp;
|
||||
fHumFirst = fHumMax = fHumMin = fHum;
|
||||
|
||||
// Turn on the heater to make a sensor change
|
||||
setHeater(true);
|
||||
@ -271,7 +270,6 @@ HTU21D::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
|
||||
uint16_t
|
||||
HTU21D::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
m_i2ControlCtx.address(m_controlAddr);
|
||||
return m_i2ControlCtx.readWordReg(reg);
|
||||
}
|
||||
|
@ -160,26 +160,26 @@ namespace upm {
|
||||
* @param rst Reset pin
|
||||
*/
|
||||
ILI9341(uint8_t csLCD, uint8_t csSD, uint8_t dc, uint8_t rst);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
*/
|
||||
std::string name() {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes GPIOs used to talk to the LCD
|
||||
*/
|
||||
void initModule();
|
||||
|
||||
|
||||
/**
|
||||
* Configures the LCD driver chip via SPI
|
||||
*/
|
||||
void configModule();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the window size inside the screen where pixel data is
|
||||
* Sets the window size inside the screen where pixel data is
|
||||
* written. Concrete implementation from GFX interface.
|
||||
*
|
||||
* @param x0 First coordinate
|
||||
@ -187,11 +187,11 @@ namespace upm {
|
||||
* @param x1 Second coordinate
|
||||
* @param y1 Second coordinate
|
||||
*/
|
||||
void setAddrWindow(uint16_t x0,
|
||||
uint16_t y0,
|
||||
uint16_t x1,
|
||||
void setAddrWindow(uint16_t x0,
|
||||
uint16_t y0,
|
||||
uint16_t x1,
|
||||
uint16_t y1);
|
||||
|
||||
|
||||
/**
|
||||
* Sends a pixel color (RGB) to the driver chip. Concrete
|
||||
* implementation from GFX interface.
|
||||
@ -211,7 +211,7 @@ namespace upm {
|
||||
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
|
||||
*/
|
||||
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
|
||||
|
||||
/**
|
||||
* Draws a horizontal line using minimal SPI writes.
|
||||
*
|
||||
@ -221,7 +221,7 @@ namespace upm {
|
||||
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
|
||||
*/
|
||||
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
|
||||
|
||||
/**
|
||||
* Draw a filled rectangle.
|
||||
*
|
||||
@ -231,33 +231,33 @@ namespace upm {
|
||||
* @param h Height of rectangle in pixels
|
||||
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
|
||||
*/
|
||||
void fillRect(int16_t x,
|
||||
int16_t y,
|
||||
int16_t w,
|
||||
void fillRect(int16_t x,
|
||||
int16_t y,
|
||||
int16_t w,
|
||||
int16_t h,
|
||||
uint16_t color);
|
||||
|
||||
|
||||
/**
|
||||
* Fill the screen with a single color.
|
||||
*
|
||||
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15]
|
||||
*/
|
||||
void fillScreen(uint16_t color);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the screen to one of four 90 deg rotations.
|
||||
*
|
||||
* @param r Rotation setting: 0, 1, 2, 3
|
||||
*/
|
||||
void setRotation(uint8_t r);
|
||||
|
||||
|
||||
/**
|
||||
* Invert colors on the display.
|
||||
*
|
||||
* @param i True or false to invert colors
|
||||
*/
|
||||
void invertDisplay(bool i);
|
||||
|
||||
|
||||
/**
|
||||
* Pass 8-bit R, G, B values and get back 16-bit packed color.
|
||||
*
|
||||
@ -267,77 +267,76 @@ namespace upm {
|
||||
* @return 16-bit packed color (RGB) value
|
||||
*/
|
||||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
|
||||
/**
|
||||
* Executes a set of commands and data.
|
||||
*
|
||||
* @param addr Pointer to the start of the commands/data section
|
||||
*/
|
||||
void executeCMDList(const uint8_t *addr);
|
||||
|
||||
|
||||
/**
|
||||
* Sends a command to the display driver via SPI.
|
||||
*
|
||||
* @param c Command to be written
|
||||
*/
|
||||
void writecommand(uint8_t c);
|
||||
|
||||
|
||||
/**
|
||||
* Sends data to the display driver via SPI
|
||||
*
|
||||
* @param d Data to be written
|
||||
*/
|
||||
void writedata(uint8_t d);
|
||||
|
||||
|
||||
/**
|
||||
* Set LCD chip select to LOW
|
||||
*/
|
||||
mraa::Result lcdCSOn();
|
||||
|
||||
|
||||
/**
|
||||
* Set LCD chip select to HIGH
|
||||
*/
|
||||
mraa::Result lcdCSOff();
|
||||
|
||||
|
||||
/**
|
||||
* Set SD card chip select to LOW
|
||||
*/
|
||||
mraa::Result sdCSOn();
|
||||
|
||||
|
||||
/**
|
||||
* Set SD card chip select to HIGH
|
||||
*/
|
||||
mraa::Result sdCSOff();
|
||||
|
||||
|
||||
/**
|
||||
* Set data/command line to HIGH
|
||||
*/
|
||||
mraa::Result dcHigh();
|
||||
|
||||
|
||||
/**
|
||||
* Set data/command line to LOW
|
||||
*/
|
||||
mraa::Result dcLow();
|
||||
|
||||
|
||||
/**
|
||||
* Set reset line to HIGH
|
||||
*/
|
||||
mraa::Result rstHigh();
|
||||
|
||||
|
||||
/**
|
||||
* Set reset line to LOW
|
||||
*/
|
||||
mraa::Result rstLow();
|
||||
|
||||
|
||||
private:
|
||||
mraa::Spi m_spi;
|
||||
uint8_t m_spiBuffer[32];
|
||||
|
||||
mraa::Gpio m_csLCDPinCtx;
|
||||
mraa::Gpio m_csSDPinCtx;
|
||||
mraa::Gpio m_dcPinCtx;
|
||||
mraa::Gpio m_rstPinCtx;
|
||||
|
||||
|
||||
mraa::Spi m_spi;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
||||
|
@ -179,7 +179,6 @@ KXCJK1013::extract3Axis(char* data, float* x, float* y, float* z)
|
||||
{
|
||||
mraa_iio_channel* channels = mraa_iio_get_channels(m_iio);
|
||||
float tmp[3];
|
||||
int i = 0;
|
||||
int iio_x, iio_y, iio_z;
|
||||
|
||||
iio_x = getChannelValue((unsigned char*) (data + channels[0].location), &channels[0]);
|
||||
|
@ -364,11 +364,10 @@ namespace upm
|
||||
mraa::Result setAddressingMode(displayAddressingMode mode);
|
||||
|
||||
private:
|
||||
mraa::Spi m_spi;
|
||||
mraa::Gpio m_gpioCD; // command(0)/data(1)
|
||||
mraa::Gpio m_gpioRST; // reset pin
|
||||
|
||||
mraa::Spi m_spi;
|
||||
|
||||
uint8_t m_cursorX;
|
||||
uint8_t m_cursorY;
|
||||
uint8_t m_textSize;
|
||||
|
@ -35,7 +35,7 @@
|
||||
using namespace upm;
|
||||
|
||||
Jhd1313m1::Jhd1313m1(int bus, int lcdAddress, int rgbAddress)
|
||||
: m_i2c_lcd_rgb(bus), Lcm1602(bus, lcdAddress, false)
|
||||
: Lcm1602(bus, lcdAddress, false), m_i2c_lcd_rgb(bus)
|
||||
{
|
||||
m_rgb_address = rgbAddress;
|
||||
m_name = "Jhd1313m1";
|
||||
|
@ -42,10 +42,10 @@ using namespace upm;
|
||||
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander,
|
||||
uint8_t numColumns, uint8_t numRows) :
|
||||
m_numColumns(numColumns), m_numRows(numRows),
|
||||
m_i2c_lcd_control(new mraa::I2c(bus_in)),
|
||||
m_gpioRS(0), m_gpioEnable(0), m_gpioD0(0),
|
||||
m_gpioD1(0), m_gpioD2(0), m_gpioD3(0),
|
||||
m_numColumns(numColumns), m_numRows(numRows)
|
||||
m_gpioD1(0), m_gpioD2(0), m_gpioD3(0)
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "Lcm1602 (I2C)";
|
||||
@ -103,13 +103,12 @@ Lcm1602::Lcm1602(int bus_in, int addr_in, bool isExpander,
|
||||
Lcm1602::Lcm1602(uint8_t rs, uint8_t enable, uint8_t d0,
|
||||
uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t numColumns, uint8_t numRows) :
|
||||
m_numColumns(numColumns), m_numRows(numRows),
|
||||
m_i2c_lcd_control(0),
|
||||
m_gpioRS(new mraa::Gpio(rs)), m_gpioEnable(new mraa::Gpio(enable)),
|
||||
m_gpioD0(new mraa::Gpio(d0)), m_gpioD1(new mraa::Gpio(d1)),
|
||||
m_gpioD2(new mraa::Gpio(d2)), m_gpioD3(new mraa::Gpio(d3)),
|
||||
m_numColumns(numColumns), m_numRows(numRows)
|
||||
m_gpioD2(new mraa::Gpio(d2)), m_gpioD3(new mraa::Gpio(d3))
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "Lcm1602 (4-bit GPIO)";
|
||||
m_isI2C = false;
|
||||
m_backlight = LCD_BACKLIGHT;
|
||||
@ -202,7 +201,6 @@ Lcm1602::write(std::string msg)
|
||||
mraa::Result
|
||||
Lcm1602::setCursor(int row, int column)
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
column = column % m_numColumns;
|
||||
uint8_t offset = column;
|
||||
|
||||
|
@ -254,7 +254,17 @@ class Lcm1602 : public LCD
|
||||
// Display size
|
||||
uint8_t m_numColumns;
|
||||
uint8_t m_numRows;
|
||||
|
||||
|
||||
mraa::I2c* m_i2c_lcd_control;
|
||||
|
||||
// gpio operation
|
||||
mraa::Gpio* m_gpioRS;
|
||||
mraa::Gpio* m_gpioEnable;
|
||||
mraa::Gpio* m_gpioD0;
|
||||
mraa::Gpio* m_gpioD1;
|
||||
mraa::Gpio* m_gpioD2;
|
||||
mraa::Gpio* m_gpioD3;
|
||||
|
||||
// Backlight
|
||||
uint8_t m_backlight;
|
||||
|
||||
@ -266,19 +276,10 @@ class Lcm1602 : public LCD
|
||||
virtual mraa::Result data(uint8_t data);
|
||||
|
||||
int m_lcd_control_address;
|
||||
mraa::I2c* m_i2c_lcd_control;
|
||||
|
||||
private:
|
||||
|
||||
// true if using i2c, false otherwise (gpio)
|
||||
bool m_isI2C;
|
||||
|
||||
// gpio operation
|
||||
mraa::Gpio* m_gpioRS;
|
||||
mraa::Gpio* m_gpioEnable;
|
||||
mraa::Gpio* m_gpioD0;
|
||||
mraa::Gpio* m_gpioD1;
|
||||
mraa::Gpio* m_gpioD2;
|
||||
mraa::Gpio* m_gpioD3;
|
||||
};
|
||||
}
|
||||
|
@ -78,15 +78,12 @@ SSD1308::draw(uint8_t* data, int bytes)
|
||||
mraa::Result
|
||||
SSD1308::write(std::string msg)
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
uint8_t data[2] = { 0x40, 0 };
|
||||
|
||||
setAddressingMode(PAGE);
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
writeChar(msg[i]);
|
||||
}
|
||||
|
||||
return error;
|
||||
return mraa::SUCCESS;
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
@ -108,7 +105,6 @@ SSD1308::setCursor(int row, int column)
|
||||
mraa::Result
|
||||
SSD1308::clear()
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
m_i2c_lcd_control.writeReg(LCD_CMD, DISPLAY_CMD_OFF); // display off
|
||||
|
@ -215,7 +215,6 @@ SSD1327::setCursor(int row, int column)
|
||||
mraa::Result
|
||||
SSD1327::clear()
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
for (rowIdx = 0; rowIdx < 12; rowIdx++) {
|
||||
|
@ -36,8 +36,6 @@ using namespace upm;
|
||||
static mraa_gpio_context *m_Ctx;
|
||||
static unsigned char *buffer;
|
||||
|
||||
static mraa_gpio_context c1, c2, c3, c4;
|
||||
|
||||
static int charlie_pairs [12][22] = {
|
||||
{3,124, 4,110, 5,96, 6,82, 7,68, 8,54, 9,40, 10,26, 11,12, -1,-1, -1,-1},
|
||||
{3,122, 4,108, 5,94, 6,80, 7,66, 8,52, 9,38, 10,24, 11,10, -1,-1, -1,-1},
|
||||
@ -132,11 +130,11 @@ void *do_draw(void *arg)
|
||||
}
|
||||
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LoL::LoL() {
|
||||
int i = 0;
|
||||
mraa_result_t error;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if ( !(m_LoLCtx[i] = mraa_gpio_init(i+2)) )
|
||||
@ -159,7 +157,6 @@ LoL::LoL() {
|
||||
|
||||
LoL::~LoL() {
|
||||
int i = 0;
|
||||
mraa_result_t error;
|
||||
for (i = 0; i < 12; i++)
|
||||
mraa_gpio_close(m_LoLCtx[i]);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) :m_spi(0), m_csnPinCtx(csn) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "LPD8806";
|
||||
|
||||
@ -60,13 +60,11 @@ LPD8806::LPD8806 (uint16_t pixelCount, uint8_t csn) : m_csnPinCtx(csn), m_spi(0)
|
||||
|
||||
uint8_t latchBytes;
|
||||
uint16_t dataBytes, totalBytes;
|
||||
uint16_t numBytes = 0;
|
||||
|
||||
dataBytes = m_pixelsCount * 3;
|
||||
latchBytes = (m_pixelsCount + 31) / 32;
|
||||
totalBytes = dataBytes + latchBytes;
|
||||
if ((m_pixels = (uint8_t *) malloc(totalBytes))) {
|
||||
numBytes = totalBytes;
|
||||
memset ( m_pixels , 0x80, dataBytes); // Init to RGB 'off' state
|
||||
memset (&m_pixels[dataBytes], 0 , latchBytes); // Clear latch bytes
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX31723::MAX31723 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
MAX31723::MAX31723 (int csn) : m_spi(0), m_csnPinCtx(csn) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "MAX31723";
|
||||
|
||||
@ -51,11 +51,10 @@ MAX31723::MAX31723 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
|
||||
short
|
||||
MAX31723::getTemperature () {
|
||||
uint8_t lsb = 0;
|
||||
uint8_t msb = 0;
|
||||
short temperature = 0;
|
||||
|
||||
lsb = readRegister (R_TEMPERATURE_LSB);
|
||||
readRegister (R_TEMPERATURE_LSB);
|
||||
msb = readRegister (R_TEMPERATURE_MSB);
|
||||
|
||||
if ((msb & 0x80) != 0) {
|
||||
@ -91,12 +90,11 @@ MAX31723::readRegister (uint8_t reg) {
|
||||
void
|
||||
MAX31723::writeRegister (uint8_t reg, uint8_t data) {
|
||||
uint8_t buffer[2] = { 0x00, 0x00 };
|
||||
uint8_t* sensorData = NULL;
|
||||
|
||||
CSOn ();
|
||||
buffer[0] = reg;
|
||||
buffer[1] = data;
|
||||
sensorData = m_spi.write(buffer, 2);
|
||||
m_spi.write(buffer, 2);
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,6 @@ MAX44009::reset() {
|
||||
|
||||
uint16_t
|
||||
MAX44009::getVisibleRaw() {
|
||||
uint8_t exponent, mantissa;
|
||||
uint8_t data[MAX44009_LUX_LENGTH];
|
||||
uint16_t* value = reinterpret_cast<uint16_t*>(&data[0]);
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MAX5487::MAX5487 (int csn) : m_csnPinCtx(csn), m_spi(0) {
|
||||
MAX5487::MAX5487 (int csn) :m_spi(0), m_csnPinCtx(csn) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
m_name = "MAX5487";
|
||||
|
||||
@ -57,7 +57,7 @@ MAX5487::setWiperA (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_A;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
@ -71,7 +71,7 @@ MAX5487::setWiperB (uint8_t wiper) {
|
||||
data[0] = R_WR_WIPER_B;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = m_spi.write(data, 2);
|
||||
m_spi.write(data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
@ -84,7 +84,6 @@ bool MHZ16::dataAvailable(unsigned int millis)
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = millis * 1000;
|
||||
|
||||
int nfds;
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
|
@ -84,7 +84,7 @@ int
|
||||
Microphone::findThreshold (thresholdContext* ctx, unsigned int threshold,
|
||||
uint16_t * buffer, int len) {
|
||||
long sum = 0;
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
sum += buffer[i];
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ Microphone::findThreshold (thresholdContext* ctx, unsigned int threshold,
|
||||
|
||||
void
|
||||
Microphone::printGraph (thresholdContext* ctx) {
|
||||
for (int i = 0; i < ctx->runningAverage; i++)
|
||||
for (unsigned int i = 0; i < ctx->runningAverage; i++)
|
||||
std::cout << ".";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
struct thresholdContext {
|
||||
long averageReading;
|
||||
long runningAverage;
|
||||
unsigned long runningAverage;
|
||||
int averagedOver;
|
||||
};
|
||||
|
||||
|
@ -37,7 +37,6 @@ using namespace upm;
|
||||
|
||||
MMA7455::MMA7455 (int bus, int devAddr) : m_i2ControlCtx(bus) {
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
m_name = "MMA7455";
|
||||
|
||||
@ -98,7 +97,6 @@ MMA7455::calibrate () {
|
||||
mraa::Result
|
||||
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
accelData xyz;
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
/*do {
|
||||
|
@ -72,8 +72,7 @@ MPL3115A2::MPL3115A2 (int bus, int devAddr, uint8_t mode) : m_i2ControlCtx(bus)
|
||||
int
|
||||
MPL3115A2::testSensor(void)
|
||||
{
|
||||
int i, iTries;
|
||||
int iError = 0;
|
||||
int iTries;
|
||||
float pressure, temperature;
|
||||
float fPMin, fPMax, fTMin, fTMax;
|
||||
|
||||
@ -113,7 +112,7 @@ MPL3115A2::testSensor(void)
|
||||
void
|
||||
MPL3115A2::dumpSensor(void)
|
||||
{
|
||||
int i, j, ival;
|
||||
int i, j;
|
||||
|
||||
fprintf(stdout, "Dumping i2c block from %s\n", MPL3115A2_NAME);
|
||||
for (i=0; i < 256; i+=16) {
|
||||
|
@ -661,8 +661,8 @@ namespace upm {
|
||||
/**
|
||||
* MPU60X0 Destructor
|
||||
*/
|
||||
~MPU60X0();
|
||||
|
||||
virtual ~MPU60X0();
|
||||
|
||||
/**
|
||||
* set up initial values and start operation
|
||||
*
|
||||
|
@ -32,7 +32,7 @@ using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
MPU9150::MPU9150 (int bus, int address, int magAddress, bool enableAk8975) :
|
||||
m_mag(0), MPU60X0(bus, address)
|
||||
MPU60X0(bus, address), m_mag(0)
|
||||
{
|
||||
m_magAddress = magAddress;
|
||||
m_i2cBus = bus;
|
||||
|
@ -75,7 +75,7 @@ namespace upm {
|
||||
/**
|
||||
* MPU9150 destructor
|
||||
*/
|
||||
~MPU9150 ();
|
||||
virtual ~MPU9150 ();
|
||||
|
||||
/**
|
||||
* Set up initial values and start operation
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user