Compare commits
77 Commits
Author | SHA1 | Date | |
---|---|---|---|
f1f9d9ec2e | |||
74d625c797 | |||
2695ef3361 | |||
a9548f3ff4 | |||
3ed0e14487 | |||
1a80400fa9 | |||
9845b24dea | |||
af7f544387 | |||
ac5c20afad | |||
9f3557aa20 | |||
d112266170 | |||
94fdd86896 | |||
c0c99fd87a | |||
684919f069 | |||
37add7eb33 | |||
e17dc9a22e | |||
84c3445412 | |||
6b2850557e | |||
f94ee6a388 | |||
cbb289438e | |||
71b0791239 | |||
757a2ce342 | |||
3fab5625c7 | |||
5324808e82 | |||
7d64e5458f | |||
ab15d1e98f | |||
d9b761469d | |||
2098449c56 | |||
63c75be370 | |||
03b4d24e64 | |||
9d1afd35f8 | |||
022b546003 | |||
1d085362d9 | |||
3504dc7246 | |||
5b7522bec4 | |||
828a9ce7d8 | |||
8cec2ad473 | |||
c3e3a6bb17 | |||
11b5d3bc58 | |||
3522e4ee8f | |||
0f548d367b | |||
1786017006 | |||
2d68d707f6 | |||
d7f4b76ed0 | |||
4a1b4f1dd4 | |||
ec75790516 | |||
fad4f72357 | |||
b3db180ffb | |||
a4f41c7cb5 | |||
40f9135412 | |||
46996e5251 | |||
2cd043c2a1 | |||
e1c66c351a | |||
a5fd4a2c10 | |||
fc7bfc113a | |||
bf82beaf9c | |||
5e37830bb7 | |||
4ff722ed2e | |||
52b0ef4b28 | |||
930ff6734d | |||
40be9b68a5 | |||
4259aeab7b | |||
d0cb2a032c | |||
4dc679af70 | |||
091bd9b381 | |||
d04f93ffca | |||
66aaa97955 | |||
387b2b86b0 | |||
e003a11723 | |||
d0504bb65b | |||
669fd317b6 | |||
af7d1d2611 | |||
1cbb486330 | |||
9516e0720c | |||
8273556539 | |||
5bc9353bb4 | |||
c8e80bf6a3 |
@ -18,4 +18,4 @@ script:
|
||||
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
||||
- export CPLUS_INCLUDE_PATH=$PWD/include
|
||||
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
||||
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON .. && make
|
||||
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
||||
|
@ -10,7 +10,7 @@ find_package (PkgConfig REQUIRED)
|
||||
|
||||
# Force a libmraa search and minimum required version every time a config is generated
|
||||
unset(MRAA_FOUND CACHE)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.8.0)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.9.1)
|
||||
message (INFO " found mraa version: ${MRAA_VERSION}")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
@ -25,7 +25,7 @@ include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production UPM!")
|
||||
set (VERSION "v0.4.1-dirty")
|
||||
set (VERSION "v0.5.1-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - UPM Version ${VERSION}")
|
||||
@ -53,9 +53,11 @@ option (BUILDSWIG "Build swig modules." ON)
|
||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||
option (BUILDSWIGNODE "Build swig node modules." ON)
|
||||
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (BUILDTESTS "Generate check-ups for upm" OFF)
|
||||
|
||||
# Find swig
|
||||
if (BUILDSWIG)
|
||||
@ -203,3 +205,15 @@ add_subdirectory (src)
|
||||
if(BUILDEXAMPLES)
|
||||
add_subdirectory (examples/c++)
|
||||
endif()
|
||||
|
||||
if(BUILDJAVAEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
|
||||
if(BUILDTESTS)
|
||||
find_package (PythonInterp REQUIRED)
|
||||
if (${PYTHONINTERP_FOUND})
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
endif()
|
||||
|
@ -83,6 +83,8 @@ Porting [link](docs/porting.md) has more information on making new UPM modules.
|
||||
|
||||
There is also an example available for max31855 [sensor](docs/max31855.md).
|
||||
|
||||
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
||||
|
||||
### Naming conventions and rules for new UPM contributions
|
||||
|
||||
Before you begin development, take a look at our naming [conventions](docs/naming.md).
|
||||
|
@ -5,12 +5,10 @@ UPM uses cmake in order to make compilation relatively painless. Cmake runs
|
||||
build out of tree so the recommended way is to clone from git and make a build/
|
||||
directory.
|
||||
|
||||
This project depends on libmraa, so that needs to be installed first. Use the
|
||||
following environment variables to configure the paths:
|
||||
This project depends on libmraa, so that needs to be installed first. Append
|
||||
the install location of mraa pkgconfig to the following environment variable:
|
||||
|
||||
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:.../mraa/build/lib/pkgconfig
|
||||
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:.../mraa/build/include
|
||||
LIBRARY_PATH=$LIBRARY_PATH:.../mraa/build/lib
|
||||
|
||||
UPM will attempt to build all directories inside src/ and they must contain
|
||||
individual CMakeLists.txt files.
|
||||
|
@ -4,6 +4,31 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### v0.5.1
|
||||
|
||||
* Updated the API and added new functionality for the MY9221 class and derived
|
||||
sensors: grovecircularled and groveledbar, along with new code samples that
|
||||
show these changes
|
||||
* Provided a fix for one JAVA example that uses interrupts and updated library
|
||||
install paths
|
||||
* Several documentation improvements and pictures were added for new sensors
|
||||
* A few other sensors received minor patches
|
||||
|
||||
### v0.5.0
|
||||
|
||||
* First implementations for industrial grade Modbus sensors, along with first
|
||||
sensor examples that use the new iio system driver in MRAA
|
||||
* Significant improvements to the stepmotor driver that will now allow precise
|
||||
control using any GPIO pin and extended the API with new functionality
|
||||
* Further improved JAVA bindings and sensor ISRs have been modified to
|
||||
implement Runnable objects
|
||||
* Improved Python typemaps and error checking, documentation now includes
|
||||
detailed function descriptions
|
||||
* Simplified the build process by eliminating the need to define redundant
|
||||
MRAA related environment variables
|
||||
* New sensors: nlgpio16, ads1x15, t3311, hdxxvxta, hwxpxx, rhusb, ili9341,
|
||||
apds9930, kxcjk1013
|
||||
|
||||
### v0.4.1
|
||||
|
||||
* Over 150 supported sensor drivers including some industrial grade devices
|
||||
@ -40,7 +65,7 @@ from earlier versions:
|
||||
includes last remaining images and grouping sensors by kits
|
||||
* Added support for Sparkfun Sensor Blocks (OLED & IMU)
|
||||
* Fully reworked API for at42qt1070, mpu9150 and lcd classes, while
|
||||
maintaining backwards compatibility for existing lcd displays.
|
||||
maintaining backwards compatibility for existing lcd displays
|
||||
* Extended doxygen tags for better integration with automated documentation
|
||||
generators
|
||||
* New sensors: rgbringcoder, hp20x, pn532, sainsmartks, lsm9ds0, eboled
|
||||
|
353
docs/creating_java_bindings.md
Normal file
@ -0,0 +1,353 @@
|
||||
Creating Java Bindings Guide
|
||||
==============
|
||||
* [Overview](#overview)
|
||||
* [Tools of trade](#tools-of-trade)
|
||||
* [Recommendations for the native API](#recommendations-for-the-native-api)
|
||||
* [Pointers](#pointers)
|
||||
* [Throwing Exceptions in Java](#throwing-exceptions-in-java)
|
||||
* [Caveats & Challenges](#caveats--challenges)
|
||||
* [Wrapping C arrays with Java arrays](#wrapping-c-arrays-with-java-arrays)
|
||||
* [Wrapping unbound C arrays with Java arrays if array is output](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output)
|
||||
* [Wrapping unbound C arrays with Java arrays if array is input](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-input)
|
||||
* [Implementing callbacks in Java](#implementing-callbacks-in-java)
|
||||
|
||||
|
||||
##Overview
|
||||
|
||||
The "Creating Java Bindings Guide" serves as a basic tutorial for using the SWIG software development tool to create 'glue code' required for Java to call into C/C++ code. It contains: guides for dealing with type conversions, exception handling, callbacks; recommendations on how to write/modify the native API to avoid issues on the Java side, and also workarounds for those issues that can't be avoided.
|
||||
|
||||
This guide was created with the [upm](https://github.com/intel-iot-devkit/upm/) and [mraa](https://github.com/intel-iot-devkit/mraa) libraries in mind, and uses examples taken from these sources, but its usage can be extended to any project of creating Java bindings for C/C++ libraries.
|
||||
|
||||
##Tools of trade
|
||||
|
||||
[SWIG General Documentation](http://www.swig.org/Doc3.0/SWIGDocumentation.html)
|
||||
|
||||
[SWIG Java-specific Documentation](http://www.swig.org/Doc3.0/Java.html)
|
||||
|
||||
|
||||
##Recommendations for the native API
|
||||
|
||||
###Pointers
|
||||
As much as possible, avoid passing values/returning values through pointers given as as arguments to methods. As the Java language does not have pointers, SWIG provides a [workaround](http://www.swig.org/Doc3.0/Java.html#Java_tips_techniques) in the typemaps.i library.
|
||||
|
||||
####Alternatives:
|
||||
1. Functions that read data from a driver, return it through a pointer given as argument, and return a bool value, should be __replaced by__ functions that return the value directly and throw a std::runtime_error if a read error occurs. E.g.:
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor, places read value in variable bar and
|
||||
* returns true if succesful. Function returns false if read failed.
|
||||
*/
|
||||
bool func(int *bar);
|
||||
```
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function reads from sensor and returns read value.
|
||||
* Or throws std::runtime_error if a read error occurs
|
||||
*/
|
||||
int func();
|
||||
```
|
||||
|
||||
2. Functions that return multiple values through pointers, that make sense to be grouped together into an array<sup>1</sup> (e.g. speed values, acceleration values), should be __replaced by__ functions that return a pointer to an array in which the elements are the returned values. Afterwards, [wrap the C array with a Java array](#wrapping-unbound-c-arrays-with-java-arrays-if-array-is-output). E.g.:
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis in the given variables.
|
||||
*/
|
||||
void getAccel(int *accelX, int *accelY, int *accelZ);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
int *getAccel();
|
||||
```
|
||||
|
||||
3. Functions that return N values through pointers, that do not make sense to grouped together (e.g. a general purpose function that returns both the light intensity and air pollution), should be __replaced by__ N functions (one for each value) that read only one specific value. E.g.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *light, int *air);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
int getLight();
|
||||
int getAir();
|
||||
```
|
||||
|
||||
4. Functions that return N values through pointers; values that do not make sense to be grouped together, but are time dependent, and make sense to be read at the same time. For example, a sensor that reads air humidity and temperature. A user may want to know the temperature value _temp_ read at the exact moment the humidity value _humid_ was read. These should be __replaced by__ N+1 functions: a _getData()_ function that reads all values at the same time and stores them in global variables; and N getter functions, one for each value. E.g.
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the light intensity and air pollution
|
||||
*/
|
||||
void getData(int *temp, int *humid);
|
||||
```
|
||||
|
||||
__Replaced by:__
|
||||
```c++
|
||||
void getData();
|
||||
int getTemp();
|
||||
int getHumid();
|
||||
```
|
||||
|
||||
<sup>1</sup>this depends on the interpretation of the returned data. For example, arguments that return the temperature and light intensity, don't make sense to be grouped into an array of size 2. But acceleration on the three axis can be grouped together in an array of size 3. where accelX is accel[0], accelY is accel[1], accelZ is accel[2].
|
||||
|
||||
__Notice:__
|
||||
Sometimes, you may be required to write JNI code. Be aware of the difference between the C JNI calling syntax and the C++ JNI calling syntax.The C++ calling syntax will not compile as C and also vice versa. It is however possible to write JNI calls which will compile under both C and C++ and is covered in the [Typemaps for both C and C++ compilation](http://www.swig.org/Doc3.0/Java.html#Java_typemaps_for_c_and_cpp) section of the SWIG Documentation.
|
||||
|
||||
|
||||
###Throwing Exceptions in Java
|
||||
####Language independent:
|
||||
The %exception directive allows you to define a general purpose exception handler. For example, you can specify the following:
|
||||
|
||||
```c++
|
||||
%exception [method_name] {
|
||||
try {
|
||||
$action
|
||||
}
|
||||
catch (std::invalid_argument& e) {
|
||||
... handle error ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If [method_name] is not specified then the directive is applied to all methods in its scope.
|
||||
|
||||
The usual thing you'd want to do is catch the C++ exception and throw an equivalent exception in your language.
|
||||
|
||||
The exception.i library file provides support for creating language independent exceptions in your interfaces. To use it, simply put an "%include exception.i" in your interface file. This provides a function SWIG_exception() that can be used to raise common language exceptions in a portable manner. For example :
|
||||
|
||||
|
||||
```c++
|
||||
// Language independent exception handler
|
||||
%include exception.i
|
||||
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch(OutOfMemory) {
|
||||
SWIG_exception(SWIG_MemoryError, "Out of memory");
|
||||
} catch(...) {
|
||||
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the upm library, the upm_exception.i interface file provides the functionality to catch common exceptions and propagate them through SWIG. It uses the exception.i library file and is language independent.
|
||||
|
||||
The upm_exception.i interface file is included in the upm.i file, therefor SWIG wraps all generated methods' body in a try-catch statement for the following exceptions:
|
||||
|
||||
* std::invalid_argument
|
||||
* std::domain_error
|
||||
* std::overflow_error
|
||||
* std::out_of_range
|
||||
* std::length_error
|
||||
* std::logic_error
|
||||
* std::bad_alloc
|
||||
* std::runtime_error
|
||||
* std::exception
|
||||
|
||||
|
||||
####Java specific:
|
||||
To throw a specific Java exception:
|
||||
|
||||
```c++
|
||||
%exception {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Where FindClass and ThrowNew are [JNI functions](http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html).
|
||||
|
||||
Java defines two tipes of exceptions: checked exception and unchecked exceptions (errors and runtime exceptions). Checked exceptions are subject to the [Catch or Specify Requirement](https://docs.oracle.com/javase/tutorial/essential/exceptions/catchOrDeclare.html).
|
||||
|
||||
The C++ compiler does not force the code to catch any exception.
|
||||
|
||||
The %exception directive does not specify if a method throws a checked exception (does not add classes to the throws clause). For this, the %javaexception(classes) directive is used; where classes is a string containing one or more comma separated Java classes.
|
||||
|
||||
```c++
|
||||
%javaexception("java.lang.Exception") {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range &e) {
|
||||
jclass clazz = jenv->FindClass("java/lang/Exception");
|
||||
jenv->ThrowNew(clazz, "Range error");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the upm library, the java_exceptions.i library file provides the functionality to catch exceptions and propagate them through SWIG as Java checked exceptions. The file provides SWIG wrappers, in the form of macros, that can be applied to methods.E.g. use the __READDATA_EXCEPTION(function)__ macro for functions that read data from a sensor and throw a std::runtime_error in case of a read failure. This will result in:
|
||||
|
||||
```java
|
||||
void function throws IOException ();
|
||||
```
|
||||
|
||||
##Caveats & Challenges
|
||||
|
||||
###Wrapping C arrays with Java arrays
|
||||
SWIG can wrap arrays in a more natural Java manner than the default by using the arrays_java.i library file. Just include this file into your SWIG interface file.
|
||||
|
||||
###Wrapping unbound C arrays with Java arrays if array is output
|
||||
Functions that return arrays, return a pointer to that array. E.g.:
|
||||
|
||||
```c++
|
||||
/*
|
||||
* Function returns the acceleration on the three
|
||||
* axis as elements of a 3-element array.
|
||||
*/
|
||||
|
||||
int *getAccel();
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jni) int* "jintArray"
|
||||
%typemap(jstype) int* "int[]"
|
||||
%typemap(jtype) int* "int[]"
|
||||
|
||||
%typemap(javaout) int* {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(out) int *getAccel {
|
||||
$result = JCALL1(NewIntArray, jenv, 3);
|
||||
JCALL4(SetIntArrayRegion, jenv, $result, 0, 3, (const signed int*)$1);
|
||||
}
|
||||
```
|
||||
|
||||
###Wrapping unbound C arrays with Java arrays if array is input
|
||||
In C, arrays are tipically passed as pointers, with an integer value representig the length of the array. In Java, the length of an array is always known, so the length argument is redundant. This example shows how to wrap the C array and also get rid the length argument. E.g.:
|
||||
|
||||
```c++
|
||||
void func(uint8_t *buffer, int length);
|
||||
```
|
||||
|
||||
__SWIG:__
|
||||
```c++
|
||||
%typemap(jtype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jstype) (uint8_t *buffer, int length) "byte[]"
|
||||
%typemap(jni) (uint8_t *buffer, int length) "jbyteArray"
|
||||
%typemap(javain) (uint8_t *buffer, int length) "$javainput"
|
||||
|
||||
%typemap(in,numinputs=1) (uint8_t *buffer, int length) {
|
||||
$1 = JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||
$2 = JCALL1(GetArrayLength, jenv, $input);
|
||||
}
|
||||
```
|
||||
|
||||
!!!! There is a difference between TYPE *name and TYPE * name in typemaps!!!!!
|
||||
|
||||
|
||||
###Implementing callbacks in Java
|
||||
Callbacks in the UPM Java library (as well as the MRAA Java library) make use of the _void mraa\_java\_isr\_callback(void\* data\)_ method from MRAA.
|
||||
|
||||
__Callbacks in the UPM Java library are implemented as follows (we use the a110x Hall Effect sensors as example):__
|
||||
|
||||
We extend the sensor class with another method, _installISR\(jobject runnable\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _mraa\_java\_isr\_callback\(\)_ method as the interrupt service routine \(ISR\) to be called, with _jobject runnable_ as argument.
|
||||
|
||||
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _installISR\(jobject runnable\)_ method in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
|
||||
|
||||
```c++
|
||||
#if defined(SWIGJAVA)
|
||||
void A110X::installISR(jobject runnable)
|
||||
{
|
||||
installISR(mraa_java_isr_callback, runnable);
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(jobject runnable\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
|
||||
|
||||
```c++
|
||||
public:
|
||||
#if defined(SWIGJAVA)
|
||||
void installISR(jobject runnable);
|
||||
#else
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
private:
|
||||
#if defined(SWIGJAVA)
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
```
|
||||
|
||||
To use callback in java, we create a ISR class, which implements the Java Runnable interface, and we override the _run\(\)_ method with the code to be executed when the interrupt is received. An example for the a110x Hall sensor that increments a counter each time an interrupt is received:
|
||||
|
||||
```java
|
||||
public class A110X_intrSample {
|
||||
public static int counter=0;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
upm_a110x.A110X hall = new upm_a110x.A110X(2);
|
||||
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
while(true){
|
||||
System.out.println("Counter: " + counter);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class A110XISR implements Runnable {
|
||||
public A110XISR(){
|
||||
super();
|
||||
}
|
||||
public void run(){
|
||||
A110X_intrSample.counter++;
|
||||
}
|
||||
}
|
||||
```
|
||||
####Issues with java callbacks and workarounds
|
||||
|
||||
__SWIGJAVA not defined at compile time__
|
||||
|
||||
Consider the following files:
|
||||
* example.h - Header file for our source file
|
||||
* example.cxx - Source file containing the class Example, for which we build java bindings
|
||||
* example.i - The SWIG interface, that includes the example.h header file
|
||||
|
||||
The build process of a java module using SWIG is split into two steps:
|
||||
|
||||
1. Generating the intermediate files, from the SWIG interface file. This will produce the java class file (Example.java), the JNI file (exampleJNI.java) and wrapper file (example_wrap.cxx). The source file (example.cxx) is not needed in the first step.
|
||||
|
||||
```
|
||||
swig -c++ -java example.i
|
||||
```
|
||||
|
||||
2. Generating the shared library from the C++ sources and wrapper file
|
||||
```
|
||||
g++ -fPIC -c example.cxx example_wrap.cxx -I/usr/lib/jvm/java-1.8.0/include -I/usr/lib/jvm/java-1.8.0/include/linux
|
||||
g++ -shared example_wrap.o sensor.o -o libexample.so
|
||||
```
|
||||
|
||||
|
||||
SWIGJAVA is always defined when SWIG parses the interface file, meaning it will be defined when it parses the header file (example.h) that is included in the interface file (example.i).
|
||||
SWIG also adds the "#define SWIGJAVA" directive in the wrapper file (example_wrap.cxx).
|
||||
However, in generating the shared library the SWIGJAVA symbol is only defined in the example_wrap.cxx file, because of the added "#define SWIGJAVA" directive. But we have also used the "#if defined(SWIGJAVA)" check in the source file (example.cxx), and thus need to define SWIGJAVA for it too. If we define the SWIGJAVA symbol as a compile flag, when compiling the source code to object code, the SWIGJAVA compile flag and #define SWIGJAVA" directive will clash and give a double definition warning (only a warning).
|
||||
|
||||
In this example it is simple to compile the two source codes separately, one with the compile flag, the other without, and then create the shared library (libexample.so).
|
||||
But in a big automatic build like the java upm libraries, this may prove too hard or too complicated to do. A workaround to this would be to define a custom symbol (e.q. JAVACALLBACK in the upm library) and also test for it. In short, replace:
|
||||
```c++
|
||||
#if defined(SWIGJAVA)
|
||||
```
|
||||
by
|
||||
```c++
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
```
|
||||
|
@ -50,10 +50,12 @@ Here's an example (disregard the "@verbatim" tags in your actual code):
|
||||
library's "@defgroup", otherwise this is a new library name, generally the
|
||||
same as chip id. *Mandatory*
|
||||
- `<chip-id>` Usually the chip number used by the sensor. When this is not
|
||||
available or relevant, use a unique descriptor that makes sense. *Mandatory*
|
||||
- `<component-name>` A short name for your sensor, can include manufacturer
|
||||
name. *Mandatory*
|
||||
- `<alt-name>` Alternative names that your sensor driver might have. *Optional*
|
||||
available or relevant, use a unique descriptor that makes sense. Must match
|
||||
class name. *Mandatory*
|
||||
- `<component-name>` A short name for your sensor, try to avoid including the
|
||||
manufacturer's name here. *Mandatory*
|
||||
- `<alt-name>` Alternative names that your sensor driver might have. This may
|
||||
include manufacturer's name. *Optional*
|
||||
- `<alt-id>` Alternative chip-ids that your sensor driver supports. *Optional*
|
||||
- `<component-category>` Mention one or more categories the sensor fits in. Can
|
||||
be 'other'. *Mandatory*
|
||||
|
BIN
docs/images/ads1015.jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
docs/images/ads1115.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
docs/images/adxrs610.jpg
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
docs/images/bma220.jpg
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
docs/images/dfrph.jpg
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
docs/images/eboled.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
docs/images/groveultrasonic.jpg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/images/ili9341.jpg
Normal file
After Width: | Height: | Size: 199 KiB |
BIN
docs/images/keypadlcd.jpg
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docs/images/lm35.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
docs/images/lsm9ds0.jpg
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docs/images/mg811.jpg
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
docs/images/mpu60x0.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
docs/images/mpu9250.jpg
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/pn532.jpg
Normal file
After Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 198 KiB |
BIN
docs/images/urm37.jpg
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
docs/images/wheelencoder.jpg
Normal file
After Width: | Height: | Size: 43 KiB |
BIN
docs/images/xbee.jpg
Normal file
After Width: | Height: | Size: 176 KiB |
@ -7,6 +7,11 @@ such sensors and known workarounds if they exist.
|
||||
|
||||
#### Grove Sensors
|
||||
|
||||
* **Grove LCD RGB Backlit** (JHD1313M1) requires 5V and should be used with an
|
||||
external power supply connected to the board to function properly. Although
|
||||
some high powered USB ports might be enough, in most cases you will encounter
|
||||
dropped characters, washed out text and/or failed I2C writes while using USB
|
||||
power alone.
|
||||
* **Grove I2C Touch Sensor** (MPR121) v1.3 is incompatible with the Intel
|
||||
Edison using the Arduino board, but will work with the Mini-breakout if
|
||||
supplied with at least 4V. Revision v1.2 works well on all Intel boards.
|
||||
@ -14,8 +19,8 @@ such sensors and known workarounds if they exist.
|
||||
on the Intel Edison boards.
|
||||
* **Grove 3-Axis Digital Gyroscope** (ITG-3200) is not compatible with the
|
||||
Intel Edison Arduino board but will work with the Mini-breakout.
|
||||
* **Grove 3-Axis Digital Accelerometer** (ADXL345) only works with the Intel
|
||||
Edison Arduino board when powered from the 3.3V line.
|
||||
* **Grove 3-Axis Digital Accelerometer +/-16g** (ADXL345) only works with the
|
||||
Intel Edison Arduino board when powered from the 3.3V line.
|
||||
* **Grove 3-Axis Digital Compass** (HMC5883L) reports inaccurate values at 5V
|
||||
on the Intel Edison Arduino board and newer revisions might not work at all.
|
||||
Use 3.3V or the Mini-breakout.
|
||||
@ -26,21 +31,24 @@ such sensors and known workarounds if they exist.
|
||||
* **Grove Barometer** (BMP085) has an unstable connection on the Intel Edison
|
||||
using the Arduino breakout and may drop read data. The Xadow version of this
|
||||
sensor (BMP180) is also dropping data packets occasionally.
|
||||
* **Grove Digital Light Sensor** (TSL2561) occasionally drops I2C reads on the
|
||||
Intel Edison with the Arduino breakout. This might cause the sensor not to
|
||||
initialize properly. Works as expected with the Mini-breakout.
|
||||
* **Grove 6-Axis Accelerometer & Compass** (LSM303) fails to write to the
|
||||
configuration register properly and returns invalid data.
|
||||
* **Grove I2C ADC Converter** does not show up on the I2C bus on the Intel
|
||||
Edison with the Arduino board.
|
||||
* **Grove I2C Motor Driver** is not compatible with the Intel Galileo due to
|
||||
the inability to change the I2C bus speed to 100 KHz.
|
||||
* **Grove Digital Light Sensor** (TSL2561) may have an unstable connection on
|
||||
the Intel Edison using the Arduino breakout that results in missed I2C reads.
|
||||
This is usually applicable when the I2C lines are pulled-up to 5V. Works as
|
||||
expected with the Mini-breakout.
|
||||
* **Grove CO2 Sensor** will return zeroed data and is unusable on the Intel
|
||||
Galileo.
|
||||
* **Grove BLE** (HM-11) does not return data on the Intel Galileo board due to
|
||||
known UART limitation.
|
||||
* **Grove Hall Sensor** (A11X), if the base shield is set to 3V on Intel Edison,
|
||||
* **Grove Hall Sensor** (A11X) if the base shield is set to 3V on Intel Edison,
|
||||
it will trigger continous callbacks when the sensor is not reading anything.
|
||||
* **Grove RTC** (DS1307) is not compatible with the Intel Edison Arduino board
|
||||
but will work with the Mini-breakout.
|
||||
|
||||
#### Adafruit Sensors
|
||||
|
||||
|
@ -30,7 +30,7 @@ Multi-sensor samples for the starter and specialized kits can be found in the
|
||||
|
||||
Supported [sensor list](http://iotdk.intel.com/docs/master/upm/modules.html) from API documentation.
|
||||
|
||||
You can also refer to the [Intel® IoT Developer Zone](https://software.intel.com/iot/sensors).
|
||||
You can also refer to the [Intel IoT Developer Zone](https://software.intel.com/iot/sensors).
|
||||
|
||||
### IDE Compatibility
|
||||
|
||||
|
@ -1,40 +1,21 @@
|
||||
# Mapping C++ sample files to Java sample files
|
||||
a110x-intr.cxx A110X_intrSample.java
|
||||
a110x.cxx A110XSample.java
|
||||
ad8232.cxx AD8232Sample.java
|
||||
adc121c021.cxx ADC121C021Sample.java
|
||||
adis16448.cxx ADIS16448Sample.java
|
||||
adxl335.cxx ADXL335Sample.java
|
||||
adxl345.cxx Adxl345Sample.java
|
||||
ak8975.cxx AK8975Sample.java
|
||||
am2315.cxx AM2315Sample.java
|
||||
apds9002.cxx APDS9002Sample.java
|
||||
biss0001.cxx BISS0001Sample.java
|
||||
bmpx8x.cxx BMPX8XSample.java
|
||||
buzzer-sound.cxx Buzzer_soundSample.java
|
||||
cjq4435.cxx CJQ4435Sample.java
|
||||
ds1307.cxx DS1307Sample.java
|
||||
eboled.cxx EBOLEDSample.java
|
||||
ecs1030.cxx ECS1030Sample.java
|
||||
enc03r.cxx ENC03RSample.java
|
||||
es08a.cxx ES08ASample.java
|
||||
flex.cxx FlexSample.java
|
||||
gp2y0a.cxx GP2Y0ASample.java
|
||||
grovebutton.cxx GroveButtonSample.java
|
||||
grovecircularled.cxx GroveCircularLEDSample.java
|
||||
grovecollision.cxx GroveCollisionSample.java
|
||||
groveehr.cxx GroveEHRSample.java
|
||||
groveeldriver.cxx GroveElDriverSample.java
|
||||
groveelectromagnet.cxx GroveElectromagnetSample.java
|
||||
groveemg.cxx GroveEMGSample.java
|
||||
grovegprs.cxx GroveGPRSSample.java
|
||||
grovegsr.cxx GroveGSRSample.java
|
||||
groveled.cxx GroveLEDSample.java
|
||||
grovelinefinder.cxx GroveLineFinderSample.java
|
||||
grovelight.cxx GroveLightSample.java
|
||||
groveloudness.cxx GroveLoudnessSample.java
|
||||
grovemoisture.cxx GroveMoistureSample.java
|
||||
groveo2.cxx GroveO2Sample.java
|
||||
groverelay.cxx GroveRelaySample.java
|
||||
groverotary.cxx GroveRotarySample.java
|
||||
grovescam.cxx GROVESCAMSample.java
|
||||
@ -48,75 +29,45 @@ h3lis331dl.cxx H3LIS331DLSample.java
|
||||
hcsr04.cxx HCSR04Sample.java
|
||||
hm11.cxx HM11Sample.java
|
||||
hmc5883l.cxx Hmc5883lSample.java
|
||||
hp20x.cxx HP20XSample.java
|
||||
ht9170.cxx HT9170Sample.java
|
||||
htu21d.cxx HTU21DSample.java
|
||||
hx711.cxx HX711Sample.java
|
||||
hyld9767.cxx HYLD9767Sample.java
|
||||
ina132.cxx INA132Sample.java
|
||||
itg3200.cxx Itg3200Sample.java
|
||||
jhd1313m1-lcd.cxx Jhd1313m1_lcdSample.java
|
||||
joystick12-example.cxx Joystick12_exampleSample.java
|
||||
l298-stepper.cxx L298_stepperSample.java
|
||||
l298.cxx L298Sample.java
|
||||
lcm1602-lcd.cxx Lcm1602_lcdSample.java
|
||||
joystick12.cxx Joystick12Sample.java
|
||||
lcm1602-i2c.cxx Lcm1602_i2cSample.java
|
||||
ldt0028.cxx LDT0028Sample.java
|
||||
lol-example.cxx LoL_exampleSample.java
|
||||
lpd8806.cxx LPD8806Sample.java
|
||||
lol.cxx LoLSample.java
|
||||
lsm303.cxx LSM303Sample.java
|
||||
lsm9ds0.cxx LSM9DS0Sample.java
|
||||
m24lr64e.cxx M24LR64ESample.java
|
||||
max31723.cxx MAX31723Sample.java
|
||||
max31855.cxx MAX31855Sample.java
|
||||
max44000.cxx MAX44000Sample.java
|
||||
max5487.cxx MAX5487Sample.java
|
||||
maxds3231m.cxx MAXDS3231MSample.java
|
||||
mg811.cxx MG811Sample.java
|
||||
mic.cxx MicrophoneSample.java
|
||||
mlx90614.cxx MLX90614Sample.java
|
||||
mma7455.cxx MMA7455Sample.java
|
||||
mma7660.cxx MMA7660Sample.java
|
||||
mpl3115a2.cxx MPL3115A2Sample.java
|
||||
mpr121.cxx MPR121Sample.java
|
||||
mpu60x0.cxx MPU60X0Sample.java
|
||||
mpu9150.cxx MPU9150Sample.java
|
||||
mpu9250.cxx MPU9250Sample.java
|
||||
mq2.cxx MQ2Sample.java
|
||||
mq3.cxx MQ3Sample.java
|
||||
mq303a.cxx MQ303ASample.java
|
||||
mq5.cxx MQ5Sample.java
|
||||
mq9.cxx MQ9Sample.java
|
||||
my9221-ledbar.cxx MY9221_ledbarSample.java
|
||||
my9221-updown.cxx MY9221_updownSample.java
|
||||
nrf24l01-broadcast.cxx NRF24L01_broadcastSample.java
|
||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
||||
nunchuck.cxx NUNCHUCKSample.java
|
||||
otp538u.cxx OTP538USample.java
|
||||
pca9685.cxx PCA9685Sample.java
|
||||
pn532-writeurl.cxx PN532_writeurlSample.java
|
||||
pn532.cxx PN532Sample.java
|
||||
ppd42ns.cxx PPD42NSSample.java
|
||||
pulsensor.cxx PulsensorSample.java
|
||||
rfr359f.cxx RFR359FSample.java
|
||||
rgbringcoder.cxx RGBRingCoderSample.java
|
||||
rotaryencoder.cxx RotaryEncoderSample.java
|
||||
rpr220-intr.cxx RPR220_intrSample.java
|
||||
rpr220.cxx RPR220Sample.java
|
||||
sainsmartks.cxx SAINSMARTKSSample.java
|
||||
sm130.cxx SM130Sample.java
|
||||
ssd1306-oled.cxx SSD1306_oledSample.java
|
||||
ssd1308-oled.cxx SSD1308_oledSample.java
|
||||
ssd1327-oled.cxx SSD1327_oledSample.java
|
||||
st7735.cxx ST7735Sample.java
|
||||
stepmotor.cxx StepMotorSample.java
|
||||
ta12200.cxx TA12200Sample.java
|
||||
tm1637.cxx TM1637Sample.java
|
||||
tp401.cxx TP401Sample.java
|
||||
tsl2561.cxx TSL2561Sample.java
|
||||
ttp223.cxx TTP223Sample.java
|
||||
ublox6.cxx Ublox6Sample.java
|
||||
uln200xa.cxx ULN200XASample.java
|
||||
waterlevel.cxx WaterLevelSample.java
|
||||
wt5001.cxx WT5001Sample.java
|
||||
yg1006.cxx YG1006Sample.java
|
||||
|
@ -14,7 +14,6 @@ macro(get_module_name example_name module_name)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
# Set source file, include and linker settings for an example
|
||||
# If example cannot be built, example_bin is cleared
|
||||
macro(add_custom_example example_bin example_src example_module_list)
|
||||
@ -74,6 +73,10 @@ endmacro()
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||
|
||||
# Set the mraa include and link directories prior to adding examples
|
||||
include_directories (${MRAA_INCLUDE_DIRS})
|
||||
link_directories (${MRAA_LIBDIR})
|
||||
|
||||
# If your sample source file matches the name of the module it tests, add it here
|
||||
# Exceptions are as follows:
|
||||
# string after first '-' is ignored (e.g. nrf24l01-transmitter maps to nrf24l01)
|
||||
@ -88,8 +91,6 @@ add_example (grovebutton)
|
||||
add_example (groverotary)
|
||||
add_example (groveslide)
|
||||
add_example (buzzer-sound)
|
||||
add_example (my9221-ledbar)
|
||||
add_example (my9221-updown)
|
||||
add_example (nrf24l01-transmitter)
|
||||
add_example (nrf24l01-receiver)
|
||||
add_example (nrf24l01-broadcast)
|
||||
@ -200,7 +201,6 @@ add_example (h3lis331dl)
|
||||
add_example (ad8232)
|
||||
add_example (grovescam)
|
||||
add_example (m24lr64e)
|
||||
add_example (grovecircularled)
|
||||
add_example (rgbringcoder)
|
||||
add_example (hp20x)
|
||||
add_example (pn532)
|
||||
@ -223,10 +223,22 @@ add_example (mcp9808)
|
||||
add_example (groveultrasonic)
|
||||
add_example (sx1276-lora)
|
||||
add_example (sx1276-fsk)
|
||||
add_example (ili9341)
|
||||
if (OPENZWAVE_FOUND)
|
||||
include_directories(${OPENZWAVE_INCLUDE_DIRS})
|
||||
add_example (ozw)
|
||||
endif()
|
||||
add_example (nlgpio16)
|
||||
add_example (ads1x15)
|
||||
if (MODBUS_FOUND)
|
||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||
add_example (t3311)
|
||||
add_example (hwxpxx)
|
||||
endif()
|
||||
add_example (hdxxvxta)
|
||||
add_example (rhusb)
|
||||
add_example (apds9930)
|
||||
add_example (kxcjk1013)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
@ -243,3 +255,5 @@ 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)
|
||||
|
320
examples/c++/ads1x15.cxx
Normal file
@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "mraa.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include "ads1015.h"
|
||||
#include "ads1115.h"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
int command;
|
||||
//Select the device you are testing here and adjust case 6 for the correct sample rates.
|
||||
//upm::ADS1015 *ads = new upm::ADS1015(1);
|
||||
upm::ADS1115 *ads = new upm::ADS1115(1, 0x49);
|
||||
float inputVoltage;
|
||||
int ans;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
cout << endl;
|
||||
cout << "1 - get Conversion \t" ;
|
||||
cout << "2 - get last conversion" << endl;
|
||||
cout << "3 - get Gain \t\t";
|
||||
cout << "4 - set Gain" << endl;;
|
||||
cout << "5 - get Data Rate \t";
|
||||
cout << "6 - set Data Rate" << endl;
|
||||
cout << "7 - Set Upper Threshold \t" ;
|
||||
cout << "8 - Set Lower Threshold \t";
|
||||
cout << "9 - Display Thresholds \t";
|
||||
cout << "10 - Set Default Thresholds \t";
|
||||
cout << "11 - Set conversion ready" << endl;
|
||||
cout << "12 - get Comp Que \t" ;
|
||||
cout << "13 - set Comp Que" << endl;
|
||||
cout << "14 - get Comp Pol \t";
|
||||
cout << "15 - set Comp Pol" << endl;
|
||||
cout << "16 - get Comp mode \t";
|
||||
cout << "17 - set Comp mode " << endl;
|
||||
cout << "18 - get Comp Latch\t";
|
||||
cout << "19 - set Comp Latch " << endl;
|
||||
cout << "20 - get Continuous \t";
|
||||
cout << "21 - set Continuous \t" << endl;
|
||||
cout << "-1 - exit" << endl;
|
||||
cout << "Enter a command: ";
|
||||
cin >> command;
|
||||
|
||||
|
||||
switch(command)
|
||||
{
|
||||
case 2:
|
||||
cout << ads->getLastSample() << endl;
|
||||
break;
|
||||
case 3:
|
||||
cout << std::hex << ads->getGain() << endl;
|
||||
break;
|
||||
case 5:
|
||||
cout << std::hex << ads->getSPS() << endl;
|
||||
break;
|
||||
case 4:
|
||||
int gain;
|
||||
ADS1015::ADSGAIN set_gain;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> gain 2/3 \t 2 -> gain1 \t 3 -> gain 2" << endl;
|
||||
cout << "4 -> gain 4 \t 5 -> gain 8 \t 6 -> gain 15" << endl;
|
||||
cin >> gain;
|
||||
switch(gain){
|
||||
case 1:
|
||||
set_gain = ADS1X15::GAIN_TWOTHIRDS;
|
||||
break;
|
||||
case 2:
|
||||
set_gain = ADS1X15::GAIN_ONE;
|
||||
break;
|
||||
case 3:
|
||||
set_gain = ADS1X15::GAIN_TWO;
|
||||
break;
|
||||
case 4:
|
||||
set_gain = ADS1X15::GAIN_FOUR;
|
||||
break;
|
||||
case 5:
|
||||
set_gain = ADS1X15::GAIN_EIGHT;
|
||||
break;
|
||||
case 6:
|
||||
set_gain = ADS1X15::GAIN_SIXTEEN;
|
||||
break;
|
||||
default:
|
||||
set_gain = ADS1X15::GAIN_ONE;
|
||||
}
|
||||
ads->setGain(set_gain);
|
||||
break;
|
||||
case 6:
|
||||
int rate;
|
||||
/*ADS1015::ADSDATARATE set_rate;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> SPS_120 \t 2 -> SPS_250 \t 3 -> SPS_490 \t 4 -> SPS_920" << endl;
|
||||
cout << "5 -> SPS_1600 \t 6 -> SPS_2400 \t 7 -> SPS_3300" << endl;
|
||||
cin >> rate;
|
||||
switch(rate){
|
||||
case 1:
|
||||
set_rate = ADS1015::SPS_128;
|
||||
break;
|
||||
case 2:
|
||||
set_rate = ADS1015::SPS_250;
|
||||
break;
|
||||
case 3:
|
||||
set_rate = ADS1015::SPS_490;
|
||||
break;
|
||||
case 4:
|
||||
set_rate = ADS1015::SPS_920;
|
||||
break;
|
||||
case 5:
|
||||
set_rate = ADS1015::SPS_1600;
|
||||
break;
|
||||
case 6:
|
||||
set_rate = ADS1015::SPS_2400;
|
||||
break;
|
||||
case 7:
|
||||
set_rate = ADS1015::SPS_3300;
|
||||
break;
|
||||
default:
|
||||
set_rate = ADS1015::SPS_1600;
|
||||
} */
|
||||
ADS1115::ADSDATARATE set_rate;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> SPS_8 \t 2 -> SPS_16 \t 3 -> SPS_32 \t 4 -> SPS_64" << endl;
|
||||
cout << "5 -> SPS_128 \t 6 -> SPS_250 \t 7 -> SPS_475 \t 8-> SPS_860" << endl;
|
||||
cin >> rate;
|
||||
switch(rate){
|
||||
case 1:
|
||||
set_rate = ADS1115::SPS_8;
|
||||
break;
|
||||
case 2:
|
||||
set_rate = ADS1115::SPS_16;
|
||||
break;
|
||||
case 3:
|
||||
set_rate = ADS1115::SPS_32;
|
||||
break;
|
||||
case 4:
|
||||
set_rate = ADS1115::SPS_64;
|
||||
break;
|
||||
case 5:
|
||||
set_rate = ADS1115::SPS_128;
|
||||
break;
|
||||
case 6:
|
||||
set_rate = ADS1115::SPS_250;
|
||||
break;
|
||||
case 7:
|
||||
set_rate = ADS1115::SPS_475;
|
||||
break;
|
||||
case 8:
|
||||
set_rate = ADS1115::SPS_860;
|
||||
break;
|
||||
default:
|
||||
set_rate = ADS1115::SPS_128;
|
||||
}
|
||||
|
||||
ads->setSPS(set_rate);
|
||||
break;
|
||||
case 1:
|
||||
int mode;
|
||||
ADS1X15::ADSMUXMODE set_mode;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> MUX_0_1 \t 2 -> MUX_0_3 \t 3 -> MUX_1_3 \t 4 -> MUX_2_3" << endl;
|
||||
cout << "5 -> SINGLE_0 \t 6 -> SINGLE_1 \t 7 -> SINGLE_2 \t 8 -> SINGLE_3" << endl;
|
||||
cin >> mode;
|
||||
switch(mode){
|
||||
case 1:
|
||||
set_mode = ADS1X15::DIFF_0_1;
|
||||
break;
|
||||
case 2:
|
||||
set_mode = ADS1X15::DIFF_0_3;
|
||||
break;
|
||||
case 3:
|
||||
set_mode = ADS1X15::DIFF_1_3;
|
||||
break;
|
||||
case 4:
|
||||
set_mode = ADS1X15::DIFF_2_3;
|
||||
break;
|
||||
case 5:
|
||||
set_mode = ADS1X15::SINGLE_0;
|
||||
break;
|
||||
case 6:
|
||||
set_mode = ADS1X15::SINGLE_1;
|
||||
break;
|
||||
case 7:
|
||||
set_mode = ADS1X15::SINGLE_2;
|
||||
break;
|
||||
case 8:
|
||||
set_mode = ADS1X15::SINGLE_3;
|
||||
break;
|
||||
default:
|
||||
set_mode = ADS1X15::DIFF_0_1;
|
||||
break;
|
||||
}
|
||||
cout << ads->getSample(set_mode) << endl;
|
||||
break;
|
||||
case 7:
|
||||
cout << " enter a float value: " ;
|
||||
cin >> inputVoltage;
|
||||
ads->setThresh(ADS1115::THRESH_HIGH, inputVoltage);
|
||||
break;
|
||||
case 8:
|
||||
cout << " enter a float value: " ;
|
||||
cin >> inputVoltage;
|
||||
ads->setThresh(ADS1115::THRESH_LOW, inputVoltage);
|
||||
break;
|
||||
case 9:
|
||||
cout << "Upper " << ads->getThresh(ADS1X15::THRESH_HIGH) << endl;
|
||||
cout << "Lower " << ads->getThresh(ADS1X15::THRESH_LOW) << endl;
|
||||
break;
|
||||
case 10:
|
||||
ads->setThresh(ADS1115::THRESH_DEFAULT);
|
||||
break;
|
||||
case 11:
|
||||
ads->setThresh(ADS1015::CONVERSION_RDY);
|
||||
break;
|
||||
case 12:
|
||||
cout << ads->getCompQue() << endl;
|
||||
break;
|
||||
case 13:
|
||||
int que;
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> CQUE_1CONV \t 2 -> CQUE_2CONV \t 3 -> CQUE_3CONV \t 4 -> CQUE_NONE" << endl;
|
||||
cin >> que;
|
||||
switch(que){
|
||||
case 1:
|
||||
ads->setCompQue(ADS1X15::CQUE_1CONV);
|
||||
break;
|
||||
case 2:
|
||||
ads->setCompQue(ADS1X15::CQUE_2CONV);
|
||||
break;
|
||||
case 3:
|
||||
ads->setCompQue(ADS1X15::CQUE_4CONV);
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
ads->setCompQue(ADS1X15::CQUE_NONE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
cout << ads->getCompPol() << endl;
|
||||
break;
|
||||
case 15:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> active high \t 2 -> active low" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompPol(true);
|
||||
else ads->setCompPol(false);
|
||||
break;
|
||||
case 16:
|
||||
cout << ads->getCompMode() << endl;
|
||||
break;
|
||||
case 17:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Window \t 2 -> Traditional (default)" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompMode(true);
|
||||
else ads->setCompMode();
|
||||
break;
|
||||
case 18:
|
||||
cout << ads->getCompLatch() << cout;
|
||||
break;
|
||||
case 19:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Latching \t 2 -> Non-latching (default)" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setCompLatch(true);
|
||||
else ads->setCompLatch();
|
||||
break;
|
||||
case 20:
|
||||
cout << ads->getContinuous() << cout;
|
||||
break;
|
||||
case 21:
|
||||
cout << "select one of the following:" << endl;
|
||||
cout << "1 -> Power Down (default) \t 2 -> Continuous" << endl;
|
||||
cin >> ans;
|
||||
if(ans == 1) ads->setContinuous(true);
|
||||
else ads->setContinuous();
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}while (command != -1 );
|
||||
|
||||
delete ads;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.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
|
||||
@ -24,40 +24,40 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "my9221.h"
|
||||
#include <signal.h>
|
||||
#include "apds9930.h"
|
||||
|
||||
int running = 0;
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main()
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::MY9221 *bar = new upm::MY9221(8, 9);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// Instantiate a Digital Proximity and Ambient Light sensor on iio device 4
|
||||
upm::APDS9930* light_proximity = new upm::APDS9930(4);
|
||||
|
||||
while (!running) {
|
||||
for (int idx = 1; idx < 11; idx++) {
|
||||
bar->setBarLevel (idx);
|
||||
usleep(1000);
|
||||
}
|
||||
while (shouldRun) {
|
||||
float lux = light_proximity->getAmbient();
|
||||
cout << "Luminance value is " << lux << endl;
|
||||
float proximity = light_proximity->getProximity();
|
||||
cout << "Proximity value is " << proximity << endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete bar;
|
||||
delete light_proximity;
|
||||
|
||||
return 0;
|
||||
}
|
@ -43,9 +43,9 @@ int main()
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a Grove Circular LED on gpio pins 5 and 4
|
||||
// Instantiate a Grove Circular LED on D9 for data, D8 for clock
|
||||
|
||||
upm::GroveCircularLED *circle = new upm::GroveCircularLED(5, 4);
|
||||
upm::GroveCircularLED *circle = new upm::GroveCircularLED(9, 8);
|
||||
|
||||
int level = 0;
|
||||
while (shouldRun)
|
||||
@ -54,6 +54,7 @@ int main()
|
||||
level = (level + 1) % 24;
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "my9221.h"
|
||||
#include "groveledbar.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -42,28 +42,27 @@ int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
|
||||
// clock. This was tested with a Grove LED bar.
|
||||
upm::GroveLEDBar* bar = new upm::GroveLEDBar(8, 9);
|
||||
|
||||
upm::MY9221* bar = new upm::MY9221(2, 3);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// count up from green to red
|
||||
for (int i=1; i<=10; i++)
|
||||
for (int i=0; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, true);
|
||||
usleep(50000);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
// count down from red to green
|
||||
for (int i=1; i<=10; i++)
|
||||
for (int i=0; i<=10; i++)
|
||||
{
|
||||
bar->setBarLevel(i, false);
|
||||
usleep(50000);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
@ -71,7 +70,7 @@ int main ()
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
// turn off the LED's
|
||||
bar->setBarLevel(0, true);
|
||||
bar->setBarLevel(0);
|
||||
|
||||
delete bar;
|
||||
return 0;
|
79
examples/c++/hdxxvxta.cxx
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 <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "hdxxvxta.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an HDXXVXTA instance, using A1 for humidity and A0
|
||||
// for temperature
|
||||
upm::HDXXVXTA *sensor = new upm::HDXXVXTA(1, 0);
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor->getHumidity()
|
||||
<< " %" << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
102
examples/c++/hwxpxx.cxx
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 "hwxpxx.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an HWXPXX instance, using MODBUS slave address 3, and
|
||||
// default comm parameters (19200, 8, N, 2)
|
||||
upm::HWXPXX *sensor = new upm::HWXPXX(defaultDev, 3);
|
||||
|
||||
// output the Slave ID (manufacturer, model, serno)
|
||||
cout << "Slave ID: " << sensor->getSlaveID() << endl;
|
||||
|
||||
// stored temperature and humidity offsets
|
||||
cout << "Temperature Offset: " << sensor->getTemperatureOffset()
|
||||
<< endl;
|
||||
cout << "Humidity Offset: " << sensor->getHumidityOffset()
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor->getHumidity()
|
||||
<< " %" << endl;
|
||||
|
||||
cout << "Slider: " << sensor->getSlider() << " %" << endl;
|
||||
|
||||
cout << "Override Switch Status: " << sensor->getOverrideSwitchStatus()
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
84
examples/c++/ili9341.cxx
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Author: Shawn Hymel
|
||||
* Copyright (c) 2016 SparkFun Electronics
|
||||
*
|
||||
* 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 "ili9341.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
//! [Interesting]
|
||||
|
||||
// Pins (Edison)
|
||||
// CS_LCD GP44 (MRAA 31)
|
||||
// CS_SD GP43 (MRAA 38) unused
|
||||
// DC GP12 (MRAA 20)
|
||||
// RESEST GP13 (MRAA 14)
|
||||
upm::ILI9341 * lcd = new upm::ILI9341(31, 38, 20, 14);
|
||||
|
||||
// Fill the screen with a solid color
|
||||
lcd->fillScreen(lcd->color565(0, 40, 16));
|
||||
|
||||
// Draw some shapes
|
||||
lcd->drawFastVLine(10, 10, 100, ILI9341_RED);
|
||||
lcd->drawFastHLine(20, 10, 50, ILI9341_CYAN);
|
||||
lcd->drawLine(160, 30, 200, 60, ILI9341_GREEN);
|
||||
lcd->fillRect(20, 30, 75, 60, ILI9341_ORANGE);
|
||||
lcd->drawCircle(70, 50, 20, ILI9341_PURPLE);
|
||||
lcd->fillCircle(120, 50, 20, ILI9341_PURPLE);
|
||||
lcd->drawTriangle(50, 100, 10, 140, 90, 140, ILI9341_YELLOW);
|
||||
lcd->fillTriangle(150, 100, 110, 140, 190, 140, ILI9341_YELLOW);
|
||||
lcd->drawRoundRect(20, 150, 50, 30, 10, ILI9341_RED);
|
||||
lcd->drawRoundRect(130, 150, 50, 30, 10, ILI9341_RED);
|
||||
lcd->fillRoundRect(75, 150, 50, 30, 10, ILI9341_RED);
|
||||
|
||||
// Write some text
|
||||
lcd->setCursor(0, 200);
|
||||
lcd->setTextColor(ILI9341_LIGHTGREY);
|
||||
lcd->setTextWrap(true);
|
||||
lcd->setTextSize(1);
|
||||
lcd->print("Text 1\n");
|
||||
lcd->setTextSize(2);
|
||||
lcd->print("Text 2\n");
|
||||
lcd->setTextSize(3);
|
||||
lcd->print("Text 3\n");
|
||||
lcd->setTextSize(4);
|
||||
lcd->print("Text 4\n");
|
||||
|
||||
// Test screen rotation
|
||||
for(int r = 0; r < 4; r++) {
|
||||
lcd->setRotation(r);
|
||||
lcd->fillRect(0, 0, 5, 5, ILI9341_WHITE);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// Invert colors, wait, then revert back
|
||||
lcd->invertDisplay(true);
|
||||
sleep(2);
|
||||
lcd->invertDisplay(false);
|
||||
|
||||
// Don't forget to free up that memory!
|
||||
delete lcd;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
75
examples/c++/kxcjk1013.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "kxcjk1013.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
upm::KXCJK1013* accelerometer;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
void
|
||||
data_callback(char* data)
|
||||
{
|
||||
float x, y, z;
|
||||
accelerometer->extract3Axis(data, &x, &y, &z);
|
||||
printf("%.1f %.1f %.1f\n", x, y, z);
|
||||
// usleep(100);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
// Instantiate a KXCJK1013 Accelerometer Sensor on iio device 0
|
||||
accelerometer = new upm::KXCJK1013(0);
|
||||
accelerometer->setScale(0.019163);
|
||||
accelerometer->setSamplingFrequency(25.0);
|
||||
accelerometer->enable3AxisChannel();
|
||||
accelerometer->installISR(data_callback, NULL);
|
||||
accelerometer->enableBuffer(16);
|
||||
|
||||
while (shouldRun) {
|
||||
sleep(1);
|
||||
}
|
||||
accelerometer->disableBuffer();
|
||||
|
||||
//! [Interesting]
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete accelerometer;
|
||||
|
||||
return 0;
|
||||
}
|
52
examples/c++/nlgpio16.cxx
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include "nlgpio16.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace upm;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
|
||||
upm::NLGPIO16* sensor = new upm::NLGPIO16();
|
||||
|
||||
// get the Version
|
||||
cout << "Device Version: " << sensor->getVersion() << endl;
|
||||
// read the gpio at pin 3
|
||||
cout << "GPIO 3 Value: " << sensor->gpioRead(3) << endl;
|
||||
// read the analog voltage at pin 5
|
||||
cout << "Analog 5 Voltage: " << sensor->analogReadVolts(5) << endl;
|
||||
// set the gpio at pin 14 to HIGH
|
||||
sensor->gpioSet(14);
|
||||
|
||||
delete sensor;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [Interesting]
|
@ -27,6 +27,8 @@
|
||||
#include "pulsensor.h"
|
||||
#include <signal.h>
|
||||
|
||||
using namespace upm;
|
||||
|
||||
int doWork = 0;
|
||||
|
||||
void
|
||||
|
88
examples/c++/rhusb.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "rhusb.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Using device " << defaultDev << endl;
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an RHUSB instance on defaultDev
|
||||
upm::RHUSB sensor(defaultDev);
|
||||
|
||||
// output the firmware ID
|
||||
cout << "Firmware ID: " << sensor.getFirmwareID() << endl;
|
||||
cout << endl;
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor.getTemperature()
|
||||
<< " C / " << sensor.getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor.getHumidity()
|
||||
<< " %" << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
@ -22,13 +23,14 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "stepmotor.h"
|
||||
#include <signal.h>
|
||||
#include "stepmotor.h"
|
||||
|
||||
int doWork = 0;
|
||||
using namespace std;
|
||||
|
||||
int doWork = 1;
|
||||
upm::StepMotor *sensor = NULL;
|
||||
|
||||
void
|
||||
@ -37,7 +39,7 @@ sig_handler(int signo)
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
doWork = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,26 +47,29 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::StepMotor(4, 6);
|
||||
sensor = new upm::StepMotor(2, 3);
|
||||
|
||||
while (!doWork) {
|
||||
sensor->setSpeed (500);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
while (doWork) {
|
||||
cout << "1 Revolution forward and back at 60 rpm" << endl;
|
||||
sensor->setSpeed(60);
|
||||
sensor->stepForward(200);
|
||||
usleep(1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep(1000000);
|
||||
|
||||
sensor->setSpeed (750);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
cout << "1 Revolution forward and back at 150 rpm" << endl;
|
||||
sensor->setSpeed(150);
|
||||
sensor->stepForward(200);
|
||||
usleep(1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep(1000000);
|
||||
|
||||
sensor->setSpeed (1000);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
cout << "1 Revolution forward and back at 300 rpm" << endl;
|
||||
sensor->setSpeed(300);
|
||||
sensor->stepForward(200);
|
||||
usleep (1000000);
|
||||
sensor->stepBackward(200);
|
||||
usleep (1000000);
|
||||
}
|
||||
|
||||
delete sensor;
|
||||
|
115
examples/c++/t3311.cxx
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 "t3311.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
string defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (argc > 1)
|
||||
defaultDev = string(argv[1]);
|
||||
|
||||
cout << "Initializing..." << endl;
|
||||
|
||||
// Instantiate an T3311 instance, using MODBUS slave address 1, and
|
||||
// default comm parameters (9600, 8, N, 2)
|
||||
upm::T3311 *sensor = new upm::T3311(defaultDev, 1);
|
||||
|
||||
// output the serial number and firmware revision
|
||||
cout << "Serial Number: " << sensor->getSerialNumber() << endl;
|
||||
cout << "Firmware Revision: " << sensor->getFirmwareMajor()
|
||||
<< "." << sensor->getFirmwareMinor() << endl;
|
||||
cout << endl;
|
||||
|
||||
// update and print available values every second
|
||||
while (shouldRun)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor->update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Temperature: " << sensor->getTemperature()
|
||||
<< " C / " << sensor->getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Humidity: " << sensor->getHumidity()
|
||||
<< " %" << endl;
|
||||
|
||||
// this value depends on the sensor configuration -- by default
|
||||
// it is the dew point temperature
|
||||
cout << "Computed Value: " << sensor->getComputedValue() << endl;
|
||||
|
||||
// with FW revisions > 2.44, extended computed data is available
|
||||
if (sensor->extendedDataAvailable())
|
||||
{
|
||||
cout << "Dew Point Temperature: " << sensor->getDewPointTemperature()
|
||||
<< " C / " << sensor->getDewPointTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << "Absolute Humidity: " << sensor->getAbsoluteHumidity()
|
||||
<< " g/m3" << endl;
|
||||
|
||||
cout << "Specific Humidity: " << sensor->getSpecificHumidity()
|
||||
<< " g/kg" << endl;
|
||||
|
||||
cout << "Mixing Ratio: " << sensor->getMixingRatio()
|
||||
<< " g/kg" << endl;
|
||||
|
||||
cout << "Specific Enthalpy: " << sensor->getSpecificEnthalpy()
|
||||
<< " kJ/kg" << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -40,4 +40,4 @@ public class A110XSample {
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_a110x.IsrCallback;
|
||||
|
||||
public class A110X_intrSample {
|
||||
|
||||
public static int counter=0;
|
||||
@ -38,7 +36,7 @@ public class A110X_intrSample {
|
||||
// is detected. This could be used to measure the rotations per
|
||||
// minute (RPM) of a rotor for example.
|
||||
|
||||
IsrCallback callback = new A110XISR();
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
while(true){
|
||||
@ -49,7 +47,7 @@ public class A110X_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class A110XISR extends IsrCallback {
|
||||
class A110XISR implements Runnable {
|
||||
public A110XISR(){
|
||||
super();
|
||||
}
|
||||
|
112
examples/java/CMakeLists.txt
Normal file
@ -0,0 +1,112 @@
|
||||
find_package(Java REQUIRED)
|
||||
include(UseJava)
|
||||
|
||||
macro(add_example example_name jar_name)
|
||||
set(example_src "${example_name}.java")
|
||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_name}/upm_${jar_name}.jar")
|
||||
|
||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||
endmacro()
|
||||
|
||||
macro(add_example_with_path example_name jar_path)
|
||||
set(example_src "${example_name}.java")
|
||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_path}")
|
||||
|
||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||
endmacro()
|
||||
|
||||
add_example(A110X_intrSample a110x)
|
||||
add_example(A110XSample a110x)
|
||||
add_example(ADC121C021Sample adc121c021)
|
||||
add_example(Adxl345Sample adxl345)
|
||||
add_example(Apds9002 apds9002)
|
||||
add_example(BISS0001Sample biss0001)
|
||||
add_example(BMPX8XSample bmpx8x)
|
||||
add_example(BuzzerSample buzzer)
|
||||
add_example(Buzzer_soundSample buzzer)
|
||||
add_example(CJQ4435Sample cjq4435)
|
||||
add_example(DS1307Sample ds1307)
|
||||
add_example(ENC03RSample enc03r)
|
||||
add_example(ES08ASample servo)
|
||||
add_example(GroveButtonSample grove)
|
||||
add_example(GroveButton_intrSample grove)
|
||||
add_example(GroveCollision grovecollision)
|
||||
add_example(GroveEHRSample groveehr)
|
||||
add_example(GroveEmg groveemg)
|
||||
add_example(GroveGsr grovegsr)
|
||||
add_example(GroveLed_multiSample grove)
|
||||
add_example(GroveLEDSample grove)
|
||||
add_example(GroveLightSample grove)
|
||||
add_example(GroveLineFinderSample grovelinefinder)
|
||||
add_example(GroveMDSample grovemd)
|
||||
add_example(GroveMoistureSample grovemoisture)
|
||||
add_example(GroveMQ3 gas)
|
||||
add_example(GroveMQ9 gas)
|
||||
add_example(GroveO2Example groveo2)
|
||||
add_example(GroveQTouch at42qt1070)
|
||||
add_example(GroveRelaySample grove)
|
||||
add_example(GroveRotarySample grove)
|
||||
add_example(GROVESCAMSample grovescam)
|
||||
add_example(GroveSlideSample grove)
|
||||
add_example(GroveSpeakerSample grovespeaker)
|
||||
add_example(GroveTempSample grove)
|
||||
add_example(GroveVDivSample grovevdiv)
|
||||
add_example(GroveWaterSample grovewater)
|
||||
add_example(GroveWFSSample grovewfs)
|
||||
add_example(GUVAS12DSample guvas12d)
|
||||
add_example(H3LIS331DLSample h3lis331dl)
|
||||
add_example(HCSR04Sample hcsr04)
|
||||
add_example(HM11Sample hm11)
|
||||
add_example(Hmc5883lSample hmc5883l)
|
||||
add_example(HMTRPSample hmtrp)
|
||||
add_example(HP20xExample hp20x)
|
||||
add_example(HTU21DSample htu21d)
|
||||
add_example(Itg3200Sample itg3200)
|
||||
add_example(Joystick12Sample joystick12)
|
||||
add_example(LDT0028Sample ldt0028)
|
||||
add_example(LoLSample lol)
|
||||
add_example(LSM303Sample lsm303)
|
||||
add_example(M24LR64ESample m24lr64e)
|
||||
add_example(MAX44000Sample max44000)
|
||||
add_example(MHZ16Sample mhz16)
|
||||
add_example(MicrophoneSample mic)
|
||||
add_example(MMA7455Sample mma7455)
|
||||
add_example(MMA7660Sample mma7660)
|
||||
add_example(MPL3115A2Sample mpl3115a2)
|
||||
add_example(MPR121Sample mpr121)
|
||||
add_example(MPU9150Sample mpu9150)
|
||||
add_example(MQ2Sample gas)
|
||||
add_example(MQ303ASample mq303a)
|
||||
add_example(MQ5Sample gas)
|
||||
add_example(GroveLEDBar my9221)
|
||||
add_example(NRF24L01_receiverSample nrf24l01)
|
||||
add_example(NRF24L01_transmitterSample nrf24l01)
|
||||
add_example(NUNCHUCKSample nunchuck)
|
||||
add_example(OTP538USample otp538u)
|
||||
add_example(PPD42NSSample ppd42ns)
|
||||
add_example(PulsensorSample pulsensor)
|
||||
add_example(RFR359FSample rfr359f)
|
||||
add_example(RotaryEncoderSample rotaryencoder)
|
||||
add_example(RPR220_intrSample rpr220)
|
||||
add_example(RPR220Sample rpr220)
|
||||
add_example(ST7735Sample st7735)
|
||||
add_example(StepMotorSample stepmotor)
|
||||
add_example(TM1637Sample tm1637)
|
||||
add_example(TP401Sample gas)
|
||||
add_example(TSL2561Sample tsl2561)
|
||||
add_example(TTP223Sample ttp223)
|
||||
add_example(Ublox6Sample ublox6)
|
||||
add_example(ULN200XASample uln200xa)
|
||||
add_example(WaterLevelSensor waterlevel)
|
||||
add_example(WT5001Sample wt5001)
|
||||
add_example(YG1006Sample yg1006)
|
||||
add_example(ZFM20Sample zfm20)
|
||||
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(Lcm1602_i2cSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(Lcm1602_parallelSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(SSD1308_oledSample lcd/upm_i2clcd.jar)
|
||||
add_example_with_path(SSD1327_oledSample lcd/upm_i2clcd.jar)
|
||||
|
@ -22,9 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_grove.IsrCallback;
|
||||
|
||||
//NOT TESTED!!!
|
||||
public class GroveButton_intrSample {
|
||||
|
||||
public static int counter = 0;
|
||||
@ -33,8 +30,8 @@ public class GroveButton_intrSample {
|
||||
// ! [Interesting]
|
||||
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
|
||||
|
||||
IsrCallback callback = new ButtonISR();
|
||||
b.installISR(mraa.Edge.EDGE_RISING.swigValue(), callback);
|
||||
ButtonISR callback = new ButtonISR();
|
||||
b.installISR(2, callback);
|
||||
|
||||
while (true) {
|
||||
System.out.println("Counter: " + counter);
|
||||
@ -44,7 +41,7 @@ public class GroveButton_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class ButtonISR extends IsrCallback {
|
||||
class ButtonISR implements Runnable {
|
||||
public ButtonISR() {
|
||||
super();
|
||||
}
|
||||
|
@ -27,13 +27,12 @@ import upm_grovecollision.*;
|
||||
public class GroveCollision {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
// Initializing the sensor on D2 on the Base Shield
|
||||
upm_grovecollision.GroveCollision collision = new upm_grovecollision.GroveCollision(2);
|
||||
boolean collisionState = false;
|
||||
|
||||
// ! [Interesting]
|
||||
while(shouldRun){
|
||||
while(true){
|
||||
if(collision.isColliding() && !collisionState){
|
||||
System.out.println("Collision!!");
|
||||
collisionState = true;
|
||||
@ -44,7 +43,6 @@ public class GroveCollision {
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
System.out.println("Exiting");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,20 +22,20 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MY9221_ledbarSample{
|
||||
public class GroveLEDBar {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
}
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.GroveLEDBar bar = new upm_my9221.GroveLEDBar((short) 8, (short) 9);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
}
|
44
examples/java/Joystick12Sample.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Stefan Andritoiu <stefan.andritoiu@intel.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.
|
||||
*/
|
||||
|
||||
public class Joystick12Sample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate a joystick on analog pins A0 and A1
|
||||
upm_joystick12.Joystick12 joystick = new upm_joystick12.Joystick12(0,1);
|
||||
|
||||
// Print the X and Y input values every second
|
||||
while(true){
|
||||
float x = joystick.getXInput();
|
||||
float y = joystick.getYInput();
|
||||
|
||||
System.out.println("Driving X: " + x + " , and Y: " + y );
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//! [Interesting]
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,7 @@ public class Lcm1602_parallelSample {
|
||||
// 10K trimmer potentiometer:
|
||||
// ends to +5V and ground
|
||||
// wiper to LCD VO pin (pin 3)
|
||||
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602(8, 13, 2, 3, 4, 5, 20, 2);
|
||||
upm_i2clcd.Lcm1602 lcd = new upm_i2clcd.Lcm1602((short) 8, (short) 13, (short) 2, (short) 3, (short) 4, (short) 5, (short) 20, (short) 2);
|
||||
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.write("Hello World");
|
||||
@ -49,4 +49,4 @@ public class Lcm1602_parallelSample {
|
||||
Thread.sleep(5000);
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,26 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
public class MY9221Sample {
|
||||
//NOT TESTED!!!
|
||||
public class LoLSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// Instantiate a Grove LED Bar, with Data pin D8 and Clock pin D9
|
||||
upm_my9221.MY9221 bar = new upm_my9221.MY9221((short) 8, (short) 9);
|
||||
// ! [Interesting]
|
||||
upm_lol.LoL sensor = new upm_lol.LoL();
|
||||
|
||||
int x = 0, y = 0;
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
// revert pixel
|
||||
sensor.setPixel(x, y, sensor.getPixel(x, y));
|
||||
|
||||
}
|
||||
if (++x == 13) {
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
if (y == 9)
|
||||
y = 0;
|
||||
Thread.sleep(10);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_rpr220.IsrCallback;
|
||||
|
||||
public class RPR220_intrSample {
|
||||
|
||||
public static int counter = 0;
|
||||
@ -35,7 +33,7 @@ public class RPR220_intrSample {
|
||||
// Instantiate an RPR220 digital pin D2
|
||||
upm_rpr220.RPR220 sensor = new upm_rpr220.RPR220(2);
|
||||
|
||||
IsrCallback callback = new RPRISR();
|
||||
RPRISR callback = new RPRISR();
|
||||
sensor.installISR(callback);
|
||||
|
||||
while (true) {
|
||||
@ -46,7 +44,7 @@ public class RPR220_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class RPRISR extends IsrCallback {
|
||||
class RPRISR implements Runnable {
|
||||
public RPRISR() {
|
||||
super();
|
||||
}
|
||||
|
@ -25,29 +25,32 @@
|
||||
//NOT TESTED!!!
|
||||
public class StepMotorSample {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_stepmotor.StepMotor sensor = new upm_stepmotor.StepMotor(4, 6);
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_stepmotor.StepMotor sensor = new upm_stepmotor.StepMotor(2, 3);
|
||||
|
||||
while (true) {
|
||||
sensor.setSpeed(500);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
while (true) {
|
||||
System.out.println("One complete rotation forward and back at 60 rpm.");
|
||||
sensor.setSpeed(60);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
|
||||
sensor.setSpeed(750);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
System.out.println("One complete rotation forward and back at 150 rpm.");
|
||||
sensor.setSpeed(150);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
|
||||
sensor.setSpeed(1000);
|
||||
sensor.stepForward(500);
|
||||
Thread.sleep(10);
|
||||
sensor.stepBackwards(500);
|
||||
Thread.sleep(10);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
System.out.println("One complete rotation forward and back at 300 rpm.");
|
||||
sensor.setSpeed(300);
|
||||
sensor.stepForward(200);
|
||||
Thread.sleep(1000);
|
||||
sensor.stepBackward(200);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
||||
|
46
examples/javascript/ads1x15.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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 mraa = require('mraa');
|
||||
var version = mraa.getVersion();
|
||||
|
||||
if (version >= 'v0.6.1') {
|
||||
console.log('mraa version (' + version + ') ok');
|
||||
}
|
||||
else {
|
||||
console.log('mraa version(' + version + ') is old - this code may not work');
|
||||
}
|
||||
|
||||
var ADS1X15 = require('jsupm_ads1x15');
|
||||
var ads1115 = new ADS1X15.ADS1115(1, 0x49);
|
||||
var ads1015 = new ADS1X15.ADS1015(1, 0x48);
|
||||
|
||||
setInterval(function(){
|
||||
console.log(ads1115.getSample());
|
||||
console.log(ads1015.getSample());
|
||||
console.log("*********************");
|
||||
}, 1000);
|
||||
|
||||
|
@ -25,9 +25,9 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Instantiate a Grove Circular LED on gpio pins 5 and 4
|
||||
var GCL = require("jsupm_grovecircularled");
|
||||
var circle = new GCL.GroveCircularLED(5, 4);
|
||||
// Instantiate a Grove Circular LED on gpio pins 9 and 8
|
||||
var GCL = require("jsupm_my9221");
|
||||
var circle = new GCL.GroveCircularLED(9, 8);
|
||||
var level = 0;
|
||||
|
||||
// Show a spinner.
|
||||
|
@ -26,9 +26,9 @@
|
||||
|
||||
var LEDBar = require("jsupm_my9221");
|
||||
|
||||
// Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
// Instantiate a MY9221, we use D8 for the data, and D9 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
var myLEDBar = new LEDBar.MY9221(2, 3);
|
||||
var myLEDBar = new LEDBar.GroveLEDBar(8, 9);
|
||||
|
||||
var directionBool = true;
|
||||
|
64
examples/javascript/hdxxvxta.js
Normal file
@ -0,0 +1,64 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* 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_hdxxvxta');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an HDXXVXTA instance, using A1 for humidity and A0
|
||||
// for temperature
|
||||
var sensor = new sensorObj.HDXXVXTA(1, 0);
|
||||
|
||||
// update and print available values every second
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
|
||||
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||
|
||||
console.log("");
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
86
examples/javascript/hwxpxx.js
Normal file
@ -0,0 +1,86 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* 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_hwxpxx');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
var defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
defaultDev = process.argv[2];
|
||||
}
|
||||
|
||||
console.log("Using device " + defaultDev);
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an HWXPXX instance, using MODBUS slave address 3, and
|
||||
// default comm parameters (19200, 8, N, 2)
|
||||
var sensor = new sensorObj.HWXPXX(defaultDev, 3);
|
||||
|
||||
// output the Slave ID (manufacturer, model, serno)
|
||||
console.log("Slave ID:", sensor.getSlaveID());
|
||||
|
||||
// stored temperature and humidity offsets
|
||||
console.log("Temperature Offset:", sensor.getTemperatureOffset());
|
||||
console.log("Humidity Offset:", sensor.getHumidityOffset());
|
||||
|
||||
console.log("");
|
||||
|
||||
// update and print available values every second
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
|
||||
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||
|
||||
console.log("Slider:", sensor.getSlider(), "%");
|
||||
|
||||
console.log("Override Switch Status:", sensor.getOverrideSwitchStatus());
|
||||
|
||||
console.log("");
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
79
examples/javascript/ili9341.js
Normal file
@ -0,0 +1,79 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/**
|
||||
* Author: Shawn Hymel
|
||||
* Copyright (c) 2016 SparkFun Electronics
|
||||
*
|
||||
* 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 ili9341 = require('jsupm_ili9341');
|
||||
|
||||
// Pins (Edison)
|
||||
// CS_LCD GP44 (MRAA 31)
|
||||
// CS_SD GP43 (MRAA 38) unused
|
||||
// DC GP12 (MRAA 20)
|
||||
// RESEST GP13 (MRAA 14)
|
||||
var lcd = new ili9341.ILI9341(31, 38, 20, 14);
|
||||
|
||||
// Fill the screen with a solid color
|
||||
lcd.fillScreen(lcd.color565(0, 40, 16));
|
||||
|
||||
// Draw some shapes
|
||||
lcd.drawFastVLine(10, 10, 100, ili9341.ILI9341_RED);
|
||||
lcd.drawFastHLine(20, 10, 50, ili9341.ILI9341_CYAN);
|
||||
lcd.drawLine(160, 30, 200, 60, ili9341.ILI9341_GREEN);
|
||||
lcd.fillRect(20, 30, 75, 60, ili9341.ILI9341_ORANGE);
|
||||
lcd.drawCircle(70, 50, 20, ili9341.ILI9341_PURPLE);
|
||||
lcd.fillCircle(120, 50, 20, ili9341.ILI9341_PURPLE);
|
||||
lcd.drawTriangle(50, 100, 10, 140, 90, 140, ili9341.ILI9341_YELLOW);
|
||||
lcd.fillTriangle(150, 100, 110, 140, 190, 140, ili9341.ILI9341_YELLOW);
|
||||
lcd.drawRoundRect(20, 150, 50, 30, 10, ili9341.ILI9341_RED);
|
||||
lcd.drawRoundRect(130, 150, 50, 30, 10, ili9341.ILI9341_RED);
|
||||
lcd.fillRoundRect(75, 150, 50, 30, 10, ili9341.ILI9341_RED);
|
||||
|
||||
// Write some text
|
||||
lcd.setCursor(0, 200);
|
||||
lcd.setTextColor(ili9341.ILI9341_LIGHTGREY);
|
||||
lcd.setTextWrap(true);
|
||||
lcd.setTextSize(1);
|
||||
lcd.print("Text 1\n");
|
||||
lcd.setTextSize(2);
|
||||
lcd.print("Text 2\n");
|
||||
lcd.setTextSize(3);
|
||||
lcd.print("Text 3\n");
|
||||
lcd.setTextSize(4);
|
||||
lcd.print("Text 4\n");
|
||||
|
||||
// Test screen rotation
|
||||
function rotateScreen(r) {
|
||||
lcd.setRotation(r);
|
||||
lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE);
|
||||
if (r < 4) {
|
||||
r++;
|
||||
setTimeout(function() { rotateScreen(r); }, 1000);
|
||||
}
|
||||
}
|
||||
rotateScreen(0);
|
||||
|
||||
// Invert colors, wait, then revert back
|
||||
setTimeout(function() { lcd.invertDisplay(true); }, 4000);
|
||||
setTimeout(function() { lcd.invertDisplay(false); }, 6000);
|
@ -47,16 +47,17 @@ console.log(outputStr);
|
||||
outputStr = "but rather the temperature of the sensor elements.";
|
||||
console.log(outputStr);
|
||||
|
||||
var gas = CO2_lib.new_intp();
|
||||
var temp = CO2_lib.new_intp();
|
||||
|
||||
function writeCO2data()
|
||||
{
|
||||
myCO2_obj.getData(gas, temp);
|
||||
outputStr = "CO2 concentration: " + CO2_lib.intp_value(gas) +
|
||||
" PPM, " +
|
||||
"Temperature (in C): " + CO2_lib.intp_value(temp);
|
||||
console.log(outputStr);
|
||||
if (!myCO2_obj.getData())
|
||||
console.log("Failed to retrieve data");
|
||||
else
|
||||
{
|
||||
outputStr = "CO2 concentration: " + myCO2_obj.getGas() +
|
||||
" PPM, " +
|
||||
"Temperature (in C): " + myCO2_obj.getTemperature();
|
||||
console.log(outputStr);
|
||||
}
|
||||
}
|
||||
var myInterval;
|
||||
setTimeout(function()
|
||||
|
51
examples/javascript/nlgpio16.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@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 sensorObj = require('jsupm_nlgpio16');
|
||||
|
||||
// Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
|
||||
var sensor = new sensorObj.NLGPIO16();
|
||||
|
||||
// get the Version
|
||||
console.log("Device Version:", sensor.getVersion());
|
||||
// read the gpio at pin 3
|
||||
console.log("GPIO 3 Value:", sensor.gpioRead(3));
|
||||
// read the analog voltage at pin 5
|
||||
console.log("Analog 5 Voltage:", sensor.analogReadVolts(5));
|
||||
// set the gpio at pin 14 to HIGH
|
||||
sensor.gpioSet(14);
|
||||
|
||||
/************** Exit code **************/
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
76
examples/javascript/rhusb.js
Normal file
@ -0,0 +1,76 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* 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_rhusb');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
var defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
defaultDev = process.argv[2];
|
||||
}
|
||||
|
||||
console.log("Using device " + defaultDev);
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an RHUSB instance on defaultDev
|
||||
var sensor = new sensorObj.RHUSB(defaultDev);
|
||||
|
||||
// output the firmware ID
|
||||
console.log("Firmware ID:", sensor.getFirmwareID());
|
||||
console.log("");
|
||||
|
||||
// update and print available values every second
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
|
||||
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||
|
||||
console.log("");
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
68
examples/javascript/stepmotor.js
Normal file
@ -0,0 +1,68 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*
|
||||
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.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 lib = require('jsupm_stepmotor');
|
||||
|
||||
// Instantiate a stepper motor driver on pins 2 (direction) and 3 (step)
|
||||
var stepper = new lib.StepMotor(2, 3);
|
||||
|
||||
function delay(milliseconds) {
|
||||
var startTime = Date.now();
|
||||
while (Date.now() - startTime < milliseconds);
|
||||
}
|
||||
|
||||
stepper.quit = function()
|
||||
{
|
||||
stepper = null;
|
||||
lib.cleanUp();
|
||||
lib = null;
|
||||
console.log("Exiting");
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
// The driver is synchronous and blocking
|
||||
console.log("Rotating 1 revolution forward and back at 60 rpm.");
|
||||
stepper.setSpeed(60);
|
||||
stepper.stepForward(200);
|
||||
delay(1000);
|
||||
stepper.stepBackward(200);
|
||||
delay(1000);
|
||||
|
||||
console.log("Rotating 1 revolution forward and back at 150 rpm.");
|
||||
stepper.setSpeed(150);
|
||||
stepper.stepForward(200);
|
||||
delay(1000);
|
||||
stepper.stepBackward(200);
|
||||
delay(1000);
|
||||
|
||||
console.log("Rotating 1 revolution forward and back at 300 rpm.");
|
||||
stepper.setSpeed(300);
|
||||
stepper.stepForward(200);
|
||||
delay(1000);
|
||||
stepper.stepBackward(200);
|
||||
delay(1000);
|
||||
|
||||
stepper.quit();
|
101
examples/javascript/t3311.js
Normal file
@ -0,0 +1,101 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* 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_t3311');
|
||||
|
||||
|
||||
/************** Main code **************/
|
||||
|
||||
var defaultDev = "/dev/ttyUSB0";
|
||||
|
||||
// if an argument was specified, use it as the device instead
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
defaultDev = process.argv[2];
|
||||
}
|
||||
|
||||
console.log("Initializing...");
|
||||
|
||||
// Instantiate an T3311 instance, using MODBUS slave address 1, and
|
||||
// default comm parameters (9600, 8, N, 2)
|
||||
var sensor = new sensorObj.T3311(defaultDev, 1);
|
||||
|
||||
// output the serial number and firmware revision
|
||||
console.log("Serial Number:", sensor.getSerialNumber());
|
||||
console.log("Firmware Revision:", sensor.getFirmwareMajor() + "." +
|
||||
sensor.getFirmwareMinor());
|
||||
console.log("");
|
||||
|
||||
// update and print available values every second
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Temperature:", sensor.getTemperature(),
|
||||
"C /", sensor.getTemperature(true), "F");
|
||||
|
||||
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||
|
||||
// this value depends on the sensor configuration -- by default
|
||||
// it is the dew point temperature
|
||||
console.log("Computed Value:", sensor.getComputedValue());
|
||||
|
||||
// with FW revisions > 2.44, extended computed data is available
|
||||
if (sensor.extendedDataAvailable())
|
||||
{
|
||||
console.log("Dew Point Temperature:", sensor.getDewPointTemperature(),
|
||||
"C /", sensor.getDewPointTemperature(true), "F");
|
||||
|
||||
console.log("Absolute Humidity:", sensor.getAbsoluteHumidity(),
|
||||
"g/m3");
|
||||
|
||||
console.log("Specific Humidity:", sensor.getSpecificHumidity(),
|
||||
"g/kg");
|
||||
|
||||
console.log("Mixing Ratio:", sensor.getMixingRatio(),
|
||||
"g/kg");
|
||||
|
||||
console.log("Specific Enthalpy:", sensor.getSpecificEnthalpy(),
|
||||
"kJ/kg");
|
||||
}
|
||||
|
||||
console.log("");
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
@ -29,10 +29,11 @@ import pyupm_i2clcd as lcdObj
|
||||
lcd = lcdObj.EBOLED();
|
||||
|
||||
lcd.clear();
|
||||
lcd.setCursor(2, 0);
|
||||
lcd.setCursor(10, 15);
|
||||
lcd.write("Hello");
|
||||
lcd.setCursor(3, 5);
|
||||
lcd.setCursor(30, 15);
|
||||
lcd.write("World!");
|
||||
lcd.refresh();
|
||||
print "Sleeping for 5 seconds..."
|
||||
time.sleep(5)
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_grovecircularled as upmGroveCircularLED
|
||||
import pyupm_my9221 as upmGroveCircularLED
|
||||
|
||||
# Exit handlers
|
||||
def SIGINTHandler(signum, frame):
|
||||
@ -39,8 +39,8 @@ atexit.register(exitHandler)
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# Instantiate a Grove Circular LED on gpio pins 5 and 4
|
||||
circle = upmGroveCircularLED.GroveCircularLED(5, 4)
|
||||
# Instantiate a Grove Circular LED on gpio pins 9 and 8
|
||||
circle = upmGroveCircularLED.GroveCircularLED(9, 8)
|
||||
|
||||
level = 0
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_my9221 as upmMy9221
|
||||
|
||||
# Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
# Instantiate a MY9221, we use D8 for the data, and D9 for the
|
||||
# data clock. This was tested with a Grove LED bar.
|
||||
myLEDBar = upmMy9221.MY9221(2, 3)
|
||||
myLEDBar = upmMy9221.GroveLEDBar(8, 9)
|
||||
|
||||
|
||||
# Exit handlers
|
59
examples/python/hdxxvxta.py
Normal file
@ -0,0 +1,59 @@
|
||||
#!/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.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_hdxxvxta as sensorObj
|
||||
|
||||
## 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)
|
||||
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an HDXXVXTA instance, using A1 for humidity and A0
|
||||
# for temperature
|
||||
sensor = sensorObj.HDXXVXTA(1, 0)
|
||||
|
||||
# update and print available values every second
|
||||
while (1):
|
||||
# update our values from the sensor
|
||||
sensor.update()
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Humidity:", sensor.getHumidity(), "%"
|
||||
|
||||
print
|
||||
time.sleep(1)
|
79
examples/python/hwxpxx.py
Normal file
@ -0,0 +1,79 @@
|
||||
#!/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.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_hwxpxx as sensorObj
|
||||
|
||||
## 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)
|
||||
|
||||
defaultDev = "/dev/ttyUSB0"
|
||||
|
||||
# if an argument was specified, use it as the device instead
|
||||
if (len(sys.argv) > 1):
|
||||
defaultDev = sys.argv[1]
|
||||
|
||||
print "Using device", defaultDev
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an HWXPXX instance, using MODBUS slave address 3, and
|
||||
# default comm parameters (19200, 8, N, 2)
|
||||
sensor = sensorObj.HWXPXX(defaultDev, 3)
|
||||
|
||||
# output the serial number and firmware revision
|
||||
print "Slave ID:", sensor.getSlaveID()
|
||||
|
||||
# stored temperature and humidity offsets
|
||||
print "Temperature Offset:", sensor.getTemperatureOffset()
|
||||
print "Humidity Offset:", sensor.getHumidityOffset()
|
||||
|
||||
print
|
||||
|
||||
# update and print available values every second
|
||||
while (1):
|
||||
# update our values from the sensor
|
||||
sensor.update()
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Humidity:", sensor.getHumidity(), "%"
|
||||
|
||||
print "Slider:", sensor.getSlider(), "%"
|
||||
|
||||
print "Override Switch Status:", sensor.getOverrideSwitchStatus()
|
||||
|
||||
print
|
||||
time.sleep(1)
|
75
examples/python/ili9341.py
Normal file
@ -0,0 +1,75 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Shawn Hymel
|
||||
# Copyright (c) 2016 SparkFun Electronics
|
||||
#
|
||||
# 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 time
|
||||
import pyupm_ili9341 as ili9341
|
||||
|
||||
# Pins (Edison)
|
||||
# CS_LCD GP44 (MRAA 31)
|
||||
# CS_SD GP43 (MRAA 38) unused
|
||||
# DC GP12 (MRAA 20)
|
||||
# RESEST GP13 (MRAA 14)
|
||||
lcd = ili9341.ILI9341(31, 38, 20, 14)
|
||||
|
||||
# Fill the screen with a solid color
|
||||
lcd.fillScreen(lcd.color565(0, 40, 16))
|
||||
|
||||
# Draw some shapes
|
||||
lcd.drawFastVLine(10, 10, 100, ili9341.ILI9341_RED)
|
||||
lcd.drawFastHLine(20, 10, 50, ili9341.ILI9341_CYAN)
|
||||
lcd.drawLine(160, 30, 200, 60, ili9341.ILI9341_GREEN)
|
||||
lcd.fillRect(20, 30, 75, 60, ili9341.ILI9341_ORANGE)
|
||||
lcd.drawCircle(70, 50, 20, ili9341.ILI9341_PURPLE)
|
||||
lcd.fillCircle(120, 50, 20, ili9341.ILI9341_PURPLE)
|
||||
lcd.drawTriangle(50, 100, 10, 140, 90, 140, ili9341.ILI9341_YELLOW)
|
||||
lcd.fillTriangle(150, 100, 110, 140, 190, 140, ili9341.ILI9341_YELLOW)
|
||||
lcd.drawRoundRect(20, 150, 50, 30, 10, ili9341.ILI9341_RED)
|
||||
lcd.drawRoundRect(130, 150, 50, 30, 10, ili9341.ILI9341_RED)
|
||||
lcd.fillRoundRect(75, 150, 50, 30, 10, ili9341.ILI9341_RED)
|
||||
|
||||
# Write some text
|
||||
lcd.setCursor(0, 200)
|
||||
lcd.setTextColor(ili9341.ILI9341_LIGHTGREY)
|
||||
lcd.setTextWrap(True)
|
||||
lcd.setTextSize(1)
|
||||
lcd._print("Text 1\n")
|
||||
lcd.setTextSize(2)
|
||||
lcd._print("Text 2\n")
|
||||
lcd.setTextSize(3)
|
||||
lcd._print("Text 3\n")
|
||||
lcd.setTextSize(4)
|
||||
lcd._print("Text 4\n")
|
||||
|
||||
# Test screen rotation
|
||||
for r in range(0, 4):
|
||||
lcd.setRotation(r)
|
||||
lcd.fillRect(0, 0, 5, 5, ili9341.ILI9341_WHITE)
|
||||
time.sleep(1)
|
||||
|
||||
# Invert colors, wait, then revert back
|
||||
lcd.invertDisplay(True)
|
||||
time.sleep(2)
|
||||
lcd.invertDisplay(False)
|
||||
|
||||
# Don't forget to free up that memory!
|
||||
del lcd
|
@ -56,16 +56,15 @@ print ("Make sure that the sensor has had "
|
||||
"The temperature reported is not the ambient temperature,\n"
|
||||
"but rather the temperature of the sensor elements.")
|
||||
|
||||
gas = upmMhz16.new_intp()
|
||||
temp = upmMhz16.new_intp()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
while(1):
|
||||
myCO2.getData(gas, temp)
|
||||
outputStr = ("CO2 concentration: {0} PPM, "
|
||||
"Temperature (in C): {1}".format(
|
||||
upmMhz16.intp_value(gas), upmMhz16.intp_value(temp)))
|
||||
print outputStr
|
||||
if (not myCO2.getData()):
|
||||
print "Failed to retrieve data"
|
||||
else:
|
||||
outputStr = ("CO2 concentration: {0} PPM, "
|
||||
"Temperature (in C): {1}".format(
|
||||
myCO2.getGas(), myCO2.getTemperature()))
|
||||
print outputStr
|
||||
|
||||
time.sleep(2)
|
||||
|
51
examples/python/nlgpio16.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@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.
|
||||
|
||||
import sys, signal, atexit
|
||||
import pyupm_nlgpio16 as sensorObj
|
||||
|
||||
# Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
|
||||
sensor = sensorObj.NLGPIO16()
|
||||
|
||||
## Exit handlers ##
|
||||
# This 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)
|
||||
|
||||
# get the Version
|
||||
print "Device Version:", sensor.getVersion()
|
||||
# read the gpio at pin 3
|
||||
print "GPIO 3 Value:", sensor.gpioRead(3)
|
||||
# read the analog voltage at pin 5
|
||||
print "Analog 5 Voltage:", sensor.analogReadVolts(5)
|
||||
# set the gpio at pin 14 to HIGH
|
||||
sensor.gpioSet(14)
|
69
examples/python/rhusb.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!/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.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_rhusb as sensorObj
|
||||
|
||||
## 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)
|
||||
|
||||
defaultDev = "/dev/ttyUSB0"
|
||||
|
||||
# if an argument was specified, use it as the device instead
|
||||
if (len(sys.argv) > 1):
|
||||
defaultDev = sys.argv[1]
|
||||
|
||||
print "Using device", defaultDev
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an RHUSB instance on defaultDev
|
||||
sensor = sensorObj.RHUSB(defaultDev)
|
||||
|
||||
# output the firmware ID
|
||||
print "Firmware ID:", sensor.getFirmwareID()
|
||||
print
|
||||
|
||||
# update and print available values every second
|
||||
while (1):
|
||||
# update our values from the sensor
|
||||
sensor.update()
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Humidity:", sensor.getHumidity(), "%"
|
||||
|
||||
print
|
||||
time.sleep(1)
|
64
examples/python/stepmotor.py
Normal file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Mihai Tudor Panu <mihai.tudor.panu@intel.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.
|
||||
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_stepmotor as mylib
|
||||
|
||||
# Instantiate a StepMotor object on pins 2 (dir) and 3 (step)
|
||||
stepper = mylib.StepMotor(2, 3)
|
||||
|
||||
## Exit handlers ##
|
||||
# This stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
print "Rotating 1 revolution forward and back at 60 rpm."
|
||||
stepper.setSpeed(60)
|
||||
stepper.stepForward(200)
|
||||
time.sleep(1)
|
||||
stepper.stepBackward(200)
|
||||
time.sleep(1)
|
||||
|
||||
print "Rotating 1 revolution forward and back at 150 rpm."
|
||||
stepper.setSpeed(150)
|
||||
stepper.stepForward(200)
|
||||
time.sleep(1)
|
||||
stepper.stepBackward(200)
|
||||
time.sleep(1)
|
||||
|
||||
print "Rotating 1 revolution forward and back at 300 rpm."
|
||||
stepper.setSpeed(300)
|
||||
stepper.stepForward(200)
|
||||
time.sleep(1)
|
||||
stepper.stepBackward(200)
|
||||
time.sleep(1)
|
90
examples/python/t3311.py
Normal file
@ -0,0 +1,90 @@
|
||||
#!/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.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_t3311 as sensorObj
|
||||
|
||||
## 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)
|
||||
|
||||
defaultDev = "/dev/ttyUSB0"
|
||||
|
||||
# if an argument was specified, use it as the device instead
|
||||
if (len(sys.argv) > 1):
|
||||
defaultDev = sys.argv[1]
|
||||
|
||||
print "Initializing..."
|
||||
|
||||
# Instantiate an T3311 instance, using MODBUS slave address 1, and
|
||||
# default comm parameters (9600, 8, N, 2)
|
||||
sensor = sensorObj.T3311(defaultDev, 1)
|
||||
|
||||
# output the serial number and firmware revision
|
||||
print "Serial Number:", sensor.getSerialNumber()
|
||||
print "Firmware Revision: {0}.{1}".format(sensor.getFirmwareMajor(),
|
||||
sensor.getFirmwareMinor())
|
||||
print
|
||||
|
||||
# update and print available values every second
|
||||
while (1):
|
||||
# update our values from the sensor
|
||||
sensor.update()
|
||||
|
||||
# we show both C and F for temperature
|
||||
print "Temperature:", sensor.getTemperature(), "C /",
|
||||
print sensor.getTemperature(True), "F"
|
||||
|
||||
print "Humidity:", sensor.getHumidity(), "%"
|
||||
|
||||
# this value depends on the sensor configuration -- by default
|
||||
# it is the dew point temperature
|
||||
print "Computed Value:", sensor.getComputedValue()
|
||||
|
||||
# with FW revisions > 2.44, extended computed data is available
|
||||
if (sensor.extendedDataAvailable()):
|
||||
print "Dew Point Temperature:", sensor.getDewPointTemperature(),
|
||||
print "C /", sensor.getDewPointTemperature(True), "F"
|
||||
|
||||
print "Absolute Humidity:", sensor.getAbsoluteHumidity(), "g/m3"
|
||||
|
||||
print "Specific Humidity:", sensor.getSpecificHumidity(),
|
||||
print "g/kg"
|
||||
|
||||
print "Mixing Ratio:", sensor.getMixingRatio(), "g/kg"
|
||||
|
||||
print "Specific Enthalpy:", sensor.getSpecificEnthalpy(),
|
||||
print "kJ/kg"
|
||||
|
||||
print
|
||||
time.sleep(1)
|
@ -1,3 +1,14 @@
|
||||
macro (file_to_list readfile outlist)
|
||||
FILE(READ "${readfile}" contents)
|
||||
STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
|
||||
STRING(REGEX REPLACE "\n" ";" contents "${contents}")
|
||||
set("${outlist}" "${contents}" )
|
||||
endmacro()
|
||||
|
||||
file_to_list ("javaswig_blacklist" JAVASWIG_BLACKLIST)
|
||||
file_to_list ("pythonswig_blacklist" PYTHONSWIG_BLACKLIST)
|
||||
file_to_list ("nodeswig_blacklist" NODESWIG_BLACKLIST)
|
||||
|
||||
macro(subdirlist result curdir)
|
||||
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||
set(dirlist "")
|
||||
@ -18,6 +29,7 @@ endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
||||
macro(upm_SWIG_PYTHON)
|
||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
|
||||
target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
|
||||
@ -49,9 +61,9 @@ macro(upm_SWIG_NODE)
|
||||
)
|
||||
if (${V8_VERSION_MAJOR} GREATER 3)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
||||
endif()
|
||||
endif()
|
||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
@ -66,6 +78,7 @@ macro(upm_SWIG_JAVA)
|
||||
if (BUILDSWIGJAVA AND BUILDSWIG)
|
||||
|
||||
FIND_PACKAGE (JNI REQUIRED)
|
||||
pkg_check_modules (MRAAJAVA REQUIRED mraajava>=0.8.0)
|
||||
|
||||
include_directories (
|
||||
${JAVA_INCLUDE_PATH}
|
||||
@ -76,7 +89,7 @@ macro(upm_SWIG_JAVA)
|
||||
set_source_files_properties (javaupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (javaupm_${libname}.i PROPERTIES SWIG_FLAGS ";-package;upm_${libname};-I${CMAKE_BINARY_DIR}/src")
|
||||
swig_add_module (javaupm_${libname} java javaupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (javaupm_${libname} ${MRAA_LIBRARIES} ${JAVA_LIBRARIES})
|
||||
swig_link_libraries (javaupm_${libname} ${MRAAJAVA_LDFLAGS} ${JAVA_LDFLAGS})
|
||||
target_include_directories ( ${SWIG_MODULE_javaupm_${libname}_REAL_NAME}
|
||||
PUBLIC
|
||||
"${JAVA_INCLUDE_DIRS}"
|
||||
@ -87,12 +100,8 @@ macro(upm_SWIG_JAVA)
|
||||
PREFIX "lib"
|
||||
SUFFIX ".so"
|
||||
)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libjavaupm_${libname}.so
|
||||
DESTINATION lib/java
|
||||
)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar
|
||||
DESTINATION lib/java
|
||||
)
|
||||
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
|
||||
|
||||
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
|
||||
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
|
||||
@ -120,16 +129,8 @@ macro(upm_doxygen)
|
||||
set (classname ${libname})
|
||||
endif()
|
||||
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
||||
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
|
||||
${CMAKE_BINARY_DIR}/xml/${classname}_8h.xml
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/xml/${classname}_8h.xml
|
||||
)
|
||||
add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
|
||||
add_dependencies (${libname}doc_i doc)
|
||||
if (BUILDSWIG)
|
||||
add_dependencies (_pyupm_${libname} ${libname}doc_i)
|
||||
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
|
||||
add_dependencies (pydoc _pyupm_${libname})
|
||||
else ()
|
||||
add_dependencies (${libname} doc)
|
||||
@ -165,18 +166,16 @@ if (SWIG_FOUND)
|
||||
endmacro()
|
||||
|
||||
endif(BUILDSWIGNODE)
|
||||
# if(BUILDSWIGJAVA)
|
||||
# add_subdirectory (java)
|
||||
# endif(BUILDSWIGJAVA)
|
||||
|
||||
|
||||
endif()
|
||||
|
||||
macro(upm_module_init)
|
||||
link_directories (${MRAA_LIBDIR})
|
||||
add_library (${libname} SHARED ${module_src})
|
||||
foreach (linkflag ${ARGN})
|
||||
target_link_libraries (${libname} ${linkflag})
|
||||
endforeach ()
|
||||
include_directories (${MRAA_INCLUDE_DIR} .)
|
||||
include_directories (${MRAA_INCLUDE_DIRS} .)
|
||||
target_link_libraries (${libname} ${MRAA_LIBRARIES})
|
||||
set_target_properties(
|
||||
${libname}
|
||||
@ -186,9 +185,15 @@ macro(upm_module_init)
|
||||
)
|
||||
upm_create_install_pkgconfig (upm-${libname}.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
if (SWIG_FOUND)
|
||||
upm_swig_python()
|
||||
upm_swig_node()
|
||||
upm_swig_java()
|
||||
if (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};")
|
||||
upm_swig_python()
|
||||
endif()
|
||||
if (NOT ";${NODESWIG_BLACKLIST};" MATCHES ";${libname};")
|
||||
upm_swig_node()
|
||||
endif()
|
||||
if (NOT ";${JAVASWIG_BLACKLIST};" MATCHES ";${libname};")
|
||||
upm_swig_java()
|
||||
endif()
|
||||
endif()
|
||||
if (BUILDDOC)
|
||||
upm_doxygen()
|
||||
@ -202,6 +207,24 @@ macro(upm_module_init)
|
||||
endif()
|
||||
endmacro(upm_module_init)
|
||||
|
||||
# Generate python module documentation from doxygen collateral
|
||||
if (BUILDDOC AND BUILDSWIGPYTHON AND SWIG_FOUND)
|
||||
# doxy2swig the doxygen output
|
||||
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py
|
||||
${CMAKE_BINARY_DIR}/xml/index.xml
|
||||
${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/xml/index.xml
|
||||
)
|
||||
add_custom_target (pyupm_doxy2swig DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i)
|
||||
add_dependencies (pyupm_doxy2swig doc)
|
||||
# BUILDDOC not set but still building python modules, generate an empty
|
||||
# pyupm_doxy2swig.i file (overwriting if necessary)
|
||||
elseif (BUILDSWIGPYTHON AND SWIG_FOUND)
|
||||
message (INFO " Generating empty ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i")
|
||||
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/pyupm_doxy2swig.i "// Empty doxy2swig stub")
|
||||
endif (BUILDDOC AND BUILDSWIGPYTHON AND SWIG_FOUND)
|
||||
|
||||
if (MODULE_LIST)
|
||||
set(SUBDIRS ${MODULE_LIST})
|
||||
set(SUBDIRS ${SUBDIRS} upm)
|
||||
|
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
class IsrCallback
|
||||
{
|
||||
public:
|
||||
virtual ~IsrCallback()
|
||||
{
|
||||
}
|
||||
virtual void run()
|
||||
{ /* empty, overloaded in Java*/
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
static void generic_callback_isr (void* data)
|
||||
{
|
||||
IsrCallback* callback = (IsrCallback*) data;
|
||||
if (callback == NULL)
|
||||
return;
|
||||
callback->run();
|
||||
}
|
||||
#endif
|
@ -58,9 +58,9 @@ bool A110X::magnetDetected()
|
||||
}
|
||||
|
||||
#ifdef JAVACALLBACK
|
||||
void A110X::installISR( IsrCallback *cb)
|
||||
void A110X::installISR(jobject runnable)
|
||||
{
|
||||
installISR(generic_callback_isr, cb);
|
||||
installISR(mraa_java_isr_callback, runnable);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -70,7 +70,7 @@ void A110X::installISR(void (*isr)(void *), void *arg)
|
||||
uninstallISR();
|
||||
|
||||
// install our interrupt handler
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_FALLING,
|
||||
mraa_gpio_isr(m_gpio, MRAA_GPIO_EDGE_BOTH,
|
||||
isr, arg);
|
||||
m_isrInstalled = true;
|
||||
}
|
||||
|
@ -26,10 +26,6 @@
|
||||
#include <string>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
#include "../IsrCallback.h"
|
||||
#endif
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief A110X Hall Effect library
|
||||
@ -90,7 +86,7 @@ namespace upm {
|
||||
* argument to the ISR.
|
||||
*/
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
void installISR(IsrCallback *cb);
|
||||
void installISR(jobject runnable);
|
||||
#else
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
|
@ -1,13 +1,8 @@
|
||||
%module(directors="1") javaupm_a110x
|
||||
%module javaupm_a110x
|
||||
%include "../upm.i"
|
||||
%include "stdint.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
%feature("director") IsrCallback;
|
||||
|
||||
%ignore generic_callback_isr;
|
||||
%include "../IsrCallback.h"
|
||||
|
||||
%{
|
||||
#include "a110x.h"
|
||||
%}
|
||||
@ -22,4 +17,4 @@
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
||||
%}
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_a110x
|
||||
%include "../upm.i"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_ad8232
|
||||
%include "../upm.i"
|
||||
|
||||
|
@ -9,9 +9,11 @@ add_dependencies(${libname} pca9685)
|
||||
target_link_libraries(${libname} pca9685)
|
||||
if (BUILDSWIG)
|
||||
if (BUILDSWIGNODE)
|
||||
set_target_properties(${SWIG_MODULE_jsupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||
swig_link_libraries (jsupm_${libname} pca9685 ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||
endif()
|
||||
if (BUILDSWIGPYTHON)
|
||||
set_target_properties(${SWIG_MODULE_pyupm_${libname}_REAL_NAME} PROPERTIES SKIP_BUILD_RPATH TRUE)
|
||||
swig_link_libraries (pyupm_${libname} pca9685 ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_adafruitms1438
|
||||
%include "../upm.i"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_adafruitss
|
||||
%include "../upm.i"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_adc121c021
|
||||
%include "../upm.i"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_adis16448
|
||||
%include "../upm.i"
|
||||
|
||||
|
5
src/ads1x15/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "ads1x15")
|
||||
set (libdescription "analog to digital converter")
|
||||
set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx)
|
||||
set (module_h ${libname}.h ads1115.h ads1015.h)
|
||||
upm_module_init()
|
102
src/ads1x15/ads1015.cxx
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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.
|
||||
*/
|
||||
#include "ads1015.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
void
|
||||
ADS1015::setSPS(ADSSAMPLERATE rate){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||
}
|
||||
|
||||
ADS1015::ADS1015(int bus, uint8_t address) : ADS1X15(bus, address) {
|
||||
m_name = "ADS1015";
|
||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||
m_bitShift = 4;
|
||||
ADS1X15::getCurrentConfig();
|
||||
}
|
||||
|
||||
ADS1015::~ADS1015(){};
|
||||
|
||||
//Private functions
|
||||
float
|
||||
ADS1015::getMultiplier(void){
|
||||
float multi = 0.0;
|
||||
switch((ADSGAIN)m_config_reg & ADS1X15_PGA_MASK){
|
||||
case GAIN_TWOTHIRDS:
|
||||
multi = 0.003;
|
||||
break;
|
||||
case GAIN_ONE:
|
||||
multi = 0.002;
|
||||
break;
|
||||
case GAIN_TWO:
|
||||
multi = 0.001;
|
||||
break;
|
||||
case GAIN_FOUR:
|
||||
multi = 0.0005;
|
||||
break;
|
||||
case GAIN_EIGHT:
|
||||
multi = 0.00025;
|
||||
break;
|
||||
case GAIN_SIXTEEN:
|
||||
multi = 0.000125;
|
||||
break;
|
||||
default:
|
||||
multi = 0.001;
|
||||
break;
|
||||
}
|
||||
return multi;
|
||||
}
|
||||
|
||||
void
|
||||
ADS1015::setDelay(){
|
||||
switch((int)ADS1X15::getSPS()){
|
||||
case 0:
|
||||
m_conversionDelay = 8000;
|
||||
break;
|
||||
case 32:
|
||||
m_conversionDelay = 4000;
|
||||
break;
|
||||
case 64:
|
||||
m_conversionDelay = 3000;
|
||||
break;
|
||||
case 96:
|
||||
m_conversionDelay = 1100;
|
||||
break;
|
||||
case 128:
|
||||
m_conversionDelay = 700;
|
||||
break;
|
||||
case 160:
|
||||
m_conversionDelay = 500;
|
||||
break;
|
||||
case 192:
|
||||
m_conversionDelay = 400;
|
||||
break;
|
||||
default:
|
||||
m_conversionDelay = 8000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
140
src/ads1x15/ads1015.h
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/*=========================================================================*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ads1x15.h"
|
||||
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
CONVERSION DELAY (in microS)
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1015_CONVERSIONDELAY (8000)
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
CONFIG REGISTER
|
||||
|
||||
-----------------------------------------------------------------------*/
|
||||
|
||||
#define ADS1015_DR_MASK (0x00E0)
|
||||
#define ADS1015_DR_128SPS (0x0000) // 128 samples per second
|
||||
#define ADS1015_DR_250SPS (0x0020) // 250 samples per second
|
||||
#define ADS1015_DR_490SPS (0x0040) // 490 samples per second
|
||||
#define ADS1015_DR_920SPS (0x0060) // 920 samples per second
|
||||
#define ADS1015_DR_1600SPS (0x0080) // 1600 samples per second (default)
|
||||
#define ADS1015_DR_2400SPS (0x00A0) // 2400 samples per second
|
||||
#define ADS1015_DR_3300SPS (0x00C0) // 3300 samples per second
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @library ads1x15
|
||||
* @sensor ADS1015
|
||||
* @comname ADS1015 ADC
|
||||
* @type electric
|
||||
* @man ti adafruit
|
||||
* @con i2c
|
||||
* @web web http://www.ti.com/lit/ds/symlink/ads1015.pdf
|
||||
*
|
||||
* @brief API for ADS1015
|
||||
*
|
||||
* The ADS1013, ADS1014, and ADS1015 are precision analog-to-digital converters (ADCs) with 12 bits of resolution
|
||||
* offered in an ultra-small, leadless QFN-10 package or an MSOP-10 package. The ADS1013/4/5 are designed with
|
||||
* precision, power, and ease of implementation in mind. The ADS1013/4/5 feature an onboard reference and oscillator.
|
||||
* Data is transferred via an I2C-compatible serial interface; four I2C slave addresses can be selected. The ADS1013/4/5
|
||||
* operate from a single power supply ranging from 2.0V to 5.5V.
|
||||
* The ADS1013/4/5 can perform conversions at rates up to 3300 samples per second (SPS). An onboard PGA is available
|
||||
* on the ADS1014 and ADS1015 that offers input ranges from the supply to as low as ±256mV, allowing both large and small
|
||||
* signals to be measured with high resolution. The ADS1015 also features an input multiplexer (MUX) that provides two
|
||||
* differential or four single-ended inputs.
|
||||
* The ADS1013/4/5 operate either in continuous conversion mode or a single-shot mode that automatically powers down
|
||||
* after a conversion and greatly reduces current consumption during idle periods. The ADS1013/4/5 are specified from
|
||||
* –40°C to +125°C.
|
||||
*
|
||||
* Tested with Adafriut ADS1015 board: https://www.adafruit.com/products/1083
|
||||
*
|
||||
* @image html ads1015.jpg
|
||||
* @snippet ads1x15.cxx Interesting
|
||||
*/
|
||||
class ADS1015 : public ADS1X15 {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @enum ADSSAMPLERATE
|
||||
* @brief uint16_t enum containing values
|
||||
* representing the sample rate of the device.
|
||||
*
|
||||
* @var ADSSAMPLERATE::SPS_128 = 0x0000
|
||||
* @var ADSSAMPLERATE::SPS_250 = 0x0020
|
||||
* @var ADSSAMPLERATE::SPS_490 = 0x0040
|
||||
* @var ADSSAMPLERATE::SPS_920 = 0x0060
|
||||
* @var ADSSAMPLERATE::SPS_1600 = 0x0080
|
||||
* @var ADSSAMPLERATE::SPS_2400 = 0x00A0
|
||||
* @var ADSSAMPLERATE::SPS_3300 = 0x00C0
|
||||
*/
|
||||
typedef enum ADSSAMPLERATE {
|
||||
SPS_128 = ADS1015_DR_128SPS,
|
||||
SPS_250 = ADS1015_DR_250SPS,
|
||||
SPS_490 = ADS1015_DR_490SPS,
|
||||
SPS_920 = ADS1015_DR_920SPS,
|
||||
SPS_1600 = ADS1015_DR_1600SPS,
|
||||
SPS_2400 = ADS1015_DR_2400SPS,
|
||||
SPS_3300 = ADS1015_DR_3300SPS
|
||||
} ADSSAMPLERATE;
|
||||
|
||||
|
||||
/**
|
||||
* ADS1X15 constructor
|
||||
*
|
||||
* @param bus i2c bus the sensor is attached to.
|
||||
* @param address. Device address. Default is 0x48.
|
||||
*/
|
||||
ADS1015 (int bus, uint8_t address = 0x48);
|
||||
|
||||
/**
|
||||
* ADS1X15 destructor
|
||||
*/
|
||||
~ADS1015 ();
|
||||
|
||||
/**
|
||||
* Sets the sample rate of the device. This function
|
||||
* needs to be overridden in subclasses as the ADS1115 and
|
||||
* ADS1015 have different sample rates.
|
||||
*
|
||||
* @param ADSSAMPLERATE enum
|
||||
*/
|
||||
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
||||
|
||||
protected:
|
||||
float getMultiplier(void);
|
||||
void setDelay(void);
|
||||
|
||||
};
|
||||
}
|
103
src/ads1x15/ads1115.cxx
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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.
|
||||
*/
|
||||
#include "ads1115.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
ADS1115::ADS1115(int bus, uint8_t address) : ADS1X15(bus, address) {
|
||||
m_name = "ADS1115";
|
||||
m_conversionDelay = ADS1115_CONVERSIONDELAY;
|
||||
m_bitShift = 0;
|
||||
ADS1X15::getCurrentConfig();
|
||||
}
|
||||
|
||||
ADS1115::~ADS1115(){};
|
||||
|
||||
void
|
||||
ADS1115::setSPS(ADSDATARATE rate){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||
}
|
||||
|
||||
//Protected functions
|
||||
float
|
||||
ADS1115::getMultiplier(void){
|
||||
float multi = 0.0;
|
||||
switch((ADSGAIN)m_config_reg & ADS1X15_PGA_MASK){
|
||||
case GAIN_TWOTHIRDS:
|
||||
multi = 0.0001875;
|
||||
break;
|
||||
case GAIN_ONE:
|
||||
multi = 0.000125;
|
||||
break;
|
||||
case GAIN_TWO:
|
||||
multi = 0.0000625;
|
||||
break;
|
||||
case GAIN_FOUR:
|
||||
multi = 0.00003125;
|
||||
break;
|
||||
case GAIN_EIGHT:
|
||||
multi = 0.000015625;
|
||||
break;
|
||||
case GAIN_SIXTEEN:
|
||||
multi = 0.0000078125;
|
||||
break;
|
||||
default:
|
||||
multi = 0.0001875;
|
||||
break;
|
||||
}
|
||||
return multi;
|
||||
}
|
||||
|
||||
void
|
||||
ADS1115::setDelay(){
|
||||
switch((int)ADS1X15::getSPS()){
|
||||
case 0:
|
||||
m_conversionDelay = 126000;
|
||||
break;
|
||||
case 32:
|
||||
m_conversionDelay = 63000;
|
||||
break;
|
||||
case 64:
|
||||
m_conversionDelay = 32000;
|
||||
break;
|
||||
case 96:
|
||||
m_conversionDelay = 16000;
|
||||
break;
|
||||
case 128:
|
||||
m_conversionDelay = 8000;
|
||||
break;
|
||||
case 160:
|
||||
m_conversionDelay = 4500;
|
||||
break;
|
||||
case 192:
|
||||
m_conversionDelay = 2200;
|
||||
break;
|
||||
case 224:
|
||||
m_conversionDelay = 1200;
|
||||
break;
|
||||
default:
|
||||
m_conversionDelay = 126000;
|
||||
break;
|
||||
}
|
||||
}
|
145
src/ads1x15/ads1115.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
/*=========================================================================*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ads1x15.h"
|
||||
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
CONVERSION DELAY (in microS)
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1115_CONVERSIONDELAY (8000)
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
CONFIG REGISTER
|
||||
|
||||
-----------------------------------------------------------------------*/
|
||||
|
||||
#define ADS1115_DR_MASK (0x00E0)
|
||||
#define ADS1115_DR_8SPS (0x0000) // 8 samples per second
|
||||
#define ADS1115_DR_16SPS (0x0020) // 16 samples per second
|
||||
#define ADS1115_DR_32SPS (0x0040) // 32 samples per second
|
||||
#define ADS1115_DR_64SPS (0x0060) // 64 samples per second
|
||||
#define ADS1115_DR_128SPS (0x0080) // 128 samples per second (default)
|
||||
#define ADS1115_DR_250SPS (0x00A0) // 250 samples per second
|
||||
#define ADS1115_DR_475SPS (0x00C0) // 475 samples per second
|
||||
#define ADS1115_DR_860SPS (0x00E0) // 860 samples per second
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @library ads1x15
|
||||
* @sensor ADS1115
|
||||
* @comname ADS1115 ADC
|
||||
* @type electric
|
||||
* @man ti adafruit
|
||||
* @con i2c
|
||||
* @web http://www.ti.com/lit/ds/symlink/ads1115.pdf
|
||||
*
|
||||
* @brief API for ADS1115
|
||||
*
|
||||
* The ADS1113, ADS1114, and ADS1115 are precision analog-to-digital converters (ADCs) with 16 bits of resolution offered
|
||||
* in an ultra-small, leadless QFN-10 package or an MSOP-10 package. The ADS1113/4/5 are designed with precision, power,
|
||||
* and ease of implementation in mind. The ADS1113/4/5 feature an onboard reference and oscillator. Data is transferred via
|
||||
* an I2C-compatible serial interface; four I2C slave addresses can be selected. The ADS1113/4/5 operate from a single power
|
||||
* supply ranging from 2.0V to 5.5V.
|
||||
* The ADS1113/4/5 can perform conversions at rates up to 860 samples per second (SPS). An onboard PGA is available on
|
||||
* the ADS1114 and ADS1115 that offers input ranges from the supply to as low as ±256mV, allowing both large and small
|
||||
* signals to be measured with high resolution. The ADS1115 also features an input multiplexer (MUX) that provides two
|
||||
* differential or four single-ended inputs.
|
||||
* The ADS1113/4/5 operate either in continuous conversion mode or a single-shot mode that automatically powers down after
|
||||
* a conversion and greatly reduces current consumption during idle periods. The ADS1113/4/5 are specified from –40°C to +125°C.
|
||||
*
|
||||
* Tested with DIYMall ADS1115 board. Also available from Adafruit: https://www.adafruit.com/products/1085
|
||||
*
|
||||
* @image html ads1115.jpg
|
||||
* @snippet ads1x15.cxx Interesting
|
||||
*/
|
||||
class ADS1115 : public ADS1X15 {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @enum ADSSAMPLERATE
|
||||
* @brief uint16_t enum containing values
|
||||
* representing the sample rate of the device.
|
||||
*
|
||||
* @var ADSSAMPLERATE::SPS_8 = 0x0000
|
||||
* @var ADSSAMPLERATE::SPS_16 = 0x0020
|
||||
* @var ADSSAMPLERATE::SPS_32 = 0x0040
|
||||
* @var ADSSAMPLERATE::SPS_64 = 0x0060
|
||||
* @var ADSSAMPLERATE::SPS_128 = 0x0080
|
||||
* @var ADSSAMPLERATE::SPS_250 = 0x00A0
|
||||
* @var ADSSAMPLERATE::SPS_475 = 0x00C0
|
||||
* @var ADSSAMPLERATE::SPS_860 = 0x00E0
|
||||
*/
|
||||
typedef enum ADSDATARATE
|
||||
{
|
||||
SPS_8 = ADS1115_DR_8SPS,
|
||||
SPS_16 = ADS1115_DR_16SPS,
|
||||
SPS_32 = ADS1115_DR_32SPS,
|
||||
SPS_64 = ADS1115_DR_64SPS,
|
||||
SPS_128 = ADS1115_DR_128SPS,
|
||||
SPS_250 = ADS1115_DR_250SPS,
|
||||
SPS_475 = ADS1115_DR_475SPS,
|
||||
SPS_860 = ADS1115_DR_860SPS
|
||||
} ADSDATARATE;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ADS1X15 constructor
|
||||
*
|
||||
* @param bus i2c bus the sensor is attached to.
|
||||
* @param address. Device address. Default is 0x48.
|
||||
*/
|
||||
ADS1115 (int bus, uint8_t address = 0x48);
|
||||
|
||||
/**
|
||||
* ADS1X15 destructor
|
||||
*/
|
||||
~ADS1115();
|
||||
|
||||
/**
|
||||
* Sets the sample rate of the device. This function
|
||||
* needs to be overridden in subclasses as the ADS1115 and
|
||||
* ADS1015 have different sample rates.
|
||||
*
|
||||
* @param ADSSAMPLERATE enum
|
||||
*/
|
||||
void setSPS(ADSDATARATE rate = ADS1115::SPS_128);
|
||||
|
||||
|
||||
protected:
|
||||
float getMultiplier(void);
|
||||
void setDelay(void);
|
||||
|
||||
};
|
||||
}
|
187
src/ads1x15/ads1x15.cxx
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "ads1x15.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace upm;
|
||||
|
||||
ADS1X15::ADS1X15(int bus, uint8_t address){
|
||||
|
||||
if(!(i2c = new mraa::I2c(bus))){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +": I2c.init() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if((i2c->address(address) != mraa::SUCCESS)){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.address() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if(i2c->frequency( mraa::I2C_FAST) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.frequency(I2C_FAST) failed");
|
||||
return;
|
||||
}
|
||||
//Will be reset by sub class.
|
||||
m_bitShift = 0;
|
||||
m_conversionDelay = .001;
|
||||
m_config_reg = 0x0000;
|
||||
}
|
||||
|
||||
ADS1X15::~ADS1X15(){}
|
||||
|
||||
float
|
||||
ADS1X15::getSample(ADSMUXMODE mode){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
|
||||
usleep(m_conversionDelay);
|
||||
return getLastSample();
|
||||
}
|
||||
|
||||
float
|
||||
ADS1X15::getLastSample(int reg){
|
||||
uint16_t value = i2c->readWordReg(reg);
|
||||
bool neg = false;
|
||||
value = swapWord(value);
|
||||
if(value & 0x8000){
|
||||
neg = true;
|
||||
value = ~value;
|
||||
}
|
||||
if(m_name == "ADS1015") value = value >> m_bitShift;
|
||||
if(neg) return 0.0 - value * getMultiplier();
|
||||
else return value * getMultiplier();
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setGain(ADSGAIN gain){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_PGA_MASK) | gain);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setSPS(ADSSAMPLERATE rate){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setCompMode(bool mode){
|
||||
if(mode) updateConfigRegister((m_config_reg & ~ADS1X15_CMODE_MASK));
|
||||
else updateConfigRegister((m_config_reg & ~ADS1X15_CMODE_MASK) | ADS1X15_CMODE_WINDOW);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setCompPol(bool mode){
|
||||
if(!mode) updateConfigRegister((m_config_reg & ~ADS1X15_CPOL_MASK));
|
||||
else updateConfigRegister((m_config_reg & ~ADS1X15_CPOL_MASK) | ADS1X15_CPOL_ACTVHI);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setCompLatch(bool mode){
|
||||
if(mode) updateConfigRegister((m_config_reg & ~ADS1X15_CLAT_MASK));
|
||||
else updateConfigRegister((m_config_reg & ~ADS1X15_CLAT_MASK) | ADS1X15_CLAT_LATCH);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setCompQue(ADSCOMP mode){
|
||||
updateConfigRegister((m_config_reg & ~ADS1X15_CQUE_MASK) | mode);
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setContinuous(bool mode){
|
||||
if(mode) updateConfigRegister((m_config_reg & ~ADS1X15_MODE_MASK));
|
||||
else updateConfigRegister((m_config_reg & ~ADS1X15_MODE_MASK) | ADS1X15_MODE_SINGLE);
|
||||
}
|
||||
|
||||
float
|
||||
ADS1X15::getThresh(ADSTHRESH reg){
|
||||
if( THRESH_HIGH && THRESH_LOW) return getLastSample(reg);
|
||||
else return 0.0;
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::setThresh(ADSTHRESH reg, float value){
|
||||
uint16_t set_value;
|
||||
switch((int)reg){
|
||||
case 4: //set conversion_rdy operation
|
||||
if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0000) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0x0080) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
set_value = value / getMultiplier();
|
||||
set_value = set_value << m_bitShift;
|
||||
if(i2c->writeWordReg(reg, swapWord(set_value)) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 5: //set default
|
||||
default:
|
||||
if(i2c->writeWordReg(ADS1X15_REG_POINTER_LOWTHRESH, 0x0080) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
if(i2c->writeWordReg(ADS1X15_REG_POINTER_HITHRESH, 0xF07F) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Private functions
|
||||
void
|
||||
ADS1X15::getCurrentConfig(){
|
||||
m_config_reg = i2c->readWordReg(ADS1X15_REG_POINTER_CONFIG);
|
||||
m_config_reg = swapWord(m_config_reg);
|
||||
setDelay();
|
||||
}
|
||||
|
||||
void
|
||||
ADS1X15::updateConfigRegister(uint16_t update, bool read){
|
||||
uint16_t temp = update;
|
||||
//Mask out read bit if we are just updating the configuration.
|
||||
if(!read) temp = update & 0x7FFF;
|
||||
if(i2c->writeWordReg(ADS1X15_REG_POINTER_CONFIG, swapWord(temp)) != mraa::SUCCESS){
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
||||
return;
|
||||
}
|
||||
//If we update the configuration re-set the in memory copy.
|
||||
if(!read) getCurrentConfig();
|
||||
}
|
||||
|
||||
uint16_t
|
||||
ADS1X15::swapWord(uint16_t value){
|
||||
uint16_t res = value;
|
||||
return ((res & 0xFF) << 8) | ((res >> 8 ) & 0xFF);
|
||||
}
|
||||
|
||||
|
424
src/ads1x15/ads1x15.h
Normal file
@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Author: Marc Graham <marc@m2ag.net>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "mraa.hpp"
|
||||
#include "mraa/i2c.hpp"
|
||||
|
||||
/*=========================================================================
|
||||
I2C ADDRESS/BITS
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1X15_ADDRESS (0x48) // 1001 000 (ADDR = GND)
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*=========================================================================
|
||||
POINTER REGISTER
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1X15_REG_POINTER_MASK (0x03)
|
||||
#define ADS1X15_REG_POINTER_CONVERT (0x00)
|
||||
#define ADS1X15_REG_POINTER_CONFIG (0x01)
|
||||
#define ADS1X15_REG_POINTER_LOWTHRESH (0x02)
|
||||
#define ADS1X15_REG_POINTER_HITHRESH (0x03)
|
||||
/*=========================================================================*/
|
||||
|
||||
/*=========================================================================
|
||||
CONFIG REGISTER
|
||||
|
||||
-----------------------------------------------------------------------*/
|
||||
#define ADS1X15_OS_MASK (0x8000)
|
||||
#define ADS1X15_OS_SINGLE (0x8000) // Write: Set to start a single-conversion
|
||||
#define ADS1X15_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress
|
||||
#define ADS1X15_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion
|
||||
|
||||
#define ADS1X15_MUX_MASK (0x7000)
|
||||
#define ADS1X15_MUX_DIFF_0_1 (0x0000) // Differential P = AIN0, N = AIN1 (default)
|
||||
#define ADS1X15_MUX_DIFF_0_3 (0x1000) // Differential P = AIN0, N = AIN3
|
||||
#define ADS1X15_MUX_DIFF_1_3 (0x2000) // Differential P = AIN1, N = AIN3
|
||||
#define ADS1X15_MUX_DIFF_2_3 (0x3000) // Differential P = AIN2, N = AIN3
|
||||
#define ADS1X15_MUX_SINGLE_0 (0x4000) // Single-ended AIN0
|
||||
#define ADS1X15_MUX_SINGLE_1 (0x5000) // Single-ended AIN1
|
||||
#define ADS1X15_MUX_SINGLE_2 (0x6000) // Single-ended AIN2
|
||||
#define ADS1X15_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
|
||||
|
||||
#define ADS1X15_PGA_MASK (0x0E00)
|
||||
#define ADS1X15_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
|
||||
#define ADS1X15_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
|
||||
#define ADS1X15_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
|
||||
#define ADS1X15_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
|
||||
#define ADS1X15_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
|
||||
#define ADS1X15_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
|
||||
|
||||
#define ADS1X15_MODE_MASK (0x0100)
|
||||
#define ADS1X15_MODE_CONTIN (0x0000) // Continuous conversion mode
|
||||
#define ADS1X15_MODE_SINGLE (0x0100) // Power-down single-shot mode (default)
|
||||
|
||||
#define ADS1X15_DR_MASK (0x00E0)
|
||||
|
||||
#define ADS1X15_CMODE_MASK (0x0010)
|
||||
#define ADS1X15_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default)
|
||||
#define ADS1X15_CMODE_WINDOW (0x0010) // Window comparator
|
||||
|
||||
#define ADS1X15_CPOL_MASK (0x0008)
|
||||
#define ADS1X15_CPOL_ACTVLOW (0x0000) // ALERT/RDY pin is low when active (default)
|
||||
#define ADS1X15_CPOL_ACTVHI (0x0008) // ALERT/RDY pin is high when active
|
||||
|
||||
#define ADS1X15_CLAT_MASK (0x0400) // Determines if ALERT/RDY pin latches once asserted
|
||||
#define ADS1X15_CLAT_NONLAT (0x0000) // Non-latching comparator (default)
|
||||
#define ADS1X15_CLAT_LATCH (0x0400) // Latching comparator
|
||||
|
||||
#define ADS1X15_CQUE_MASK (0x0003)
|
||||
/* This wouldn't compile for the python wrapper. with these in for some reason.
|
||||
#define ADS1X15_CQUE_1CONV (0x0000) // Assert ALERT/RDY after one conversions
|
||||
#define ADS1X15_CQUE_2CONV (0x0001) // Assert ALERT/RDY after two conversions
|
||||
#define ADS1X15_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions
|
||||
#define ADS1X15_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default)
|
||||
*/
|
||||
/*=========================================================================*/
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief ADS1X15 family adc library
|
||||
*
|
||||
* Library for TI analog to digital converter ic. Base clase fro ADS1X15 provides all the functionality that
|
||||
* ADS1115 and ADS1015 ics have in common.
|
||||
*
|
||||
* @defgroup ads1x15 libupm-ads1x15
|
||||
* @ingroup ti adafruit i2c electric
|
||||
*/
|
||||
class ADS1X15 {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @enum ADSGAIN
|
||||
* @brief uint16_t enum containing values for
|
||||
* setting gain for ADS1X15 devices.
|
||||
*
|
||||
* @var ADSGAIN::TWOTHIRDS = 0x0000
|
||||
* @var ADSGAIN::ONE = 0x0200
|
||||
* @var ADSGAIN::TWO = 0x0400
|
||||
* @var ADSGAIN::FOUR = 0x0600
|
||||
* @var ADSGAIN::EIGHT = 0x0800
|
||||
* @var ADSGAIN::SIXTEEN = 0x0A00
|
||||
*/
|
||||
typedef enum ADSGAIN {
|
||||
GAIN_TWOTHIRDS = ADS1X15_PGA_6_144V,
|
||||
GAIN_ONE = ADS1X15_PGA_4_096V,
|
||||
GAIN_TWO = ADS1X15_PGA_2_048V,
|
||||
GAIN_FOUR = ADS1X15_PGA_1_024V,
|
||||
GAIN_EIGHT = ADS1X15_PGA_0_512V,
|
||||
GAIN_SIXTEEN = ADS1X15_PGA_0_256V
|
||||
} ADSGAIN ;
|
||||
|
||||
/**
|
||||
* @enum ADSMUXMODE
|
||||
* @brief uint16_t enum containing values used
|
||||
* for selecting ADS1X15 read operations.
|
||||
*
|
||||
* @var ADSMUXMODE::DIFF_0_1 = 0x0000
|
||||
* @var ADSMUXMODE::DIFF_0_2 = 0x1000
|
||||
* @var ADSMUXMODE::DIFF_1_3 = 0x2000
|
||||
* @var ADSMUXMODE::DIFF_2_3 = 0x3000
|
||||
* @var ADSMUXMODE::SINGLE_0 = 0x4000
|
||||
* @var ADSMUXMODE::SINGLE_1 = 0x5000
|
||||
* @var ADSMUXMODE::SINGLE_2 = 0x6000
|
||||
* @var ADSMUXMODE::SINGLE_3 = 0x7000
|
||||
*/
|
||||
typedef enum ADSMUXMODE {
|
||||
DIFF_0_1 = ADS1X15_MUX_DIFF_0_1, // Differential P = AIN0, N = AIN1 (default)
|
||||
DIFF_0_3 = ADS1X15_MUX_DIFF_0_3, // Differential P = AIN0, N = AIN3
|
||||
DIFF_1_3 = ADS1X15_MUX_DIFF_1_3, // Differential P = AIN1, N = AIN3
|
||||
DIFF_2_3 = ADS1X15_MUX_DIFF_2_3, // Differential P = AIN2, N = AIN3
|
||||
SINGLE_0 = ADS1X15_MUX_SINGLE_0, // Single-ended AIN0
|
||||
SINGLE_1 = ADS1X15_MUX_SINGLE_1, // Single-ended AIN1
|
||||
SINGLE_2 = ADS1X15_MUX_SINGLE_2, // Single-ended AIN2
|
||||
SINGLE_3 = ADS1X15_MUX_SINGLE_3 // Single-ended AIN3
|
||||
} ADSMUXMODE;
|
||||
|
||||
/**
|
||||
* @enum ADSCOMP
|
||||
* @brief uint16_t enum containing values
|
||||
* for setting ADS1X15 comparator queue modes.
|
||||
*
|
||||
* @var ADSCOMP::CQUE_1CONV = 0x0000
|
||||
* @var ADSCOMP::CQUE_2CONV = 0x0001
|
||||
* @var ADSCOMP::CQUE_3CONV = 0x0002
|
||||
* @var ADSCOMP::CQUE_NONE = 0x0003
|
||||
*/
|
||||
typedef enum ADSCOMP {
|
||||
CQUE_1CONV = 0x0000, // Assert ALERT/RDY after one conversions
|
||||
CQUE_2CONV = 0x0001, // Assert ALERT/RDY after two conversions
|
||||
CQUE_4CONV = 0x0002, // Assert ALERT/RDY after four conversions
|
||||
CQUE_NONE = 0x0003 // Disable the comparator and put ALERT/RDY in high state (default)
|
||||
} ADSCOMP;
|
||||
|
||||
/**
|
||||
* @enum ADSTHRESH
|
||||
* @brief uint8_t enum containing register addresses
|
||||
* used for setting HI and LOW threshold values as
|
||||
* well as setting conversion ready and set to default.
|
||||
*
|
||||
* @var ADSTHRESH::THRESH_LOW = 0x02
|
||||
* @var ADSTHRESH::THRESH_HIGH = 0x03
|
||||
* @var ADSTHRESH::CONVERSION_RDY = 0x04
|
||||
* @var ADSTHRESH::THRESH_DEFAULT = 0x05
|
||||
*/
|
||||
typedef enum ADSTHRESH {
|
||||
THRESH_LOW = ADS1X15_REG_POINTER_LOWTHRESH,
|
||||
THRESH_HIGH = ADS1X15_REG_POINTER_HITHRESH,
|
||||
CONVERSION_RDY = 0x04,
|
||||
THRESH_DEFAULT = 0x05
|
||||
|
||||
} ADSTHRESH;
|
||||
|
||||
/**
|
||||
* @enum ADSSAMPLERATE
|
||||
* @brief uint16_t enum containing values
|
||||
* representing the sample rate of the device.
|
||||
* Will be overridden in subclass
|
||||
*
|
||||
* @var ADSSAMPLERATE::SPS_DEFAULT = 0x0080
|
||||
*/
|
||||
typedef enum ADSSAMPLERATE {
|
||||
SPS_DEFAULT = 0x0080
|
||||
} ADSSAMPLERATE;
|
||||
|
||||
/**
|
||||
* ADS1X15 constructor
|
||||
*
|
||||
* @param bus i2c bus the sensor is attached to.
|
||||
* @param address. Device address. Default is 0x48.
|
||||
*/
|
||||
ADS1X15(int bus, uint8_t address);
|
||||
|
||||
/**
|
||||
* ADS1X15 destructor
|
||||
*/
|
||||
virtual ~ADS1X15 ();
|
||||
|
||||
/**
|
||||
* Returns the name of the sensor
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of conversion register without performing
|
||||
* a conversion operation. Will use a multiplier based on the
|
||||
* current gain setting to give the voltage as a float. Used
|
||||
* internally to return the HI and LOW threshold values.
|
||||
*
|
||||
* @param reg uint8_t value specifying register to read.
|
||||
* Should generally be called with no parameter.
|
||||
*/
|
||||
float getLastSample(int reg = ADS1X15_REG_POINTER_CONVERT);
|
||||
|
||||
/**
|
||||
* Performs a read as specified by ADS1X15::ADSMUXMOE and
|
||||
* returns the value as a float. Uses getLastSample() internally
|
||||
* to return voltage value.
|
||||
*
|
||||
* @pram mode ADSMUXMODE specifying inputs to be sampled.
|
||||
*/
|
||||
float getSample(ADSMUXMODE mode = ADS1X15::DIFF_0_1);
|
||||
|
||||
/**
|
||||
* Returns the current gain setting being used by the device
|
||||
* as an ADSGAIN value.
|
||||
*/
|
||||
ADSGAIN getGain(){
|
||||
return (ADSGAIN)(m_config_reg & ADS1X15_PGA_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PGA gain bits to the desired gain. Default
|
||||
* is +/- 2.094 volts.
|
||||
*
|
||||
* @param gain ADSGAIN value reprenting the desired gain.
|
||||
* See warnings in spec sheet.
|
||||
*/
|
||||
void setGain(ADSGAIN gain = ADS1X15::GAIN_TWO);
|
||||
|
||||
/**
|
||||
* Returns the current device sample rate a an ADSSAMPLERATE
|
||||
* value.
|
||||
*/
|
||||
ADSSAMPLERATE getSPS(void){
|
||||
return (ADSSAMPLERATE)(m_config_reg & ADS1X15_DR_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample rate of the device. This function
|
||||
* needs to be overrode in subclasses as the ADS1115 and
|
||||
* ADS1015 have different data rates.
|
||||
*
|
||||
* @param ADSSAMPLERATE enum
|
||||
* SPS_DEFAULT = 0x0080
|
||||
*/
|
||||
virtual void setSPS(ADSSAMPLERATE rate);
|
||||
|
||||
/**
|
||||
* Returns the comparator mode.
|
||||
* False = Traditional comparator with Hysteresis (default)
|
||||
* True = Window Comparator
|
||||
*/
|
||||
bool getCompMode(void){
|
||||
return (bool)(m_config_reg & ADS1X15_CMODE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparator mode of the device.
|
||||
*
|
||||
* @param mode bool value denoting mode.
|
||||
* False = Traditional comparator with Hysteresis (default)
|
||||
* True = Window Comparator
|
||||
*/
|
||||
void setCompMode(bool mode = false);
|
||||
|
||||
/**
|
||||
* Get comparator polarity. Reports the polarity
|
||||
* of the ALERT/RDY pin. Returns:
|
||||
* False = Active Low (default)
|
||||
* True = Active High
|
||||
*/
|
||||
bool getCompPol(void){
|
||||
return (bool)(m_config_reg & ADS1X15_CPOL_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comparator polarity. Controls the
|
||||
* polarity of the ALERT/RDY pin.
|
||||
*
|
||||
* @param mode bool.
|
||||
* False = Active Low (default)
|
||||
* True = Active High
|
||||
*/
|
||||
void setCompPol(bool mode = false);
|
||||
|
||||
/**
|
||||
* Returns bool representing the state of the
|
||||
* comparator latching functionality.
|
||||
* False = Non Latching comparator (default)
|
||||
* True = Latching Comparator
|
||||
*/
|
||||
bool getCompLatch(void){
|
||||
return (bool)(m_config_reg & ADS1X15_CLAT_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bit controlling comparator operation.
|
||||
*
|
||||
* @param mode bool
|
||||
* False = Non Latching comparator (default)
|
||||
* True = Latching Comparator
|
||||
*/
|
||||
void setCompLatch(bool mode = false);
|
||||
|
||||
/**
|
||||
* Returns ADSCOMP value representing the state of
|
||||
* comparator queue.
|
||||
*
|
||||
* CQUE_1CONV = Assert after one conversion
|
||||
* CQUE_2CONV = Assert after two conversions
|
||||
* CQUE_2CONV = Assert after four conversions
|
||||
* CQUE_NONE = Disable comparator (default)
|
||||
*/
|
||||
ADSCOMP getCompQue(void){
|
||||
return (ADSCOMP)(m_config_reg & ADS1X15_CQUE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bits controlling Comparator queue operation.
|
||||
*
|
||||
* @param mode ADSCOMP enum.
|
||||
* CQUE_1CONV = Assert after one conversion
|
||||
* CQUE_2CONV = Assert after two conversions
|
||||
* CQUE_2CONV = Assert after four conversions
|
||||
* CQUE_NONE = Disable comparator (default)
|
||||
*/
|
||||
void setCompQue(ADSCOMP mode = ADS1X15::CQUE_NONE);
|
||||
|
||||
/**
|
||||
* Returns bool reflecting state of device mode bit.
|
||||
*
|
||||
* False = Power Down Single shot mode (default)
|
||||
* True = Continuous conversion mode
|
||||
*/
|
||||
bool getContinuous(void){
|
||||
return !(bool)(m_config_reg & ADS1X15_MODE_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state of device mode but.
|
||||
*
|
||||
* @param mode bool
|
||||
* False = Power Down Single shot mode (default)
|
||||
* True = Continuous conversion mode
|
||||
*/
|
||||
void setContinuous(bool mode = false);
|
||||
|
||||
/**
|
||||
* Returns current high or low threshold setting.
|
||||
*
|
||||
* @param reg ADSTHRES enum value.
|
||||
* Returns 0.0 unless THRESH_HIGH or THRESH_LOW requested.
|
||||
*/
|
||||
float getThresh(ADSTHRESH reg = THRESH_LOW);
|
||||
|
||||
/**
|
||||
* Sets threshold levels or configures for conversion ready
|
||||
* operation of ALERT/RDY output.
|
||||
*
|
||||
* @param reg ADSTHRESH enum
|
||||
* @param value float value to set threshold register to.
|
||||
*
|
||||
* THRESH_LOW = Sets low thresh register.
|
||||
* THRESH_HIGH = Sets high thresh register.
|
||||
* CONVERSION_RDY = Configures conversion ready operation
|
||||
* THRESH_DEFAULT = resets high/low registers to startup values.
|
||||
*/
|
||||
void setThresh(ADSTHRESH reg = THRESH_DEFAULT , float value = 0.0);
|
||||
|
||||
protected:
|
||||
std::string m_name;
|
||||
float m_conversionDelay;
|
||||
uint8_t m_bitShift;
|
||||
uint16_t m_config_reg;
|
||||
//Must be overridden in subclass for proper values.
|
||||
virtual float getMultiplier(void) = 0;
|
||||
//Must be overridden in subclass for proper values.
|
||||
virtual void setDelay(void) = 0;
|
||||
void getCurrentConfig();
|
||||
void updateConfigRegister(uint16_t update, bool read = false);
|
||||
uint16_t swapWord(uint16_t value);
|
||||
|
||||
mraa::I2c* i2c;
|
||||
|
||||
};}
|
26
src/ads1x15/javaupm_ads1x15.i
Normal file
@ -0,0 +1,26 @@
|
||||
%module javaupm_ads1x15
|
||||
%include "../upm.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
%{
|
||||
#include "ads1x15.h"
|
||||
#include "ads1015.h"
|
||||
#include "ads1115.h"
|
||||
%}
|
||||
|
||||
%include "ads1x15.h"
|
||||
%include "ads1015.h"
|
||||
%include "ads1115.h"
|
||||
|
||||
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_ads1x15");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
17
src/ads1x15/jsupm_ads1x15.i
Normal file
@ -0,0 +1,17 @@
|
||||
%module jsupm_ads1x15
|
||||
%include "../upm.i"
|
||||
|
||||
%include "ads1x15.h"
|
||||
%{
|
||||
#include "ads1x15.h"
|
||||
%}
|
||||
|
||||
%include "ads1015.h"
|
||||
%{
|
||||
#include "ads1015.h"
|
||||
%}
|
||||
|
||||
%include "ads1115.h"
|
||||
%{
|
||||
#include "ads1115.h"
|
||||
%}
|
21
src/ads1x15/pyupm_ads1x15.i
Normal file
@ -0,0 +1,21 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_ads1x15
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ads1x15.h"
|
||||
%{
|
||||
#include "ads1x15.h"
|
||||
%}
|
||||
|
||||
%include "ads1015.h"
|
||||
%{
|
||||
#include "ads1015.h"
|
||||
%}
|
||||
|
||||
%include "ads1115.h"
|
||||
%{
|
||||
#include "ads1115.h"
|
||||
%}
|