Compare commits

..

74 Commits

Author SHA1 Message Date
0954617a4b upm: version bump to v0.1.5
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-25 10:07:42 +01:00
36be22cb90 mraa: change all existing code to use libmraa.
* Made CMake depend on 0.4 libmraa

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-25 10:05:27 +01:00
8d25ecacdd mpu9150: added new sensor (acceleromter, gyro and compass)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-24 18:17:46 +00:00
739d4e23e8 upm: depend on libmaa 0.3.1
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-20 18:28:50 +01:00
81c8baa071 microphone: added new sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-20 15:25:43 +00:00
2fa9b7b6c9 hcsr04: fix compilation issue with maa_gpio_isr args
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-20 15:22:55 +00:00
b1e548ae8a buzzer: fix for PWM frequencies
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-20 11:04:25 +00:00
d00500ba12 pulsensor: Added new sensor (not stable and not documented yet)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-18 09:37:50 +00:00
2c0e83e406 stepmotor: changed name from step_motor to stepmotor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-18 08:51:31 +00:00
b03cbf4f36 step_motor: Added new module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-17 14:58:59 +00:00
b291f372d7 CMakeLists.txt: up version to 0.1.4
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:44:04 +01:00
8d8485be82 CMakeLists.txt: depend on maa 0.2.9+
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:41:11 +01:00
b4f25c84a5 CMakeLists.txt: add soversion to libs in UPM
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:41:05 +01:00
4c7fa11bb2 gfx.h: fix global maa.h header location
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-17 11:34:02 +01:00
c18a9433fc gy65: Added new digital pressure sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-16 16:43:05 +00:00
8fe679494c st7735: Added text feature and documentation with license
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-16 12:32:59 +00:00
2c1baf66b5 max31855: add sensor and documentation on creation of a UPM sensor
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-13 16:45:55 +01:00
3e12ed6719 st7735: added new spi lcd module (missing bitmap and text)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-13 13:50:55 +00:00
e24df89ebd docs: Added intial documentation for UPM and start of a porting walkthrough
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-13 11:53:51 +01:00
186dd03b79 servo: removed defines from es08a and made engine move smoothly
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-12 15:26:01 +00:00
0050f92b06 lcd: rename from iiclcd to i2clcd, add swig
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 14:16:39 +01:00
058c40e340 servo: update to use cmake macro for servo
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 11:44:17 +01:00
cea5816c43 upm: new standard for modules cmake file
* Update all previously updated modules

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-12 11:39:10 +01:00
54a4afc6a7 my9221 mma7455: corrected spelling mistake
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 20:50:19 +01:00
1dd8626044 mma7455: added new accelerometer module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-11 13:21:58 +00:00
1c138d9167 ledbar: rename to my9221
* Use new cmake macro

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:11:36 +01:00
3dccffe055 4digitdisplay: rename to tm1637
* Use new cmake macro

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:07:21 +01:00
34e343869c upm: update past modules to use new CMake macro
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 15:02:44 +01:00
d71e4e5dc2 cmake: update swig support
* Bumped required CMake Version

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 14:36:56 +01:00
7e3358b586 doc: make docs not generate by default. BUILDDOC
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-11 14:36:56 +01:00
ca0b0cce44 doxygen: added documentation to new public methods
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 13:39:02 +00:00
12b2ab6991 max44000: Added swig to the module and set i2c methods as public
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 13:34:27 +00:00
3be0cdf5c2 upm: rename generated ipk package
* Version bump to 0.1.2

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-10 11:48:34 +01:00
d1f7df0552 doxygen: Added documentation to led bar (my9221)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 08:08:41 +00:00
0340d736de doxygen: fix to documentaion of buzzer sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 07:27:04 +00:00
a2ca2c1497 doxygen: Added documentation to ultrasonic sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 07:24:56 +00:00
236cc9acc1 doxygen: Added documentation to Buzzer sensor
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-10 06:54:45 +00:00
864306acf5 cmake: added logic for building a tagged commit
* If the HEAD is 0 away from a tag, i.e. if it has just been tagged,
  removes commit number from version

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 19:23:27 +01:00
814cc4a0e8 doxygen: Added documentation for servo base and es08a
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-09 16:00:07 +00:00
1ff0e5ee57 upm: add protection around function for packaging
* Would not build if not building IPK.

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 18:00:29 +01:00
38efe2d7a3 max44000: Added new sensor module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-09 15:37:33 +00:00
fa1753f4ef ipk: add cpack ipk generation
* added similar cmake modules used in libmaa

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-09 17:10:44 +01:00
b73841b28b Doxyfile.in: make doc generation work
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-09 14:45:28 +01:00
9c34b829ef 4digitdisplay.cxx: add Interesting tag and remove pointless array
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-09 14:45:03 +01:00
451d0390b6 doxygen: Added documentation to nrf24l01 module
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 15:40:24 +00:00
7d898e3274 doxygen: added documentation to tm1637 seven segment display
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 13:56:12 +00:00
b4ae08935d Merge branch 'ykiveish-master' 2014-06-06 15:14:53 +01:00
3ee752b297 Merge branch 'master' of github.com:ykiveish/upm into ykiveish-master
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>

Conflicts:
	examples/CMakeLists.txt
	src/CMakeLists.txt
	src/hcsr04/CMakeLists.txt
	src/servo/CMakeLists.txt
