mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 12:21:11 +03:00
Compare commits
49 Commits
cxx-interf
...
v1.7.1
Author | SHA1 | Date | |
---|---|---|---|
16e72d2ff7 | |||
94be00a63d | |||
d5cb613ad0 | |||
c0c37028e4 | |||
eb8d64f52b | |||
1ddf969020 | |||
85608a9f61 | |||
4927311a0c | |||
b50b93272d | |||
ed4fe56ef8 | |||
67b77b78aa | |||
bc01f710ea | |||
1af38e060e | |||
62f84dcc47 | |||
6ae7e9125b | |||
07a9af07fe | |||
89e2ec870a | |||
4935a16530 | |||
9ef90ccb81 | |||
5f2557b159 | |||
09208e90d0 | |||
e0105cb601 | |||
c2ce3e8222 | |||
db3c73cbd1 | |||
be46240b8c | |||
ef81a20140 | |||
8a617aa904 | |||
a16d279b6f | |||
3e84b74bdf | |||
186bbfab76 | |||
01cc3a0734 | |||
09e536b4ff | |||
dc45cd7859 | |||
3790c0bbc1 | |||
7a2332fa7d | |||
330c94f1e2 | |||
9a959b578c | |||
cdfb68c381 | |||
6228498147 | |||
8b4e1020f4 | |||
3a077df5f6 | |||
1b5087105b | |||
ec9143e976 | |||
37642f3b01 | |||
17110d41d0 | |||
dd73c4aa45 | |||
8f63914d76 | |||
306872619a | |||
ad15b27cb1 |
10
.travis.yml
10
.travis.yml
@ -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
|
||||
|
@ -130,7 +130,7 @@ find_package (PkgConfig REQUIRED)
|
||||
|
||||
# Force a libmraa search and minimum required version every time a config is generated
|
||||
unset(MRAA_FOUND CACHE)
|
||||
set(MRAA_MINIMUM 1.9.0)
|
||||
set(MRAA_MINIMUM 2.0.0)
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=${MRAA_MINIMUM})
|
||||
# Also, get full path to the mraa library
|
||||
find_library(MRAA_LIBRARY NAMES mraa HINTS ${MRAA_LIBDIR})
|
||||
@ -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.1")
|
||||
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 ()
|
||||
|
@ -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}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -4,6 +4,22 @@ Changelog {#changelog}
|
||||
Here's a list summarizing some of the key undergoing changes to our library
|
||||
from earlier versions:
|
||||
|
||||
### v1.7.1
|
||||
|
||||
* Bumped library compatibility to new MRAA 2.0 APIs
|
||||
* Added installation details for Fedora
|
||||
* Minor fixes based on static analysis vulnerability report
|
||||
|
||||
### 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 |
@ -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
BIN
docs/images/kxtj3.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
@ -54,6 +54,18 @@ sudo apt-get install libupm-dev libupm-java python-upm python3-upm node-upm upm-
|
||||
Running UPM applications on Ubuntu systems requires elevated permissions
|
||||
(e.g. run with `sudo`).
|
||||
|
||||
### Fedora Linux
|
||||
|
||||
MRAA and UPM are available through the default package repositories on Fedora and can be
|
||||
installed in the standard method using dnf.
|
||||
|
||||
To install:
|
||||
|
||||
```bash
|
||||
sudo dnf install upm
|
||||
sudo dnf install paython3-upm nodejs-upm upm-examples
|
||||
```
|
||||
|
||||
### Node.js bindings only (NPM)
|
||||
|
||||
This option allows compiling MRAA/UPM on any system with npm and node-gyp.
|
||||
|
@ -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.
|
||||
|
||||

|
||||
|
||||
### Building UPM
|
||||
See building documentation [here](https://github.com/intel-iot-devkit/upm/blob/master/docs/building.md).
|
||||
|
||||
|
@ -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``
|
||||
##############################
|
||||
|
||||
|
@ -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® XDK IoT Edition is the recommended IDE for Node.js development.
|
||||
Visit the Intel® 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"
|
||||
|
@ -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
|
||||
|
@ -120,7 +120,7 @@ if(BUILDEXAMPLES)
|
||||
|
||||
# Add all examples as an install component (if building examples)
|
||||
install (DIRECTORY ${PROJECT_SOURCE_DIR}/examples
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm/
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/upm
|
||||
COMPONENT ${CMAKE_PROJECT_NAME}-examples
|
||||
FILES_MATCHING
|
||||
PATTERN "*.c"
|
||||
|
71
examples/c++/bh1749.cxx
Executable file
71
examples/c++/bh1749.cxx
Executable 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
81
examples/c++/bh1792.cxx
Executable 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]
|
73
examples/c++/kxtj3.cxx
Executable file
73
examples/c++/kxtj3.cxx
Executable 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;
|
||||
}
|
@ -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
73
examples/c/bh1749.c
Executable 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
86
examples/c/bh1792.c
Executable 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;
|
||||
}
|
@ -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
75
examples/c/kxtj3.c
Executable 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;
|
||||
}
|
@ -24,8 +24,11 @@
|
||||
|
||||
public class A110X_intr_Example {
|
||||
|
||||
public static int counter=0;
|
||||
private static int counter=0;
|
||||
|
||||
public static void incrementCounter() {
|
||||
counter++;
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//! [Interesting]
|
||||
// Instantiate an A110X sensor on digital pin D2
|
||||
@ -52,6 +55,6 @@ class A110XISR implements Runnable {
|
||||
super();
|
||||
}
|
||||
public void run(){
|
||||
A110X_intr_Example.counter++;
|
||||
A110X_intr_Example.incrementCounter();
|
||||
}
|
||||
}
|
53
examples/java/BH1749_Example.java
Executable file
53
examples/java/BH1749_Example.java
Executable 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]
|
||||
}
|
||||
}
|
69
examples/java/BH1792_Example.java
Executable file
69
examples/java/BH1792_Example.java
Executable 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]
|
@ -24,9 +24,12 @@
|
||||
|
||||
public class Button_intr_Example {
|
||||
|
||||
public static int counter = 0;
|
||||
private static int counter = 0;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
public static void incrementCounter() {
|
||||
counter++;
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_button.Button b = new upm_button.Button(2);
|
||||
|
||||
@ -47,7 +50,7 @@ class ButtonISR implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Button_intr_Example.counter++;
|
||||
Button_intr_Example.incrementCounter();
|
||||
System.out.println("Button pressed!");
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,9 @@ 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)
|
||||
@ -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)
|
||||
|
@ -32,7 +32,7 @@ public class FlexSensor_Example {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -24,8 +24,11 @@
|
||||
|
||||
public class GroveButton_intr_Example {
|
||||
|
||||
public static int counter = 0;
|
||||
private static int counter = 0;
|
||||
|
||||
public static void incrementCounter() {
|
||||
counter++;
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
upm_grove.GroveButton b = new upm_grove.GroveButton(2);
|
||||
@ -47,7 +50,7 @@ class ButtonISR implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
GroveButton_intr_Example.counter++;
|
||||
GroveButton_intr_Example.incrementCounter();
|
||||
System.out.println("Button pressed!");
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ public class GroveQTouch_Example {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
// ! [Interesting]
|
||||
|
49
examples/java/KXTJ3_Example.java
Executable file
49
examples/java/KXTJ3_Example.java
Executable 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,8 +24,11 @@
|
||||
|
||||
public class RPR220_intr_Example {
|
||||
|
||||
public static int counter = 0;
|
||||
private static int counter = 0;
|
||||
|
||||
public static void incrementCounter() {
|
||||
counter++;
|
||||
}
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// ! [Interesting]
|
||||
// This example uses an interrupt handler to increment a counter
|
||||
@ -49,6 +52,6 @@ class RPRISR implements Runnable {
|
||||
super();
|
||||
}
|
||||
public void run() {
|
||||
RPR220_intr_Example.counter++;
|
||||
RPR220_intr_Example.incrementCounter();
|
||||
}
|
||||
}
|
@ -85,7 +85,7 @@ public class WT5001_Example {
|
||||
vol = mp3.getVolume();
|
||||
System.out.println("The current volume is: " + vol);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
@ -93,7 +93,7 @@ public class WT5001_Example {
|
||||
ps = mp3.getPlayState();
|
||||
System.out.println("The current play state is: " + ps);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
@ -101,7 +101,7 @@ public class WT5001_Example {
|
||||
numf = mp3.getNumFiles(upm_wt5001.WT5001.WT5001_PLAYSOURCE_T.SD);
|
||||
System.out.println("The number of files on the SD card is: " + numf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
@ -109,7 +109,7 @@ public class WT5001_Example {
|
||||
curf = mp3.getCurrentFile();
|
||||
System.out.println("The current file is: " + curf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
|
||||
int year[] = new int[1];
|
||||
|
57
examples/javascript/bh1749.js
Executable file
57
examples/javascript/bh1749.js
Executable 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
50
examples/javascript/bh1792.js
Executable 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
54
examples/javascript/kxtj3.js
Executable 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);
|
||||
});
|
60
examples/python/bh1749.py
Executable file
60
examples/python/bh1749.py
Executable 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()
|
58
examples/python/bh1792.py
Executable file
58
examples/python/bh1792.py
Executable file
@ -0,0 +1,58 @@
|
||||
# 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, datetime
|
||||
import sys
|
||||
import signal
|
||||
import atexit
|
||||
from upm import pyupm_bh1792
|
||||
|
||||
def main():
|
||||
bh1792_sensor = pyupm_bh1792.BH1792()
|
||||
bh1792_sensor.SoftReset()
|
||||
bh1792_sensor.EnableSyncMode(256, 32)
|
||||
bh1792_sensor.StartMeasurement()
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
61
examples/python/kxtj3.py
Executable file
61
examples/python/kxtj3.py
Executable 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()
|
@ -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);
|
||||
|
@ -20,5 +20,6 @@ cmake \
|
||||
-DBUILDTESTS=$BUILDTESTS \
|
||||
-DWERROR=$WERROR \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
|
||||
-H. \
|
||||
-Bbuild
|
||||
|
@ -53,6 +53,9 @@ sonar_cmd_base="build-wrapper-linux-x86-64 --out-dir ${bw_output_path} make -j8
|
||||
-Dsonar.inclusions='CMakeLists.txt,examples/**/*,include/**/*,src/**/*,tests/**/*' \
|
||||
-Dsonar.java.binaries='src' \
|
||||
-Dsonar.coverage.exclusions='**/*' \
|
||||
-Dsonar.issue.ignore.multicriteria=r1 \
|
||||
-Dsonar.issue.ignore.multicriteria.r1.ruleKey=squid:S2189 \
|
||||
-Dsonar.issue.ignore.multicriteria.r1.resourceKey=**/*.java \
|
||||
-Dsonar.cfamily.build-wrapper-output=${bw_output_path} \
|
||||
-Dsonar.host.url=https://sonarcloud.io \
|
||||
-Dsonar.organization=${SONAR_ORG} \
|
||||
|
@ -248,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
|
||||
@ -308,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}"
|
||||
@ -821,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)
|
||||
|
@ -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){
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
8
src/bh1749/CMakeLists.txt
Executable file
8
src/bh1749/CMakeLists.txt
Executable 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
702
src/bh1749/bh1749.c
Executable 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, ®_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, ®_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, ®_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 += snprintf(dump, 6, "0x40 ");
|
||||
for(int i = 0; i < len; i++)
|
||||
count += snprintf(dump + count, 4, "%02X ", reg_values[i]);
|
||||
snprintf(dump + count - 1, 3, "\n");
|
||||
|
||||
len = 6;
|
||||
if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
count += snprintf(dump + count, 6, "0x60 ");
|
||||
for(int i = 0; i < len; i++)
|
||||
count += snprintf(dump + count, 4, "%02X ", reg_values[i]);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
304
src/bh1749/bh1749.cxx
Executable file
304
src/bh1749/bh1749.cxx
Executable 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
429
src/bh1749/bh1749.h
Executable 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
345
src/bh1749/bh1749.hpp
Executable 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;
|
||||
};
|
||||
}
|
18
src/bh1749/bh1749.i
Executable file
18
src/bh1749/bh1749.i
Executable file
@ -0,0 +1,18 @@
|
||||
%include "../common_top.i"
|
||||
|
||||
/* BEGIN Java syntax ------------------------------------------------------- */
|
||||
#ifdef SWIGJAVA
|
||||
JAVA_JNI_LOADLIBRARY(javaupm_bh1749)
|
||||
#endif
|
||||
/* END Java syntax */
|
||||
|
||||
/* BEGIN Common SWIG syntax ------------------------------------------------- */
|
||||
%include "std_vector.i"
|
||||
%template(uint16Vector) std::vector<uint16_t>;
|
||||
|
||||
%{
|
||||
#include "bh1749.hpp"
|
||||
%}
|
||||
%include "bh1749.h"
|
||||
%include "bh1749.hpp"
|
||||
/* END Common SWIG syntax */
|
49
src/bh1749/bh1749.json
Executable file
49
src/bh1749/bh1749.json
Executable 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
160
src/bh1749/bh1749_registers.h
Executable 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
|
||||
|
@ -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
|
||||
*
|
||||
|
8
src/bh1792/CMakeLists.txt
Executable file
8
src/bh1792/CMakeLists.txt
Executable 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
889
src/bh1792/bh1792.c
Executable 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, ®_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, ®_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, ®_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 += snprintf(dump, 6, "0x41 ");
|
||||
for(int i = 0; i < len; i++)
|
||||
count += snprintf(dump + count, 4, "%02X ", reg_values[i]);
|
||||
snprintf(dump + count - 1, 3, "\n");
|
||||
|
||||
len = 1;
|
||||
if(bh1792_read_registers(dev, BH1792_FIFO_LEV, reg_values, len) != UPM_SUCCESS)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
count += snprintf(dump + count, 6, "0x4B ");
|
||||
for(int i = 0; i < len; i++)
|
||||
count += snprintf(dump + count, 4, "%02X ", reg_values[i]);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
305
src/bh1792/bh1792.cxx
Executable file
305
src/bh1792/bh1792.cxx
Executable 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, ¤t) != 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, ¤t) != 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
411
src/bh1792/bh1792.h
Executable 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
324
src/bh1792/bh1792.hpp
Executable 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
28
src/bh1792/bh1792.i
Executable 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
62
src/bh1792/bh1792.json
Executable 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
129
src/bh1792/bh1792glc_registers.h
Executable 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
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -61,7 +61,6 @@
|
||||
|
||||
typedef struct _button_context {
|
||||
mraa_gpio_context gpio;
|
||||
uint8_t gpio_pin;
|
||||
bool isr_installed;
|
||||
} *button_context;
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -45,7 +45,6 @@
|
||||
*/
|
||||
typedef struct _collision_context {
|
||||
mraa_gpio_context gpio;
|
||||
uint8_t gpio_pin;
|
||||
} *collision_context;
|
||||
|
||||
/**
|
||||
|
@ -28,9 +28,9 @@ void cleanUp()
|
||||
* See https://codereview.chromium.org/412163003 for this API change
|
||||
*/
|
||||
#if (SWIG_V8_VERSION < 0x032838)
|
||||
while (!v8::V8::IdleNotification())
|
||||
while (!v8::V8::IdleNotificationDeadline())
|
||||
#else
|
||||
while (!v8::Isolate::GetCurrent()->IdleNotification(1000))
|
||||
while (!v8::Isolate::GetCurrent()->IdleNotificationDeadline(1000))
|
||||
#endif
|
||||
{;}
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ int ecezo_send_command(const ecezo_context dev, char *cmd, char *buffer,
|
||||
// our write buffer
|
||||
char writeBuffer[ECEZO_MAX_BUFFER_LEN];
|
||||
|
||||
strncpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN);
|
||||
memcpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN - 1);
|
||||
writeBuffer[ECEZO_MAX_BUFFER_LEN - 1] = 0;
|
||||
|
||||
int writelen = strlen(writeBuffer);
|
||||
|
@ -67,8 +67,8 @@ namespace upm {
|
||||
*
|
||||
* @image html ecs1030.jpg
|
||||
* <br><em>ECS1030 Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
* <a href=https://creativecommons.org/licenses/by/2.0/>
|
||||
* CC BY 2.0</a>.</em>
|
||||
*
|
||||
* @snippet ecs1030.cxx Interesting
|
||||
*/
|
||||
|
@ -51,8 +51,8 @@ namespace upm {
|
||||
*
|
||||
* @image html flex.jpg
|
||||
* <br><em>Flex Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
* <a href=https://creativecommons.org/licenses/by/2.0/>
|
||||
* CC BY 2.0</a>.</em>
|
||||
*
|
||||
* @snippet flex.cxx Interesting
|
||||
*/
|
||||
|
@ -422,6 +422,10 @@ and is not meant to be installed anywhere.
|
||||
@ingroup byman
|
||||
@brief Semtech Corporation
|
||||
|
||||
@defgroup rohm ROHM Semiconductor
|
||||
@ingroup byman
|
||||
@brief ROHM Semiconductor
|
||||
|
||||
|
||||
### Groups for the various Starter Kits ###
|
||||
|
||||
|
@ -44,7 +44,6 @@ GroveUltraSonic::GroveUltraSonic (int pin) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", pin);
|
||||
exit (1);
|
||||
}
|
||||
mraa_gpio_use_mmaped(m_pinCtx, 1);
|
||||
mraa_gpio_isr (m_pinCtx, MRAA_GPIO_EDGE_BOTH,
|
||||
&signalISR, this);
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ float kx122_get_sample_period(const kx122_context dev)
|
||||
{KX122_ODR_12800,128000},{KX122_ODR_25600,25600}
|
||||
};
|
||||
|
||||
uint8_t reg_val;
|
||||
uint8_t reg_val = 0;
|
||||
|
||||
kx122_read_register(dev,KX122_ODCNTL, ®_val);
|
||||
reg_val = reg_val & KX122_ODCNTL_OSA_MASK;
|
||||
|
@ -22,6 +22,8 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
@ -29,6 +31,7 @@ extern "C"{
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/spi.h>
|
||||
|
@ -22,6 +22,8 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <mraa/gpio.hpp>
|
||||
|
||||
|
8
src/kxtj3/CMakeLists.txt
Executable file
8
src/kxtj3/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
upm_mixed_module_init (NAME kxtj3
|
||||
DESCRIPTION "Tri-Axis Accelerometer"
|
||||
C_HDR kxtj3.h kxtj3_registers.h
|
||||
C_SRC kxtj3.c
|
||||
CPP_HDR kxtj3.hpp
|
||||
CPP_SRC kxtj3.cxx
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa utilities-c)
|
1095
src/kxtj3/kxtj3.c
Executable file
1095
src/kxtj3/kxtj3.c
Executable file
File diff suppressed because it is too large
Load Diff
315
src/kxtj3/kxtj3.cxx
Executable file
315
src/kxtj3/kxtj3.cxx
Executable file
@ -0,0 +1,315 @@
|
||||
/*
|
||||
* 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 <string>
|
||||
|
||||
#include "kxtj3.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
KXTJ3::KXTJ3(int bus, uint8_t addr) : m_kxtj3(kxtj3_init(bus, addr))
|
||||
{
|
||||
if (!m_kxtj3)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_init() failed");
|
||||
}
|
||||
|
||||
KXTJ3::~KXTJ3()
|
||||
{
|
||||
kxtj3_close(m_kxtj3);
|
||||
}
|
||||
|
||||
void KXTJ3::SensorInit(KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T resolution, KXTJ3_G_RANGE_T g_range)
|
||||
{
|
||||
if (kxtj3_sensor_init(m_kxtj3, odr, resolution, g_range) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_sensor_init() failed");
|
||||
}
|
||||
|
||||
uint8_t KXTJ3::GetWhoAmI()
|
||||
{
|
||||
uint8_t who_am_i;
|
||||
if (kxtj3_get_who_am_i(m_kxtj3, &who_am_i) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_who_am_i() failed");
|
||||
|
||||
return who_am_i;
|
||||
}
|
||||
|
||||
void KXTJ3::SensorActive()
|
||||
{
|
||||
if (kxtj3_set_sensor_active(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_sensor_active() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SensorStandby()
|
||||
{
|
||||
if (kxtj3_set_sensor_standby(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_sensor_standby() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetGRange(KXTJ3_G_RANGE_T g_range)
|
||||
{
|
||||
if (kxtj3_set_g_range(m_kxtj3, g_range) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_g_range() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetResolution(KXTJ3_RESOLUTION_T resolution)
|
||||
{
|
||||
if (kxtj3_set_resolution(m_kxtj3, resolution) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_resolution() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetOdr(KXTJ3_ODR_T odr)
|
||||
{
|
||||
if (kxtj3_set_odr(m_kxtj3, odr) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_odr() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetOdrForWakeup(KXTJ3_ODR_WAKEUP_T odr)
|
||||
{
|
||||
if (kxtj3_set_odr_wakeup_function(m_kxtj3, odr) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_odr_wakeup_function() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SelfTestDigitalCommunication()
|
||||
{
|
||||
if (kxtj3_self_test_digital_communication(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_self_test_digital_communication() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SensorSelfTest()
|
||||
{
|
||||
if (kxtj3_sensor_self_test(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_sensor_self_test() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SensorSoftwareReset()
|
||||
{
|
||||
if (kxtj3_sensor_software_reset(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_sensor_software_reset() failed");
|
||||
}
|
||||
|
||||
std::vector<float> KXTJ3::GetAccelerationRawVector()
|
||||
{
|
||||
std::vector<float> xyz(3);
|
||||
if (kxtj3_get_acceleration_data_raw(m_kxtj3, &xyz[0], &xyz[1], &xyz[2]) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_acceleration_data_raw() failed");
|
||||
|
||||
return xyz;
|
||||
}
|
||||
|
||||
std::vector<float> KXTJ3::GetAccelerationVector()
|
||||
{
|
||||
std::vector<float> xyz(3);
|
||||
if (kxtj3_get_acceleration_data(m_kxtj3, &xyz[0], &xyz[1], &xyz[2]) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_acceleration_data() failed");
|
||||
|
||||
return xyz;
|
||||
}
|
||||
|
||||
float KXTJ3::GetAccelerationSamplePeriod()
|
||||
{
|
||||
return kxtj3_get_acceleration_sampling_period(m_kxtj3);
|
||||
}
|
||||
|
||||
float KXTJ3::GetWakeUpSamplePeriod()
|
||||
{
|
||||
return kxtj3_get_wakeup_sampling_period(m_kxtj3);
|
||||
}
|
||||
|
||||
void KXTJ3::EnableDataReadyInterrupt()
|
||||
{
|
||||
if (kxtj3_enable_data_ready_interrupt(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_enable_data_ready_interrupt() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::DisableDataReadyInterrupt()
|
||||
{
|
||||
if (kxtj3_disable_data_ready_interrupt(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_disable_data_ready_interrupt() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::EnableWakeUpInterrupt()
|
||||
{
|
||||
if (kxtj3_enable_wakeup_interrupt(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_enable_wakeup_interrupt() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::DisableWakeUpInterrupt()
|
||||
{
|
||||
if (kxtj3_disable_wakeup_interrupt(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_disable_wakeup_interrupt() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::EnableInterruptPin(KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type)
|
||||
{
|
||||
if (kxtj3_enable_interrupt_pin(m_kxtj3, polarity, response_type) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_enable_interrupt_pin() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::DisableInterruptPin()
|
||||
{
|
||||
if (kxtj3_disable_interrupt_pin(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_disable_interrupt_pin() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetInterruptPolarity(KXTJ3_INTERRUPT_POLARITY_T polarity)
|
||||
{
|
||||
if (kxtj3_set_interrupt_polarity(m_kxtj3, polarity) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_interrupt_polarity() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetInerruptResponse(KXTJ3_INTERRUPT_RESPONSE_T response_type)
|
||||
{
|
||||
if (kxtj3_set_interrupt_response(m_kxtj3, response_type) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_interrupt_response() failed");
|
||||
}
|
||||
|
||||
bool KXTJ3::GetInterruptStatus()
|
||||
{
|
||||
return kxtj3_get_interrupt_status(m_kxtj3);
|
||||
}
|
||||
|
||||
uint8_t KXTJ3::ReadInterruptSource1()
|
||||
{
|
||||
uint8_t reg_value;
|
||||
if (kxtj3_read_interrupt_source1_reg(m_kxtj3, ®_value) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_read_interrupt_source1_reg() failed");
|
||||
|
||||
return reg_value;
|
||||
}
|
||||
|
||||
KXTJ3_INTERRUPT_SOURCE_T KXTJ3::GetInterruptSource()
|
||||
{
|
||||
return kxtj3_get_interrupt_source(m_kxtj3);
|
||||
}
|
||||
|
||||
void KXTJ3::InstallIsr(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
|
||||
{
|
||||
if (kxtj3_install_isr(m_kxtj3, edge, pin, isr, isr_args) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_install_isr() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::UninstallIsr()
|
||||
{
|
||||
kxtj3_uninstall_isr(m_kxtj3);
|
||||
}
|
||||
|
||||
void KXTJ3::ClearInterrupt()
|
||||
{
|
||||
if (kxtj3_clear_interrupt_information(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_clear_interrupt_information() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::EnableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis)
|
||||
{
|
||||
if (kxtj3_enable_wakeup_single_axis_direction(m_kxtj3, axis) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_enable_wakeup_single_axis_direction() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::DisableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis)
|
||||
{
|
||||
if (kxtj3_disable_wakeup_single_axis_direction(m_kxtj3, axis) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_disable_wakeup_single_axis_direction() failed");
|
||||
}
|
||||
|
||||
kxtj3_wakeup_axes KXTJ3::GetWakeUpAxisDirection()
|
||||
{
|
||||
return kxtj3_get_wakeup_axis_and_direction(m_kxtj3);
|
||||
}
|
||||
|
||||
void KXTJ3::EnableWakeUpLatch()
|
||||
{
|
||||
if (kxtj3_enable_wakeup_latch(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_enable_wakeup_latch() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::DisableWakeUpLatch()
|
||||
{
|
||||
if (kxtj3_disable_wakeup_latch(m_kxtj3) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_disable_wakeup_latch() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpMotionCounter(uint8_t count)
|
||||
{
|
||||
if (kxtj3_set_wakeup_motion_counter(m_kxtj3, count) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_motion_counter() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpMotionTime(float desired_time)
|
||||
{
|
||||
if (kxtj3_set_wakeup_motion_time(m_kxtj3, desired_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_motion_time() failed");
|
||||
}
|
||||
|
||||
float KXTJ3::GetWakeUpMotionTime()
|
||||
{
|
||||
float out_time;
|
||||
if (kxtj3_get_wakeup_motion_time(m_kxtj3, &out_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_wakeup_motion_time() failed");
|
||||
|
||||
return out_time;
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpNonActivityCounter(uint8_t count)
|
||||
{
|
||||
if (kxtj3_set_wakeup_non_activity_counter(m_kxtj3, count) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_non_activity_counter() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpNonActivityTime(float desired_time)
|
||||
{
|
||||
if (kxtj3_set_wakeup_non_activity_time(m_kxtj3, desired_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_non_activity_time() failed");
|
||||
}
|
||||
|
||||
float KXTJ3::GetWakeUpNonActivityTime()
|
||||
{
|
||||
float out_time;
|
||||
if (kxtj3_get_wakeup_non_activity_time(m_kxtj3, &out_time) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_wakeup_non_activity_time() failed");
|
||||
|
||||
return out_time;
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpThresholdCounter(uint16_t count)
|
||||
{
|
||||
if (kxtj3_set_wakeup_threshold_counter(m_kxtj3, count) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_threshold_counter() failed");
|
||||
}
|
||||
|
||||
void KXTJ3::SetWakeUpThresholdGRange(float g_threshold)
|
||||
{
|
||||
if (kxtj3_set_wakeup_threshold_g_value(m_kxtj3, g_threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_set_wakeup_threshold_g_value() failed");
|
||||
}
|
||||
|
||||
float KXTJ3::GetWakeUpThresholdGRange()
|
||||
{
|
||||
float out_threshold;
|
||||
if (kxtj3_get_wakeup_threshold(m_kxtj3, &out_threshold) != UPM_SUCCESS)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) + "kxtj3_get_wakeup_threshold() failed");
|
||||
|
||||
return out_threshold;
|
||||
}
|
746
src/kxtj3/kxtj3.h
Executable file
746
src/kxtj3/kxtj3.h
Executable file
@ -0,0 +1,746 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <upm.h>
|
||||
|
||||
#include "kxtj3_registers.h"
|
||||
|
||||
/**
|
||||
* @brief C API for the kxtj3 driver
|
||||
* @defgroup kxtj3 libupm-kxtj3
|
||||
* @ingroup Kionix i2c accelerometer
|
||||
*
|
||||
* @include kxtj3.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library kxtj3
|
||||
* @sensor kxtj3
|
||||
* @comname tri-axis accelerometer
|
||||
* @type accelerometer
|
||||
* @man Kionix
|
||||
* @con i2c
|
||||
*
|
||||
* @brief C API for the kxtj3 driver
|
||||
*
|
||||
* @image html kxtj3.png
|
||||
*/
|
||||
|
||||
#define SECOND_IN_MICRO_S 1000000
|
||||
|
||||
/**
|
||||
* @brief Resolution types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LOW_RES,
|
||||
HIGH_RES
|
||||
} KXTJ3_RESOLUTION_T;
|
||||
|
||||
/**
|
||||
* @brief Interrupt polarity types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
ACTIVE_LOW,
|
||||
ACTIVE_HIGH
|
||||
|
||||
} KXTJ3_INTERRUPT_POLARITY_T;
|
||||
|
||||
/**
|
||||
* @brief Interrupt response types
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LATCH_UNTIL_CLEARED,
|
||||
TRANSMIT_ONE_PULSE
|
||||
} KXTJ3_INTERRUPT_RESPONSE_T;
|
||||
|
||||
/**
|
||||
* @brief Interrupt sources
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NO_INTERRUPT,
|
||||
KXTJ3_DATA_READY_INTERRUPT = KXTJ3_INT_SOURCE1_DRDY,
|
||||
KXTJ3_WAKEUP_INTERRUPT = KXTJ3_INT_SOURCE1_WUFS,
|
||||
KXTJ3_DATA_READY_AND_WAKEUP_INT = KXTJ3_INT_SOURCE1_DRDY | KXTJ3_INT_SOURCE1_WUFS
|
||||
} KXTJ3_INTERRUPT_SOURCE_T;
|
||||
|
||||
/**
|
||||
* @brief Acceleration ranges
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KXTJ3_RANGE_2G = KXTJ3_CTRL_REG1_GSEL_2G,
|
||||
KXTJ3_RANGE_4G = KXTJ3_CTRL_REG1_GSEL_4G,
|
||||
KXTJ3_RANGE_8G = KXTJ3_CTRL_REG1_GSEL_8G,
|
||||
KXTJ3_RANGE_8G_14 = KXTJ3_CTRL_REG1_GSEL_8G_14,
|
||||
KXTJ3_RANGE_16G = KXTJ3_CTRL_REG1_GSEL_16G,
|
||||
KXTJ3_RANGE_16G_2 = KXTJ3_CTRL_REG1_GSEL_16G2,
|
||||
KXTJ3_RANGE_16G_3 = KXTJ3_CTRL_REG1_GSEL_16G3,
|
||||
KXTJ3_RANGE_16G_14 = KXTJ3_CTRL_REG1_GSEL_16G_14
|
||||
} KXTJ3_G_RANGE_T;
|
||||
|
||||
/**
|
||||
* @brief Output Data Rates for normal mode
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KXTJ3_ODR_0P781 = KXTJ3_DATA_CTRL_REG_OSA_0P781,
|
||||
KXTJ3_ODR_1P563 = KXTJ3_DATA_CTRL_REG_OSA_1P563,
|
||||
KXTJ3_ODR_3P125 = KXTJ3_DATA_CTRL_REG_OSA_3P125,
|
||||
KXTJ3_ODR_6P25 = KXTJ3_DATA_CTRL_REG_OSA_6P25,
|
||||
KXTJ3_ODR_12P5 = KXTJ3_DATA_CTRL_REG_OSA_12P5,
|
||||
KXTJ3_ODR_25 = KXTJ3_DATA_CTRL_REG_OSA_25,
|
||||
KXTJ3_ODR_50 = KXTJ3_DATA_CTRL_REG_OSA_50,
|
||||
KXTJ3_ODR_100 = KXTJ3_DATA_CTRL_REG_OSA_100,
|
||||
KXTJ3_ODR_200 = KXTJ3_DATA_CTRL_REG_OSA_200,
|
||||
KXTJ3_ODR_400 = KXTJ3_DATA_CTRL_REG_OSA_400,
|
||||
KXTJ3_ODR_800 = KXTJ3_DATA_CTRL_REG_OSA_800,
|
||||
KXTJ3_ODR_1600 = KXTJ3_DATA_CTRL_REG_OSA_1600
|
||||
} KXTJ3_ODR_T;
|
||||
|
||||
/**
|
||||
* @brief Output Data Rates for wake-up function
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KXTJ3_ODR_WAKEUP_0P781 = KXTJ3_CTRL_REG2_OWUF_0P781,
|
||||
KXTJ3_ODR_WAKEUP_1P563 = KXTJ3_CTRL_REG2_OWUF_1P563,
|
||||
KXTJ3_ODR_WAKEUP_3P125 = KXTJ3_CTRL_REG2_OWUF_3P125,
|
||||
KXTJ3_ODR_WAKEUP_6P25 = KXTJ3_CTRL_REG2_OWUF_6P25,
|
||||
KXTJ3_ODR_WAKEUP_12P5 = KXTJ3_CTRL_REG2_OWUF_12P5,
|
||||
KXTJ3_ODR_WAKEUP_25 = KXTJ3_CTRL_REG2_OWUF_25,
|
||||
KXTJ3_ODR_WAKEUP_50 = KXTJ3_CTRL_REG2_OWUF_50,
|
||||
KXTJ3_ODR_WAKEUP_100 = KXTJ3_CTRL_REG2_OWUF_100
|
||||
} KXTJ3_ODR_WAKEUP_T;
|
||||
|
||||
/**
|
||||
* @brief Wake-up source axis and direction
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
X_NEGATIVE = KXTJ3_INT_CTRL_REG2_XNWU,
|
||||
X_POSITIVE = KXTJ3_INT_CTRL_REG2_XPWU,
|
||||
Y_NEGATIVE = KXTJ3_INT_CTRL_REG2_YNWU,
|
||||
Y_POSITIVE = KXTJ3_INT_CTRL_REG2_YPWU,
|
||||
Z_NEGATIVE = KXTJ3_INT_CTRL_REG2_ZNWU,
|
||||
Z_POSITIVE = KXTJ3_INT_CTRL_REG2_ZPWU
|
||||
} KXTJ3_WAKEUP_SOURCE_T;
|
||||
|
||||
/**
|
||||
* @brief Use it to get axis and direction for wake-up function
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool X_NEGATIVE,
|
||||
X_POSITIVE,
|
||||
Y_NEGATIVE,
|
||||
Y_POSITIVE,
|
||||
Z_NEGATIVE,
|
||||
Z_POSITIVE;
|
||||
} kxtj3_wakeup_axes;
|
||||
|
||||
/**
|
||||
* @brief Sensor context
|
||||
*/
|
||||
typedef struct _kxtj3_context
|
||||
{
|
||||
mraa_i2c_context i2c;
|
||||
KXTJ3_RESOLUTION_T res_mode;
|
||||
KXTJ3_G_RANGE_T g_range_mode;
|
||||
float acceleration_scale;
|
||||
KXTJ3_ODR_T odr;
|
||||
float odr_in_sec;
|
||||
KXTJ3_ODR_WAKEUP_T odr_wakeup;
|
||||
float odr_in_sec_wakeup;
|
||||
mraa_gpio_context interrupt_pin;
|
||||
} * kxtj3_context;
|
||||
|
||||
/**
|
||||
@brief KXTJ3 initialization. Sets sensor default values and put it to active state.
|
||||
|
||||
@param bus I2C bus to use
|
||||
@param addr I2C address of the sensor
|
||||
@return The sensor context, or NULL if an error occurs
|
||||
*/
|
||||
kxtj3_context kxtj3_init(int bus, uint8_t addr);
|
||||
|
||||
/**
|
||||
@brief Initializes the sensor with the given resolution and acceleration range
|
||||
|
||||
This gets called during the kxtj3_init(), so it will not need to be called unless the sensor is reset
|
||||
|
||||
Sensor is automatically set into standby mode during the initialization
|
||||
Sensor is set to active mode after initialization
|
||||
|
||||
Be cautious not to set resolution to LOW_RES along with g_range as 14-bits modes
|
||||
|
||||
@param dev The sensor context
|
||||
@param odr Output Data Rate, One of the KXTJ3_ODR_T values
|
||||
@param res Resolution mode, One of the KXTJ3_RESOLUTION_T values. LOW_RES valid only for ODR <= 200 Hz.
|
||||
@param g_range Acceleration range, One of the KXTJ3_G_RANGE_T values
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_sensor_init(const kxtj3_context dev, KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T res, KXTJ3_G_RANGE_T g_range);
|
||||
|
||||
/**
|
||||
@brief Gets "who am I" value of the sensor
|
||||
|
||||
@param dev The sensor context
|
||||
@param data Pointer to a uint8_t variable to store the value
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_get_who_am_i(const kxtj3_context dev, uint8_t *data);
|
||||
|
||||
/**
|
||||
@brief KXTJ3 destructor
|
||||
Closes the I2C context, and removes interrupts
|
||||
Frees memory of the kxtj3_context
|
||||
|
||||
@param dev The sensor context
|
||||
*/
|
||||
void kxtj3_close(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Sets the sensor to active mode
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_sensor_active(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Sets the sensor to the standby mode
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_sensor_standby(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Sets the acceleration range of the sensor
|
||||
|
||||
Sensor needs to be in standby mode when setting the acceleration range value
|
||||
|
||||
Be cautious not to set g_range to 14-bits modes with the resolution being on LOW_RES.
|
||||
If the acceleration range is not compatible with resolution mode, the resolution is set automatically
|
||||
to the compatible value.
|
||||
|
||||
@param dev The sensor context
|
||||
@param g_range One of the KXTJ3_G_RANGE_T values
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_g_range(const kxtj3_context dev, KXTJ3_G_RANGE_T g_range);
|
||||
|
||||
/**
|
||||
@brief Sets the resolution of the sensor. High resolution (14 bits and 12 bits) or low resolution (8 bits).
|
||||
|
||||
LOW_RES valid only for ODR <= 200 Hz
|
||||
|
||||
Be cautious not to set resolution to LOW_RES with the G_RANG being on 14-bits modes.
|
||||
If the resolution mode is not compatible with acceleration range, the resolution is set automatically
|
||||
to the compatible value.
|
||||
|
||||
Sensor needs to be in standby mode when setting the sensor resolution
|
||||
|
||||
@param dev The sensor context
|
||||
@param resolution One of the KXTJ3_RESOLUTION_T values
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_resolution(const kxtj3_context dev, KXTJ3_RESOLUTION_T resolution);
|
||||
|
||||
/**
|
||||
@brief Sets the ODR of the sensor
|
||||
|
||||
Sensor needs to be in standby mode when setting the ODR
|
||||
|
||||
@param dev The sensor context
|
||||
@param odr One of the KXTJ3_ODR_T values
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_odr(const kxtj3_context dev, KXTJ3_ODR_T odr);
|
||||
|
||||
/**
|
||||
@brief Sets the ODR of the wakeup function of the sensor
|
||||
|
||||
Sensor needs to be in standby mode when setting the ODR
|
||||
|
||||
@param dev The sensor context
|
||||
@param odr One of the KXTJ3_ODR_WAKEUP_T values
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_odr_wakeup_function(const kxtj3_context dev, KXTJ3_ODR_WAKEUP_T odr);
|
||||
|
||||
/**
|
||||
@brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
|
||||
CTRL_REG2, then checks the DCST_RESP register for a 0xAA, after the register is read, its
|
||||
value is 0x55 and DCST bit is cleared.
|
||||
|
||||
This function is called by kxtj3_sensor_self_test also
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_self_test_digital_communication(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Performs a self-test of the sensor. The test applies an electrostatic force to the sensor,
|
||||
simulating input acceleration. The test compares samples from all axis before and after
|
||||
applying the electrostatic force to the sensor. If the amount of acceleration increases according
|
||||
to the values defined in TABLE 1 of the datasheet (0.5 g), the test passes.
|
||||
|
||||
The function prints out the values before and during test and the average difference for each axis
|
||||
|
||||
See the datasheet for more information
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_sensor_self_test(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers
|
||||
to pre-defined values.
|
||||
|
||||
You should call kxtj3_sensor_init() after the software reset
|
||||
|
||||
See the datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_sensor_software_reset(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Gets raw accelerometer data from the sensor
|
||||
|
||||
@param dev The sensor context
|
||||
@param x Pointer to a floating point variable to store the x-axis value. Set to NULL if not wanted.
|
||||
@param y Pointer to a floating point variable to store the y-axis value. Set to NULL if not wanted.
|
||||
@param z Pointer to a floating point variable to store the z-axis value. Set to NULL if not wanted.
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_get_acceleration_data_raw(const kxtj3_context dev, float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
@brief Gets converted (m/s^2) accelerometer data from the sensor
|
||||
|
||||
@param dev The sensor context
|
||||
@param x Pointer to a floating point variable to store the x-axis value. Set to NULL if not wanted.
|
||||
@param y Pointer to a floating point variable to store the y-axis value. Set to NULL if not wanted.
|
||||
@param z Pointer to a floating point variable to store the z-axis value. Set to NULL if not wanted.
|
||||
*/
|
||||
upm_result_t kxtj3_get_acceleration_data(const kxtj3_context dev, float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
@brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
|
||||
the sampling rate of the sensor
|
||||
|
||||
@param dev The sensor context
|
||||
@return Floating point value of the sampling period
|
||||
*/
|
||||
float kxtj3_get_acceleration_sampling_period(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
Gets the duration of one sample period (in seconds) for the wakeup function depending on
|
||||
the sampling rate of the sensor wakeup function
|
||||
|
||||
@param dev The sensor context
|
||||
@return Floating point value of the sampling period
|
||||
*/
|
||||
float kxtj3_get_wakeup_sampling_period(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Enables the data ready interrupt. Availability of new acceleration data is
|
||||
reflected as an interrupt.
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_enable_data_ready_interrupt(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Disables the data ready interrupt
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_disable_data_ready_interrupt(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Enables the wakeup function (motion detection)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_enable_wakeup_interrupt(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Disables the wakeup function (motion detection)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_disable_wakeup_interrupt(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Enables interrupts on the interrupt pin, sets polarity and response types
|
||||
|
||||
Polarity ACTIVE_HIGH or ACTIVE_LOW
|
||||
|
||||
Response either latch until cleared by reading INT_REL register, or transmit one pulse
|
||||
Pulse width of 0.03-0.05ms
|
||||
|
||||
For Wakeup function, the response type is always latched unless set wakeup latch off
|
||||
|
||||
Sensor needs to be in standby mode when enabling the interrupt
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
|
||||
@param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_enable_interrupt_pin(const kxtj3_context dev, KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type);
|
||||
|
||||
/**
|
||||
@brief Disables interrupts on the interrupt pin of the sensor
|
||||
|
||||
Sensor needs to be in standby mode when disabling the interrupt pin
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_disable_interrupt_pin(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Sets the polarity of the interrupt pin
|
||||
|
||||
Polarity ACTIVE_HIGH or ACTIVE_LOW
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_interrupt_polarity(const kxtj3_context dev, KXTJ3_INTERRUPT_POLARITY_T polarity);
|
||||
|
||||
/**
|
||||
@brief Sets the response type of the interrupt pin
|
||||
|
||||
Response either latch until cleared by reading INT_REL register, or transmit one pulse
|
||||
Pulse width of 0.03-0.05ms
|
||||
|
||||
For Wakeup function, the response type is always latched unless set wakeup latch off
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_interrupt_response(const kxtj3_context dev, KXTJ3_INTERRUPT_RESPONSE_T response_type);
|
||||
|
||||
/**
|
||||
@brief Gets the status of the interrupts. (Has an interrupt occurred).
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@return Return true if an interrupt event has occurred (DRDY or WUFS is 1), returns false if no interrupts have occurred
|
||||
*/
|
||||
bool kxtj3_get_interrupt_status(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Gets the source of the interrupt
|
||||
The value stored is one or more of the KXTJ3_INTERRUPT_SOURCE_T values
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param reg_value Pointer to a uint8_t variable to store the value
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_read_interrupt_source1_reg(const kxtj3_context dev, uint8_t *reg_value);
|
||||
|
||||
/**
|
||||
@brief Gets the source of the interrupt
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@return One of the KXTJ3_INTERRUPT_SOURCE_T values/types
|
||||
*/
|
||||
KXTJ3_INTERRUPT_SOURCE_T kxtj3_get_interrupt_source(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin
|
||||
|
||||
@param dev The sensor context
|
||||
@param edge One of the mraa_gpio_edge_t values, Interrupt trigger edge
|
||||
@param pin The GPIO pin to use as the interrupt pin
|
||||
@param isr Pointer to the function to be called, when the interrupt occurs
|
||||
@param isr_args The arguments to be passed to the function
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_install_isr(const kxtj3_context dev, mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
@brief Uninstalls a previously installed interrupt handler for interrupt pin
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
void kxtj3_uninstall_isr(const kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Clears latching interrupts information of Wakeup (with axis and direction information) and Data Ready
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_clear_interrupt_information(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Enables wakeup interrupt for the given axis (axis with direction)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@param axis The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_enable_wakeup_single_axis_direction(kxtj3_context dev, KXTJ3_WAKEUP_SOURCE_T axis);
|
||||
|
||||
/**
|
||||
@brief Disables wakeup interrupt for the given axis (axis with direction)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@param axis The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_disable_wakeup_single_axis_direction(kxtj3_context dev, KXTJ3_WAKEUP_SOURCE_T axis);
|
||||
|
||||
/**
|
||||
@brief Gets the source axis and direction of motion detection of the wakeup function interrupt
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@return A kxtj3_wakeup_axes struct with values of true/false for a wakeup for each axis and its direction
|
||||
*/
|
||||
kxtj3_wakeup_axes kxtj3_get_wakeup_axis_and_direction(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
|
||||
|
||||
When this bit is set, the wakeup interrupt has to be cleared manually
|
||||
(cannot use interrupt response with pulse)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_enable_wakeup_latch(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled
|
||||
(cannot use interrupt response with pulse).
|
||||
|
||||
The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
|
||||
an almost continuous manner
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
When this bit is cleared, and the interrupt response type is set to Pulse, then upon a wakeup event
|
||||
the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
|
||||
output will not reset until data is read or interrupt cleared.
|
||||
|
||||
@param dev The sensor context
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_disable_wakeup_latch(kxtj3_context dev);
|
||||
|
||||
/**
|
||||
@brief Sets the timer counter of motion before sending a wakeup interrupt
|
||||
|
||||
The count is limited to values from 1 to 255
|
||||
|
||||
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY
|
||||
is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param count The timer count from 1 to 255
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_motion_counter(kxtj3_context dev, uint8_t count);
|
||||
|
||||
/**
|
||||
@brief Sets the timer of motion before sending a wakeup interrupt
|
||||
|
||||
the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param desired_time The desired time in seconds
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_motion_time(kxtj3_context dev, float desired_time);
|
||||
|
||||
/**
|
||||
@brief Gets the current count value of the timer of motion before sending a wakeup interrupt
|
||||
|
||||
@param dev The sensor context
|
||||
@param out_time Pointer to a float variable to store the time value in seconds
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_get_wakeup_motion_time(kxtj3_context dev, float *out_time);
|
||||
|
||||
/**
|
||||
@brief Sets the timer counter of non-activity before sending another wakeup interrupt
|
||||
|
||||
The count is limited to values from 1 to 255
|
||||
|
||||
Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY
|
||||
is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param count The timer count from 1 to 255
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_non_activity_counter(kxtj3_context dev, uint8_t count);
|
||||
|
||||
/**
|
||||
@brief Sets the timer of non-activity before sending another wakeup interrupt
|
||||
|
||||
the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param desired_time The desired time in seconds
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_non_activity_time(kxtj3_context dev, float desired_time);
|
||||
|
||||
/**
|
||||
@brief Gets the current count value of the timer of non-activity before sending another wakeup interrupt
|
||||
|
||||
@param dev The sensor context
|
||||
@param out_time Pointer to a float variable to store the time value in seconds
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_get_wakeup_non_activity_time(kxtj3_context dev, float *out_time);
|
||||
|
||||
/**
|
||||
@brief Sets the threshold counter for acceleration difference before sending a wakeup interrupt
|
||||
|
||||
The count is limited to values from 1 to 4096, that it is 16g threshold with (3.9mg/count)
|
||||
It is advised to not set the threshold to a very low value which may cause bad behaviour
|
||||
in the wakeup interrupt
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param count The timer count from 1 to 4096, that it is 16g threshold with (3.9mg/count)
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_threshold_counter(kxtj3_context dev, uint16_t count);
|
||||
|
||||
/**
|
||||
@brief Sets the threshold g value for acceleration difference before sending a wakeup interrupt
|
||||
|
||||
The count is limited to values up to 16g, with steps of 3.9mg. It is advised to not set
|
||||
the threshold to a very low value which may cause bad behaviour in the wakeup interrupt
|
||||
|
||||
Sensor must be in standby mode before performing this action
|
||||
|
||||
See datasheet for more details
|
||||
|
||||
@param dev The sensor context
|
||||
@param g_threshold The acceleration threshold (in g) in g, from 3.9mg to 16g, steps of 3.9mg/count
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_set_wakeup_threshold_g_value(kxtj3_context dev, float g_threshold);
|
||||
|
||||
/**
|
||||
@brief Gets the current threshold difference value before sending wakeup interrupt
|
||||
|
||||
@param dev The sensor context
|
||||
@param out_threshold Pointer to a float variable to store the threshold value in g
|
||||
@return UPM result
|
||||
*/
|
||||
upm_result_t kxtj3_get_wakeup_threshold(kxtj3_context dev, float *out_threshold);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
565
src/kxtj3/kxtj3.hpp
Executable file
565
src/kxtj3/kxtj3.hpp
Executable file
@ -0,0 +1,565 @@
|
||||
/*
|
||||
* 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 <mraa/gpio.hpp>
|
||||
|
||||
#include "kxtj3.h"
|
||||
|
||||
/**
|
||||
* @brief C API for the kxtj3 driver
|
||||
* @defgroup kxtj3 libupm-kxtj3
|
||||
* @ingroup Kionix i2c accelerometer
|
||||
*
|
||||
* @include kxtj3.cxx
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library kxtj3
|
||||
* @sensor kxtj3
|
||||
* @comname tri-axis accelerometer
|
||||
* @type accelerometer
|
||||
* @man Kionix
|
||||
* @con i2c
|
||||
*
|
||||
* @brief C++ API for the kxtj3 driver
|
||||
*
|
||||
* @image html kxtj3.png
|
||||
*/
|
||||
|
||||
namespace upm
|
||||
{
|
||||
class KXTJ3
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief KXTJ3 constructor
|
||||
*
|
||||
* If no errors occur, the device is initialized with default values and set to active state
|
||||
*
|
||||
* @param bus I2C bus
|
||||
* @param addr I2C address of the sensor
|
||||
* @throws std::runtime_error on initialization failure
|
||||
*/
|
||||
KXTJ3(int bus, uint8_t addr = 0x0f);
|
||||
|
||||
/**
|
||||
* @brief KXTJ3 destructor
|
||||
*
|
||||
* Closes the I2C context, and removes interrupts
|
||||
* Frees memory of the kxtj3_context
|
||||
*
|
||||
* @throws std::runtime_error on initialization failure
|
||||
*/
|
||||
virtual ~KXTJ3();
|
||||
|
||||
/**
|
||||
* @brief Initializes the sensor with given sampling rate, resolution and acceleration range.
|
||||
* This gets called in the constructor, so it will not need to be called unless the device is reset.
|
||||
*
|
||||
* Sensor is set to standby mode during the initialization and back to active after initialization.
|
||||
*
|
||||
* @param odr One of the KXTJ3_ODR_T values
|
||||
* @param resolution One of the KXTJ3_RESOLUTION_T values
|
||||
* @param g_range One of the KXTJ3_G_RANGE_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SensorInit(KXTJ3_ODR_T odr, KXTJ3_RESOLUTION_T resolution, KXTJ3_G_RANGE_T g_range);
|
||||
|
||||
/**
|
||||
* @brief Gets "who am I" value of the sensor
|
||||
*
|
||||
* @return Who am I value of the sensor
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
uint8_t GetWhoAmI();
|
||||
|
||||
/**
|
||||
* @brief Sets the sensor to active mode
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SensorActive();
|
||||
|
||||
/**
|
||||
* @brief Sets the sensor to standby mode
|
||||
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SensorStandby();
|
||||
|
||||
/**
|
||||
* @brief Sets the acceleration range of the sensor
|
||||
*
|
||||
* Sensor needs to be in standby mode when setting the acceleration range value
|
||||
*
|
||||
* Be cautious not to set g_range to 14-bits modes with the resolution being on LOW_RES
|
||||
*
|
||||
* @param g_range One of the KXTJ3_G_RANGE_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetGRange(KXTJ3_G_RANGE_T g_range);
|
||||
|
||||
/**
|
||||
* @brief Sets the resolution of the sensor. High resolution (14 bits and 12 bits) or low resolution (8 bits).
|
||||
*
|
||||
* LOW_RES valid only for ODR <= 200 Hz
|
||||
*
|
||||
* Be cautious not to set resolution to LOW_RES with the G_RANG being on 14-bits modes
|
||||
*
|
||||
* Sensor needs to be in standby mode when setting the sensor resolution
|
||||
*
|
||||
* @param resolution One of the KXTJ3_RESOLUTION_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetResolution(KXTJ3_RESOLUTION_T resolution);
|
||||
|
||||
/**
|
||||
* @brief Sets the ODR of the sensor
|
||||
*
|
||||
* Sensor needs to be in standby mode when setting the ODR
|
||||
*
|
||||
* @param odr One of the KXTJ3_ODR_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetOdr(KXTJ3_ODR_T odr);
|
||||
|
||||
/**
|
||||
* @brief Sets the ODR of the wakeup function of the sensor
|
||||
*
|
||||
* Sensor needs to be in standby mode when setting the ODR
|
||||
*
|
||||
* @param odr One of the KXTJ3_ODR_WAKEUP_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetOdrForWakeup(KXTJ3_ODR_WAKEUP_T odr);
|
||||
|
||||
/**
|
||||
* @brief Performs a self-test for digital communication of the sensor. The test sets DCST bit in
|
||||
* CTRL_REG2, then checks the DCST_RESP register for a 0xAA, after the register is read, its
|
||||
* value is 0x55 and DCST bit is cleared.
|
||||
*
|
||||
* This method is called by SensorSelfTest also
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SelfTestDigitalCommunication();
|
||||
|
||||
/**
|
||||
* @brief Performs a self-test of the sensor. The test applies an electrostatic force to the sensor,
|
||||
* simulating input acceleration. The test compares samples from all axis before and after
|
||||
* applying the electrostatic force to the sensor. If the amount of acceleration increases according
|
||||
* to the values defined in TABLE 1 of the datasheet (0.5 g), the test passes.
|
||||
*
|
||||
* The method prints out the values before and during test and the average difference for each axis
|
||||
*
|
||||
* See the datasheet for more information
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SensorSelfTest();
|
||||
|
||||
/**
|
||||
* @brief Performs a sensor software reset. The software reset clears the RAM of the sensor and resets all registers
|
||||
* to pre-defined values.
|
||||
*
|
||||
* You should call kxtj3_sensor_init() after the software reset
|
||||
*
|
||||
* See the datasheet for more details
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SensorSoftwareReset();
|
||||
|
||||
/**
|
||||
* Gets raw acceleration data from the sensor.
|
||||
*
|
||||
* @return Acceleration vector [x, y, z]
|
||||
* @throws std::runtime_error on failure.
|
||||
*/
|
||||
std::vector<float> GetAccelerationRawVector();
|
||||
|
||||
/**
|
||||
* Gets acceleration data in (m/s^2) from the sensor.
|
||||
*
|
||||
* @return Acceleration vector [x, y, z]
|
||||
* @throws std::runtime_error on failure.
|
||||
*/
|
||||
std::vector<float> GetAccelerationVector();
|
||||
|
||||
/**
|
||||
* @brief Gets the duration of one sample period (in seconds) for getting the acceleration data depending on
|
||||
* the sampling rate of the sensor
|
||||
*
|
||||
* @return Floating point value of the sampling period
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
float GetAccelerationSamplePeriod();
|
||||
|
||||
/**
|
||||
* @brief Gets the duration of one sample period (in seconds) for the wakeup function depending on
|
||||
* the sampling rate of the sensor wakeup function
|
||||
*
|
||||
* @return Floating point value of the sampling period
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
float GetWakeUpSamplePeriod();
|
||||
|
||||
/**
|
||||
* @brief Enables the data ready interrupt. Availability of new acceleration data is
|
||||
* reflected as an interrupt.
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void EnableDataReadyInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Disables the data ready interrupt
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void DisableDataReadyInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Enables the wakeup function (motion detection)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void EnableWakeUpInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Disables the wakeup function (motion detection)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void DisableWakeUpInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Enables interrupts on the interrupt pin, sets polarity and response types.
|
||||
* Polarity ACTIVE_HIGH or ACTIVE_LOW.
|
||||
* Response either latch until cleared by reading INT_REL register, or transmit one pulse
|
||||
* Pulse width of 0.03-0.05ms.
|
||||
*
|
||||
* For Wakeup function, the response type is always latched unless set wakeup latch off
|
||||
* Sensor needs to be in standby mode when enabling the interrupt
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
|
||||
* @param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values.
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void EnableInterruptPin(KXTJ3_INTERRUPT_POLARITY_T polarity, KXTJ3_INTERRUPT_RESPONSE_T response_type);
|
||||
|
||||
/**
|
||||
* @brief Disables interrupts on the interrupt pin of the sensor
|
||||
*
|
||||
* Sensor needs to be in standby mode when disabling the interrupt pin
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void DisableInterruptPin();
|
||||
|
||||
/**
|
||||
* @brief Sets the polarity of the interrupt pin
|
||||
*
|
||||
* Polarity ACTIVE_HIGH or ACTIVE_LOW
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @param polarity Select the polarity of the interrupt. One of the KXTJ3_INTERRUPT_POLARITY_T values.
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetInterruptPolarity(KXTJ3_INTERRUPT_POLARITY_T polarity);
|
||||
|
||||
/**
|
||||
* @brief Sets the response type of the interrupt pin
|
||||
*
|
||||
* Response either latch until cleared by reading INT_REL register, or transmit one pulse
|
||||
* Pulse width of 0.03-0.05ms
|
||||
*
|
||||
* For Wakeup function, the response type is always latched unless set wakeup latch off
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param response_type Select the response type of the interrupt. One of the KXTJ3_INTERRUPT_RESPONSE_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetInerruptResponse(KXTJ3_INTERRUPT_RESPONSE_T response_type);
|
||||
|
||||
/**
|
||||
* @brief Gets the status of the interrupts. (Has an interrupt occurred)
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @return Return true if an interrupt event has occurred (DRDY or WUFS is 1),
|
||||
* returns false if no interrupts have occurred
|
||||
*/
|
||||
bool GetInterruptStatus();
|
||||
|
||||
/**
|
||||
* @brief Gets the source of the interrupt
|
||||
* The value stored is one or more of the KXTJ3_INTERRUPT_SOURCE_T values
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @return Value of the interrupt source register
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
uint8_t ReadInterruptSource1();
|
||||
|
||||
/**
|
||||
* @brief Gets the source of the interrupt
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @return One of the KXTJ3_INTERRUPT_SOURCE_T values/types
|
||||
*/
|
||||
KXTJ3_INTERRUPT_SOURCE_T GetInterruptSource();
|
||||
|
||||
/**
|
||||
* @brief Installs an interrupt handler to be executed when an interrupt is detected on the interrupt pin
|
||||
|
||||
* @param edge One of the mraa_gpio_edge_t values. Interrupt trigger edge.
|
||||
* @param pin The GPIO pin to use as the interrupt pin
|
||||
* @param isr Pointer to the method to be called, when the interrupt occurs
|
||||
* @param isr_args The arguments to be passed to the method
|
||||
* @return std::runtime_error on failure
|
||||
*/
|
||||
void InstallIsr(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
|
||||
|
||||
/**
|
||||
* @brief Uninstalls a previously installed interrupt handler for interrupt pin
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void UninstallIsr();
|
||||
|
||||
/**
|
||||
* @brief Clears latching interrupts information of Wakeup (with axis and direction information) and Data Ready
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void ClearInterrupt();
|
||||
|
||||
/**
|
||||
* @brief Enables wakeup interrupt for the given axis (axis with direction)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @param axis The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void EnableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis);
|
||||
|
||||
/**
|
||||
* @brief Disables wakeup interrupt for the given axis (axis with direction)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @param axis The axis to enable, takes one of KXTJ3_WAKEUP_SOURCE_T value
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void DisableWakeUpSingleAxisDirection(KXTJ3_WAKEUP_SOURCE_T axis);
|
||||
|
||||
/**
|
||||
* @brief Gets the source axis and direction of motion detection of the wakeup function interrupt
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @return A kxtj3_wakeup_axes struct with values of true/false
|
||||
* for a wakeup for each axis and its direction
|
||||
*/
|
||||
kxtj3_wakeup_axes GetWakeUpAxisDirection();
|
||||
|
||||
/**
|
||||
* @brief Enables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
|
||||
*
|
||||
* When this bit is set, the wakeup interrupt has to be cleared manually
|
||||
* (cannot use interrupt response with pulse)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void EnableWakeUpLatch();
|
||||
|
||||
/**
|
||||
* @brief Disables the Unlatched mode motion interrupt (ULMODE). This mode is always by default enabled.
|
||||
* (cannot use interrupt response with pulse)
|
||||
*
|
||||
* The wakeup threshold is advised to not be very low to avoid interrupt being triggered in
|
||||
* an almost continuous manner
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* When this bit is cleared, and the interrupt response type is set to Pulse, then upon a wakeup event
|
||||
* the wakeup interrupt signal will pulse and return low, but only once. Then, the interrupt
|
||||
* output will not reset until data is read or interrupt cleared.
|
||||
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void DisableWakeUpLatch();
|
||||
|
||||
/**
|
||||
* @brief Sets the timer counter of motion before sending a wakeup interrupt
|
||||
*
|
||||
* The count is limited to values from 1 to 255
|
||||
*
|
||||
* Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY
|
||||
* is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param count The timer count from 1 to 255
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpMotionCounter(uint8_t count);
|
||||
|
||||
/**
|
||||
* @brief Sets the timer of motion before sending a wakeup interrupt
|
||||
*
|
||||
* the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param desired_time The desired time in seconds
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpMotionTime(float desired_time);
|
||||
|
||||
/**
|
||||
* @brief Get the current count value of the timer of motion before sending a wakeup interrupt
|
||||
*
|
||||
* @return Time value in seconds
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
float GetWakeUpMotionTime();
|
||||
|
||||
/**
|
||||
* @brief Sets the timer counter of non-activity before sending another wakeup interrupt
|
||||
*
|
||||
* The count is limited to values from 1 to 255
|
||||
*
|
||||
* Every count is calculated as (1 / Wakeup_ODR_FREQUENCY) where Wakeup_ODR_FREQUENCY
|
||||
* is the current odr_in_Hz value from odr_map_in_Hz_wakeup value
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param count The timer count from 1 to 255
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpNonActivityCounter(uint8_t count);
|
||||
|
||||
/**
|
||||
* @brief Sets the timer of non-activity before sending another wakeup interrupt
|
||||
*
|
||||
* the desired time should be such that (0 < desired_time * wakeup_odr_frequency <= 255)
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param desired_time The desired time in seconds
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpNonActivityTime(float desired_time);
|
||||
|
||||
/**
|
||||
* @brief Get the current count value of the timer of non-activity before sending another wakeup interrupt
|
||||
*
|
||||
* @return Time value in seconds
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
float GetWakeUpNonActivityTime();
|
||||
|
||||
/**
|
||||
* @brief Sets the threshold counter for acceleration difference before sending a wakeup interrupt
|
||||
*
|
||||
* The count is limited to values from 1 to 4096, that it is 16g threshold with (3.9mg/count)
|
||||
* It is advised to not set the threshold to a very low value which may cause bad behaviour
|
||||
* in the wakeup interrupt
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param count The timer count from 1 to 4096, that it is 16g threshold with (3.9mg/count)
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpThresholdCounter(uint16_t count);
|
||||
|
||||
/**
|
||||
* @brief Sets the threshold g value for acceleration difference before sending a wakeup interrupt
|
||||
*
|
||||
* The count is limited to values up to 16g, with steps of 3.9mg. It is advised to not set
|
||||
* the threshold to a very low value which may cause bad behaviour in the wakeup interrupt
|
||||
*
|
||||
* Sensor must be in standby mode before performing this action
|
||||
*
|
||||
* See datasheet for more details
|
||||
*
|
||||
* @param g_threshold The acceleration threshold (in g) in g, from 3.9mg to 16g, steps of 3.9mg/count.
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void SetWakeUpThresholdGRange(float g_threshold);
|
||||
|
||||
/**
|
||||
* @brief Get the current threshold difference value before sending wakeup interrupt
|
||||
*
|
||||
* @return Threshold value in g
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
float GetWakeUpThresholdGRange();
|
||||
|
||||
private:
|
||||
kxtj3_context m_kxtj3;
|
||||
|
||||
/* Disable implicit copy and assignment operators */
|
||||
KXTJ3(const KXTJ3 &) = delete;
|
||||
KXTJ3 &operator=(const KXTJ3 &) = delete;
|
||||
};
|
||||
} // namespace upm
|
20
src/kxtj3/kxtj3.i
Normal file
20
src/kxtj3/kxtj3.i
Normal file
@ -0,0 +1,20 @@
|
||||
%include "../common_top.i"
|
||||
|
||||
/* BEGIN Java syntax ------------------------------------------------------- */
|
||||
#ifdef SWIGJAVA
|
||||
JAVA_JNI_LOADLIBRARY(javaupm_kxtj3)
|
||||
#endif
|
||||
/* END Java syntax */
|
||||
|
||||
/* BEGIN Common SWIG syntax ------------------------------------------------- */
|
||||
%include "std_vector.i"
|
||||
%template(floatVector) std::vector<float>;
|
||||
|
||||
%apply float *OUTPUT {float *x, float *y, float *z};
|
||||
|
||||
%{
|
||||
#include "kxtj3.hpp"
|
||||
%}
|
||||
%include "kxtj3.h"
|
||||
%include "kxtj3.hpp"
|
||||
/* END Common SWIG syntax */
|
72
src/kxtj3/kxtj3.json
Executable file
72
src/kxtj3/kxtj3.json
Executable file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"Library": "KXTJ3",
|
||||
"Description": "Kionix KXTJ3 tri-axis accelerometer sensor library",
|
||||
"Sensor Class": {
|
||||
"KXTJ3": {
|
||||
"Name": "Kionix KXTJ3 tri-axis accelerometer sensor",
|
||||
"Description": "This is the UPM Module for the Kionix KXTJ3 accelerometer sensor. The Kionix KXTJ3 sensor is a multifunctional sensor that provides multiple functionalities. The sensor provides an extended g-range up to +/- 16g, higher resolution embedded wake-up function down to 3.9mg, and a flexible interrupt circuitry. The KXTJ3 sense element offers lower noise performance, exceptional shock resiliency, stable performance over temperature, and virtually eliminates offset and sensitivity shifts from reflow.",
|
||||
"Categories": [
|
||||
"acceleration"
|
||||
],
|
||||
"Connections": [
|
||||
"i2c"
|
||||
],
|
||||
"Project Type": [
|
||||
"prototyping",
|
||||
"commercial"
|
||||
],
|
||||
"Manufacturers": [
|
||||
"Kionix"
|
||||
],
|
||||
"Image": "kxtj3.png",
|
||||
"Examples": {
|
||||
"C++": [
|
||||
"kxtj3.cxx"
|
||||
],
|
||||
"C": [
|
||||
"kxtj3.c"
|
||||
],
|
||||
"Java": [
|
||||
"KXTJ3_Example.java"
|
||||
],
|
||||
"Python": [
|
||||
"kxtj3.py"
|
||||
],
|
||||
"Node.js": [
|
||||
"kxtj3.js"
|
||||
]
|
||||
},
|
||||
"Specifications": {
|
||||
"Supply Voltage (VDD)": {
|
||||
"unit": "V",
|
||||
"min": 1.71,
|
||||
"typical": 2.5,
|
||||
"max": 3.6
|
||||
},
|
||||
"I/O Pads Supply Voltage (IO_VDD)": {
|
||||
"unit": "V",
|
||||
"min": 1.7,
|
||||
"max": 3.6
|
||||
},
|
||||
"Supply Current": {
|
||||
"unit": "uA",
|
||||
"min": 0.9,
|
||||
"max": 155
|
||||
},
|
||||
"Operating Temperature": {
|
||||
"unit": "°C",
|
||||
"min": -40,
|
||||
"max": 85
|
||||
}
|
||||
},
|
||||
"Urls": {
|
||||
"Product Pages": [
|
||||
"http://www.kionix.com/product/KXTJ3-1057"
|
||||
],
|
||||
"Datasheets": [
|
||||
"http://kionixfs.kionix.com/en/datasheet/KXTJ3-1057-Specifications-Rev-3.0.pdf"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
204
src/kxtj3/kxtj3_registers.h
Executable file
204
src/kxtj3/kxtj3_registers.h
Executable file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2017 Kionix Inc.
|
||||
|
||||
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 __KXTJ3_REGISTERS_H__
|
||||
#define __KXTJ3_REGISTERS_H__
|
||||
/* registers */
|
||||
// output register x
|
||||
#define KXTJ3_XOUT_L 0x06
|
||||
#define KXTJ3_XOUT_H 0x07
|
||||
// output register y
|
||||
#define KXTJ3_YOUT_L 0x08
|
||||
#define KXTJ3_YOUT_H 0x09
|
||||
// output register z
|
||||
#define KXTJ3_ZOUT_L 0x0A
|
||||
#define KXTJ3_ZOUT_H 0x0B
|
||||
// This register can be used to verify proper integrated circuit functionality
|
||||
#define KXTJ3_DCST_RESP 0x0C
|
||||
// This register can be used for supplier recognition, as it can be factory written to a known byte value.
|
||||
#define KXTJ3_WHO_AM_I 0x0F
|
||||
// This register reports which function caused an interrupt.
|
||||
#define KXTJ3_INT_SOURCE1 0x16
|
||||
// This register reports the axis and direction of detected motion
|
||||
#define KXTJ3_INT_SOURCE2 0x17
|
||||
// This register reports the status of the interrupt
|
||||
#define KXTJ3_STATUS_REG 0x18
|
||||
#define KXTJ3_INT_REL 0x1A
|
||||
// Read/write control register that controls the main feature set
|
||||
#define KXTJ3_CTRL_REG1 0x1B
|
||||
// Read/write control register that provides more feature set control
|
||||
#define KXTJ3_CTRL_REG2 0x1D
|
||||
// This register controls the settings for the physical interrupt pin
|
||||
#define KXTJ3_INT_CTRL_REG1 0x1E
|
||||
// This register controls which axis and direction of detected motion can cause an interrupt
|
||||
#define KXTJ3_INT_CTRL_REG2 0x1F
|
||||
// Read/write control register that configures the acceleration outputs
|
||||
#define KXTJ3_DATA_CTRL_REG 0x21
|
||||
#define KXTJ3_WAKEUP_COUNTER 0x29
|
||||
#define KXTJ3_NA_COUNTER 0x2A
|
||||
// When 0xCA is written to this register, the MEMS self-test function is enabled
|
||||
#define KXTJ3_SELF_TEST 0x3A
|
||||
#define KXTJ3_WAKEUP_THRESHOLD_H 0x6A
|
||||
#define KXTJ3_WAKEUP_THRESHOLD_L 0x6B
|
||||
// This register can be used for supplier recognition, as it can be factory written to a known byte value.
|
||||
#define KXCJC_WHO_AM_I 0x0F
|
||||
/* registers bits */
|
||||
// before set
|
||||
#define KXTJ3_DCST_RESP_DCSTR_BEFORE (0x55 << 0)
|
||||
// after set
|
||||
#define KXTJ3_DCST_RESP_DCSTR_AFTER (0xAA << 0)
|
||||
// WHO_AM_I -value for KXTJ3
|
||||
#define KXTJ3_WHO_AM_I_WIA_ID (0x35 << 0)
|
||||
// indicates that new acceleration data
|
||||
#define KXTJ3_INT_SOURCE1_DRDY (0x01 << 4)
|
||||
// Wake up
|
||||
#define KXTJ3_INT_SOURCE1_WUFS (0x01 << 1)
|
||||
// x-
|
||||
#define KXTJ3_INT_SOURCE2_XNWU (0x01 << 5)
|
||||
// x+
|
||||
#define KXTJ3_INT_SOURCE2_XPWU (0x01 << 4)
|
||||
// y-
|
||||
#define KXTJ3_INT_SOURCE2_YNWU (0x01 << 3)
|
||||
// y+
|
||||
#define KXTJ3_INT_SOURCE2_YPWU (0x01 << 2)
|
||||
// z-
|
||||
#define KXTJ3_INT_SOURCE2_ZNWU (0x01 << 1)
|
||||
// z+
|
||||
#define KXTJ3_INT_SOURCE2_ZPWU (0x01 << 0)
|
||||
// reports the combined (OR) interrupt information of DRDY and WUFS in the interrupt source register
|
||||
#define KXTJ3_STATUS_REG_INT (0x01 << 4)
|
||||
// controls the operating mode of the KXTJ3
|
||||
#define KXTJ3_CTRL_REG1_PC (0x01 << 7)
|
||||
// determines the performance mode of the KXTJ3
|
||||
#define KXTJ3_CTRL_REG1_RES (0x01 << 6)
|
||||
// enables the reporting of the availability of new acceleration data as an interrupt
|
||||
#define KXTJ3_CTRL_REG1_DRDYE (0x01 << 5)
|
||||
// 2g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_2G (0x00 << 2)
|
||||
// 16g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_16G (0x01 << 2)
|
||||
// 4g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_4G (0x02 << 2)
|
||||
// 16g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_16G2 (0x03 << 2)
|
||||
// 8g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_8G (0x04 << 2)
|
||||
// 16g range
|
||||
#define KXTJ3_CTRL_REG1_GSEL_16G3 (0x05 << 2)
|
||||
// 8g range with 14b resolution
|
||||
#define KXTJ3_CTRL_REG1_GSEL_8G_14 (0x06 << 2)
|
||||
// 16g range with 14b resolution
|
||||
#define KXTJ3_CTRL_REG1_GSEL_16G_14 (0x07 << 2)
|
||||
// enables 14-bit mode if GSEL = '11'
|
||||
#define KXTJ3_CTRL_REG1_EN16G (0x01 << 2)
|
||||
// enables the Wake Up (motion detect) function.
|
||||
#define KXTJ3_CTRL_REG1_WUFE (0x01 << 1)
|
||||
// initiates software reset
|
||||
#define KXTJ3_CTRL_REG2_SRST (0x01 << 7)
|
||||
// initiates the digital communication self-test function.
|
||||
#define KXTJ3_CTRL_REG2_DCST (0x01 << 4)
|
||||
// 0.78Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_0P781 (0x00 << 0)
|
||||
// 1.563Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_1P563 (0x01 << 0)
|
||||
// 3.125Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_3P125 (0x02 << 0)
|
||||
// 6.25Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_6P25 (0x03 << 0)
|
||||
// 12.5Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_12P5 (0x04 << 0)
|
||||
// 25Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_25 (0x05 << 0)
|
||||
// 50Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_50 (0x06 << 0)
|
||||
// 100Hz
|
||||
#define KXTJ3_CTRL_REG2_OWUF_100 (0x07 << 0)
|
||||
// enables/disables the physical interrupt pin
|
||||
#define KXTJ3_INT_CTRL_REG1_IEN (0x01 << 5)
|
||||
// sets the polarity of the physical interrupt pin
|
||||
#define KXTJ3_INT_CTRL_REG1_IEA (0x01 << 4)
|
||||
// sets the response of the physical interrupt pin
|
||||
#define KXTJ3_INT_CTRL_REG1_IEL (0x01 << 3)
|
||||
// selftest polarity
|
||||
#define KXTJ3_INT_CTRL_REG1_STPOL (0x01 << 1)
|
||||
// Unlatched mode motion interrupt; 0=disabled,1=enabled
|
||||
#define KXTJ3_INT_CTRL_REG2_ULMODE (0x01 << 7)
|
||||
// x-
|
||||
#define KXTJ3_INT_CTRL_REG2_XNWU (0x01 << 5)
|
||||
// x+
|
||||
#define KXTJ3_INT_CTRL_REG2_XPWU (0x01 << 4)
|
||||
// y-
|
||||
#define KXTJ3_INT_CTRL_REG2_YNWU (0x01 << 3)
|
||||
// y+
|
||||
#define KXTJ3_INT_CTRL_REG2_YPWU (0x01 << 2)
|
||||
// z-
|
||||
#define KXTJ3_INT_CTRL_REG2_ZNWU (0x01 << 1)
|
||||
// z+
|
||||
#define KXTJ3_INT_CTRL_REG2_ZPWU (0x01 << 0)
|
||||
// 12.5Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_12P5 (0x00 << 0)
|
||||
// 25Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_25 (0x01 << 0)
|
||||
// 50Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_50 (0x02 << 0)
|
||||
// 100Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_100 (0x03 << 0)
|
||||
// 200Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_200 (0x04 << 0)
|
||||
// 400Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_400 (0x05 << 0)
|
||||
// 800Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_800 (0x06 << 0)
|
||||
// 1600Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_1600 (0x07 << 0)
|
||||
// 0.78Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_0P781 (0x08 << 0)
|
||||
// 1.563Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_1P563 (0x09 << 0)
|
||||
// 3.125Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_3P125 (0x0A << 0)
|
||||
// 6.25Hz
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_6P25 (0x0B << 0)
|
||||
// charge on
|
||||
#define KXTJ3_SELF_TEST_MEMS_TEST_ENABLE (0xCA << 0)
|
||||
// charge off
|
||||
#define KXTJ3_SELF_TEST_MEMS_TEST_DISABLE (0x00 << 0)
|
||||
// WHO_AM_I -value for KXCJC
|
||||
#define KXCJC_WHO_AM_I_WIA_ID (0x36 << 0)
|
||||
/*registers bit masks */
|
||||
|
||||
#define KXTJ3_DCST_RESP_DCSTR_MASK 0xFF
|
||||
|
||||
#define KXTJ3_WHO_AM_I_WIA_MASK 0xFF
|
||||
// selects the acceleration range of the accelerometer outputs
|
||||
#define KXTJ3_CTRL_REG1_GSEL_MASK 0x1C
|
||||
// sets the Output Data Rate for the Wake Up function
|
||||
#define KXTJ3_CTRL_REG2_OWUF_MASK 0x07
|
||||
// sets the output data rate (ODR)
|
||||
#define KXTJ3_DATA_CTRL_REG_OSA_MASK 0x0F
|
||||
|
||||
#define KXTJ3_SELF_TEST_MEMS_TEST_MASK 0xFF
|
||||
|
||||
#define KXCJC_WHO_AM_I_WIA_MASK 0xFF
|
||||
#endif
|
@ -58,8 +58,8 @@ namespace upm {
|
||||
*
|
||||
* @image html l298.jpg
|
||||
* <br><em>L298 Dual H-Bridge Motor Driver 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>
|
||||
*
|
||||
* Example driving a DC motor
|
||||
* @snippet l298.cxx Interesting
|
||||
|
@ -76,8 +76,8 @@ namespace upm
|
||||
*
|
||||
* @image html eboled.jpg
|
||||
* <br><em>OLED Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
* <a href=https://creativecommons.org/licenses/by/2.0/>
|
||||
* CC BY 2.0</a>.</em>
|
||||
*
|
||||
* @snippet lcd-eboled.cxx Interesting
|
||||
*/
|
||||
|
@ -76,7 +76,7 @@ led_context led_init_str(const char* name){
|
||||
dev->gpio = NULL;
|
||||
|
||||
dev->name = name;
|
||||
dev->gpioled = mraa_led_init(name);
|
||||
dev->gpioled = mraa_led_init_raw(name);
|
||||
|
||||
if (!dev->gpioled) {
|
||||
printf("%s: Unable to initialize gpioled device (%s).\n", __FUNCTION__, dev->name);
|
||||
|
@ -71,8 +71,8 @@ namespace upm {
|
||||
*
|
||||
* @image html lsm9ds0.jpg
|
||||
* <br><em>LSM9DS0 Sensor image provided by SparkFun* under
|
||||
* <a href=https://creativecommons.org/licenses/by-nc-sa/3.0/>
|
||||
* CC BY-NC-SA-3.0</a>.</em>
|
||||
* <a href=https://creativecommons.org/licenses/by/2.0/>
|
||||
* CC BY 2.0</a>.</em>
|
||||
*
|
||||
* @snippet lsm9ds0.cxx Interesting
|
||||
*/
|
||||
|
@ -113,9 +113,9 @@ typedef enum {
|
||||
*/
|
||||
typedef struct _m24lr64e_context {
|
||||
mraa_i2c_context i2c;
|
||||
uint8_t bus;
|
||||
int bus;
|
||||
uint8_t address;
|
||||
m24lr64e_access_mode mode;
|
||||
m24lr64e_access_mode mode;
|
||||
} *m24lr64e_context;
|
||||
|
||||
/**
|
||||
|
@ -61,8 +61,8 @@ namespace upm {
|
||||
*
|
||||
* @image html maxsonarez.jpg
|
||||
* <br><em>LV-MaxSonar-EZ Ultrasonic Ranger 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 maxsonarez.cxx Interesting
|
||||
*/
|
||||
|
@ -456,8 +456,7 @@ upm_result_t mcp2515_set_opmode(const mcp2515_context dev,
|
||||
<< _MCP2515_CANSTAT_OPMODE_SHIFT);
|
||||
|
||||
bool done = false;
|
||||
upm_clock_t clock;
|
||||
upm_clock_init(&clock);
|
||||
upm_clock_t clock = upm_clock_init();
|
||||
|
||||
do
|
||||
{
|
||||
@ -623,8 +622,7 @@ upm_result_t mcp2515_transmit_buffer(const mcp2515_context dev,
|
||||
return UPM_SUCCESS;
|
||||
|
||||
// now spin with timeout waiting for it to be transmitted
|
||||
upm_clock_t clock;
|
||||
upm_clock_init(&clock);
|
||||
upm_clock_t clock = upm_clock_init();
|
||||
bool done = false;
|
||||
|
||||
do
|
||||
|
@ -41,7 +41,6 @@ MHZ16::MHZ16(int uart)
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_uart_init() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// This requires a recent MRAA (1/2015)
|
||||
@ -51,7 +50,6 @@ MHZ16::MHZ16(int uart)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": mraa_uart_get_dev_path() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// now open the tty
|
||||
@ -61,7 +59,35 @@ MHZ16::MHZ16(int uart)
|
||||
": open of " +
|
||||
string(devPath) + " failed: " +
|
||||
string(strerror(errno)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MHZ16::MHZ16(const std::string& uart_raw)
|
||||
{
|
||||
m_ttyFd = -1;
|
||||
|
||||
if ( !(m_uart = mraa_uart_init_raw(uart_raw.c_str())) )
|
||||
{
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_uart_init_raw() failed");
|
||||
}
|
||||
|
||||
// This requires a recent MRAA (1/2015)
|
||||
const char *devPath = mraa_uart_get_dev_path(m_uart);
|
||||
|
||||
if (!devPath)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": mraa_uart_get_dev_path() failed");
|
||||
}
|
||||
|
||||
// now open the tty
|
||||
if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": open of " +
|
||||
string(devPath) + " failed: " +
|
||||
string(strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,8 +118,8 @@ bool MHZ16::dataAvailable(unsigned int millis)
|
||||
|
||||
if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0)
|
||||
return true; // data is ready
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int MHZ16::readData(char *buffer, int len)
|
||||
@ -111,7 +137,6 @@ int MHZ16::readData(char *buffer, int len)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": read() failed: " +
|
||||
string(strerror(errno)));
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -132,7 +157,6 @@ int MHZ16::writeData(char *buffer, int len)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": write() failed: " +
|
||||
string(strerror(errno)));
|
||||
return rv;
|
||||
}
|
||||
|
||||
tcdrain(m_ttyFd);
|
||||
@ -164,7 +188,6 @@ bool MHZ16::setupTty(speed_t baud)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": tcsetattr() failed: " +
|
||||
string(strerror(errno)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -176,7 +199,6 @@ bool MHZ16::verifyPacket(uint8_t *pkt, int len)
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": invalid packet header received");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -195,7 +217,6 @@ bool MHZ16::getData()
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Timed out waiting for response");
|
||||
return false;
|
||||
}
|
||||
|
||||
// read the packet
|
||||
@ -206,7 +227,6 @@ bool MHZ16::getData()
|
||||
{
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": Invalid packet size read");
|
||||
return false;
|
||||
}
|
||||
|
||||
// will throw an exception if it fails
|
||||
|
@ -40,12 +40,6 @@
|
||||
|
||||
#include <mraa/uart.h>
|
||||
|
||||
const int MHZ16_DEFAULT_UART = 0;
|
||||
|
||||
// protocol start and end codes
|
||||
const uint8_t MHZ16_START = 0x7e;
|
||||
const uint8_t MHZ16_END = 0x7e;
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief MHZ16 Serial CO2 Sensor
|
||||
@ -80,14 +74,21 @@ namespace upm {
|
||||
/**
|
||||
* MHZ16 constructor
|
||||
*
|
||||
* @param uart Default UART to use (0 or 1)
|
||||
* @param uart Default mraa UART index to use
|
||||
*/
|
||||
MHZ16(int uart);
|
||||
|
||||
/**
|
||||
* MHZ16 constructor
|
||||
*
|
||||
* @param uart_raw Full path to UART device.
|
||||
*/
|
||||
MHZ16(const std::string& uart_raw = "/dev/ttyS0");
|
||||
|
||||
/**
|
||||
* MHZ16 destructor
|
||||
*/
|
||||
~MHZ16();
|
||||
virtual ~MHZ16();
|
||||
|
||||
/**
|
||||
* Checks to see if there is data available for reading
|
||||
@ -169,9 +170,9 @@ namespace upm {
|
||||
|
||||
private:
|
||||
mraa_uart_context m_uart;
|
||||
int m_ttyFd;
|
||||
int gas;
|
||||
int temp;
|
||||
int m_ttyFd = 0;
|
||||
int gas = 0;
|
||||
int temp = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,8 @@ mq303a_context mq303a_init(int pin, int heater_pin) {
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
dev->aio_pin = pin;
|
||||
dev->gpio_pin = heater_pin;
|
||||
dev->aio = mraa_aio_init(dev->aio_pin);
|
||||
dev->gpio = mraa_gpio_init(dev->gpio_pin);
|
||||
dev->aio = mraa_aio_init(pin);
|
||||
dev->gpio = mraa_gpio_init(heater_pin);
|
||||
|
||||
if(mraa_gpio_dir(dev->gpio, MRAA_GPIO_OUT) != MRAA_SUCCESS)
|
||||
{
|
||||
|
@ -43,8 +43,6 @@
|
||||
typedef struct _mq303a_context {
|
||||
mraa_gpio_context gpio;
|
||||
mraa_aio_context aio;
|
||||
uint8_t gpio_pin;
|
||||
uint8_t aio_pin;
|
||||
} *mq303a_context;
|
||||
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user