Compare commits

..

39 Commits

Author SHA1 Message Date
67b77b78aa upm: version 1.7.0
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-06 08:00:22 -07:00
bc01f710ea docs: remove images and references to obsolete IDEs
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-06 07:55:48 -07:00
1af38e060e images: update Sparkfun license for images to CC BY 2.0
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-06 07:46:33 -07:00
62f84dcc47 mmap-gpio: remove deprecated mmapped gpio function calls
The memory mapped GPIO function calls have been deprecated and in turn removed from the UPM libraries. MRAA now provides the best/fastest GPIO access possible based on the selected platform/pin automatically.

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-04 07:53:16 -07:00
6ae7e9125b examples: gcc8 fixes for -Werror=format-truncation
Fixes below issues:
tm1637.cxx:69:29: error: "%2d%02d" directive output may be truncated writing between 5 and 15 bytes into a destination of size 5 [-Werror=format-truncation=]
          snprintf(myTime, 5, "%2d%02d", (hour + timezone + 24) % 24, min);

jhd1313m1.c:65:49: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 8 [-Werror=format-truncation=]
          snprintf(str, sizeof(str), "Hello World %d", ndx);

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-04 07:27:53 -07:00
07a9af07fe upm-c: remove uint8_t limit from pin/bus variables in structs
This removes unnecessary uint8 types from C driver structs that prevented some sensors from being initialized when connected to a MRAA subplatform.

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-09-04 06:32:12 -07:00
89e2ec870a bh17xx: minor documentation and formatting updates, added rohm to vendor groups
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-10 10:24:50 -07:00
4935a16530 BH1749: Add library blocks to headers, JSON format, and change SWIG JAVA vector type
- Add library blocks to header files
- Removed unneccessay new lines in JSON file
- Change SWIG Java floatVector to uint16Vector

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-09 12:03:40 -07:00
9ef90ccb81 bh1749: Add examples for all languages
* Examples for C/C++/Python/Java/JavaScript
* Add Java example to CMakeLists

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-09 12:03:35 -07:00
5f2557b159 bh1749: C/C++ driver implementation for BH1749 color sensor
* Main C implementation
* C++ wrapper on C implementation

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-09 12:03:29 -07:00
09208e90d0 BH1792: Add examples for all languages
- Examples for C/C++/Python/Java/JavaScript
- Add build line for java BH1792_Example

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-09 12:03:24 -07:00
e0105cb601 BH1792: C/C++ driver for ROHM heart rate sensor
- Base C implementation, with all features and measurement modes (interrupts uses ISR)
- C++ wrapper around C implementation

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-08-09 12:03:19 -07:00
c2ce3e8222 gtest: Bump up to 3ms min-delay for CI
Much less stringent unit test for min timing delay.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-07-31 15:46:21 -07:00
db3c73cbd1 utilities: Update time/r methods for LINUX
Default to MONOTONIC clock for timer methods to avoid falling victim to
clock corrections.  Changed signatures from accepting pointers since
this is not needed an complicates calls and Java/JS/Python bindings.

    * Switched from nanosleep to clock_nanosleep to allow developers to
      provide a clock for LINUX
    * Default upm_clock_init to CLOCK_MONOTONIC
    * Updated logic to calculating delay and elapsed to be more readable
    * Added ns flavors for completeness
    * Refactored all upm_* delay/timer methods
    * Added #else for preprocessor cases w/o an #else
    * Added test for AQI
    * Added test fixture with logic to identify a minimum delay time
      which is used as a metric for testing all delay methods
    * Much more lenient unit testing of delays to minimize false CI
      failures

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-07-31 14:20:30 -07:00
be46240b8c gtest: Qualify nmea_gps test with nmea_gps target
Change the unit test CMakeLists to only build the nmea_gps unit test if
the nmea_gps target exists.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-07-30 10:05:07 -07:00
ef81a20140 gtest: Added headers to unit tests
Added missing headers for the C++ unit tests.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-07-18 13:51:01 -07:00
8a617aa904 upm: musl and gcc8 fixes
gcc8 detects that strncpy is overwiritng the null terminating character
the source strings are already initialized to 0 so memcpy would do the same
job

Fixes
rn2903.c:153:5: error: 'strncpy' output may be truncated copying 16 bytes from a string of length 511 [-Werror=stringop-truncation]
     strncpy(dev->hardware_eui, dev->resp_data, RN2903_MAX_HEX_EUI64);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

include sys/types.h for uint definition

uint is defined in sys/types.h, therefore this
header needs to be included, it gets exposed with
musl where this header is not getting included indirectly
as it is happening when building on glibc

Fixes build errors on musl e.g.
upm/src/kx122/kx122.hpp:456:31: error: 'uint' has not been declared
|        void setBufferThreshold(uint samples);
|                                ^~~~

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2018-07-13 13:36:39 -07:00
a16d279b6f bma220: Added std_vector to SWIG interface file
Updated the bma220 SWIG interface file to use std_vector.i for JS and
Python.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-07-02 15:14:47 -07:00
3e84b74bdf kxtj3: A few last-minute changes to the kxtj3 src
* Removed trailing whitespace
    * Fixed a few spelling errors
    * Switched to upm_delay_us for C source

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-21 10:33:38 -07:00
186bbfab76 kxtj3: Add java/python/javascript examples
* Java/Python/Javascript examples
* change usleep to upm_delay_us in C++ example
* Add Java example to CMakeLists

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-21 10:04:36 -07:00
01cc3a0734 kxtj3: fixed requested issues
* Virtual destructor
* Add header guards
* Constructor default values
* Remove methods with pointer parameters in C++ code

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-21 10:04:24 -07:00
09e536b4ff kxtj3: C/C++ driver implementation with examples
Kionix tri-axis accelerometer sensor driver
* C implementation
* C++ wrapper
* C/C++ examples

Signed-off-by: Assam Boudjelthia <assam.boudjelthia@fi.rohmeurope.com>
Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-21 09:59:37 -07:00
dc45cd7859 kx122: Adding missing header guards
Added pragma once to both headers.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-14 14:17:47 -07:00
3790c0bbc1 rsc.py: Added snippet to test rsc_regs.h types
Since UPM Travis-CI runs ctests (one of which loads python examples),
the added lines would fail if the RSC_DATA_RATE and RSC_MODE have not
been included in the python rsc module.)

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-08 14:14:47 -07:00
7a2332fa7d nrf8001: Updated to the mixed module init method
A few small changes to the nrf8001 which exposes a bit more via SWIG.
Also removed a method which had no implementation.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-08 14:14:47 -07:00
330c94f1e2 CMake: Expose *_regs.h to SWIG wrappers
Some of the UPM libraries have a common C header with types used in both
the C and C++ source.  This commit adds these common header files to the
SWIG modules.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-08 14:14:47 -07:00
9a959b578c nmea_gps: Added str method for coordinate struct
Provide a method to print out a coordinate structure which can be
dropped into online mapping pages.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-01 10:20:00 -07:00
cdfb68c381 nmea_gps: Handle different GGA structure
Testing against ublox - handle null age of differential GPS.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-06-01 09:59:55 -07:00
6228498147 nmea_gps: Added parsing TXT and bw calculations
Added code to parse GPTXT nmea sentences.  Added methods to calculate
sentences/second and raw bytes/second.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-05-25 15:51:13 -07:00
8b4e1020f4 nmea_gps: Fix iterator
Small fixes for new nmea_gps code.  Fixed an iterator which could get
dereferenced incorrectly, and changed an auto to an explicit type.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-05-23 20:52:57 -07:00
3a077df5f6 nmea_gps: Update to handle parsing into structures
NMEA GPS class now uses threads to handle parsing NMEA sentences.
Currently only handles GGA, GSV, and GLL types.  Added queues for
holding parsed data.

    * Parsing thread
    * Parse GPS Fix from GGA and GLL
    * Parse satellite info from GSV
    * Provide a queue for GPS fix data as well as raw sentences
      (for debugging)
    * Target structures and NMEAGPS class have a __str__() method
      which summarizes the objects into a std::string.  These are
      tied to the __str__ method in python
    * Added google unit test for the above functionality

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-05-23 08:30:22 -07:00
1b5087105b docker-compose.yaml: Default to empty build type
Allow targets to specify a CMake build type but do not set a default
(removed 'Release').  The CXX flags for Release slow the builds down
significantly on Travis-CI (which can hit the time limit for jobs).

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-05-14 14:30:49 -07:00
ec9143e976 debug/release: Add minimal debug/release CI builds
This commit enables both a minimal DEBUG and minimal RELEASE build on
Travis-CI.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-05-14 10:08:22 -07:00
37642f3b01 bmx055: fix typo in cmakelists causing bmc150 header not to install
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
2018-05-03 11:37:59 -07:00
17110d41d0 mhz16: Remove post-throw returns + small fixes
Removed the 'return false;' lines after throws since these are not
needed and are generally flagged by static analysis tools.  Also removed
a EOL spaces and added initializers for member variables at declaration
(since more than one constructor exists).

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-04-27 11:34:49 -07:00
dd73c4aa45 mhz16: Adding raw path constructor for UART
This commit adds an additional constructor to the MHZ16 which takes a
path (string reference) to a UART device on the filesystem.

    Example: MHZ16("/dev/ttyS0");

    * Added constructor for device path w/default
    * Removed unused global consts from header

Signed-off-by: g-vidal <gerard.vidal@ens-lyon.fr>
Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-04-27 11:17:47 -07:00
8f63914d76 docs: Clarification for lib-level 'make-install'
While a 'make install' under a target library directory (build/src/lcd)
will build all dependencies required to make the target, it will NOT
install those dependencies.  This can cause confusion for developers.
Adding a note to the build docs to clarify this case.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-04-17 15:37:12 -07:00
306872619a examples: Remove double-backslash from install path
This commit removes the double-backslash when installing the examples.

Before:
   .../upm//examples/...

Before:
   .../upm/examples/...

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-04-16 10:42:23 -07:00
ad15b27cb1 kx122: Fix for uninitialized variable w/release
Fix so a release build doesn't flag reg_val as uninitialized.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-04-06 16:03:08 -07:00
297 changed files with 11070 additions and 5272 deletions

View File

@ -16,11 +16,17 @@ jobs:
include:
- &run-with-clang-minimal
stage: Clang 3.8 - minimal with unit tests
env: TARGET=minimal
env:
- TARGET=minimal
- CMAKE_BUILD_TYPE=Debug
before_script: docker-compose pull ${TARGET}
script:
- export CC=clang-3.8 CXX=clang++-3.8
- BUILDARCH=MOCK docker-compose run ${TARGET}
- docker-compose run ${TARGET}
- <<: *run-with-clang-minimal
env:
- TARGET=minimal
- CMAKE_BUILD_TYPE=Release
- &run-with-clang
stage: Clang 3.8
env: TARGET=python

View File

@ -229,7 +229,7 @@ include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
# If git_describe fails, use a dirty version
if (${VERSION} MATCHES -NOTFOUND)
set (VERSION "v1.6.0")
set (VERSION "v1.7.0")
message (WARNING "Failed to retrieve UPM version with 'git describe' (using "
"${VERSION}). Check that git is installed and this is a valid git repo.")
endif ()
@ -482,6 +482,9 @@ endif()
# UPM common headers
set (UPM_COMMON_HEADER_DIRS ${CMAKE_HOME_DIRECTORY}/include)
# Generate a build-only C++ header to add functionality to SWIG'ed modules
configure_file (${PROJECT_SOURCE_DIR}/cmake/modules/version.hpp.in ${PROJECT_BINARY_DIR}/src/version.hpp @ONLY)
# UPM source
add_subdirectory (src)

View File

@ -0,0 +1,6 @@
#include <string>
inline std::string getVersion()
{
return "@upm_VERSION_STRING@";
}

View File

@ -16,6 +16,7 @@ services:
- BUILDCORDOVA=${BUILDCORDOVA:-OFF}
- BUILDSWIGNODE=${BUILDSWIGNODE:-OFF}
- BUILDEXAMPLES=${BUILDEXAMPLES:-OFF}
- CMAKE_BUILD_TYPE
- IPK=${IPK:-OFF}
- RPM=${RPM:-OFF}
- NPM=${NPM:-OFF}

View File