2014-06-06 15:14:34 +01:00
557f63edf6 ssd1327: Added new lcd module.
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:41 +00:00
3ce441f0a8 lcd: changed the OOO generalisation.
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:40 +00:00
039b138194 ssd1308: Added new oled display
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:40 +00:00
23d847e380 hcsr04: Added new sonar module (not working properly yet)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:39 +00:00
356b1dd43c servo: Added new module servo
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-06 12:36:39 +00:00
794eb19bd7 COPYING: add MIT license
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-05 16:28:22 +01:00
fdb943c2eb upm: add install options to all current libraries
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-05 15:50:01 +01:00
4896881ea4 cmake: add recursive search for folders
* No need for many add_subdirectory

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
2014-06-05 13:58:34 +01:00
af09aeadc3 Merge branch 'ykiveish-master' 2014-06-05 13:45:47 +01:00
28b68b71c8 hcsr04: Added new sonar module (not working properly yet)
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-04 14:57:19 +00:00
aac51c4850 servo: Added new module servo
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 10:52:58 -07:00
f1cf463126 Merge branch 'ykiveish-master' 2014-06-03 12:00:56 +01:00
5b8922f7bf styling: convert TAB to four SPACES
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 09:38:34 +00:00
0db7af89f9 general: added stdlib definition to fix broken compilation on maa v0.2.7
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
2014-06-03 09:35:47 +00:00
fdcd36e1ae styling: remove trailing whitespace from all modules
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-06-02 11:49:57 +01:00
83c29cc330 Merge branch 'ykiveish-master' 2014-06-02 11:47:56 +01:00
e63076ecf4 nrf24l01 :: Added NRF module with examples.
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-06-02 02:33:21 -07:00
93aa79fe4b 4digitdisplay: added new 4digitdisplay module
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:13:47 -07:00
dd55123062 ledbar: added ledbar module
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:11:12 -07:00
c60b342e0f lcd: added grove-lcd rgb and deleted the old lcm1602 folder
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-30 06:04:49 -07:00
e785b0f03b cmake: make required maa version 0.2.6+
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-28 14:22:37 +01:00
81278510c0 Merge branch 'ykiveish-master'
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-28 14:21:01 +01:00
725fc4661c buzzer: added buzzer with example
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
2014-05-28 05:57:28 -07:00
b26cbd09f1 hmc5883l.h: change char to uint8_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-27 11:11:45 +01:00
1d74ead4cc Lcm1602: clean up API and use maa_result_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-23 14:21:10 +01:00
77d103f396 cmake: update to maa 0.2.6
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
2014-05-23 14:20:07 +01:00
141 changed files with 9517 additions and 337 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8)
cmake_minimum_required (VERSION 2.8.11)
project (upm)
find_package (SWIG)
@ -8,22 +8,86 @@ 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.5)
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})
# Make a version file containing the current version from git.
include (GetGitRevisionDescription)
git_describe (VERSION "--tags")
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
message (WARNING " - Install git to compile a production libmraa!")
set (VERSION "v0.1.5-dirty")
endif ()
message (INFO " - UPM Version ${VERSION}")
#parse the version information into pieces.
string (REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${VERSION}")
string (REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+\\-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
if ("${VERSION_COMMIT}" MATCHES "^v.*")
set (VERSION_COMMIT "")
endif()
set (upm_VERSION_MAJOR ${VERSION_MAJOR})
set (upm_VERSION_MINOR ${VERSION_MINOR})
set (upm_VERSION_PATCH ${VERSION_PATCH})
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
set (CMAKE_SWIG_FLAGS "")
# add a target to generate API documentation with Doxygen
find_package (Doxygen)
if (DOXYGEN_FOUND)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif (DOXYGEN_FOUND)
option (IPK "Generate IPK using CPack" OFF)
option (BUILDDOC "Build all doc." OFF)
option (BUILDSWIG "Build swig modules." ON)
option (BUILDSWIGPYTHON "Build swig python modules." ON)
option (BUILDSWIGNODE "Build swig node modules." ON)
if (BUILDDOC)
# add a target to generate API documentation with Doxygen
find_package (Doxygen)
if (DOXYGEN_FOUND)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target (doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif (DOXYGEN_FOUND)
endif()
if (IPK)
include (TargetArch)
target_architecture (DETECTED_ARCH)
message( INFO " - Target arch is ${DETECTED_ARCH}")
set(CPACK_GENERATOR "DEB")
set(OPKG_ARCH ${DETECTED_ARCH})
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
set(upm_PACKAGE_ON_TAG ".")
if ("${VERSION_COMMIT}" STREQUAL "")
set(upm_PACKAGE_ON_TAG "")
endif()
set(CPACK_PACKAGE_VERSION
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
set(CPACK_PACKAGE_NAME "upm")
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
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})
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
include (CPack)
endif()
add_subdirectory (src)
add_subdirectory (examples)

20
COPYING Normal file
View File

@ -0,0 +1,20 @@
Copyright © 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.

View File

@ -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
@ -753,9 +753,8 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/hmc5883l/hmc5883l.h \
@CMAKE_CURRENT_SOURCE_DIR@/src/grove/grove.h \
@CMAKE_CURRENT_SOURCE_DIR@/src/lcm1602/lcm1602.h \
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src \
@CMAKE_CURRENT_SOURCE_DIR@/docs \
@CMAKE_CURRENT_SOURCE_DIR@/README.md
# This tag can be used to specify the character encoding of the source files
@ -823,7 +822,7 @@ FILE_PATTERNS = *.c \
# be searched for input files as well.
# The default value is: NO.
RECURSIVE = NO
RECURSIVE = YES
# The EXCLUDE tag can be used to specify files and/or directories that should be
# excluded from the INPUT source files. This way you can easily exclude a
@ -832,7 +831,7 @@ RECURSIVE = NO
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE =
EXCLUDE = @PROJECT_SOURCE_DIR@/src/doxy2swig.py
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
@ -865,14 +864,16 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).
EXAMPLE_PATH =
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples/ \
@CMAKE_CURRENT_SOURCE_DIR@/docs/ \
@CMAKE_CURRENT_SOURCE_DIR@/src/max31855/
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
# *.h) to filter out the source-files in the directories. If left blank all
# files are included.
EXAMPLE_PATTERNS = *
EXAMPLE_PATTERNS = *.cxx
# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
# searched for input files to be used with the \include or \dontinclude commands

View File

@ -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.
@ -12,15 +12,20 @@ to provide identification/pin location on the board.
Typically an update() function will be called in order to get new data from the
sensor in order to reduce load when doing multiple reads to sensor data.
A basic sensor is expected to work as such:
s = new sensor();
print(sensor->read());
sleep(1);
s->update();
print(sensor->read();
### Example
A sensor/acturo is expected to work as such (here is the servo ES08A api):
@snippet es08a.cxx Interesting
However implementation and API design is compeltely up to the developer, some
enumerable sensors for example may provide much clever instanciation. Displays
may also create more complex structures in order to interface with them.
For more information on maa, see the maa documentation
### Building UPM
See @ref building
### Making your own UPM module
@ref porting has more information on making new UPM modules

View File

@ -0,0 +1,222 @@
# - The builtin (binary) CPack Deb generator (Unix only)
# CPackDeb may be used to create Deb package using CPack.
# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
# used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration
#
# However CPackRPM has specific features which are controlled by
# the specifics CPACK_RPM_XXX variables.You'll find a detailed usage on
# the wiki:
# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
# However as a handy reminder here comes the list of specific variables:
#
# CPACK_DEBIAN_PACKAGE_NAME
# Mandatory : YES
# Default : CPACK_PACKAGE_NAME (lower case)
# The debian package summary
# CPACK_DEBIAN_PACKAGE_VERSION
# Mandatory : YES
# Default : CPACK_PACKAGE_VERSION
# The debian package version
# CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# Mandatory : YES
# Default : Output of dpkg --print-architecture or i386
# The debian package architecture
# CPACK_DEBIAN_PACKAGE_DEPENDS
# Mandatory : NO
# Default : -
# May be used to set deb dependencies.
# CPACK_DEBIAN_PACKAGE_MAINTAINER
# Mandatory : YES
# Default : CPACK_PACKAGE_CONTACT
# The debian package maintainer
# CPACK_DEBIAN_PACKAGE_DESCRIPTION
# Mandatory : YES
# Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
# The debian package description
# CPACK_DEBIAN_PACKAGE_SECTION
# Mandatory : YES
# Default : 'devel'
# The debian package section
# CPACK_DEBIAN_PACKAGE_PRIORITY
# Mandatory : YES
# Default : 'optional'
# The debian package priority
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
# Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
# CPack script for creating Debian package
# Author: Mathieu Malaterre
#
# http://wiki.debian.org/HowToPackageForDebian
IF(CMAKE_BINARY_DIR)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.")
ENDIF(CMAKE_BINARY_DIR)
IF(NOT UNIX)
MESSAGE(FATAL_ERROR "CPackDeb.cmake may only be used under UNIX.")
ENDIF(NOT UNIX)
# Let's define the control file found in debian package:
# Binary package:
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
# DEBIAN/control
# debian policy enforce lower case for package name
# Package: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)
# Version: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
IF(NOT CPACK_PACKAGE_VERSION)
MESSAGE(FATAL_ERROR "Debian package requires a package version")
ENDIF(NOT CPACK_PACKAGE_VERSION)
SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_VERSION)
# Architecture: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# There is no such thing as i686 architecture on debian, you should use i386 instead
# $ dpkg --print-architecture
FIND_PROGRAM(DPKG_CMD dpkg)
IF(NOT DPKG_CMD)
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
ENDIF(NOT DPKG_CMD)
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# have a look at GET_PROPERTY(result GLOBAL PROPERTY ENABLED_FEATURES),
# this returns the successful FIND_PACKAGE() calls, maybe this can help
# Depends:
# You should set: DEBIAN_PACKAGE_DEPENDS
# TODO: automate 'objdump -p | grep NEEDED'
IF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
MESSAGE(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DEPENDS)
# Maintainer: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
IF(NOT CPACK_PACKAGE_CONTACT)
MESSAGE(FATAL_ERROR "Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER")
ENDIF(NOT CPACK_PACKAGE_CONTACT)
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER)
# Description: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
IF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
MESSAGE(FATAL_ERROR "Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION")
ENDIF(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY)
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY})
ENDIF(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION)
# Section: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
# Priority: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
# Recommends:
# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
# Suggests:
# You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
# Typical examples are:
# - conffiles
# - postinst
# - postrm
# - prerm"
# Usage:
# SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
# For debian source packages:
# debian/control
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles
# .dsc
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles
# Builds-Depends:
#IF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
# "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
# )
#ENDIF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# Description: (mandatory)
#if(NOT CPACK_SECTION)
# message(FATAL_ERROR "opkg package requires a package section")
#endif(NOT CPACK_SECTION)
# Package for opkg
FIND_PROGRAM(OPKG_CMD opkg-build)
if( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
message("CPack: opkg-build not found. Skipping packaging")
else( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )
SET(CPACK_OPKG_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
FILE(MAKE_DIRECTORY ${CPACK_OPKG_ROOTDIR}/CONTROL)
set(CPACK_OPKG_CONTROL_FILE "${CPACK_OPKG_ROOTDIR}/CONTROL/control")
# Write controlfile
FILE(WRITE ${CPACK_OPKG_CONTROL_FILE}
"Package: ${CPACK_PACKAGE_NAME}
Version: ${CPACK_PACKAGE_VERSION}
Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
Architecture: ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}
Section: ${CPACK_DEBIAN_PACKAGE_SECTION}
Priority: optional
Maintainer: ${CPACK_DEBIAN_PACKAGE_MAINTAINER}
Depends: ${CPACK_DEBIAN_PACKAGE_DEPENDS}
Provides: ${CPACK_DEBIAN_PACKAGE_PROVIDES}
Replaces: ${CPACK_DEBIAN_PACKAGE_REPLACES}
Conflicts: ${CPACK_DEBIAN_PACKAGE_CONFLICTS}
Source: https://github.com/intel-iot-devkit/upm
#Essential: no
")
set(OPKG_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
execute_process(
COMMAND "${OPKG_CMD}" "-o" "0" "${CPACK_PACKAGE_FILE_NAME}" "."
RESULT_VARIABLE _result
OUTPUT_VARIABLE _res_output
ERROR_VARIABLE _res_error
WORKING_DIRECTORY ${CPACK_TOPLEVEL_DIRECTORY}
)
if(${_result})
message("Result '${_result}'")
message("Output '${_res_output}'")
message("Error '${_res_error}'")
else(${_result})
message("CPack: Package ${OPKG_FILE_NAME}.ipk generated.")
set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}")
file(RENAME ${CPACK_TOPLEVEL_DIRECTORY}/${OPKG_FILE_NAME}.ipk ${CPACK_BINARY_DIR}/${OPKG_FILE_NAME}.ipk)
endif(${_result})
endif( ${OPKG_CMD} STREQUAL "OPKG_CMD-NOTFOUND" )

View File

@ -0,0 +1,130 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,38 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

View File

@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,136 @@
# Based on the Qt 5 processor detection code, so should be very accurate
# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h
# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64)
# Regarding POWER/PowerPC, just as is noted in the Qt source,
# "There are many more known variants/revisions that we do not handle/detect."
set(archdetect_c_code "
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
#if defined(__ARM_ARCH_7__) \\
|| defined(__ARM_ARCH_7A__) \\
|| defined(__ARM_ARCH_7R__) \\
|| defined(__ARM_ARCH_7M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7)
#error cmake_ARCH armv7
#elif defined(__ARM_ARCH_6__) \\
|| defined(__ARM_ARCH_6J__) \\
|| defined(__ARM_ARCH_6T2__) \\
|| defined(__ARM_ARCH_6Z__) \\
|| defined(__ARM_ARCH_6K__) \\
|| defined(__ARM_ARCH_6ZK__) \\
|| defined(__ARM_ARCH_6M__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6)
#error cmake_ARCH armv6
#elif defined(__ARM_ARCH_5TEJ__) \\
|| (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5)
#error cmake_ARCH armv5
#else
#error cmake_ARCH arm
#endif
#elif defined(__i586) || defined(__i586__)
#error cmake_ARCH i586
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error cmake_ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error cmake_ARCH x86_64
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#error cmake_ARCH ia64
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\
|| defined(_M_MPPC) || defined(_M_PPC)
#if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#error cmake_ARCH ppc64
#else
#error cmake_ARCH ppc
#endif
#endif
#error cmake_ARCH unknown
")
# Set ppc_support to TRUE before including this file or ppc and ppc64
# will be treated as invalid architectures since they are no longer supported by Apple
function(target_architecture output_var)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
# On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set
# First let's normalize the order of the values
# Note that it's not possible to compile PowerPC applications if you are using
# the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we
# disable it by default
# See this page for more information:
# http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4
# Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime.
# On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise.
foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES})
if("${osx_arch}" STREQUAL "ppc" AND ppc_support)
set(osx_arch_ppc TRUE)
elseif("${osx_arch}" STREQUAL "i386")
set(osx_arch_i386 TRUE)
elseif("${osx_arch}" STREQUAL "x86_64")
set(osx_arch_x86_64 TRUE)
elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support)
set(osx_arch_ppc64 TRUE)
else()
message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}")
endif()
endforeach()
# Now add all the architectures in our normalized order
if(osx_arch_ppc)
list(APPEND ARCH ppc)
endif()
if(osx_arch_i386)
list(APPEND ARCH i386)
endif()
if(osx_arch_x86_64)
list(APPEND ARCH x86_64)
endif()
if(osx_arch_ppc64)
list(APPEND ARCH ppc64)
endif()
else()
file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}")
enable_language(C)
# Detect the architecture in a rather creative way...
# This compiles a small C program which is a series of ifdefs that selects a
# particular #error preprocessor directive whose message string contains the
# target architecture. The program will always fail to compile (both because
# file is not a valid C program, and obviously because of the presence of the
# #error preprocessor directives... but by exploiting the preprocessor in this
# way, we can detect the correct target architecture even when cross-compiling,
# since the program itself never needs to be run (only the compiler/preprocessor)
try_run(
run_result_unused
compile_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/arch.c"
COMPILE_OUTPUT_VARIABLE ARCH
CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)
# Parse the architecture name from the compiler output
string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")
# Get rid of the value marker leaving just the architecture name
string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}")
# If we are compiling with an unknown architecture this variable should
# already be set to "unknown" but in the case that it's empty (i.e. due
# to a typo in the code), then set it to unknown
if (NOT ARCH)
set(ARCH unknown)
endif()
endif()
set(${output_var} "${ARCH}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,4 @@
#include "version.h"
const char* gVERSION = "@VERSION@";
const char* gVERSION_SHORT = "@VERSION_SHORT@";

31
docs/building.md Normal file
View File

@ -0,0 +1,31 @@
Building UPM {#building}
============
UPM uses cmake in order to make compilation relatively painless. Cmake runs
build out of tree so the recommended way is to clone from git and make a build/
directory.
UPM will attempt to build all directories inside src/ and they must contain
individual CMakeLists.txt files.
~~~~~~~~~~~~~{.sh}
mkdir build
cd build
cmake ..
make
~~~~~~~~~~~~~
Our cmake configure has a number of options, `cmake -i` will ask you all sorts
of interesting questions, you can disable swig modules, build documentation
etc...
Few recommended options:
Changing install path from /usr/local to /usr
-DCMAKE_INSTALL_PREFIX:PATH=/usr
Building debug build:
-DCMAKE_BUILD_TYPE=DEBUG
Using clang instead of gcc:
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang

16
docs/contributions.md Normal file
View File

@ -0,0 +1,16 @@
Contributing a module {#contributions}
=====================
Here are the rules of contribution:
- Try not to break master. In any commit.
- 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
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 mraa. If you tested on a specific board/platform please
tell us what this was in your PR.

96
docs/max31855.md Normal file
View File

@ -0,0 +1,96 @@
Making a UPM module for MAX31855 {#max31855}
================================
The Maxim Integrated MAX31855 is a thermocouple amplifier allowing you to read
from a K type themocouple. My board comes from the Pmod kit form Maxim
(MAX31855PMB1) but you can get this from many different sources. The adafruit
people made arduino code already so we'll use that as a
[reference](https://github.com/adafruit/Adafruit-MAX31855-library/blob/master/Adafruit_MAX31855.cpp).
### Basics
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
* max31855.h
* jsupm_max31855.i
* pyupm_max31855.i
* CMakeLists.txt
And then an example file to use & test our lib with in upm/examples/max31855.cxx.
### Swig
The .i files are used by swig, there is one for each python & javascript. They
contain essentially the same thing and are very simple. The only thing to
change between the javascript & node.js one is the argument to %module.
@snippet jsupm_max31855.i Interesting
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.
### API
Then we create the header (max31855.h) , a very simple header in our case we
will have only a very basic api. We provide a getTemp() function which will
return the same type as in the arduino library, a double.
@snippet max31855.h Interesting
Note that the header contains both the io that we will use, the gpio is in this
case used as the chip select pin.
### Implementing our API
In the adafruit library the read function (our chip is a 3pin SPI so only read
is possible), the spiread32() does all the work. It starts by setting up the io
so we will do the same in our constructor.
Note unlike on Arduino, we'll just set a 2Mhz clock and let the chip do the
work.
@snippet src/max31855/max31855.cxx Constructor
Then we also need to implement a nice cleanup in our destructor.
@snippet src/max31855/max31855.cxx Destructor
Then to read data, we will use spi_write_buf which will allow us to write a
whole uint32_t in order to get one back, which is what the arduino code does in
spiread32. Obviously we set our chip select to low first. Here is the start of
the implementation of MAX31855::getTemp()
@snippet src/max31855/max31855.cxx spi
Then using the arduino code as reference we simply reconstruct form the 4
uint8_t values a 32bit int value and select only the valuable parts of
information from that. The MAX31855 datahseet explains exactly which bits are
useful, we will just do the same as the adafruit code, first checking the error
bit and then scrapping everything but the 14bit of thermocouple data that are
useful to us and converting it to a double.
@snippet src/max31855/max31855.cxx conversion
### Finalizing
Our final example, very easy to use api!
@snippet examples/max31855.cxx Interesting
### Building
The we need to add it to the examples/CMakeLists.txt. Only three lines are required
~~~~~~~~~~~
add_executable (max31855-example max31855.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/max31855)
target_link_libraries (max31855-example max31855 ${CMAKE_THREAD_LIBS_INIT})
~~~~~~~~~~~
Note you dont have to rebuild everything, cmake keeps target lists so if you
named your example target <modulename>-example you can simply do make
max31855-example and both the library & example will build.

24
docs/naming.md Normal file
View File

@ -0,0 +1,24 @@
Naming a module {#naming}
===============
UPM attemps to follow a clear naming pattern. Modules should be sensibly named
and then placed in /usr/lib/upm and headers in /usr/include/upm.
### Choosing a name
1. Pick a name
2. Use it
### Rules for name picking
1. Your lib must belong to namespace UPM
2. Usually picking the name of the chip of your sensor/actuator might make
sense. Other times this does not. Try to pick a generic name so people with a
similar sensor can inherit your class if they only have minor changes.
3. Avoid brand names
### Doubt
If ever, give me a ping via email: brendan.le.foll@intel.com and I'll try
suggest decent names for your module.

65
docs/porting.md Normal file
View File

@ -0,0 +1,65 @@
Porting a module from Arduino {#porting}
=============================
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
### Adding a new module to UPM
1. Choose a name for your module (see @ref naming)
2. Make a new folder in src/<modulename>
3. Create a CMakeLists.txt file inside src/<modulename>
### CmakeLists.txt
By default you need a header called <modulename>.h and a C++ file called
<modulename>.cxx. You can have multiple headers and source files. Only public
headers need to be added to module_h and all source files need to be in
module_src.
~~~~~~~~~~~
set (libname "modulename")
set (libdescription "Module Description")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()
~~~~~~~~~~~
### Making your API
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 mraa_*_context structs that are
required to talk to the board's IO. An I2c sensor will create a
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 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 mraa API documentation for exact API.
### Building
To build your module just follow @ref building. By creating a folder and the
CMakelists.txt file you have done all that is required to add your sensor to
the UPM build system.
### Sending your module to us for inclusion in UPM
The last step is when you're happy with your module and it works send us a pull
request! We'd love to include your sensor in our repository.
If you don't like github you can also send brendan.le.foll@intel.com a git
formatted patch if your sensor. More details are on @ref contributing and on
https://help.github.com/articles/creating-a-pull-request

View File

@ -0,0 +1,42 @@
/*
* 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 "tm1637.h"
int
main(int argc, char **argv)
{
//! [Interesting]
upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
display->write ("1337");
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete display;
return 0;
}

View File

@ -2,12 +2,65 @@ add_executable (compass compass.cxx)
add_executable (groveled groveled.cxx)
add_executable (grovetemp grovetemp.cxx)
add_executable (lcm-lcd lcm-lcd.cxx)
add_executable (rgb-lcd rgb-lcd.cxx)
add_executable (buzzer-sound buzzer-sound.cxx)
add_executable (led-bar led-bar.cxx)
add_executable (seg-lcd 4digitdisplay.cxx)
add_executable (nrf_transmitter nrf_transmitter.cxx)
add_executable (nrf_receiver nrf_receiver.cxx)
add_executable (es08a es08a.cxx)
add_executable (son-hcsr04 hcsr04.cxx)
add_executable (oled-1308 oled-1308.cxx)
add_executable (oled-1327 oled-1327.cxx)
add_executable (proximity max44000.cxx)
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)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
include_directories (${PROJECT_SOURCE_DIR}/src/lcm1602)
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
include_directories (${PROJECT_SOURCE_DIR}/src/my9221)
include_directories (${PROJECT_SOURCE_DIR}/src/tm1637)
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
include_directories (${PROJECT_SOURCE_DIR}/src/servo)
include_directories (${PROJECT_SOURCE_DIR}/src/hcsr04)
include_directories (${PROJECT_SOURCE_DIR}/src/max44000)
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)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcm-lcd lcm1602 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (led-bar my9221 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (seg-lcd tm1637 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (es08a servo ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (son-hcsr04 hcsr04 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (oled-1308 i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (oled-1327 i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (proximity max44000 ${CMAKE_THREAD_LIBS_INIT})
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})

54
examples/buzzer-sound.cxx Normal file
View File

@ -0,0 +1,54 @@
/*
* 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 <signal.h>
#include "buzzer.h"
int
main(int argc, char **argv) {
int chord[] = { DO, RE, MI, FA, SOL, LA, SI, DO, SI };
//! [Interesting]
// create Buzzer instance
upm::Buzzer* sound = new upm::Buzzer(5);
// print sensor name
std::cout << sound->name() << std::endl;
// play sound (DO, RE, ME, etc...)
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]
std::cout << "exiting application" << std::endl;
delete sound;
return 0;
}

49
examples/es08a.cxx Normal file
View File

@ -0,0 +1,49 @@
/*
* 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 "es08a.h"
#include <signal.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
//! [Interesting]
upm::ES08A *servo = new upm::ES08A(5);
servo->setAngle (180);
//! [Interesting]
servo->setAngle (90);
servo->setAngle (0);
servo->setAngle (90);
servo->setAngle (180);
std::cout << "exiting application" << std::endl;
delete servo;
return 0;
}

77
examples/gy65.cxx Normal file
View File

@ -0,0 +1,77 @@
/*
* 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 "gy65.h"
#include <signal.h>
int doWork = 0;
upm::GY65 *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]
uint32_t presure = 0;
float temperature = 0;
float altitude = 0;
uint32_t sealevel = 0;
sensor = new upm::GY65(0, ADDR);
while (!doWork) {
presure = sensor->getPressure ();
temperature = sensor->getTemperature ();
altitude = sensor->getAltitude ();
sealevel = sensor->getSealevelPressure ();
std::cout << "pressure value = " <<
presure <<
", atitude value = " <<
altitude <<
", sealevel value = " <<
sealevel <<
", temperature = " <<
temperature << std::endl;
usleep (100000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

63
examples/hcsr04.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* 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 "hcsr04.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
upm::HCSR04 *sonar = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
sonar->m_doWork = 1;
}
}
//! [Interesting]
void
interrupt (void * args) {
sonar->ackEdgeDetected ();
}
int
main(int argc, char **argv)
{
sonar = new upm::HCSR04(5, 7, &interrupt);
signal(SIGINT, sig_handler);
printf ("width = %d\n", sonar->getDistance());
std::cout << "exiting application" << std::endl;
delete sonar;
return 0;
}
//! [Interesting]

View File

@ -28,13 +28,13 @@ int
main(int argc, char **argv)
{
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
lcd->cursor(0,0);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->cursor(1,2);
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->cursor(2,4);
lcd->setCursor(2,4);
lcd->write("Hello World");
lcd->cursor(3,6);
lcd->setCursor(3,6);
lcd->write("Hello World");
lcd->close();
}

63
examples/led-bar.cxx Normal file
View File

@ -0,0 +1,63 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "my9221.h"
#include <signal.h>
int running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
upm::MY9221 *bar = new upm::MY9221(8, 9);
signal(SIGINT, sig_handler);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
}
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete bar;
return 0;
}

41
examples/max31855.cxx Normal file
View File

@ -0,0 +1,41 @@
/*
* 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 <signal.h>
//! [Interesting]
#include "max31855.h"
int
main(int argc, char **argv)
{
upm::MAX31855 *temp = new upm::MAX31855(0, 8);
std::cout << temp->getTemp() << std::endl;
return 0;
}
//! [Interesting]

42
examples/max44000.cxx Normal file
View File

@ -0,0 +1,42 @@
/*
* 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 "max44000.h"
int
main(int argc, char **argv)
{
//! [Interesting]
upm::MAX44000 *sensor = new upm::MAX44000(0, ADDR);
std::cout << "proximity value = " << sensor->getAmbient () << std::endl;
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

74
examples/mic-example.cxx Normal file
View 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]

64
examples/mma7455.cxx Normal file
View File

@ -0,0 +1,64 @@
/*
* 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 "mma7455.h"
#include <signal.h>
#include <pthread.h>
int doWork = 0;
upm::MMA7455 *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::MMA7455(0, ADDR);
short x, y, z;
while (!doWork) {
sensor->readData(&x, &y, &z);
std::cout << "Accelerometer X(" << x << ") Y(" << y << ") Z(" << z << ")" << std::endl;
usleep (100000);
}
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

View 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;
}

72
examples/nrf_receiver.cxx Normal file
View File

@ -0,0 +1,72 @@
/*
* 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 "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
//! [Interesting]
void nrf_handler () {
std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
}
//! [Interesting]
int
main(int argc, char **argv)
{
//! [Interesting]
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi1");
comm->nrfSetTXaddr ((uint8_t *) "devi2");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
comm->nrfListenForChannel ();
}
std::cout << "exiting application" << std::endl;
delete comm;
//! [Interesting]
return 0;
}

View 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 <string.h>
#include <unistd.h>
#include <iostream>
#include "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
void nrf_handler () {
}
int
main(int argc, char **argv)
{
//! [Interesting]
uint32_t dummyData = 0;
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi2");
comm->nrfSetTXaddr ((uint8_t *) "devi1");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
comm->nrfSend ();
std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
usleep (3000000);
dummyData += 3000;
}
std::cout << "exiting application" << std::endl;
delete comm;
//! [Interesting]
return 0;
}

116
examples/oled-1308.cxx Normal file
View File

@ -0,0 +1,116 @@
/*
* Author: Yevgeniy Kiveish <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 "ssd1308.h"
#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
};
int
main(int argc, char **argv)
{
upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
/*
* Simple print hello world
*/
// lcd->setCursor (0, 0);
// lcd->write ("Hello World");
/*
* Simple print hello world
*/
lcd->clear ();
lcd->draw (SeeedLogo, 1024);
lcd->close ();
}

126
examples/oled-1327.cxx Normal file
View File

@ -0,0 +1,126 @@
/*
* Author: Yevgeniy Kiveish <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 "ssd1327.h"
#define DEVICE_ADDRESS 0x3C
#define BUS_NUMBER 0x0
static uint8_t SeeedLogo[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x01, 0xC0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x07, 0x80, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x01, 0xE0,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0F, 0x00, 0x01, 0xE0,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x0F, 0x00, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
0x0F, 0x80, 0x01, 0xE0, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x0F, 0x80, 0x01, 0xE0,
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x0F, 0x80, 0x03, 0xE0, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1E, 0x07, 0x80, 0x03, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E,
0x07, 0x80, 0x03, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x07, 0x80, 0x03, 0xC1,
0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x87, 0xC0, 0x07, 0xC1, 0xF0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F,
0xC3, 0xC0, 0x07, 0x87, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE1, 0xE0, 0x07, 0x0F,
0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0xE0, 0x0F, 0x0F, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xF8, 0xF0, 0x0E, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xF8, 0x70, 0x1C, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x30, 0x18, 0x7E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x18, 0x30, 0xFC, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x88, 0x21, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0xC4, 0x47, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x0F, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x06,
0x00, 0x00, 0x60, 0x00, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xDF, 0xE1, 0x9F, 0xEC, 0x7E,
0xE6, 0x73, 0x9C, 0xE7, 0x39, 0xCE, 0x1C, 0xDF, 0xE1, 0xB9, 0xEC, 0xE7, 0xE0, 0x61, 0xD8, 0x66,
0x1B, 0x86, 0x1C, 0x06, 0x61, 0xB0, 0x6D, 0xC3, 0x7C, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x0F, 0x86,
0x61, 0xB0, 0x6D, 0x83, 0x3E, 0x7F, 0xFF, 0xFF, 0xFF, 0x06, 0x07, 0xC6, 0x61, 0xB0, 0x6D, 0x83,
0xC3, 0x61, 0x18, 0x46, 0x03, 0x86, 0x18, 0x66, 0x61, 0xB0, 0x6D, 0xC3, 0xFE, 0x7F, 0x9F, 0xE7,
0xF9, 0xFE, 0x1F, 0xE6, 0x3F, 0x9F, 0xEC, 0xFE, 0x7E, 0x3F, 0x0F, 0xC3, 0xF0, 0xFA, 0x0F, 0xC6,
0x3F, 0x9F, 0xEC, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00,
0x00, 0x20, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x20, 0x82, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0xF3, 0xCF, 0x70, 0x9E, 0x79, 0xE7, 0x80, 0x00, 0x00,
0x00, 0x00, 0x7D, 0x9E, 0x68, 0x20, 0xB2, 0xC8, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x9E,
0x6F, 0x20, 0xB2, 0xF9, 0xE7, 0x80, 0x00, 0x00, 0x00, 0x00, 0x46, 0x9A, 0x61, 0x20, 0xB2, 0xCB,
0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xF3, 0xCF, 0x30, 0x9E, 0x79, 0xE7, 0x90, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x02, 0x00, 0x00, 0x82, 0x60, 0x00, 0x00,
0xF8, 0x00, 0x00, 0x40, 0x40, 0x02, 0x00, 0x00, 0x83, 0x60, 0x00, 0x00, 0x8C, 0x00, 0x00, 0x40,
0x60, 0xB7, 0x79, 0xE7, 0x81, 0xC7, 0x92, 0x70, 0x89, 0xE7, 0x9E, 0x78, 0x7C, 0xE2, 0xC9, 0x2C,
0x81, 0xCC, 0xD2, 0x40, 0xFB, 0x21, 0xB2, 0x48, 0x40, 0x62, 0xF9, 0x2C, 0x80, 0x8C, 0xD2, 0x40,
0x8B, 0xE7, 0xB0, 0x48, 0x40, 0xE2, 0xC9, 0x2C, 0x80, 0x84, 0xD2, 0x40, 0x8B, 0x2D, 0x92, 0x48,
0x7D, 0xB3, 0x79, 0x27, 0x80, 0x87, 0x9E, 0x40, 0x8D, 0xE7, 0x9E, 0x48, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int
main(int argc, char **argv)
{
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
*/
lcd->draw (SeeedLogo, 96 * 96 / 8);
lcd->close ();
}

61
examples/pulsensor.cxx Normal file
View 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;
}

37
examples/rgb-lcd.cxx Normal file
View File

@ -0,0 +1,37 @@
/*
* Author: Yevgeniy Kiveish <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 "jhd1313m1.h"
int
main(int argc, char **argv)
{
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->close();
}

79
examples/st7735.cxx Normal file
View File

@ -0,0 +1,79 @@
/*
* 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 "st7735.h"
#include <signal.h>
int
main(int argc, char **argv)
{
//! [Interesting]
upm::ST7735 * lcd = new upm::ST7735(7, 4, 9, 8);
lcd->fillScreen (ST7735_RED);
lcd->refresh ();
lcd->fillScreen (ST7735_CYAN);
lcd->refresh ();
lcd->fillScreen (ST7735_BLACK);
lcd->refresh ();
lcd->drawLine(10, 10, 10, 100, ST7735_MAGENTA);
lcd->drawLine(20, 20, 10, 100, ST7735_YELLOW);
lcd->drawLine(30, 30, 50, 100, ST7735_WHITE);
lcd->refresh ();
lcd->drawPixel (20, 20, ST7735_GREEN);
lcd->refresh ();
lcd->drawTriangle (50, 50, 80, 80, 60, 90, ST7735_GREEN);
lcd->refresh ();
lcd->drawCircle (100, 110, 10, ST7735_BLUE);
lcd->refresh ();
lcd->setTextWrap(0x0);
lcd->setCursor(0, 30);
lcd->setTextColor(ST7735_RED, ST7735_RED);
lcd->setTextSize(1);
lcd->print("Hello World!");
lcd->setCursor(10, 50);
lcd->setTextColor(ST7735_RED, ST7735_YELLOW);
lcd->setTextSize(2);
lcd->print("BIG");
lcd->refresh ();
std::cout << "exiting application" << std::endl;
delete lcd;
//! [Interesting]
return 0;
}

73
examples/stepmotor.cxx Normal file
View 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;
}

View File

@ -1,3 +1,124 @@
add_subdirectory (hmc5883l)
add_subdirectory (grove)
add_subdirectory (lcm1602)
macro(subdirlist result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
set(dirlist ${dirlist} ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()
macro (upm_CREATE_INSTALL_PKGCONFIG generated_file install_location)
configure_file (${PROJECT_SOURCE_DIR}/src/pkgconfig.in
${CMAKE_CURRENT_BINARY_DIR}/${generated_file} @ONLY)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${generated_file} DESTINATION ${install_location})
endmacro (upm_CREATE_INSTALL_PKGCONFIG)
macro(upm_SWIG_PYTHON)
if(BUILDSWIGPYTHON)
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} ${MRAA_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_pyupm_${libname}_REAL_NAME}
PUBLIC
"${PYTHON_INCLUDE_PATH}"
"${PYTHON_INCLUDE_DIRS}"
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so
${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py
DESTINATION lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/
COMPONENT ${libname})
endif()
endmacro()
macro(upm_SWIG_NODE)
if(BUILDSWIGNODE)
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} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
PUBLIC
"${NODE_INCLUDE_DIRS}"
)
set_target_properties (jsupm_${libname} PROPERTIES
PREFIX ""
SUFFIX ".node"
)
createpackagejson(${libname})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
endif()
endmacro()
macro(upm_doxygen)
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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)
endif ()
endmacro()
if (SWIG_FOUND)
if(BUILDSWIGPYTHON)
find_package (PythonLibs)
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
endif(BUILDSWIGPYTHON)
if(BUILDSWIGNODE)
find_path (NODE_ROOT_DIR "node/node.h")
set (NODE_INCLUDE_DIRS
${NODE_ROOT_DIR}/src
${NODE_ROOT_DIR}/node
${NODE_ROOT_DIR}/deps/v8/include
${NODE_ROOT_DIR}/deps/uv/include
)
macro(createpackagejson)
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
endmacro()
endif(BUILDSWIGNODE)
endif()
macro(upm_module_init)
add_library (${libname} SHARED ${module_src})
include_directories (${MRAA_INCLUDE_DIR} .)
target_link_libraries (${libname} ${MRAA_LIBRARIES})
set_target_properties(
${libname}
PROPERTIES PREFIX "libupm-"
SOVERSION ${upm_VERSION_MAJOR}
VERSION ${upm_VERSION_STRING}
)
upm_create_install_pkgconfig (upm-${libname}.pc lib${LIB_SUFFIX}/pkgconfig)
if (SWIG_FOUND)
upm_swig_python()
upm_swig_node()
upm_doxygen()
endif()
install (TARGETS ${libname} DESTINATION lib COMPONENT ${libname})
install (FILES ${module_h} DESTINATION include/upm COMPONENT ${libname})
if (IPK)
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
set(CPACK_COMPONENT_${libname}_DESCRIPTION "${libdescription}")
endif()
endmacro(upm_module_init)
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
foreach(subdir ${SUBDIRS})
add_subdirectory(${subdir})
endforeach()

View File

@ -0,0 +1,5 @@
set (libname "buzzer")
set (libdescription "upm buzzer")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

51
src/buzzer/buzzer.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* 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 "buzzer.h"
using namespace upm;
Buzzer::Buzzer (int pinNumber) {
m_pwm_context = mraa_pwm_init (pinNumber);
m_name = "Buzzer";
}
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 note;
}
Buzzer::~Buzzer() {
mraa_pwm_close(m_pwm_context);
std::cout << "executed mraa_pwm_close" << std::endl;
}

81
src/buzzer/buzzer.h Normal file
View File

@ -0,0 +1,81 @@
/*
* 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/pwm.h>
#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 {
/**
* @brief C++ API for Buzzer component
*
* This file defines the Buzzer C++ interface for libbuzzer
*
* @snippet buzzer-sound.cxx Interesting
*
*/
class Buzzer {
public:
/**
* Instanciates a Buzzer object
*
* @param pin Buzzer pin number
*/
Buzzer (int pinNumber);
/**
* Buzzer object destructor.
*/
~Buzzer ();
/**
* Play chords.
*
* @param note chords (DO, RE, ME, etc...)
* @param delay time in microsec for playing the sound
*/
int playSound (int note, int delay);
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
protected:
std::string m_name;
private:
mraa_pwm_context m_pwm_context;
};
}

View File

@ -0,0 +1,7 @@
%module jsupm_buzzer
%{
#include "buzzer.h"
%}
%include "buzzer.h"

View File

@ -0,0 +1,8 @@
%module pyupm_buzzer
%feature("autodoc", "3");
%include "buzzer.h"
%{
#include "buzzer.h"
%}

View File

@ -1,39 +1,5 @@
set (libname "grove")
add_library (grove SHARED grove.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (grove ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_grove.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_grove.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_grove.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_grove python pyupm_grove.i grove.cxx)
# swig_add_module (jsupm_grove javascript jsupm_grove.i grove.cxx)
swig_link_libraries (pyupm_grove ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_grove ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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_grove_REAL_NAME} ${libname}doc_i)
endif ()
endif ()
set (libdescription "upm grove module")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -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);
}

View File

@ -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 {
@ -44,11 +44,11 @@ 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;
};
class GroveTemp: public Grove {
@ -58,7 +58,7 @@ class GroveTemp: public Grove {
float raw_value();
int value();
private:
maa_aio_context m_aio;
mraa_aio_context m_aio;
};
class GroveLight: public Grove {
@ -68,7 +68,7 @@ class GroveLight: public Grove {
float raw_value();
int value();
private:
maa_aio_context m_aio;
mraa_aio_context m_aio;
};
}

5
src/gy65/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
set (libname "gy65")
set (libdescription "upm GY65")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

222
src/gy65/gy65.cxx Normal file
View File

@ -0,0 +1,222 @@
/*
* 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 "gy65.h"
using namespace upm;
GY65::GY65 (int bus, int devAddr, uint8_t mode) {
m_name = "GY65";
m_controlAddr = devAddr;
m_bus = bus;
m_i2ControlCtx = mraa_i2c_init(m_bus);
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
if (i2cReadReg_8 (0xD0) != 0x55) {
std::cout << "Error :: Cannot continue" << std::endl;
return;
}
if (mode > BMP085_ULTRAHIGHRES) {
mode = BMP085_ULTRAHIGHRES;
}
oversampling = mode;
/* read calibration data */
ac1 = i2cReadReg_16 (BMP085_CAL_AC1);
ac2 = i2cReadReg_16 (BMP085_CAL_AC2);
ac3 = i2cReadReg_16 (BMP085_CAL_AC3);
ac4 = i2cReadReg_16 (BMP085_CAL_AC4);
ac5 = i2cReadReg_16 (BMP085_CAL_AC5);
ac6 = i2cReadReg_16 (BMP085_CAL_AC6);
b1 = i2cReadReg_16 (BMP085_CAL_B1);
b2 = i2cReadReg_16 (BMP085_CAL_B2);
mb = i2cReadReg_16 (BMP085_CAL_MB);
mc = i2cReadReg_16 (BMP085_CAL_MC);
md = i2cReadReg_16 (BMP085_CAL_MD);
}
GY65::~GY65() {
mraa_i2c_stop(m_i2ControlCtx);
}
int32_t
GY65::getPressure () {
int32_t UT, UP, B3, B5, B6, X1, X2, X3, p;
uint32_t B4, B7;
UT = getTemperatureRaw();
UP = getPressureRaw();
B5 = computeB5(UT);
// do pressure calcs
B6 = B5 - 4000;
X1 = ((int32_t)b2 * ( (B6 * B6)>>12 )) >> 11;
X2 = ((int32_t)ac2 * B6) >> 11;
X3 = X1 + X2;
B3 = ((((int32_t)ac1*4 + X3) << oversampling) + 2) / 4;
X1 = ((int32_t)ac3 * B6) >> 13;
X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15;
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
if (B7 < 0x80000000) {
p = (B7 * 2) / B4;
} else {
p = (B7 / B4) * 2;
}
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
p = p + ((X1 + X2 + (int32_t)3791)>>4);
return p;
}
int32_t
GY65::getPressureRaw () {
uint32_t raw;
i2cWriteReg (BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
if (oversampling == BMP085_ULTRALOWPOWER) {
usleep(5000);
} else if (oversampling == BMP085_STANDARD) {
usleep(8000);
} else if (oversampling == BMP085_HIGHRES) {
usleep(14000);
} else {
usleep(26000);
}
raw = i2cReadReg_16 (BMP085_PRESSUREDATA);
raw <<= 8;
raw |= i2cReadReg_8 (BMP085_PRESSUREDATA + 2);
raw >>= (8 - oversampling);
return raw;
}
int16_t
GY65::getTemperatureRaw () {
i2cWriteReg (BMP085_CONTROL, BMP085_READTEMPCMD);
usleep(5000);
return i2cReadReg_16 (BMP085_TEMPDATA);
}
float
GY65::getTemperature () {
int32_t UT, B5; // following ds convention
float temp;
UT = getTemperatureRaw ();
B5 = computeB5 (UT);
temp = (B5 + 8) >> 4;
temp /= 10;
return temp;
}
int32_t
GY65::getSealevelPressure(float altitudeMeters) {
float pressure = getPressure ();
return (int32_t)(pressure / pow(1.0-altitudeMeters/44330, 5.255));
}
float
GY65::getAltitude (float sealevelPressure) {
float altitude;
float pressure = getPressure ();
altitude = 44330 * (1.0 - pow(pressure /sealevelPressure,0.1903));
return altitude;
}
int32_t
GY65::computeB5(int32_t UT) {
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
return X1 + X2;
}
mraa_result_t
GY65::i2cWriteReg (uint8_t reg, uint8_t value) {
mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { reg, value };
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
error = mraa_i2c_write (m_i2ControlCtx, data, 2);
return error;
}
uint16_t
GY65::i2cReadReg_16 (int reg) {
uint16_t data;
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
mraa_i2c_write_byte(m_i2ControlCtx, reg);
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;
data |= high;
return data;
}
uint8_t
GY65::i2cReadReg_8 (int reg) {
uint8_t data;
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
mraa_i2c_write_byte(m_i2ControlCtx, reg);
mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
mraa_i2c_read(m_i2ControlCtx, &data, 0x1);
return data;
}

161
src/gy65/gy65.h Normal file
View File

@ -0,0 +1,161 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Credits to Adafruit.
* Based on Adafruit BMP085 library.
*
* 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>
#include <math.h>
#define ADDR 0x77 // device address
// registers address
#define BMP085_ULTRALOWPOWER 0
#define BMP085_STANDARD 1
#define BMP085_HIGHRES 2
#define BMP085_ULTRAHIGHRES 3
#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
#define BMP085_CONTROL 0xF4
#define BMP085_TEMPDATA 0xF6
#define BMP085_PRESSUREDATA 0xF6
#define BMP085_READTEMPCMD 0x2E
#define BMP085_READPRESSURECMD 0x34
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for GY65 chip (Atmospheric Pressure Sensor)
*
* This file defines the gy65 C++ interface for libgy65
*
* @snippet gy65.cxx Interesting
*/
class GY65 {
public:
/**
* Instanciates a GY65 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
GY65 (int bus, int devAddr, uint8_t mode = BMP085_ULTRAHIGHRES);
/**
* GY65 object destructor, basicaly it close i2c connection.
*/
~GY65 ();
/**
* Return calculated pressure
*/
int32_t getPressure ();
/**
*
* Get raw pressure data
*/
int32_t getPressureRaw ();
/**
* Get raw temperature data from chip
*/
int16_t getTemperatureRaw ();
/**
* Return calculated temperature
*/
float getTemperature ();
/**
* With given absolute altitude sea level can be calculated
*
* @param altitudeMeters altitude
*/
int32_t getSealevelPressure(float altitudeMeters = 0);
/**
* With given sea level altitude in meters can be calculated
*
* @param sealevelPressure Sea level
*/
float getAltitude (float sealevelPressure = 101325);
/**
* Calculation of B5 (check spec for more information)
*
* @param UT
*/
int32_t computeB5 (int32_t UT);
/**
* Read two bytes register
*
* @param reg address of a register
*/
uint16_t i2cReadReg_16 (int reg);
/**
* Write to one byte register
*
* @param reg address of a register
* @param value byte to be written
*/
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
/**
* Read one byte register
*
* @param reg address of a register
*/
uint8_t i2cReadReg_8 (int reg);
private:
std::string m_name;
int m_controlAddr;
int m_bus;
mraa_i2c_context m_i2ControlCtx;
uint8_t oversampling;
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
uint16_t ac4, ac5, ac6;
};
}

7
src/gy65/jsupm_gy65.i Normal file
View File

@ -0,0 +1,7 @@
%module jsupm_gy65
%{
#include "gy65.h"
%}
%include "gy65.h"

10
src/gy65/pyupm_gy65.i Normal file
View File

@ -0,0 +1,10 @@
%module pyupm_gy65
%include "stdint.i"
%feature("autodoc", "3");
%include "gy65.h"
%{
#include "gy65.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "hcsr04")
set (libdescription "upm proximity sensor")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

94
src/hcsr04/hcsr04.cxx Normal file
View File

@ -0,0 +1,94 @@
/*
* 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 <functional>
#include "hcsr04.h"
using namespace upm;
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
mraa_result_t error = MRAA_SUCCESS;
m_name = "HCSR04";
m_pwmTriggerCtx = mraa_pwm_init (triggerPin);
if (m_pwmTriggerCtx == NULL) {
std::cout << "PWM context is NULL" << std::endl;
exit (1);
}
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);
}
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 () {
mraa_result_t error = MRAA_SUCCESS;
mraa_pwm_close (m_pwmTriggerCtx);
error = mraa_gpio_close (m_echoPinCtx);
if (error != MRAA_SUCCESS) {
mraa_result_print (error);
}
}
int
HCSR04::getDistance () {
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;
while (!m_doWork) {
sleep (1);
}
return m_FallingTimeStamp - m_RisingTimeStamp;
}
void
HCSR04::ackEdgeDetected () {
struct timeval timer;
gettimeofday(&timer, NULL);
++m_InterruptCounter;
if (!(m_InterruptCounter % 2)) {
m_FallingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
m_doWork = 1;
} else {
m_RisingTimeStamp = 1000000 * timer.tv_sec + timer.tv_usec;
}
}

99
src/hcsr04/hcsr04.h Normal file
View File

@ -0,0 +1,99 @@
/*
* 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/pwm.h>
#include <sys/time.h>
#define HIGH 1
#define LOW 0
#define MAX_PERIOD 7968
#define TRIGGER_PULSE 10
namespace upm {
/**
* @brief C++ API for HCSR04 (ultrasonic ranging module) component
*
* This file defines the HCSR04 C++ interface for libhcsr04
*
* @snippet hcsr04.cxx Interesting
*
*/
class HCSR04 {
public:
/**
* Instanciates a HCSR04 object
*
* @param triggerPin pin for triggering the sensor for distance
* @param echoPin pulse response to triggering
* @param fptr function pointer for handling raising and
* falling interrupts
*/
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
/**
* HCSR04 object destructor.
*/
~HCSR04 ();
/**
* Get the distance from the sensor.
*/
int getDistance ();
/**
* On each interrupt this function will detect if the interrupt
* was falling edge or rising.
* Should be called from the interrupt handler.
*/
void ackEdgeDetected ();
uint8_t m_doWork; /**< Flag to controll blocking function while waiting for falling edge interrupt */
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
private:
mraa_pwm_context m_pwmTriggerCtx;
mraa_gpio_context m_echoPinCtx;
uint8_t m_waitEcho;
long m_RisingTimeStamp;
long m_FallingTimeStamp;
uint8_t m_InterruptCounter;
std::string m_name;
};
}

View File

@ -0,0 +1,7 @@
%module jsupm_hcsr04
%{
#include "hcsr04.h"
%}
%include "hcsr04.h"

View File

@ -0,0 +1,8 @@
%module pyupm_hcsr04
%feature("autodoc", "3");
%include "hcsr04.h"
%{
#include "hcsr04.h"
%}

View File

@ -1,39 +1,5 @@
set (libname "hmc5883l")
add_library (hmc5883l SHARED hmc5883l.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (hmc5883l ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_hmc5883l.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_hmc5883l.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_hmc5883l.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_hmc5883l python pyupm_hmc5883l.i hmc5883l.cxx)
# swig_add_module (jsupm_hmc5883l javascript jsupm_hmc5883l.i hmc5883l.cxx)
swig_link_libraries (pyupm_hmc5883l ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_hmc5883l ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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_hmc5883l_REAL_NAME} ${libname}doc_i)
endif ()
endif ()
set (libdescription "libupm Digital Compass")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -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

View File

@ -23,7 +23,7 @@
*/
#pragma once
#include <maa/i2c.h>
#include <mraa/i2c.h>
#define MAX_BUFFER_LENGTH 6
@ -48,14 +48,14 @@ public:
/**
* Updates the values by reading from i2c
*
*
* @return 0 for success
*/
int update();
private:
int m_coor[3];
char m_rx_tx_buf[MAX_BUFFER_LENGTH];
maa_i2c_context m_i2c;
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
mraa_i2c_context m_i2c;
};
}

