Compare commits
29 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 |
@ -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.9.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.5.0-dirty")
|
||||
set (VERSION "v0.5.1-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - UPM Version ${VERSION}")
|
||||
|
@ -4,18 +4,28 @@ 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.
|
||||
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.
|
||||
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.
|
||||
implement Runnable objects
|
||||
* Improved Python typemaps and error checking, documentation now includes
|
||||
detailed function descriptions.
|
||||
detailed function descriptions
|
||||
* Simplified the build process by eliminating the need to define redundant
|
||||
MRAA related environment variables.
|
||||
MRAA related environment variables
|
||||
* New sensors: nlgpio16, ads1x15, t3311, hdxxvxta, hwxpxx, rhusb, ili9341,
|
||||
apds9930, kxcjk1013
|
||||
|
||||
@ -55,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
|
||||
|
@ -253,61 +253,29 @@ __SWIG:__
|
||||
|
||||
|
||||
###Implementing callbacks in Java
|
||||
Method calls from the Java instance are passed to the C++ instance transparently via C wrapper functions. In the default usage of SWIG, this arrangement is asymmetric in the sense that no corresponding mechanism exists to pass method calls down the inheritance chain from C++ to Java. To address this problem, SWIG introduces new classes called directors at the bottom of the C++ inheritance chain. The job of the directors is to route method calls correctly, either to C++ implementations higher in the inheritance chain or to Java implementations lower in the inheritance chain. The upshot is that C++ classes can be extended in Java and from C++ these extensions look exactly like native C++ classes. For more on Java directors, read the ["Cross language polymorphism using directors"](http://www.swig.org/Doc3.0/SWIGDocumentation.html#Java_directors) chapter of the SWIG documentation.
|
||||
To enable directors, add the "directors" option to the %module directive, and use the %feature("director") directive to tell SWIG which classes and methods should get directors. If only a class is specified, the %feature is applied to all virtual methods in that class. If no class or method is specified, the %feature is applied globally to all virtual methods.
|
||||
|
||||
```
|
||||
%module(directors="1") modulename
|
||||
%feature("director") IsrCallback;
|
||||
```
|
||||
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 create a new C++ class, that will be wrapped by SWIG, called _IsrCallback_; and a method _generic\_callback\_isr(void\* data)_ that takes an instance of IsrCallback as argument.
|
||||
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)
|
||||
class IsrCallback
|
||||
void A110X::installISR(jobject runnable)
|
||||
{
|
||||
public:
|
||||
virtual ~IsrCallback()
|
||||
{
|
||||
}
|
||||
virtual void run()
|
||||
{ /* empty, overridden in Java*/
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
static void generic_callback_isr (void* data)
|
||||
{
|
||||
IsrCallback* callback = (IsrCallback*) data;
|
||||
if (callback == NULL)
|
||||
return;
|
||||
callback->run();
|
||||
installISR(mraa_java_isr_callback, runnable);
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
SWIGJAVA is a symbol that is always defined by SWIG when using Java. We enclose the _IsrCallback_ class and _generic\_callback\_isr()_ in a _\#if defined(SWIGJAVA)_ check, to ensure the code only exists when creating a wrapper for Java.
|
||||
We extend the sensor class with another method, _installISR\(IsrCallback \*cb\)_, which is a wrapper over the original _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ method. This will install the _generic\_callback\_isr\(\)_ method as the interrupt service routine \(ISR\) to be called, with the _IsrCallback_ object (referenced by *cb) as argument.
|
||||
|
||||
```c++
|
||||
#if defined(SWIGJAVA)
|
||||
void A110X::installISR( IsrCallback *cb)
|
||||
{
|
||||
installISR(generic_callback_isr, cb);
|
||||
}
|
||||
#endif
|
||||
```
|
||||
|
||||
We hide the underlying method, _installISR\(void \(\*isr\)\(void \*\), void \*arg\)_ , and expose only the _installISR\(IsrCallback \*cb\)_ to SWIG, through the use of the SWIGJAVA symbol. When SWIGJAVA is defined, we change the access modifier of the underlying method to private.
|
||||
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(IsrCallback *cb);
|
||||
void installISR(jobject runnable);
|
||||
#else
|
||||
void installISR(void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
@ -317,7 +285,7 @@ private:
|
||||
#endif
|
||||
```
|
||||
|
||||
To use callback in java, we create a ISR class, which extends the new IsrCallback class created by SWIG, 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:
|
||||
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 {
|
||||
@ -326,7 +294,7 @@ public class A110X_intrSample {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
upm_a110x.A110X hall = new upm_a110x.A110X(2);
|
||||
|
||||
IsrCallback callback = new A110XISR();
|
||||
A110XISR callback = new A110XISR();
|
||||
hall.installISR(callback);
|
||||
|
||||
while(true){
|
||||
@ -336,7 +304,7 @@ public class A110X_intrSample {
|
||||
}
|
||||
}
|
||||
|
||||
class A110XISR extends IsrCallback {
|
||||
class A110XISR implements Runnable {
|
||||
public A110XISR(){
|
||||
super();
|
||||
}
|
||||
@ -383,18 +351,3 @@ by
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
```
|
||||
|
||||
__Use GlobalRef instead of WeakRef__
|
||||
|
||||
By default, SWIG uses WeakRef to the Java objects handled by a director. Once Java objects run out of scope they can get cleaned up. In many cases WeakRef is undesirable as we may still want to be able to run methods or access fields in the objects passed to the JNI layer (e.g. we want to pass a runnable-like object which should be called when something happens). To use GlobalRefs instead, the following line must be added after the director declaration:
|
||||
|
||||
```
|
||||
SWIG_DIRECTOR_OWNED(module)
|
||||
```
|
||||
|
||||
For, example, in case of a module called IsrCallback (used for interrupts in MRAA and UPM), we would declare said module as such:
|
||||
|
||||
```
|
||||
%feature ("director") IsrCallback;
|
||||
SWIG_DIRECTOR_OWNED(IsrCallback)
|
||||
```
|
||||
|
||||
|
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/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 |
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 |
@ -91,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)
|
||||
@ -203,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)
|
||||
@ -258,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)
|
||||
|
@ -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;
|
||||
|
||||
@ -44,26 +44,25 @@ int main ()
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a MY9221, we use D2 for the data, and D3 for the
|
||||
// data clock. This was tested with a Grove LED bar.
|
||||
|
||||
upm::MY9221* bar = new upm::MY9221(2, 3);
|
||||
// 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);
|
||||
|
||||
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;
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "my9221.h"
|
||||
#include <signal.h>
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::MY9221 *bar = new upm::MY9221(8, 9);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (int idx = 1; idx < 11; idx++) {
|
||||
bar->setBarLevel (idx);
|
||||
usleep(1000);
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete bar;
|
||||
|
||||
return 0;
|
||||
}
|
@ -29,6 +29,7 @@ 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)
|
||||
@ -77,8 +78,7 @@ add_example(MPU9150Sample mpu9150)
|
||||
add_example(MQ2Sample gas)
|
||||
add_example(MQ303ASample mq303a)
|
||||
add_example(MQ5Sample gas)
|
||||
add_example(MY9221_ledbarSample my9221)
|
||||
add_example(MY9221Sample my9221)
|
||||
add_example(GroveLEDBar my9221)
|
||||
add_example(NRF24L01_receiverSample nrf24l01)
|
||||
add_example(NRF24L01_transmitterSample nrf24l01)
|
||||
add_example(NUNCHUCKSample nunchuck)
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -22,12 +22,12 @@
|
||||
* 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);
|
||||
upm_my9221.GroveLEDBar bar = new upm_my9221.GroveLEDBar((short) 8, (short) 9);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 MY9221Sample {
|
||||
|
||||
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);
|
||||
|
||||
while (true) {
|
||||
for (short idx = 1; idx < 11; idx++) {
|
||||
bar.setBarLevel(idx);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
@ -100,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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -55,8 +55,8 @@
|
||||
namespace upm {
|
||||
/**
|
||||
* @library ads1x15
|
||||
* @sensor ADS1115
|
||||
* @comname ADS1115 ADC
|
||||
* @sensor ADS1015
|
||||
* @comname ADS1015 ADC
|
||||
* @type electric
|
||||
* @man ti adafruit
|
||||
* @con i2c
|
||||
|
@ -65,6 +65,7 @@ namespace upm {
|
||||
*
|
||||
* This driver was developed using the DFRobot ADXRS610 Gyro Beakout board.
|
||||
*
|
||||
* @image html adxrs610.jpg
|
||||
* @snippet adxrs610.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -63,6 +63,7 @@ namespace upm {
|
||||
*
|
||||
* This driver was developed on a DFRobot BMA (Tiny).
|
||||
*
|
||||
* @image html bma220.jpg
|
||||
* @snippet bma220.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -83,6 +83,7 @@ namespace upm {
|
||||
* this calibration, you can measure the pH value of an alkaline
|
||||
* solution.
|
||||
*
|
||||
* @image html dfrph.jpg
|
||||
* @snippet dfrph.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
set (libname "grovecircularled")
|
||||
set (libdescription "upm grove circular led")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grovecircularled.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
GroveCircularLED::GroveCircularLED (uint8_t di, uint8_t dcki)
|
||||
: m_clkPinCtx(dcki),
|
||||
m_dataPinCtx(di)
|
||||
{
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// set direction (out)
|
||||
error = m_dataPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
printError(error);
|
||||
}
|
||||
error = m_clkPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
printError(error);
|
||||
}
|
||||
|
||||
m_clkPinCtx.useMmap(true);
|
||||
m_dataPinCtx.useMmap(true);
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
GroveCircularLED::setSpinner (uint8_t position) {
|
||||
if (position < 0 || position >= 24) {
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
uint32_t state = (block_idx == position) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
GroveCircularLED::setLevel (uint8_t level, bool direction) {
|
||||
if (level < 0 || level > 24) {
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (direction) {
|
||||
for(uint8_t block_idx = 24; block_idx > 0; block_idx--) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
uint32_t state = (block_idx <= level) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
} else {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
uint32_t state = (block_idx <= level - 1) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
}
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
GroveCircularLED::setStatus (bool status[24]) {
|
||||
for(uint8_t block_idx = 0; block_idx < 24; block_idx++) {
|
||||
if (block_idx % 12 == 0) {
|
||||
send16bitBlock (CMDMODE);
|
||||
}
|
||||
send16bitBlock (status[block_idx] ? BIT_HIGH : BIT_LOW);
|
||||
}
|
||||
return lockData ();
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
GroveCircularLED::lockData () {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
error = m_dataPinCtx.write (LOW);
|
||||
usleep(10);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = m_dataPinCtx.write(HIGH);
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
GroveCircularLED::send16bitBlock (short data) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = m_dataPinCtx.write (state);
|
||||
state = m_clkPinCtx.read ();
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
}
|
||||
|
||||
error = m_clkPinCtx.write (state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
return error;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
%module javaupm_grovecircularled
|
||||
%include "../upm.i"
|
||||
%include "arrays_java.i";
|
||||
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
||||
|
||||
%include "grovecircularled.h"
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_grovecircularled");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
@ -1,8 +0,0 @@
|
||||
%module jsupm_grovecircularled
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
||||
|
||||
%include "grovecircularled.h"
|
@ -1,11 +0,0 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_grovecircularled
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "grovecircularled.h"
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
@ -46,7 +46,7 @@ namespace upm {
|
||||
* @sensor groveultrasonic
|
||||
* @comname Grove Ultrasonic Ranger
|
||||
* @type sound
|
||||
* @man grove
|
||||
* @man seeed
|
||||
* @con gpio
|
||||
*
|
||||
* @brief API for Grove Ultrasonic Ranger
|
||||
@ -57,6 +57,7 @@ namespace upm {
|
||||
* to 4 m (13'1.5") and works best when the object is within a 30 degree angle
|
||||
* relative to the sensor.
|
||||
*
|
||||
* @image html groveultrasonic.jpg
|
||||
* @snippet groveultrasonic.cxx Interesting
|
||||
*/
|
||||
class GroveUltraSonic {
|
||||
|
@ -57,16 +57,20 @@ H3LIS331DL::~H3LIS331DL()
|
||||
|
||||
bool H3LIS331DL::init(DR_BITS_T odr, PM_BITS_T pm, FS_BITS_T fs)
|
||||
{
|
||||
if (!setDataRate(odr))
|
||||
if (!setDataRate(odr)) {
|
||||
return false;
|
||||
if (!setPowerMode(pm))
|
||||
}
|
||||
if (!setPowerMode(pm)) {
|
||||
return false;
|
||||
if (!setFullScale(fs))
|
||||
}
|
||||
if (!setFullScale(fs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// now enable X, Y, and Z axes
|
||||
if (enableAxis(REG1_XEN | REG1_YEN | REG1_ZEN))
|
||||
if (!enableAxis(REG1_XEN | REG1_YEN | REG1_ZEN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ namespace upm {
|
||||
*
|
||||
* This module defines the HC-SR04 interface for libhcsr04
|
||||
*
|
||||
* @image html groveultrasonic.jpg
|
||||
* @snippet hcsr04.cxx Interesting
|
||||
*/
|
||||
class HCSR04 {
|
||||
|
@ -86,7 +86,7 @@ Itg3200::calibrate(void)
|
||||
for(int i = 0; i < reads; i++){
|
||||
|
||||
Itg3200::update();
|
||||
if (i > skip){
|
||||
if (i >= skip){
|
||||
for (int j = 0; j < 3; j++){
|
||||
temp[j] += m_rotation[j];
|
||||
}
|
||||
|
@ -45,6 +45,14 @@
|
||||
|
||||
namespace upm
|
||||
{
|
||||
const uint8_t COLOR_WHITE = 0x01;
|
||||
const uint8_t COLOR_BLACK = 0x00;
|
||||
const uint8_t COLOR_XOR = 0x02;
|
||||
const uint8_t OLED_WIDTH = 0x40; // 64 pixels
|
||||
const uint8_t VERT_COLUMNS = 0x20; // half width for hi/lo 16bit writes.
|
||||
const uint8_t OLED_HEIGHT = 0x30; // 48 pixels
|
||||
const int BUFFER_SIZE = 192;
|
||||
|
||||
/**
|
||||
* @library i2clcd
|
||||
* @sensor eboled
|
||||
@ -66,17 +74,13 @@ namespace upm
|
||||
* standard GPIO -- this driver only concerns itself with the
|
||||
* display.
|
||||
*
|
||||
* @image html eboled.jpg
|
||||
* <br><em>OLED Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
*
|
||||
* @snippet eboled.cxx Interesting
|
||||
*/
|
||||
|
||||
const uint8_t COLOR_WHITE = 0x01;
|
||||
const uint8_t COLOR_BLACK = 0x00;
|
||||
const uint8_t COLOR_XOR = 0x02;
|
||||
const uint8_t OLED_WIDTH = 0x40; // 64 pixels
|
||||
const uint8_t VERT_COLUMNS = 0x20; // half width for hi/lo 16bit writes.
|
||||
const uint8_t OLED_HEIGHT = 0x30; // 48 pixels
|
||||
const int BUFFER_SIZE = 192;
|
||||
|
||||
class EBOLED : public LCD
|
||||
{
|
||||
// SSD commands
|
||||
|
@ -32,7 +32,7 @@ namespace upm
|
||||
/**
|
||||
* @brief I2C LCD Display library
|
||||
* @defgroup i2clcd libupm-i2clcd
|
||||
* @ingroup seeed sparkfun adafruit i2c gpio display gsk
|
||||
* @ingroup dfrobot sainsmart seeed sparkfun adafruit i2c gpio display gsk
|
||||
*/
|
||||
class LCD
|
||||
{
|
||||
|
@ -62,7 +62,10 @@ namespace upm
|
||||
* an I2C expander/backpack.
|
||||
*
|
||||
* @image html lcm1602.jpeg
|
||||
* @snippet lcm1602-lcd.cxx Interesting
|
||||
* Example for LCM1602 displays that use the I2C bus
|
||||
* @snippet lcm1602-i2c.cxx Interesting
|
||||
* Code sample for GPIO based LCM1602 displays
|
||||
* @snippet lcm1602-parallel.cxx Interesting
|
||||
*/
|
||||
class Lcm1602 : public LCD
|
||||
{
|
||||
|
@ -34,16 +34,20 @@ namespace upm
|
||||
* @sensor sainsmartks
|
||||
* @comname SainSmart LCD Keypad Shield
|
||||
* @type display
|
||||
* @man sainsmart
|
||||
* @man sainsmart dfrobot sparkfun
|
||||
* @web http://www.sainsmart.com/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html
|
||||
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=51
|
||||
* @web https://www.sparkfun.com/products/13293
|
||||
* @con gpio analog
|
||||
*
|
||||
* @brief API for Sainsmart LCD Keypad Shield
|
||||
*
|
||||
* The Sainsmart LCD Keypad Shield uses 6 digital outputs and 1
|
||||
* analog input (for the keypad). The outputs are used to drive an
|
||||
* attached LCM1602 LCD controller.
|
||||
* The Sainsmart LCD Keypad Shield uses 6 digital outputs and 1 analog input
|
||||
* (for the keypad). The outputs are used to drive an attached LCM1602 LCD
|
||||
* controller. This driver should also be compatible with the similar LCD
|
||||
* keypad shields from DFRobot and Sparkfun.
|
||||
*
|
||||
* @image html keypadlcd.jpg
|
||||
* @snippet sainsmartks.cxx Interesting
|
||||
*/
|
||||
class SAINSMARTKS : public Lcm1602
|
||||
|
@ -54,6 +54,7 @@ namespace upm {
|
||||
* This driver was developed using the DFRobot LM35 Linear
|
||||
* Temperature Sensor
|
||||
*
|
||||
* @image html lm35.jpg
|
||||
* @snippet lm35.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -68,6 +68,11 @@ namespace upm {
|
||||
*
|
||||
* This driver was developed on a Sparkfun 9DOF edison block.
|
||||
*
|
||||
* @image html lsm9ds0.jpg
|
||||
* <br><em>LSM9DS0 Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
*
|
||||
* @snippet lsm9ds0.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -64,6 +64,7 @@ namespace upm {
|
||||
* on the sensor will light, and the digital pin will be driven
|
||||
* high.
|
||||
*
|
||||
* @image html mg811.jpg
|
||||
* @snippet mg811.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace upm {
|
||||
* @comname AK8975 3-axis Magnetometer
|
||||
* @altname AK9875
|
||||
* @type compass
|
||||
* @man grove
|
||||
* @man seeed
|
||||
* @con i2c
|
||||
*
|
||||
* @brief API for the AK8975 magnetometer
|
||||
|
@ -55,6 +55,7 @@ namespace upm {
|
||||
* should allow an end user to implement whatever features are
|
||||
* required.
|
||||
*
|
||||
* @image html mpu60x0.jpg
|
||||
* @snippet mpu60x0.cxx Interesting
|
||||
*/
|
||||
class MPU60X0 {
|
||||
|
@ -46,6 +46,7 @@ namespace upm {
|
||||
*
|
||||
* This module defines the MPU9250 interface for libmpu9150
|
||||
*
|
||||
* @image html mpu9250.jpg
|
||||
* @snippet mpu9250.cxx Interesting
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
set (libname "my9221")
|
||||
set (libdescription "upm ledbar")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
set (libdescription "upm my9221")
|
||||
set (module_src ${libname}.cxx groveledbar.cxx grovecircularled.cxx)
|
||||
set (module_h ${libname}.h groveledbar.h grovecircularled.h)
|
||||
upm_module_init()
|
||||
|
94
src/my9221/grovecircularled.cxx
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar driver)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled driver)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grovecircularled.h"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
GroveCircularLED::GroveCircularLED (uint8_t dataPin, uint8_t clockPin)
|
||||
: MY9221(dataPin, clockPin, 2)
|
||||
{
|
||||
// auto refresh by default
|
||||
setAutoRefresh(true);
|
||||
clearAll();
|
||||
}
|
||||
|
||||
GroveCircularLED::~GroveCircularLED()
|
||||
{
|
||||
}
|
||||
|
||||
void GroveCircularLED::setSpinner(uint8_t position)
|
||||
{
|
||||
if (position > 23)
|
||||
position = 23;
|
||||
|
||||
for (uint8_t i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
|
||||
m_bitStates[i] = (i == position) ? m_highIntensity : m_lowIntensity;
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void GroveCircularLED::setLevel(uint8_t level, bool direction)
|
||||
{
|
||||
if (level > 23)
|
||||
level = 23;
|
||||
|
||||
if (!direction)
|
||||
{
|
||||
for (int i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
|
||||
m_bitStates[i] = (i < level) ? m_highIntensity : m_lowIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i<(LEDS_PER_INSTANCE * m_instances); i++)
|
||||
m_bitStates[i] = (((LEDS_PER_INSTANCE * m_instances) - i) <= level)
|
||||
? m_highIntensity : m_lowIntensity;
|
||||
}
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
|
||||
return;
|
||||
}
|
@ -1,10 +1,18 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* This module is based on the my9221 driver
|
||||
*
|
||||
* 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
|
||||
@ -27,29 +35,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#include <mraa/gpio.hpp>
|
||||
|
||||
#define MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
#define BIT_HIGH 0x00ff
|
||||
#define BIT_LOW 0x0000
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
#include "my9221.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief Grove Circular LED library
|
||||
* @defgroup grovecircularled libupm-grovecircularled
|
||||
* @ingroup seeed display gpio
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library grovecircularled
|
||||
* @library my9221
|
||||
* @sensor grovecircularled
|
||||
* @comname Grove Circular LED
|
||||
* @type display
|
||||
@ -65,52 +58,39 @@ namespace upm {
|
||||
* @image html grovecircularled.jpg
|
||||
* @snippet grovecircularled.cxx Interesting
|
||||
*/
|
||||
class GroveCircularLED {
|
||||
|
||||
class GroveCircularLED : public MY9221 {
|
||||
public:
|
||||
/**
|
||||
* Instantiates an MY9221 object
|
||||
* Instantiates an GroveCircularLED object
|
||||
*
|
||||
* @param di Data pin
|
||||
* @param dcki Clock pin
|
||||
* @param dataPin Data pin
|
||||
* @param clockPin Clock pin
|
||||
*/
|
||||
GroveCircularLED (uint8_t di, uint8_t dcki);
|
||||
GroveCircularLED(uint8_t dataPin, uint8_t clockPin);
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param level Selected level for the circular LED (0-24)
|
||||
* @param direction Up or down; up is true and default
|
||||
* GroveCircularLED destructor
|
||||
*/
|
||||
mraa::Result setLevel (uint8_t level, bool direction=true);
|
||||
~GroveCircularLED();
|
||||
|
||||
/**
|
||||
* Sets the spinner (lights up all the other LEDs but one)
|
||||
* Sets the spinner (turns off all LEDs but selected one)
|
||||
*
|
||||
* @param position Selected position for the spinner (0-23)
|
||||
*/
|
||||
mraa::Result setSpinner (uint8_t position);
|
||||
void setSpinner(uint8_t position);
|
||||
|
||||
/**
|
||||
* Sets the lighting status
|
||||
*
|
||||
* @param status Boolean array (24 elements)
|
||||
* @param level Selected level for the circular LED (0-23)
|
||||
* @param direction Up or down; up is true and default
|
||||
*/
|
||||
mraa::Result setStatus (bool status[24]);
|
||||
void setLevel(uint8_t level, bool direction=true);
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
protected:
|
||||
private:
|
||||
mraa::Result lockData ();
|
||||
mraa::Result send16bitBlock (short data);
|
||||
|
||||
std::string m_name;
|
||||
mraa::Gpio m_clkPinCtx;
|
||||
mraa::Gpio m_dataPinCtx;
|
||||
};
|
||||
|
||||
}
|
88
src/my9221/groveledbar.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar driver)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled driver)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "groveledbar.h"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
GroveLEDBar::GroveLEDBar (uint8_t dataPin, uint8_t clockPin, int instances)
|
||||
: MY9221(dataPin, clockPin, instances)
|
||||
{
|
||||
// auto refresh by default
|
||||
setAutoRefresh(true);
|
||||
clearAll();
|
||||
}
|
||||
|
||||
GroveLEDBar::~GroveLEDBar()
|
||||
{
|
||||
}
|
||||
|
||||
void GroveLEDBar::setBarLevel(uint8_t level, bool greenToRed, int barNumber)
|
||||
{
|
||||
if (level > 10)
|
||||
level = 10;
|
||||
|
||||
if (barNumber >= m_instances)
|
||||
barNumber = m_instances - 1;
|
||||
|
||||
int start = barNumber * LEDS_PER_INSTANCE;
|
||||
int end = start + LEDS_PER_INSTANCE;
|
||||
|
||||
if (!greenToRed)
|
||||
{
|
||||
for (int i=start; i<end; i++)
|
||||
m_bitStates[i] = (i < (level + start)) ?
|
||||
m_highIntensity : m_lowIntensity;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=start; i<end; i++)
|
||||
m_bitStates[i] = ( ((start + LEDS_PER_INSTANCE) - i) <=
|
||||
(level + 2 + start)) ?
|
||||
m_highIntensity : m_lowIntensity;
|
||||
}
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
|
||||
return;
|
||||
}
|
99
src/my9221/groveledbar.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/common.hpp>
|
||||
#include <mraa/gpio.hpp>
|
||||
|
||||
#include "my9221.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @library my9221
|
||||
* @sensor groveledbar
|
||||
* @comname Grove LED Bar
|
||||
* @altname MY9221 LED Bar
|
||||
* @type display
|
||||
* @man seeed
|
||||
* @web http://www.seeedstudio.com/wiki/Grove_-_LED_Bar
|
||||
* @con gpio
|
||||
* @kit eak
|
||||
*
|
||||
* @brief API for Grove LED Bars base on the MY9221
|
||||
*
|
||||
* This is a 10-segment LED bar, with 8 green segments, 1 yellow
|
||||
* segment, and one red segment. They can be daisy chained together
|
||||
* so that this module can control multiple LED bars.
|
||||
*
|
||||
* @image html my9221.jpg
|
||||
* @snippet groveledbar.cxx Interesting
|
||||
*/
|
||||
|
||||
class GroveLEDBar : public MY9221 {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Instantiates an GroveLEDBar object
|
||||
*
|
||||
* @param dataPin Data pin
|
||||
* @param clockPin Clock pin
|
||||
* @param instances Number of daisy-chained Grove LED Bars, default 1
|
||||
*/
|
||||
GroveLEDBar(uint8_t dataPin, uint8_t clockPin, int instances=1);
|
||||
|
||||
/**
|
||||
* GroveLEDBar destructor
|
||||
*/
|
||||
~GroveLEDBar();
|
||||
|
||||
/**
|
||||
* Sets the bar level
|
||||
*
|
||||
* @param level Selected level for the bar (0 - 10). 0 is off
|
||||
* @param greenToRed true if you start the level on the first
|
||||
* green LED, false otherwise
|
||||
* @param barNumber If you have multiple LED bars chained
|
||||
* together, this argument selects a specific bar starting at 0.
|
||||
* The default is 0.
|
||||
*/
|
||||
void setBarLevel(uint8_t level, bool greenToRed=true, int barNumber=0);
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
@ -1,11 +1,20 @@
|
||||
%module javaupm_my9221
|
||||
%include "../upm.i"
|
||||
|
||||
%include "my9221.h"
|
||||
%{
|
||||
#include "my9221.h"
|
||||
%}
|
||||
|
||||
%include "my9221.h"
|
||||
%include "groveledbar.h"
|
||||
%{
|
||||
#include "groveledbar.h"
|
||||
%}
|
||||
|
||||
%include "grovecircularled.h"
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
|
@ -1,8 +1,18 @@
|
||||
%module jsupm_my9221
|
||||
%include "../upm.i"
|
||||
|
||||
%include "my9221.h"
|
||||
%{
|
||||
#include "my9221.h"
|
||||
%}
|
||||
|
||||
%include "my9221.h"
|
||||
%include "groveledbar.h"
|
||||
%{
|
||||
#include "groveledbar.h"
|
||||
%}
|
||||
|
||||
%include "grovecircularled.h"
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
||||
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar driver)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled driver)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@ -31,76 +42,150 @@
|
||||
#include "my9221.h"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
MY9221::MY9221 (uint8_t di, uint8_t dcki)
|
||||
: m_clkPinCtx(dcki), m_dataPinCtx(di) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
|
||||
// set direction (out)
|
||||
error = m_clkPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError(error);
|
||||
MY9221::MY9221 (uint8_t dataPin, uint8_t clockPin, int instances)
|
||||
: m_gpioData(dataPin), m_gpioClk(clockPin), m_bitStates(0)
|
||||
{
|
||||
if (instances < 1)
|
||||
{
|
||||
throw std::out_of_range(std::string(__FUNCTION__) +
|
||||
": instances must be at least 1");
|
||||
}
|
||||
|
||||
// set direction (out)
|
||||
error = m_dataPinCtx.dir(mraa::DIR_OUT);
|
||||
if (error != mraa::SUCCESS) {
|
||||
mraa::printError(error);
|
||||
}
|
||||
// set directions
|
||||
m_gpioClk.dir(mraa::DIR_OUT);
|
||||
m_gpioData.dir(mraa::DIR_OUT);
|
||||
|
||||
// we warn if these fail, since it may not be possible to handle
|
||||
// more than one instance
|
||||
|
||||
if (m_gpioClk.useMmap(true) != mraa::SUCCESS)
|
||||
cerr << __FUNCTION__
|
||||
<< ": Warning: mmap of Clk pin failed, correct operation "
|
||||
<< "may be affected."
|
||||
<< endl;
|
||||
|
||||
if (m_gpioData.useMmap(true) != mraa::SUCCESS)
|
||||
cerr << __FUNCTION__
|
||||
<< ": Warning: mmap of Data pin failed, correct operation "
|
||||
<< "may be affected."
|
||||
<< endl;
|
||||
|
||||
setLowIntensityValue(0x00); // full off
|
||||
setHighIntensityValue(0xff); // full brightness
|
||||
|
||||
m_commandWord = 0x0000; // all defaults
|
||||
m_instances = instances;
|
||||
|
||||
m_bitStates = new uint16_t[instances * LEDS_PER_INSTANCE];
|
||||
|
||||
setAutoRefresh(true);
|
||||
clearAll();
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
MY9221::setBarLevel (uint8_t level, bool direction) {
|
||||
if (level > 10) {
|
||||
return mraa::ERROR_INVALID_PARAMETER;
|
||||
MY9221::~MY9221()
|
||||
{
|
||||
clearAll();
|
||||
|
||||
if (!m_autoRefresh)
|
||||
refresh();
|
||||
|
||||
delete m_bitStates;
|
||||
}
|
||||
|
||||
send16bitBlock (CMDMODE);
|
||||
if (direction) {
|
||||
level += 3;
|
||||
for(uint8_t block_idx = 12; block_idx > 0; block_idx--) {
|
||||
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
} else {
|
||||
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
|
||||
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
|
||||
send16bitBlock (state);
|
||||
}
|
||||
}
|
||||
return lockData ();
|
||||
void MY9221::setLED(int led, bool on)
|
||||
{
|
||||
int maxLed = (LEDS_PER_INSTANCE * m_instances) - 1;
|
||||
|
||||
if (led > maxLed)
|
||||
led = maxLed;
|
||||
if (led < 0)
|
||||
led = 0;
|
||||
|
||||
m_bitStates[led] = (on) ? m_highIntensity : m_lowIntensity;
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
MY9221::lockData () {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
usleep(100);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++) {
|
||||
error = m_dataPinCtx.write(HIGH);
|
||||
error = m_dataPinCtx.write(LOW);
|
||||
}
|
||||
return error;
|
||||
void MY9221::setLowIntensityValue(int intensity)
|
||||
{
|
||||
m_lowIntensity = (intensity & 0xff);
|
||||
}
|
||||
|
||||
mraa::Result
|
||||
MY9221::send16bitBlock (short data) {
|
||||
mraa::Result error = mraa::SUCCESS;
|
||||
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
|
||||
uint32_t state = (data & 0x8000) ? HIGH : LOW;
|
||||
error = m_dataPinCtx.write(state);
|
||||
state = m_clkPinCtx.read();
|
||||
|
||||
if (state) {
|
||||
state = LOW;
|
||||
} else {
|
||||
state = HIGH;
|
||||
void MY9221::setHighIntensityValue(int intensity)
|
||||
{
|
||||
m_highIntensity = (intensity & 0xff);
|
||||
}
|
||||
|
||||
error = m_clkPinCtx.write(state);
|
||||
void MY9221::setAll()
|
||||
{
|
||||
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
|
||||
m_bitStates[i] = m_highIntensity;
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
}
|
||||
|
||||
void MY9221::clearAll()
|
||||
{
|
||||
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
|
||||
m_bitStates[i] = m_lowIntensity;
|
||||
|
||||
if (m_autoRefresh)
|
||||
refresh();
|
||||
}
|
||||
|
||||
void MY9221::refresh()
|
||||
{
|
||||
for (int i=0; i<(m_instances * LEDS_PER_INSTANCE); i++)
|
||||
{
|
||||
if (i % 12 == 0)
|
||||
{
|
||||
send16bitBlock(m_commandWord);
|
||||
}
|
||||
send16bitBlock(m_bitStates[i]);
|
||||
}
|
||||
|
||||
lockData();
|
||||
}
|
||||
|
||||
void MY9221::lockData()
|
||||
{
|
||||
m_gpioData.write(0);
|
||||
usleep(220);
|
||||
|
||||
for(int idx = 0; idx < 4; idx++)
|
||||
{
|
||||
m_gpioData.write(1);
|
||||
m_gpioData.write(0);
|
||||
}
|
||||
|
||||
// in reality, we only need > 200ns + (m_instances * 10ns), so the
|
||||
// following should be good for up to m_instances < 80), if the
|
||||
// datasheet is to be believed :)
|
||||
usleep(1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void MY9221::send16bitBlock(uint16_t data)
|
||||
{
|
||||
for (uint8_t bit_idx = 0; bit_idx < 16; bit_idx++)
|
||||
{
|
||||
uint32_t state = (data & 0x8000) ? 1 : 0;
|
||||
m_gpioData.write(state);
|
||||
state = m_gpioClk.read();
|
||||
|
||||
if (state)
|
||||
state = 0;
|
||||
else
|
||||
state = 1;
|
||||
|
||||
m_gpioClk.write(state);
|
||||
|
||||
data <<= 1;
|
||||
}
|
||||
return error;
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* These modules were rewritten, based on original work by:
|
||||
*
|
||||
* (original my9221/groveledbar)
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* (grovecircularled)
|
||||
* Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Contributions: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
@ -24,77 +35,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.hpp>
|
||||
#include <mraa/common.hpp>
|
||||
|
||||
#include <mraa/gpio.hpp>
|
||||
|
||||
#define MAX_BIT_PER_BLOCK 16
|
||||
#define CMDMODE 0x0000
|
||||
#define BIT_HIGH 0x00ff
|
||||
#define BIT_LOW 0x0000
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief MY9221 LED Bar library
|
||||
* @brief MY9221 LED Controller library
|
||||
* @defgroup my9221 libupm-my9221
|
||||
* @ingroup seeed display gpio eak
|
||||
*/
|
||||
/**
|
||||
* @library my9221
|
||||
* @sensor my9221
|
||||
* @comname Grove LED Bar
|
||||
* @altname MY9221 LED Bar
|
||||
* @type display
|
||||
* @man seeed
|
||||
* @web http://www.seeedstudio.com/wiki/Grove_-_LED_Bar
|
||||
* @con gpio
|
||||
* @kit eak
|
||||
*
|
||||
* @brief API for MY9221-based LED Bars
|
||||
*
|
||||
* This module defines the MY9221 interface for libmy9221
|
||||
*
|
||||
* @image html my9221.jpg
|
||||
* @snippet my9221-ledbar.cxx Interesting
|
||||
* @snippet my9221-updown.cxx Interesting
|
||||
*/
|
||||
class MY9221 {
|
||||
public:
|
||||
|
||||
// 12 LED channels per chip (instance)
|
||||
static const int LEDS_PER_INSTANCE = 12;
|
||||
|
||||
/**
|
||||
* Instantiates an MY9221 object
|
||||
*
|
||||
* @param di Data pin
|
||||
* @param dcki Clock pin
|
||||
* @param dataPin Data pin
|
||||
* @param clockPin Clock pin
|
||||
* @param instances Number of daisy-chained my9221s, default 1
|
||||
*/
|
||||
MY9221 (uint8_t di, uint8_t dcki);
|
||||
MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1);
|
||||
|
||||
/**
|
||||
* Sets the bar level
|
||||
* MY9221 destructor
|
||||
*/
|
||||
~MY9221();
|
||||
|
||||
/**
|
||||
* Enable or disable auto refresh. When auto refresh is enabled,
|
||||
* update the LED display as soon as the internal state changes.
|
||||
* When false, the display(s) will not be updated until the
|
||||
* refresh() method is called.
|
||||
*
|
||||
* @param level Selected level for the bar (1 - 10)
|
||||
* @param direction Up or down; up is true and default
|
||||
* @param enable true to enable auto refresh, false otherwise
|
||||
*/
|
||||
mraa::Result setBarLevel (uint8_t level, bool direction=true);
|
||||
void setAutoRefresh(bool enable)
|
||||
{
|
||||
m_autoRefresh = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the component
|
||||
* Set an LED to a specific on (high intensity) or off (low
|
||||
* intensity) value.
|
||||
*
|
||||
* @param led The LED whose state you wish to change
|
||||
* @param on true to turn on the LED, false to turn the LED off
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
mraa::Result lockData ();
|
||||
mraa::Result send16bitBlock (short data);
|
||||
void setLED(int led, bool on);
|
||||
|
||||
std::string m_name;
|
||||
mraa::Gpio m_clkPinCtx;
|
||||
mraa::Gpio m_dataPinCtx;
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the OFF state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setLowIntensityValue(int intensity);
|
||||
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the ON state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setHighIntensityValue(int intensity);
|
||||
|
||||
/**
|
||||
* Set all of the LEDS to the ON (high intensity value) state.
|
||||
*/
|
||||
void setAll();
|
||||
|
||||
/**
|
||||
* Set all of the LEDS to the OFF (low intensity value) state.
|
||||
*/
|
||||
void clearAll();
|
||||
|
||||
/**
|
||||
* Set the LED states to match the internal stored states. This
|
||||
* is useful when auto refresh (setAutoRefresh()) is false to
|
||||
* update the display.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
protected:
|
||||
virtual void lockData();
|
||||
virtual void send16bitBlock(uint16_t data);
|
||||
|
||||
bool m_autoRefresh;
|
||||
// we're only doing 8-bit greyscale, so the high order bits are
|
||||
// always 0
|
||||
uint16_t m_lowIntensity;
|
||||
uint16_t m_highIntensity;
|
||||
|
||||
unsigned int m_instances;
|
||||
|
||||
// an array of uint16_t's representing our bit states (on/off)
|
||||
// intensities. Only the low 8 bits are used, but in the future
|
||||
// 16bit support can work here as well.
|
||||
uint16_t *m_bitStates;
|
||||
|
||||
uint16_t m_commandWord;
|
||||
|
||||
mraa::Gpio m_gpioClk;
|
||||
mraa::Gpio m_gpioData;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,3 +9,13 @@
|
||||
%{
|
||||
#include "my9221.h"
|
||||
%}
|
||||
|
||||
%include "groveledbar.h"
|
||||
%{
|
||||
#include "groveledbar.h"
|
||||
%}
|
||||
|
||||
%include "grovecircularled.h"
|
||||
%{
|
||||
#include "grovecircularled.h"
|
||||
%}
|
||||
|
@ -66,6 +66,7 @@ namespace upm {
|
||||
*
|
||||
* @brief API for the PN532 based NFC/RFID reader/writer
|
||||
*
|
||||
* @image html pn532.jpg
|
||||
* Identify a card and print out basic info
|
||||
* @snippet pn532.cxx Interesting
|
||||
* Add a URI to an already NDEF formatted ultralight or NTAG2XX tag
|
||||
|
@ -74,6 +74,7 @@ namespace upm {
|
||||
*
|
||||
* (https://www.dfrobot.com/wiki/index.php?title=URM37_V4.0_Ultrasonic_Sensor_%28SKU:SEN0001%29)
|
||||
*
|
||||
* @image html urm37.jpg
|
||||
* An example using analog mode
|
||||
* @snippet urm37.cxx Interesting
|
||||
* An example using UART mode
|
||||
|
@ -59,6 +59,7 @@ namespace upm {
|
||||
* correlate the number of counts to a time period for calculating
|
||||
* an RPM or other value as needed.
|
||||
*
|
||||
* @image html wheelencoder.jpg
|
||||
* @snippet wheelencoder.cxx Interesting
|
||||
*/
|
||||
class WheelEncoder {
|
||||
|
@ -70,6 +70,11 @@ namespace upm {
|
||||
* windows software, however it is possible of course to configure
|
||||
* them manually using AT commands. See the examples.
|
||||
*
|
||||
* @image html xbee.jpg
|
||||
* <br><em>XBee Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
*
|
||||
* @snippet xbee.cxx Interesting
|
||||
*/
|
||||
|
||||
|