@ -4,10 +4,17 @@ API Changes {#apichanges}
Here's a list of other API changes made to the library that break source/binary
compatibility between releases:
# vNext
* The interface of **kx122** has been modified to return values instead of
receiving pointers. This applies to member functions: getWhoAmI,
getInterruptSource, getBufferStatus, getRawBufferSamples, and getBufferSamples.
# v1.7.0
* The interface of **kx122** has been modified to return values instead
of receiving pointers. This applies to member functions: getWhoAmI,
getInterruptSource, getBufferStatus, getRawBufferSamples, and
getBufferSamples.
* The **tm1637** constructor has been updated and the fast GPIO parameter
has been removed with the deprecation of supporting MRAA functions. The
GPIO lines will initialize by default in fast mode when available.
* The generic **nmea_gps** library for GPS devices has been greatly enhanced
with new APIs to offer better control over acquisition intervals and simplify
parsing of the returned data.
# v1.6.0

View File

@ -96,13 +96,16 @@ You can also generate the include and lib directories containing all the sensor
headers and library files respectively with *make install*. Further, you may
choose to generate these only for a specific sensor you modified, and this can
be achieved by building from the individual makefile of the sensor. Assuming
you're in the build directory, to make the lcd module you would:
you're in the build directory, to build/install the lcd module you would:
~~~~~~~~~~~~~
cd src/lcd
make install
~~~~~~~~~~~~~
Note: 'make install' under src/lcd will build all targets (and dependencies)
for the lcd but will NOT install dependencies.
Often developers are only interested in building one module or even just the
python/node module to do some quick testing using scripting. In order to do
this you need to use the target name for the python or node module you want to

View File

@ -4,6 +4,16 @@ Changelog {#changelog}
Here's a list summarizing some of the key undergoing changes to our library
from earlier versions:
### v1.7.0
* Added Cordova bindings based on Java packages
* Complete rework of the nmea_gps library giving more control over data
acquisition and parsing
* Added GTest support for unit tests
* Removed calls to deprecated MRAA fast GPIO functions
* Several bug fixes and improvements around SWIG type maps and gcc8 support
* New sensors: kx122, kxtj3, bh1792, bh1749
### v1.6.0
* Extended LED library to support the new MRAA gpio-leds APIs

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -1,361 +0,0 @@
Creative Commons Legal Code
Attribution-NonCommercial-ShareAlike 3.0 Unported
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
DAMAGES RESULTING FROM ITS USE.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
CONDITIONS.
1. Definitions
a. "Adaptation" means a work based upon the Work, or upon the Work and
other pre-existing works, such as a translation, adaptation,
derivative work, arrangement of music or other alterations of a
literary or artistic work, or phonogram or performance and includes
cinematographic adaptations or any other form in which the Work may be
recast, transformed, or adapted including in any form recognizably
derived from the original, except that a work that constitutes a
Collection will not be considered an Adaptation for the purpose of
this License. For the avoidance of doubt, where the Work is a musical
work, performance or phonogram, the synchronization of the Work in
timed-relation with a moving image ("synching") will be considered an
Adaptation for the purpose of this License.
b. "Collection" means a collection of literary or artistic works, such as
encyclopedias and anthologies, or performances, phonograms or
broadcasts, or other works or subject matter other than works listed
in Section 1(g) below, which, by reason of the selection and
arrangement of their contents, constitute intellectual creations, in
which the Work is included in its entirety in unmodified form along
with one or more other contributions, each constituting separate and
independent works in themselves, which together are assembled into a
collective whole. A work that constitutes a Collection will not be
considered an Adaptation (as defined above) for the purposes of this
License.
c. "Distribute" means to make available to the public the original and
copies of the Work or Adaptation, as appropriate, through sale or
other transfer of ownership.
d. "License Elements" means the following high-level license attributes
as selected by Licensor and indicated in the title of this License:
Attribution, Noncommercial, ShareAlike.
e. "Licensor" means the individual, individuals, entity or entities that
offer(s) the Work under the terms of this License.
f. "Original Author" means, in the case of a literary or artistic work,
the individual, individuals, entity or entities who created the Work
or if no individual or entity can be identified, the publisher; and in
addition (i) in the case of a performance the actors, singers,
musicians, dancers, and other persons who act, sing, deliver, declaim,
play in, interpret or otherwise perform literary or artistic works or
expressions of folklore; (ii) in the case of a phonogram the producer
being the person or legal entity who first fixes the sounds of a
performance or other sounds; and, (iii) in the case of broadcasts, the
organization that transmits the broadcast.
g. "Work" means the literary and/or artistic work offered under the terms
of this License including without limitation any production in the
literary, scientific and artistic domain, whatever may be the mode or
form of its expression including digital form, such as a book,
pamphlet and other writing; a lecture, address, sermon or other work
of the same nature; a dramatic or dramatico-musical work; a
choreographic work or entertainment in dumb show; a musical
composition with or without words; a cinematographic work to which are
assimilated works expressed by a process analogous to cinematography;
a work of drawing, painting, architecture, sculpture, engraving or
lithography; a photographic work to which are assimilated works
expressed by a process analogous to photography; a work of applied
art; an illustration, map, plan, sketch or three-dimensional work
relative to geography, topography, architecture or science; a
performance; a broadcast; a phonogram; a compilation of data to the
extent it is protected as a copyrightable work; or a work performed by
a variety or circus performer to the extent it is not otherwise
considered a literary or artistic work.
h. "You" means an individual or entity exercising rights under this
License who has not previously violated the terms of this License with
respect to the Work, or who has received express permission from the
Licensor to exercise rights under this License despite a previous
violation.
i. "Publicly Perform" means to perform public recitations of the Work and
to communicate to the public those public recitations, by any means or
process, including by wire or wireless means or public digital
performances; to make available to the public Works in such a way that
members of the public may access these Works from a place and at a
place individually chosen by them; to perform the Work to the public
by any means or process and the communication to the public of the
performances of the Work, including by public digital performance; to
broadcast and rebroadcast the Work by any means including signs,
sounds or images.
j. "Reproduce" means to make copies of the Work by any means including
without limitation by sound or visual recordings and the right of
fixation and reproducing fixations of the Work, including storage of a
protected performance or phonogram in digital form or other electronic
medium.
2. Fair Dealing Rights. Nothing in this License is intended to reduce,
limit, or restrict any uses free from copyright or rights arising from
limitations or exceptions that are provided for in connection with the
copyright protection under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License,
Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
perpetual (for the duration of the applicable copyright) license to
exercise the rights in the Work as stated below:
a. to Reproduce the Work, to incorporate the Work into one or more
Collections, and to Reproduce the Work as incorporated in the
Collections;
b. to create and Reproduce Adaptations provided that any such Adaptation,
including any translation in any medium, takes reasonable steps to
clearly label, demarcate or otherwise identify that changes were made
to the original Work. For example, a translation could be marked "The
original work was translated from English to Spanish," or a
modification could indicate "The original work has been modified.";
c. to Distribute and Publicly Perform the Work including as incorporated
in Collections; and,
d. to Distribute and Publicly Perform Adaptations.
The above rights may be exercised in all media and formats whether now
known or hereafter devised. The above rights include the right to make
such modifications as are technically necessary to exercise the rights in
other media and formats. Subject to Section 8(f), all rights not expressly
granted by Licensor are hereby reserved, including but not limited to the
rights described in Section 4(e).
4. Restrictions. The license granted in Section 3 above is expressly made
subject to and limited by the following restrictions:
a. You may Distribute or Publicly Perform the Work only under the terms
of this License. You must include a copy of, or the Uniform Resource
Identifier (URI) for, this License with every copy of the Work You
Distribute or Publicly Perform. You may not offer or impose any terms
on the Work that restrict the terms of this License or the ability of
the recipient of the Work to exercise the rights granted to that
recipient under the terms of the License. You may not sublicense the
Work. You must keep intact all notices that refer to this License and
to the disclaimer of warranties with every copy of the Work You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Work, You may not impose any effective technological
measures on the Work that restrict the ability of a recipient of the
Work from You to exercise the rights granted to that recipient under
the terms of the License. This Section 4(a) applies to the Work as
incorporated in a Collection, but this does not require the Collection
apart from the Work itself to be made subject to the terms of this
License. If You create a Collection, upon notice from any Licensor You
must, to the extent practicable, remove from the Collection any credit
as required by Section 4(d), as requested. If You create an
Adaptation, upon notice from any Licensor You must, to the extent
practicable, remove from the Adaptation any credit as required by
Section 4(d), as requested.
b. You may Distribute or Publicly Perform an Adaptation only under: (i)
the terms of this License; (ii) a later version of this License with
the same License Elements as this License; (iii) a Creative Commons
jurisdiction license (either this or a later license version) that
contains the same License Elements as this License (e.g.,
Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License").
You must include a copy of, or the URI, for Applicable License with
every copy of each Adaptation You Distribute or Publicly Perform. You
may not offer or impose any terms on the Adaptation that restrict the
terms of the Applicable License or the ability of the recipient of the
Adaptation to exercise the rights granted to that recipient under the
terms of the Applicable License. You must keep intact all notices that
refer to the Applicable License and to the disclaimer of warranties
with every copy of the Work as included in the Adaptation You
Distribute or Publicly Perform. When You Distribute or Publicly
Perform the Adaptation, You may not impose any effective technological
measures on the Adaptation that restrict the ability of a recipient of
the Adaptation from You to exercise the rights granted to that
recipient under the terms of the Applicable License. This Section 4(b)
applies to the Adaptation as incorporated in a Collection, but this
does not require the Collection apart from the Adaptation itself to be
made subject to the terms of the Applicable License.
c. You may not exercise any of the rights granted to You in Section 3
above in any manner that is primarily intended for or directed toward
commercial advantage or private monetary compensation. The exchange of
the Work for other copyrighted works by means of digital file-sharing
or otherwise shall not be considered to be intended for or directed
toward commercial advantage or private monetary compensation, provided
there is no payment of any monetary compensation in con-nection with
the exchange of copyrighted works.
d. If You Distribute, or Publicly Perform the Work or any Adaptations or
Collections, You must, unless a request has been made pursuant to
Section 4(a), keep intact all copyright notices for the Work and
provide, reasonable to the medium or means You are utilizing: (i) the
name of the Original Author (or pseudonym, if applicable) if supplied,
and/or if the Original Author and/or Licensor designate another party
or parties (e.g., a sponsor institute, publishing entity, journal) for
attribution ("Attribution Parties") in Licensor's copyright notice,
terms of service or by other reasonable means, the name of such party
or parties; (ii) the title of the Work if supplied; (iii) to the
extent reasonably practicable, the URI, if any, that Licensor
specifies to be associated with the Work, unless such URI does not
refer to the copyright notice or licensing information for the Work;
and, (iv) consistent with Section 3(b), in the case of an Adaptation,
a credit identifying the use of the Work in the Adaptation (e.g.,
"French translation of the Work by Original Author," or "Screenplay
based on original Work by Original Author"). The credit required by
this Section 4(d) may be implemented in any reasonable manner;
provided, however, that in the case of a Adaptation or Collection, at
a minimum such credit will appear, if a credit for all contributing
authors of the Adaptation or Collection appears, then as part of these
credits and in a manner at least as prominent as the credits for the
other contributing authors. For the avoidance of doubt, You may only
use the credit required by this Section for the purpose of attribution
in the manner set out above and, by exercising Your rights under this
License, You may not implicitly or explicitly assert or imply any
connection with, sponsorship or endorsement by the Original Author,
Licensor and/or Attribution Parties, as appropriate, of You or Your
use of the Work, without the separate, express prior written
permission of the Original Author, Licensor and/or Attribution
Parties.
e. For the avoidance of doubt:
i. Non-waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme cannot be waived, the Licensor
reserves the exclusive right to collect such royalties for any
exercise by You of the rights granted under this License;
ii. Waivable Compulsory License Schemes. In those jurisdictions in
which the right to collect royalties through any statutory or
compulsory licensing scheme can be waived, the Licensor reserves
the exclusive right to collect such royalties for any exercise by
You of the rights granted under this License if Your exercise of
such rights is for a purpose or use which is otherwise than
noncommercial as permitted under Section 4(c) and otherwise waives
the right to collect royalties through any statutory or compulsory
licensing scheme; and,
iii. Voluntary License Schemes. The Licensor reserves the right to
collect royalties, whether individually or, in the event that the
Licensor is a member of a collecting society that administers
voluntary licensing schemes, via that society, from any exercise
by You of the rights granted under this License that is for a
purpose or use which is otherwise than noncommercial as permitted
under Section 4(c).
f. Except as otherwise agreed in writing by the Licensor or as may be
otherwise permitted by applicable law, if You Reproduce, Distribute or
Publicly Perform the Work either by itself or as part of any
Adaptations or Collections, You must not distort, mutilate, modify or
take other derogatory action in relation to the Work which would be
prejudicial to the Original Author's honor or reputation. Licensor
agrees that in those jurisdictions (e.g. Japan), in which any exercise
of the right granted in Section 3(b) of this License (the right to
make Adaptations) would be deemed to be a distortion, mutilation,
modification or other derogatory action prejudicial to the Original
Author's honor and reputation, the Licensor will waive or not assert,
as appropriate, this Section, to the fullest extent permitted by the
applicable national law, to enable You to reasonably exercise Your
right under Section 3(b) of this License (right to make Adaptations)
but not otherwise.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE
FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS
AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE
WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT
LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT
DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
a. This License and the rights granted hereunder will terminate
automatically upon any breach by You of the terms of this License.
Individuals or entities who have received Adaptations or Collections
from You under this License, however, will not have their licenses
terminated provided such individuals or entities remain in full
compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
survive any termination of this License.
b. Subject to the above terms and conditions, the license granted here is
perpetual (for the duration of the applicable copyright in the Work).
Notwithstanding the above, Licensor reserves the right to release the
Work under different license terms or to stop distributing the Work at
any time; provided, however that any such election will not serve to
withdraw this License (or any other license that has been, or is
required to be, granted under the terms of this License), and this
License will continue in full force and effect unless terminated as
stated above.
8. Miscellaneous
a. Each time You Distribute or Publicly Perform the Work or a Collection,
the Licensor offers to the recipient a license to the Work on the same
terms and conditions as the license granted to You under this License.
b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
offers to the recipient a license to the original Work on the same
terms and conditions as the license granted to You under this License.
c. If any provision of this License is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this License, and without further action
by the parties to this agreement, such provision shall be reformed to
the minimum extent necessary to make such provision valid and
enforceable.
d. No term or provision of this License shall be deemed waived and no
breach consented to unless such waiver or consent shall be in writing
and signed by the party to be charged with such waiver or consent.
e. This License constitutes the entire agreement between the parties with
respect to the Work licensed here. There are no understandings,
agreements or representations with respect to the Work not specified
here. Licensor shall not be bound by any additional provisions that
may appear in any communication from You. This License may not be
modified without the mutual written agreement of the Licensor and You.
f. The rights granted under, and the subject matter referenced, in this
License were drafted utilizing the terminology of the Berne Convention
for the Protection of Literary and Artistic Works (as amended on
September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
and the Universal Copyright Convention (as revised on July 24, 1971).
These rights and subject matter take effect in the relevant
jurisdiction in which the License terms are sought to be enforced
according to the corresponding provisions of the implementation of
those treaty provisions in the applicable national law. If the
standard suite of rights granted under applicable copyright law
includes additional rights not granted under this License, such
additional rights are deemed to be included in the License; this
License is not intended to restrict the license of any rights under
applicable law.
Creative Commons Notice
Creative Commons is not a party to this License, and makes no warranty
whatsoever in connection with the Work. Creative Commons will not be
liable to You or any party on any legal theory for any damages
whatsoever, including without limitation any general, special,
incidental or consequential damages arising in connection to this
license. Notwithstanding the foregoing two (2) sentences, if Creative
Commons has expressly identified itself as the Licensor hereunder, it
shall have all rights and obligations of Licensor.
Except for the limited purpose of indicating to the public that the
Work is licensed under the CCPL, Creative Commons does not authorize
the use by either party of the trademark "Creative Commons" or any
related trademark or logo of Creative Commons without the prior
written consent of Creative Commons. Any permitted use will be in
compliance with Creative Commons' then-current trademark usage
guidelines, as may be published on its website or otherwise made
available upon request from time to time. For the avoidance of doubt,
this trademark restriction does not form part of this License.
Creative Commons may be contacted at https://creativecommons.org/.

BIN
docs/images/kxtj3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -34,13 +34,6 @@ var lib = require('jsupm_<module-name>');
### Supported Sensors
The full list is available on [Intel® IoT Developer Zone](https://software.intel.com/en-us/iot/hardware/sensors).
### IDE Integration
Intel® XDK IoT Edition is the recommended IDE for Node.js development. Visit
the Intel® Developer Zone [IDE page](https://software.intel.com/iot/software/ide)
for more information on how to get started.
![Intel XDK](http://iotdk.intel.com/docs/master/upm/docs/icons/xdk.png)
### Building UPM
See building documentation [here](https://github.com/intel-iot-devkit/upm/blob/master/docs/building.md).

View File

@ -23,15 +23,6 @@ repository.
Individual sensor usage examples for Python are available `here <https://github.com/intel-iot-devkit/upm/tree/master/examples/python>`_.
``IDE Compatibility``
################
While there is no official IDE provided with our Python libraries, we do recommend the web-based IDE Wyliodrin. It can be used with multiple programming
languages, including Python. More information can be found on the Intel Developer Zone IDE page.
.. image:: ../docs/icons/wyliodrin.png
:target: https://software.intel.com/iot/software/ide
``Making your own UPM Module``
##############################

View File

@ -36,19 +36,6 @@
href="https://github.com/intel-iot-devkit/upm/tree/master/examples/javascript">here</a>.</p>
</div>
<div class="section" id="ide">
<h3><tt class="docutils literal"><span class="pre">IDE Compatibility</span>
<span class="pre">UPM</span></tt><a class="headerlink"
href="#ide"
title="Permalink to this headline">*</a></h3>
<p>Intel&reg; XDK IoT Edition is the recommended IDE for Node.js development.
Visit the Intel&reg; Developer Zone IDE page for more information on how to get
started.<br>
<a href="https://software.intel.com/iot/software/ide"><img src="../docs/icons/xdk.png"/></a>
</p>
</div>
<div class="section" id="building-upm">
<h3><tt class="docutils literal"><span class="pre">Building</span>
<span class="pre">UPM</span></tt><a class="headerlink"

View File

@ -3,6 +3,9 @@ a110x.cxx A110X_Example.java a110x.js a110x.py
a110x-intr.cxx A110X_intr_Example.java a110x-intr.js a110x-intr.py
adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py
adxl345.cxx Adxl345_Example.java adxl345.js adxl345.py
bh1749.cxx BH1749_Example.java bh1749.js bh1749.py
bh1750.cxx BH1750_Example.java bh1750.js bh1750.py
bh1792.cxx BH1792_Example.java bh1792.js bh1792.py
biss0001.cxx BISS0001_Example.java biss0001.js biss0001.py
bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py
bno055.cxx BNO055_Example.java bno055.js bno055.py

View File

@ -4,15 +4,15 @@ file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cxx")
# - Handle special cases here --------------------------------------------------
# Test humidity interface for 2 sensor libraries
add_example(core-humiditysensor.cxx TARGETS si7005 bmp280)
add_example(interfaces-humiditysensor.cxx TARGETS si7005 bmp280)
# Test pressure interface for 2 sensor libraries
add_example(core-pressuresensor.cxx TARGETS bmp280 bmpx8x)
add_example(interfaces-pressuresensor.cxx TARGETS bmp280 bmpx8x)
# Test temperature interface for 3 sensor libraries
add_example(core-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
add_example(interfaces-temperaturesensor.cxx TARGETS bmp280 bmpx8x si7005)
# Test light interface for 2 sensor libraries
add_example(core-lightsensor.cxx TARGETS si1132 max44009)
add_example(interfaces-lightsensor.cxx TARGETS si1132 max44009)
# Test light controller interface for 3 sensor libraries
add_example(core-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
add_example(interfaces-lightcontroller.cxx TARGETS lp8860 ds1808lc hlg150h)
# - Create an executable for all other src files in this directory -------------
foreach (_example_src ${example_src_list})

View File

@ -43,14 +43,14 @@ main()
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
gpio.dir(mraa::DIR_OUT_HIGH);
/* Show usage from the iADC interface */
upm::iADC* adc = static_cast<upm::iADC*>(&sensor);
/* Show usage from the IADC interface */
upm::IADC* adc = static_cast<upm::IADC*>(&sensor);
if (adc == NULL) {
std::cout << "ADC not detected" << std::endl;
return 1;
}
std::cout << "ADC " << adc->Name() << " detected. ";
std::cout << "ADC " << adc->getModuleName() << " detected. ";
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
while (true) {
for (unsigned int i = 0; i < adc->getNumInputs(); ++i) {

71
examples/c++/bh1749.cxx Executable file
View File

@ -0,0 +1,71 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <unistd.h>
#include <stdexcept>
#include <signal.h>
#include <vector>
#include "bh1749.hpp"
#include "upm_utilities.h"
bool isStopped;
upm::BH1749 dev;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<uint16_t> result = dev.GetMeasurements();
std::cout << "R: " << result.at(0) <<
", G: " << result.at(1) <<
", B: " << result.at(2) <<
", IR: " << result.at(3) <<
", G2: " << result.at(4) << std::endl;
dev.ResetInterrupt();
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.SensorInit(INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
dev.SetThresholdHigh(511);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
dev.EnableInterrupt();
dev.Enable();
while(!isStopped) {
upm_delay_ms(1000);
}
return 0;
}
//! [Interesting]

81
examples/c++/bh1792.cxx Executable file
View File

@ -0,0 +1,81 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <signal.h>
#include <sys/time.h>
#include "bh1792.hpp"
#include "upm_utilities.h"
bool isStopped;
upm::BH1792 dev;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<std::vector<int>> fifo;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
try {
fifo = dev.GetFifoData();
std::cout << "\nHeart beat sensor FIFO data:" << std::endl;
for(int i = 0; i < 32; i++)
std::cout << i << ": off: " << fifo.at(i).at(0) << ", on: " <<
fifo.at(i).at(1) << std::endl;
std::cout << "timestamp " << now.tv_sec << " sec, " << now.tv_nsec <<
" nsec" << std::endl;
} catch (std::exception& e) {
std::cout << "Failed to read FIFO data" << std::endl;
throw;
}
}
int main(int argc, char **argv)
{
float measTime;
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.EnableSyncMode(256, 32);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
measTime = dev.GetMeasurementTimeMS();
dev.StartMeasurement();
while(!isStopped) {
usleep(measTime * 1000);
}
return 0;
}
//! [Interesting]

View File

@ -47,7 +47,7 @@ main(int argc, char** argv)
//! [Interesting]
// Instantiate a IMS instance using i2c bus 0 and default address
upm::IMS sensor("i:0:0x20");
upm::IMS sensor(0);
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
while (shouldRun) {

View File

@ -38,14 +38,14 @@
#define EDISON_GPIO_SI7005_CS 20
//! [Interesting]
// Simple example of using iHumiditySensor to determine
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// iHumiditySensor is then used to get readings from sensor
// ILightSensor is then used to get readings from sensor
upm::iHumiditySensor*
upm::IHumiditySensor*
getHumiditySensor()
{
upm::iHumiditySensor* humiditySensor = NULL;
upm::IHumiditySensor* humiditySensor = NULL;
try {
humiditySensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
@ -66,26 +66,22 @@ getHumiditySensor()
int
main()
{
upm::iHumiditySensor* sensor = getHumiditySensor();
if (sensor == NULL) {
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
if (humiditySensor == NULL) {
std::cout << "Humidity sensor not detected" << std::endl;
return 1;
}
std::cout << "Humidity sensor " << sensor->Name() << " detected" << std::endl;
try {
std::map<std::string, float> values = sensor->HumidityAll();
for (std::map<std::string, float>::const_iterator it = values.begin();
it != values.end(); ++it)
std::cout << it->first << " = " << it->second
<< sensor->Unit(it->first) << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = humiditySensor->getHumidityRelative();
std::cout << "Humidity = " << value << "%" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
upm_delay(1);
}
delete sensor;
delete humiditySensor;
return 0;
}

View File

@ -66,7 +66,7 @@ main(int argc, char** argv)
upm::ILightController* lightController = getLightController();
if (lightController != NULL) {
//std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
} else {
std::cerr << "Error. Unsupported platform." << std::endl;
return 1;

View File

@ -36,14 +36,14 @@
#define FT4222_I2C_BUS 0
//! [Interesting]
// Simple example of using iLightSensor to determine
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// iLightSensor is then used to get readings from sensor
// ILightSensor is then used to get readings from sensor
upm::iLightSensor*
upm::ILightSensor*
getLightSensor()
{
upm::iLightSensor* lightSensor = NULL;
upm::ILightSensor* lightSensor = NULL;
try {
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
return lightSensor;
@ -62,26 +62,22 @@ getLightSensor()
int
main()
{
upm::iLightSensor* sensor = getLightSensor();
if (sensor == NULL) {
upm::ILightSensor* lightSensor = getLightSensor();
if (lightSensor == NULL) {
std::cout << "Light sensor not detected" << std::endl;
return 1;
}
std::cout << "Light sensor " << sensor->Name() << " detected" << std::endl;
try {
std::map<std::string, float> values = sensor->LightAll();
for (std::map<std::string, float>::const_iterator it = values.begin();
it != values.end(); ++it)
std::cout << it->first << " = " << it->second
<< sensor->Unit(it->first) << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
float value = lightSensor->getVisibleLux();
std::cout << "Light level = " << value << " lux" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
upm_delay(1);
}
delete sensor;
delete lightSensor;
return 0;
}

View File

@ -36,14 +36,14 @@
#define FT4222_I2C_BUS 0
//! [Interesting]
// Simple example of using iPressureSensor to determine
// Simple example of using ILightSensor to determine
// which sensor is present and return its name.
// iPressureSensor is then used to get readings from sensor
// ILightSensor is then used to get readings from sensor
upm::iPressureSensor*
upm::IPressureSensor*
getPressureSensor()
{
upm::iPressureSensor* pressureSensor = NULL;
upm::IPressureSensor* pressureSensor = NULL;
try {
pressureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
return pressureSensor;
@ -63,26 +63,22 @@ getPressureSensor()
int
main()
{
upm::iPressureSensor* sensor = getPressureSensor();
if (sensor == NULL) {
upm::IPressureSensor* pressureSensor = getPressureSensor();
if (pressureSensor == NULL) {
std::cout << "Pressure sensor not detected" << std::endl;
return 1;
}
std::cout << "Pressure sensor " << sensor->Name() << " detected" << std::endl;
try {
std::map<std::string, float> values = sensor->PressureAll();
for (std::map<std::string, float>::const_iterator it = values.begin();
it != values.end(); ++it)
std::cout << it->first << " = " << it->second
<< sensor->Unit(it->first) << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
int value = pressureSensor->getPressurePa();
std::cout << "Pressure = " << value << " Pa" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
upm_delay(1);
}
delete sensor;
delete pressureSensor;
return 0;
}

View File

@ -39,14 +39,14 @@
#define EDISON_GPIO_SI7005_CS 20
//! [Interesting]
// Simple example of using iTemperatureSensor to determine
// Simple example of using ITemperatureSensor to determine
// which sensor is present and return its name.
// iTemperatureSensor is then used to get readings from sensor
// ITemperatureSensor is then used to get readings from sensor
upm::iTemperatureSensor*
upm::ITemperatureSensor*
getTemperatureSensor()
{
upm::iTemperatureSensor* temperatureSensor = NULL;
upm::ITemperatureSensor* temperatureSensor = NULL;
try {
temperatureSensor = new upm::BME280(mraa_get_sub_platform_id(FT4222_I2C_BUS));
@ -73,26 +73,23 @@ getTemperatureSensor()
int
main()
{
upm::iTemperatureSensor* sensor = getTemperatureSensor();
if (sensor == NULL) {
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
if (temperatureSensor == NULL) {
std::cout << "Temperature sensor not detected" << std::endl;
return 1;
}
std::cout << "Temperature sensor " << sensor->Name() << " detected" << std::endl;
try {
std::map<std::string, float> values = sensor->TemperatureAll();
for (std::map<std::string, float>::const_iterator it = values.begin();
it != values.end(); ++it)
std::cout << it->first << " = " << it->second
<< sensor->Unit(it->first) << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected"
<< std::endl;
while (true) {
try {
int value = temperatureSensor->getTemperatureCelsius();
std::cout << "Temperature = " << value << "C" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
upm_delay(1);
}
delete sensor;
delete temperatureSensor;
return 0;
}

73
examples/c++/kxtj3.cxx Executable file
View File

@ -0,0 +1,73 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <iomanip>
#include <unistd.h>
#include <signal.h>
#include "kxtj3.hpp"
#include "upm_utilities.h"
#define SENSOR_ADDR 0x0f
#define I2C_BUS 0
#define SAMPLE_COUNT 10
bool isStopped = false;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_acceleration_data(upm::KXTJ3 &dev)
{
float wait_time = dev.GetAccelerationSamplePeriod() * SECOND_IN_MICRO_S;
int sample_counter = SAMPLE_COUNT;
std::vector<float> xyz;
while ((sample_counter-- > 0) && !isStopped)
{
xyz = dev.GetAccelerationVector();
std::cout << std::fixed << std::setprecision(3)
<< xyz[0] << " | " << xyz[1] << " | " << xyz[2] << std::endl;
upm_delay_us(wait_time);
}
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
std::cout << "Sensor init" << std::endl;
upm::KXTJ3 dev(I2C_BUS, SENSOR_ADDR);
std::cout << "Setting settings:\nODR: 25 Hz\nResolution: "
<< "High\nAcceleration range: 16g with 14bits" << std::endl;
dev.SensorInit(KXTJ3_ODR_25, HIGH_RES, KXTJ3_RANGE_16G_14);
std::cout << "Showing acceleration data:" << std::endl;
print_acceleration_data(dev);
std::cout << "Closing sensor" << std::endl;
return 0;
}

View File

@ -1,49 +0,0 @@
#include <iostream>
#include <unistd.h>
#include "core/iUpmObject.hpp"
#include "noelstemplightreader.hpp"
void printMap(upm::NoelsTempLightReader &sensor, std::map<std::string, float> &data)
{
if (data.empty())
std::cout << "Empty map" << std::endl;
for (std::map<std::string, float>::const_iterator it = data.begin();
it != data.end(); ++it)
{
std::cout << "label: " << it->first << ", value: " << it->second
<< ", unit: " << sensor.Unit(it->first) << std::endl;
}
std::cout << std::endl;
}
int main ()
{
upm::NoelsTempLightReader sensor;
std::cout << "iUpmObject JsonDefinition..." << std::endl << ((upm::iUpmObject&)sensor).JsonDefinition() << std::endl << std::endl;
std::cout << "iSensorType JsonDefinition..." << std::endl << ((upm::iSensorType&)sensor).JsonDefinition() << std::endl << std::endl;
std::cout << "iMraa JsonDefinition..." << std::endl << ((upm::iMraa&)sensor).JsonDefinition() << std::endl << std::endl;
std::cout << "NoelsTempLightReader JsonDefinition..." << std::endl << sensor.JsonDefinition() << std::endl << std::endl;
std::cout << "Read all light values..." << std::endl;
std::map<std::string, float> values = sensor.LightAll();
printMap(sensor, values);
std::cout << "Read a single light value for light0..." << std::endl;
std::cout << "Single value = " << sensor.LightForSource("light0") << std::endl << std::endl;
try
{
std::cout << "Read a single light value for lightX (doesn't exist)..." << std::endl;
sensor.LightForSource("lightX");
}
catch (const std::exception& e) { std::cout << e.what() << std::endl << std::endl;}
std::cout << "Read a light value for lightX (doesn't exist)..." << std::endl;
values = sensor.LightForSources(std::vector<std::string>({"lightX"}));
printMap(sensor, values);
std::cout << "Read all values as JsonDefinition..." << std::endl << sensor.JsonValues() << std::endl;
return 0;
}

View File

@ -31,7 +31,7 @@ int
main(int argc, char** argv)
{
//! [Interesting]
upm::ES08A servo("p:5");
upm::ES08A servo(5);
// Sets the shaft to 180, then to 90, then to 0,
// then back to 90, and finally back to 180,

View File

@ -42,18 +42,18 @@ main()
/* Create an instance of the T6713 sensor */
upm::T6713 sensor(EDISON_I2C_BUS);
/* Show usage from the iCO2Sensor interface */
upm::iCO2Sensor* cO2Sensor = static_cast<upm::iCO2Sensor*>(&sensor);
/* Show usage from the ICO2Sensor interface */
upm::ICO2Sensor* cO2Sensor = static_cast<upm::ICO2Sensor*>(&sensor);
if (cO2Sensor == NULL) {
std::cout << "CO2 sensor not detected" << std::endl;
return 1;
}
std::cout << "CO2 sensor " << cO2Sensor->Name() << " detected" << std::endl;
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
while (true) {
try {
uint16_t value = cO2Sensor->CO2ForSource(cO2Sensor->Sources()[0]);
std::cout << "CO2 level = " << value << cO2Sensor->Units()[0] << std::endl;
uint16_t value = cO2Sensor->getPpm();
std::cout << "CO2 level = " << value << " ppm" << std::endl;
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}

View File

@ -49,7 +49,7 @@ main(int argc, char** argv)
int timezone = -7; // Your UTC offset
time_t rawtime;
struct tm* gmt;
char myTime[5];
char myTime[15];
fprintf(stdout, "TM1637 Display Example\n");
signal(SIGINT, sig_handler);
@ -66,7 +66,7 @@ main(int argc, char** argv)
int hour = (gmt) ? gmt->tm_hour : 0;
int min = (gmt) ? gmt->tm_min : 0;
// Format and store the time in 24 hour format
snprintf(myTime, 5, "%2d%02d", (hour + timezone + 24) % 24, min);
snprintf(myTime, 15, "%2d%02d", (hour + timezone + 24) % 24, min);
myDisplay.write(myTime); // Write to display as string
myDisplay.setColon(point ^= true); // Toggle the dots on the display

73
examples/c/bh1749.c Executable file
View File

@ -0,0 +1,73 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <signal.h>
#include "bh1749.h"
#include "upm_utilities.h"
bool isStopped;
#define SENSOR_ADDR 0x39
#define I2C_BUS 0
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_data(void *dev)
{
uint16_t result[5];
bh1749_get_measurements((bh1749_context)dev, result);
printf("R: %d, G: %d, B: %d, IR: %d, G2: %d\n", result[0],
result[1], result[2], result[3], result[4]);
bh1749_reset_interrupt(dev);
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
bh1749_context dev = bh1749_init(I2C_BUS, SENSOR_ADDR);
if (!dev) {
printf("bh1749_init() failed.\n");
return -1;
}
bh1749_soft_reset(dev);
bh1749_sensor_init(dev, INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
bh1749_set_threshold_high(dev, 511);
bh1749_enable_interrupt(dev);
printf("Installing ISR\n");
bh1749_install_isr(dev, MRAA_GPIO_EDGE_FALLING, 33, &print_data, (void *)dev);
bh1749_enable(dev);
while(!isStopped) {
upm_delay_ms(1000);
}
bh1749_close(dev);
return 0;
}

86
examples/c/bh1792.c Executable file
View File

@ -0,0 +1,86 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <signal.h>
#include "bh1792.h"
#include <sys/time.h>
#include "upm_utilities.h"
bool isStopped;
#define SENSOR_ADDR 0x5b
#define I2C_BUS 0
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_data(void *args)
{
bh1792_context dev = (bh1792_context)args;
uint16_t led_on[32], led_off[32];
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
if(bh1792_get_fifo_data(dev, led_off, led_on) == UPM_SUCCESS) {
printf("\nFIFO data:\n");
for(int i = 0; i < 32; i++)
printf("%d: off: %d, on: %d\n", i, led_off[i], led_on[i]);
printf("timestamp %ld sec, %ld nsec\n", now.tv_sec, now.tv_nsec);
}
}
int main(int argc, char **argv)
{
float meas_time;
signal(SIGINT, signal_int_handler);
bh1792_context dev = bh1792_init(I2C_BUS, SENSOR_ADDR);
if (!dev) {
printf("bh1792_init() failed.\n");
return -1;
}
printf("Software reset\n");
bh1792_soft_reset(dev);
bh1792_enable_sync_mode(dev, 256, 32);
bh1792_install_isr(dev, MRAA_GPIO_EDGE_FALLING, 33, &print_data, dev);
bh1792_get_meas_time_ms(dev, &meas_time);
bh1792_start_measurement(dev);
printf("Heart beat sensor data\n");
while(!isStopped) {
usleep(meas_time * 1000);
}
bh1792_close(dev);
return 0;
}

View File

@ -51,7 +51,7 @@ int main(int argc, char **argv)
}
int ndx = 0;
char str[20];
char str[23];
uint8_t rgb[7][3] = {
{0xd1, 0x00, 0x00},
{0xff, 0x66, 0x22},

75
examples/c/kxtj3.c Executable file
View File

@ -0,0 +1,75 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "kxtj3.h"
#define SENSOR_ADDR 0x0f
#define I2C_BUS 0
#define SAMPLE_COUNT 10
bool isStopped = false;
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_acceleration_data(kxtj3_context dev)
{
float wait_time = kxtj3_get_acceleration_sampling_period(dev) * SECOND_IN_MICRO_S;
uint8_t sample_counter = 0;
float x, y, z;
while (sample_counter < SAMPLE_COUNT && !isStopped)
{
kxtj3_get_acceleration_data(dev, &x, &y, &z);
printf("%.02f | %.02f | %.02f\n", x, y, z);
usleep(wait_time);
sample_counter++;
}
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
printf("Sensor init\n");
kxtj3_context dev = kxtj3_init(I2C_BUS, SENSOR_ADDR);
if (!dev)
{
printf("kxtj3_init() failed.\n");
return -1;
}
printf("Setting settings:\nODR: 25 Hz\nResolution: High\nAcceleration range: 16g with 14bits");
kxtj3_sensor_init(dev, KXTJ3_ODR_25, HIGH_RES, KXTJ3_RANGE_16G_14);
printf("Showing acceleration data:\n");
print_acceleration_data(dev);
printf("Closing sensor\n");
kxtj3_close(dev);
return 0;
}

View File

@ -0,0 +1,53 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 BH1749_Example {
public static void main(String[] args) throws InterruptedException {
//! [Interesting]
int sampleCounter = 10;
long waitTime;
upm_bh1749.BH1749 bh1749;
upm_bh1749.uint16Vector result;
bh1749 = new upm_bh1749.BH1749();
bh1749.SensorInit(upm_bh1749.OPERATING_MODES.INT_JUDGE_1,
upm_bh1749.MEAS_TIMES.MEAS_240MS, upm_bh1749.RGB_GAINS.RGB_GAIN_1X,
upm_bh1749.IR_GAINS.IR_GAIN_1X, upm_bh1749.INT_SOURCES.RED);
bh1749.SetThresholdHigh(511);
bh1749.Enable();
waitTime = bh1749.GetMeasurementTime();
System.out.println("Color readings");
while (sampleCounter-- > 0) {
result = bh1749.GetMeasurements();
System.out.println("R: " + result.get(0) + ", G: " + result.get(1) +
", B: " + result.get(2) + ", IR: " + result.get(3) +
", G2: " + result.get(4));
Thread.sleep((long) waitTime);
}
//! [Interesting]
}
}

View File

@ -0,0 +1,69 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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.
*/
//! [Interesting]
public class BH1792_Example {
public static void main(String[] args) throws InterruptedException {
int sampleCounter = 20;
float waitTime;
upm_bh1792.BH1792 bh1792;
bh1792 = new upm_bh1792.BH1792();
BH1792ISR callback = new BH1792ISR(bh1792);
bh1792.SoftReset();
bh1792.EnableSyncMode(256, 32);
bh1792.InstallISR(33, callback);
waitTime = bh1792.GetMeasurementTimeMS();
bh1792.StartMeasurement();
System.out.println("Heart rate sensor readings");
while (true) {
Thread.sleep((long) waitTime);
}
}
}
class BH1792ISR implements Runnable {
upm_bh1792.intVector2D result;
upm_bh1792.BH1792 bh1792;
public BH1792ISR(upm_bh1792.BH1792 bh1792) {
super();
this.bh1792 = bh1792;
}
public void run() {
result = this.bh1792.GetFifoData();
for(int i = 0; i < 32; i++)
System.out.println(i + ": off: " + result.get(i).get(0) +
", on: " + result.get(i).get(1));
System.out.println("Timestamp: " + System.nanoTime() + " nsec\n");
}
}
//! [Interesting]

View File

@ -24,7 +24,7 @@
*/
import upm_bmp280.*;
import upm_core.*;
import upm_interfaces.*;
public class BME280_Interface_Example
{
@ -35,9 +35,9 @@ public class BME280_Interface_Example
// Instantiate a BME280 instance using default i2c bus and address
BME280 sensor = new BME280();
iTemperatureSensor t_sensor = sensor;
iHumiditySensor h_sensor = sensor;
iPressureSensor p_sensor = sensor;
ITemperatureSensor t_sensor = sensor;
IHumiditySensor h_sensor = sensor;
IPressureSensor p_sensor = sensor;
// For SPI, bus 0, you would pass -1 as the address, and a
// valid pin for CS:
@ -51,15 +51,15 @@ public class BME280_Interface_Example
System.out.println("Calling Interface Functions: ");
System.out.println("Compensation Temperature: "
+ t_sensor.TemperatureForSource("temperature")
+ t_sensor.getTemperatureCelsius()
+ " C / ");
System.out.println("Pressure: "
+ p_sensor.PressureForSource("pressure")
+ p_sensor.getPressurePa()
+ " Pa");
System.out.println("Humidity: "
+ h_sensor.HumidityForSource("humidity")
+ h_sensor.getHumidityRelative()
+ " %RH");
System.out.println();

View File

@ -24,9 +24,9 @@ include(UseJava)
# add_example(SensorFooExample sensorfoo)
#
# # Creates SensorFooExample JAVA target, depends on targets: sensorfoo,
# # and core and will add both upm_sensorfoo.jar and upm_core.jar
# # and interfaces and will add both upm_sensorfoo.jar and upm_interfaces.jar
# # to the javac classpath.
# add_example(SensorFooExample "sensorfoo;core"")
# add_example(SensorFooExample "sensorfoo;interfaces"")
#
function(add_example example_class_name dependency_list)
set(example_file "${example_class_name}.java")
@ -68,23 +68,25 @@ add_example(A110X_Example a110x)
add_example(A110X_intr_Example a110x)
add_example(Ad8232_Example ad8232)
add_example(ADC121C021_Example adc121c021)
add_example(Ads1015_Example "ads1x15;core")
add_example(Ads1015_Example "ads1x15;interfaces")
add_example(Ads1115_Example ads1x15)
add_example(Adxl345_Example adxl345)
add_example(AM2315_Example am2315)
add_example(APA102_Example apa102)
add_example(Apds9002_Example apds9002)
add_example(BH1749_Example bh1749)
add_example(BH1750_Example bh1750)
add_example(BH1792_Example bh1792)
add_example(BISS0001_Example biss0001)
add_example(BMA250E_Example bma250e)
add_example(BMC150_Example bmx055)
add_example(BME280_Example "bmp280;core")
add_example(BME280_Example "bmp280;interfaces")
add_example(BMG160_Example bmg160)
add_example(BMI055_Example bmx055)
add_example(BMI160_Example bmi160)
add_example(BMM150_Example bmm150)
add_example(BMP280_Example "bmp280;core")
add_example(BMPX8X_Example "bmpx8x;core")
add_example(BMP280_Example "bmp280;interfaces")
add_example(BMPX8X_Example "bmpx8x;interfaces")
add_example(BMX055_Example bmx055)
add_example(BNO055_Example bno055)
add_example(Button_Example button)
@ -101,7 +103,7 @@ add_example(ECS1030_Example ecs1030)
add_example(EHR_Example ehr)
add_example(Emg_Example emg)
add_example(ENC03R_Example enc03r)
add_example(ES08A_Example "servo;core")
add_example(ES08A_Example "servo;interfaces")
add_example(FlexSensor_Example flex)
add_example(Gp2y0a_Example gp2y0a)
add_example(GroveButton_Example grove)
@ -144,6 +146,7 @@ add_example(Jhd1313m1_Example jhd1313m1)
add_example(Jhd1313m1_lcd_Example jhd1313m1)
add_example(Joystick12_Example joystick12)
add_example(KX122_Example kx122)
add_example(KXTJ3_Example kxtj3)
add_example(Lcm1602_i2c_Example lcm1602)
add_example(Lcm1602_parallel_Example lcm1602)
add_example(LDT0028_Example ldt0028)
@ -229,9 +232,9 @@ add_example(YG1006_Example yg1006)
add_example(ZFM20_Example zfm20)
if(SWIG_VERSION VERSION_GREATER 3.0.8)
add_example(BME280_Interface_Example "bmp280;core")
add_example(IMS_Example "ims;core")
add_example(RHUSB_Example "rhusb;core")
add_example(BME280_Interface_Example "bmp280;interfaces")
add_example(IMS_Example "ims;interfaces")
add_example(RHUSB_Example "rhusb;interfaces")
endif()
if (OPENZWAVE_FOUND)

View File

@ -50,4 +50,4 @@ public class ES08A_Example {
System.out.println("Set angle to 180");
// ! [Interesting]
}
}
}

View File

@ -22,6 +22,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_ims.IMS;
public class IMS_Example
{
public static void main(String[] args) throws InterruptedException
@ -29,18 +31,18 @@ public class IMS_Example
// ! [Interesting]
// Instantiate a IMS instance using bus 0 and default i2c address
upm_ims.IMS sensor = new upm_ims.IMS((short)0);
IMS sensor = new IMS((short)0);
while (true)
{
System.out.println("Version: "
+ upm_ims.javaupm_ims.LibraryVersion()
+ sensor.get_version()
+ " light: "
+ sensor.LightForSource("light")
+ sensor.get_light()
+ " moisture: "
+ sensor.MoistureForSource("moisture")
+ sensor.get_moisture()
+ " temp: "
+ sensor.TemperatureForSource("temperature")
+ sensor.get_temperature()
+ " C");
Thread.sleep(1000);

View File

@ -0,0 +1,49 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 KXTJ3_Example {
public static void main(String[] args) throws InterruptedException {
upm_kxtj3.KXTJ3 kxtj3 = new upm_kxtj3.KXTJ3(0);
kxtj3.SensorInit(upm_kxtj3.KXTJ3_ODR_T.KXTJ3_ODR_25,
upm_kxtj3.KXTJ3_RESOLUTION_T.HIGH_RES,
upm_kxtj3.KXTJ3_G_RANGE_T.KXTJ3_RANGE_16G_14);
float waitTime = kxtj3.GetAccelerationSamplePeriod() * 1000;
int sampleCounter = 10;
System.out.println("Setting settings:\nODR: 25 Hz\nResolution: " +
"High\nAcceleration range: 16g with 14bits");
System.out.println("Acceleration");
upm_kxtj3.floatVector xyz;
while (sampleCounter-- > 0) {
xyz = kxtj3.GetAccelerationVector();
System.out.println("x = " + xyz.get(0) + " y = " + xyz.get(1) +
" z = " + xyz.get(2));
Thread.sleep((long) waitTime);
}
}
}

View File

@ -1,42 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Your Full Name <your@email.address>
* Copyright (c) <year> <copyright holder>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import upm_noelstemplightreader.*;
public class NoelsTempLightReaderSample {
public static void main (String args[]) throws InterruptedException {
//! [Interesting]
// Instantiate new sensor instance
upm_noelstemplightreader.NoelsTempLightReader sensor = new upm_noelstemplightreader.NoelsTempLightReader();
while (true) {
//System.out.println("NoelsTempLightReader says: " + sensor.Name());
// Repeate every 2 seconds
Thread.sleep(2000);
}
//! [Interesting]
}
}

View File

@ -39,12 +39,6 @@ public class RHUSB_Example {
// Instantiate an RHUSB instance on defaultDev
upm_rhusb.RHUSB sensor = new upm_rhusb.RHUSB(defaultDev);
// Print out info from the sensor core
System.out.println("UPM Version:" + System.lineSeparator()
+ upm_rhusb.javaupm_rhusb.LibraryVersion() + System.lineSeparator());
System.out.println("JSON Definition:" + System.lineSeparator()
+ sensor.JsonDefinition() + System.lineSeparator());
// output the firmware ID
System.out.println("Firmware ID: " + sensor.getFirmwareID());

57
examples/javascript/bh1749.js Executable file
View File

@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 bh1749 = require("jsupm_bh1749");
var bh1749_sensor = new bh1749.BH1749();
bh1749_sensor.SensorInit(
bh1749.INT_JUDGE_1,
bh1749.MEAS_240MS,
bh1749.RGB_GAIN_1X,
bh1749.IR_GAIN_1X,
bh1749.RED);
bh1749_sensor.SetThresholdHigh(511);
bh1749_sensor.Enable();
var waitTime = bh1749_sensor.GetMeasurementTime();
var counter = 10;
console.log("Color readings: ");
var interval = setInterval(function() {
data = bh1749_sensor.GetMeasurements();
console.log(
"R: " + data.get(0) + ", G: " + data.get(1) + ", B: " + data.get(2) +
", IR: " + data.get(3) + ", G2: " + data.get(4)
);
counter--;
if (counter == 0) {
clearInterval(interval);
}
}, waitTime);
process.on("SIGINT", function() {
clearInterval(interval);
console.log("Exiting...");
process.exit(0);
});

50
examples/javascript/bh1792.js Executable file
View File

@ -0,0 +1,50 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 bh1792 = require("/usr/include/nodejs/lib/node_modules/jsupm_bh1792");
var bh1792_sensor = new bh1792.BH1792();
bh1792_sensor.SoftReset();
bh1792_sensor.EnableSyncMode(256, 32);
bh1792_sensor.StartMeasurement();
var waitTime = bh1792_sensor.GetMeasurementTimeMS();
var counter = 10;
console.log("Heart beat sensor readings: ");
var interval = setInterval(function() {
data = bh1792_sensor.GetGreenData();
console.log("off: " + data.get(0) + ", on: " + data.get(1) +
", timestamp: " + Date.now() + " msec");
counter--;
if (counter == 0) {
clearInterval(interval);
}
}, waitTime);
process.on("SIGINT", function() {
clearInterval(interval);
console.log("Exiting...");
process.exit(0);
});

54
examples/javascript/kxtj3.js Executable file
View File

@ -0,0 +1,54 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 kxtj3 = require("jsupm_kxtj3");
var kxtj3_sensor = new kxtj3.KXTJ3(0x0, 0x0f);
kxtj3_sensor.SensorInit(
kxtj3.KXTJ3_ODR_25,
kxtj3.HIGH_RES,
kxtj3.KXTJ3_RANGE_16G_14);
var waitTime = kxtj3_sensor.GetAccelerationSamplePeriod();
var counter = 10;
console.log("Setting settings:\nODR: 25 Hz\nResolution: \
High\nAcceleration range: 16g with 14bits");
console.log("Acceleration: ");
var interval = setInterval(function() {
data = kxtj3_sensor.GetAccelerationVector();
console.log(
"x: " + data.get(0) + " y: " + data.get(1) + " z: " + data.get(2)
);
counter--;
if (counter == 0) {
clearInterval(interval);
}
}, waitTime * 1000);
process.on("SIGINT", function() {
clearInterval(interval);
console.log("Exiting...");
process.exit(0);
});

View File

@ -1,40 +0,0 @@
/*
* The MIT License (MIT)
*
* Author: Your Full Name <your@email.address>
* Copyright (c) <year> <copyright holder>
*
* 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 jsupm_noelstemplightreader = require('jsupm_noelstemplightreader');
// Create an instance of the sensor
var sensor = new upm_noelstemplightreader.NoelsTempLightReader(0);
loop();
function loop()
{
// Call a method from the noelstemplightreader
console.log("NoelsTempLightReader says: " + sensor.helloWorld());
// Call loop every 2 seconds
setTimeout(loop, 2000);
}

60
examples/python/bh1749.py Executable file
View File

@ -0,0 +1,60 @@
# The MIT License (MIT)
#
# Author: Assam Boudjelthia
# Copyright (c) 2018 Rohm Semiconductor.
#
# 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
from upm import pyupm_bh1749
def main():
bh1749_sensor = pyupm_bh1749.BH1749()
bh1749_sensor.SensorInit(pyupm_bh1749.INT_JUDGE_1,
pyupm_bh1749.MEAS_240MS,
pyupm_bh1749.RGB_GAIN_1X,
pyupm_bh1749.IR_GAIN_1X,
pyupm_bh1749.RED)
bh1749_sensor.SetThresholdHigh(511)
# Prevent stack printing on CTRL^C
def SIGINTHandler(signum, frame):
raise SystemExit
def exitHandler():
print("Exiting")
sys.exit(0)
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
sampleCounter = 10
waitTime = bh1749_sensor.GetMeasurementTime()
print("Color readings: ")
while sampleCounter > 0:
[r, g, b, ir, g2] = bh1749_sensor.GetMeasurements()
print ("R: %d, y: %d, G: %d, IR: %d, G2: %d" % (r, g, b, ir, g2))
time.sleep(waitTime / 1000.0)
sampleCounter -= 1
if __name__ == '__main__':
main()

View File

@ -1,7 +1,7 @@
# The MIT License (MIT)
#
# Author: Your Full Name <your@email.address>
# Copyright (c) <year> <copyright holder>
# Author: Assam Boudjelthia
# Copyright (c) 2018 Rohm Semiconductor.
#
# 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
@ -20,20 +20,39 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time
from upm import pyupm_noelstemplightreader
import time, datetime
import sys
import signal
import atexit
from upm import pyupm_bh1792
def main():
# Create an instance of NoelsTempLightReader
sensor = pyupm_noelstemplightreader.NoelsTempLightReader(0)
bh1792_sensor = pyupm_bh1792.BH1792()
bh1792_sensor.SoftReset()
bh1792_sensor.EnableSyncMode(256, 32)
bh1792_sensor.StartMeasurement()
while True:
print("NoelsTempLightReader says: %s" % sensor.helloWorld)
# Prevent stack printing on CTRL^C
def SIGINTHandler(signum, frame):
raise SystemExit
def exitHandler():
print("Exiting")
sys.exit(0)
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
sampleCounter = 10
waitTime = bh1792_sensor.GetMeasurementTimeMS()
print("Heart beat sensor readings: ")
while sampleCounter > 0:
[off, on] = bh1792_sensor.GetGreenData()
print ("off: %d, on: %d, timestamp: %d msec" % (off, on, time.time() * 1000))
time.sleep(waitTime / 1000.0)
sampleCounter -= 1
# Repeat every 2 seconds
sleep(2)
if __name__ == '__main__':
main()

61
examples/python/kxtj3.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
# The MIT License (MIT)
#
# Author: Assam Boudjelthia
# Copyright (c) 2018 Rohm Semiconductor.
#
# 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
import time, sys, signal, atexit
from upm import pyupm_kxtj3
def main():
kxtj3_sensor = pyupm_kxtj3.KXTJ3(0x0, 0x0f)
kxtj3_sensor.SensorInit(pyupm_kxtj3.KXTJ3_ODR_25,
pyupm_kxtj3.HIGH_RES,
pyupm_kxtj3.KXTJ3_RANGE_16G_14)
# Prevent stack printing on CTRL^C
def SIGINTHandler(signum, frame):
raise SystemExit
def exitHandler():
print("Exiting")
sys.exit(0)
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
sampleCounter = 10
waitTime = kxtj3_sensor.GetAccelerationSamplePeriod()
print("Setting settings:\nODR: 25 Hz\nResolution: "
"High\nAcceleration range: 16g with 14bits")
print("Acceleration:")
while sampleCounter > 0:
[x, y, z] = kxtj3_sensor.GetAccelerationVector()
print ("x: %0.02f, y: %0.02f, z: %0.02f" % (x, y, z))
time.sleep(waitTime)
sampleCounter -= 1
if __name__ == '__main__':
main()

View File

@ -25,6 +25,11 @@ from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_rsc as rsc
# Since CI loads each python example, the following would fail if the types
# from rsc_regs.h are NOT exposed in the pyupm_rsc module
mode = rsc.NORMAL_MODE
dr = rsc.N_DR_20_SPS
def main():
# Instantiate a Honeywell RSC Pressure sensor on the SPI bus 0
rsc_sensor = rsc.RSC(0, 9, 8);

View File

@ -68,7 +68,7 @@ make -j8 -Cbuild
# Anotate the .java src from doxygen
find src/ -name "*.i" > build/upm.i.list
#../doxy/doxyport build/upm.i.list \
# -s src/core/,src/bacnetmstp,src/bmg160,src/bma250e,src/bmm150 \
# -s src/interfaces/,src/bacnetmstp,src/bmg160,src/bma250e,src/bmm150 \
# -m doxy/samples.mapping.txt \
# -d build/src/ \
# --convert-protected-to-private \

View File

@ -25,7 +25,7 @@ cd ${ROOT_DIR} && make -j8 -Cbuild 2> ${BUILD_LOGS_DIR}/build-doc.log
cd ${BUILD_DIR} && find ../src/ -name "*.i" > upm.i.list && \
../doxy/doxyport/doxyport upm.i.list \
--cmake ./compile_commands.json \
--source ../src/core/,../src/bacnetmstp,src \
--source ../src/interfaces/,../src/bacnetmstp,src \
--destination src/ \
--convert-protected-to-private \
--output upm-java-files.txt \

View File

@ -20,5 +20,6 @@ cmake \
-DBUILDTESTS=$BUILDTESTS \
-DWERROR=$WERROR \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
-H. \
-Bbuild

View File

@ -7,8 +7,7 @@ set (SWIG_CXX_DISABLE_WARNINGS -Wno-error
-Wno-delete-non-virtual-dtor
-Wno-unused-function
-Wno-maybe-uninitialized
-Wno-strict-aliasing
-Wno-unused-but-set-variable)
-Wno-strict-aliasing)
# If building under android, make sure swig gets an ANDROID flag
if (ANDROID)
@ -249,11 +248,10 @@ function (_get_current_dot_i_file filePrefix varDotIFile)
# This file will exist OUTSIDE the source tree
set(${varDotIFile} "${CMAKE_CURRENT_BINARY_DIR}/${libname}.i")
# First, create the include variables
set(SWIG_HASH_INCLUDES)
foreach (_hpp ${module_hpp})
set(SWIG_HASH_INCLUDES "#include \"${_hpp}\"")
endforeach()
# Create preprocessor include string for importing
string(REGEX REPLACE ";" "\"\n#include \"" SWIG_HASH_INCLUDES "${module_h_hpp}")
set(SWIG_HASH_INCLUDES "#include \"${SWIG_HASH_INCLUDES}\"")
# And the SWIG import string
string(REPLACE "#" "%" SWIG_PERCENT_INCLUDES "${SWIG_HASH_INCLUDES}")
# Write the interface file
@ -309,7 +307,7 @@ macro(_upm_swig_python)
set (python_wrapper_target ${SWIG_MODULE_${python_wrapper_name}_REAL_NAME})
add_dependencies(${python_wrapper_target} ${libname})
swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname})
swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname} -Wl,--unresolved-symbols=report-all)
target_include_directories (${python_wrapper_target}
PUBLIC
"${PYTHON_INCLUDE_PATH}"
@ -515,13 +513,13 @@ function(upm_swig_java)
swig_add_library (javaupm_${libname} LANGUAGE java SOURCES ${SWIG_CURRENT_DOT_I_FILE})
endif ()
# If the C++ target depends on C++ core, make the JAVA target
# depend on the JAVA core
if ("${_c_cxx_dependency_list}" MATCHES core)
add_dependencies(javaupm_${libname} javaupm_core)
# If this target depends on core, include the java core
# If the C++ target depends on C++ interfaces, make the JAVA target
# depend on the JAVA interfaces
if ("${_c_cxx_dependency_list}" MATCHES interfaces)
add_dependencies(javaupm_${libname} javaupm_interfaces)
# If this target depends on interfaces, include the java interfaces
# target .jar file in the classpath, otherwise this variable will be empty
set (INTERFACES_JAR_FILE ${CMAKE_BINARY_DIR}/src/core/upm_core.jar)
set (INTERFACES_JAR_FILE ${CMAKE_BINARY_DIR}/src/interfaces/upm_interfaces.jar)
endif ()
# For linker to report unresolved symbols. Note, there is currently no test
# for linker flags (similar to compile files), so this is it for now.
@ -565,10 +563,10 @@ function(upm_swig_java)
set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar)
endif ()
# Only include the upm_core.jar in the classpath for targets which
# depend on the core target. This fixes an issue where javac
# complains about an empty upm_core.jar when trying to build a target
# which does not depend on javaupm_core. If not previously set,
# Only include the upm_interfaces.jar in the classpath for targets which
# depend on the interfaces target. This fixes an issue where javac
# complains about an empty upm_interfaces.jar when trying to build a target
# which does not depend on javaupm_interfaces. If not previously set,
# INTERFACES_JAR_FILE will be empty, and javac *should* not complain.
add_custom_command (TARGET javaupm_${libname}
POST_BUILD
@ -633,12 +631,12 @@ if (BUILDSWIGNODE)
file (COPY ${CMAKE_SOURCE_DIR}/include DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
set (upm_LIB_INCLUDE_DIRS_GYP "'.',\n${upm_LIB_INCLUDE_DIRS_GYP}")
# Utilities and core
# Utilities and interfaces
file (COPY ${CMAKE_SOURCE_DIR}/src/utilities DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
file (COPY ${CMAKE_SOURCE_DIR}/src/core DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
file (COPY ${CMAKE_SOURCE_DIR}/src/interfaces DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname})
set (upm_LIB_SRCS_GYP "'utilities/upm_utilities.c',\n${upm_LIB_SRCS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'utilities',\n${upm_LIB_INCLUDE_DIRS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'core',\n${upm_LIB_INCLUDE_DIRS_GYP}")
set (upm_LIB_INCLUDE_DIRS_GYP "'interfaces',\n${upm_LIB_INCLUDE_DIRS_GYP}")
# Add readme, package.json for NPM and node-gyp config file
configure_file (${PROJECT_SOURCE_DIR}/src/binding.gyp.in ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}/binding.gyp @ONLY)
@ -790,22 +788,6 @@ function(upm_module_init)
# Create the target library from src/hdrs
add_library (${libname} SHARED ${module_src} ${module_hpp})
# Add a upm_library_globals to all C++ libraries
if (NOT IS_C_LIBRARY)
# Share some GLOBAL (per library) info with the library (UPM version and library base name)
target_compile_definitions(${libname}
PRIVATE -DUPM_LIBRARY_BASE_NAME=${libname}
-DUPM_VERSION_STRING=${upm_VERSION_STRING})
# Add a source file which contains the shared GLOBAL info
target_sources(${libname}
PRIVATE ${CMAKE_SOURCE_DIR}/src/upm_library_globals.cxx
${CMAKE_SOURCE_DIR}/src/upm_library_globals.hpp)
# This source depends on libdl (uses dladdr), make sure to link this
target_link_libraries (${libname} ${CMAKE_DL_LIBS})
endif()
# Specify the current source directory as an INTERFACE include dir.
# This allows for transitive header dependencies via target_link_libraries
target_include_directories(${libname} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
@ -838,6 +820,16 @@ function(upm_module_init)
# Don't SWIG C
if (NOT IS_C_LIBRARY)
# When auto-generating a SWIG .i file, first include any C headers which
# end in *_regs.h. Then, include the C++ headers.
if (UPM_MIXED_MODULE_INIT_C_HDR AND UPM_MIXED_MODULE_INIT_CPP_WRAPS_C)
string(REGEX MATCHALL "[^;]*_regs.h" _regs "${UPM_MIXED_MODULE_INIT_C_HDR}")
if(_regs)
list(APPEND module_h_hpp "${_regs}")
endif()
endif ()
list(APPEND module_h_hpp "${module_hpp}")
separate_arguments (module_h_hpp)
if (BUILDSWIGPYTHON)
upm_swig_python()
endif (BUILDSWIGPYTHON)
@ -872,14 +864,8 @@ function(upm_module_init)
DESTINATION include/upm
COMPONENT ${CMAKE_PROJECT_NAME}-dev)
# Handle build/install for JSON library descriptor file
# Install JSON library descriptor files into datadir (if they exist)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.json")
# Copy JSON library descriptor file to binary directory (for testing/running from build dir)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${basename}.json"
"${CMAKE_CURRENT_BINARY_DIR}/${basename}.json"
COPYONLY)
# Install JSON library descriptor files into datadir (if they exist)
install (FILES "${CMAKE_CURRENT_SOURCE_DIR}/${basename}.json"
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm/${basename}
COMPONENT ${CMAKE_PROJECT_NAME})
@ -931,10 +917,10 @@ if (NOT "${MODULE_LIST}" MATCHES ";utilities;")
set(MODULE_LIST "utilities;${MODULE_LIST}")
endif()
# If the module list does NOT include the core directory, prepend it since
# some sensor library targets depend on core
if (NOT "${MODULE_LIST}" MATCHES ";core;")
set(MODULE_LIST "core;${MODULE_LIST}")
# If the module list does NOT include the interfaces directory, prepend it since
# some sensor library targets depend on interfaces
if (NOT "${MODULE_LIST}" MATCHES ";interfaces;")
set(MODULE_LIST "interfaces;${MODULE_LIST}")
endif()
# Iterate over each directory in MODULE_LIST

View File

@ -35,13 +35,9 @@ ad8232_context ad8232_init(int lo_plus, int lo_minus, int output,
return NULL;
}
dev->gpio_lo_plus_pin = lo_plus;
dev->gpio_lo_minus_pin = lo_minus;
dev->aio_pin = output;
dev->aio = mraa_aio_init(dev->aio_pin);
dev->gpio_lo_plus = mraa_gpio_init(dev->gpio_lo_plus_pin);
dev->gpio_lo_minus = mraa_gpio_init(dev->gpio_lo_minus_pin);
dev->aio = mraa_aio_init(output);
dev->gpio_lo_plus = mraa_gpio_init(lo_plus);
dev->gpio_lo_minus = mraa_gpio_init(lo_minus);
if (dev->aio == NULL || dev->gpio_lo_minus == NULL ||
dev->gpio_lo_plus == NULL){

View File

@ -51,9 +51,6 @@ typedef struct _ad8232_context {
mraa_aio_context aio;
mraa_gpio_context gpio_lo_plus;
mraa_gpio_context gpio_lo_minus;
uint8_t aio_pin;
uint8_t gpio_lo_plus_pin;
uint8_t gpio_lo_minus_pin;
int a_res;
} *ad8232_context;

View File

@ -65,8 +65,8 @@ namespace upm {
*
* @image html ad8232.jpg
* <br><em>AD8232 Heart Rate Monitor image provided by SparkFun under
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
* CC BY-NC-SA-3.0</a>.</em>
* <a href=https://creativecommons.org/licenses/by/2.0/>
* CC BY 2.0</a>.</em>
*
* @snippet ad8232.cxx Interesting
*/

View File

@ -2,7 +2,7 @@ set (libname "ads1x15")
set (libdescription "Texas Instruments I2C ADC Library")
set (module_src ${libname}.cxx ads1115.cxx ads1015.cxx)
set (module_hpp ${libname}.hpp ads1115.hpp ads1015.hpp)
upm_module_init(core mraa)
upm_module_init(interfaces mraa)
compiler_flag_supported(CXX is_supported -Wno-overloaded-virtual)
if (is_supported)
target_compile_options(${libname} PUBLIC -Wno-overloaded-virtual)

View File

@ -40,7 +40,7 @@ ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
m_bitShift = 4;
ADS1X15::getCurrentConfig();
if (vref < 0.0 || vref > 6.144)
throw std::runtime_error(std::string(__FUNCTION__) + " : vref out of range");
UPM_THROW("vref out of range");
else if (vref > 4.096)
setGain(GAIN_TWOTHIRDS);
else if (vref > 2.048)
@ -57,6 +57,12 @@ ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
ADS1015::~ADS1015(){};
const char*
ADS1015::getModuleName() {
return m_name.c_str();
}
unsigned int
ADS1015::getNumInputs() {
return 4;
@ -67,7 +73,7 @@ ADS1015::getResolutionInBits() {
return 12;
}
unsigned int
uint16_t
ADS1015::getRawValue(unsigned int input) {
ADS1X15::ADSMUXMODE mode = getMuxMode(input);
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
@ -157,7 +163,7 @@ ADS1015::getMuxMode(unsigned int input) {
case 3:
return SINGLE_3;
default:
throw std::runtime_error(std::string(__FUNCTION__) + " : Invalid input");
UPM_THROW("Invalid input");
}
}

View File

@ -26,7 +26,7 @@
#pragma once
#include "ads1x15.hpp"
#include "iADC.hpp"
#include "interfaces/iADC.hpp"
#define ADS1015_VREF 2.048
@ -54,63 +54,63 @@
/*=========================================================================*/
namespace upm {
/**
* @library ads1x15
* @sensor ADS1015
* @comname 12-bit ADC with Integrated MUX, PGA, Comparator, Oscillator, and Reference
* @type electric
* @man ti adafruit
* @con i2c
* @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 deg C to +125 deg C.
*
* Tested with Adafriut ADS1015 board: https://www.adafruit.com/products/1083
*
* @image html ads1015.jpg
* @snippet ads1x15.cxx Interesting
* @snippet ads1x15-ads1015.cxx Interesting
* @snippet ads1x15-adc-sensor.cxx Interesting
*/
class ADS1015 : public ADS1X15, public iADC {
/**
* @library ads1x15
* @sensor ADS1015
* @comname 12-bit ADC with Integrated MUX, PGA, Comparator, Oscillator, and Reference
* @type electric
* @man ti adafruit
* @con i2c
* @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 deg C to +125 deg C.
*
* Tested with Adafriut ADS1015 board: https://www.adafruit.com/products/1083
*
* @image html ads1015.jpg
* @snippet ads1x15.cxx Interesting
* @snippet ads1x15-ads1015.cxx Interesting
* @snippet ads1x15-adc-sensor.cxx Interesting
*/
class ADS1015 : public ADS1X15, public IADC {
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;
/**
* @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;
/**
@ -130,9 +130,6 @@ namespace upm {
*/
~ADS1015 ();
virtual std::string Name() {return "ADS1015";}
virtual std::string Description() {return "12-bit ADC with integrated MUX, PGA, comparator, oscillator, and reference";}
/**
* Sets the sample rate of the device. This function
* needs to be overridden in subclasses as the ADS1115 and
@ -154,7 +151,7 @@ namespace upm {
*
* @return current conversion value
*/
unsigned int getRawValue(unsigned int input);
uint16_t getRawValue(unsigned int input);
/**
* Read current voltage for current single ended analogue input
@ -170,6 +167,14 @@ namespace upm {
*/
unsigned int getResolutionInBits();
/**
* Returns module name
*
* @return modulename as const char*
*/
const char* getModuleName();
protected:
float getMultiplier(void);
void setDelay(void);

View File

@ -1,12 +1,28 @@
%include "../common_top.i"
%include "iADC.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%import "../interfaces/javaupm_iADC.i"
%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%}
JAVA_JNI_LOADLIBRARY(javaupm_ads1x15)
#endif
/* END Java syntax */
/* BEGIN Javascript syntax ------------------------------------------------- */
#ifdef SWIGJAVASCRIPT
%include "iModuleStatus.hpp"
%include "iADC.hpp"
#endif
/* END Javascript syntax */
/* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON
%include "iModuleStatus.hpp"
%include "iADC.hpp"
#endif
/* END Python syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%{
#include "ads1x15.hpp"

8
src/bh1749/CMakeLists.txt Executable file
View File

@ -0,0 +1,8 @@
upm_mixed_module_init (NAME bh1749
DESCRIPTION "ROHM Color Sensor"
C_HDR bh1749.h bh1749_registers.h
C_SRC bh1749.c
CPP_HDR bh1749.hpp
CPP_SRC bh1749.cxx
CPP_WRAPS_C
REQUIRES mraa)

702
src/bh1749/bh1749.c Executable file
View File

@ -0,0 +1,702 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include "bh1749.h"
#define DEFAULT_OP_MODE INT_JUDGE_1
#define DEFAULT_MEAS_TIME MEAS_240MS
#define DEFAULT_RGB_GAIN RGB_GAIN_1X
#define DEFAULT_IR_GAIN IR_GAIN_1X
#define DEFAULT_INT_SOURCE RED
#define DEFUALT_THRESHOLD_HIGH 511
/**
* @brief Reads the value of a register
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save register value
* @return UPM result
*/
static upm_result_t bh1749_read_register(bh1749_context dev, uint8_t reg, uint8_t *data)
{
uint8_t value = mraa_i2c_read_byte_data(dev->i2c, reg);
if(value < 0) {
printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
*data = value;
return UPM_SUCCESS;
}
/**
* @brief Reads the values of a set of registers
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save registers values
* @return UPM result
*/
static upm_result_t bh1749_read_registers(bh1749_context dev, uint8_t reg, uint8_t *data, uint8_t len)
{
uint8_t value;
for(int i = 0; i < len; i++) {
if(bh1749_read_register(dev, reg + i, &value) != UPM_SUCCESS) {
return UPM_ERROR_OPERATION_FAILED;
}
*(data + i) = value;
}
return UPM_SUCCESS;
}
/**
* @brief Writes a value to a register
*
* @param dev The sensor context
* @param value Value to write
* @param reg Register address
* @return UPM result
*/
static upm_result_t bh1749_write_register(bh1749_context dev, uint8_t value, uint8_t reg)
{
if (mraa_i2c_write_byte_data(dev->i2c, value, reg) != MRAA_SUCCESS) {
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
/**
* @brief Sets a bit on in a register with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1749_set_bit_on(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value |= bit_mask;
return bh1749_write_register(dev, reg_value, reg);
}
/**
* @brief Sets a bit off in a register with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1749_set_bit_off(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
return bh1749_write_register(dev, reg_value, reg);
}
/**
* @brief Sets the value of a register as a given pattern with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param value Value to write
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1749_set_bits_with_mask(bh1749_context dev, uint8_t reg, uint8_t value, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
reg_value |= value;
return bh1749_write_register(dev, reg_value, reg);
}
upm_result_t bh1749_check_who_am_i(bh1749_context dev)
{
uint8_t partId;
if(bh1749_read_register(dev, BH1749_SYSTEM_CONTROL, &partId) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
partId &= BH1749_SYSTEM_CONTROL_PART_MASK;
if(partId != BH1749_SYSTEM_CONTROL_PART_ID) {
printf("%s: wrong manufacturer ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
bh1749_context bh1749_init(int bus, int addr)
{
bh1749_context dev = (bh1749_context)malloc(sizeof(struct _bh1749_context));
if (!dev)
return NULL;
dev->i2c = NULL;
dev->interrupt = NULL;
if (mraa_init() != MRAA_SUCCESS) {
printf("%s: mraa_init() failed.\n", __FUNCTION__);
bh1749_close(dev);
return NULL;
}
if (!(dev->i2c = mraa_i2c_init(bus))) {
printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__);
bh1749_close(dev);
return NULL;
}
if (mraa_i2c_address(dev->i2c, addr)) {
printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__);
bh1749_close(dev);
return NULL;
}
if(bh1749_check_who_am_i(dev) != UPM_SUCCESS)
return NULL;
dev->enabled = false;
dev->isrEnabled = false;
if(bh1749_sensor_init(dev, DEFAULT_OP_MODE, DEFAULT_MEAS_TIME,
DEFAULT_RGB_GAIN, DEFAULT_IR_GAIN, DEFAULT_INT_SOURCE) != UPM_SUCCESS)
return NULL;
bh1749_set_threshold_high(dev, DEFUALT_THRESHOLD_HIGH);
return dev;
}
void bh1749_close(bh1749_context dev)
{
if(dev->isrEnabled)
bh1749_remove_isr(dev);
if (dev->i2c)
mraa_i2c_stop(dev->i2c);
free(dev);
}
upm_result_t bh1749_enable(bh1749_context dev)
{
int status;
status = bh1749_set_bit_on(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_enable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = true;
return UPM_SUCCESS;
}
upm_result_t bh1749_disable(bh1749_context dev)
{
int status;
status = bh1749_set_bit_off(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_disable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = false;
return UPM_SUCCESS;
}
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
{
if(bh1749_set_operating_mode(dev, opMode) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_measurement_time(dev, measTime) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_rgb_gain(dev, rgbGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_ir_gain(dev, irGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_set_int_source(dev, intSource);
}
upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMode)
{
if(bh1749_write_register(dev, opMode, BH1749_PERSISTENCE) != UPM_SUCCESS) {
printf("%s: Setting operating mode failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->operating_mode = opMode;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_operating_mode(bh1749_context dev, uint8_t *opMode)
{
uint8_t value;
if(bh1749_read_register(dev, BH1749_PERSISTENCE, &value) != UPM_SUCCESS) {
printf("%s: Failed to read operating mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
value &= BH1749_PERSISTENCE_MODE_MASK;
if(value != INT_JUDGE_0 && value != INT_JUDGE_1 &&
value != INT_JUDGE_4 && value != INT_JUDGE_4) {
printf("%s: Returned invalid mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
*opMode = value;
return UPM_SUCCESS;
}
upm_result_t bh1749_set_measurement_time(bh1749_context dev, MEAS_TIMES measTime)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, measTime,
BH1749_MODE_CONTROL1_ODR_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->meas_time = measTime;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_measurement_time(bh1749_context dev, uint8_t *meas_time)
{
uint8_t time_reg;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &time_reg) != UPM_SUCCESS) {
printf("%s: Failed to read measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
time_reg &= BH1749_MODE_CONTROL1_ODR_MASK;
if(time_reg == MEAS_35MS)
*meas_time = 35;
else if(time_reg == MEAS_120MS)
*meas_time = 120;
else if(time_reg == MEAS_240MS)
*meas_time = 240;
else {
printf("%s: Returned invalid time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, rgbGain,
BH1749_MODE_CONTROL1_RGB_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting RGB gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->rgb_gain = rgbGain;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_rgb_gain(bh1749_context dev, uint8_t *gain)
{
uint8_t rgb_gain;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &rgb_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
rgb_gain &= BH1749_MODE_CONTROL1_RGB_GAIN_MASK;
if(rgb_gain == RGB_GAIN_1X)
*gain = 1;
else if(rgb_gain == RGB_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, irGain,
BH1749_MODE_CONTROL1_IR_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting IR gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->ir_gain = irGain;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_ir_gain(bh1749_context dev, uint8_t *gain)
{
uint8_t ir_gain;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &ir_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
ir_gain &= BH1749_MODE_CONTROL1_IR_GAIN_MASK;
if(ir_gain == IR_GAIN_1X)
*gain = 1;
else if(ir_gain == IR_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource)
{
if(bh1749_set_bits_with_mask(dev, BH1749_INTERRUPT, intSource,
BH1749_INTERRUPT_SOURCE_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting interrupt source gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_src = intSource;
return UPM_SUCCESS;
}
char bh1749_get_interrupt_source_char(bh1749_context dev)
{
char intSourceChar = ' ';
uint8_t intSource;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intSource) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt source\n", __FUNCTION__);
return intSourceChar;
}
intSource &= BH1749_INTERRUPT_SOURCE_MASK;
if(intSource == RED)
intSourceChar = 'r';
else if(intSource == GREEN)
intSourceChar = 'g';
else if(intSource == BLUE)
intSourceChar = 'b';
else {
printf("%s: Returned invalid interrupt source\n", __FUNCTION__);
return intSourceChar;
}
return intSourceChar;
}
upm_result_t bh1749_enable_interrupt(bh1749_context dev)
{
if(bh1749_set_bit_on(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_reset_interrupt(dev);
}
upm_result_t bh1749_disable_interrupt(bh1749_context dev)
{
return bh1749_set_bit_off(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK);
}
upm_result_t bh1749_reset_interrupt(bh1749_context dev)
{
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_INT_RESET);
}
bool bh1749_is_interrupted(bh1749_context dev)
{
uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt status\n", __FUNCTION__);
return false;
}
intStatus &= BH1749_INTERRUPT_STATUS_MASK;
if(intStatus != BH1749_INTERRUPT_STATUS_ACTIVE)
return false;
return true;
}
bool bh1749_is_interrupt_enabled(bh1749_context dev)
{
uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt enabled\n", __FUNCTION__);
return false;
}
intStatus &= BH1749_INTERRUPT_EN_MASK;
if(intStatus != BH1749_INTERRUPT_EN_ENABLE)
return false;
return true;
}
upm_result_t bh1749_soft_reset(bh1749_context dev)
{
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_SW_RESET_MASK);
}
upm_result_t bh1749_set_threshold_high(bh1749_context dev, uint16_t threshold)
{
if(bh1749_write_register(dev, threshold, BH1749_TH_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TH_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write high threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thh = threshold;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_threshold_high(bh1749_context dev, uint16_t *threshold)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_TH_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TH_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold)
{
if(bh1749_write_register(dev, threshold, BH1749_TL_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TL_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write low threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thl = threshold;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_threshold_low(bh1749_context dev, uint16_t *threshold)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_TL_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TL_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_red(bh1749_context dev, uint16_t *red)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_RED_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_RED_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*red = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_green(bh1749_context dev, uint16_t *green)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_GREEN_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*green = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_blue(bh1749_context dev, uint16_t *blue)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_BLUE_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_BLUE_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*blue = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_ir(bh1749_context dev, uint16_t *ir)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_IR_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_IR_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*ir = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_green2(bh1749_context dev, uint16_t *green2)
{
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_GREEN2_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN2_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*green2 = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result)
{
uint16_t value;
int step = 0;
if(bh1749_get_red(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_blue(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_ir(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green2(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
return UPM_SUCCESS;
}
upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int pin,
void (*isr)(void *), void *isr_args)
{
if(dev->isrEnabled)
bh1749_remove_isr(dev);
mraa_gpio_context isr_gpio = NULL;
if (!(isr_gpio = mraa_gpio_init(pin))) {
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
mraa_gpio_dir(isr_gpio, MRAA_GPIO_IN);
if (mraa_gpio_isr(isr_gpio, edge, isr, isr_args) != MRAA_SUCCESS) {
mraa_gpio_close(isr_gpio);
printf("%s: mraa_gpio_isr() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->interrupt = isr_gpio;
dev->isrEnabled = true;
return UPM_SUCCESS;
}
void bh1749_remove_isr(bh1749_context dev)
{
mraa_gpio_isr_exit(dev->interrupt);
mraa_gpio_close(dev->interrupt);
dev->interrupt = NULL;
dev->isrEnabled = false;
}
upm_result_t bh1749_registers_dump(bh1749_context dev, char *dump)
{
uint8_t reg_values[10];
int count = 0;
int len = 3;
if(bh1749_read_registers(dev, BH1749_SYSTEM_CONTROL, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump, "0x40 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
sprintf(dump + count - 1, "\n");
len = 6;
if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump + count, "0x60 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
return UPM_SUCCESS;
}

304
src/bh1749/bh1749.cxx Executable file
View File

@ -0,0 +1,304 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 "bh1749.hpp"
using namespace upm;
void BH1749::CheckWhoAmI()
{
if(bh1749_check_who_am_i(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_check_who_am_i() failed");
}
BH1749::BH1749(int bus, int addr) : m_bh1749(bh1749_init(bus, addr))
{
if(!m_bh1749)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_init() failed");
}
BH1749::~BH1749()
{
bh1749_close(m_bh1749);
}
void BH1749::Enable()
{
if(bh1749_enable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable() failed");
}
void BH1749::Disable()
{
if(bh1749_disable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable() failed");
}
void BH1749::SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
{
if(bh1749_sensor_init(m_bh1749, opMode, measTime, rgbGain, irGain, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_sensor_init() failed");
}
void BH1749::SetOperatingMode(OPERATING_MODES opMode)
{
if(bh1749_set_operating_mode(m_bh1749, opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_operating_mode() failed");
}
int BH1749::GetOperatingMode()
{
uint8_t opMode;
if(bh1749_get_operating_mode(m_bh1749, &opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_operating_mode() failed");
return opMode;
}
void BH1749::SetMeasurementTime(MEAS_TIMES measTime)
{
if(bh1749_set_measurement_time(m_bh1749, measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_measurement_time() failed");
}
int BH1749::GetMeasurementTime()
{
uint8_t measTime;
if(bh1749_get_measurement_time(m_bh1749, &measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurement_time() failed");
return measTime;
}
void BH1749::SetRgbGain(RGB_GAINS rgbGain)
{
if(bh1749_set_rgb_gain(m_bh1749, rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_rgb_gain() failed");
}
int BH1749::GetRgbGain()
{
uint8_t rgbGain;
if(bh1749_get_rgb_gain(m_bh1749, &rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_rgb_gain() failed");
return rgbGain;
}
void BH1749::SetIrGain(IR_GAINS irGain)
{
if(bh1749_set_ir_gain(m_bh1749, irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_ir_gain() failed");
}
int BH1749::GetIrGain()
{
uint8_t irGain;
if(bh1749_get_ir_gain(m_bh1749, &irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir_gain() failed");
return irGain;
}
void BH1749::SetIntSource(INT_SOURCES intSource)
{
if(bh1749_set_int_source(m_bh1749, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_int_source() failed");
}
char BH1749::GetInterruptSourceChar()
{
char intSource = bh1749_get_interrupt_source_char(m_bh1749);
if( intSource == ' ')
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_interrupt_source_char() failed");
return intSource;
}
void BH1749::EnableInterrupt()
{
if(bh1749_enable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable_interrupt() failed");
}
void BH1749::DisableInterrupt()
{
if(bh1749_disable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable_interrupt() failed");
}
void BH1749::ResetInterrupt()
{
if(bh1749_reset_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_reset_interrupt() failed");
}
bool BH1749::IsInterrupted()
{
return bh1749_is_interrupted(m_bh1749);
}
bool BH1749::IsInterruptEnabled()
{
return bh1749_is_interrupt_enabled(m_bh1749);
}
void BH1749::SoftReset()
{
if(bh1749_soft_reset(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_soft_reset() failed");
}
void BH1749::SetThresholdHigh(uint16_t threshold)
{
if(bh1749_set_threshold_high(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_high() failed");
}
int BH1749::GetThresholdHigh()
{
uint16_t threhold;
if(bh1749_get_threshold_high(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_high() failed");
return threhold;
}
void BH1749::SetThresholdLow(uint16_t threshold)
{
if(bh1749_set_threshold_low(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_low() failed");
}
int BH1749::GetThresholdLow()
{
uint16_t threhold;
if(bh1749_get_threshold_low(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_low() failed");
return threhold;
}
uint16_t BH1749::GetRed()
{
uint16_t red;
if(bh1749_get_red(m_bh1749, &red) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_red() failed");
return red;
}
uint16_t BH1749::GetGreen()
{
uint16_t green;
if(bh1749_get_green(m_bh1749, &green) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green() failed");
return green;
}
uint16_t BH1749::GetBlue()
{
uint16_t blue;
if(bh1749_get_blue(m_bh1749, &blue) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_blue() failed");
return blue;
}
uint16_t BH1749::GetIr()
{
uint16_t ir;
if(bh1749_get_ir(m_bh1749, &ir) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir() failed");
return ir;
}
uint16_t BH1749::GetGeen2()
{
uint16_t green2;
if(bh1749_get_green2(m_bh1749, &green2) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green2() failed");
return green2;
}
std::vector<uint16_t> BH1749::GetMeasurements()
{
uint16_t res[5];
if(bh1749_get_measurements(m_bh1749, res) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurements() failed");
std::vector<uint16_t> result(res, res + sizeof res / sizeof res[0]);
return result;
}
void BH1749::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
{
if(bh1749_install_isr(m_bh1749, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_install_isr() failed");
}
void BH1749::RemoveISR()
{
bh1749_remove_isr(m_bh1749);
}
std::string BH1749::RegistersDump()
{
char dump[255];
std::string dumpStr;
if(bh1749_registers_dump(m_bh1749, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_registers_dump() failed");
dumpStr = dump;
return dumpStr;
}

429
src/bh1749/bh1749.h Executable file
View File

@ -0,0 +1,429 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include <mraa/i2c.h>
#include <mraa/gpio.h>
#include <unistd.h>
#include <upm_types.h>
#include "bh1749_registers.h"
/**
* @file bh1749.h
* @library bh1749
* @brief C API for the bh1749 driver
*
* @include bh1749.c
*/
/**
* @brief Operation modes enum for interrupt modes (persistance)
*/
typedef enum {
INT_JUDGE_0 = BH1749_PERSISTENCE_MODE_STATUS_ACTIVE_AFTER_MEASUREMENT,
INT_JUDGE_1 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_MEASUREMENT,
INT_JUDGE_4 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_4_SAME,
INT_JUDGE_8 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_8_SAME,
} OPERATING_MODES;
/**
* @brief Measuremnt time choices
*/
typedef enum {
MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6,
MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333,
MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167
} MEAS_TIMES;
/**
* @brief RGB gain choices
*/
typedef enum {
RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X,
RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X
} RGB_GAINS;
/**
* @brief IR gain choices
*/
typedef enum {
IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X,
IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X
} IR_GAINS;
/**
* @brief Interrupt source choices
*/
typedef enum {
RED = BH1749_INTERRUPT_SOURCE_SELECT_RED,
GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN,
BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE
} INT_SOURCES;
/**
* @brief The full sensor context
*/
typedef struct _bh1749_context
{
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
uint16_t int_thh;
uint16_t int_thl;
INT_SOURCES int_src;
IR_GAINS ir_gain;
RGB_GAINS rgb_gain;
MEAS_TIMES meas_time;
OPERATING_MODES operating_mode;
} *bh1749_context;
/**
* @brief Check "who am I" register value to identify the sensor
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_check_who_am_i(bh1749_context dev);
/**
* @brief Init the sensor with specific bus and address. This function calls
* the sensor_init() function to set default values for operating mode, gains,
* measurement time, interrupt source and then sets threshold high to 511.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @return context of initialized sensor
*/
bh1749_context bh1749_init(int bus, int addr);
/**
* @brief Close and free sensor context
*
* @param dev Sensor context
*/
void bh1749_close(bh1749_context dev);
/**
* @brief Enables RGB color measurement on the sensor
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_enable(bh1749_context dev);
/**
* @brief Disables RGB color measurement on the sensor
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_disable(bh1749_context dev);
/**
* @brief Initializes (writes) configuration values to sensor
*
* @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES enum
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @param irGain IR gain choice, a value of IR_GAINS enum
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @return UPM result
*/
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
/**
* @brief Sets operating mode (interrupt persistance)
*
* @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @return UPM result
*/
upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMode);
/**
* @brief Gets operating mode (interrupt persistance) value
*
* @param dev Sensor context
* @param opMode pointer (uint8_t) to save value
* @return UPM result
*/
upm_result_t bh1749_get_operating_mode(bh1749_context dev, uint8_t *opMode);
/**
* @brief Sets measurement time (ODR)
*
* @param dev Sensor context
* @param measTime measurement time choice, a value of MEAS_TIMES enum
* @return UPM result
*/
upm_result_t bh1749_set_measurement_time(bh1749_context dev, MEAS_TIMES measTime);
/**
* @brief Sets measurement time (ODR)
*
* @param dev Sensor context
* @param meas_time pointer (uint8_t) to save value
* @return UPM result
*/
upm_result_t bh1749_get_measurement_time(bh1749_context dev, uint8_t *meas_time);
/**
* @brief Sets RGB gain values
*
* @param dev Sensor context
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @return UPM result
*/
upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain);
/**
* @brief Gets RGB gain value
*
* @param dev Sensor context
* @param gain pointer (uint8_t) to save value
* @return UPM result
*/
upm_result_t bh1749_get_rgb_gain(bh1749_context dev, uint8_t *gain);
/**
* @brief Sets IR gain values
*
* @param dev Sensor context
* @param irGain IR gain choice, a value of IR_GAINS enum
* @return UPM result
*/
upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain);
/**
* @brief Gets IR gain value
*
* @param dev Sensor context
* @param gain pointer (uint8_t) to save value
* @return UPM result
*/
upm_result_t bh1749_get_ir_gain(bh1749_context dev, uint8_t *gain);
/**
* @brief Sets interrupt source value
*
* @param dev Sensor context
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @return UPM result
*/
upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource);
/**
* @brief Gets interrupt source value
*
* @param dev Sensor context
* @return character of interrupt source
*/
char bh1749_get_interrupt_source_char(bh1749_context dev);
/**
* @brief Enables interrupt mode and resets the interrupt status (clear)
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_enable_interrupt(bh1749_context dev);
/**
* @brief Disables interrupt mode
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_disable_interrupt(bh1749_context dev);
/**
* @brief Resets interrupt status (clear) to allow new interrupts
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_reset_interrupt(bh1749_context dev);
/**
* @brief Checks the status of the interrupt
*
* @param dev Sensor context
* @return true if there is interrupt, otherwise false
*/
bool bh1749_is_interrupted(bh1749_context dev);
/**
* @brief Checks whether interrupt mode is enabled
*
* @param dev Sensor context
* @return true if interrupt is enabled, otherwise false
*/
bool bh1749_is_interrupt_enabled(bh1749_context dev);
/**
* @brief Initiates a software reset to the sensor. All register values will
* be written to their defaults, thus sensor_init() must be called after this,
* and thresholds also needs to be set.
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_soft_reset(bh1749_context dev);
/**
* @brief Sets interrupt threshold high value
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
*/
upm_result_t bh1749_set_threshold_high(bh1749_context dev, uint16_t threshold);
/**
* @brief Gets interrupt threshold high value
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_threshold_high(bh1749_context dev, uint16_t *threshold);
/**
* @brief Sets interrupt threshold low value
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
*/
upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold);
/**
* @brief Gets interrupt threshold low value
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_threshold_low(bh1749_context dev, uint16_t *threshold);
/**
* @brief Gets value of Red color channel
*
* @param dev Sensor context
* @param red Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_red(bh1749_context dev, uint16_t *red);
/**
* @brief Gets value of Green color channel
*
* @param dev Sensor context
* @param green Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_green(bh1749_context dev, uint16_t *green);
/**
* @brief Gets value of Blue color channel
*
* @param dev Sensor context
* @param blue Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_blue(bh1749_context dev, uint16_t *blue);
/**
* @brief Gets value of IR color channel
*
* @param dev Sensor context
* @param ir Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_ir(bh1749_context dev, uint16_t *ir);
/**
* @brief Gets value of Green2 color channel
*
* @param dev Sensor context
* @param green Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1749_get_green2(bh1749_context dev, uint16_t *green2);
/**
* @brief Gets all channels measurements values
*
* @param dev Sensor context
* @param result Pointer of uint16_t to write all values ordered as:
* Red, Green, Blue, IR, Green2
*
* @return UPM result
*/
upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @return UPM result
*/
upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int pin,
void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*
* @param dev Sensor context
*/
void bh1749_remove_isr(bh1749_context dev);
/**
* @brief Gets a dump of configuration registers as a string
*
* @param dev Sensor context
* @param dump Pointer of char to save dump string
* @return UPM result
*/
upm_result_t bh1749_registers_dump(bh1749_context dev, char *dump);
#ifdef __cplusplus
}
#endif

345
src/bh1749/bh1749.hpp Executable file
View File

@ -0,0 +1,345 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <vector>
#include "bh1749.h"
/**
* @brief BH1749 Color Sensor
* @defgroup bh1749 libupm-bh1749
* @ingroup rohm i2c color
*/
/**
* @library bh1749
* @sensor bh1749
* @comname Color Sensor
* @type color sensor
* @man rohm
* @con i2c
*
* @brief C++ API wrapper for the bh1749 driver
*
* @snippet bh1749.cxx Interesting
*/
namespace upm {
class BH1749 {
public:
/**
* @brief Initialize a sensor instance with bus and address.
*
* This calls SensorInit() to set default values for operating mode,
* gains, measurement time, interrupt source and then sets threshold
* high to 511.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1749(int bus = 0, int addr = 0x39);
/**
* @brief Close and free sensor
*/
virtual ~BH1749();
/**
* @brief Enables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_enable() fails
*/
void Enable();
/**
* @brief Disables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_disable() fails
*/
void Disable();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Initializes (writes) configuration values to sensor
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES enum
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @param irGain IR gain choice, a value of IR_GAINS enum
* @param intSource interrupt source choice, a value of INT_SOURCES enum
*
* @throws std::runtime_error if one of values setting fails
*/
void SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
/**
* @brief Sets operating mode (interrupt persistance)
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @throws std::runtime_error if writing value fails
*/
void SetOperatingMode(OPERATING_MODES opMode);
/**
* @brief Gets operating mode (interrupt persistance) value
*
* @param opMode pointer (uint8_t) to save value
* @return operating mode value
* @throws std::runtime_error if reading the value fails
*/
int GetOperatingMode();
/**
* @brief Sets measurement time (ODR)
*
* @param measTime measurement time choice, a value of MEAS_TIMES enum
* @throws std::runtime_error if writing value fails
*/
void SetMeasurementTime(MEAS_TIMES measTime);
/**
* @brief Gets measurement time (ODR) value
*
* @return measurement time value
* @throws std::runtime_error if reading the value fails
*/
int GetMeasurementTime();
/**
* @brief Sets RGB gain value
*
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetRgbGain(RGB_GAINS rgbGain);
/**
* @brief Gets RGB gain value
*
* @return RGB gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetRgbGain();
/**
* @brief Sets IR gain value
*
* @param irGain IR gain choice, a value of IR_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetIrGain(IR_GAINS irGain);
/**
* @brief Gets IR gain value
*
* @return IR gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetIrGain();
/**
* @brief Sets interrupt source value
*
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @throws std::runtime_error if writing value fails
*/
void SetIntSource(INT_SOURCES intSource);
/**
* @brief Gets interrupt source value
*
* @return interrupt source value
* @throws std::runtime_error if reading the value fails
*/
char GetInterruptSourceChar();
/**
* @brief Enables interrupt mode
*
* @throws std::runtime_error if writing enable bit fails
*/
void EnableInterrupt();
/**
* @brief Disables interrupt mode
*
* @throws std::runtime_error if writing disable bit fails
*/
void DisableInterrupt();
/**
* @brief Resets interrupt status (clear) to allow new interrupt reads
*
* @throws std::runtime_error if writing reset bit fails
*/
void ResetInterrupt();
/**
* @brief Gets interrupt status, whether interrupt is raised or not
*
* @return true if interrupt is raised, otherwise false
*/
bool IsInterrupted();
/**
* @brief Gets interrupt mode status
*
* @return true if interrupt is enabled, otherwise false
*/
bool IsInterruptEnabled();
/**
* @brief Initiates a software reset to the sensor. All register values
* will be written to their defaults, thus sensor_init() must be called
* after this, and thresholds also needs to be set.
*
* @throws std::runtime_error if writing reset bit fails
*/
void SoftReset();
/**
* @brief Sets threshold high value
*
* @param threshold interrupt threshold high value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdHigh(uint16_t threshold);
/**
* @brief Gets threshold high value
*
* @return threshold high value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdHigh();
/**
* @brief Sets threshold low value
*
* @param threshold interrupt threshold low value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdLow(uint16_t threshold);
/**
* @brief Gets threshold low value
*
* @return threshold low value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdLow();
/**
* @brief Gets value of Red color channel
*
* @return red channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetRed();
/**
* @brief Gets value of Green color channel
*
* @return green channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGreen();
/**
* @brief Gets value of Blue color channel
*
* @return blue channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetBlue();
/**
* @brief Gets value of IR color channel
*
* @return ir channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetIr();
/**
* @brief Gets value of Green2 color channel
*
* @return green2 channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGeen2();
/**
* @brief Gets all channels measurements values
*
* @return vector with all channels values ordered as:
* Red, Green, Blue, IR, Green2
* @throws std::runtime_error if reading one of the values fails
*/
std::vector<uint16_t> GetMeasurements();
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
private:
bh1749_context m_bh1749;
/* Disable implicit copy and assignment operators */
BH1749(const BH1749 &) = delete;
BH1749 &operator=(const BH1749 &) = delete;
};
}

View File

@ -1,17 +1,18 @@
%include "../common_top.i"
%include "iMraa.i"
%include "iLightSensor.i"
%include "iTemperatureSensor.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
JAVA_JNI_LOADLIBRARY(javaupm_noelstemplightreader)
JAVA_JNI_LOADLIBRARY(javaupm_bh1749)
#endif
/* END Java syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%include "std_vector.i"
%template(uint16Vector) std::vector<uint16_t>;
%{
#include "noelstemplightreader.hpp"
#include "bh1749.hpp"
%}
%include "noelstemplightreader.hpp"
%include "bh1749.h"
%include "bh1749.hpp"
/* END Common SWIG syntax */

49
src/bh1749/bh1749.json Executable file
View File

@ -0,0 +1,49 @@
{
"Library": "BH1749",
"Description": "ROHM BH1749 Color sensor (16-bit) library",
"Sensor Class": {
"BH1749": {
"Name": "ROHM BH1749 Color sensor (16-bit)",
"Description": "BH1749NUC is a digital color sensor IC with I2C bus interface. This IC senses Red, Green, Blue (RGB) and Infrared and converts them to digital values. The high sensitivity, wide dynamic range and excellent Ircut characteristics make it possible for this IC to obtain the accurate illuminance and color temperature of ambient light. It is ideal for adjusting LCD backlight of TV, mobile phone and tablet PC.",
"Categories": ["color sensor"],
"Connections": ["i2c"],
"Project Type": ["prototyping", "commercial"],
"Manufacturers": ["ROHM"],
"Examples": {
"C++": ["bh1749.cxx"],
"C": ["bh1749.c"],
"Java": ["BH1749_Example.java"],
"Python": ["bh1749.py"],
"Node.js": ["bh1749.js"]
},
"Specifications": {
"Supply Voltage (VDD)": {
"unit": "V",
"min": 2.3,
"max": 3.6
},
"Supply Current": {
"unit": "uA",
"min": 0.8,
"max": 190
},
"Operating Temperature": {
"unit": "°C",
"min": -40,
"max": 85
}, "Illumination Detection": {
"unit" : "klx",
"value": 80
}
},
"Urls": {
"Product Pages": [
"https://www.rohm.com/products/sensors-mems/color-sensor-ics/bh1745nuc-product"
],
"Datasheets": [
"https://www.rohm.com/datasheet/BH1749NUC/bh1749nuc-e"
]
}
}
}
}

160
src/bh1749/bh1749_registers.h Executable file
View File

@ -0,0 +1,160 @@
/*
The MIT License (MIT)
Copyright (c) 2017 Rohm Semiconductor
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __BH1749_REGISTERS_H__
#define __BH1749_REGISTERS_H__
/* registers */
#define BH1749_REGISTER_DUMP_START 0x40
#define BH1749_SYSTEM_CONTROL 0x40
#define BH1749_MODE_CONTROL1 0x41
#define BH1749_MODE_CONTROL2 0x42
// Least significant byte of uint16 RED measurement value
#define BH1749_RED_DATA_LSBS 0x50
// Most significant byte of uint16 RED measurement value
#define BH1749_RED_DATA_MSBS 0x51
// Least significant byte of uint16 GREEN measurement value
#define BH1749_GREEN_DATA_LSBS 0x52
// Most significant byte of uint16 GREEN measurement value
#define BH1749_GREEN_DATA_MSBS 0x53
// Least significant byte of uint16 BLUE measurement value
#define BH1749_BLUE_DATA_LSBS 0x54
// Most significant byte of uint16 BLUE measurement value
#define BH1749_BLUE_DATA_MSBS 0x55
// Least significant byte of uint16 IR measurement value
#define BH1749_IR_DATA_LSBS 0x58
// Most significant byte of uint16 IR measurement value
#define BH1749_IR_DATA_MSBS 0x59
// Least significant byte of uint16 GREEN2 measurement value
#define BH1749_GREEN2_DATA_LSBS 0x5A
// Most significant byte of uint16 GREEN2 measurement value
#define BH1749_GREEN2_DATA_MSBS 0x5B
// Interrupt control register
#define BH1749_INTERRUPT 0x60
// Interrupt status update control register
#define BH1749_PERSISTENCE 0x61
// Least significant byte of interrupt threshold high level
#define BH1749_TH_LSBS 0x62
// Most significant byte of interrupt threshold high level
#define BH1749_TH_MSBS 0x63
// Least significant byte of interrupt threshold low level
#define BH1749_TL_LSBS 0x64
// Most significant byte of interrupt threshold low level
#define BH1749_TL_MSBS 0x65
#define BH1749_ID_REG 0x92
#define BH1749_REGISTER_DUMP_END 0x92
/* registers bits */
// Software reset is not done
#define BH1749_SYSTEM_CONTROL_SW_RESET_NOT_DONE (0x00 << 7)
// Software reset is done
#define BH1749_SYSTEM_CONTROL_SW_RESET_DONE (0x01 << 7)
// INT pin status is not changed
#define BH1749_SYSTEM_CONTROL_INT_NO_ACTION (0x00 << 6)
// INT pin becomes inactive (high impedance)
#define BH1749_SYSTEM_CONTROL_INT_RESET (0x01 << 6)
#define BH1749_SYSTEM_CONTROL_PART_ID (0x0D << 0)
#define BH1749_MODE_CONTROL1_RESERVED7_WRITE0 (0x00 << 7)
#define BH1749_MODE_CONTROL1_IR_GAIN_RESERVED0 (0x00 << 5)
#define BH1749_MODE_CONTROL1_IR_GAIN_1X (0x01 << 5)
#define BH1749_MODE_CONTROL1_IR_GAIN_RESERVED1 (0x02 << 5)
#define BH1749_MODE_CONTROL1_IR_GAIN_32X (0x03 << 5)
#define BH1749_MODE_CONTROL1_RGB_GAIN_RESERVED0 (0x00 << 3)
#define BH1749_MODE_CONTROL1_RGB_GAIN_1X (0x01 << 3)
#define BH1749_MODE_CONTROL1_RGB_GAIN_RESERVED1 (0x02 << 3)
#define BH1749_MODE_CONTROL1_RGB_GAIN_32X (0x03 << 3)
// Reserved value
#define BH1749_MODE_CONTROL1_ODR_RESERVED0 (0x00 << 0)
// Reserved value
#define BH1749_MODE_CONTROL1_ODR_RESERVED1 (0x01 << 0)
// 120ms measurement time
#define BH1749_MODE_CONTROL1_ODR_8P333 (0x02 << 0)
// 240ms measurement time
#define BH1749_MODE_CONTROL1_ODR_4P167 (0x03 << 0)
// Reserved value
#define BH1749_MODE_CONTROL1_ODR_RESERVED2 (0x04 << 0)
// 35ms measurement time
#define BH1749_MODE_CONTROL1_ODR_28P6 (0x05 << 0)
// Reserved value
#define BH1749_MODE_CONTROL1_ODR_RESERVED3 (0x06 << 0)
// Reserved value
#define BH1749_MODE_CONTROL1_ODR_RESERVED4 (0x07 << 0)
#define BH1749_MODE_CONTROL2_VALID_NO (0x00 << 7)
#define BH1749_MODE_CONTROL2_VALID_YES (0x01 << 7)
#define BH1749_MODE_CONTROL2_RESERVED65_WRITE00 (0x00 << 5)
#define BH1749_MODE_CONTROL2_RGB_MEASUREMENT_INACTIVE (0x00 << 4)
#define BH1749_MODE_CONTROL2_RGB_MEASUREMENT_ACTIVE (0x01 << 4)
#define BH1749_MODE_CONTROL2_RESERVED30_WRITE0000 (0x00 << 0)
#define BH1749_INTERRUPT_STATUS_INACTIVE (0x00 << 7)
#define BH1749_INTERRUPT_STATUS_ACTIVE (0x01 << 7)
#define BH1749_INTERRUPT_RESERVED64_WRITE000 (0x00 << 4)
// red channel
#define BH1749_INTERRUPT_SOURCE_SELECT_RED (0x00 << 2)
// green channel
#define BH1749_INTERRUPT_SOURCE_SELECT_GREEN (0x01 << 2)
// blue channel
#define BH1749_INTERRUPT_SOURCE_SELECT_BLUE (0x02 << 2)
// Reserved value
#define BH1749_INTERRUPT_SOURCE_RESERVED0 (0x03 << 2)
#define BH1749_INTERRUPT_RESERVED1_WRITE0 (0x00 << 1)
#define BH1749_INTERRUPT_EN_DISABLE (0x00 << 0)
#define BH1749_INTERRUPT_EN_ENABLE (0x01 << 0)
#define BH1749_PERSISTENCE_RESERVED72_WRITE000000 (0x00 << 2)
// Interrupt status becomes active at each measurement end.
#define BH1749_PERSISTENCE_MODE_STATUS_ACTIVE_AFTER_MEASUREMENT (0x00 << 0)
// Interrupt status is updated at each measurement end.
#define BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_MEASUREMENT (0x01 << 0)
// Interrupt status is updated if 4 consecutive threshold judgements are the same
#define BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_4_SAME (0x02 << 0)
// Interrupt status is updated if 8 consecutive threshold judgements are the same
#define BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_8_SAME (0x03 << 0)
// Manufacturer ID
#define BH1749_ID_REG_MANUFACTURER_ID (0xE0 << 0)
/*registers bit masks */
#define BH1749_SYSTEM_CONTROL_SW_RESET_MASK 0x80
#define BH1749_SYSTEM_CONTROL_INT_MASK 0x40
#define BH1749_SYSTEM_CONTROL_PART_MASK 0x3F
#define BH1749_MODE_CONTROL1_RESERVED7_MASK 0x80
#define BH1749_MODE_CONTROL1_IR_GAIN_MASK 0x60
#define BH1749_MODE_CONTROL1_RGB_GAIN_MASK 0x18
#define BH1749_MODE_CONTROL1_ODR_MASK 0x07
// Measurement data update flag. Sets to 0 if MODE_CONTROL1/2 reg,
// MODE_CONTROL2, INTERRUPT, T(H/L)_(LSB/MSB) is written or
// MODE_CONTROL2 read. In specification named as VALID.
#define BH1749_MODE_CONTROL2_VALID_MASK 0x80
#define BH1749_MODE_CONTROL2_RESERVED65_MASK 0x60
#define BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK 0x10
#define BH1749_MODE_CONTROL2_RESERVED30_MASK 0x0F
#define BH1749_INTERRUPT_STATUS_MASK 0x80
#define BH1749_INTERRUPT_RESERVED64_MASK 0x70
#define BH1749_INTERRUPT_SOURCE_MASK 0x0C
// Write 0
#define BH1749_INTERRUPT_RESERVED1_MASK 0x02
#define BH1749_INTERRUPT_EN_MASK 0x01
#define BH1749_PERSISTENCE_RESERVED72_MASK 0xFC
#define BH1749_PERSISTENCE_MODE_MASK 0x03
#define BH1749_ID_REG_MANUFACTURER_MASK 0xFF
#endif

View File

@ -36,7 +36,7 @@ namespace upm {
/**
* @brief BH1750 Light Sensor
* @defgroup bh1750 libupm-bh1750
* @ingroup dfrobot i2c
* @ingroup rohm dfrobot i2c
*/
/**
@ -44,7 +44,7 @@ namespace upm {
* @sensor bh1750
* @comname Digital Light Sensor
* @type light
* @man dfrobot
* @man rohm dfrobot
* @con i2c
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=531
*
@ -63,7 +63,7 @@ namespace upm {
/**
* BH1750 object constructor (Analog mode)
*
* @param bus The I2C bus to use
* @param bus The I2C bus to use
* @param addr The I2C address of the device
* @param mode The mode to start operation under. One of the
* BH1750_OPMODES_T values. The default is the highest precision,

8
src/bh1792/CMakeLists.txt Executable file
View File

@ -0,0 +1,8 @@
upm_mixed_module_init (NAME bh1792
DESCRIPTION "ROHM Color Sensor"
C_HDR bh1792.h bh1792glc_registers.h
C_SRC bh1792.c
CPP_HDR bh1792.hpp
CPP_SRC bh1792.cxx
CPP_WRAPS_C
REQUIRES mraa)

889
src/bh1792/bh1792.c Executable file
View File

@ -0,0 +1,889 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include "bh1792.h"
/**
* @brief Reads the value of a register
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save register value
* @return UPM result
*/
static upm_result_t bh1792_read_register(bh1792_context dev, uint8_t reg,
uint8_t *data);
/**
* @brief Reads the values of a set of registers
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save registers values
* @return UPM result
*/
static upm_result_t bh1792_read_registers(bh1792_context dev, uint8_t reg,
uint8_t *data, uint8_t len);
/**
* @brief Writes a value to a register
*
* @param dev The sensor context
* @param value Value to write
* @param reg Register address
* @return UPM result
*/
static upm_result_t bh1792_write_register(bh1792_context dev, uint8_t value,
uint8_t reg);
/**
* @brief Sets a bit on in a register with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1792_set_bit_on(bh1792_context dev, uint8_t reg,
uint8_t bit_mask);
/**
* @brief Sets a bit off in a register with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1792_set_bit_off(bh1792_context dev, uint8_t reg,
uint8_t bit_mask);
/**
* @brief Sets the value of a register as a given pattern with a bit mask
*
* @param dev The sensor context
* @param reg Register address
* @param value Value to write
* @param bit_mask Mask to use
* @return UPM result
*/
static upm_result_t bh1792_set_bits_with_mask(bh1792_context dev, uint8_t reg,
uint8_t value, uint8_t bit_mask);
/**
* @brief Writes sync bit each 1 second. This function is used in a thread.
*
* @param dev The sensor context
*/
static void *bh1792_sync_measurement(void *args);
/**
* @brief Sets the measurement time for synchronized mode
*
* @param dev The sensor context
* @param meas_mode Measurement mode choice, take a value of MEAS_MODES
* @return UPM result
*/
static upm_result_t bh1792_set_sync_meas_mode(bh1792_context dev, uint16_t meas_freq);
/**
* @brief Selects the LED light type to use for measurement
*
* @param dev The sensor context
* @param led_type Can take a value of GREEN or IR
* @return UPM result
*/
static upm_result_t bh1792_select_led_type(bh1792_context dev, LED_TYPES led_type);
/**
* @brief Sets the interrupt mode to be used, this is called when choosing
* operation mode
*
* @param dev The sensor context
* @param int_mode Interrupt mode, one of INTERRUPT_MODES values
* @return UPM result
*/
static upm_result_t bh1792_set_interrupt_mode(bh1792_context dev, INTERRUPT_MODES int_mode);
/**
* @brief Sets the RDY bit of the sensor
*
* @param dev The sensor context
* @return UPM result
*/
static upm_result_t bh1792_set_rdy_bit(bh1792_context dev);
static upm_result_t bh1792_read_register(bh1792_context dev, uint8_t reg,
uint8_t *data)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t value = mraa_i2c_read_byte_data(dev->i2c, reg);
if(value < 0) {
printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
*data = value;
return UPM_SUCCESS;
}
static upm_result_t bh1792_read_registers(bh1792_context dev, uint8_t reg,
uint8_t *data, uint8_t len)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t value;
for(int i = 0; i < len; i++) {
if(bh1792_read_register(dev, reg + i, &value) != UPM_SUCCESS) {
return UPM_ERROR_OPERATION_FAILED;
}
*(data + i) = value;
}
return UPM_SUCCESS;
}
static upm_result_t bh1792_write_register(bh1792_context dev, uint8_t value,
uint8_t reg)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if (mraa_i2c_write_byte_data(dev->i2c, value, reg) != MRAA_SUCCESS) {
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
static upm_result_t bh1792_set_bit_on(bh1792_context dev, uint8_t reg,
uint8_t bit_mask)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t reg_value;
int status;
status = bh1792_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value |= bit_mask;
return bh1792_write_register(dev, reg_value, reg);
}
static upm_result_t bh1792_set_bit_off(bh1792_context dev, uint8_t reg,
uint8_t bit_mask)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t reg_value;
int status;
status = bh1792_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
return bh1792_write_register(dev, reg_value, reg);
}
static upm_result_t bh1792_set_bits_with_mask(bh1792_context dev, uint8_t reg,
uint8_t value, uint8_t bit_mask)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t reg_value;
int status;
status = bh1792_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
reg_value |= value;
return bh1792_write_register(dev, reg_value, reg);
}
bh1792_context bh1792_init(int bus, int addr)
{
bh1792_context dev = (bh1792_context)malloc(sizeof(struct _bh1792_context));
if (!dev)
return NULL;
dev->i2c = NULL;
dev->interrupt = NULL;
if (mraa_init() != MRAA_SUCCESS) {
printf("%s: mraa_init() failed.\n", __FUNCTION__);
bh1792_close(dev);
return NULL;
}
if (!(dev->i2c = mraa_i2c_init(bus))) {
printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__);
bh1792_close(dev);
return NULL;
}
if (mraa_i2c_address(dev->i2c, addr)) {
printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__);
bh1792_close(dev);
return NULL;
}
if(bh1792_check_who_am_i(dev) != UPM_SUCCESS)
return NULL;
dev->enabled = false;
dev->isrEnabled = false;
dev->sync_thread_alive = false;
return dev;
}
void bh1792_close(bh1792_context dev)
{
if(dev) {
bh1792_stop_measurement(dev);
if(dev->isrEnabled)
bh1792_remove_isr(dev);
if (dev->i2c)
mraa_i2c_stop(dev->i2c);
if(dev->sync_thread_alive) {
dev->sync_thread_alive = false;
pthread_join(dev->sync_thread, NULL);
}
free(dev);
}
}
upm_result_t bh1792_check_who_am_i(bh1792_context dev)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t who_am_i;
if(bh1792_read_register(dev, BH1792_MANUFACTURER_REG, &who_am_i) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(who_am_i != BH1792_MANUFACTURER_REG_MANUFACTURER_ID) {
printf("%s: wrong manufacturer ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1792_read_register(dev, BH1792_PARTID_REG, &who_am_i) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(who_am_i != BH1792_PARTID_REG_PART_ID) {
printf("%s: wrong part ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
static upm_result_t bh1792_set_rdy_bit(bh1792_context dev)
{
return bh1792_set_bit_on(dev, BH1792_MEAS_CONTROL1, BH1792_MEAS_CONTROL1_RDY);
}
bool bh1792_is_enabled(bh1792_context dev)
{
if(!dev)
return false;
return dev->enabled;
}
upm_result_t bh1792_soft_reset(bh1792_context dev)
{
return bh1792_set_bit_on(dev, BH1792_RESET, BH1792_RESET_SWRESET);
}
static upm_result_t bh1792_select_led_type(bh1792_context dev, LED_TYPES led_type)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t status;
if(led_type == GREEN) {
status = bh1792_set_bit_off(dev, BH1792_MEAS_CONTROL1,
BH1792_MEAS_CONTROL1_SEL_ADC_MASK);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
} else {
if(dev->op_mode == SYNCHRONIZED) {
printf("%s: IR LED only for single & non-sync modes\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
status = bh1792_set_bit_on(dev, BH1792_MEAS_CONTROL1,
BH1792_MEAS_CONTROL1_SEL_ADC_MASK);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
}
dev->led_type = led_type;
return UPM_SUCCESS;
}
static upm_result_t bh1792_set_sync_meas_mode(bh1792_context dev, uint16_t meas_freq)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t status;
MEAS_MODES meas_mode;
switch(meas_freq) {
case 32:
meas_mode = MSR_32Hz;
break;
case 64:
meas_mode = MSR_64Hz;
break;
case 128:
meas_mode = MSR_128Hz;
break;
case 256:
meas_mode = MSR_256Hz;
break;
case 1024:
meas_mode = MSR_1024Hz;
break;
default:
return UPM_ERROR_INVALID_PARAMETER;
}
status = bh1792_set_bits_with_mask(dev, BH1792_MEAS_CONTROL1, meas_mode,
BH1792_MEAS_CONTROL1_MSR_MASK);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->meas_freq = meas_freq;
return UPM_SUCCESS;
}
upm_result_t bh1792_get_meas_time_ms(bh1792_context dev, float *meas_time_ms)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t meas_time_reg;
if(bh1792_read_register(dev, BH1792_MEAS_CONTROL1, &meas_time_reg) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
switch(meas_time_reg & BH1792_MEAS_CONTROL1_MSR_MASK) {
case MSR_32Hz:
*meas_time_ms = 1000 / (float)32;
break;
case MSR_64Hz:
*meas_time_ms = 1000 / (float)64;
break;
case MSR_128Hz:
*meas_time_ms = 1000 / (float)128;
break;
case MSR_256Hz:
*meas_time_ms = 1000 / (float)256;
break;
case MSR_1024Hz:
*meas_time_ms = 1000 / (float)1024;
break;
case MSR_SINGLE:
case MSR_NON_SYNC:
*meas_time_ms = 1000 / (float)4;
break;
default:
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
}
upm_result_t bh1792_set_green_leds_current(bh1792_context dev, uint8_t current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(current > LED_CURRENT_MAX)
return UPM_ERROR_OUT_OF_RANGE;
uint8_t status;
status = bh1792_set_bits_with_mask(dev, BH1792_MEAS_CONTROL2,
current & BH1792_MEAS_CONTROL2_LED_CURRENT1_MASK,
BH1792_MEAS_CONTROL2_LED_CURRENT1_MASK);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->green_current = current;
return UPM_SUCCESS;
}
upm_result_t bh1792_get_green_leds_current(bh1792_context dev, uint8_t *current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t data;
if(bh1792_read_register(dev, BH1792_MEAS_CONTROL2, &data) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*current = data & BH1792_MEAS_CONTROL2_LED_CURRENT1_MASK;
return UPM_SUCCESS;
}
upm_result_t bh1792_set_ir_led_current(bh1792_context dev, uint8_t current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(current > LED_CURRENT_MAX)
return UPM_ERROR_OUT_OF_RANGE;
uint8_t status;
status = bh1792_set_bits_with_mask(dev, BH1792_MEAS_CONTROL3,
current & BH1792_MEAS_CONTROL3_LED_CURRENT2_MASK,
BH1792_MEAS_CONTROL3_LED_CURRENT2_MASK);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->ir_current = current;
return UPM_SUCCESS;
}
upm_result_t bh1792_get_ir_led_current(bh1792_context dev, uint8_t *current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t data;
if(bh1792_read_register(dev, BH1792_MEAS_CONTROL3, &data) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*current = data & BH1792_MEAS_CONTROL3_LED_CURRENT2_MASK;
return UPM_SUCCESS;
}
upm_result_t bh1792_set_ir_threshold(bh1792_context dev, uint16_t threshold)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_write_register(dev, threshold, BH1792_MEAS_CONTROL4_L) != UPM_SUCCESS ||
bh1792_write_register(dev, threshold >> 8, BH1792_MEAS_CONTROL4_H) != UPM_SUCCESS) {
printf("%s: Failed to write high threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->threshold = threshold;
return UPM_SUCCESS;
}
upm_result_t bh1792_get_ir_threshold(bh1792_context dev, uint16_t *threshold)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t data[2];
if(bh1792_read_register(dev, BH1792_MEAS_CONTROL4_H, &data[1]) != UPM_SUCCESS ||
bh1792_read_register(dev, BH1792_MEAS_CONTROL4_L, &data[0]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*threshold = data[1] << 8 | data[0];
return UPM_SUCCESS;
}
upm_result_t bh1792_get_fifo_size(bh1792_context dev, uint8_t *count)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t fifo_count;
if(bh1792_read_register(dev, BH1792_FIFO_LEV, &fifo_count) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*count = fifo_count & BH1792_FIFO_LEV_LEVEL_MASK;
return UPM_SUCCESS;
}
static upm_result_t bh1792_set_interrupt_mode(bh1792_context dev, INTERRUPT_MODES int_mode)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_bits_with_mask(dev, BH1792_MEAS_CONTROL5, int_mode,
BH1792_MEAS_CONTROL5_INT_SEL_MASK) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->interrupt_mode = int_mode;
return UPM_SUCCESS;
}
upm_result_t bh1792_disable_interrupt(bh1792_context dev)
{
return bh1792_set_bits_with_mask(dev, BH1792_MEAS_CONTROL5, 0,
BH1792_MEAS_CONTROL5_INT_SEL_MASK);
}
upm_result_t bh1792_clear_interrupt(bh1792_context dev)
{
uint8_t data;
return bh1792_read_register(dev, BH1792_INT_CLEAR, &data);
}
static void *bh1792_sync_measurement(void *args)
{
bh1792_context dev = (bh1792_context)args;
dev->sync_thread_alive = true;
while(dev->sync_thread_alive) {
bh1792_set_bit_on(dev, BH1792_MEAS_SYNC, BH1792_MEAS_SYNC_MEAS_SYNC);
usleep(ONE_SEC_IN_MIRCO_SEC);
}
return (void *)UPM_SUCCESS;
}
upm_result_t bh1792_start_measurement(bh1792_context dev)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(dev->op_mode == SYNCHRONIZED) {
if(dev->sync_thread_alive) {
dev->sync_thread_alive = false;
pthread_join(dev->sync_thread, NULL);
}
pthread_create(&dev->sync_thread, NULL, &bh1792_sync_measurement, dev);
}
if(bh1792_set_bit_on(dev, BH1792_MEAS_START, BH1792_MEAS_START_MEAS_ST) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->enabled = true;
return UPM_SUCCESS;
}
upm_result_t bh1792_stop_measurement(bh1792_context dev)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_soft_reset(dev) != UPM_SUCCESS)
return UPM_SUCCESS;
dev->enabled = false;
return UPM_SUCCESS;
}
upm_result_t bh1792_restart_measurement(bh1792_context dev)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t status;
status = bh1792_stop_measurement(dev);
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
switch(dev->op_mode) {
case SYNCHRONIZED:
status = bh1792_enable_sync_mode(dev, dev->meas_freq, dev->green_current);
break;
case NON_SYNCHRONIZED:
status = bh1792_enable_non_sync_mode(dev, dev->ir_current, dev->threshold);
break;
case SINGLE_GREEN:
status = bh1792_enable_single_mode(dev, GREEN, dev->green_current);
break;
case SINGLE_IR:
status = bh1792_enable_single_mode(dev, IR, dev->ir_current);
break;
}
if(status != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1792_start_measurement(dev);
}
upm_result_t bh1792_get_fifo_data(bh1792_context dev, uint16_t fifo_led_off[],
uint16_t fifo_led_on[])
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(dev->op_mode != SYNCHRONIZED)
return UPM_ERROR_NO_DATA;
uint8_t data[4];
for(int i = 0; i < FIFO_WATERMARK; i++) {
if(bh1792_read_registers(dev, BH1792_FIFO_DATA0_L, data, 4) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
fifo_led_off[i] = data[1] << 8 | data[0];
fifo_led_on[i] = data[3] << 8 | data[2];
}
return UPM_SUCCESS;
}
upm_result_t bh1792_discard_fifo_data(bh1792_context dev)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t data[4];
for(int i = 0; i < FIFO_WATERMARK; i++)
bh1792_read_registers(dev, BH1792_FIFO_DATA0_L, data, 4);
return UPM_SUCCESS;
}
upm_result_t bh1792_get_green_data(bh1792_context dev, uint16_t *green_led_off,
uint16_t *green_led_on)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(dev->op_mode == NON_SYNCHRONIZED || dev->op_mode == SINGLE_IR)
return UPM_ERROR_NO_DATA;
uint8_t data[4];
if(bh1792_read_registers(dev, BH1792_DATAOUT_LEDOFF_L, data, 4) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*green_led_off = data[1] << 8 | data[0];
*green_led_on = data[3] << 8 | data[2];
return UPM_SUCCESS;
}
upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
uint16_t *ir_led_on)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(dev->op_mode != NON_SYNCHRONIZED && dev->op_mode != SINGLE_IR)
return UPM_ERROR_NO_DATA;
uint8_t data[4];
if(bh1792_read_registers(dev, BH1792_IRDATA_LEDOFF_L, data, 4) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*ir_led_off = data[1] << 8 | data[0];
*ir_led_on = data[3] << 8 | data[2];
return UPM_SUCCESS;
}
upm_result_t bh1792_enable_sync_mode(bh1792_context dev, uint16_t meas_freq,
uint8_t green_current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t status;
if(bh1792_set_rdy_bit(dev) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_green_leds_current(dev, green_current) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_select_led_type(dev, GREEN) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
status = bh1792_set_sync_meas_mode(dev, meas_freq);
if(status != UPM_SUCCESS)
return status;
dev->op_mode = SYNCHRONIZED;
return bh1792_set_interrupt_mode(dev, WATER_MARK);
}
upm_result_t bh1792_enable_non_sync_mode(bh1792_context dev, uint8_t ir_current,
uint16_t threshold)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_rdy_bit(dev) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_ir_led_current(dev, ir_current) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_select_led_type(dev, IR) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_sync_meas_mode(dev, MSR_NON_SYNC) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
dev->op_mode = NON_SYNCHRONIZED;
return bh1792_set_interrupt_mode(dev, IR_THRESHOLD_JUDGE);
}
upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
uint8_t current)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_rdy_bit(dev) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(led_type == GREEN) {
if(bh1792_set_green_leds_current(dev, current) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
} else {
if(bh1792_set_ir_led_current(dev, current) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1792_select_led_type(dev, led_type) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1792_set_sync_meas_mode(dev, MSR_SINGLE) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(led_type == GREEN)
dev->op_mode = SINGLE_GREEN;
else
dev->op_mode = SINGLE_IR;
return bh1792_set_interrupt_mode(dev, ON_COMPLETE);
}
upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
int pin, void (*isr)(void *), void *isr_args)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
if(dev->isrEnabled)
bh1792_remove_isr(dev);
mraa_gpio_context isr_gpio = NULL;
if (!(isr_gpio = mraa_gpio_init(pin))) {
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
mraa_gpio_dir(isr_gpio, MRAA_GPIO_IN);
if (mraa_gpio_isr(isr_gpio, edge, isr, isr_args) != MRAA_SUCCESS) {
mraa_gpio_close(isr_gpio);
printf("%s: mraa_gpio_isr() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->interrupt = isr_gpio;
dev->isrEnabled = true;
return UPM_SUCCESS;
}
upm_result_t bh1792_install_isr_falling_edge(bh1792_context dev, int pin,
void (*isr)(void *), void *isr_args)
{
return bh1792_install_isr(dev, MRAA_GPIO_EDGE_FALLING, pin, isr, isr_args);
}
void bh1792_remove_isr(bh1792_context dev)
{
if(dev) {
mraa_gpio_isr_exit(dev->interrupt);
mraa_gpio_close(dev->interrupt);
dev->interrupt = NULL;
dev->isrEnabled = false;
}
}
upm_result_t bh1792_registers_dump(bh1792_context dev, char *dump)
{
if(!dev)
return UPM_ERROR_OPERATION_FAILED;
uint8_t reg_values[10];
int count = 0;
int len = 8;
if(bh1792_read_registers(dev, BH1792_MEAS_CONTROL1, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump, "0x41 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
sprintf(dump + count - 1, "\n");
len = 1;
if(bh1792_read_registers(dev, BH1792_FIFO_LEV, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump + count, "0x4B ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
return UPM_SUCCESS;
}

305
src/bh1792/bh1792.cxx Executable file
View File

@ -0,0 +1,305 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <stdexcept>
#include "bh1792.hpp"
using namespace upm;
BH1792::BH1792(int bus, int addr) : m_bh1792(bh1792_init(bus, addr))
{
if(!m_bh1792)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_init() failed");
}
BH1792::~BH1792()
{
bh1792_close(m_bh1792);
}
void BH1792::CheckWhoAmI()
{
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_check_who_am_i() failed");
}
bool BH1792::IsEnabled()
{
return bh1792_is_enabled(m_bh1792);
}
void BH1792::SoftReset()
{
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_soft_reset() failed");
}
float BH1792::GetMeasurementTimeMS()
{
float meas_time;
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_meas_time_ms() failed");
return meas_time;
}
void BH1792::SetGreenLedsCurrent(uint16_t current)
{
uint8_t status;
status = bh1792_set_green_leds_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed");
}
}
int BH1792::GetGreenLedsCurrent()
{
uint8_t current;
if(bh1792_get_green_leds_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_leds_current() failed");
return (int)current;
}
void BH1792::SetIrLedCurrent(uint16_t current)
{
uint8_t status;
status = bh1792_set_ir_led_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed");
}
}
int BH1792::GetIrLedCurrent()
{
uint8_t current;
if(bh1792_get_ir_led_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_led_current() failed");
return (int)current;
}
void BH1792::SetIrThreshold(uint16_t threshold)
{
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_threshold() failed");
}
int BH1792::GetIrThreshold()
{
uint16_t threshold;
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_threshold() failed");
return (int)threshold;
}
int BH1792::GetFifoSize()
{
uint8_t size;
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_size() failed");
return (int)size;
}
void BH1792::DisableInterrupt()
{
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_disable_interrupt() failed");
}
void BH1792::ClearInterrupt()
{
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_clear_interrupt() failed");
}
void BH1792::StartMeasurement()
{
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_start_measurement() failed");
}
void BH1792::StopMeasurement()
{
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_stop_measurement() failed");
}
void BH1792::RestartMeasurement()
{
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_restart_measurement() failed");
}
std::vector<std::vector<int>> BH1792::GetFifoData()
{
uint16_t fifo_off[FIFO_WATERMARK], fifo_on[FIFO_WATERMARK];
if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_data() failed");
std::vector<int> item;
std::vector<std::vector<int>> result;
item.reserve(2);
result.reserve(FIFO_WATERMARK);
for(int i = 0; i < FIFO_WATERMARK; i++) {
item.clear();
item.push_back(fifo_off[i]);
item.push_back(fifo_on[i]);
result.push_back(item);
}
return result;
}
void BH1792::DiscardFifoData()
{
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_discard_fifo_data() failed");
}
std::vector<int> BH1792::GetGreenData()
{
uint16_t green_off, green_on;
if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_data() failed");
std::vector<int> result;
result.reserve(2);
result.push_back(green_off);
result.push_back(green_on);
return result;
}
std::vector<int> BH1792::GetIrData()
{
uint16_t ir_off, ir_on;
if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_data() failed");
std::vector<int> result;
result.reserve(2);
result.push_back(ir_off);
result.push_back(ir_on);
return result;
}
void BH1792::EnableSyncMode(uint16_t measFreq, uint16_t green_current)
{
uint8_t status;
status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
if(status == UPM_ERROR_INVALID_PARAMETER) {
throw std::invalid_argument(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed, invalid measurement frequncy");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed");
}
}
void BH1792::EnableNonSyncMode(uint16_t ir_current, uint16_t threshold)
{
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_non_sync_mode() failed");
}
void BH1792::EnableSingleMode(LED_TYPES led_type, uint16_t current)
{
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_single_mode() failed");
}
void BH1792::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
{
if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr() failed");
}
void BH1792::InstallISR(int pin, void (*isr)(void *), void *isr_args)
{
if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr_falling_edge() failed");
}
void BH1792::RemoveISR()
{
bh1792_remove_isr(m_bh1792);
}
std::string BH1792::RegistersDump()
{
char dump[255];
std::string dumpStr;
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_registers_dump() failed");
dumpStr = dump;
return dumpStr;
}

411
src/bh1792/bh1792.h Executable file
View File

@ -0,0 +1,411 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include <mraa/i2c.h>
#include <mraa/gpio.h>
#include <unistd.h>
#include <upm_types.h>
#include <pthread.h>
#include "bh1792glc_registers.h"
/**
* @file bh1792.h
* @library bh1792
* @brief C API for the bh1792 driver
*
* @include bh1792.c
*/
#define ONE_SEC_IN_MIRCO_SEC 1000000
#define FIFO_WATERMARK 32
#define LED_CURRENT_MAX 63
/**
* @brief Measurement modes, for synchronized time modes, non synchronized
* and single modes.
*/
typedef enum {
MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ,
MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ,
MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ,
MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ,
MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ,
MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE,
MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE
} MEAS_MODES;
/**
* @brief LED light types
*/
typedef enum {
GREEN,
IR
} LED_TYPES;
/**
* @brief Interrupt modes of the sensor
*/
typedef enum {
WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK,
IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD,
ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE
} INTERRUPT_MODES;
/**
* @brief Operations modes available with the sensor
*/
typedef enum {
SYNCHRONIZED,
NON_SYNCHRONIZED,
SINGLE_GREEN,
SINGLE_IR
} OP_MODES;
/**
* @brief bh1792 sensor context
*/
typedef struct _bh1792_context
{
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
OP_MODES op_mode;
pthread_t sync_thread;
bool sync_thread_alive;
LED_TYPES led_type;
INTERRUPT_MODES interrupt_mode;
uint16_t meas_freq;
uint8_t green_current;
uint8_t ir_current;
uint16_t threshold;
} *bh1792_context;
/**
* @brief Init the sensor with specific bus and address. Before starting
* measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode,
* or bh1792_enable_single_mode) have to be called.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @return context of initialized sensor
*/
bh1792_context bh1792_init(int bus, int addr);
/**
* @brief Close and free sensor context
*
* @param dev Sensor context
*/
void bh1792_close(bh1792_context dev);
/**
* @brief Check "who am I" register value to identify the sensor
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1792_check_who_am_i(bh1792_context dev);
/**
* @brief Checks if the measuremnt on sensor is enabled
*
* @param The sensor context
* @return True if measurement is enabled, or false otherwise
*/
bool bh1792_is_enabled(bh1792_context dev);
/**
* @brief Initiates a software reset to the sensor. All register values will
* be written to their defaults, thus intended operation mode need to be
* enabled.
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1792_soft_reset(bh1792_context dev);
/**
* @brief Gets the value of measurement time is milli-seconds
*
* @param dev The sensor context
* @param meas_time_ms Float pointer to store value of measurement time
* @return UPM result
*/
upm_result_t bh1792_get_meas_time_ms(bh1792_context dev, float *meas_time);
/**
* @brief Sets the green LED Current value
*
* @param dev The sensor context
* @param current The current value, accepted values are between 0-63
* @return UPM result
*/
upm_result_t bh1792_set_green_leds_current(bh1792_context dev, uint8_t current);
/**
* @brief Gets the green LED current value
*
* @param dev The sensor context
* @param current Pointer to store the read current value
* @return UPM result
*/
upm_result_t bh1792_get_green_leds_current(bh1792_context dev, uint8_t *current);
/**
* @brief Sets the IR LED Current value
*
* @param dev The sensor context
* @param current The current value, accepted values are between 0-63
* @return UPM result
*/
upm_result_t bh1792_set_ir_led_current(bh1792_context dev, uint8_t current);
/**
* @brief Gets the IR LED current value
*
* @param dev The sensor context
* @param current Pointer to store the read current value
* @return UPM result
*/
upm_result_t bh1792_get_ir_led_current(bh1792_context dev, uint8_t *current);
/**
* @brief Sets interrupt ir threshold value for non-synchronized mode
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
*/
upm_result_t bh1792_set_ir_threshold(bh1792_context dev, uint16_t threshold);
/**
* @brief Gets interrupt ir threshold value
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
*/
upm_result_t bh1792_get_ir_threshold(bh1792_context dev, uint16_t *threshold);
/**
* @brief Gets the current size of built-in FIFO
*
* @param dev The sensor context
* @param count The pointer to store the size
* @return UPM result
*/
upm_result_t bh1792_get_fifo_size(bh1792_context dev, uint8_t *count);
/**
* @brief Disables interrupt function. Interrupt is enabled by default on all
* operation modes, so this have to be called after enabling a specific
* operation mode
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_disable_interrupt(bh1792_context dev);
/**
* @brief Clears the interrupt flag allowing more interrupts to be raised
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_clear_interrupt(bh1792_context dev);
/**
* @brief Starts the measuremnt on sensor or enable the sensor
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_start_measurement(bh1792_context dev);
/**
* @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous
* configuration call bh1792_restart_measurement().
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_stop_measurement(bh1792_context dev);
/**
* @brief Restart the measurement, This function stops measurement, then
* re-writes the configuration registers again and start measurement with same
* configuration.
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_restart_measurement(bh1792_context dev);
/**
* @brief Gets the fifo data of 32 entries and resets the WATERMARK interrupt
* flag.
*
* @param dev The sensor context
* @param fifo_led_off Array/Pointer to store 32 entries of fifo LED_OFF data
* @param fifo_led_on Array/Pointer to store 32 entries of fifo LED_ON data
* @return UPM result
*/
upm_result_t bh1792_get_fifo_data(bh1792_context dev, uint16_t fifo_led_off[],
uint16_t fifo_led_on[]);
/**
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag.
*
* @param dev The sensor context
* @return UPM result
*/
upm_result_t bh1792_discard_fifo_data(bh1792_context dev);
/**
* @brief Gets the values from using green LED light
*
* @param dev The sensor context
* @param green_led_off Pointer to store the reading value of LED_OFF
* @param green_led_on Pointer to store the reading value of LED_ON
* @return UPM result
*/
upm_result_t bh1792_get_green_data(bh1792_context dev, uint16_t *green_led_off,
uint16_t *green_led_on);
/**
* @brief Gets the values from using IR LED light
*
* @param dev The sensor context
* @param ir_led_off Pointer to store the reading value of LED_OFF
* @param ir_led_on Pointer to store the reading value of LED_ON
* @return UPM result
*/
upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
uint16_t *ir_led_on);
/**
* @brief Enables and configures the sensor to use synchronized mode. This will
* use the built-in FIFO and raises a WATERMARK interrupt when FIFO size
* reaches 32 entries. To clear that interrupt flag FIFO must be read or
* discarded. This mode uses only green LED.
*
* You need to call bh1792_start_measurement() after this.
*
* @param dev The sensor context
* @param meas_freq Measurement frequncy mode, valid values 32, 64, 128, 256,
* 1024
* @param green_current Green LED current value
* @return UPM result
*/
upm_result_t bh1792_enable_sync_mode(bh1792_context dev, uint16_t meas_freq,
uint8_t green_current);
/**
* @brief Enabled and configures the sensor to use non-synchronized mode. This
* mode uses IR_THRESHOLD interrupt, it will raise an interrupt if IR LED ON
* value is equal or greater than the threshold value. Interrupt must be
* cleared before receiving new interrupts. This mode uses only IR LED.
*
* You need to call bh1792_start_measurement() after this.
*
* @param dev The sensor context
* @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value
* @return UPM result
*/
upm_result_t bh1792_enable_non_sync_mode(bh1792_context dev, uint8_t ir_current,
uint16_t threshold);
/**
* @brief Enables and configures the sensor to use single mode. This sets the
* sensor to take only one measurement and raise an interrupt after measurement
* is finished. Interrupt flags has to be cleared to recieved new interrupts.
* This mode uses both green and IR LEDs.
*
* You need to call bh1792_start_measurement() after this. If you need to get
* continuous values, clear interrupt and bh1792_start_measurement()
* continuously.
*
* @param dev The sensor context
* @param led_type LED light type to use, takes GREEN or IR values
* @param current The chosen led_type current value
* @return UPM result
*/
upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
uint8_t current);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @return UPM result
*/
upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param dev Sensor context
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @return UPM result
*/
upm_result_t bh1792_install_isr_falling_edge(bh1792_context dev, int pin,
void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*
* @param dev Sensor context
*/
void bh1792_remove_isr(bh1792_context dev);
/**
* @brief Gets a dump of configuration registers as a string
*
* @param dev Sensor context
* @param dump Pointer of char to save dump string
* @return UPM result
*/
upm_result_t bh1792_registers_dump(bh1792_context dev, char *dump);
#ifdef __cplusplus
}
#endif

324
src/bh1792/bh1792.hpp Executable file
View File

@ -0,0 +1,324 @@
/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* 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 <vector>
#include <string>
#include "bh1792.h"
/**
* @brief BH1792 Heart Rate Sensor
* @defgroup bh1792 libupm-bh1792
* @ingroup rohm i2c medical
*/
/**
* @library bh1792
* @sensor bh1792
* @comname Heart Rate Sensor
* @type medical
* @man rohm
* @con i2c
*
* @brief C++ API for the bh1792 driver
*
* @snippet bh1792.cxx Interesting
*/
namespace upm {
class BH1792 {
public:
/**
* @brief Init the sensor with specific bus and address. Before
* starting measurement, one of (EnableSyncMode, EnableNonSyncMode,
* or EnableSingleMode) has to be called.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1792(int bus = 0, int addr = 0x5b);
/**
* @brief Close and free sensor
*/
virtual ~BH1792();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Checks if the measuremnt on sensor is enabled
*
* @return True if measurement is enabled, or false otherwise
*/
bool IsEnabled();
/**
* @brief Initiates a software reset to the sensor. All register values
* will be written to their defaults, thus intended operation mode need
* to be enabled.
*
* @throws std::runtime_error if software reset fails
*/
void SoftReset();
/**
* @brief Gets the value of measurement time is milli-seconds
*
* @return measurement time float in milli-seconds
* @throws std::runtime_error if reading measurement time fails
*/
float GetMeasurementTimeMS();
/**
* @brief Sets the green LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetGreenLedsCurrent(uint16_t current);
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetGreenLedsCurrent();
/**
* @brief Sets the IR LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetIrLedCurrent(uint16_t current);
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrLedCurrent();
/**
* @brief Sets interrupt IR threshold value for non-synchronized mode
*
* @param threshold Value to be written, range 0-65536
* @throws std::runtime_error if setting threshold fails
*/
void SetIrThreshold(uint16_t threshold);
/**
* @brief Gets interrupt IR threshold value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrThreshold();
/**
* @brief Gets the current size of built-in FIFO
*
* @return Number of entries store in FIFO
* @throws std::runtime_error if reading size fails
*/
int GetFifoSize();
/**
* @brief Disables interrupt function. Interrupt is enabled by default
* on all operation modes, so this have to be called after enabling a
* specific operation mode
*
* @throws std::runtime_error if setting interrupt disable bits fails
*/
void DisableInterrupt();
/**
* @brief Clears the interrupt flag allowing more interrupts to be
* raised
*
* @throws std::runtime_error if clearing interrupt fails
*/
void ClearInterrupt();
/**
* @brief Starts the measuremnt on sensor or enable the sensor
*
* @throws std::runtime_error if starting measurement fails
*/
void StartMeasurement();
/**
* @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous
* configuration call RestartMeasurement().
*
* @throws std::runtime_error if disabling measurement fails
*/
void StopMeasurement();
/**
* @brief Restart the measurement, This function stops measurement,
* then re-writes the configuration registers again and start
* measurement with same configuration.
*
* @throws std::runtime_error if restarting measurement fails
*/
void RestartMeasurement();
/**
* @brief Gets the fifo data of 32 entries and resets the WATERMARK
* interrupt flag.
*
* @return vector of values of the retrieved FIFO values, which are
* vectors containing 2 values each (led off, led_on)
* @throws std::runtime_error if reading FIFO data fails
*/
std::vector<std::vector<int>> GetFifoData();
/**
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag.
*
* @throws std::runtime_error if reading FIFO data fails
*/
void DiscardFifoData();
/**
* @brief Gets the values from using green LED light
*
* @return vector of values (led off, led on) of green led values
* @throws std::runtime_error if reading green data fails
*/
std::vector<int> GetGreenData();
/**
* @brief Gets the values from using IR LED light
*
* @return vector of values (led off, led on) of IR led values
* @throws std::runtime_error if reading IR data fails
*/
std::vector<int> GetIrData();
/**
* @brief Enables and configures the sensor to use synchronized mode.
* This will use the built-in FIFO and raises a WATERMARK interrupt
* when FIFO size reaches 32 entries. To clear that interrupt flag FIFO
* must be read or discarded. This mode uses only green LED.
*
* You need to call StartMeasurement() after this.
*
* @param measFreq Measurement frequncy mode, valid values 32, 64, 128,
* 256, 1024
* @param green_current Green LED current value
* @throws std::runtime_error if enabling synchronized mode fails
* @throws std::invalid_argument if measurement frequency is invalid
*/
void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
/**
* @brief Enabled and configures the sensor to use non-synchronized
* mode. This mode uses IR_THRESHOLD interrupt, it will raise an
* interrupt if IR LED ON value is equal or greater than the threshold
* value. Interrupt must be cleared before receiving new interrupts.
* This mode uses only IR LED.
*
* You need to call StartMeasurement() after this.
*
* @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value
*
* @throws std::runtime_error if enabling non-synchronized mode fails
*/
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
/**
* @brief Enables and configures the sensor to use single mode. This
* sets the sensor to take only one measurement and raise an interrupt
* after measurement is finished. Interrupt flags has to be cleared to
* recieved new interrupts. This mode uses both green and IR LEDs.
*
* You need to call StartMeasurement() after this. If you need to get
* continuous values, clear interrupt and StartMeasurement()
* continuously.
*
* @param led_type LED light type to use, takes GREEN or IR (0 or 1)
* @param current The chosen led_type current value
* @throws std::runtime_error if enabling single mode fails
*/
void EnableSingleMode(LED_TYPES led_type, uint16_t current);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
void *isr_args);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
private:
bh1792_context m_bh1792;
/* Disable implicit copy and assignment operators */
BH1792(const BH1792 &) = delete;
BH1792 &operator=(const BH1792 &) = delete;
};
}

28
src/bh1792/bh1792.i Executable file
View File

@ -0,0 +1,28 @@
%include "../common_top.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%ignore InstallISR(mraa_gpio_edge_t, int, void *, void *);
%extend upm::BH1792 {
void InstallISR(int pin, jobject runnable)
{
$self->InstallISR(pin, mraa_java_isr_callback, runnable);
}
}
JAVA_JNI_LOADLIBRARY(javaupm_bh1792)
#endif
/* END Java syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%include "std_vector.i"
%template(intVector) std::vector<int>;
%template(intVector2D) std::vector<std::vector<int>>;
%{
#include "bh1792.hpp"
%}
%include "bh1792.h"
%include "bh1792.hpp"
/* END Common SWIG syntax */

62
src/bh1792/bh1792.json Executable file
View File

@ -0,0 +1,62 @@
{
"Library": "BH1792",
"Description": "ROHM BH1792 Heart Rate Sensor library",
"Sensor Class": {
"BH1792": {
"Name": "ROHM BH1792 Heart Rate Sensor library",
"Description": "BH1792GLC is optical sensor for heart rate monitor IC in which LED driver, green light and IR detection photodiode are incorporated. This device drives LED and provides the intensity of light reflected from body. LED brightness can be adjusted by LED driver current. The photodiode having the high sensitivity for green light and excellent wavelength selectivity achieves accurate pulse wave detection.",
"Categories": ["medical"],
"Connections": ["i2c"],
"Project Type": ["prototyping", "commercial"],
"Manufacturers": ["ROHM"],
"Examples": {
"C++": ["bh1792.cxx"],
"C": ["bh1792.c"],
"Java": ["BH1792_Example.java"],
"Python": ["bh1792.py"],
"Node.js": ["bh1792.js"]
},
"Specifications": {
"Supply Voltage (VDD)": {
"unit": "V",
"min": 2.5,
"typical": 3.0,
"max": 3.6
},
"Terminal Input Voltage": {
"unit": "V",
"min": 0.7,
"max": 5.5
},
"Supply Current": {
"unit": "uA",
"min": 0.8,
"max": 200
},
"LED Supply Current": {
"unit": "mA",
"typical": 1.4,
"max": 3.0
},
"Standby Mode Current": {
"unit": "uA",
"typical": 0.8,
"max": 1.5
},
"Operating Temperature": {
"unit": "°C",
"min": -20,
"max": 85
}
},
"Urls": {
"Product Pages": [
"https://www.rohm.com/sensor-shield-support/heart-rate-sensor2"
],
"Datasheets": [
"https://www.rohm.com/datasheet/BH1792GLC/bh1792glc-e"
]
}
}
}
}

129
src/bh1792/bh1792glc_registers.h Executable file
View File

@ -0,0 +1,129 @@
/*
The MIT License (MIT)
Copyright (c) 2017 Rohm Semiconductor
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __BH1792GLC_REGISTERS_H__
#define __BH1792GLC_REGISTERS_H__
/* registers */
#define BH1792_REGISTER_DUMP_START 0x0F
#define BH1792_MANUFACTURER_REG 0x0F
// WHO_AM_I -value
#define BH1792_PARTID_REG 0x10
// Soft reset
#define BH1792_RESET 0x40
// System control setting
#define BH1792_MEAS_CONTROL1 0x41
// LED 1 & 2 control register
#define BH1792_MEAS_CONTROL2 0x42
// LED 3 control register
#define BH1792_MEAS_CONTROL3 0x43
// IR Interrupt Threshold Value [7:0]
#define BH1792_MEAS_CONTROL4_L 0x44
// IR Interrupt Threshold Value [15:8]
#define BH1792_MEAS_CONTROL4_H 0x45
#define BH1792_MEAS_CONTROL5 0x46
#define BH1792_MEAS_START 0x47
#define BH1792_MEAS_SYNC 0x48
#define BH1792_FIFO_LEV 0x4B
// FIFO Output data 0 [7:0]
#define BH1792_FIFO_DATA0_L 0x4C
// FIFO Output data 0 [15:8]
#define BH1792_FIFO_DATA0_H 0x4D
// FIFO Output data 1 [7:0]
#define BH1792_FIFO_DATA1_L 0x4E
// FIFO Output data 1 [15:8]
#define BH1792_FIFO_DATA1_H 0x4F
// IR Data Count Value during no LED emission [7:0]
#define BH1792_IRDATA_LEDOFF_L 0x50
// IR Data Count Value during no LED emission [15:8]
#define BH1792_IRDATA_LEDOFF_H 0x51
// IR Data Count Value during LED emission [7:0]
#define BH1792_IRDATA_LEDON_L 0x52
// IR Data Count Value during LED emission [15:8]
#define BH1792_IRDATA_LEDON_H 0x53
// Green Data Count Value during no LED emission [7:0]
#define BH1792_DATAOUT_LEDOFF_L 0x54
// Green Data Count Value during no LED emission [15:8]
#define BH1792_DATAOUT_LEDOFF_H 0x55
// Green Data Count Value during LED emission [7:0]
#define BH1792_DATAOUT_LEDON_L 0x56
// Green Data Count Value during LED emission [15:8]
#define BH1792_DATAOUT_LEDON_H 0x57
// IR threshold judgement and measurement completion interrupt is cleared when reading this register.
#define BH1792_INT_CLEAR 0x58
#define BH1792_REGISTER_DUMP_END 0x58
/* registers bits */
#define BH1792_MANUFACTURER_REG_MANUFACTURER_ID (0xE0 << 0)
#define BH1792_PARTID_REG_PART_ID (0x0E << 0)
// 1 : Software reset is performed
#define BH1792_RESET_SWRESET (0x01 << 7)
// 1 : OSC block is active, 0: prohibited
#define BH1792_MEAS_CONTROL1_RDY (0x01 << 7)
// Green mode, leds 1 & 2 active
#define BH1792_MEAS_CONTROL1_SEL_ADC_GREEN (0x00 << 4)
// IR mode, led 3 active. Can be used only in single and non synch modes.
#define BH1792_MEAS_CONTROL1_SEL_ADC_IR (0x01 << 4)
// 32 Hz synchronous mode
#define BH1792_MEAS_CONTROL1_MSR_32HZ (0x00 << 0)
// 128 Hz synchronous mode
#define BH1792_MEAS_CONTROL1_MSR_128HZ (0x01 << 0)
// 64 Hz synchronous mode
#define BH1792_MEAS_CONTROL1_MSR_64HZ (0x02 << 0)
// 256 Hz synchronous mode
#define BH1792_MEAS_CONTROL1_MSR_256HZ (0x03 << 0)
#define BH1792_MEAS_CONTROL1_MSR_PROHIBITED (0x04 << 0)
// 1024 Hz synchronous mode
#define BH1792_MEAS_CONTROL1_MSR_1024HZ (0x05 << 0)
// non synchronized measurement mode
#define BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE (0x06 << 0)
// single measurement mode
#define BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE (0x07 << 0)
// LED driver mode, for usage see datasheet
#define BH1792_MEAS_CONTROL3_LED_EN2 (0x01 << 7)
// No interrupt output.
#define BH1792_MEAS_CONTROL5_INT_SEL_DISABLE (0x00 << 0)
// Watermark interrupt FIFO, fires when number of stored samples reaches 32. Cleared when number of samples falls below 32.
#define BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK (0x01 << 0)
// IR threshold judgement interrupt. Used in non synchroniozed mode.
#define BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD (0x02 << 0)
// Measurement completion interrupt. In single mode.
#define BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE (0x03 << 0)
// Flag of start measurement. MEAS_ST=1 after RDY=1 starts measurement. In single measurement mode MEAS_ST=1 restarts measurement.
#define BH1792_MEAS_START_MEAS_ST (0x01 << 0)
// Used in synhcronized measurement mode. Write once per second.
#define BH1792_MEAS_SYNC_MEAS_SYNC (0x01 << 0)
/*registers bit masks */
#define BH1792_MANUFACTURER_REG_MANUFACTURER_MASK 0xFF
#define BH1792_PARTID_REG_PART_MASK 0xFF
// Select LED omitting frequency
#define BH1792_MEAS_CONTROL1_SEL_ADC_MASK 0x10
// Measurement mode
#define BH1792_MEAS_CONTROL1_MSR_MASK 0x07
#define BH1792_MEAS_CONTROL2_LED_EN1_MASK 0xC0
#define BH1792_MEAS_CONTROL2_LED_CURRENT1_MASK 0x3F
#define BH1792_MEAS_CONTROL3_LED_CURRENT2_MASK 0x3F
// Interrupt function select
#define BH1792_MEAS_CONTROL5_INT_SEL_MASK 0x03
#define BH1792_FIFO_LEV_LEVEL_MASK 0x3F
#endif

View File

@ -35,12 +35,14 @@ JAVA_JNI_LOADLIBRARY(javaupm_bma220)
/* BEGIN Javascript syntax ------------------------------------------------- */
#ifdef SWIGJAVASCRIPT
%include "../upm_vectortypes.i"
%pointer_functions(float, floatp);
#endif
/* END Javascript syntax */
/* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON
%include "../upm_vectortypes.i"
%pointer_functions(float, floatp);
#endif
/* END Python syntax */

View File

@ -5,5 +5,5 @@ upm_mixed_module_init (NAME bmp280
CPP_HDR bmp280.hpp bme280.hpp
CPP_SRC bmp280.cxx bme280.cxx
CPP_WRAPS_C
REQUIRES mraa core utilities-c)
REQUIRES mraa interfaces utilities-c)
target_link_libraries(${libnamec} m)

View File

@ -54,17 +54,3 @@ void BME280::setOversampleRateHumidity(BME280_OSRS_H_T rate)
{
bmp280_set_oversample_rate_humidity(m_bmp280, rate);
}
std::map<std::string, float> BME280::HumidityForSources(std::vector<std::string> sources)
{
std::map<std::string, float> ret;
if (std::find(sources.begin(), sources.end(), "humidity") != sources.end())
{
update();
ret["humidity"] = getHumidity();
}
return ret;
}

View File

@ -26,7 +26,7 @@
#pragma once
#include <string>
#include "iHumiditySensor.hpp"
#include "interfaces/iHumiditySensor.hpp"
#include "bmp280.hpp"
@ -57,7 +57,7 @@ namespace upm {
* @snippet bmp280-bme280.cxx Interesting
*/
class BME280 : public virtual BMP280, public virtual iHumiditySensor {
class BME280 : public BMP280, public IHumiditySensor {
public:
/**
@ -88,12 +88,6 @@ namespace upm {
*/
virtual ~BME280();
virtual std::string Name () {return "BME280";}
virtual std::string Description () {return "Digital absolute pressure sensor with humidity";}
/* Provide an implementation of a method to get sensor values by source */
virtual std::map<std::string, float> HumidityForSources(std::vector<std::string> sources);
/**
* Return the current measured relative humidity. update()
* must have been called prior to calling this method. If the
@ -114,6 +108,12 @@ namespace upm {
*/
void setOversampleRateHumidity(BME280_OSRS_H_T rate);
// Interface support
const char *getModuleName()
{
return "BME280";
};
int getHumidityRelative()
{
return int(getHumidity());

View File

@ -48,8 +48,6 @@ BMP280::BMP280(int bus, int addr, int cs) :
if (!m_bmp280)
throw std::runtime_error(string(__FUNCTION__)
+ ": bmp280_init() failed");
AddSource("temperature", "C");
AddSource("pressure", "Pa");
}
BMP280::~BMP280()
@ -152,29 +150,3 @@ void BMP280::setUsageMode(BMP280_USAGE_MODE_T mode)
bmp280_set_usage_mode(m_bmp280, mode);
}
std::map<std::string, float> BMP280::TemperatureForSources(std::vector<std::string> sources)
{
std::map<std::string, float> ret;
if (std::find(sources.begin(), sources.end(), "temperature") != sources.end())
{
update();
ret["temperature"] = getTemperature(false);
}
return ret;
}
std::map<std::string, float> BMP280::PressureForSources(std::vector<std::string> sources)
{
std::map<std::string, float> ret;
if (std::find(sources.begin(), sources.end(), "pressure") != sources.end())
{
update();
ret["pressure"] = getPressure();
}
return ret;
}

View File

@ -28,8 +28,8 @@
#include <string>
#include "bmp280.h"
#include "iPressureSensor.hpp"
#include "iTemperatureSensor.hpp"
#include "interfaces/iPressureSensor.hpp"
#include "interfaces/iTemperatureSensor.hpp"
namespace upm {
@ -67,7 +67,7 @@ namespace upm {
* @snippet bmp280.cxx Interesting
*/
class BMP280 : public virtual iTemperatureSensor, public virtual iPressureSensor {
class BMP280 : public ITemperatureSensor, public IPressureSensor {
public:
/**
@ -93,16 +93,6 @@ namespace upm {
BMP280(int bus=BMP280_DEFAULT_I2C_BUS, int addr=BMP280_DEFAULT_ADDR,
int cs=-1);
virtual std::string Name () {return "BMP280";}
virtual std::string Description () {return "Digital absolute pressure sensor";}
/* Provide an implementation of a method to get sensor values by source */
virtual std::map<std::string, float> TemperatureForSources(std::vector<std::string> sources);
/* Provide an implementation of a method to get sensor values by source */
virtual std::map<std::string, float> PressureForSources(std::vector<std::string> sources);
/**
* BMP280 Destructor.
*/
@ -227,6 +217,12 @@ namespace upm {
void setMeasureMode(BMP280_MODES_T mode);
// Interface support
const char *getModuleName()
{
return "BMP280";
};
int getTemperatureCelsius()
{
return int(getTemperature(false));

View File

@ -1,17 +1,40 @@
%include "../common_top.i"
%include "iHumiditySensor.i"
%include "iTemperatureSensor.i"
%include "iPressureSensor.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%import "../interfaces/javaupm_iTemperatureSensor.i"
%import "../interfaces/javaupm_iHumiditySensor.i"
%import "../interfaces/javaupm_iPressureSensor.i"
%include "arrays_java.i";
%include "../java_buffer.i"
%typemap(javaimports) SWIGTYPE %{
import upm_interfaces.*;
%}
JAVA_JNI_LOADLIBRARY(javaupm_bmp280)
#endif
/* END Java syntax */
/* BEGIN Javascript syntax ------------------------------------------------- */
#ifdef SWIGJAVASCRIPT
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
%include "iHumiditySensor.hpp"
#endif
/* END Javascript syntax */
/* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
%include "iHumiditySensor.hpp"
#endif
/* END Python syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%{
#include "bmp280_regs.h"

View File

@ -6,5 +6,5 @@ upm_mixed_module_init (NAME bmpx8x
CPP_SRC bmpx8x.cxx
FTI_SRC bmpx8x_fti.c
CPP_WRAPS_C
REQUIRES mraa core utilities-c)
REQUIRES mraa interfaces utilities-c)
target_link_libraries(${libnamec} m)

View File

@ -44,9 +44,6 @@ BMPX8X::BMPX8X (int bus, int addr) :
if (!m_bmpx8x)
throw std::runtime_error(string(__FUNCTION__)
+ ": bmpx8x_init() failed");
AddSource("temperature", "C");
AddSource("pressure", "Pa");
}
BMPX8X::~BMPX8X()
@ -121,24 +118,3 @@ float BMPX8X::getAltitude(int sealevelPressure)
{
return bmpx8x_get_altitude(m_bmpx8x, sealevelPressure);
}
std::map<std::string, float> BMPX8X::TemperatureForSources(std::vector<std::string> sources)
{
std::map<std::string, float> ret;
if (std::find(sources.begin(), sources.end(), "temperature") != sources.end())
ret["temperature"] = getTemperatureCelsius();
return ret;
}
std::map<std::string, float> BMPX8X::PressureForSources(std::vector<std::string> sources)
{
std::map<std::string, float> ret;
if (std::find(sources.begin(), sources.end(), "pressure") != sources.end())
ret["pressure"] = getPressurePa();
return ret;
}

View File

@ -32,8 +32,8 @@
#include "bmpx8x.h"
#include "iPressureSensor.hpp"
#include "iTemperatureSensor.hpp"
#include "interfaces/iPressureSensor.hpp"
#include "interfaces/iTemperatureSensor.hpp"
namespace upm {
@ -68,7 +68,7 @@ namespace upm {
* @snippet bmpx8x.cxx Interesting
*/
class BMPX8X : public iPressureSensor, public iTemperatureSensor {
class BMPX8X : public IPressureSensor, public ITemperatureSensor {
public:
/**
* Instantiates a BMPX8X object
@ -85,18 +85,6 @@ namespace upm {
*/
virtual ~BMPX8X();
/** Return the name of this device */
virtual std::string Name () {return "BMPX8X";}
/** Return the description of this device */
virtual std::string Description () {return "Atmospheric pressure sensor";}
/* Provide an implementation of a method to get sensor values by source */
virtual std::map<std::string, float> TemperatureForSources(std::vector<std::string> sources);
/* Provide an implementation of a method to get sensor values by source */
virtual std::map<std::string, float> PressureForSources(std::vector<std::string> sources);
/**
* Query the device and update the internal state. This
* method must be called before calling getPressure(),
@ -190,7 +178,7 @@ namespace upm {
/**
* Return latest calculated temperature value in Celsius. See
* iTemperatureSensor.
* ITemperatureSensor.
*
* @return The current temperature in Celsius.
*/
@ -202,7 +190,7 @@ namespace upm {
/**
* Return latest calculated pressure value in Pascals. See
* iPressureSensor.
* IPressureSensor.
*
* @return The current pressure in Pascals.
*/
@ -212,6 +200,16 @@ namespace upm {
return getPressure();
}
/**
* Returns the name of module.
*
* @return The name of the module.
*/
const char *getModuleName()
{
return "BMPX8X";
}
protected:
// our underlying C context.
bmpx8x_context m_bmpx8x;

View File

@ -1,13 +1,23 @@
%include "../common_top.i"
%include "iPressureSensor.i"
%include "iTemperatureSensor.i"
/* BEGIN Java syntax ------------------------------------------------------- */
#ifdef SWIGJAVA
%import "../interfaces/javaupm_iPressureSensor.i"
%typemap(javaimports) SWIGTYPE %{import upm_interfaces.*;%}
%import "../interfaces/javaupm_iTemperatureSensor.i"
JAVA_JNI_LOADLIBRARY(javaupm_bmpx8x)
#endif
/* END Java syntax */
/* BEGIN Python syntax ----------------------------------------------------- */
#ifdef SWIGPYTHON
%include "iModuleStatus.hpp"
%include "iTemperatureSensor.hpp"
%include "iPressureSensor.hpp"
#endif
/* END Python syntax */
/* BEGIN Common SWIG syntax ------------------------------------------------- */
%{
#include "bmpx8x_defs.h"

View File

@ -1,5 +1,5 @@
upm_mixed_module_init (NAME bmx055
DESCRIPTION "Bosch IMU Sensor Library"
CPP_HDR bmx055.hpp bmc150.cxx bmi055.hpp
CPP_HDR bmx055.hpp bmc150.hpp bmi055.hpp
CPP_SRC bmx055.cxx bmc150.cxx bmi055.cxx
REQUIRES mraa bmg160 bma250e bmm150)

View File

@ -42,9 +42,7 @@ button_context button_init(int pin){
return NULL;
}
dev->gpio_pin = pin;
dev->gpio = mraa_gpio_init(dev->gpio_pin);
dev->gpio = mraa_gpio_init(pin);
mraa_gpio_dir(dev->gpio, MRAA_GPIO_IN);
dev->isr_installed = false;

View File

@ -61,7 +61,6 @@
typedef struct _button_context {
mraa_gpio_context gpio;
uint8_t gpio_pin;
bool isr_installed;
} *button_context;

View File

@ -39,8 +39,7 @@ collision_context collision_init(int pin) {
if (!dev)
return NULL;
dev->gpio_pin = pin;
dev->gpio = mraa_gpio_init(dev->gpio_pin);
dev->gpio = mraa_gpio_init(pin);
if(mraa_gpio_dir(dev->gpio, MRAA_GPIO_IN) != MRAA_SUCCESS)
{

View File

@ -45,7 +45,6 @@
*/
typedef struct _collision_context {
mraa_gpio_context gpio;
uint8_t gpio_pin;
} *collision_context;
/**

View File

@ -2,14 +2,15 @@
%include "cpointer.i"
%include "stdint.i"
%include "typemaps.i"
#if SWIGJAVA
%include "java_exceptions.i"
#else
%include "upm_exception.i"
#endif
%import "_upm.i"
/* Import additional SWIG helps (not exposed in wrapper) */
%import _upm.i
%{
#include "version.hpp"
%}
%include "version.hpp"
%apply int { speed_t };
%apply int { mraa_result_t };
@ -34,6 +35,7 @@ void cleanUp()
{;}
}
%}
void cleanUp();
#endif
#if (SWIGJAVA)
@ -41,7 +43,7 @@ void cleanUp()
%typemap(jstype) jobject runnable "java.lang.Runnable"
#endif
/* Disable nested struct warnings */
// Disable nested struct warnings
#pragma SWIG nowarn=312,325
#if SWIGPYTHON

View File

@ -1,11 +0,0 @@
/* Any java package including an interface .i requires an import for
upm_core java package in the JNI source */
%pragma(java) jniclassimports=%{
import upm_core.*;
%}
/* Add the global UPM methods to all wrappers */
%{
#include "../upm_library_globals.hpp"
%}
%include "../upm_library_globals.hpp"

View File

@ -1,13 +0,0 @@
%include ".iSensorType.i"
#if (SWIGJAVA)
#if SWIG_VERSION >= 0x030009
%include "swiginterface.i"
%interface_impl(upm::iADC);
#endif
#endif
%{
#include "iADC.hpp"
%}
%include "iADC.hpp"

Some files were not shown because too many files have changed in this diff Show More