5
src/lcd/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
set (libname "i2clcd")
set (libdescription "upm lcd/oled displays")
set (module_src i2clcd.cxx lcm1602.cxx jhd1313m1.cxx ssd1308.cxx ssd1327.cxx)
set (module_h i2clcd.h lcm1602.h jhd1313m1.h ssd1308.h ssd1327.h)
upm_module_init()

86
src/lcd/i2clcd.cxx Normal file
View File

@ -0,0 +1,86 @@
/*
* 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 "i2clcd.h"
using namespace upm;
I2CLcd::I2CLcd (int bus, int lcdAddress) {
m_lcd_control_address = lcdAddress;
m_bus = bus;
m_i2c_lcd_control = mraa_i2c_init(m_bus);
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");
}
}
mraa_result_t
I2CLcd::write (int row, int column, std::string msg) {
setCursor (row, column);
write (msg);
}
mraa_result_t
I2CLcd::close() {
return mraa_i2c_stop(m_i2c_lcd_control);
}
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 = mraa_i2c_address (ctx, deviceAdress);
error = mraa_i2c_write (ctx, data, 2);
return error;
}
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 = mraa_i2c_address (ctx, m_lcd_control_address);
error = mraa_i2c_write (ctx, data, 2);
return error;
}
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 = mraa_i2c_address (ctx, m_lcd_control_address);
error = mraa_i2c_write (ctx, data, 2);
return error;
}

95
src/lcd/i2clcd.h Normal file
View 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/i2c.h>
namespace upm {
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_DATA 0x40
#define LCD_CMD 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
class I2CLcd {
public:
I2CLcd (int bus, int lcdAddress);
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;
}
protected:
std::string m_name;
int m_lcd_control_address;
int m_bus;
mraa_i2c_context m_i2c_lcd_control;
};
}

107
src/lcd/jhd1313m1.cxx Normal file
View File

@ -0,0 +1,107 @@
/*
* 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 "jhd1313m1.h"
using namespace upm;
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : I2CLcd(bus, lcdAddress) {
mraa_result_t error = MRAA_SUCCESS;
m_rgb_address = rgbAddress;
m_i2c_lcd_rgb = mraa_i2c_init(m_bus);
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");
}
usleep(50000);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
i2Cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
clear ();
usleep(4500);
i2Cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT);
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, 255);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
i2cReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
}
Jhd1313m1::~Jhd1313m1() {
}
/*
* **************
* virtual area
* **************
*/
mraa_result_t
Jhd1313m1::write (std::string msg) {
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]);
}
return error;
}
mraa_result_t
Jhd1313m1::setCursor (int row, int column) {
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);
return error;
}
mraa_result_t
Jhd1313m1::clear () {
return i2Cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
}
mraa_result_t
Jhd1313m1::home () {
return i2Cmd (m_i2c_lcd_control, LCD_RETURNHOME);
}

