mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 20:01:12 +03:00
Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
ffdd6d2f00 | |||
044037b892 | |||
ad87704c19 | |||
00114f69d2 | |||
c99821ad26 | |||
a9939d6352 | |||
5ed36a37f9 | |||
03b9cf89a0 | |||
9c9b273b5a | |||
586acf7502 | |||
d0e83d7076 | |||
1747fbbe19 | |||
45f85e9944 | |||
b31e88c233 | |||
58b80f6b58 | |||
574a39d3c1 | |||
bb38b35b32 | |||
d15bf22536 | |||
731704eaac | |||
00170bea97 | |||
8cfb3d3dab | |||
d2e2682f0e | |||
22ad93956c | |||
86a3be4517 | |||
8a67c143bf | |||
7dc8ec6244 | |||
0d544dadeb | |||
9f66c10b26 | |||
2822d63c9c | |||
0954617a4b | |||
36be22cb90 | |||
8d25ecacdd | |||
739d4e23e8 | |||
81c8baa071 | |||
2fa9b7b6c9 | |||
b1e548ae8a | |||
d00500ba12 | |||
2c0e83e406 | |||
b03cbf4f36 |
@ -8,9 +8,9 @@ endif ()
|
||||
|
||||
find_package (Threads REQUIRED)
|
||||
find_package (PkgConfig REQUIRED)
|
||||
# force the libmaa version to be the required version
|
||||
pkg_check_modules (MAA REQUIRED maa>=0.2.9)
|
||||
message (INFO " found libmaa version: ${MAA_VERSION}")
|
||||
# force the libmraa version to be the required version
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.4.0)
|
||||
message (INFO " found libmraa version: ${MRAA_VERSION}")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||
@ -19,8 +19,8 @@ set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_
|
||||
include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmaa!")
|
||||
set (VERSION "v0.1.4-dirty")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.1.5-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - UPM Version ${VERSION}")
|
||||
@ -81,7 +81,7 @@ if (IPK)
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
|
||||
set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmaa0 (>= ${MAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmraa0 (>= ${MRAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
|
||||
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
|
@ -44,7 +44,7 @@ PROJECT_NUMBER = @upm_VERSION_STRING@
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
# quick idea about the purpose of the project. Keep the description short.
|
||||
|
||||
PROJECT_BRIEF = "Sensor/Actuator repository for libmaa (v@MAA_VERSION@)"
|
||||
PROJECT_BRIEF = "Sensor/Actuator repository for libmraa (v@MRAA_VERSION@)"
|
||||
|
||||
# With the PROJECT_LOGO tag one can specify an logo or icon that is included in
|
||||
# the documentation. The maximum height of the logo should not exceed 55 pixels
|
||||
|
@ -1,8 +1,8 @@
|
||||
UPM - Sensor/Actuator repository for Maa
|
||||
UPM - Sensor/Actuator repository for Mraa
|
||||
==============
|
||||
|
||||
UPM is a high level repository for sensors that use maa. Each sensor links to
|
||||
libmaa and are not meant to be interlinked although some groups of sensors may
|
||||
UPM is a high level repository for sensors that use mraa. Each sensor links to
|
||||
libmraa and are not meant to be interlinked although some groups of sensors may
|
||||
be. Each sensor contains a header which allows to interface with it. Typically
|
||||
a sensor is represented as a class and instanciated.
|
||||
|
||||
|
@ -29,3 +29,31 @@ Building debug build:
|
||||
Using clang instead of gcc:
|
||||
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang
|
||||
|
||||
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
|
||||
rebuild. For example the lcd module target name is i2clcd. Therfore the python
|
||||
module target name will be prefixed by _pyupm_. Just do the following to build
|
||||
only that module. Modules not using the UPM cmake macros may have different
|
||||
naming.
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
make _pyupm_i2clcd
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Sometimes you want to build a small C++ example against an installed library.
|
||||
This is fairly easy if installed systemwide. Just link against the correct
|
||||
librar (in this case libupm-tm1637) and then add /usr/include/upm to the loader
|
||||
path:
|
||||
|
||||
~~~~~~~~~~~~
|
||||
g++ test.cxx -lupm_tm1637 -I/usr/include/upm
|
||||
~~~~~~~~~~~~
|
||||
|
||||
You can also use pkg-config to return the information to you, which is
|
||||
considered the correct way if including UPM in a build system like cmake or
|
||||
autotools on linux.
|
||||
|
||||
~~~~~~~~~~~
|
||||
pkg-config --cflags --libs upm-tm1637
|
||||
~~~~~~~~~~~
|
||||
|
@ -2,15 +2,33 @@ Contributing a module {#contributions}
|
||||
=====================
|
||||
|
||||
Here are the rules of contribution:
|
||||
- Try not to break master. In any commit.
|
||||
- Your module must have an example that builds against your UPM library
|
||||
- Commits must have a sign-off line by everyone who reviewed them
|
||||
- Commits must be named <file/module>: Some decent description
|
||||
- You must license your module under an FOSS license. The recommended license
|
||||
- You must license your module under a FOSS license. The recommended license
|
||||
is MIT but any permissive license is fine. Please consider that people using
|
||||
UPM may want to write proprietary programs with your sensors so we like to
|
||||
avoid GPL. (LGPL is fine). If your license is not MIT please include a
|
||||
LICENSE file in src/<mymodule>/
|
||||
- Please test your module builds before contributing and make sure it works on
|
||||
the latest version of maa. If you tested on a specific board/platform please
|
||||
the latest version of mraa. If you tested on a specific board/platform please
|
||||
tell us what this was in your PR.
|
||||
- Try not to break master. In any commit.
|
||||
- Attempt to have some decent API documentation below are the explicit rules on documentation:
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
- Try to have no warnings in doxygen, this is generally fairly easy
|
||||
- Have the specific sensor manufacturer/model & version that you used, if you
|
||||
support multiple versions please list
|
||||
- Comments do not need full stops
|
||||
- Stick to <80 chars per line even in comments
|
||||
- No text is allowed on the same line as the start or end of a comment /** */
|
||||
- All classes should have a "@brief" and a "@snippet"
|
||||
|
||||
The example should have an 'Interesting' section which will be highlighted as a
|
||||
code sample in doxygen. Everything in between such tags will show up in the
|
||||
class documentation when the following is put at the end of a class docstring
|
||||
as show above.
|
||||
|
||||
|
@ -9,7 +9,7 @@ people made arduino code already so we'll use that as a
|
||||
|
||||
### Basics
|
||||
|
||||
This is a spi module so we will use the maa spi functions to build our module.
|
||||
This is a spi module so we will use the mraa spi functions to build our module.
|
||||
First thing to do is to create a tree structure like this in upm/src/max31855:
|
||||
|
||||
* max31855.cxx
|
||||
@ -31,7 +31,8 @@ change between the javascript & node.js one is the argument to %module.
|
||||
The %include parameter defines which functions will be available to the
|
||||
node/python module created, Whilst the headers inside %{} will be explicitly
|
||||
required during compilation. Typically only the top level header is required in
|
||||
either of those args.
|
||||
either of those args. The upm.i is just a shortcut to include some commonly
|
||||
used swig wrappers for UPM sensors, it's not obligatory but recommended.
|
||||
|
||||
### API
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
Porting a module from Arduino {#porting}
|
||||
=============================
|
||||
|
||||
Porting arduino libraries to libmaa as UPM libraries is usually fairly easy.
|
||||
Porting arduino libraries to libmraa as UPM libraries is usually fairly easy.
|
||||
The issues typically come from misunderstanding of how a non real time OS deals
|
||||
with interupts and timers. It also highly depends on the sensor. A concrete
|
||||
example is explained in detail on @ref max31855
|
||||
@ -31,22 +31,22 @@ upm_module_init()
|
||||
|
||||
The easiest way to do this is to have a look at a similar sensor to yours.
|
||||
Typically create a class for your sensor with a constructor that defines the
|
||||
pins it is on. This constructor will create the maa_*_context structs that are
|
||||
pins it is on. This constructor will create the mraa_*_context structs that are
|
||||
required to talk to the board's IO. An I2c sensor will create a
|
||||
maa_i2c_context, keep it as a private member and require a bus number and slave
|
||||
mraa_i2c_context, keep it as a private member and require a bus number and slave
|
||||
address in it's constructor.
|
||||
|
||||
Typically in sensors a simple object->read() function is prefered, depending on
|
||||
your sensor/actuaotr this may or may not be easy or not even make sense. Most
|
||||
UPM apis have a simple set of functions.
|
||||
|
||||
### Mapping arduino API to libmaa
|
||||
### Mapping arduino API to libmraa
|
||||
|
||||
Your constructor is similar to the setup() function in arduino, you should
|
||||
initialise your IO the way you want it. This means initialising contexts
|
||||
(private members) and setting the correct modes for them.
|
||||
|
||||
See the maa API documentation for exact API.
|
||||
See the mraa API documentation for exact API.
|
||||
|
||||
### Building
|
||||
|
||||
|
@ -17,6 +17,15 @@ add_executable (accelerometer mma7455.cxx)
|
||||
add_executable (lcd st7735.cxx)
|
||||
add_executable (max31855-example max31855.cxx)
|
||||
add_executable (gy65-example gy65.cxx)
|
||||
add_executable (stepmotor-example stepmotor.cxx)
|
||||
add_executable (pulsensor-example pulsensor.cxx)
|
||||
add_executable (mic-example mic-example.cxx)
|
||||
add_executable (mpu9150-example mpu9150-example.cxx)
|
||||
add_executable (maxds3231m-example maxds3231m.cxx)
|
||||
add_executable (max31723-example max31723.cxx)
|
||||
add_executable (max5487-example max5487.cxx)
|
||||
add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx)
|
||||
add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -32,6 +41,14 @@ include_directories (${PROJECT_SOURCE_DIR}/src/mma7455)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/st7735)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31855)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/gy65)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/stepmotor)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/pulsensor)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mic)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31723)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max5487)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf8001)
|
||||
|
||||
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -52,3 +69,12 @@ target_link_libraries (accelerometer mma7455 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lcd st7735 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31855-example max31855 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (gy65-example gy65 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (stepmotor-example stepmotor ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (pulsensor-example pulsensor ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mic-example mic ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max5487-example max5487 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-broadcast-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-helloworld-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
@ -25,20 +25,8 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
@ -51,13 +39,10 @@ main(int argc, char **argv) {
|
||||
std::cout << sound->name() << std::endl;
|
||||
// play sound (DO, RE, ME, etc...)
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
|
||||
std::cout << sound->playSound(chord[chord_ind]) << std::endl;
|
||||
usleep(1000);
|
||||
}
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||
// play one second for each chord
|
||||
std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Use i2c device 0 all the time
|
||||
//! [Interesting]
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
std::cout << led->name() << std::endl;
|
||||
for (int i=0; i < 10; i++) {
|
||||
@ -38,6 +38,7 @@ main(int argc, char **argv)
|
||||
led->off();
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
40
examples/grovelight.cxx
Normal file
40
examples/grovelight.cxx
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses AIO 0
|
||||
//! [Interesting]
|
||||
upm::GroveLight* light = new upm::GroveLight(0);
|
||||
int lightValue = light->value();
|
||||
|
||||
delete light;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -29,13 +29,14 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Use i2c device 0 all the time
|
||||
//! [Interesting]
|
||||
upm::GroveTemp* s = new upm::GroveTemp(0);
|
||||
std::cout << s->name() << std::endl;
|
||||
for (int i=0; i < 10; i++) {
|
||||
std::cout << s->value() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
void
|
||||
interrupt (void) {
|
||||
interrupt (void * args) {
|
||||
sonar->ackEdgeDetected ();
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,11 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("Hello World");
|
||||
//! [Interesting]
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->setCursor(2,4);
|
||||
|
61
examples/max31723.cxx
Normal file
61
examples/max31723.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "max31723.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAX31723 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX31723(7);
|
||||
usleep (1000000);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
66
examples/max5487.cxx
Normal file
66
examples/max5487.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "max5487.h"
|
||||
#include <signal.h>
|
||||
|
||||
upm::MAX5487 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX5487(7);
|
||||
|
||||
// Power LED UP
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
// Power LED DOWN
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(255 - i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
75
examples/maxds3231m.cxx
Normal file
75
examples/maxds3231m.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "maxds3231m.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAXDS3231M *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Time3231 t;
|
||||
sensor = new upm::MAXDS3231M(0, ADDR);
|
||||
|
||||
t.second = 1;
|
||||
t.minute = 3;
|
||||
t.hour = 3;
|
||||
t.day = 3;
|
||||
t.month = 3;
|
||||
t.year = 3;
|
||||
t.weekDay = 3;
|
||||
sensor->setDate (t); // Note, second should be set to 1.
|
||||
|
||||
usleep (500000);
|
||||
|
||||
while (!doWork) {
|
||||
if (sensor->getDate (t)) {
|
||||
std::cout << (int)t.hour << ":" << (int)t.minute << ":" << (int)t.second << std::endl;
|
||||
}
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
74
examples/mic-example.cxx
Normal file
74
examples/mic-example.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mic.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::Microphone *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
is_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sensor = new upm::Microphone(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
thresholdContext ctx;
|
||||
ctx.averageReading = 0;
|
||||
ctx.runningAverage = 0;
|
||||
ctx.averagedOver = 2;
|
||||
|
||||
while (!is_running) {
|
||||
int len = sensor->getSampledWindow (2, 128, buffer);
|
||||
if (len) {
|
||||
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
|
||||
sensor->printGraph(&ctx);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
59
examples/mpu9150-example.cxx
Normal file
59
examples/mpu9150-example.cxx
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mpu9150.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Vector3D data;
|
||||
upm::MPU9150 *sensor = new upm::MPU9150(0, ADDR);
|
||||
sensor->getData ();
|
||||
sensor->getAcceleromter (&data);
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "DEVICE ID (" << (int) sensor->getDeviceID () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "ACCELEROMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getGyro (&data);
|
||||
std::cout << "GYRO :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getMagnometer (&data);
|
||||
std::cout << "MAGNOMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
std::cout << "TEMPERATURE (" << sensor->getTemperature () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
177
examples/nrf8001_broadcast.cxx
Normal file
177
examples/nrf8001_broadcast.cxx
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf8001.h"
|
||||
#include "nrf8001_broadcast.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
if (lib_aci_event_get (&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup\n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby\n");
|
||||
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
|
||||
printf ("Broadcasting started\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; //ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
printf ("ACI_EVT_CMD_RSP\n");
|
||||
while (1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
|
||||
printf ("Broadcasting timed out\n");
|
||||
} else {
|
||||
printf ("Evt Disconnected. Link Loss\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
printf ("ACI_EVT_DATA_RECEIVED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
93
examples/nrf8001_broadcast.h
Normal file
93
examples/nrf8001_broadcast.h
Normal file
@ -0,0 +1,93 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PIPE_GAP_DEVICE_NAME_SET 1
|
||||
|
||||
#define NUMBER_OF_PIPES 1
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xffff /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 13
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x03,0x02,0x41,0xd7,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x64,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x38,0x02,0xff,0x02,0x58,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x05,0x06,0x10,0x54,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x0e,0x03,0x00,0x00,0x2a,0x04,0x14,0x0b,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x62,0x63,0x61,0x73,0x74,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,\
|
||||
0x05,0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,0x04,0x01,0xff,0xff,0xff,0xff,0x00,0x00,0xff,\
|
||||
0xff,0x04,0x04,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x04,0x06,0x20,0x70,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x0d,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0x60,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x03,0x4c,0xf2,\
|
||||
},\
|
||||
},\
|
||||
}
|
362
examples/nrf8001_helloworld.cxx
Normal file
362
examples/nrf8001_helloworld.cxx
Normal file
@ -0,0 +1,362 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf8001.h"
|
||||
#include "nrf8001_helloworld.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
#include "uart_over_ble.h"
|
||||
|
||||
/*
|
||||
* You can use the nRF UART app in the Apple iOS app store and Google Play for Android 4.3 for Samsung Galaxy S4
|
||||
* with this helloworld application
|
||||
*/
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
/*
|
||||
Timing change state variable
|
||||
*/
|
||||
static bool timing_change_done = false;
|
||||
|
||||
/*
|
||||
Used to test the UART TX characteristic notification
|
||||
*/
|
||||
static uart_over_ble_t uart_over_ble;
|
||||
static uint8_t uart_buffer[20];
|
||||
static uint8_t uart_buffer_len = 0;
|
||||
static uint8_t dummychar = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
void
|
||||
uart_over_ble_init (void) {
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_tx (uint8_t *buffer, uint8_t buffer_len) {
|
||||
bool status = false;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) &&
|
||||
(aci_state.data_credit_available >= 1)) {
|
||||
status = lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, buffer, buffer_len);
|
||||
if (status) {
|
||||
aci_state.data_credit_available--;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_process_control_point_rx(uint8_t *byte, uint8_t length) {
|
||||
bool status = false;
|
||||
aci_ll_conn_params_t *conn_params;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX) ) {
|
||||
switch (*byte) {
|
||||
/*
|
||||
Queues a ACI Disconnect to the nRF8001 when this packet is received.
|
||||
May cause some of the UART packets being sent to be dropped
|
||||
*/
|
||||
case UART_OVER_BLE_DISCONNECT:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Queues an ACI Change Timing to the nRF8001
|
||||
*/
|
||||
case UART_OVER_BLE_LINK_TIMING_REQ:
|
||||
/*
|
||||
Parameters:
|
||||
Connection interval min: 2 bytes
|
||||
Connection interval max: 2 bytes
|
||||
Slave latency: 2 bytes
|
||||
Timeout: 2 bytes
|
||||
Same format as Peripheral Preferred Connection Parameters (See nRFgo studio -> nRF8001 Configuration -> GAP Settings
|
||||
Refer to the ACI Change Timing Request in the nRF8001 Product Specifications
|
||||
*/
|
||||
conn_params = (aci_ll_conn_params_t *)(byte+1);
|
||||
lib_aci_change_timing( conn_params->min_conn_interval,
|
||||
conn_params->max_conn_interval,
|
||||
conn_params->slave_latency,
|
||||
conn_params->timeout_mult);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Clears the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_STOP:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = false;
|
||||
status = true;
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
Set the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_OK:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
|
||||
// We enter the if statement only when there is a ACI event available to be processed
|
||||
if (lib_aci_event_get(&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup \n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby \n");
|
||||
// Looking for an iPhone by sending radio advertisements
|
||||
// When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
|
||||
if (aci_evt->params.device_started.hw_error) {
|
||||
usleep (20000); //Handle the HW error event correctly.
|
||||
} else {
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; // ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
//If an ACI command response event comes with an error -> stop
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
//ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
|
||||
//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
|
||||
//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command
|
||||
printf ("ACI_EVT_CMD_RSP \n");
|
||||
}
|
||||
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) {
|
||||
//Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
|
||||
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
|
||||
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED");
|
||||
uart_over_ble_init ();
|
||||
timing_change_done = false;
|
||||
aci_state.data_credit_available = aci_state.data_credit_total;
|
||||
|
||||
/*
|
||||
Get the device version of the nRF8001 and store it in the Hardware Revision String
|
||||
*/
|
||||
lib_aci_device_version();
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS \n");
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done)) {
|
||||
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
|
||||
// Used to increase or decrease bandwidth
|
||||
timing_change_done = true;
|
||||
|
||||
char hello[]="Hello World, works";
|
||||
uart_tx((uint8_t *)&hello[0], strlen(hello));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_TIMING:
|
||||
printf ("Evt link connection interval changed \n");
|
||||
lib_aci_set_local_data(&aci_state,
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
|
||||
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval), /* Byte aligned */
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
printf ("ACI_EVT_DISCONNECTED \n");
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
for(int i=0; i<aci_evt->len - 2; i++) {
|
||||
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
|
||||
}
|
||||
|
||||
uart_buffer_len = aci_evt->len - 2;
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
//Subtract for Opcode and Pipe number
|
||||
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
|
||||
}
|
||||
|
||||
printf ("Incomming data - %s\n", uart_buffer);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_CREDIT:
|
||||
printf ("ACI_EVT_DATA_CREDIT \n");
|
||||
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_ERROR:
|
||||
printf ("ACI_EVT_PIPE_ERROR \n");
|
||||
//Increment the credit available as the data packet was not sent.
|
||||
//The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
|
||||
//for the credit.
|
||||
if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
|
||||
aci_state.data_credit_available++;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR \n");
|
||||
lib_aci_connect(0/* in seconds, 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* setup_required is set to true when the device starts up and enters setup mode.
|
||||
* It indicates that do_aci_setup() should be called. The flag should be cleared if
|
||||
* do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
|
||||
*/
|
||||
if(setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
254
examples/nrf8001_helloworld.h
Normal file
254
examples/nrf8001_helloworld.h
Normal file
@ -0,0 +1,254 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SETUP_ID 0
|
||||
#define SETUP_FORMAT 2 /** nRF8001 Cx */
|
||||
#define ACI_DYNAMIC_DATA_SIZE 263
|
||||
|
||||
/* Service: GATT - Characteristic: Service Changed - Pipe: TX_ACK */
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK 1
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: Hardware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET 2
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET_MAX_SIZE 9
|
||||
|
||||
/* Service: Device Information - Characteristic: Manufacturer Name String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET 3
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET_MAX_SIZE 20
|
||||
|
||||
/* Service: Device Information - Characteristic: Model Number String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET 4
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET_MAX_SIZE 8
|
||||
|
||||
/* Service: Device Information - Characteristic: Firmware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET 5
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: PNP_ID - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET 6
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET_MAX_SIZE 7
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART RX - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX 7
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART TX - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX 8
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX 9
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX 10
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Link Timing Current - Pipe: SET */
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET 11
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE 6
|
||||
|
||||
|
||||
#define NUMBER_OF_PIPES 11
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_TX_ACK}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0x12 /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xa /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xa /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 30
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x02,0x02,0x41,0xfe,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x01,0x00,0x00,0x06,0x00,0x00,\
|
||||
0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1e,0x06,0x10,0x1c,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x14,0x03,0x90,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x02,0x03,0x00,0x00,0x2a,0x04,0x04,0x14,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x48,0x65,0x6c,0x6c,0x6f,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x63,0x6f,0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,\
|
||||
0x00,0x05,0x2a,0x01,0x01,0x80,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,\
|
||||
0x04,0x01,0x0a,0x00,0x12,0x00,0x00,0x00,0x0a,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x70,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,0x04,0x04,0x05,0x05,0x00,0x09,0x28,\
|
||||
0x03,0x01,0x22,0x0a,0x00,0x05,0x2a,0x26,0x04,0x05,0x04,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x8c,0x0a,0x2a,0x05,0x01,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x0b,0x29,0x02,\
|
||||
0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x0c,0x28,0x00,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xa8,0x0a,0x18,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,0x00,0x27,0x2a,\
|
||||
0x04,0x04,0x09,0x01,0x00,0x0e,0x2a,0x27,0x01,0x0a,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xc4,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x0f,0x28,0x03,0x01,0x02,\
|
||||
0x10,0x00,0x29,0x2a,0x04,0x04,0x14,0x02,0x00,0x10,0x2a,0x29,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xe0,0x01,0x30,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x11,0x28,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xfc,0x03,0x01,0x02,0x12,0x00,0x24,0x2a,0x04,0x04,0x08,0x02,0x00,0x12,0x2a,0x24,0x01,\
|
||||
0x31,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x18,0x00,0x13,0x28,0x03,0x01,0x02,0x14,0x00,0x26,0x2a,0x04,0x04,0x04,0x02,0x00,0x14,\
|
||||
0x2a,0x26,0x01,0x33,0x34,0x00,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x34,0x15,0x28,0x03,0x01,0x02,0x16,0x00,0x50,0x2a,0x06,0x04,0x08,0x07,0x00,0x16,0x2a,\
|
||||
0x50,0x01,0x02,0x00,0x00,0xaa,0xaa,0xcc,0xcc,0x04,0x04,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x50,0x10,0x00,0x17,0x28,0x00,0x01,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x01,0x00,0x40,0x6e,0x04,0x04,0x13,0x13,0x00,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x6c,0x28,0x03,0x01,0x04,0x19,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x02,0x00,0x40,0x6e,0x44,0x10,0x14,0x00,0x00,0x19,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x88,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x13,0x13,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xa4,0x1a,0x28,0x03,0x01,0x10,0x1b,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
0xf3,0xa3,0xb5,0x03,0x00,0x40,0x6e,0x14,0x00,0x14,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xc0,0x1b,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xdc,0x00,0x1c,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x1d,0x28,0x03,0x01,\
|
||||
0x14,0x1e,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xf8,0xf3,0xa3,0xb5,0x04,0x00,0x40,0x6e,0x54,0x10,0x09,0x00,0x00,0x1e,0x00,0x04,0x02,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x22,0x14,0x02,0x00,0x1f,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x20,0x28,0x03,\
|
||||
0x01,0x02,0x21,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1b,0x06,0x22,0x30,0x93,0xf3,0xa3,0xb5,0x05,0x00,0x40,0x6e,0x06,0x04,0x07,0x06,0x00,0x21,0x00,0x05,\
|
||||
0x02,0xff,0xff,0xff,0xff,0xff,0xff,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x00,0x2a,0x05,0x01,0x00,0x04,0x04,0x00,0x0a,0x00,0x0b,0x2a,0x27,0x01,0x00,0x80,0x04,\
|
||||
0x00,0x0e,0x00,0x00,0x2a,0x29,0x01,0x00,0x80,0x04,0x00,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x24,0x01,0x00,0x80,0x04,0x00,0x12,0x00,0x00,0x2a,0x26,0x01,0x00,\
|
||||
0x80,0x04,0x00,0x14,0x00,0x00,0x2a,0x50,0x01,0x00,0x80,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x38,0x00,0x16,0x00,0x00,0x00,0x02,0x02,0x00,0x08,0x04,0x00,0x19,0x00,0x00,0x00,0x03,\
|
||||
0x02,0x00,0x02,0x04,0x00,0x1b,0x00,0x1c,0x00,0x04,0x02,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x40,0x54,0x0a,0x04,0x00,0x1e,0x00,0x1f,0x00,0x05,0x02,0x00,0x80,0x04,0x00,0x21,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x50,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,0xa3,0xb5,0x00,0x00,0x40,0x6e,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x02,0xb2,0xd1,\
|
||||
},\
|
||||
},\
|
||||
}
|
@ -27,90 +27,72 @@
|
||||
#define DEVICE_ADDRESS 0x3C
|
||||
#define BUS_NUMBER 0x0
|
||||
|
||||
static uint8_t SeeedLogo[] ={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
|
||||
0xff, 0xfc, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x20, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0x60, 0xe0, 0xc0,
|
||||
0xc0, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x80, 0xc0,
|
||||
0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0,
|
||||
0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0xc0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0xc0,
|
||||
0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0,
|
||||
0xf8, 0xf8, 0x00, 0xd8, 0xd8, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00,
|
||||
0x00, 0x03, 0x0f, 0x1e, 0x3c, 0x70, 0xe3, 0xcf, 0x9f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0xbf,
|
||||
0xcf, 0xe3, 0x70, 0x78, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x33, 0x77, 0x66, 0x66, 0x66, 0x6c,
|
||||
0x7d, 0x18, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37, 0x07, 0x00, 0x0f, 0x3f, 0x7f,
|
||||
0x66, 0x66, 0x66, 0x66, 0x77, 0x27, 0x07, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37,
|
||||
0x07, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
|
||||
0x11, 0x37, 0x67, 0x66, 0x66, 0x6c, 0x7d, 0x38, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00, 0x00, 0x1f,
|
||||
0x3f, 0x70, 0x60, 0x60, 0x70, 0x7f, 0x7f, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31,
|
||||
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x06, 0x1f, 0x3b, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
|
||||
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
|
||||
0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
|
||||
0x08, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0x20, 0xa0,
|
||||
0xa0, 0xa0, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x08, 0x00, 0x20, 0x40, 0x80, 0x40,
|
||||
0x20, 0x00, 0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0xe0, 0x00,
|
||||
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x01, 0x02,
|
||||
0x02, 0x02, 0x01, 0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00,
|
||||
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x02,
|
||||
0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x02,
|
||||
0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x82, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01,
|
||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00,
|
||||
0x00, 0x00, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x82, 0x8c, 0x60, 0x1c, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e,
|
||||
0x20, 0x20, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x0c, 0x00, 0x12, 0x2a, 0x2a,
|
||||
0x2a, 0x1c, 0x20, 0x1c, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3f, 0x00, 0x02, 0x02, 0x3c, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static uint8_t intel_logo[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 192, 192, 192, 224,
|
||||
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
|
||||
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
|
||||
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
|
||||
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
|
||||
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
|
||||
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
|
||||
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
|
||||
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
|
||||
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
|
||||
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
|
||||
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
|
||||
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
|
||||
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
|
||||
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
|
||||
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
|
||||
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
|
||||
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
|
||||
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
|
||||
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
|
||||
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
|
||||
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
|
||||
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
|
||||
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
|
||||
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
|
||||
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
|
||||
//! [Interesting]
|
||||
upm::SSD1308 *lcd = new upm::SSD1308(BUS_NUMBER, DEVICE_ADDRESS);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
// lcd->setCursor (0, 0);
|
||||
// lcd->write ("Hello World");
|
||||
lcd->clear();
|
||||
lcd->draw(intel_logo, 1024);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
lcd->clear ();
|
||||
lcd->draw (SeeedLogo, 1024);
|
||||
|
||||
lcd->close ();
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
@ -106,21 +106,19 @@ static uint8_t SeeedLogo[] ={
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::SSD1327 *lcd = new upm::SSD1327 (BUS_NUMBER, 0x3C);
|
||||
//! [Interesting]
|
||||
upm::SSD1327 *lcd = new upm::SSD1327(BUS_NUMBER, 0x3C);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
for(uint8_t i = 0; i < 12 ; i++) {
|
||||
lcd->setCursor (i, 0);
|
||||
lcd->setGrayLevel (i);
|
||||
lcd->write ("Hello World");
|
||||
// Simple print hello world
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
lcd->setCursor(i, 0);
|
||||
lcd->setGrayLevel(i);
|
||||
lcd->write("Hello World");
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
lcd->draw (SeeedLogo, 96 * 96 / 8);
|
||||
// Simple print hello world
|
||||
lcd->draw(SeeedLogo, 96 * 96 / 8);
|
||||
|
||||
lcd->close ();
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
61
examples/pulsensor.cxx
Normal file
61
examples/pulsensor.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "pulsensor.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
pulsensor_context sensor_ctx;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handler (clbk_data data) {
|
||||
printf ("callback data (%d)\n", data);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
init_pulsensor (&sensor_ctx, handler);
|
||||
|
||||
start_sampler (&sensor_ctx);
|
||||
while (!doWork) {
|
||||
usleep (5);
|
||||
}
|
||||
stop_sampler (&sensor_ctx);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
74
examples/python/make_oled_pic.py
Executable file
74
examples/python/make_oled_pic.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from PIL import Image
|
||||
import sys
|
||||
|
||||
# Pixels are arranged in one byte for 8 vertical pixels and not addressed individually
|
||||
# We convert the image to greysacle and end up making it monochrome where we
|
||||
# consider that every pixel that is '40' is black.
|
||||
|
||||
width = 128
|
||||
height = 64
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print('Please specify an image to use as the only argument')
|
||||
exit(1)
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
im = im.convert('L').resize((width, height))
|
||||
|
||||
data = list(im.getdata())
|
||||
|
||||
byteblock = [0 for i in range(width)]
|
||||
widthblock = [list(byteblock) for i in range(int(height/8))]
|
||||
numblock = 0
|
||||
pixcount = 0
|
||||
i = 0
|
||||
|
||||
# we split the list by width * 8, to create data chunks of 8rows
|
||||
datachunks=[data[x:x+(width*8)] for x in range(0, len(data), (width*8))]
|
||||
|
||||
# grab every pixel of image (or datachunk)
|
||||
while i < len(widthblock):
|
||||
pixcount = 0
|
||||
for y in datachunks[i]:
|
||||
xcoor = pixcount % width
|
||||
ycoor = int(pixcount/width)
|
||||
blknum = xcoor % len(widthblock)
|
||||
blkycoor = ycoor
|
||||
|
||||
# 40 is what we consider 'black'
|
||||
if y > 40:
|
||||
widthblock[i][xcoor] |= (1 << blkycoor)
|
||||
|
||||
pixcount += 1
|
||||
i += 1
|
||||
|
||||
flatlist = [y for x in widthblock for y in x]
|
||||
|
||||
carray = 'static uint8_t image[] = {\n' + ', '.join(str(x) for x in flatlist)
|
||||
print(carray + '\n};')
|
31
examples/python/using_carrays.py
Normal file
31
examples/python/using_carrays.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
import pyupm_mic
|
||||
|
||||
mymic = pyupm_mic.Microphone(1)
|
||||
# careful this is an unitialised array with no bounds checking!
|
||||
x = pyupm_mic.uint16Array(3)
|
||||
mymic.getSampledWindow(100, 3, x)
|
||||
|
@ -27,6 +27,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
|
||||
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
|
||||
lcd->setCursor(0,0);
|
||||
@ -34,4 +35,5 @@ main(int argc, char **argv)
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
73
examples/stepmotor.cxx
Normal file
73
examples/stepmotor.cxx
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "stepmotor.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::StepMotor *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::StepMotor(4, 6);
|
||||
|
||||
while (!doWork) {
|
||||
sensor->setSpeed (500);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
|
||||
sensor->setSpeed (750);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
|
||||
sensor->setSpeed (1000);
|
||||
sensor->stepForward (500);
|
||||
usleep (10000);
|
||||
sensor->stepBackwards (500);
|
||||
usleep (10000);
|
||||
}
|
||||
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -16,11 +16,11 @@ macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
|
||||
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
||||
|
||||
macro(upm_SWIG_PYTHON)
|
||||
if(BUILDSWIGPYTHON)
|
||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||
set (CMAKE_C_FLAGS -DSWIGPYTHON=${SWIG_FOUND})
|
||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
|
||||
swig_link_libraries (pyupm_${libname} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
|
||||
target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
|
||||
PUBLIC
|
||||
"${PYTHON_INCLUDE_PATH}"
|
||||
@ -34,12 +34,12 @@ macro(upm_SWIG_PYTHON)
|
||||
endmacro()
|
||||
|
||||
macro(upm_SWIG_NODE)
|
||||
if(BUILDSWIGNODE)
|
||||
if (BUILDSWIGNODE AND BUILDSWIG)
|
||||
set (CMAKE_CXX_FLAGS -DBUILDING_NODE_EXTENSION)
|
||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
|
||||
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
||||
swig_link_libraries (jsupm_${libname} ${MAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||
PUBLIC
|
||||
"${NODE_INCLUDE_DIRS}"
|
||||
@ -65,7 +65,11 @@ macro(upm_doxygen)
|
||||
)
|
||||
add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
|
||||
add_dependencies (${libname}doc_i doc)
|
||||
add_dependencies (${SWIG_MODULE_pyupm_${libname}_REAL_NAME} ${libname}doc_i)
|
||||
if (BUILDSWIG)
|
||||
add_dependencies (_pyupm_${libname} ${libname}doc_i)
|
||||
else ()
|
||||
add_dependencies (${libname} doc)
|
||||
endif ()
|
||||
endif ()
|
||||
endmacro()
|
||||
|
||||
@ -95,8 +99,8 @@ endif()
|
||||
|
||||
macro(upm_module_init)
|
||||
add_library (${libname} SHARED ${module_src})
|
||||
include_directories (${MAA_INCLUDE_DIR} .)
|
||||
target_link_libraries (${libname} ${MAA_LIBRARIES})
|
||||
include_directories (${MRAA_INCLUDE_DIR} .)
|
||||
target_link_libraries (${libname} ${MRAA_LIBRARIES})
|
||||
set_target_properties(
|
||||
${libname}
|
||||
PROPERTIES PREFIX "libupm-"
|
||||
@ -107,6 +111,8 @@ macro(upm_module_init)
|
||||
if (SWIG_FOUND)
|
||||
upm_swig_python()
|
||||
upm_swig_node()
|
||||
endif()
|
||||
if (BUILDDOC)
|
||||
upm_doxygen()
|
||||
endif()
|
||||
install (TARGETS ${libname} DESTINATION lib COMPONENT ${libname})
|
||||
|
@ -30,22 +30,22 @@
|
||||
using namespace upm;
|
||||
|
||||
Buzzer::Buzzer (int pinNumber) {
|
||||
m_pwm_context = maa_pwm_init (pinNumber);
|
||||
m_pwm_context = mraa_pwm_init (pinNumber);
|
||||
m_name = "Buzzer";
|
||||
}
|
||||
|
||||
int Buzzer::playSound (int note) {
|
||||
maa_pwm_enable (m_pwm_context, 1);
|
||||
maa_pwm_period_us (m_pwm_context, note);
|
||||
maa_pwm_write (m_pwm_context, 50.0);
|
||||
usleep (10000);
|
||||
maa_pwm_enable (m_pwm_context, 0);
|
||||
int Buzzer::playSound (int note, int delay) {
|
||||
mraa_pwm_enable (m_pwm_context, 1);
|
||||
mraa_pwm_period_us (m_pwm_context, note);
|
||||
mraa_pwm_pulsewidth_us (m_pwm_context, note / 2);
|
||||
usleep (delay);
|
||||
mraa_pwm_enable (m_pwm_context, 0);
|
||||
|
||||
return 0;
|
||||
return note;
|
||||
}
|
||||
|
||||
Buzzer::~Buzzer() {
|
||||
maa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed maa_pwm_close" << std::endl;
|
||||
mraa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed mraa_pwm_close" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
#define DO 3830000 // 261 Hz
|
||||
#define RE 3400000 // 294 Hz
|
||||
#define MI 3038000 // 329 Hz
|
||||
#define FA 2864000 // 349 Hz
|
||||
#define SOL 2550000 // 392 Hz
|
||||
#define LA 2272000 // 440 Hz
|
||||
#define SI 2028000 // 493 Hz
|
||||
#define DO 3300 // 261 Hz 3830
|
||||
#define RE 2930 // 294 Hz
|
||||
#define MI 2600 // 329 Hz
|
||||
#define FA 2460 // 349 Hz
|
||||
#define SOL 2190 // 392 Hz
|
||||
#define LA 1960 // 440 Hz
|
||||
#define SI 1750 // 493 Hz
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -41,7 +41,7 @@ namespace upm {
|
||||
*
|
||||
* This file defines the Buzzer C++ interface for libbuzzer
|
||||
*
|
||||
* @snippet es08a.cxx Interesting
|
||||
* @snippet buzzer-sound.cxx Interesting
|
||||
*
|
||||
*/
|
||||
class Buzzer {
|
||||
@ -49,7 +49,7 @@ class Buzzer {
|
||||
/**
|
||||
* Instanciates a Buzzer object
|
||||
*
|
||||
* @param pin Buzzer pin number
|
||||
* @param pinNumber Buzzer pin number
|
||||
*/
|
||||
Buzzer (int pinNumber);
|
||||
|
||||
@ -62,8 +62,9 @@ class Buzzer {
|
||||
* Play chords.
|
||||
*
|
||||
* @param note chords (DO, RE, ME, etc...)
|
||||
* @param delay time in microsec for playing the sound
|
||||
*/
|
||||
int playSound (int note);
|
||||
int playSound (int note, int delay);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
@ -75,6 +76,6 @@ class Buzzer {
|
||||
protected:
|
||||
std::string m_name;
|
||||
private:
|
||||
maa_pwm_context m_pwm_context;
|
||||
mraa_pwm_context m_pwm_context;
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_buzzer
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_buzzer
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
3
src/carrays_uint16_t.i
Normal file
3
src/carrays_uint16_t.i
Normal file
@ -0,0 +1,3 @@
|
||||
%include "stdint.i"
|
||||
%include "carrays.i"
|
||||
%array_class(uint16_t, uint16Array);
|
@ -33,31 +33,31 @@ using namespace upm;
|
||||
|
||||
GroveLed::GroveLed(int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_gpio = maa_gpio_init(pin);
|
||||
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
|
||||
mraa_init();
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||
m_name = "LED Socket";
|
||||
}
|
||||
|
||||
GroveLed::~GroveLed()
|
||||
{
|
||||
maa_gpio_close(m_gpio);
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::write(int value)
|
||||
mraa_result_t GroveLed::write(int value)
|
||||
{
|
||||
if (value >= 1) {
|
||||
return maa_gpio_write(m_gpio, 1);
|
||||
return mraa_gpio_write(m_gpio, 1);
|
||||
}
|
||||
return maa_gpio_write(m_gpio, 0);
|
||||
return mraa_gpio_write(m_gpio, 0);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::on()
|
||||
mraa_result_t GroveLed::on()
|
||||
{
|
||||
return write(1);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::off()
|
||||
mraa_result_t GroveLed::off()
|
||||
{
|
||||
return write(0);
|
||||
}
|
||||
@ -66,19 +66,19 @@ maa_result_t GroveLed::off()
|
||||
|
||||
GroveTemp::GroveTemp(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Temperature Sensor";
|
||||
}
|
||||
|
||||
GroveTemp::~GroveTemp()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveTemp::value ()
|
||||
{
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
float r = (float)(1023-a)*10000/a;
|
||||
float t = 1/(logf(r/10000)/3975 + 1/298.15)-273.15;
|
||||
return (int) t;
|
||||
@ -86,32 +86,32 @@ int GroveTemp::value ()
|
||||
|
||||
float GroveTemp::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
//// GroveLight ////
|
||||
|
||||
GroveLight::GroveLight(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Light Sensor";
|
||||
}
|
||||
|
||||
GroveLight::~GroveLight()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveLight::value ()
|
||||
{
|
||||
// rough conversion to Lux
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
a = 10000/(((1023-a)*10/a)*15)^(4/3);
|
||||
return a;
|
||||
}
|
||||
|
||||
float GroveLight::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -40,35 +40,76 @@ class Grove {
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove LED
|
||||
*
|
||||
* Very basic UPM module for grove LED, or any LED for that matter
|
||||
*
|
||||
* @snippet groveled.cxx Interesting
|
||||
*/
|
||||
class GroveLed: public Grove {
|
||||
public:
|
||||
GroveLed(int pin);
|
||||
~GroveLed();
|
||||
maa_result_t write(int value);
|
||||
maa_result_t off();
|
||||
maa_result_t on();
|
||||
mraa_result_t write(int value);
|
||||
mraa_result_t off();
|
||||
mraa_result_t on();
|
||||
private:
|
||||
maa_gpio_context m_gpio;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove Temperature sensor
|
||||
*
|
||||
* Very basic UPM module for grove temperature sensor on analog
|
||||
*
|
||||
* @snippet grovetemp.cxx Interesting
|
||||
*/
|
||||
class GroveTemp: public Grove {
|
||||
public:
|
||||
GroveTemp(unsigned int pin);
|
||||
~GroveTemp();
|
||||
/**
|
||||
* Get raw value from AIO pin
|
||||
*
|
||||
* @return the raw value from the ADC
|
||||
*/
|
||||
float raw_value();
|
||||
/**
|
||||
* Get the temperature from the sensor
|
||||
*
|
||||
* @return the normalised temperature
|
||||
*/
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove light sensor
|
||||
*
|
||||
* Very basic UPM module for grove Light sensor on analog
|
||||
*
|
||||
* @snippet grovelight.cxx Interesting
|
||||
*/
|
||||
class GroveLight: public Grove {
|
||||
public:
|
||||
GroveLight(unsigned int pin);
|
||||
~GroveLight();
|
||||
/**
|
||||
* Get raw value from AIO pin
|
||||
*
|
||||
* @return the raw value from the ADC
|
||||
*/
|
||||
float raw_value();
|
||||
/**
|
||||
* Get the light value from the sensor
|
||||
*
|
||||
* @return the normalised light reading
|
||||
*/
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_grove
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "grove.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_grove
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
@ -36,10 +36,10 @@ GY65::GY65 (int bus, int devAddr, uint8_t mode) {
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ GY65::GY65 (int bus, int devAddr, uint8_t mode) {
|
||||
}
|
||||
|
||||
GY65::~GY65() {
|
||||
maa_i2c_stop(m_i2ControlCtx);
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
int32_t
|
||||
@ -180,13 +180,13 @@ GY65::computeB5(int32_t UT) {
|
||||
return X1 + X2;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
GY65::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = maa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
@ -195,11 +195,11 @@ uint16_t
|
||||
GY65::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, (uint8_t *)&data, 0x2);
|
||||
|
||||
uint8_t high = (data & 0xFF00) >> 8;
|
||||
data = (data << 8) & 0xFF00;
|
||||
@ -212,11 +212,11 @@ uint8_t
|
||||
GY65::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_write_byte(m_i2ControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
maa_i2c_read(m_i2ControlCtx, &data, 0x1);
|
||||
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
mraa_i2c_read(m_i2ControlCtx, &data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
#include <math.h>
|
||||
|
||||
#define ADDR 0x77 // device address
|
||||
@ -73,7 +73,8 @@ class GY65 {
|
||||
* Instanciates a GY65 object
|
||||
*
|
||||
* @param bus number of used bus
|
||||
* @param devAddr addres of used i2c device
|
||||
* @param devAddr address of used i2c device
|
||||
* @param mode BMP085 mode
|
||||
*/
|
||||
GY65 (int bus, int devAddr, uint8_t mode = BMP085_ULTRAHIGHRES);
|
||||
|
||||
@ -137,7 +138,7 @@ class GY65 {
|
||||
* @param reg address of a register
|
||||
* @param value byte to be written
|
||||
*/
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Read one byte register
|
||||
@ -151,7 +152,7 @@ class GY65 {
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2ControlCtx;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
|
||||
uint8_t oversampling;
|
||||
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_gy65
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "gy65.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_gy65
|
||||
%include "../upm.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
|
@ -31,44 +31,44 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void)) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "HCSR04";
|
||||
|
||||
m_pwmTriggerCtx = maa_pwm_init (triggerPin);
|
||||
m_pwmTriggerCtx = mraa_pwm_init (triggerPin);
|
||||
if (m_pwmTriggerCtx == NULL) {
|
||||
std::cout << "PWM context is NULL" << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_init();
|
||||
m_echoPinCtx = maa_gpio_init(echoPin);
|
||||
mraa_init();
|
||||
m_echoPinCtx = mraa_gpio_init(echoPin);
|
||||
if (m_echoPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", echoPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_gpio_dir(m_echoPinCtx, MAA_GPIO_IN);
|
||||
gpio_edge_t edge = MAA_GPIO_EDGE_BOTH;
|
||||
maa_gpio_isr (m_echoPinCtx, edge, fptr);
|
||||
mraa_gpio_dir(m_echoPinCtx, MRAA_GPIO_IN);
|
||||
gpio_edge_t edge = MRAA_GPIO_EDGE_BOTH;
|
||||
mraa_gpio_isr (m_echoPinCtx, edge, fptr, NULL);
|
||||
}
|
||||
|
||||
HCSR04::~HCSR04 () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
maa_pwm_close (m_pwmTriggerCtx);
|
||||
error = maa_gpio_close (m_echoPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
mraa_pwm_close (m_pwmTriggerCtx);
|
||||
error = mraa_gpio_close (m_echoPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
HCSR04::getDistance () {
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
maa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
maa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
mraa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
mraa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
|
||||
m_doWork = 0;
|
||||
m_InterruptCounter = 0;
|
||||
|
@ -24,9 +24,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define HIGH 1
|
||||
@ -55,7 +55,7 @@ class HCSR04 {
|
||||
* @param fptr function pointer for handling raising and
|
||||
* falling interrupts
|
||||
*/
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void));
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
|
||||
|
||||
/**
|
||||
* HCSR04 object destructor.
|
||||
@ -85,8 +85,8 @@ class HCSR04 {
|
||||
}
|
||||
|
||||
private:
|
||||
maa_pwm_context m_pwmTriggerCtx;
|
||||
maa_gpio_context m_echoPinCtx;
|
||||
mraa_pwm_context m_pwmTriggerCtx;
|
||||
mraa_gpio_context m_echoPinCtx;
|
||||
|
||||
uint8_t m_waitEcho;
|
||||
long m_RisingTimeStamp;
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_hcsr04
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "hcsr04.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_hcsr04
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
@ -79,17 +79,17 @@ using namespace upm;
|
||||
|
||||
Hmc5883l::Hmc5883l(int bus)
|
||||
{
|
||||
m_i2c = maa_i2c_init(bus);
|
||||
m_i2c = mraa_i2c_init(bus);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_CONF_REG_B;
|
||||
m_rx_tx_buf[1] = GA_1_3_REG;
|
||||
maa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
m_rx_tx_buf[0] = HMC5883L_MODE_REG;
|
||||
m_rx_tx_buf[1] = HMC5883L_CONT_MODE;
|
||||
maa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
mraa_i2c_write(m_i2c, m_rx_tx_buf, 2);
|
||||
|
||||
Hmc5883l::update();
|
||||
}
|
||||
@ -97,11 +97,11 @@ Hmc5883l::Hmc5883l(int bus)
|
||||
int
|
||||
Hmc5883l::update(void)
|
||||
{
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
maa_i2c_write_byte(m_i2c, HMC5883L_DATA_REG);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_write_byte(m_i2c, HMC5883L_DATA_REG);
|
||||
|
||||
maa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
maa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
|
||||
mraa_i2c_address(m_i2c, HMC5883L_I2C_ADDR);
|
||||
mraa_i2c_read(m_i2c, m_rx_tx_buf, DATA_REG_SIZE);
|
||||
|
||||
// x
|
||||
m_coor[0] = (m_rx_tx_buf[HMC5883L_X_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_X_LSB_REG];
|
||||
@ -110,7 +110,7 @@ Hmc5883l::update(void)
|
||||
// y
|
||||
m_coor[1] = (m_rx_tx_buf[HMC5883L_Y_MSB_REG] << 8 ) | m_rx_tx_buf[HMC5883L_Y_LSB_REG];
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
float
|
||||
|
@ -23,25 +23,44 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define MAX_BUFFER_LENGTH 6
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for HMC5883l (3-axis digital compass)
|
||||
*
|
||||
* This file defines the HMC5883l C++ interface for libhmc5883l
|
||||
*
|
||||
* @snippet hmc5883l.cxx Interesting
|
||||
*
|
||||
*/
|
||||
|
||||
class Hmc5883l {
|
||||
public:
|
||||
/// Creates a Hmc5883l object
|
||||
/**
|
||||
* Creates a Hmc5883l object
|
||||
*
|
||||
* @param bus number of used i2c bus
|
||||
*
|
||||
*/
|
||||
Hmc5883l(int bus);
|
||||
|
||||
/// Returns the direction
|
||||
/*
|
||||
* Returns the direction
|
||||
*/
|
||||
float direction();
|
||||
|
||||
/// Returns the heading
|
||||
/*
|
||||
* Returns the heading
|
||||
*/
|
||||
float heading();
|
||||
|
||||
/**
|
||||
* Returns a pointer to an int[3] that contains the coordinates as ints
|
||||
*
|
||||
* @return *int to an int[3]
|
||||
*/
|
||||
int* coordinates();
|
||||
@ -55,7 +74,7 @@ public:
|
||||
private:
|
||||
int m_coor[3];
|
||||
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
|
||||
maa_i2c_context m_i2c;
|
||||
mraa_i2c_context m_i2c;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_hmc5883l
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "hmc5883l.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_hmc5883l
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
@ -33,54 +33,54 @@ I2CLcd::I2CLcd (int bus, int lcdAddress) {
|
||||
m_lcd_control_address = lcdAddress;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2c_lcd_control = maa_i2c_init(m_bus);
|
||||
m_i2c_lcd_control = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
I2CLcd::write (int row, int column, std::string msg) {
|
||||
setCursor (row, column);
|
||||
write (msg);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
I2CLcd::close() {
|
||||
return maa_i2c_stop(m_i2c_lcd_control);
|
||||
return mraa_i2c_stop(m_i2c_lcd_control);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { addr, value };
|
||||
error = maa_i2c_address (ctx, deviceAdress);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, deviceAdress);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2Cmd (maa_i2c_context ctx, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2Cmd (mraa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_CMD, value };
|
||||
error = maa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
I2CLcd::i2cData (maa_i2c_context ctx, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t
|
||||
I2CLcd::i2cData (mraa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { LCD_DATA, value };
|
||||
error = maa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = maa_i2c_write (ctx, data, 2);
|
||||
error = mraa_i2c_address (ctx, m_lcd_control_address);
|
||||
error = mraa_i2c_write (ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -55,6 +55,11 @@ namespace upm {
|
||||
#define LCD_BLINKON 0x01
|
||||
#define LCD_BLINKOFF 0x00
|
||||
|
||||
// flags for display/cursor shift
|
||||
#define LCD_DISPLAYMOVE 0x08
|
||||
#define LCD_MOVERIGHT 0x04
|
||||
#define LCD_MOVELEFT 0x00
|
||||
|
||||
// flags for function set
|
||||
#define LCD_8BITMODE 0x10
|
||||
#define LCD_4BITMODE 0x00
|
||||
@ -70,17 +75,17 @@ namespace upm {
|
||||
class I2CLcd {
|
||||
public:
|
||||
I2CLcd (int bus, int lcdAddress);
|
||||
maa_result_t write (int x, int y, std::string msg);
|
||||
|
||||
virtual maa_result_t write (std::string msg) = 0;
|
||||
virtual maa_result_t setCursor (int row, int column) = 0;
|
||||
virtual maa_result_t clear () = 0;
|
||||
virtual maa_result_t home () = 0;
|
||||
virtual maa_result_t i2Cmd (maa_i2c_context ctx, uint8_t value);
|
||||
virtual maa_result_t i2cReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual maa_result_t i2cData (maa_i2c_context ctx, uint8_t value);
|
||||
|
||||
maa_result_t close();
|
||||
mraa_result_t write (int x, int y, std::string msg);
|
||||
|
||||
virtual mraa_result_t write (std::string msg) = 0;
|
||||
virtual mraa_result_t setCursor (int row, int column) = 0;
|
||||
virtual mraa_result_t clear () = 0;
|
||||
virtual mraa_result_t home () = 0;
|
||||
virtual mraa_result_t i2Cmd (mraa_i2c_context ctx, uint8_t value);
|
||||
virtual mraa_result_t i2cReg (mraa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
|
||||
virtual mraa_result_t i2cData (mraa_i2c_context ctx, uint8_t value);
|
||||
|
||||
mraa_result_t close();
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
@ -89,7 +94,7 @@ class I2CLcd {
|
||||
std::string m_name;
|
||||
int m_lcd_control_address;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2c_lcd_control;
|
||||
mraa_i2c_context m_i2c_lcd_control;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,13 +30,13 @@
|
||||
using namespace upm;
|
||||
|
||||
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
m_rgb_address = rgbAddress;
|
||||
m_i2c_lcd_rgb = maa_i2c_init(m_bus);
|
||||
m_i2c_lcd_rgb = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
|
||||
i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
|
||||
clear ();
|
||||
usleep(4500);
|
||||
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
|
||||
LCD_ENTRYLEFT |
|
||||
LCD_ENTRYSHIFTDECREMENT);
|
||||
@ -67,7 +67,29 @@ Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcd
|
||||
}
|
||||
|
||||
Jhd1313m1::~Jhd1313m1() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::setColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
|
||||
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, r);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, g);
|
||||
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, b);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
Jhd1313m1::scroll(bool direction)
|
||||
{
|
||||
if (direction)
|
||||
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT));
|
||||
return i2Cmd (m_i2c_lcd_control, (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -75,9 +97,9 @@ Jhd1313m1::~Jhd1313m1() {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t data[2] = {0x40, 0};
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = i2cData (m_i2c_lcd_control, msg[i]);
|
||||
@ -86,9 +108,9 @@ Jhd1313m1::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
error = i2Cmd (m_i2c_lcd_control, offset);
|
||||
@ -96,12 +118,12 @@ Jhd1313m1::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::clear () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Jhd1313m1::home () {
|
||||
return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
|
||||
}
|
||||
|
@ -28,18 +28,74 @@
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for Jhd1313m1 i2c controller for HD44780 based displays with
|
||||
* an RGB backlight such as the Grove RGB i2c LCD display
|
||||
*
|
||||
* @snippet rgb-lcd.cxx Interesting
|
||||
*/
|
||||
class Jhd1313m1 : public I2CLcd {
|
||||
public:
|
||||
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
|
||||
~Jhd1313m1 ();
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
/**
|
||||
* Jhd1313m1 constructor
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
* @param address the slave address the rgb backlight is on
|
||||
*/
|
||||
Jhd1313m1(int bus, int lcdAddress, int rgbAddress);
|
||||
/**
|
||||
* Jhd1313m1 destructor
|
||||
*/
|
||||
~Jhd1313m1();
|
||||
/**
|
||||
* Make the LCD scroll text
|
||||
*
|
||||
* @param direction, true is typical scrolling to the right
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t scroll (bool direction);
|
||||
/**
|
||||
* Set the color of the backlight
|
||||
*
|
||||
* @param r 0-255 value for red
|
||||
* @param g 0-255 value for green
|
||||
* @param b 0-255 value for blue
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private:
|
||||
int m_rgb_address;
|
||||
maa_i2c_context m_i2c_lcd_rgb;
|
||||
mraa_i2c_context m_i2c_lcd_rgb;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_i2clcd
|
||||
%include "../upm.i"
|
||||
|
||||
%include "i2clcd.h"
|
||||
%{
|
||||
|
@ -33,7 +33,7 @@
|
||||
using namespace upm;
|
||||
|
||||
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
usleep(50000);
|
||||
expandWrite(LCD_BACKLIGHT);
|
||||
@ -61,7 +61,7 @@ Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
}
|
||||
|
||||
Lcm1602::~Lcm1602 () {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -69,18 +69,18 @@ Lcm1602::~Lcm1602 () {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
error = send (msg[i], LCD_RS);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
|
||||
uint8_t offset = ((column % 16) + row_addr[row]);
|
||||
@ -88,12 +88,12 @@ Lcm1602::setCursor (int row, int column) {
|
||||
return send (LCD_CMD | offset, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::clear () {
|
||||
return send(LCD_CLEARDISPLAY, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::home () {
|
||||
return send(LCD_RETURNHOME, 0);
|
||||
}
|
||||
@ -103,9 +103,9 @@ Lcm1602::home () {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::send (uint8_t value, int mode) {
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
uint8_t h = value & 0xf0;
|
||||
uint8_t l = (value << 4) & 0xf0;
|
||||
ret = write4bits(h | mode);
|
||||
@ -113,26 +113,26 @@ Lcm1602::send (uint8_t value, int mode) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::write4bits(uint8_t value)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
ret = expandWrite(value);
|
||||
ret = pulseEnable(value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::expandWrite(uint8_t value)
|
||||
{
|
||||
uint8_t buffer = value | LCD_BACKLIGHT;
|
||||
return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
|
||||
return mraa_i2c_write_byte(m_i2c_lcd_control, buffer);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
Lcm1602::pulseEnable(uint8_t value)
|
||||
{
|
||||
maa_result_t ret = MAA_SUCCESS;
|
||||
mraa_result_t ret = MRAA_SUCCESS;
|
||||
ret = expandWrite(value | LCD_EN);
|
||||
usleep(1);
|
||||
ret = expandWrite(value & ~LCD_EN);
|
||||
|
@ -32,24 +32,61 @@
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for LCM1602 i2c controller for HD44780 based displays
|
||||
*
|
||||
* This supports all sizes of HD44780 displays from 16x2 to 4x20, the
|
||||
* controller has no idea of the actual display hardware so will let you write
|
||||
* further than you can see
|
||||
*
|
||||
* @snippet lcm-lcd.cxx Interesting
|
||||
*/
|
||||
class Lcm1602 : public I2CLcd {
|
||||
public:
|
||||
/** LCM1602 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
*/
|
||||
/**
|
||||
* Lcm1602 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
Lcm1602(int bus, int address);
|
||||
/**
|
||||
* Lcm1602 Destructor
|
||||
*/
|
||||
~Lcm1602();
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private :
|
||||
maa_result_t send (uint8_t value, int mode);
|
||||
maa_result_t write4bits(uint8_t value);
|
||||
maa_result_t expandWrite(uint8_t value);
|
||||
maa_result_t pulseEnable(uint8_t value);
|
||||
mraa_result_t send(uint8_t value, int mode);
|
||||
mraa_result_t write4bits(uint8_t value);
|
||||
mraa_result_t expandWrite(uint8_t value);
|
||||
mraa_result_t pulseEnable(uint8_t value);
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_i2clcd
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
@ -45,9 +45,9 @@ SSD1308::~SSD1308 () {
|
||||
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::draw (uint8_t *data, int bytes) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setAddressingMode (HORIZONTAL);
|
||||
for (int idx = 0; idx < bytes; idx++) {
|
||||
@ -62,9 +62,9 @@ SSD1308::draw (uint8_t *data, int bytes) {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t data[2] = {0x40, 0};
|
||||
|
||||
setAddressingMode (PAGE);
|
||||
@ -75,9 +75,9 @@ SSD1308::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_PAGE_START_ADDR + row); // set page address
|
||||
error = i2Cmd (m_i2c_lcd_control, BASE_LOW_COLUMN_ADDR + (8 * column & 0x0F)); // set column lower address
|
||||
@ -86,9 +86,9 @@ SSD1308::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::clear () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
|
||||
@ -103,10 +103,10 @@ SSD1308::clear () {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
|
||||
home ();
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::home () {
|
||||
return setCursor (0, 0);
|
||||
}
|
||||
@ -116,8 +116,8 @@ SSD1308::home () {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t
|
||||
SSD1308::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
@ -127,12 +127,12 @@ SSD1308::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1308::setAddressingMode (displayAddressingMode mode) {
|
||||
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_MEM_ADDR_MODE); //set addressing mode
|
||||
i2Cmd (m_i2c_lcd_control, mode); //set page addressing mode
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace upm {
|
||||
|
||||
#define DISPLAY_CMD_OFF 0xAE
|
||||
#define DISPLAY_CMD_OFF 0xAE
|
||||
#define DISPLAY_CMD_ON 0xAF
|
||||
|
||||
#define BASE_LOW_COLUMN_ADDR 0x00
|
||||
@ -145,26 +145,64 @@ typedef enum {
|
||||
PAGE = 2
|
||||
} displayAddressingMode;
|
||||
|
||||
/**
|
||||
* @brief C++ API for SSD1308 i2c controlled OLED displays
|
||||
*
|
||||
* @snippet lcm-lcd.cxx Interesting
|
||||
*/
|
||||
class SSD1308 : public I2CLcd {
|
||||
public:
|
||||
/** SSD1308 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
*/
|
||||
/**
|
||||
* SSD1308 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1308 (int bus, int address);
|
||||
/**
|
||||
* SSD1308 Destructor
|
||||
*/
|
||||
~SSD1308 ();
|
||||
maa_result_t draw(uint8_t *data, int bytes);
|
||||
|
||||
// pure virtual methods
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
private:
|
||||
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
|
||||
maa_result_t setNormalDisplay ();
|
||||
maa_result_t setAddressingMode (displayAddressingMode mode);
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setAddressingMode (displayAddressingMode mode);
|
||||
};
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ using namespace upm;
|
||||
#define CMD_SLEEP 10000
|
||||
|
||||
SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
usleep (INIT_SLEEP);
|
||||
i2Cmd (m_i2c_lcd_control, 0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands
|
||||
usleep (INIT_SLEEP);
|
||||
@ -123,9 +123,9 @@ SSD1327::~SSD1327 () {
|
||||
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::draw (uint8_t *data, int bytes) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setHorizontalMode ();
|
||||
for (int row = 0; row < bytes; row++) {
|
||||
@ -151,9 +151,9 @@ SSD1327::draw (uint8_t *data, int bytes) {
|
||||
* virtual area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::write (std::string msg) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
setVerticalMode ();
|
||||
for (std::string::size_type i = 0; i < msg.size(); ++i) {
|
||||
@ -163,9 +163,9 @@ SSD1327::write (std::string msg) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setCursor (int row, int column) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
//Column Address
|
||||
i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
|
||||
@ -185,9 +185,9 @@ SSD1327::setCursor (int row, int column) {
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::clear () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
uint8_t columnIdx, rowIdx;
|
||||
|
||||
for(rowIdx = 0; rowIdx < 12; rowIdx++) {
|
||||
@ -197,15 +197,15 @@ SSD1327::clear () {
|
||||
}
|
||||
}
|
||||
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::home () {
|
||||
return setCursor (0, 0);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setGrayLevel (uint8_t level) {
|
||||
grayHigh = (level << 4) & 0xF0;
|
||||
grayLow = level & 0x0F;
|
||||
@ -216,8 +216,8 @@ SSD1327::setGrayLevel (uint8_t level) {
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
maa_result_t
|
||||
SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
mraa_result_t
|
||||
SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
|
||||
if (value < 0x20 || value > 0x7F) {
|
||||
value = 0x20; // space
|
||||
}
|
||||
@ -238,12 +238,12 @@ SSD1327::writeChar (maa_i2c_context ctx, uint8_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setNormalDisplay () {
|
||||
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setHorizontalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
@ -267,7 +267,7 @@ SSD1327::setHorizontalMode () {
|
||||
usleep (CMD_SLEEP);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
SSD1327::setVerticalMode () {
|
||||
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
|
||||
usleep (CMD_SLEEP);
|
||||
|
@ -147,27 +147,67 @@ typedef enum {
|
||||
|
||||
class SSD1327 : public I2CLcd {
|
||||
public:
|
||||
/** SSD1308 Constructor.
|
||||
* Calls MAA initialisation functions.
|
||||
/**
|
||||
* SSD1308 Constructor, calls libmraa initialisation functions
|
||||
*
|
||||
* @param bus i2c bus to use
|
||||
* @param address the slave address the lcd is registered on.
|
||||
* @param address the slave address the lcd is registered on
|
||||
*/
|
||||
SSD1327 (int bus, int address);
|
||||
/**
|
||||
* SSD1327 destructor
|
||||
*/
|
||||
~SSD1327 ();
|
||||
maa_result_t draw(uint8_t *data, int bytes);
|
||||
|
||||
// virtual methods
|
||||
maa_result_t write (std::string msg);
|
||||
maa_result_t setCursor (int row, int column);
|
||||
maa_result_t clear ();
|
||||
maa_result_t home ();
|
||||
maa_result_t setGrayLevel (uint8_t level);
|
||||
/**
|
||||
* Draw an image, see examples/python/make_oled_pic.py for an
|
||||
* explanation on how the pixels are mapped to bytes
|
||||
*
|
||||
* @param data the buffer to read
|
||||
* @param bytes the amount of bytes to read from the pointer
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t draw(uint8_t *data, int bytes);
|
||||
/**
|
||||
* Set gray level for LCD panel
|
||||
*
|
||||
* @param gray level from 0-255
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setGrayLevel (uint8_t level);
|
||||
/**
|
||||
* Write a string to LCD
|
||||
*
|
||||
* @param msg The std::string to write to display, note only ascii
|
||||
* chars are supported
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t write(std::string msg);
|
||||
/**
|
||||
* Set cursor to a coordinate
|
||||
*
|
||||
* @param row The row to set cursor to
|
||||
* @param column The column to set cursor to
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t setCursor(int row, int column);
|
||||
/**
|
||||
* Clear display from characters
|
||||
*
|
||||
* @return Result of operatio
|
||||
*/
|
||||
mraa_result_t clear();
|
||||
/**
|
||||
* Return to coordinate 0,0
|
||||
*
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t home();
|
||||
|
||||
private:
|
||||
maa_result_t writeChar (maa_i2c_context ctx, uint8_t value);
|
||||
maa_result_t setNormalDisplay ();
|
||||
maa_result_t setHorizontalMode ();
|
||||
maa_result_t setVerticalMode ();
|
||||
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
|
||||
mraa_result_t setNormalDisplay ();
|
||||
mraa_result_t setHorizontalMode ();
|
||||
mraa_result_t setVerticalMode ();
|
||||
|
||||
uint8_t grayHigh;
|
||||
uint8_t grayLow;
|
||||
|
5
src/max31723/CMakeLists.txt
Normal file
5
src/max31723/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "max31723")
|
||||
set (libdescription "Very accurate temperature sensor")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
8
src/max31723/jsupm_max31723.i
Normal file
8
src/max31723/jsupm_max31723.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_max31723
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "max31723.h"
|
||||
%}
|
||||
|
||||
%include "max31723.h"
|
139
src/max31723/max31723.cxx
Normal file
139
src/max31723/max31723.cxx
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "max31723.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
struct MAX31723Exception : public std::exception {
|
||||
std::string message;
|
||||
MAX31723Exception (std::string msg) : message (msg) { }
|
||||
~MAX31723Exception () throw () { }
|
||||
const char* what() const throw () { return message.c_str(); }
|
||||
};
|
||||
|
||||
MAX31723::MAX31723 (int csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "MAX31723";
|
||||
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
throw MAX31723Exception ("GPIO failed to initilize");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
throw MAX31723Exception ("GPIO failed to initilize");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
throw MAX31723Exception ("SPI failed to initilize");
|
||||
}
|
||||
|
||||
// set spi mode to mode2 (CPOL = 1, CPHA = 0)
|
||||
mraa_spi_mode (m_spi, MRAA_SPI_MODE2);
|
||||
// set ontinuously perform temperature conversions
|
||||
writeRegister (R_STS_WRITE_CMD, B_CONT_READING);
|
||||
}
|
||||
|
||||
MAX31723::~MAX31723() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
short
|
||||
MAX31723::getTemperature () {
|
||||
uint8_t lsb = 0;
|
||||
uint8_t msb = 0;
|
||||
short temperature = 0;
|
||||
|
||||
lsb = readRegister (R_TEMPERATURE_LSB);
|
||||
msb = readRegister (R_TEMPERATURE_MSB);
|
||||
|
||||
if ((msb & 0x80) != 0) {
|
||||
msb &= 0x7F;
|
||||
temperature = 0 - msb;
|
||||
|
||||
} else {
|
||||
temperature = msb;
|
||||
}
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
|
||||
uint8_t
|
||||
MAX31723::readRegister (uint8_t reg) {
|
||||
uint8_t data[2] = { 0x00, 0x00 };
|
||||
uint8_t* sensorData = NULL;
|
||||
|
||||
CSOn ();
|
||||
data[0] = reg;
|
||||
sensorData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
CSOff ();
|
||||
|
||||
return sensorData[1];
|
||||
}
|
||||
|
||||
void
|
||||
MAX31723::writeRegister (uint8_t reg, uint8_t data) {
|
||||
uint8_t buffer[2] = { 0x00, 0x00 };
|
||||
uint8_t* sensorData = NULL;
|
||||
|
||||
CSOn ();
|
||||
buffer[0] = reg;
|
||||
buffer[1] = data;
|
||||
sensorData = mraa_spi_write_buf(m_spi, buffer, 2);
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MAX31723::CSOn () {
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MAX31723::CSOff () {
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
}
|
95
src/max31723/max31723.h
Normal file
95
src/max31723/max31723.h
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for MAX31723 chip (Temperature sensor)
|
||||
*
|
||||
* This file defines the MAX31723 C++ interface for libmax31723
|
||||
*
|
||||
*/
|
||||
class MAX31723 {
|
||||
public:
|
||||
static const uint8_t R_STS_READ_CMD = 0x00;
|
||||
static const uint8_t R_STS_WRITE_CMD = 0x80;
|
||||
static const uint8_t R_TEMPERATURE_LSB = 0x01;
|
||||
static const uint8_t R_TEMPERATURE_MSB = 0x02;
|
||||
|
||||
static const uint8_t B_CONT_READING = 0x00;
|
||||
|
||||
/**
|
||||
* Instanciates a MAX31723 object
|
||||
*
|
||||
* @param bus number of used bus
|
||||
* @param devAddr addres of used i2c device
|
||||
*/
|
||||
MAX31723 (int csn);
|
||||
|
||||
/**
|
||||
* MAXDS3231M object destructor, basicaly it close i2c connection.
|
||||
*/
|
||||
~MAX31723 ();
|
||||
|
||||
/**
|
||||
* Get on board temperature.
|
||||
*/
|
||||
short getTemperature ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
|
||||
uint8_t readRegister (uint8_t reg);
|
||||
void writeRegister (uint8_t reg, uint8_t data);
|
||||
|
||||
/**
|
||||
* Set chip select pin LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
|
||||
/**
|
||||
* Set chip select pin HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
};
|
||||
|
||||
}
|
9
src/max31723/pyupm_max31723.i
Normal file
9
src/max31723/pyupm_max31723.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_max31723
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "max31723.h"
|
||||
%{
|
||||
#include "max31723.h"
|
||||
%}
|
@ -1,5 +1,6 @@
|
||||
//! [Interesting]
|
||||
%module jsupm_max31855
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "max31855.h"
|
||||
|
@ -36,12 +36,12 @@ using namespace upm;
|
||||
MAX31855::MAX31855(int bus, int cs)
|
||||
{
|
||||
// initialise chip select as a normal gpio
|
||||
m_gpio = maa_gpio_init(cs);
|
||||
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
|
||||
m_gpio = mraa_gpio_init(cs);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||
|
||||
// initialise the spi bus with a 2Mhz clock
|
||||
m_sensor = maa_spi_init(bus);
|
||||
maa_spi_frequency(m_sensor, 2000000);
|
||||
m_sensor = mraa_spi_init(bus);
|
||||
mraa_spi_frequency(m_sensor, 2000000);
|
||||
}
|
||||
//! [Constructor]
|
||||
|
||||
@ -49,14 +49,14 @@ MAX31855::MAX31855(int bus, int cs)
|
||||
MAX31855::~MAX31855()
|
||||
{
|
||||
// close both m_sensor & m_gpio cleanly
|
||||
maa_result_t error;
|
||||
error = maa_spi_stop(m_sensor);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
mraa_result_t error;
|
||||
error = mraa_spi_stop(m_sensor);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = maa_gpio_close(m_gpio);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print(error);
|
||||
error = mraa_gpio_close(m_gpio);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
//! [Destructor]
|
||||
@ -66,7 +66,7 @@ MAX31855::getTemp()
|
||||
{
|
||||
//! [spi]
|
||||
// set chip select low
|
||||
maa_gpio_write(m_gpio, 0);
|
||||
mraa_gpio_write(m_gpio, 0);
|
||||
|
||||
uint8_t buf[4];
|
||||
|
||||
@ -74,14 +74,14 @@ MAX31855::getTemp()
|
||||
memset(buf, 0, sizeof(uint8_t)*4);
|
||||
|
||||
// Write buffer to the spi slave
|
||||
uint8_t* x = maa_spi_write_buf(m_sensor, buf, 4);
|
||||
uint8_t* x = mraa_spi_write_buf(m_sensor, buf, 4);
|
||||
//! [spi]
|
||||
|
||||
//! [conversion]
|
||||
// Endian correct way of making our char array into an 32bit int
|
||||
int32_t temp = (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3];;
|
||||
|
||||
// maa_spi_write_buf does not free the return buffer
|
||||
// mraa_spi_write_buf does not free the return buffer
|
||||
free(x);
|
||||
|
||||
if (temp & 0x7) {
|
||||
@ -97,7 +97,7 @@ MAX31855::getTemp()
|
||||
//! [conversion]
|
||||
|
||||
// set chip select high
|
||||
maa_gpio_write(m_gpio, 1);
|
||||
mraa_gpio_write(m_gpio, 1);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/spi.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -61,8 +61,8 @@ class MAX31855 {
|
||||
double getTemp();
|
||||
|
||||
private:
|
||||
maa_spi_context m_sensor;
|
||||
maa_gpio_context m_gpio;
|
||||
mraa_spi_context m_sensor;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
//! [Interesting]
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_max31855
|
||||
%include "../upm.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_max44000
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "max44000.h"
|
||||
|
@ -36,10 +36,10 @@ MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
m_maxControlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2cMaxControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2cMaxControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t ret = maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
if (ret != MAA_SUCCESS) {
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ MAX44000::MAX44000 (int bus, int devAddr) {
|
||||
}
|
||||
|
||||
MAX44000::~MAX44000() {
|
||||
maa_i2c_stop(m_i2cMaxControlCtx);
|
||||
mraa_i2c_stop(m_i2cMaxControlCtx);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
@ -80,11 +80,11 @@ uint8_t
|
||||
MAX44000::i2cReadReg_8 (int reg) {
|
||||
uint8_t data;
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -93,22 +93,22 @@ uint16_t
|
||||
MAX44000::i2cReadReg_16 (int reg) {
|
||||
uint16_t data;
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
|
||||
|
||||
maa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
maa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
|
||||
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
mraa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MAX44000::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = maa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
error = maa_i2c_write (m_i2cMaxControlCtx, data, 2);
|
||||
error = mraa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
|
||||
error = mraa_i2c_write (m_i2cMaxControlCtx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define ADDR 0x4A // device address
|
||||
|
||||
@ -122,14 +122,14 @@ class MAX44000 {
|
||||
* @param reg address of a register
|
||||
* @param value byte to be written
|
||||
*/
|
||||
maa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_maxControlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2cMaxControlCtx;
|
||||
mraa_i2c_context m_i2cMaxControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_max44000
|
||||
%include "../upm.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
|
5
src/max5487/CMakeLists.txt
Normal file
5
src/max5487/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "max5487")
|
||||
set (libdescription "Digital potentiometer")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
8
src/max5487/jsupm_max5487.i
Normal file
8
src/max5487/jsupm_max5487.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_max5487
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "max5487.h"
|
||||
%}
|
||||
|
||||
%include "max5487.h"
|
117
src/max5487/max5487.cxx
Normal file
117
src/max5487/max5487.cxx
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "max5487.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
struct MAX5487Exception : public std::exception {
|
||||
std::string message;
|
||||
MAX5487Exception (std::string msg) : message (msg) { }
|
||||
~MAX5487Exception () throw () { }
|
||||
const char* what() const throw () { return message.c_str(); }
|
||||
};
|
||||
|
||||
MAX5487::MAX5487 (int csn) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "MAX5487";
|
||||
|
||||
m_csnPinCtx = mraa_gpio_init (csn);
|
||||
if (m_csnPinCtx == NULL) {
|
||||
throw MAX5487Exception ("GPIO failed to initilize");
|
||||
}
|
||||
|
||||
error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
throw MAX5487Exception ("GPIO failed to initilize");
|
||||
}
|
||||
|
||||
m_spi = mraa_spi_init (0);
|
||||
if (m_spi == NULL) {
|
||||
throw MAX5487Exception ("SPI failed to initilize");
|
||||
}
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
MAX5487::~MAX5487() {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_spi_stop(m_spi);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
error = mraa_gpio_close (m_csnPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MAX5487::setWiperA (uint8_t wiper) {
|
||||
uint8_t data[2] = { 0x00, 0x00};
|
||||
|
||||
CSOn ();
|
||||
|
||||
data[0] = R_WR_WIPER_A;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
void
|
||||
MAX5487::setWiperB (uint8_t wiper) {
|
||||
uint8_t data[2] = { 0x00, 0x00};
|
||||
|
||||
CSOn ();
|
||||
|
||||
data[0] = R_WR_WIPER_B;
|
||||
data[1] = wiper;
|
||||
|
||||
uint8_t* retData = mraa_spi_write_buf(m_spi, data, 2);
|
||||
|
||||
CSOff ();
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
|
||||
mraa_result_t
|
||||
MAX5487::CSOn () {
|
||||
return mraa_gpio_write (m_csnPinCtx, LOW);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MAX5487::CSOff () {
|
||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||
}
|
93
src/max5487/max5487.h
Normal file
93
src/max5487/max5487.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/spi.h>
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for MAX5487 chip (Temperature sensor)
|
||||
*
|
||||
* This file defines the MAX5487 C++ interface for libmax5487
|
||||
*
|
||||
*/
|
||||
class MAX5487 {
|
||||
public:
|
||||
static const uint8_t R_WR_WIPER_A = 0x01;
|
||||
static const uint8_t R_WR_WIPER_B = 0x02;
|
||||
|
||||
/**
|
||||
* Instanciates a MAX5487 object
|
||||
*
|
||||
* @param bus number of used bus
|
||||
* @param devAddr addres of used i2c device
|
||||
*/
|
||||
MAX5487 (int csn);
|
||||
|
||||
/**
|
||||
* MAX5487 object destructor, basicaly it close SPI connection and GPIO.
|
||||
*/
|
||||
~MAX5487 ();
|
||||
|
||||
/**
|
||||
* Set wiper for port A.
|
||||
*/
|
||||
void setWiperA (uint8_t wiper);
|
||||
|
||||
/**
|
||||
* Set wiper for port B.
|
||||
*/
|
||||
void setWiperB (uint8_t wiper);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_spi_context m_spi;
|
||||
mraa_gpio_context m_csnPinCtx;
|
||||
|
||||
/**
|
||||
* Set chip select pin LOW
|
||||
*/
|
||||
mraa_result_t CSOn ();
|
||||
|
||||
/**
|
||||
* Set chip select pin HIGH
|
||||
*/
|
||||
mraa_result_t CSOff ();
|
||||
};
|
||||
|
||||
}
|
9
src/max5487/pyupm_max5487.i
Normal file
9
src/max5487/pyupm_max5487.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_max5487
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "max5487.h"
|
||||
%{
|
||||
#include "max5487.h"
|
||||
%}
|
5
src/maxds3231m/CMakeLists.txt
Normal file
5
src/maxds3231m/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "maxds3231m")
|
||||
set (libdescription "realtime clock sensor from MAX family")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
8
src/maxds3231m/jsupm_maxds3231m.i
Normal file
8
src/maxds3231m/jsupm_maxds3231m.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_maxds3231m
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "maxds3231m.h"
|
||||
%}
|
||||
|
||||
%include "maxds3231m.h"
|
146
src/maxds3231m/maxds3231m.cxx
Normal file
146
src/maxds3231m/maxds3231m.cxx
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "maxds3231m.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
struct DS3231Exception : public std::exception {
|
||||
std::string message;
|
||||
DS3231Exception (std::string msg) : message (msg) { }
|
||||
~DS3231Exception () throw () { }
|
||||
const char* what() const throw () { return message.c_str(); }
|
||||
};
|
||||
|
||||
MAXDS3231M::MAXDS3231M (int bus, int devAddr) {
|
||||
m_name = "MAXDS3231M";
|
||||
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2Ctx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
throw DS3231Exception ("Couldn't initilize I2C.");
|
||||
}
|
||||
}
|
||||
|
||||
MAXDS3231M::~MAXDS3231M() {
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
void
|
||||
MAXDS3231M::setDate (Time3231 &time) {
|
||||
uint8_t *data = (uint8_t *)&time;
|
||||
|
||||
i2cWriteReg_N (TIME_CAL_ADDR, 7, data);
|
||||
}
|
||||
|
||||
bool
|
||||
MAXDS3231M::getDate (Time3231 &time) {
|
||||
uint8_t buffer[7];
|
||||
|
||||
// We need 7 bytes of data.
|
||||
if (i2cReadReg_N (TIME_CAL_ADDR, 7, buffer) > 6) {
|
||||
uint8_t century = (buffer[5] & 0x80) >> 7;
|
||||
|
||||
time.second = BCDtoDEC(buffer[0]);
|
||||
time.minute = BCDtoDEC(buffer[1]);
|
||||
time.hour = BCDtoDEC(buffer[2]);
|
||||
time.day = BCDtoDEC(buffer[4]);
|
||||
time.month = BCDtoDEC(buffer[5] & 0x1F);
|
||||
time.year = (century == 1) ? 2000 + BCDtoDEC(buffer[6]) : 1900 + BCDtoDEC(buffer[6]);
|
||||
time.weekDay = BCDtoDEC(buffer[3]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
MAXDS3231M::getTemperature () {
|
||||
uint8_t buffer[2];
|
||||
uint8_t msb = 0;
|
||||
uint8_t lsb = 0;
|
||||
|
||||
i2cReadReg_N (TEMPERATURE_ADDR, 2, buffer);
|
||||
msb = buffer[0];
|
||||
lsb = buffer[1] >> 6;
|
||||
|
||||
if ((msb & 0x80) != 0)
|
||||
msb |= ~((1 << 8) - 1); // if negative get two's complement
|
||||
|
||||
return 0.25 * lsb + msb;
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
uint16_t
|
||||
MAXDS3231M::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
|
||||
if (m_i2Ctx == NULL) {
|
||||
throw DS3231Exception ("Couldn't find initilized I2C.");
|
||||
}
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MAXDS3231M::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
if (m_i2Ctx == NULL) {
|
||||
throw DS3231Exception ("Couldn't find initilized I2C.");
|
||||
}
|
||||
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, buffer, len);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MAXDS3231M::DECtoBSD(uint8_t data) {
|
||||
return ((data / 10 * 16) + (data % 10));
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MAXDS3231M::BCDtoDEC(uint8_t data) {
|
||||
return ((data / 16 * 10) + (data % 16));
|
||||
}
|
125
src/maxds3231m/maxds3231m.h
Normal file
125
src/maxds3231m/maxds3231m.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define ADDR 0x68 // device address
|
||||
|
||||
// timekeeping registers
|
||||
#define TIME_CAL_ADDR 0x00
|
||||
#define ALARM1_ADDR 0x07
|
||||
#define ALARM2_ADDR 0x0B
|
||||
#define CONTROL_ADDR 0x0E
|
||||
#define STATUS_ADDR 0x0F
|
||||
#define AGING_OFFSET_ADDR 0x10
|
||||
#define TEMPERATURE_ADDR 0x11
|
||||
|
||||
// control register bits
|
||||
#define A1IE 0x1
|
||||
#define A2IE 0x2
|
||||
#define INTCN 0x4
|
||||
|
||||
// status register bits
|
||||
#define A1F 0x1
|
||||
#define A2F 0x2
|
||||
#define OSF 0x80
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
struct Time3231 {
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
int16_t year;
|
||||
uint8_t weekDay;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for MAXDS3231M chip (Ambient and Infrared Proximity Sensor)
|
||||
*
|
||||
* This file defines the MAXDS3231M C++ interface for libmax44000
|
||||
*
|
||||
*/
|
||||
class MAXDS3231M {
|
||||
public:
|
||||
/**
|
||||
* Instanciates a MAXDS3231M object
|
||||
*
|
||||
* @param bus number of used bus
|
||||
* @param devAddr addres of used i2c device
|
||||
*/
|
||||
MAXDS3231M (int bus, int devAddr);
|
||||
|
||||
/**
|
||||
* MAXDS3231M object destructor, basicaly it close i2c connection.
|
||||
*/
|
||||
~MAXDS3231M ();
|
||||
|
||||
/**
|
||||
* Set date and time on the chip.
|
||||
*
|
||||
* @param time staracture
|
||||
*/
|
||||
void setDate (Time3231 &time);
|
||||
|
||||
/**
|
||||
* Get date and time located on the chip.
|
||||
*
|
||||
* @param time staracture
|
||||
*/
|
||||
bool getDate (Time3231 &time);
|
||||
|
||||
/**
|
||||
* Get on board temperature.
|
||||
*/
|
||||
uint16_t getTemperature ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_i2cAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer);
|
||||
uint8_t DECtoBSD (uint8_t data);
|
||||
uint8_t BCDtoDEC (uint8_t data);
|
||||
};
|
||||
|
||||
}
|
9
src/maxds3231m/pyupm_maxds3231m.i
Normal file
9
src/maxds3231m/pyupm_maxds3231m.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module pyupm_maxds3231m
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "maxds3231m.h"
|
||||
%{
|
||||
#include "maxds3231m.h"
|
||||
%}
|
5
src/mic/CMakeLists.txt
Normal file
5
src/mic/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "mic")
|
||||
set (libdescription "Microphone simple API")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
9
src/mic/jsupm_mic.i
Normal file
9
src/mic/jsupm_mic.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_mic
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint16_t.i"
|
||||
|
||||
%{
|
||||
#include "mic.h"
|
||||
%}
|
||||
|
||||
%include "mic.h"
|
96
src/mic/mic.cxx
Normal file
96
src/mic/mic.cxx
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <functional>
|
||||
#include <string.h>
|
||||
#include "mic.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Microphone::Microphone(int micPin) {
|
||||
// initialise analog mic input
|
||||
m_micCtx = mraa_aio_init(micPin);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Microphone::~Microphone() {
|
||||
// close analog input
|
||||
mraa_result_t error;
|
||||
error = mraa_aio_close(m_micCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Microphone::getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples,
|
||||
uint16_t * buffer) {
|
||||
int sampleIdx = 0;
|
||||
|
||||
// must have freq
|
||||
if (!freqMS) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// too much samples
|
||||
if (numberOfSamples > 0xFFFFFF) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (sampleIdx < numberOfSamples) {
|
||||
buffer[sampleIdx++] = mraa_aio_read (m_micCtx);
|
||||
usleep(freqMS * 1000);
|
||||
}
|
||||
|
||||
return sampleIdx;
|
||||
}
|
||||
|
||||
int
|
||||
Microphone::findThreshold (thresholdContext* ctx, unsigned int threshold,
|
||||
uint16_t * buffer, unsigned int len) {
|
||||
long sum = 0;
|
||||
for (unsigned int i = 0; i < len; i++) {
|
||||
sum += buffer[i];
|
||||
}
|
||||
|
||||
ctx->averageReading = sum / len;
|
||||
ctx->runningAverage = (((ctx->averagedOver-1) * ctx->runningAverage) + ctx->averageReading) / ctx->averagedOver;
|
||||
|
||||
if (ctx->runningAverage > threshold) {
|
||||
return ctx->runningAverage;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Microphone::printGraph (thresholdContext* ctx) {
|
||||
for (int i = 0; i < ctx->runningAverage; i++)
|
||||
std::cout << ".";
|
||||
std::cout << std::endl;
|
||||
}
|
93
src/mic/mic.h
Normal file
93
src/mic/mic.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
|
||||
struct thresholdContext {
|
||||
long averageReading;
|
||||
long runningAverage;
|
||||
int averagedOver;
|
||||
};
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief C++ API for Microphone
|
||||
*
|
||||
* This file defines the Microphone Analog sensor
|
||||
*
|
||||
* @snippet mic-example.cxx Interesting
|
||||
*
|
||||
*/
|
||||
class Microphone {
|
||||
public:
|
||||
/**
|
||||
* Instanciates a Microphone object
|
||||
*
|
||||
* @param micPin pin where microphone is connected
|
||||
*/
|
||||
Microphone(int micPin);
|
||||
|
||||
/**
|
||||
* MAX31723 object destructor
|
||||
*/
|
||||
~Microphone();
|
||||
|
||||
/**
|
||||
* Get samples from microphone according to provided window and
|
||||
* number of samples
|
||||
*
|
||||
* @param freqMS time between each sample (in microseconds)
|
||||
* @param numberOfSamples number of sample to sample for this window
|
||||
* @param buffer bufer with sampled data
|
||||
*/
|
||||
int getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, uint16_t * buffer);
|
||||
|
||||
/**
|
||||
* Given sampled buffer this method will return TRUE/FALSE if threshold
|
||||
* was reached
|
||||
*
|
||||
* @param ctx threshold context
|
||||
* @param threshold sample threshold
|
||||
* @param buffer buffer with samples
|
||||
* @param len bufer len
|
||||
*/
|
||||
int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, unsigned int len);
|
||||
|
||||
/**
|
||||
*
|
||||
* Print running average of threshold context
|
||||
*
|
||||
* @param ctx threshold context
|
||||
*/
|
||||
void printGraph (thresholdContext* ctx);
|
||||
|
||||
private:
|
||||
mraa_aio_context m_micCtx;
|
||||
};
|
||||
|
||||
}
|
12
src/mic/pyupm_mic.i
Normal file
12
src/mic/pyupm_mic.i
Normal file
@ -0,0 +1,12 @@
|
||||
%module pyupm_mic
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint16_t.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "mic.h"
|
||||
%{
|
||||
#include "mic.h"
|
||||
%}
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_mma7455
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "mma7455.h"
|
||||
|
@ -36,95 +36,95 @@ using namespace upm;
|
||||
MMA7455::MMA7455 (int bus, int devAddr) {
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
|
||||
m_name = "MMA7455";
|
||||
|
||||
m_controlAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2ControlCtx = maa_i2c_init(m_bus);
|
||||
m_i2ControlCtx = mraa_i2c_init(m_bus);
|
||||
|
||||
maa_result_t error = maa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MAA_SUCCESS) {
|
||||
mraa_result_t error = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// setting GLVL 0x1 (64LSB/g) and MODE 0x1 (Measurement Mode)
|
||||
data = (BIT (MMA7455_GLVL0) | BIT (MMA7455_MODE0));
|
||||
error = ic2WriteReg (MMA7455_MCTL, &data, 0x1);
|
||||
if (error != MAA_SUCCESS) {
|
||||
if (error != MRAA_SUCCESS) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != calibrate ()) {
|
||||
|
||||
if (MRAA_SUCCESS != calibrate ()) {
|
||||
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MMA7455::~MMA7455() {
|
||||
maa_i2c_stop(m_i2ControlCtx);
|
||||
mraa_i2c_stop(m_i2ControlCtx);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::calibrate () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
int i = 0;
|
||||
|
||||
|
||||
accelData xyz;
|
||||
xyz.value.x = xyz.value.y = xyz.value.z = 0;
|
||||
|
||||
|
||||
do {
|
||||
error = readData (&xyz.value.x, &xyz.value.y, &xyz.value.z);
|
||||
if (MAA_SUCCESS != error) {
|
||||
if (MRAA_SUCCESS != error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
xyz.value.x += 2 * -xyz.value.x;
|
||||
xyz.value.y += 2 * -xyz.value.y;
|
||||
xyz.value.z += 2 * -(xyz.value.z - 64);
|
||||
|
||||
|
||||
error = ic2WriteReg (MMA7455_XOFFL, (unsigned char *) &xyz, 0x6);
|
||||
if (error != MAA_SUCCESS) {
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
} while ( ++i < 3 );
|
||||
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
accelData xyz;
|
||||
unsigned char data = 0;
|
||||
int nBytes = 0;
|
||||
|
||||
|
||||
/*do {
|
||||
nBytes = ic2ReadReg (MMA7455_STATUS, &data, 0x1);
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == MAA_SUCCESS);
|
||||
|
||||
if (nBytes == MAA_SUCCESS) {
|
||||
} while ( !(data & MMA7455_DRDY) && nBytes == MRAA_SUCCESS);
|
||||
|
||||
if (nBytes == MRAA_SUCCESS) {
|
||||
std::cout << "NO_GDB :: 1" << std::endl;
|
||||
return MAA_SUCCESS;
|
||||
return MRAA_SUCCESS;
|
||||
}*/
|
||||
|
||||
|
||||
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
|
||||
if (nBytes == 0) {
|
||||
std::cout << "NO_GDB :: 2" << std::endl;
|
||||
return MAA_ERROR_UNSPECIFIED;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
|
||||
if (xyz.reg.x_msb & 0x02) {
|
||||
xyz.reg.x_msb |= 0xFC;
|
||||
}
|
||||
|
||||
|
||||
if (xyz.reg.y_msb & 0x02) {
|
||||
xyz.reg.y_msb |= 0xFC;
|
||||
}
|
||||
|
||||
|
||||
if (xyz.reg.z_msb & 0x02) {
|
||||
xyz.reg.z_msb |= 0xFC;
|
||||
}
|
||||
@ -133,44 +133,43 @@ MMA7455::readData (short * ptrX, short * ptrY, short * ptrZ) {
|
||||
*ptrX = xyz.value.x;
|
||||
*ptrY = xyz.value.y;
|
||||
*ptrZ = xyz.value.z;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != maa_i2c_write_byte(m_i2ControlCtx, reg)) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (MAA_SUCCESS != maa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) maa_i2c_read(m_i2ControlCtx, buf, size);
|
||||
|
||||
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
|
||||
}
|
||||
|
||||
maa_result_t
|
||||
mraa_result_t
|
||||
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[size + 1];
|
||||
data[0] = reg;
|
||||
memcpy(&data[1], buf, size);
|
||||
|
||||
error = maa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MAA_SUCCESS) {
|
||||
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
error = maa_i2c_write (m_i2ControlCtx, data, size + 1);
|
||||
if (error != MAA_SUCCESS) {
|
||||
error = mraa_i2c_write (m_i2ControlCtx, data, size + 1);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/i2c.h>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define ADDR 0x1D // device address
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
#define MMA7455_YOFFH 0x13 // Read/Write, Offset Drift Y MSB
|
||||
#define MMA7455_ZOFFL 0x14 // Read/Write, Offset Drift Z LSB
|
||||
#define MMA7455_ZOFFH 0x15 // Read/Write, Offset Drift Z MSB
|
||||
#define MMA7455_MCTL 0x16 // Read/Write, Mode Control Register
|
||||
#define MMA7455_MCTL 0x16 // Read/Write, Mode Control Register
|
||||
#define MMA7455_INTRST 0x17 // Read/Write, Interrupt Latch Reset
|
||||
#define MMA7455_CTL1 0x18 // Read/Write, Control 1 Register
|
||||
#define MMA7455_CTL2 0x19 // Read/Write, Control 2 Register
|
||||
@ -64,11 +64,11 @@
|
||||
#define MMA7455_TW 0x1E // Read/Write, Time Window for Second Pulse Value
|
||||
#define MMA7455_RESERVED2 0x1F // Reserved
|
||||
|
||||
// Defines for the bits, to be able to change
|
||||
// Defines for the bits, to be able to change
|
||||
// between bit number and binary definition.
|
||||
// By using the bit number, programming the MMA7455
|
||||
// By using the bit number, programming the MMA7455
|
||||
// is like programming an AVR microcontroller.
|
||||
// But instead of using "(1<<X)", or "_BV(X)",
|
||||
// But instead of using "(1<<X)", or "_BV(X)",
|
||||
// the Arduino "bit(X)" is used.
|
||||
#define MMA7455_D0 0
|
||||
#define MMA7455_D1 1
|
||||
@ -129,7 +129,7 @@
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
|
||||
union accelData {
|
||||
struct {
|
||||
unsigned char x_lsb;
|
||||
@ -139,7 +139,7 @@ union accelData {
|
||||
unsigned char z_lsb;
|
||||
unsigned char z_msb;
|
||||
} reg;
|
||||
|
||||
|
||||
struct {
|
||||
short x;
|
||||
short y;
|
||||
@ -179,12 +179,12 @@ class MMA7455 {
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calibrate the sensor
|
||||
*/
|
||||
maa_result_t calibrate ();
|
||||
|
||||
mraa_result_t calibrate ();
|
||||
|
||||
/**
|
||||
* Read X, Y and Z acceleration data
|
||||
*
|
||||
@ -192,32 +192,32 @@ class MMA7455 {
|
||||
* @param ptrY Y axis
|
||||
* @param ptrZ Z axis
|
||||
*/
|
||||
maa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
|
||||
mraa_result_t readData (short * ptrX, short * ptrY, short * ptrZ);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param reg register address
|
||||
* @param buf register data buffer
|
||||
* @param size buffer size
|
||||
*/
|
||||
int ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param reg register address
|
||||
* @param buf register data buffer
|
||||
* @param buf register data buffer
|
||||
* @param size buffer size
|
||||
*/
|
||||
maa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
mraa_result_t ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_controlAddr;
|
||||
int m_bus;
|
||||
maa_i2c_context m_i2ControlCtx;
|
||||
mraa_i2c_context m_i2ControlCtx;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_mma7455
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
5
src/mpu9150/CMakeLists.txt
Normal file
5
src/mpu9150/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "mpu9150")
|
||||
set (libdescription "giro, acceleromter and magnometer sensor based on mpu9150")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
8
src/mpu9150/jsupm_mpu9150.i
Normal file
8
src/mpu9150/jsupm_mpu9150.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_mpu9150
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "mpu9150.h"
|
||||
%}
|
||||
|
||||
%include "mpu9150.h"
|
226
src/mpu9150/mpu9150.cxx
Normal file
226
src/mpu9150/mpu9150.cxx
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
* 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "mpu9150.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MPU9150::MPU9150 (int bus, int devAddr) {
|
||||
m_name = "MPU9150";
|
||||
|
||||
m_i2cAddr = devAddr;
|
||||
m_bus = bus;
|
||||
|
||||
m_i2Ctx = mraa_i2c_init(m_bus);
|
||||
|
||||
mraa_result_t ret = mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
fprintf(stderr, "Messed up i2c bus\n");
|
||||
}
|
||||
|
||||
initSensor ();
|
||||
}
|
||||
|
||||
MPU9150::~MPU9150() {
|
||||
mraa_i2c_stop(m_i2Ctx);
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::initSensor () {
|
||||
uint8_t regData = 0x0;
|
||||
|
||||
// setClockSource
|
||||
updateRegBits ( MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT,
|
||||
MPU6050_PWR1_CLKSEL_LENGTH, MPU6050_CLOCK_PLL_XGYRO);
|
||||
// setFullScaleGyroRange
|
||||
updateRegBits ( MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT,
|
||||
MPU6050_GCONFIG_FS_SEL_LENGTH, MPU6050_GYRO_FS_250);
|
||||
// setFullScaleAccelRange
|
||||
updateRegBits ( MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT,
|
||||
MPU6050_ACONFIG_AFS_SEL_LENGTH, MPU6050_ACCEL_FS_2);
|
||||
// setSleepEnabled
|
||||
i2cReadReg_N (MPU6050_RA_PWR_MGMT_1, 0x1, ®Data);
|
||||
regData &= ~(1 << MPU6050_PWR1_SLEEP_BIT);
|
||||
i2cWriteReg (MPU6050_RA_PWR_MGMT_1, regData);
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MPU9150::getDeviceID () {
|
||||
uint8_t regData = 0x0;
|
||||
getRegBits (MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, ®Data);
|
||||
return regData;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::getData () {
|
||||
uint8_t buffer[14];
|
||||
|
||||
for (int i = 0; i < SMOOTH_TIMES; i++) {
|
||||
i2cReadReg_N (MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
|
||||
axisAcceleromter.rawData.axisX = (((int16_t)buffer[0]) << 8) | buffer[1];
|
||||
axisAcceleromter.rawData.axisY = (((int16_t)buffer[2]) << 8) | buffer[3];
|
||||
axisAcceleromter.rawData.axisZ = (((int16_t)buffer[4]) << 8) | buffer[5];
|
||||
axisAcceleromter.sumData.axisX += (double) axisAcceleromter.rawData.axisX / 16384;
|
||||
axisAcceleromter.sumData.axisY += (double) axisAcceleromter.rawData.axisY / 16384;
|
||||
axisAcceleromter.sumData.axisZ += (double) axisAcceleromter.rawData.axisZ / 16384;
|
||||
|
||||
axisGyroscope.rawData.axisX = (((int16_t)buffer[8]) << 8) | buffer[9];
|
||||
axisGyroscope.rawData.axisY = (((int16_t)buffer[10]) << 8) | buffer[11];
|
||||
axisGyroscope.rawData.axisZ = (((int16_t)buffer[12]) << 8) | buffer[13];
|
||||
axisGyroscope.sumData.axisX += (double) axisAcceleromter.rawData.axisX * 250 / 32768;
|
||||
axisGyroscope.sumData.axisY += (double) axisAcceleromter.rawData.axisY * 250 / 32768;
|
||||
axisGyroscope.sumData.axisZ += (double) axisAcceleromter.rawData.axisZ * 250 / 32768;
|
||||
|
||||
i2cWriteReg (MPU6050_RA_INT_PIN_CFG, 0x02);
|
||||
usleep (10000);
|
||||
m_i2cAddr = MPU9150_RA_MAG_ADDRESS;
|
||||
i2cWriteReg (0x0A, 0x01);
|
||||
usleep (10000);
|
||||
i2cReadReg_N (MPU9150_RA_MAG_XOUT_L, 6, buffer);
|
||||
m_i2cAddr = ADDR;
|
||||
|
||||
axisMagnetomer.rawData.axisX = (((int16_t)buffer[0]) << 8) | buffer[1];
|
||||
axisMagnetomer.rawData.axisY = (((int16_t)buffer[2]) << 8) | buffer[3];
|
||||
axisMagnetomer.rawData.axisZ = (((int16_t)buffer[4]) << 8) | buffer[5];
|
||||
axisMagnetomer.sumData.axisX += (double) axisMagnetomer.rawData.axisX * 1200 / 4096;
|
||||
axisMagnetomer.sumData.axisY += (double) axisMagnetomer.rawData.axisY * 1200 / 4096;
|
||||
axisMagnetomer.sumData.axisZ += (double) axisMagnetomer.rawData.axisZ * 1200 / 4096;
|
||||
}
|
||||
|
||||
axisAcceleromter.data.axisX = axisAcceleromter.sumData.axisX / SMOOTH_TIMES;
|
||||
axisAcceleromter.data.axisY = axisAcceleromter.sumData.axisY / SMOOTH_TIMES;
|
||||
axisAcceleromter.data.axisZ = axisAcceleromter.sumData.axisZ / SMOOTH_TIMES;
|
||||
|
||||
axisGyroscope.data.axisX = axisGyroscope.sumData.axisX / SMOOTH_TIMES;
|
||||
axisGyroscope.data.axisY = axisGyroscope.sumData.axisY / SMOOTH_TIMES;
|
||||
axisGyroscope.data.axisZ = axisGyroscope.sumData.axisZ / SMOOTH_TIMES;
|
||||
|
||||
axisMagnetomer.data.axisX = axisMagnetomer.sumData.axisX / SMOOTH_TIMES;
|
||||
axisMagnetomer.data.axisY = axisMagnetomer.sumData.axisY / SMOOTH_TIMES;
|
||||
axisMagnetomer.data.axisZ = axisMagnetomer.sumData.axisZ / SMOOTH_TIMES;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::getAcceleromter (Vector3D * data) {
|
||||
data->axisX = axisAcceleromter.data.axisX;
|
||||
data->axisY = axisAcceleromter.data.axisY;
|
||||
data->axisZ = axisAcceleromter.data.axisZ;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::getGyro (Vector3D * data) {
|
||||
data->axisX = axisGyroscope.data.axisX;
|
||||
data->axisY = axisGyroscope.data.axisY;
|
||||
data->axisZ = axisGyroscope.data.axisZ;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::getMagnometer (Vector3D * data) {
|
||||
data->axisX = axisMagnetomer.data.axisX;
|
||||
data->axisY = axisMagnetomer.data.axisY;
|
||||
data->axisZ = axisMagnetomer.data.axisZ;
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
float
|
||||
MPU9150::getTemperature () {
|
||||
uint8_t buffer[2];
|
||||
uint16_t tempRaw = 0;
|
||||
|
||||
updateRegBits (MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, 0x1, 0x0);
|
||||
i2cReadReg_N (MPU6050_RA_TEMP_OUT_H, 2, buffer);
|
||||
tempRaw = (((int16_t)buffer[0]) << 8) | buffer[1];
|
||||
|
||||
return (float)tempRaw / 340.0 + 35.0;
|
||||
}
|
||||
|
||||
/*
|
||||
* **************
|
||||
* private area
|
||||
* **************
|
||||
*/
|
||||
uint16_t
|
||||
MPU9150::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
||||
int readByte = 0;
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
mraa_i2c_write_byte(m_i2Ctx, reg);
|
||||
|
||||
mraa_i2c_address(m_i2Ctx, m_i2cAddr);
|
||||
readByte = mraa_i2c_read(m_i2Ctx, buffer, len);
|
||||
return readByte;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
MPU9150::i2cWriteReg (uint8_t reg, uint8_t value) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
uint8_t data[2] = { reg, value };
|
||||
error = mraa_i2c_address (m_i2Ctx, m_i2cAddr);
|
||||
error = mraa_i2c_write (m_i2Ctx, data, 2);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
MPU9150::updateRegBits (uint8_t reg, uint8_t bitStart, uint8_t length, uint16_t data) {
|
||||
uint8_t regData;
|
||||
|
||||
if (i2cReadReg_N (reg, 0x1, ®Data) != 0) {
|
||||
uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
|
||||
data <<= (bitStart - length + 1); // shift data into correct position
|
||||
data &= mask; // zero all non-important bits in data
|
||||
regData &= ~(mask); // zero all important bits in existing byte
|
||||
regData |= data; // combine data with existing byte
|
||||
return i2cWriteReg (reg, regData);
|
||||
} else {
|
||||
return 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t
|
||||
MPU9150::getRegBits (uint8_t reg, uint8_t bitStart, uint8_t length, uint8_t * data) {
|
||||
uint8_t count = 0;
|
||||
uint8_t regData;
|
||||
if (i2cReadReg_N (reg, 0x1, ®Data) != 0) {
|
||||
uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1);
|
||||
regData &= mask;
|
||||
regData >>= (bitStart - length + 1);
|
||||
*data = regData;
|
||||
}
|
||||
return count;
|
||||
}
|
196
src/mpu9150/mpu9150.h
Normal file
196
src/mpu9150/mpu9150.h
Normal file
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
* 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/i2c.h>
|
||||
|
||||
#define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
|
||||
#define MPU6050_ADDRESS_AD0_HIGH 0x69 // address pin high (VCC)
|
||||
#define ADDR MPU6050_ADDRESS_AD0_LOW // device address
|
||||
|
||||
// registers address
|
||||
#define MPU6050_CLOCK_PLL_XGYRO 0x01
|
||||
#define MPU6050_GYRO_FS_250 0x00
|
||||
#define MPU6050_ACCEL_FS_2 0x00
|
||||
#define MPU6050_RA_INT_PIN_CFG 0x37
|
||||
|
||||
#define MPU6050_RA_ACCEL_XOUT_H 0x3B
|
||||
#define MPU6050_RA_ACCEL_XOUT_L 0x3C
|
||||
#define MPU6050_RA_ACCEL_YOUT_H 0x3D
|
||||
#define MPU6050_RA_ACCEL_YOUT_L 0x3E
|
||||
#define MPU6050_RA_ACCEL_ZOUT_H 0x3F
|
||||
#define MPU6050_RA_ACCEL_ZOUT_L 0x40
|
||||
#define MPU6050_RA_TEMP_OUT_H 0x41
|
||||
#define MPU6050_RA_TEMP_OUT_L 0x42
|
||||
#define MPU6050_RA_GYRO_XOUT_H 0x43
|
||||
#define MPU6050_RA_GYRO_XOUT_L 0x44
|
||||
#define MPU6050_RA_GYRO_YOUT_H 0x45
|
||||
#define MPU6050_RA_GYRO_YOUT_L 0x46
|
||||
#define MPU6050_RA_GYRO_ZOUT_H 0x47
|
||||
#define MPU6050_RA_GYRO_ZOUT_L 0x48
|
||||
|
||||
#define MPU6050_RA_CONFIG 0x1A
|
||||
#define MPU6050_CFG_DLPF_CFG_BIT 2
|
||||
#define MPU6050_CFG_DLPF_CFG_LENGTH 3
|
||||
|
||||
#define MPU6050_RA_GYRO_CONFIG 0x1B
|
||||
#define MPU6050_GCONFIG_FS_SEL_BIT 4
|
||||
#define MPU6050_GCONFIG_FS_SEL_LENGTH 2
|
||||
|
||||
#define MPU6050_RA_ACCEL_CONFIG 0x1C
|
||||
#define MPU6050_ACONFIG_AFS_SEL_BIT 4
|
||||
#define MPU6050_ACONFIG_AFS_SEL_LENGTH 2
|
||||
|
||||
// magnotometer
|
||||
#define MPU9150_RA_MAG_ADDRESS 0x0C
|
||||
#define MPU9150_RA_MAG_XOUT_L 0x03
|
||||
|
||||
#define MPU6050_RA_PWR_MGMT_1 0x6B
|
||||
#define MPU6050_PWR1_CLKSEL_BIT 2
|
||||
#define MPU6050_PWR1_CLKSEL_LENGTH 3
|
||||
#define MPU6050_PWR1_SLEEP_BIT 6
|
||||
|
||||
#define MPU6050_RA_INT_PIN_CFG 0x37
|
||||
|
||||
// temperature
|
||||
#define MPU6050_PWR1_TEMP_DIS_BIT 3
|
||||
#define MPU6050_RA_WHO_AM_I 0x75
|
||||
#define MPU6050_WHO_AM_I_BIT 6
|
||||
#define MPU6050_WHO_AM_I_LENGTH 6
|
||||
|
||||
#define SMOOTH_TIMES 10.0
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
namespace upm {
|
||||
|
||||
struct Vector3DRaw {
|
||||
uint16_t axisX;
|
||||
uint16_t axisY;
|
||||
uint16_t axisZ;
|
||||
};
|
||||
|
||||
struct Vector3D {
|
||||
double axisX;
|
||||
double axisY;
|
||||
double axisZ;
|
||||
};
|
||||
|
||||
struct AxisData {
|
||||
Vector3DRaw rawData;
|
||||
Vector3D sumData;
|
||||
Vector3D data;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for MPU9150 chip (Accelrometer, Gyro and Magnometer Sensor)
|
||||
*
|
||||
* This file defines the MPU9150 C++ interface for libmpu9150
|
||||
*
|
||||
* @snippet mpu9150-example.cxx Interesting
|
||||
*/
|
||||
class MPU9150 {
|
||||
public:
|
||||
/**
|
||||
* Instanciates a MPU9150 object
|
||||
*
|
||||
* @param bus number of used bus
|
||||
* @param devAddr addres of used i2c device
|
||||
*/
|
||||
MPU9150 (int bus, int devAddr);
|
||||
|
||||
/**
|
||||
* MPU9150 object destructor, basicaly it close i2c connection.
|
||||
*/
|
||||
~MPU9150 ();
|
||||
|
||||
/**
|
||||
* Initiate MPU9150 chips
|
||||
*/
|
||||
mraa_result_t initSensor ();
|
||||
|
||||
/**
|
||||
* Get identity of the device
|
||||
*/
|
||||
uint8_t getDeviceID ();
|
||||
|
||||
/**
|
||||
* Get the Accelerometer, Gyro and Compass data from the chip and
|
||||
* save it in private section.
|
||||
*/
|
||||
mraa_result_t getData ();
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
mraa_result_t getAcceleromter (Vector3D * data);
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
mraa_result_t getGyro (Vector3D * data);
|
||||
|
||||
/**
|
||||
* @param data structure with 3 axis (x,y,z)
|
||||
*/
|
||||
mraa_result_t getMagnometer (Vector3D * data);
|
||||
|
||||
/**
|
||||
* Read on die temperature from the chip
|
||||
*/
|
||||
float getTemperature ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
int m_i2cAddr;
|
||||
int m_bus;
|
||||
mraa_i2c_context m_i2Ctx;
|
||||
|
||||
AxisData axisMagnetomer;
|
||||
AxisData axisAcceleromter;
|
||||
AxisData axisGyroscope;
|
||||
|
||||
uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer);
|
||||
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
|
||||
int updateRegBits (uint8_t reg, uint8_t bitStart,
|
||||
uint8_t length, uint16_t data);
|
||||
uint8_t getRegBits (uint8_t reg, uint8_t bitStart,
|
||||
uint8_t length, uint8_t * data);
|
||||
};
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user