45
src/lcd/jhd1313m1.h Normal file
View File

@ -0,0 +1,45 @@
/*
* 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 "i2clcd.h"
namespace upm {
class Jhd1313m1 : public I2CLcd {
public:
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
~Jhd1313m1 ();
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
private:
int m_rgb_address;
mraa_i2c_context m_i2c_lcd_rgb;
};
}

21
src/lcd/jsupm_i2clcd.i Normal file
View File

@ -0,0 +1,21 @@
%module jsupm_i2clcd
%include "i2clcd.h"
%{
#include "i2clcd.h"
%}
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}
%include "ssd1327.h"
%{
#include "ssd1327.h"
%}

View File

@ -30,50 +30,10 @@
#include "lcm1602.h"
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in)
{
address = addr_in;
bus = bus_in;
maa_init();
m_i2c = maa_i2c_init(bus);
maa_i2c_address(m_i2c, address);
Lcm1602::Lcm1602(int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
mraa_result_t error = MRAA_SUCCESS;
usleep(50000);
expandWrite(LCD_BACKLIGHT);
@ -98,77 +58,81 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
send(LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT, 0);
home();
}
int
Lcm1602::clear()
{
Lcm1602::~Lcm1602 () {
}
/*
* **************
* virtual area
* **************
*/
mraa_result_t
Lcm1602::write (std::string msg) {
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;
}
mraa_result_t
Lcm1602::setCursor (int row, int column) {
mraa_result_t error = MRAA_SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
return send (LCD_CMD | offset, 0);
}
mraa_result_t
Lcm1602::clear () {
return send(LCD_CLEARDISPLAY, 0);
}
int
Lcm1602::home()
{
mraa_result_t
Lcm1602::home () {
return send(LCD_RETURNHOME, 0);
}
int
Lcm1602::cursor(int row, int column)
{
if (row > 3)
return 99;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
}
int
Lcm1602::write(std::string msg)
{
int ret = 0;
for(std::string::size_type i = 0; i < msg.size(); ++i) {
ret = send(msg[i], LCD_RS);
}
return 0;
}
int
Lcm1602::close()
{
return maa_i2c_stop(m_i2c);
}
int
Lcm1602::send(char value, int mode)
{
int ret = 0;
char h = value & 0xf0;
char l = (value << 4) & 0xf0;
/*
* **************
* private area
* **************
*/
mraa_result_t
Lcm1602::send (uint8_t value, int mode) {
mraa_result_t ret = MRAA_SUCCESS;
uint8_t h = value & 0xf0;
uint8_t l = (value << 4) & 0xf0;
ret = write4bits(h | mode);
ret = write4bits(l | mode);
return ret;
}
int
Lcm1602::write4bits(char value)
mraa_result_t
Lcm1602::write4bits(uint8_t value)
{
int ret = 0;
mraa_result_t ret = MRAA_SUCCESS;
ret = expandWrite(value);
ret = pulseEnable(value);
return 0;
return ret;
}
int
Lcm1602::expandWrite(char value)
mraa_result_t
Lcm1602::expandWrite(uint8_t value)
{
char buffer = value | LCD_BACKLIGHT;
return maa_i2c_write_byte(m_i2c, buffer);
uint8_t buffer = value | LCD_BACKLIGHT;
return mraa_i2c_write_byte(m_i2c_lcd_control, buffer);
}
int
Lcm1602::pulseEnable(char value)
mraa_result_t
Lcm1602::pulseEnable(uint8_t value)
{
int ret = 0;
mraa_result_t ret = MRAA_SUCCESS;
ret = expandWrite(value | LCD_EN);
usleep(1);
ret = expandWrite(value & ~LCD_EN);

View File

@ -7,7 +7,7 @@
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* Permission is hereby granted, free of uint8_tge, 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
@ -28,37 +28,28 @@
#pragma once
#include <string>
#include <maa/i2c.h>
#include "i2clcd.h"
namespace upm {
class Lcm1602 {
public:
/** LCM1602 Constructor.
* Calls MAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
Lcm1602(int bus, int address);
// Clear the screen
int clear();
// Set the cursor to home
int home();
// change cursor to row,column.
int cursor(int row, int column);
//write a string at the position
int write(std::string msg);
int close();
private:
int address;
int bus;
int send(char value, int mode);
int write4bits(char value);
int expandWrite(char value);
int pulseEnable(char value);
maa_i2c_context m_i2c;
};
class Lcm1602 : public I2CLcd {
public:
/** LCM1602 Constructor.
* Calls MRAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
Lcm1602(int bus, int address);
~Lcm1602();
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
private :
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);
};
}

23
src/lcd/pyupm_i2clcd.i Normal file
View File

@ -0,0 +1,23 @@
%module pyupm_i2clcd
%feature("autodoc", "3");
%include "i2clcd.h"
%{
#include "i2clcd.h"
%}
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}
%include "ssd1327.h"
%{
#include "ssd1327.h"
%}

139
src/lcd/ssd1308.cxx Normal file
View 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 <string>
#include <unistd.h>
#include "ssd1308.h"
using namespace upm;
SSD1308::SSD1308 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
printf ("NO_GDB :: DISPLAY_CMD_OFF \n");
usleep (4500);
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
usleep (4500);
setNormalDisplay (); // set to normal display '1' is ON
clear ();
setAddressingMode (PAGE);
}
SSD1308::~SSD1308 () {
}
mraa_result_t
SSD1308::draw (uint8_t *data, int bytes) {
mraa_result_t error = MRAA_SUCCESS;
setAddressingMode (HORIZONTAL);
for (int idx = 0; idx < bytes; idx++) {
i2cData (m_i2c_lcd_control, data[idx]);
}
return error;
}
/*
* **************
* virtual area
* **************
*/
mraa_result_t
SSD1308::write (std::string msg) {
mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = {0x40, 0};
setAddressingMode (PAGE);
for (std::string::size_type i = 0; i < msg.size(); ++i) {
writeChar (m_i2c_lcd_control, msg[i]);
}
return error;
}
mraa_result_t
SSD1308::setCursor (int row, int column) {
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
error = i2Cmd (m_i2c_lcd_control, BASE_HIGH_COLUMN_ADDR + ((8 * column >> 4) & 0x0F)); // set column higher address
return error;
}
mraa_result_t
SSD1308::clear () {
mraa_result_t error = MRAA_SUCCESS;
uint8_t columnIdx, rowIdx;
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_OFF); // display off
for(rowIdx = 0; rowIdx < 8; rowIdx++) {
setCursor (rowIdx, 0);
// clear all columns
for(columnIdx = 0; columnIdx < 16; columnIdx++) {
writeChar (m_i2c_lcd_control, ' ');
}
}
i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_ON); // display on
home ();
return MRAA_SUCCESS;
}
mraa_result_t
SSD1308::home () {
return setCursor (0, 0);
}
/*
* **************
* private area
* **************
*/
mraa_result_t
SSD1308::writeChar (mraa_i2c_context ctx, uint8_t value) {
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
for (uint8_t idx = 0; idx < 8; idx++) {
i2cData (m_i2c_lcd_control, BasicFont[value - 32][idx]);
}
}
mraa_result_t
SSD1308::setNormalDisplay () {
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
}
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
}

170
src/lcd/ssd1308.h Normal file
View File

@ -0,0 +1,170 @@
/*
* 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 "i2clcd.h"
namespace upm {
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF
#define BASE_LOW_COLUMN_ADDR 0x00
#define BASE_HIGH_COLUMN_ADDR 0x10
#define BASE_PAGE_START_ADDR 0xB0
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
#define DISPLAY_CMD_SET_NORMAL 0xA6
const uint8_t BasicFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
typedef enum {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2
} displayAddressingMode;
class SSD1308 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MRAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
SSD1308 (int bus, int address);
~SSD1308 ();
mraa_result_t draw(uint8_t *data, int bytes);
// pure virtual methods
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
private:
mraa_result_t writeChar (mraa_i2c_context ctx, uint8_t value);
mraa_result_t setNormalDisplay ();
mraa_result_t setAddressingMode (displayAddressingMode mode);
};
}

276
src/lcd/ssd1327.cxx Normal file
View File

@ -0,0 +1,276 @@
/*
* 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>
#include <unistd.h>
#include "ssd1327.h"
using namespace upm;
#define INIT_SLEEP 50000
#define CMD_SLEEP 10000
SSD1327::SSD1327 (int bus_in, int addr_in) : I2CLcd (bus_in, addr_in) {
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);
i2Cmd (m_i2c_lcd_control, 0x12);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAE); // Set display off
usleep (INIT_SLEEP);
i2Cmd (m_i2c_lcd_control, 0xA8); // set multiplex ratio
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x5F); // 96
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA1); // set display start line
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x00); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA2); // set display offset
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x60);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA0); // set remap
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x46);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAB); // set vdd internal
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x81); // set contrasr
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x53); // 100 nit
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB1); // Set Phase Length
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X51); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB9); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xBC); // set pre_charge voltage/VCOMH
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x08); // (0x08);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xBE); // set VCOMH
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X07); // (0x07);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xB6); // Set second pre-charge period
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x01); //
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xD5); // enable second precharge and enternal vsl
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0X62); // (0x62);
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xA4); // Set Normal Display Mode
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x2E); // Deactivate Scroll
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0xAF); // Switch on display
usleep (INIT_SLEEP);
// Row Address
error = i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
usleep (INIT_SLEEP);
// Column Address
error = i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep (INIT_SLEEP);
error = i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments)
usleep (INIT_SLEEP);
clear ();
setNormalDisplay ();
setVerticalMode ();
}
SSD1327::~SSD1327 () {
}
mraa_result_t
SSD1327::draw (uint8_t *data, int bytes) {
mraa_result_t error = MRAA_SUCCESS;
setHorizontalMode ();
for (int row = 0; row < bytes; row++) {
for (uint8_t col = 0; col < 8; col+=2) {
uint8_t value = 0x0;
uint8_t bitOne = (data[row] << col) & 0x80;
uint8_t bitTwo = (data[row] << (col + 1)) & 0x80;
value |= (bitOne) ? grayHigh : 0x00;
value |= (bitTwo) ? grayLow : 0x00;
i2cData (m_i2c_lcd_control, value);
usleep (CMD_SLEEP - 2000);
}
}
return error;
}
/*
* **************
* virtual area
* **************
*/
mraa_result_t
SSD1327::write (std::string msg) {
mraa_result_t error = MRAA_SUCCESS;
setVerticalMode ();
for (std::string::size_type i = 0; i < msg.size(); ++i) {
writeChar (m_i2c_lcd_control, msg[i]);
}
return error;
}
mraa_result_t
SSD1327::setCursor (int row, int column) {
mraa_result_t error = MRAA_SUCCESS;
//Column Address
i2Cmd (m_i2c_lcd_control, 0x15); /* Set Column Address */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x08 + (column * 4)); /* Start Column: Start from 8 */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x37); /* End Column */
usleep (CMD_SLEEP);
// Row Address
i2Cmd (m_i2c_lcd_control, 0x75); /* Set Row Address */
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x00 + (row * 8)); /* Start Row*/
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x07 + (row * 8)); /* End Row*/
usleep (CMD_SLEEP);
return error;
}
mraa_result_t
SSD1327::clear () {
mraa_result_t error = MRAA_SUCCESS;
uint8_t columnIdx, rowIdx;
for(rowIdx = 0; rowIdx < 12; rowIdx++) {
// clear all columns
for(columnIdx = 0; columnIdx < 12; columnIdx++) {
writeChar (m_i2c_lcd_control, ' ');
}
}
return MRAA_SUCCESS;
}
mraa_result_t
SSD1327::home () {
return setCursor (0, 0);
}
mraa_result_t
SSD1327::setGrayLevel (uint8_t level) {
grayHigh = (level << 4) & 0xF0;
grayLow = level & 0x0F;
}
/*
* **************
* private area
* **************
*/
mraa_result_t
SSD1327::writeChar (mraa_i2c_context ctx, uint8_t value) {
if (value < 0x20 || value > 0x7F) {
value = 0x20; // space
}
for (uint8_t row = 0; row < 8; row=row+2) {
for (uint8_t col = 0; col < 8; col++) {
uint8_t data = 0x0;
uint8_t bitOne = ((BasicFont[value - 32][row]) >> col) & 0x1;
uint8_t bitTwo = ((BasicFont[value - 32][row + 1]) >> col) & 0x1;
data |= (bitOne) ? grayHigh : 0x00;
data |= (bitTwo) ? grayLow : 0x00;
i2cData (m_i2c_lcd_control, data);
usleep (CMD_SLEEP - 2000);
}
}
}
mraa_result_t
SSD1327::setNormalDisplay () {
return i2Cmd (m_i2c_lcd_control, DISPLAY_CMD_SET_NORMAL); // set to normal display '1' is ON
}
mraa_result_t
SSD1327::setHorizontalMode () {
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x42); // horizontal mode
usleep (CMD_SLEEP);
// Row Address
i2Cmd (m_i2c_lcd_control, 0x75); // Set Row Address
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x00); // Start 0
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x5f); // End 95
usleep (CMD_SLEEP);
// Column Address
i2Cmd (m_i2c_lcd_control, 0x15); // Set Column Address
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments)
usleep (CMD_SLEEP);
}
mraa_result_t
SSD1327::setVerticalMode () {
i2Cmd (m_i2c_lcd_control, 0xA0); // remap to
usleep (CMD_SLEEP);
i2Cmd (m_i2c_lcd_control, 0x46); // Vertical mode
usleep (CMD_SLEEP);
}

175
src/lcd/ssd1327.h Normal file
View File

@ -0,0 +1,175 @@
/*
* 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 "i2clcd.h"
namespace upm {
/*
#define DISPLAY_CMD_OFF 0xAE
#define DISPLAY_CMD_ON 0xAF
#define BASE_LOW_COLUMN_ADDR 0x00
#define BASE_HIGH_COLUMN_ADDR 0x10
#define BASE_PAGE_START_ADDR 0xB0
#define DISPLAY_CMD_MEM_ADDR_MODE 0x20
*/
#define DISPLAY_CMD_SET_NORMAL 0xA4
const uint8_t BasicFont[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
{0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
{0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
{0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
{0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
{0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
{0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
{0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
{0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
{0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
{0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
{0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
{0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
{0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
{0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
{0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
{0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
{0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
{0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
{0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
{0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
{0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
{0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
{0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
{0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
{0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
{0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
{0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
{0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
{0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
{0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
{0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
{0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
{0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
{0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
{0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
{0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
{0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
{0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
};
typedef enum {
HORIZONTAL = 0,
VERTICAL = 1,
PAGE = 2
} displayAddressingMode;
class SSD1327 : public I2CLcd {
public:
/** SSD1308 Constructor.
* Calls MRAA initialisation functions.
* @param bus i2c bus to use
* @param address the slave address the lcd is registered on.
*/
SSD1327 (int bus, int address);
~SSD1327 ();
mraa_result_t draw(uint8_t *data, int bytes);
// virtual methods
mraa_result_t write (std::string msg);
mraa_result_t setCursor (int row, int column);
mraa_result_t clear ();
mraa_result_t home ();
mraa_result_t setGrayLevel (uint8_t level);
private:
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;
};
}

View File

@ -1,39 +0,0 @@
set (libname "lcm1602")
add_library (lcm1602 SHARED lcm1602.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (lcm1602 ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_lcm1602 python pyupm_lcm1602.i lcm1602.cxx)
# swig_add_module (jsupm_lcm1602 javascript jsupm_lcm1602.i lcm1602.cxx)
swig_link_libraries (pyupm_lcm1602 ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_lcm1602 ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
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_lcm1602_REAL_NAME} ${libname}doc_i)
endif ()
endif ()

View File

@ -1,7 +0,0 @@
%module jsupm_lcm1602
%{
#include "lcm1602.h"
%}
%include "lcm1602.h"

View File

@ -1,12 +0,0 @@
%module pyupm_lcm1602
%feature("autodoc", "3");
#ifdef DOXYGEN
%include "lcm1602_doc.i"
#endif
%include "lcm1602.h"
%{
#include "lcm1602.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "max31855")
set (libdescription "K type thermistor amplifier")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,9 @@
//! [Interesting]
%module jsupm_max31855
%{
#include "max31855.h"
%}
%include "max31855.h"
//! [Interesting]

103
src/max31855/max31855.cxx Normal file
View File

@ -0,0 +1,103 @@
/*
* 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 "max31855.h"
using namespace upm;
//! [Constructor]
MAX31855::MAX31855(int bus, int cs)
{
// initialise chip select as a normal gpio
m_gpio = mraa_gpio_init(cs);
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
// initialise the spi bus with a 2Mhz clock
m_sensor = mraa_spi_init(bus);
mraa_spi_frequency(m_sensor, 2000000);
}
//! [Constructor]
//! [Destructor]
MAX31855::~MAX31855()
{
// close both m_sensor & m_gpio cleanly
mraa_result_t error;
error = mraa_spi_stop(m_sensor);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
error = mraa_gpio_close(m_gpio);
if (error != MRAA_SUCCESS) {
mraa_result_print(error);
}
}
//! [Destructor]
double
MAX31855::getTemp()
{
//! [spi]
// set chip select low
mraa_gpio_write(m_gpio, 0);
uint8_t buf[4];
// set our input buffer to 0, this is clean but not required
memset(buf, 0, sizeof(uint8_t)*4);
// Write buffer to the spi slave
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];;
// mraa_spi_write_buf does not free the return buffer
free(x);
if (temp & 0x7) {
std::cerr << "Something went very wrong!" << std::endl;
}
// scrap all the data we dont care about
temp >>= 18;
// LSB = 0.25 degrees C
double c = (double) temp;
c *= 0.25;
//! [conversion]
// set chip select high
mraa_gpio_write(m_gpio, 1);
return c;
}

69
src/max31855/max31855.h Normal file
View File

@ -0,0 +1,69 @@
/*
* 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/spi.h>
#include <mraa/gpio.h>
namespace upm {
/**
* @brief C++ API for MAX31855
*
* This file defines the max31855 SPI sensor
*
* @snippet examples/max31855.cxx Interesting
*
*/
//! [Interesting]
class MAX31855 {
public:
/**
* Instanciates a MAX31855 object
*
* @param bus The spi bus to use
* @param cs The chip select pin
*/
MAX31855(int bus, int cs);
/**
* MAX31855 object destructor
*/
~MAX31855();
/**
* Get the distance from the sensor
*
* @return value in degrees celcius
*/
double getTemp();
private:
mraa_spi_context m_sensor;
mraa_gpio_context m_gpio;
};
//! [Interesting]
}

View File

@ -0,0 +1,10 @@
%module pyupm_max31855
%include "stdint.i"
%feature("autodoc", "3");
%include "max31855.h"
%{
#include "max31855.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "max44000")
set (libdescription "upm MAX44000")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,7 @@
%module jsupm_max44000
%{
#include "max44000.h"
%}
%include "max44000.h"

114
src/max44000/max44000.cxx Normal file
View File

@ -0,0 +1,114 @@
/*
* 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 "max44000.h"
using namespace upm;
MAX44000::MAX44000 (int bus, int devAddr) {
m_name = "MAX44000";
m_maxControlAddr = devAddr;
m_bus = bus;
m_i2cMaxControlCtx = mraa_i2c_init(m_bus);
mraa_result_t ret = mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
if (ret != MRAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
// i2cWriteReg (MCR, 0x2C);
// i2cWriteReg (TCR, 0x6);
}
MAX44000::~MAX44000() {
mraa_i2c_stop(m_i2cMaxControlCtx);
}
uint16_t
MAX44000::getProximity () {
uint16_t data = 0;
data = (i2cReadReg_8 (ALSDATA_HIGH) & 0x7F) << 8;
data = data | i2cReadReg_8 (ALSDATA_LOW);
return data;
}
uint16_t
MAX44000::getAmbient () {
uint16_t data = 0;
data = (i2cReadReg_8 (ALSDATA_HIGH) & 0x7F) << 8;
data = data | i2cReadReg_8 (ALSDATA_LOW);
return data;
}
/*
* **************
* private area
* **************
*/
uint8_t
MAX44000::i2cReadReg_8 (int reg) {
uint8_t data;
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
mraa_i2c_read(m_i2cMaxControlCtx, &data, 0x1);
return data;
}
uint16_t
MAX44000::i2cReadReg_16 (int reg) {
uint16_t data;
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
mraa_i2c_write_byte(m_i2cMaxControlCtx, reg);
mraa_i2c_address(m_i2cMaxControlCtx, m_maxControlAddr);
mraa_i2c_read(m_i2cMaxControlCtx, (uint8_t *)&data, 0x2);
return data;
}
mraa_result_t
MAX44000::i2cWriteReg (uint8_t reg, uint8_t value) {
mraa_result_t error = MRAA_SUCCESS;
uint8_t data[2] = { reg, value };
error = mraa_i2c_address (m_i2cMaxControlCtx, m_maxControlAddr);
error = mraa_i2c_write (m_i2cMaxControlCtx, data, 2);
return error;
}

135
src/max44000/max44000.h Normal file
View File

@ -0,0 +1,135 @@
/*
* 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 0x4A // device address
// registers address
#define ISR 0x00 // Interrupt Status Register
#define MCR 0x01 // Main Configuration Register
#define RCR 0x02 // Receive Configuration Register
#define TCR 0x03 // Transmit Configuration Register
#define ALSDATA_HIGH 0x04 // ambient sensor data high byte
#define ALSDATA_LOW 0x05 // ambient sensor data low byte
#define PRXDATA 0x15 // proximity sensor data
#define ALS_UP_THRESH_HIGH 0x06 // ALS Interrupt Threshold Registers High
#define ALS_UP_THRESH_LOW 0x07 // ALS Interrupt Threshold Registers LOW
#define ALS_LO_THRESH_HIGH 0x08 // ALS Interrupt Threshold Registers High
#define ALS_LO_THRESH_LOW 0x09 // ALS Interrupt Threshold Registers Low
#define TPTR 0x0A // ALS/PROX Threshold Persist Timer Register
#define PROX_THRESH_IND 0x0B // Proximity Threshold Register
#define PROX_THRESH 0x0C // Proximity Threshold Register
#define TRIM_GAIN_GREEN 0x0F // Digital Gain Trim Register
#define TRIM_GAIN_IR 0x10 // Digital Gain Trim Register
#define HIGH 1
#define LOW 0
namespace upm {
/**
* @brief C++ API for MAX44000 chip (Ambient and Infrared Proximity Sensor)
*
* This file defines the MAX44000 C++ interface for libmax44000
*
* @snippet proximity.cxx Interesting
*
* PMOD pins for MAX44000PMB1 board
*
* ( -= J1 =- )
* (1) - NUL
* (2) - IRQ
* (3) - SCL
* (4) - SDA
* (5) - GND
* (6) - VCC
*
*/
class MAX44000 {
public:
/**
* Instanciates a MAX44000 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MAX44000 (int bus, int devAddr);
/**
* MAX44000 object destructor, basicaly it close i2c connection.
*/
~MAX44000 ();
/**
* Read the proximity value from the chip (based on ambient data).
*/
uint16_t getProximity ();
/**
* Read the ambient value from the chip (based on ambient data).
*/
uint16_t getAmbient ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* Read one byte register
*
* @param reg address of a register
*/
uint8_t i2cReadReg_8 (int reg);
/**
* Read two bytes register
*
* @param reg address of a register
*/
uint16_t i2cReadReg_16 (int reg);
/**
* Write to one byte register
*
* @param reg address of a register
* @param value byte to be written
*/
mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
private:
std::string m_name;
int m_maxControlAddr;
int m_bus;
mraa_i2c_context m_i2cMaxControlCtx;
};
}

View File

@ -0,0 +1,10 @@
%module pyupm_max44000
%include "stdint.i"
%feature("autodoc", "3");
%include "max44000.h"
%{
#include "max44000.h"
%}

5
src/mic/CMakeLists.txt Normal file
View 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()

7
src/mic/jsupm_mic.i Normal file
View File

@ -0,0 +1,7 @@
%module jsupm_mic
%{
#include "mic.h"
%}
%include "mic.h"

96
src/mic/mic.cxx Normal file
View 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;
}

86
src/mic/mic.h Normal file
View File

@ -0,0 +1,86 @@
/*
* 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
*
* @return freqMS time between each sample (in microseconds)
* @return numberOfSamples number of sample to sample for this window
* @return 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
*
* @return threshold sample threshold
* @return buffer buffer with samples
* @return len bufer len
*/
int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, unsigned int len);
void printGraph (thresholdContext* ctx);
private:
mraa_aio_context m_micCtx;
};
}

10
src/mic/pyupm_mic.i Normal file
View File

@ -0,0 +1,10 @@
%module pyupm_mic
%include "stdint.i"
%feature("autodoc", "3");
%include "mic.h"
%{
#include "mic.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "mma7455")
set (libdescription "upm MMA7455")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

View File

@ -0,0 +1,7 @@
%module jsupm_mma7455
%{
#include "mma7455.h"
%}
%include "mma7455.h"

176
src/mma7455/mma7455.cxx Normal file
View File

@ -0,0 +1,176 @@
/*
* 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 <string.h>
#include <pthread.h>
#include <math.h>
#include "mma7455.h"
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 = mraa_i2c_init(m_bus);
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 != MRAA_SUCCESS) {
std::cout << "ERROR :: MMA7455 instance wan not created (Mode)" << std::endl;
return;
}
if (MRAA_SUCCESS != calibrate ()) {
std::cout << "ERROR :: MMA7455 instance wan not created (Calibrate)" << std::endl;
return;
}
}
MMA7455::~MMA7455() {
mraa_i2c_stop(m_i2ControlCtx);
}
mraa_result_t
MMA7455::calibrate () {
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 (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 != MRAA_SUCCESS) {
return error;
}
} while ( ++i < 3 );
return error;
}
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 == MRAA_SUCCESS);
if (nBytes == MRAA_SUCCESS) {
std::cout << "NO_GDB :: 1" << std::endl;
return MRAA_SUCCESS;
}*/
nBytes = ic2ReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6);
if (nBytes == 0) {
std::cout << "NO_GDB :: 2" << std::endl;
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;
}
// The result is the g-force in units of 64 per 'g'.
*ptrX = xyz.value.x;
*ptrY = xyz.value.y;
*ptrZ = xyz.value.z;
return MRAA_SUCCESS;
}
int
MMA7455::ic2ReadReg (unsigned char reg, unsigned char * buf, unsigned char size) {
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
if (MRAA_SUCCESS != mraa_i2c_write_byte(m_i2ControlCtx, reg)) {
return 0;
}
if (MRAA_SUCCESS != mraa_i2c_address(m_i2ControlCtx, m_controlAddr)) {
return 0;
}
return (int) mraa_i2c_read(m_i2ControlCtx, buf, size);
}
mraa_result_t
MMA7455::ic2WriteReg (unsigned char reg, unsigned char * buf, unsigned char size) {
mraa_result_t error = MRAA_SUCCESS;
uint8_t data[size + 1];
data[0] = reg;
memcpy(&data[1], buf, size);
error = mraa_i2c_address (m_i2ControlCtx, m_controlAddr);
if (error != MRAA_SUCCESS) {
return error;
}
error = mraa_i2c_write (m_i2ControlCtx, data, size + 1);
if (error != MRAA_SUCCESS) {
return error;
}
return error;
}

223
src/mma7455/mma7455.h Normal file
View File

@ -0,0 +1,223 @@
/*
* 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 0x1D // device address
// Register names according to the datasheet.
// Register 0x1C is sometimes called 'PW', and sometimes 'PD'.
// The two reserved registers can not be used.
#define MMA7455_XOUTL 0x00 // Read only, Output Value X LSB
#define MMA7455_XOUTH 0x01 // Read only, Output Value X MSB
#define MMA7455_YOUTL 0x02 // Read only, Output Value Y LSB
#define MMA7455_YOUTH 0x03 // Read only, Output Value Y MSB
#define MMA7455_ZOUTL 0x04 // Read only, Output Value Z LSB
#define MMA7455_ZOUTH 0x05 // Read only, Output Value Z MSB
#define MMA7455_XOUT8 0x06 // Read only, Output Value X 8 bits
#define MMA7455_YOUT8 0x07 // Read only, Output Value Y 8 bits
#define MMA7455_ZOUT8 0x08 // Read only, Output Value Z 8 bits
#define MMA7455_STATUS 0x09 // Read only, Status Register
#define MMA7455_DETSRC 0x0A // Read only, Detection Source Register
#define MMA7455_TOUT 0x0B // Temperature Output Value (Optional)
#define MMA7455_RESERVED1 0x0C // Reserved
#define MMA7455_I2CAD 0x0D // Read/Write, I2C Device Address
#define MMA7455_USRINF 0x0E // Read only, User Information (Optional)
#define MMA7455_WHOAMI 0x0F // Read only, "Who am I" value (Optional)
#define MMA7455_XOFFL 0x10 // Read/Write, Offset Drift X LSB
#define MMA7455_XOFFH 0x11 // Read/Write, Offset Drift X MSB
#define MMA7455_YOFFL 0x12 // Read/Write, Offset Drift Y LSB
#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_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
#define MMA7455_LDTH 0x1A // Read/Write, Level Detection Threshold Limit Value
#define MMA7455_PDTH 0x1B // Read/Write, Pulse Detection Threshold Limit Value
#define MMA7455_PD 0x1C // Read/Write, Pulse Duration Value
#define MMA7455_LT 0x1D // Read/Write, Latency Time Value (between pulses)
#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
// between bit number and binary definition.
// By using the bit number, programming the MMA7455
// is like programming an AVR microcontroller.
// But instead of using "(1<<X)", or "_BV(X)",
// the Arduino "bit(X)" is used.
#define MMA7455_D0 0
#define MMA7455_D1 1
#define MMA7455_D2 2
#define MMA7455_D3 3
#define MMA7455_D4 4
#define MMA7455_D5 5
#define MMA7455_D6 6
#define MMA7455_D7 7
// Status Register
#define MMA7455_DRDY MMA7455_D0
#define MMA7455_DOVR MMA7455_D1
#define MMA7455_PERR MMA7455_D2
// Mode Control Register
#define MMA7455_MODE0 MMA7455_D0
#define MMA7455_MODE1 MMA7455_D1
#define MMA7455_GLVL0 MMA7455_D2
#define MMA7455_GLVL1 MMA7455_D3
#define MMA7455_STON MMA7455_D4
#define MMA7455_SPI3W MMA7455_D5
#define MMA7455_DRPD MMA7455_D6
// Control 1 Register
#define MMA7455_INTPIN MMA7455_D0
#define MMA7455_INTREG0 MMA7455_D1
#define MMA7455_INTREG1 MMA7455_D2
#define MMA7455_XDA MMA7455_D3
#define MMA7455_YDA MMA7455_D4
#define MMA7455_ZDA MMA7455_D5
#define MMA7455_THOPT MMA7455_D6
#define MMA7455_DFBW MMA7455_D7
// Control 2 Register
#define MMA7455_LDPL MMA7455_D0
#define MMA7455_PDPL MMA7455_D1
#define MMA7455_DRVO MMA7455_D2
// Interrupt Latch Reset Register
#define MMA7455_CLR_INT1 MMA7455_D0
#define MMA7455_CLR_INT2 MMA7455_D1
// Detection Source Register
#define MMA7455_INT1 MMA7455_D0
#define MMA7455_INT2 MMA7455_D1
#define MMA7455_PDZ MMA7455_D2
#define MMA7455_PDY MMA7455_D3
#define MMA7455_PDX MMA7455_D4
#define MMA7455_LDZ MMA7455_D5
#define MMA7455_LDY MMA7455_D6
#define MMA7455_LDX MMA7455_D7
// I2C Device Address Register
#define MMA7455_I2CDIS MMA7455_D7
#define HIGH 1
#define LOW 0
namespace upm {
union accelData {
struct {
unsigned char x_lsb;
unsigned char x_msb;
unsigned char y_lsb;
unsigned char y_msb;
unsigned char z_lsb;
unsigned char z_msb;
} reg;
struct {
short x;
short y;
short z;
} value;
};
#define BIT(n) (1<<n)
/**
* @brief C++ API for MMA7455 chip (accelerometer)
*
* This file defines the MMA7455 C++ interface for libmma7455
*
* @snippet mma7455.cxx Interesting
*
*/
class MMA7455 {
public:
/**
* Instanciates a MMA7455 object
*
* @param bus number of used bus
* @param devAddr addres of used i2c device
*/
MMA7455 (int bus, int devAddr);
/**
* MMA7455 object destructor, basicaly it close i2c connection.
*/
~MMA7455 ();
/**
* Return name of the component
*/
std::string name()
{
return m_name;
}
/**
* Calibrate the sensor
*/
mraa_result_t calibrate ();
/**
* Read X, Y and Z acceleration data
*
* @param ptrX X axis
* @param ptrY Y axis
* @param ptrZ Z axis
*/
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 size buffer 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;
mraa_i2c_context m_i2ControlCtx;
};
}

View File

@ -0,0 +1,8 @@
%module pyupm_mma7455
%feature("autodoc", "3");
%include "mma7455.h"
%{
#include "mma7455.h"
%}

View 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()

View File

@ -0,0 +1,7 @@
%module jsupm_mpu9150
%{
#include "mpu9150.h"
%}
%include "mpu9150.h"

226
src/mpu9150/mpu9150.cxx Normal file
View 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, &regData);
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, &regData);
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, &regData) != 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, &regData) != 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
View 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);
};
}

View File

@ -0,0 +1,10 @@
%module pyupm_mpu9150
%include "stdint.i"
%feature("autodoc", "3");
%include "mpu9150.h"
%{
#include "mpu9150.h"
%}

View File

@ -0,0 +1,5 @@
set (libname "my9221")
set (libdescription "upm ledbar")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

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