Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
88eaced5a2 | |||
b8e1b5850c | |||
e3177c260c | |||
3ed11d7c37 | |||
52198840b8 | |||
cb9d8e2339 | |||
02fb40f058 | |||
cbe211c8cf | |||
94a49a8f36 | |||
2aeb9ddea3 | |||
6d239b9f63 | |||
ee2d398bfa | |||
50fd1d7478 | |||
e7d811e4df | |||
03fa37b130 | |||
b5066c3d55 | |||
30187ba5f9 | |||
4eb6c4e19d | |||
0ea310ac71 | |||
5c4de1b926 | |||
59a66b41bb | |||
d878a5cf1a | |||
428f4e5bfc | |||
050c134664 | |||
ffdd6d2f00 | |||
044037b892 | |||
ad87704c19 | |||
00114f69d2 | |||
c99821ad26 | |||
a9939d6352 | |||
5ed36a37f9 | |||
03b9cf89a0 | |||
9c9b273b5a | |||
586acf7502 | |||
d0e83d7076 | |||
1747fbbe19 | |||
45f85e9944 | |||
b31e88c233 | |||
58b80f6b58 | |||
574a39d3c1 | |||
bb38b35b32 | |||
d15bf22536 | |||
731704eaac | |||
00170bea97 | |||
8cfb3d3dab | |||
d2e2682f0e | |||
22ad93956c | |||
86a3be4517 | |||
8a67c143bf | |||
7dc8ec6244 | |||
0d544dadeb | |||
9f66c10b26 | |||
2822d63c9c | |||
0954617a4b | |||
36be22cb90 | |||
8d25ecacdd | |||
739d4e23e8 | |||
81c8baa071 | |||
2fa9b7b6c9 | |||
b1e548ae8a | |||
d00500ba12 | |||
2c0e83e406 | |||
b03cbf4f36 | |||
b291f372d7 | |||
8d8485be82 | |||
b4f25c84a5 | |||
4c7fa11bb2 | |||
c18a9433fc | |||
8fe679494c | |||
2c1baf66b5 | |||
3e12ed6719 | |||
e24df89ebd | |||
186dd03b79 | |||
0050f92b06 | |||
058c40e340 | |||
cea5816c43 | |||
54a4afc6a7 | |||
1dd8626044 | |||
1c138d9167 | |||
3dccffe055 | |||
34e343869c | |||
d71e4e5dc2 | |||
7e3358b586 | |||
ca0b0cce44 | |||
12b2ab6991 |
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
cmake_minimum_required (VERSION 2.8.11)
|
||||
project (upm)
|
||||
|
||||
find_package (SWIG)
|
||||
@ -8,9 +8,9 @@ endif ()
|
||||
|
||||
find_package (Threads REQUIRED)
|
||||
find_package (PkgConfig REQUIRED)
|
||||
# force the libmaa version to be the required version
|
||||
pkg_check_modules (MAA REQUIRED maa>=0.2.6)
|
||||
message (INFO " found libmaa version: ${MAA_VERSION}")
|
||||
# force the libmraa version to be the required version
|
||||
pkg_check_modules (MRAA REQUIRED mraa>=0.4.0)
|
||||
message (INFO " found libmraa version: ${MRAA_VERSION}")
|
||||
|
||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||
@ -19,8 +19,8 @@ set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_
|
||||
include (GetGitRevisionDescription)
|
||||
git_describe (VERSION "--tags")
|
||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND")
|
||||
message (WARNING " - Install git to compile a production libmaa!")
|
||||
set (VERSION "v0.1.2-dirty")
|
||||
message (WARNING " - Install git to compile a production libmraa!")
|
||||
set (VERSION "v0.1.8-dirty")
|
||||
endif ()
|
||||
|
||||
message (INFO " - UPM Version ${VERSION}")
|
||||
@ -39,22 +39,28 @@ endif()
|
||||
set (upm_VERSION_MAJOR ${VERSION_MAJOR})
|
||||
set (upm_VERSION_MINOR ${VERSION_MINOR})
|
||||
set (upm_VERSION_PATCH ${VERSION_PATCH})
|
||||
set (upm_VERSION_STRING ${maa_VERSION_MAJOR}.${maa_VERSION_MINOR}.${maa_VERSION_PATCH})
|
||||
set (upm_VERSION_STRING ${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH})
|
||||
|
||||
set (CMAKE_SWIG_FLAGS "")
|
||||
|
||||
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)
|
||||
|
||||
# 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)
|
||||
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)
|
||||
@ -75,7 +81,7 @@ if (IPK)
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DETECTED_ARCH})
|
||||
set(CPACK_SYSTEM_NAME ${DETECTED_ARCH})
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmaa0 (>= ${MAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmraa0 (>= ${MRAA_VERSION})")
|
||||
set(CPACK_DEBIAN_PACKAGE_PROVIDES "upm-dev, upm-dbg, upm-doc")
|
||||
set(CPACK_DEBIAN_PACKAGE_REPLACES ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
set(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_DEBIAN_PACKAGE_PROVIDES})
|
||||
|
25
Doxyfile.in
@ -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
|
||||
@ -99,7 +99,7 @@ BRIEF_MEMBER_DESC = YES
|
||||
# brief descriptions will be completely suppressed.
|
||||
# The default value is: YES.
|
||||
|
||||
REPEAT_BRIEF = YES
|
||||
REPEAT_BRIEF = NO
|
||||
|
||||
# This tag implements a quasi-intelligent brief description abbreviator that is
|
||||
# used to form the text in various listings. Each string in this list, if found
|
||||
@ -129,6 +129,8 @@ ABBREVIATE_BRIEF = "The $name class" \
|
||||
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
|
||||
DETAILS_AT_TOP = YES
|
||||
|
||||
# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
|
||||
# inherited members of a class in the documentation of that class as if those
|
||||
# members were ordinary class members. Constructors, destructors and assignment
|
||||
@ -510,7 +512,7 @@ HIDE_SCOPE_NAMES = YES
|
||||
# the files that are included by a file in the documentation of that file.
|
||||
# The default value is: YES.
|
||||
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
SHOW_INCLUDE_FILES = NO
|
||||
|
||||
# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
|
||||
# grouped member an include statement to the documentation, telling the reader
|
||||
@ -536,7 +538,7 @@ INLINE_INFO = YES
|
||||
# name. If set to NO the members will appear in declaration order.
|
||||
# The default value is: YES.
|
||||
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_MEMBER_DOCS = NO
|
||||
|
||||
# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
|
||||
# descriptions of file, namespace and class members alphabetically by member
|
||||
@ -671,7 +673,7 @@ FILE_VERSION_FILTER =
|
||||
# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
|
||||
# tag is left empty.
|
||||
|
||||
LAYOUT_FILE =
|
||||
LAYOUT_FILE = @CMAKE_CURRENT_SOURCE_DIR@/DoxygenLayout.xml
|
||||
|
||||
# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
|
||||
# the reference definitions. This must be a list of .bib files. The .bib
|
||||
@ -754,6 +756,7 @@ WARN_LOGFILE =
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
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
|
||||
@ -846,7 +849,9 @@ EXCLUDE_SYMLINKS = NO
|
||||
# Note that the wildcards are matched against the file with absolute path, so to
|
||||
# exclude all test directories for example use the pattern */test/*
|
||||
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_PATTERNS = @PROJECT_SOURCE_DIR@/src/nrf8001/aci* \
|
||||
@PROJECT_SOURCE_DIR@/src/nrf8001/lib* \
|
||||
@PROJECT_SOURCE_DIR@/src/nrf8001/hal*
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
@ -863,7 +868,9 @@ EXCLUDE_SYMBOLS =
|
||||
# that contain example code fragments that are included (see the \include
|
||||
# command).
|
||||
|
||||
EXAMPLE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/examples/
|
||||
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
|
||||
@ -883,7 +890,7 @@ EXAMPLE_RECURSIVE = NO
|
||||
# that contain images that are to be included in the documentation (see the
|
||||
# \image command).
|
||||
|
||||
IMAGE_PATH =
|
||||
IMAGE_PATH = @CMAKE_CURRENT_SOURCE_DIR@/docs/images/
|
||||
|
||||
# The INPUT_FILTER tag can be used to specify a program that doxygen should
|
||||
# invoke to filter for each input file. Doxygen will invoke the filter program
|
||||
@ -2206,7 +2213,7 @@ INCLUDE_GRAPH = YES
|
||||
# The default value is: YES.
|
||||
# This tag requires that the tag HAVE_DOT is set to YES.
|
||||
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = NO
|
||||
|
||||
# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
|
||||
# dependency graph for every global function or class method.
|
||||
|
194
DoxygenLayout.xml
Normal file
@ -0,0 +1,194 @@
|
||||
<doxygenlayout version="1.0">
|
||||
<!-- Generated by doxygen 1.8.7 -->
|
||||
<!-- Navigation index tabs for HTML output -->
|
||||
<navindex>
|
||||
<tab type="mainpage" visible="yes" title=""/>
|
||||
<tab type="pages" visible="yes" title="" intro=""/>
|
||||
<tab type="modules" visible="yes" title="" intro=""/>
|
||||
<tab type="namespaces" visible="yes" title="">
|
||||
<tab type="namespacelist" visible="yes" title="" intro=""/>
|
||||
<tab type="namespacemembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="classes" visible="yes" title="">
|
||||
<tab type="classlist" visible="yes" title="" intro=""/>
|
||||
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="hierarchy" visible="yes" title="" intro=""/>
|
||||
<tab type="classmembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="files" visible="yes" title="">
|
||||
<tab type="filelist" visible="yes" title="" intro=""/>
|
||||
<tab type="globals" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="examples" visible="yes" title="" intro=""/>
|
||||
</navindex>
|
||||
|
||||
<!-- Layout definition for a class page -->
|
||||
<class>
|
||||
<briefdescription visible="yes"/>
|
||||
<detaileddescription title=""/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<memberdecl>
|
||||
<nestedclasses visible="yes" title=""/>
|
||||
<publictypes title=""/>
|
||||
<services title=""/>
|
||||
<interfaces title=""/>
|
||||
<publicslots title=""/>
|
||||
<signals title=""/>
|
||||
<publicmethods title=""/>
|
||||
<publicstaticmethods title=""/>
|
||||
<publicattributes title=""/>
|
||||
<publicstaticattributes title=""/>
|
||||
<protectedtypes title=""/>
|
||||
<protectedslots title=""/>
|
||||
<protectedmethods title=""/>
|
||||
<protectedstaticmethods title=""/>
|
||||
<protectedattributes title=""/>
|
||||
<protectedstaticattributes title=""/>
|
||||
<packagetypes title=""/>
|
||||
<packagemethods title=""/>
|
||||
<packagestaticmethods title=""/>
|
||||
<packageattributes title=""/>
|
||||
<packagestaticattributes title=""/>
|
||||
<properties title=""/>
|
||||
<events title=""/>
|
||||
<privatetypes title=""/>
|
||||
<privateslots title=""/>
|
||||
<privatemethods title=""/>
|
||||
<privatestaticmethods title=""/>
|
||||
<privateattributes title=""/>
|
||||
<privatestaticattributes title=""/>
|
||||
<friends title=""/>
|
||||
<related title="" subtitle=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<memberdef>
|
||||
<inlineclasses title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<services title=""/>
|
||||
<interfaces title=""/>
|
||||
<constructors title=""/>
|
||||
<functions title=""/>
|
||||
<related title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
<events title=""/>
|
||||
</memberdef>
|
||||
<allmemberslink visible="yes"/>
|
||||
<inheritancegraph visible="$CLASS_GRAPH"/>
|
||||
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
|
||||
<usedfiles visible="$SHOW_USED_FILES"/>
|
||||
<authorsection visible="yes"/>
|
||||
</class>
|
||||
|
||||
<!-- Layout definition for a namespace page -->
|
||||
<namespace>
|
||||
<briefdescription visible="yes"/>
|
||||
<memberdecl>
|
||||
<nestednamespaces visible="yes" title=""/>
|
||||
<constantgroups visible="yes" title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdef>
|
||||
<inlineclasses title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="yes"/>
|
||||
</namespace>
|
||||
|
||||
<!-- Layout definition for a file page -->
|
||||
<file>
|
||||
<briefdescription visible="no"/>
|
||||
<includegraph visible="$INCLUDE_GRAPH"/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<detaileddescription title="API Description"/>
|
||||
<sourcelink visible="yes"/>
|
||||
<memberdecl>
|
||||
<classes visible="yes" title=""/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<functions title=""/>
|
||||
<constantgroups visible="yes" title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<variables title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<memberdef>
|
||||
<inlineclasses title=""/>
|
||||
<functions title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<variables title=""/>
|
||||
</memberdef>
|
||||
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
|
||||
<authorsection/>
|
||||
</file>
|
||||
|
||||
<!-- Layout definition for a group page -->
|
||||
<group>
|
||||
<briefdescription visible="yes"/>
|
||||
<groupgraph visible="$GROUP_GRAPHS"/>
|
||||
<memberdecl>
|
||||
<nestedgroups visible="yes" title=""/>
|
||||
<dirs visible="yes" title=""/>
|
||||
<files visible="yes" title=""/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<classes visible="yes" title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<enumvalues title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<signals title=""/>
|
||||
<publicslots title=""/>
|
||||
<protectedslots title=""/>
|
||||
<privateslots title=""/>
|
||||
<events title=""/>
|
||||
<properties title=""/>
|
||||
<friends title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdef>
|
||||
<pagedocs/>
|
||||
<inlineclasses title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title=""/>
|
||||
<enumvalues title=""/>
|
||||
<functions title=""/>
|
||||
<variables title=""/>
|
||||
<signals title=""/>
|
||||
<publicslots title=""/>
|
||||
<protectedslots title=""/>
|
||||
<privateslots title=""/>
|
||||
<events title=""/>
|
||||
<properties title=""/>
|
||||
<friends title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="yes"/>
|
||||
</group>
|
||||
|
||||
<!-- Layout definition for a directory page -->
|
||||
<directory>
|
||||
<briefdescription visible="yes"/>
|
||||
<directorygraph visible="yes"/>
|
||||
<memberdecl>
|
||||
<dirs visible="yes"/>
|
||||
<files visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
</directory>
|
||||
</doxygenlayout>
|
76
README.md
@ -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,71 @@ 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
|
||||
### Supported Sensors
|
||||
|
||||
Temperature Sensors:
|
||||
* upm::MAX31723
|
||||
* upm::MAX31855
|
||||
* upm::TH02
|
||||
* upm::GroveTemp
|
||||
|
||||
Compass/Gyro/Magnometer Sensors:
|
||||
* upm::Hmc5883l
|
||||
* upm::MPU9150
|
||||
|
||||
Atmospheric Pressure Sensors:
|
||||
* upm::GY65
|
||||
|
||||
Light/Proximity Sensors:
|
||||
* upm::MAXDS3231M
|
||||
* upm::MAX44000
|
||||
* upm::HCSR04
|
||||
* upm::GroveLight
|
||||
|
||||
Gas Sensors:
|
||||
* upm::MQ2
|
||||
* upm::MQ3
|
||||
* upm::MQ5
|
||||
* upm::MQ9
|
||||
|
||||
Displays:
|
||||
* upm::Jhd1313m1
|
||||
* upm::Lcm1602
|
||||
* upm::ST7735
|
||||
* upm::SSD1308
|
||||
* upm::SSD1327
|
||||
|
||||
LED controllers/segment displays:
|
||||
* upm::TM1637
|
||||
* upm::MY9221
|
||||
|
||||
RFID:
|
||||
* upm::SM130
|
||||
|
||||
Wireless Communication:
|
||||
* upm::NRF24l01
|
||||
|
||||
Servo/motors:
|
||||
* upm::ES08A
|
||||
* upm::StepMotor
|
||||
|
||||
Digital potentiometer
|
||||
* upm::MAX5487
|
||||
|
||||
### Building UPM
|
||||
|
||||
See @ref building
|
||||
|
||||
### Making your own UPM module
|
||||
|
||||
@ref porting has more information on making new UPM modules
|
||||
|
||||
|
27
TODO
Normal file
@ -0,0 +1,27 @@
|
||||
Easy:
|
||||
MAX7221 - SPI 8 digit LED
|
||||
- https://mbed.org/components/MAX7221/
|
||||
-
|
||||
SCA61T - inclinometer SPI
|
||||
- https://mbed.org/components/SCA61T-Inclinometer/
|
||||
DS1721 - i2c temperature/thermostat
|
||||
- https://mbed.org/components/DS1721/
|
||||
MPL3115A2 - i2c altimeter
|
||||
- https://mbed.org/components/MPL3115A2/
|
||||
- http://www.ebay.co.uk/itm/Barometric-Pressure-Altitude-Temperature-Sensor-I2C-MPL3115A2-/221499210102?pt=UK_BOI_Electrical_Test_Measurement_Equipment_ET&hash=item339261b976
|
||||
TEMT6200 - Ambient light sensor
|
||||
- https://mbed.org/components/TEMT6200/
|
||||
CMPS03 - i2c digital compass
|
||||
- https://mbed.org/components/CMPS03-Digital-Compass/
|
||||
- http://www.ebay.co.uk/itm/Magnetic-Compass-CMPS03-/221437925374?pt=UK_BOI_Electrical_Test_Measurement_Equipment_ET&hash=item338eba97fe
|
||||
- http://www.robot-italy.com/it/cmps03-robot-compass-module.html
|
||||
|
||||
Medium
|
||||
E-ink sharp 1.3" LCD
|
||||
- https://mbed.org/components/13-SHARP-Memory-LCD/
|
||||
LCD-S401
|
||||
- https://mbed.org/components/Lumex-LCD-S401/
|
||||
|
||||
Hard:
|
||||
RA8875 - 480x272 SPI 4 wire
|
||||
- https://mbed.org/components/RA8875-Based-Display/
|
59
docs/building.md
Normal file
@ -0,0 +1,59 @@
|
||||
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
|
||||
|
||||
Often developers are only interested in building one module or even just the
|
||||
python/node module to do some quick testing using scripting. In order to do
|
||||
this you need to use the target name for the python or node module you want to
|
||||
rebuild. For example the lcd module target name is i2clcd. Therfore the python
|
||||
module target name will be prefixed by _pyupm_. Just do the following to build
|
||||
only that module. Modules not using the UPM cmake macros may have different
|
||||
naming.
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
make _pyupm_i2clcd
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Sometimes you want to build a small C++ example against an installed library.
|
||||
This is fairly easy if installed systemwide. Just link against the correct
|
||||
librar (in this case libupm-tm1637) and then add /usr/include/upm to the loader
|
||||
path:
|
||||
|
||||
~~~~~~~~~~~~
|
||||
g++ test.cxx -lupm_tm1637 -I/usr/include/upm
|
||||
~~~~~~~~~~~~
|
||||
|
||||
You can also use pkg-config to return the information to you, which is
|
||||
considered the correct way if including UPM in a build system like cmake or
|
||||
autotools on linux.
|
||||
|
||||
~~~~~~~~~~~
|
||||
pkg-config --cflags --libs upm-tm1637
|
||||
~~~~~~~~~~~
|
34
docs/contributions.md
Normal file
@ -0,0 +1,34 @@
|
||||
Contributing a module {#contributions}
|
||||
=====================
|
||||
|
||||
Here are the rules of contribution:
|
||||
- Your module must have an example that builds against your UPM library
|
||||
- Commits must have a sign-off line by everyone who reviewed them
|
||||
- Commits must be named <file/module>: Some decent description
|
||||
- You must license your module under a FOSS license. The recommended license
|
||||
is MIT but any permissive license is fine. Please consider that people using
|
||||
UPM may want to write proprietary programs with your sensors so we like to
|
||||
avoid GPL. (LGPL is fine). If your license is not MIT please include a
|
||||
LICENSE file in src/mymodule/
|
||||
- Please test your module builds before contributing and make sure it works on
|
||||
the latest version of mraa. If you tested on a specific board/platform please
|
||||
tell us what this was in your PR.
|
||||
- Try not to break master. In any commit.
|
||||
- Attempt to have some decent API documentation below are the explicit rules on documentation:
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
- Try to have no warnings in doxygen, this is generally fairly easy
|
||||
- Have the specific sensor manufacturer/model & version that you used, if you
|
||||
support multiple versions please list
|
||||
- Comments do not need full stops
|
||||
- Stick to <80 chars per line even in comments
|
||||
- No text is allowed on the same line as the start or end of a comment /** */
|
||||
- All classes should have a "@brief" and a "@snippet"
|
||||
|
||||
The example should have an 'Interesting' section which will be highlighted as a
|
||||
code sample in doxygen. Everything in between such tags will show up in the
|
||||
class documentation when the following is put at the end of a class docstring
|
||||
as show above.
|
||||
|
BIN
docs/images/grovegas.jpeg
Normal file
After Width: | Height: | Size: 131 KiB |
BIN
docs/images/grovergblcd.jpeg
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
docs/images/lcm1602.jpeg
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
docs/images/lpd8806.jpeg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
docs/images/max31723.jpeg
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
docs/images/max31855.jpeg
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
docs/images/max44000.jpeg
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
docs/images/max5487.jpeg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
docs/images/mq9.jpeg
Normal file
After Width: | Height: | Size: 9.7 KiB |
BIN
docs/images/ssd1308.jpeg
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
docs/images/ssd1327.jpeg
Normal file
After Width: | Height: | Size: 62 KiB |
97
docs/max31855.md
Normal file
@ -0,0 +1,97 @@
|
||||
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. The upm.i is just a shortcut to include some commonly
|
||||
used swig wrappers for UPM sensors, it's not obligatory but recommended.
|
||||
|
||||
### 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
@ -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
@ -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 contributions and on
|
||||
https://help.github.com/articles/creating-a-pull-request
|
||||
|
@ -13,17 +13,57 @@ 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)
|
||||
add_executable (maxds3231m-example maxds3231m.cxx)
|
||||
add_executable (max31723-example max31723.cxx)
|
||||
add_executable (max5487-example max5487.cxx)
|
||||
add_executable (nrf8001-broadcast-example nrf8001_broadcast.cxx)
|
||||
add_executable (nrf8001-helloworld-example nrf8001_helloworld.cxx)
|
||||
add_executable (lpd8806-example lpd8806-example.cxx)
|
||||
add_executable (mlx90614-example mlx90614-example.cxx)
|
||||
add_executable (ecs1030-example ecs1030-example.cxx)
|
||||
add_executable (mq2-example mq2-example.cxx)
|
||||
add_executable (mq3-example mq3-example.cxx)
|
||||
add_executable (mq5-example mq5-example.cxx)
|
||||
add_executable (mq9-example mq9-example.cxx)
|
||||
add_executable (tcs3414cs-example tcs3414cs-example.cxx)
|
||||
add_executable (th02-example th02-example.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
|
||||
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)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max31723)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/max5487)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf8001)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/lpd8806)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mlx90614)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ecs1030)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/gas)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/tcs3414cs)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/th02)
|
||||
|
||||
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -31,8 +71,8 @@ target_link_libraries (grovetemp grove ${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 ledbar ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (seg-lcd 4digitdisplay ${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})
|
||||
@ -40,3 +80,25 @@ 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})
|
||||
target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (max5487-example max5487 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-broadcast-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nrf8001-helloworld-example nrf8001 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (lpd8806-example lpd8806 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mlx90614-example mlx90614 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ecs1030-example ecs1030 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq2-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq3-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq5-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mq9-example gas ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (tcs3414cs-example tcs3414cs ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (th02-example th02 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
@ -25,20 +25,8 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
@ -51,13 +39,10 @@ main(int argc, char **argv) {
|
||||
std::cout << sound->name() << std::endl;
|
||||
// play sound (DO, RE, ME, etc...)
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
|
||||
std::cout << sound->playSound(chord[chord_ind]) << std::endl;
|
||||
usleep(1000);
|
||||
}
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||
// play one second for each chord
|
||||
std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
|
61
examples/ecs1030-example.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include "ecs1030.h"
|
||||
|
||||
int is_running = 0;
|
||||
upm::ECS1030 *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::ECS1030(0);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!is_running) {
|
||||
std::cout << "I = " << sensor->getCurrency_A () << ", Power = " << sensor->getPower_A () << std::endl;
|
||||
std::cout << "I = " << sensor->getCurrency_B () << ", Power = " << sensor->getPower_B () << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
@ -28,40 +28,19 @@
|
||||
#include <signal.h>
|
||||
#include <stdlib.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::ES08A *servo = new upm::ES08A(5);
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
int clock = 0;
|
||||
while (!running) {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
servo->setAngle (clock);
|
||||
clock += 10;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
servo->setAngle (clock);
|
||||
clock -= 10;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
@ -29,7 +29,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Use i2c device 0 all the time
|
||||
//! [Interesting]
|
||||
upm::GroveLed* led = new upm::GroveLed(2);
|
||||
std::cout << led->name() << std::endl;
|
||||
for (int i=0; i < 10; i++) {
|
||||
@ -38,6 +38,7 @@ main(int argc, char **argv)
|
||||
led->off();
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
40
examples/grovelight.cxx
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "grove.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// This example uses AIO 0
|
||||
//! [Interesting]
|
||||
upm::GroveLight* light = new upm::GroveLight(0);
|
||||
int lightValue = light->value();
|
||||
|
||||
delete light;
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
@ -29,13 +29,14 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
// Use i2c device 0 all the time
|
||||
//! [Interesting]
|
||||
upm::GroveTemp* s = new upm::GroveTemp(0);
|
||||
std::cout << s->name() << std::endl;
|
||||
for (int i=0; i < 10; i++) {
|
||||
std::cout << s->value() << std::endl;
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
77
examples/gy65.cxx
Normal 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;
|
||||
}
|
@ -43,7 +43,7 @@ sig_handler(int signo)
|
||||
|
||||
//! [Interesting]
|
||||
void
|
||||
interrupt (void) {
|
||||
interrupt (void * args) {
|
||||
sonar->ackEdgeDetected ();
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,11 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
|
||||
lcd->setCursor(0,0);
|
||||
lcd->write("Hello World");
|
||||
//! [Interesting]
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->setCursor(2,4);
|
||||
|
104
examples/lpd8806-example.cxx
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 "lpd8806.h"
|
||||
#include <signal.h>
|
||||
|
||||
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
|
||||
|
||||
int doWork = 0;
|
||||
upm::LPD8806 *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::LPD8806(10, 7);
|
||||
usleep (1000000);
|
||||
|
||||
sensor->show ();
|
||||
|
||||
while (!doWork) {
|
||||
// Back-and-forth lights
|
||||
scanner(127, 0, 0, 30); // red, slow
|
||||
scanner(0, 0, 127, 15); // blue, fast
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait) {
|
||||
int i, j, pos, dir;
|
||||
|
||||
pos = 0;
|
||||
dir = 1;
|
||||
|
||||
for(i=0; i < ((sensor->getStripLength() - 1) * 8); i++) {
|
||||
// Draw 5 pixels centered on pos. setPixelColor() will clip
|
||||
// any pixels off the ends of the strip, no worries there.
|
||||
// we'll make the colors dimmer at the edges for a nice pulse
|
||||
// look
|
||||
sensor->setPixelColor(pos - 2, r/4, g/4, b/4);
|
||||
sensor->setPixelColor(pos - 1, r/2, g/2, b/2);
|
||||
sensor->setPixelColor(pos, r, g, b);
|
||||
sensor->setPixelColor(pos + 1, r/2, g/2, b/2);
|
||||
sensor->setPixelColor(pos + 2, r/4, g/4, b/4);
|
||||
|
||||
sensor->show();
|
||||
usleep (wait * 1000);
|
||||
// If we wanted to be sneaky we could erase just the tail end
|
||||
// pixel, but it's much easier just to erase the whole thing
|
||||
// and draw a new one next time.
|
||||
for(j=-2; j<= 2; j++) {
|
||||
sensor->setPixelColor(pos+j, 0,0,0);
|
||||
}
|
||||
// Bounce off ends of strip
|
||||
pos += dir;
|
||||
if(pos < 0) {
|
||||
pos = 1;
|
||||
dir = -dir;
|
||||
} else if (pos >= sensor->getStripLength()) {
|
||||
pos = sensor->getStripLength() - 2;
|
||||
dir = -dir;
|
||||
}
|
||||
}
|
||||
}
|
61
examples/max31723.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "max31723.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAX31723 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX31723(7);
|
||||
usleep (1000000);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
41
examples/max31855.cxx
Normal 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]
|
66
examples/max5487.cxx
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "max5487.h"
|
||||
#include <signal.h>
|
||||
|
||||
upm::MAX5487 *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
sensor = new upm::MAX5487(7);
|
||||
|
||||
// Power LED UP
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
// Power LED DOWN
|
||||
for (int i = 0; i < 255; i++) {
|
||||
sensor->setWiperA(255 - i);
|
||||
usleep (5000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
75
examples/maxds3231m.cxx
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "maxds3231m.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MAXDS3231M *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Time3231 t;
|
||||
sensor = new upm::MAXDS3231M(0, ADDR);
|
||||
|
||||
t.second = 1;
|
||||
t.minute = 3;
|
||||
t.hour = 3;
|
||||
t.day = 3;
|
||||
t.month = 3;
|
||||
t.year = 3;
|
||||
t.weekDay = 3;
|
||||
sensor->setDate (t); // Note, second should be set to 1.
|
||||
|
||||
usleep (500000);
|
||||
|
||||
while (!doWork) {
|
||||
if (sensor->getDate (t)) {
|
||||
std::cout << (int)t.hour << ":" << (int)t.minute << ":" << (int)t.second << std::endl;
|
||||
}
|
||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
74
examples/mic-example.cxx
Normal file
@ -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]
|
60
examples/mlx90614-example.cxx
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 "mlx90614.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::MLX90614 *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::MLX90614(0, DEVICE_ADDR);
|
||||
|
||||
while (!doWork) {
|
||||
std::cout << "Object Temperature (" << sensor->readObjectTempC() << ") Ambient Temperature (" << sensor->readAmbientTempC() << ")" << std::endl;
|
||||
usleep (1000000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
64
examples/mma7455.cxx
Normal 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;
|
||||
}
|
59
examples/mpu9150-example.cxx
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mpu9150.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::Vector3D data;
|
||||
upm::MPU9150 *sensor = new upm::MPU9150(0, ADDR);
|
||||
sensor->getData ();
|
||||
sensor->getAcceleromter (&data);
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "DEVICE ID (" << (int) sensor->getDeviceID () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
std::cout << "ACCELEROMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getGyro (&data);
|
||||
std::cout << "GYRO :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
|
||||
sensor->getMagnometer (&data);
|
||||
std::cout << "MAGNOMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
|
||||
<< " Z (" << data.axisZ << ")" << std::endl;
|
||||
std::cout << "TEMPERATURE (" << sensor->getTemperature () << ")" << std::endl;
|
||||
std::cout << "*************************************************" << std::endl;
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
74
examples/mq2-example.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mq2.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ2 *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::MQ2(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, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
74
examples/mq3-example.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mq3.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ3 *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::MQ3(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, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
74
examples/mq5-example.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mq5.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ5 *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::MQ5(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, 7);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
74
examples/mq9-example.cxx
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "mq9.h"
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int is_running = 0;
|
||||
uint16_t buffer [128];
|
||||
upm::MQ9 *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::MQ9(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, 5);
|
||||
if (thresh) {
|
||||
// do something ....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
177
examples/nrf8001_broadcast.cxx
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf8001.h"
|
||||
#include "nrf8001_broadcast.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
if (lib_aci_event_get (&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup\n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby\n");
|
||||
lib_aci_broadcast(10/* in seconds */, 0x0100 /* advertising interval 100ms */);
|
||||
printf ("Broadcasting started\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; //ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
printf ("ACI_EVT_CMD_RSP\n");
|
||||
while (1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
|
||||
printf ("Broadcasting timed out\n");
|
||||
} else {
|
||||
printf ("Evt Disconnected. Link Loss\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
printf ("ACI_EVT_DATA_RECEIVED\n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
93
examples/nrf8001_broadcast.h
Normal file
@ -0,0 +1,93 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define PIPE_GAP_DEVICE_NAME_SET 1
|
||||
|
||||
#define NUMBER_OF_PIPES 1
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0xffff /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xffff /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific maximum*/
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xffff /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 13
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x03,0x02,0x41,0xd7,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x06,0x00,0x01,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x64,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x38,0x02,0xff,0x02,0x58,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x05,0x06,0x10,0x54,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x0e,0x03,0x00,0x00,0x2a,0x04,0x14,0x0b,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x62,0x63,0x61,0x73,0x74,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x04,0x04,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,0x00,0x05,0x2a,0x01,0x01,0x00,0x00,0x04,0x04,\
|
||||
0x05,0x05,0x00,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,0x04,0x01,0xff,0xff,0xff,0xff,0x00,0x00,0xff,\
|
||||
0xff,0x04,0x04,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x04,0x06,0x20,0x70,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x0d,0x06,0x40,0x00,0x2a,0x00,0x01,0x00,0x80,0x04,0x00,0x03,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0x60,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x03,0x4c,0xf2,\
|
||||
},\
|
||||
},\
|
||||
}
|
362
examples/nrf8001_helloworld.cxx
Normal file
@ -0,0 +1,362 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "nrf8001.h"
|
||||
#include "nrf8001_helloworld.h"
|
||||
#include <lib_aci.h>
|
||||
#include <aci_setup.h>
|
||||
#include <signal.h>
|
||||
#include "uart_over_ble.h"
|
||||
|
||||
/*
|
||||
* You can use the nRF UART app in the Apple iOS app store and Google Play for Android 4.3 for Samsung Galaxy S4
|
||||
* with this helloworld application
|
||||
*/
|
||||
|
||||
#ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
|
||||
static services_pipe_type_mapping_t
|
||||
services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
|
||||
#else
|
||||
#define NUMBER_OF_PIPES 0
|
||||
static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Store the setup for the nRF8001 in the flash of the AVR to save on RAM
|
||||
*/
|
||||
static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
|
||||
|
||||
/**
|
||||
* aci_struct that will contain
|
||||
* total initial credits
|
||||
* current credit
|
||||
* current state of the aci (setup/standby/active/sleep)
|
||||
* open remote pipe pending
|
||||
* close remote pipe pending
|
||||
* Current pipe available bitmap
|
||||
* Current pipe closed bitmap
|
||||
* Current connection interval, slave latency and link supervision timeout
|
||||
* Current State of the the GATT client (Service Discovery)
|
||||
* Status of the bond (R) Peer address
|
||||
*/
|
||||
static struct aci_state_t aci_state;
|
||||
|
||||
/**
|
||||
* Temporary buffers for sending ACI commands
|
||||
*/
|
||||
static hal_aci_evt_t aci_data;
|
||||
|
||||
/*
|
||||
Timing change state variable
|
||||
*/
|
||||
static bool timing_change_done = false;
|
||||
|
||||
/*
|
||||
Used to test the UART TX characteristic notification
|
||||
*/
|
||||
static uart_over_ble_t uart_over_ble;
|
||||
static uint8_t uart_buffer[20];
|
||||
static uint8_t uart_buffer_len = 0;
|
||||
static uint8_t dummychar = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_aci_setup () {
|
||||
/**
|
||||
* Point ACI data structures to the the setup data that the nRFgo studio generated for the nRF8001
|
||||
*/
|
||||
if (NULL != services_pipe_type_mapping) {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
|
||||
} else {
|
||||
aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
|
||||
}
|
||||
|
||||
aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
|
||||
aci_state.aci_setup_info.setup_msgs = setup_msgs;
|
||||
aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
|
||||
}
|
||||
|
||||
void
|
||||
uart_over_ble_init (void) {
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_tx (uint8_t *buffer, uint8_t buffer_len) {
|
||||
bool status = false;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) &&
|
||||
(aci_state.data_credit_available >= 1)) {
|
||||
status = lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, buffer, buffer_len);
|
||||
if (status) {
|
||||
aci_state.data_credit_available--;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool
|
||||
uart_process_control_point_rx(uint8_t *byte, uint8_t length) {
|
||||
bool status = false;
|
||||
aci_ll_conn_params_t *conn_params;
|
||||
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX) ) {
|
||||
switch (*byte) {
|
||||
/*
|
||||
Queues a ACI Disconnect to the nRF8001 when this packet is received.
|
||||
May cause some of the UART packets being sent to be dropped
|
||||
*/
|
||||
case UART_OVER_BLE_DISCONNECT:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
lib_aci_disconnect(&aci_state, ACI_REASON_TERMINATE);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Queues an ACI Change Timing to the nRF8001
|
||||
*/
|
||||
case UART_OVER_BLE_LINK_TIMING_REQ:
|
||||
/*
|
||||
Parameters:
|
||||
Connection interval min: 2 bytes
|
||||
Connection interval max: 2 bytes
|
||||
Slave latency: 2 bytes
|
||||
Timeout: 2 bytes
|
||||
Same format as Peripheral Preferred Connection Parameters (See nRFgo studio -> nRF8001 Configuration -> GAP Settings
|
||||
Refer to the ACI Change Timing Request in the nRF8001 Product Specifications
|
||||
*/
|
||||
conn_params = (aci_ll_conn_params_t *)(byte+1);
|
||||
lib_aci_change_timing( conn_params->min_conn_interval,
|
||||
conn_params->max_conn_interval,
|
||||
conn_params->slave_latency,
|
||||
conn_params->timeout_mult);
|
||||
status = true;
|
||||
break;
|
||||
|
||||
/*
|
||||
Clears the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_STOP:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = false;
|
||||
status = true;
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
Set the RTS of the UART over BLE
|
||||
*/
|
||||
case UART_OVER_BLE_TRANSMIT_OK:
|
||||
/*
|
||||
Parameters:
|
||||
None
|
||||
*/
|
||||
uart_over_ble.uart_rts_local = true;
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
|
||||
init_aci_setup ();
|
||||
init_local_interfaces (&aci_state, 10, 8, 4);
|
||||
|
||||
while (1) {
|
||||
static bool setup_required = false;
|
||||
|
||||
// We enter the if statement only when there is a ACI event available to be processed
|
||||
if (lib_aci_event_get(&aci_state, &aci_data)) {
|
||||
aci_evt_t * aci_evt;
|
||||
aci_evt = &aci_data.evt;
|
||||
switch(aci_evt->evt_opcode) {
|
||||
/**
|
||||
As soon as you reset the nRF8001 you will get an ACI Device Started Event
|
||||
*/
|
||||
case ACI_EVT_DEVICE_STARTED: {
|
||||
aci_state.data_credit_total = aci_evt->params.device_started.credit_available;
|
||||
switch(aci_evt->params.device_started.device_mode) {
|
||||
case ACI_DEVICE_SETUP:
|
||||
/**
|
||||
When the device is in the setup mode
|
||||
*/
|
||||
printf ("Evt Device Started: Setup \n");
|
||||
setup_required = true;
|
||||
break;
|
||||
|
||||
case ACI_DEVICE_STANDBY:
|
||||
printf ("Evt Device Started: Standby \n");
|
||||
// Looking for an iPhone by sending radio advertisements
|
||||
// When an iPhone connects to us we will get an ACI_EVT_CONNECTED event from the nRF8001
|
||||
if (aci_evt->params.device_started.hw_error) {
|
||||
usleep (20000); //Handle the HW error event correctly.
|
||||
} else {
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break; // ACI Device Started Event
|
||||
|
||||
case ACI_EVT_CMD_RSP:
|
||||
//If an ACI command response event comes with an error -> stop
|
||||
if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
|
||||
//ACI ReadDynamicData and ACI WriteDynamicData will have status codes of
|
||||
//TRANSACTION_CONTINUE and TRANSACTION_COMPLETE
|
||||
//all other ACI commands will have status code of ACI_STATUS_SCUCCESS for a successful command
|
||||
printf ("ACI_EVT_CMD_RSP \n");
|
||||
}
|
||||
if (ACI_CMD_GET_DEVICE_VERSION == aci_evt->params.cmd_rsp.cmd_opcode) {
|
||||
//Store the version and configuration information of the nRF8001 in the Hardware Revision String Characteristic
|
||||
lib_aci_set_local_data(&aci_state, PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET,
|
||||
(uint8_t *)&(aci_evt->params.cmd_rsp.params.get_device_version), sizeof(aci_evt_cmd_rsp_params_get_device_version_t));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_CONNECTED:
|
||||
printf ("ACI_EVT_CONNECTED");
|
||||
uart_over_ble_init ();
|
||||
timing_change_done = false;
|
||||
aci_state.data_credit_available = aci_state.data_credit_total;
|
||||
|
||||
/*
|
||||
Get the device version of the nRF8001 and store it in the Hardware Revision String
|
||||
*/
|
||||
lib_aci_device_version();
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_STATUS:
|
||||
printf ("ACI_EVT_PIPE_STATUS \n");
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX) && (false == timing_change_done)) {
|
||||
lib_aci_change_timing_GAP_PPCP(); // change the timing on the link as specified in the nRFgo studio -> nRF8001 conf. -> GAP.
|
||||
// Used to increase or decrease bandwidth
|
||||
timing_change_done = true;
|
||||
|
||||
char hello[]="Hello World, works";
|
||||
uart_tx((uint8_t *)&hello[0], strlen(hello));
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_TIMING:
|
||||
printf ("Evt link connection interval changed \n");
|
||||
lib_aci_set_local_data(&aci_state,
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET,
|
||||
(uint8_t *)&(aci_evt->params.timing.conn_rf_interval), /* Byte aligned */
|
||||
PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DISCONNECTED:
|
||||
printf ("ACI_EVT_DISCONNECTED \n");
|
||||
lib_aci_connect(0/* in seconds : 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_RECEIVED:
|
||||
if (PIPE_UART_OVER_BTLE_UART_RX_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
for(int i=0; i<aci_evt->len - 2; i++) {
|
||||
uart_buffer[i] = aci_evt->params.data_received.rx_data.aci_data[i];
|
||||
}
|
||||
|
||||
uart_buffer_len = aci_evt->len - 2;
|
||||
if (lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX == aci_evt->params.data_received.rx_data.pipe_number) {
|
||||
//Subtract for Opcode and Pipe number
|
||||
uart_process_control_point_rx(&aci_evt->params.data_received.rx_data.aci_data[0], aci_evt->len - 2);
|
||||
}
|
||||
|
||||
printf ("Incomming data - %s\n", uart_buffer);
|
||||
break;
|
||||
|
||||
case ACI_EVT_DATA_CREDIT:
|
||||
printf ("ACI_EVT_DATA_CREDIT \n");
|
||||
aci_state.data_credit_available = aci_state.data_credit_available + aci_evt->params.data_credit.credit;
|
||||
break;
|
||||
|
||||
case ACI_EVT_PIPE_ERROR:
|
||||
printf ("ACI_EVT_PIPE_ERROR \n");
|
||||
//Increment the credit available as the data packet was not sent.
|
||||
//The pipe error also represents the Attribute protocol Error Response sent from the peer and that should not be counted
|
||||
//for the credit.
|
||||
if (ACI_STATUS_ERROR_PEER_ATT_ERROR != aci_evt->params.pipe_error.error_code) {
|
||||
aci_state.data_credit_available++;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACI_EVT_HW_ERROR:
|
||||
printf ("ACI_EVT_HW_ERROR \n");
|
||||
lib_aci_connect(0/* in seconds, 0 means forever */, 0x0050 /* advertising interval 50ms*/);
|
||||
printf ("Advertising started \n");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* setup_required is set to true when the device starts up and enters setup mode.
|
||||
* It indicates that do_aci_setup() should be called. The flag should be cleared if
|
||||
* do_aci_setup() returns ACI_STATUS_TRANSACTION_COMPLETE.
|
||||
*/
|
||||
if(setup_required) {
|
||||
if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
|
||||
setup_required = false;
|
||||
}
|
||||
}
|
||||
|
||||
usleep (100);
|
||||
}
|
||||
|
||||
close_local_interfaces (&aci_state);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
254
examples/nrf8001_helloworld.h
Normal file
@ -0,0 +1,254 @@
|
||||
#include "hal_platform.h"
|
||||
#include "aci.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#define SETUP_ID 0
|
||||
#define SETUP_FORMAT 2 /** nRF8001 Cx */
|
||||
#define ACI_DYNAMIC_DATA_SIZE 263
|
||||
|
||||
/* Service: GATT - Characteristic: Service Changed - Pipe: TX_ACK */
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK 1
|
||||
#define PIPE_GATT_SERVICE_CHANGED_TX_ACK_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: Hardware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET 2
|
||||
#define PIPE_DEVICE_INFORMATION_HARDWARE_REVISION_STRING_SET_MAX_SIZE 9
|
||||
|
||||
/* Service: Device Information - Characteristic: Manufacturer Name String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET 3
|
||||
#define PIPE_DEVICE_INFORMATION_MANUFACTURER_NAME_STRING_SET_MAX_SIZE 20
|
||||
|
||||
/* Service: Device Information - Characteristic: Model Number String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET 4
|
||||
#define PIPE_DEVICE_INFORMATION_MODEL_NUMBER_STRING_SET_MAX_SIZE 8
|
||||
|
||||
/* Service: Device Information - Characteristic: Firmware Revision String - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET 5
|
||||
#define PIPE_DEVICE_INFORMATION_FIRMWARE_REVISION_STRING_SET_MAX_SIZE 4
|
||||
|
||||
/* Service: Device Information - Characteristic: PNP_ID - Pipe: SET */
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET 6
|
||||
#define PIPE_DEVICE_INFORMATION_PNP_ID_SET_MAX_SIZE 7
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART RX - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX 7
|
||||
#define PIPE_UART_OVER_BTLE_UART_RX_RX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART TX - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX 8
|
||||
#define PIPE_UART_OVER_BTLE_UART_TX_TX_MAX_SIZE 20
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: TX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX 9
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_TX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Control Point - Pipe: RX */
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX 10
|
||||
#define PIPE_UART_OVER_BTLE_UART_CONTROL_POINT_RX_MAX_SIZE 9
|
||||
|
||||
/* Service: UART over BTLE - Characteristic: UART Link Timing Current - Pipe: SET */
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET 11
|
||||
#define PIPE_UART_OVER_BTLE_UART_LINK_TIMING_CURRENT_SET_MAX_SIZE 6
|
||||
|
||||
|
||||
#define NUMBER_OF_PIPES 11
|
||||
|
||||
#define SERVICES_PIPE_TYPE_MAPPING_CONTENT {\
|
||||
{ACI_STORE_LOCAL, ACI_TX_ACK}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_TX}, \
|
||||
{ACI_STORE_LOCAL, ACI_RX}, \
|
||||
{ACI_STORE_LOCAL, ACI_SET}, \
|
||||
}
|
||||
|
||||
#define GAP_PPCP_MAX_CONN_INT 0x12 /**< Maximum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_MIN_CONN_INT 0xa /**< Minimum connection interval as a multiple of 1.25 msec , 0xFFFF means no specific value requested */
|
||||
#define GAP_PPCP_SLAVE_LATENCY 0
|
||||
#define GAP_PPCP_CONN_TIMEOUT 0xa /** Connection Supervision timeout multiplier as a multiple of 10msec, 0xFFFF means no specific value requested */
|
||||
|
||||
#define NB_SETUP_MESSAGES 30
|
||||
#define SETUP_MESSAGES_CONTENT {\
|
||||
{0x00,\
|
||||
{\
|
||||
0x07,0x06,0x00,0x00,0x02,0x02,0x41,0xfe,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x0b,0x01,0x01,0x00,0x00,0x06,0x00,0x00,\
|
||||
0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1e,0x06,0x10,0x1c,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x14,0x03,0x90,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x00,0x04,0x04,0x02,0x02,0x00,0x01,0x28,0x00,0x01,0x00,0x18,0x04,0x04,0x05,0x05,0x00,\
|
||||
0x02,0x28,0x03,0x01,0x02,0x03,0x00,0x00,0x2a,0x04,0x04,0x14,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x1c,0x05,0x00,0x03,0x2a,0x00,0x01,0x48,0x65,0x6c,0x6c,0x6f,0x63,0x73,0x65,0x6d,0x69,\
|
||||
0x2e,0x63,0x6f,0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x38,0x05,0x05,0x00,0x04,0x28,0x03,0x01,0x02,0x05,0x00,0x01,0x2a,0x06,0x04,0x03,0x02,\
|
||||
0x00,0x05,0x2a,0x01,0x01,0x80,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x54,0x06,0x28,0x03,0x01,0x02,0x07,0x00,0x04,0x2a,0x06,0x04,0x09,0x08,0x00,0x07,0x2a,\
|
||||
0x04,0x01,0x0a,0x00,0x12,0x00,0x00,0x00,0x0a,0x00,0x04,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x70,0x02,0x02,0x00,0x08,0x28,0x00,0x01,0x01,0x18,0x04,0x04,0x05,0x05,0x00,0x09,0x28,\
|
||||
0x03,0x01,0x22,0x0a,0x00,0x05,0x2a,0x26,0x04,0x05,0x04,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0x8c,0x0a,0x2a,0x05,0x01,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,0x00,0x0b,0x29,0x02,\
|
||||
0x01,0x00,0x00,0x04,0x04,0x02,0x02,0x00,0x0c,0x28,0x00,0x01,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xa8,0x0a,0x18,0x04,0x04,0x05,0x05,0x00,0x0d,0x28,0x03,0x01,0x02,0x0e,0x00,0x27,0x2a,\
|
||||
0x04,0x04,0x09,0x01,0x00,0x0e,0x2a,0x27,0x01,0x0a,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xc4,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x0f,0x28,0x03,0x01,0x02,\
|
||||
0x10,0x00,0x29,0x2a,0x04,0x04,0x14,0x02,0x00,0x10,0x2a,0x29,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xe0,0x01,0x30,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,0x00,0x11,0x28,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x20,0xfc,0x03,0x01,0x02,0x12,0x00,0x24,0x2a,0x04,0x04,0x08,0x02,0x00,0x12,0x2a,0x24,0x01,\
|
||||
0x31,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x05,0x05,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x18,0x00,0x13,0x28,0x03,0x01,0x02,0x14,0x00,0x26,0x2a,0x04,0x04,0x04,0x02,0x00,0x14,\
|
||||
0x2a,0x26,0x01,0x33,0x34,0x00,0x00,0x04,0x04,0x05,0x05,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x34,0x15,0x28,0x03,0x01,0x02,0x16,0x00,0x50,0x2a,0x06,0x04,0x08,0x07,0x00,0x16,0x2a,\
|
||||
0x50,0x01,0x02,0x00,0x00,0xaa,0xaa,0xcc,0xcc,0x04,0x04,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x50,0x10,0x00,0x17,0x28,0x00,0x01,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x01,0x00,0x40,0x6e,0x04,0x04,0x13,0x13,0x00,0x18,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x6c,0x28,0x03,0x01,0x04,0x19,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,\
|
||||
0xa3,0xb5,0x02,0x00,0x40,0x6e,0x44,0x10,0x14,0x00,0x00,0x19,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0x88,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x13,0x13,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xa4,0x1a,0x28,0x03,0x01,0x10,0x1b,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
0xf3,0xa3,0xb5,0x03,0x00,0x40,0x6e,0x14,0x00,0x14,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xc0,0x1b,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,0x02,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xdc,0x00,0x1c,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x1d,0x28,0x03,0x01,\
|
||||
0x14,0x1e,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x21,0xf8,0xf3,0xa3,0xb5,0x04,0x00,0x40,0x6e,0x54,0x10,0x09,0x00,0x00,0x1e,0x00,0x04,0x02,\
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x14,0x03,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x22,0x14,0x02,0x00,0x1f,0x29,0x02,0x01,0x00,0x00,0x04,0x04,0x13,0x13,0x00,0x20,0x28,0x03,\
|
||||
0x01,0x02,0x21,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1b,0x06,0x22,0x30,0x93,0xf3,0xa3,0xb5,0x05,0x00,0x40,0x6e,0x06,0x04,0x07,0x06,0x00,0x21,0x00,0x05,\
|
||||
0x02,0xff,0xff,0xff,0xff,0xff,0xff,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x00,0x2a,0x05,0x01,0x00,0x04,0x04,0x00,0x0a,0x00,0x0b,0x2a,0x27,0x01,0x00,0x80,0x04,\
|
||||
0x00,0x0e,0x00,0x00,0x2a,0x29,0x01,0x00,0x80,0x04,0x00,0x10,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x1c,0x00,0x00,0x2a,0x24,0x01,0x00,0x80,0x04,0x00,0x12,0x00,0x00,0x2a,0x26,0x01,0x00,\
|
||||
0x80,0x04,0x00,0x14,0x00,0x00,0x2a,0x50,0x01,0x00,0x80,0x04,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x1f,0x06,0x40,0x38,0x00,0x16,0x00,0x00,0x00,0x02,0x02,0x00,0x08,0x04,0x00,0x19,0x00,0x00,0x00,0x03,\
|
||||
0x02,0x00,0x02,0x04,0x00,0x1b,0x00,0x1c,0x00,0x04,0x02,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x40,0x54,0x0a,0x04,0x00,0x1e,0x00,0x1f,0x00,0x05,0x02,0x00,0x80,0x04,0x00,0x21,0x00,0x00,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x13,0x06,0x50,0x00,0x9e,0xca,0xdc,0x24,0x0e,0xe5,0xa9,0xe0,0x93,0xf3,0xa3,0xb5,0x00,0x00,0x40,0x6e,\
|
||||
},\
|
||||
},\
|
||||
{0x00,\
|
||||
{\
|
||||
0x06,0x06,0xf0,0x00,0x02,0xb2,0xd1,\
|
||||
},\
|
||||
},\
|
||||
}
|
@ -27,90 +27,72 @@
|
||||
#define DEVICE_ADDRESS 0x3C
|
||||
#define BUS_NUMBER 0x0
|
||||
|
||||
static uint8_t SeeedLogo[] ={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
|
||||
0xff, 0xfc, 0x00, 0x00, 0x00, 0x80, 0xf0, 0x20, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0x60, 0xe0, 0xc0,
|
||||
0xc0, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x80, 0xc0,
|
||||
0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x60, 0xe0, 0xc0, 0xc0,
|
||||
0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00, 0xc0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0xc0,
|
||||
0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0,
|
||||
0xf8, 0xf8, 0x00, 0xd8, 0xd8, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0x60, 0xc0, 0xc0, 0x80, 0x00,
|
||||
0x00, 0x03, 0x0f, 0x1e, 0x3c, 0x70, 0xe3, 0xcf, 0x9f, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0xbf,
|
||||
0xcf, 0xe3, 0x70, 0x78, 0x3e, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x33, 0x77, 0x66, 0x66, 0x66, 0x6c,
|
||||
0x7d, 0x18, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37, 0x07, 0x00, 0x0f, 0x3f, 0x7f,
|
||||
0x66, 0x66, 0x66, 0x66, 0x77, 0x27, 0x07, 0x00, 0x1f, 0x3f, 0x76, 0x66, 0x66, 0x66, 0x76, 0x37,
|
||||
0x07, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00,
|
||||
0x11, 0x37, 0x67, 0x66, 0x66, 0x6c, 0x7d, 0x38, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00, 0x00, 0x1f,
|
||||
0x3f, 0x70, 0x60, 0x60, 0x70, 0x7f, 0x7f, 0x00, 0x0f, 0x3f, 0x71, 0x60, 0x60, 0x60, 0x60, 0x31,
|
||||
0x7f, 0x7f, 0x00, 0x7f, 0x7f, 0x00, 0x06, 0x1f, 0x3b, 0x60, 0x60, 0x60, 0x60, 0x71, 0x3f, 0x1f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0xb0, 0x00, 0xc0, 0x20,
|
||||
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00,
|
||||
0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xf8, 0x08,
|
||||
0x08, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0x20, 0xa0,
|
||||
0xa0, 0xa0, 0xc0, 0x00, 0x40, 0xa0, 0xa0, 0xa0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x48, 0x48, 0x48, 0x08, 0x00, 0x20, 0x40, 0x80, 0x40,
|
||||
0x20, 0x00, 0x00, 0x20, 0xf0, 0x20, 0x20, 0x00, 0xc0, 0xa0, 0xa0, 0xa0, 0xc0, 0x00, 0xe0, 0x00,
|
||||
0x20, 0x20, 0xc0, 0x00, 0xc0, 0x20, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x01, 0x02,
|
||||
0x02, 0x02, 0x01, 0x00, 0x01, 0x02, 0x02, 0x02, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00,
|
||||
0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x03, 0x02,
|
||||
0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x02,
|
||||
0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x82, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01,
|
||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x00, 0x01, 0x02, 0x02, 0x02, 0x00, 0x00, 0x03, 0x00,
|
||||
0x00, 0x00, 0x03, 0x00, 0x01, 0x02, 0x02, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x82, 0x8c, 0x60, 0x1c, 0x02, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x1e,
|
||||
0x20, 0x20, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x3e, 0x04, 0x02, 0x02, 0x00, 0x1c, 0x2a, 0x2a, 0x2a, 0x0c, 0x00, 0x12, 0x2a, 0x2a,
|
||||
0x2a, 0x1c, 0x20, 0x1c, 0x22, 0x22, 0x22, 0x14, 0x00, 0x3f, 0x00, 0x02, 0x02, 0x3c, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static uint8_t intel_logo[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 192, 192, 192, 224,
|
||||
224, 224, 224, 240, 240, 248, 248, 120, 120, 120, 120, 60, 60, 60, 60, 60,
|
||||
62, 30, 30, 30, 30, 30, 30, 30, 31, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 31, 31, 31, 31, 31,
|
||||
30, 62, 62, 62, 62, 126, 126, 124, 124, 252, 252, 248, 248, 240, 240, 240,
|
||||
224, 224, 224, 192, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 0, 56, 56, 28, 30, 14, 15, 15, 7, 7, 7, 7, 3, 3, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 192, 193, 195, 195,
|
||||
195, 7, 15, 15, 63, 127, 255, 255, 255, 254, 252, 252, 240, 192, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 192, 192, 240, 248, 124, 124, 60, 0, 0, 0, 0, 159, 159,
|
||||
159, 159, 159, 159, 159, 159, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,
|
||||
0, 0, 0, 0, 254, 254, 254, 254, 254, 254, 254, 254, 128, 128, 128, 128,
|
||||
128, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 192, 192, 192, 192, 192, 192, 128,
|
||||
128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 3, 7, 3, 3, 3, 0, 0, 0, 0, 0, 1, 1, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 224, 248, 252, 252, 255, 127, 15, 15, 3, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 15, 15, 15, 15, 15, 15, 255, 255, 255, 255, 255,
|
||||
255, 255, 252, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 15, 15,
|
||||
15, 15, 15, 224, 224, 252, 254, 255, 255, 255, 255, 159, 159, 143, 143,
|
||||
135, 135, 143, 159, 255, 255, 255, 255, 255, 255, 252, 248, 0, 0, 0, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||
224, 248, 248, 255, 255, 255, 255, 255, 127, 15, 255, 255, 255, 255, 255,
|
||||
255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 192, 192, 192, 192, 192, 31, 31, 255, 255, 255,
|
||||
255, 255, 255, 231, 231, 199, 199, 199, 199, 199, 199, 199, 199, 231, 231,
|
||||
231, 231, 199, 135, 0, 0, 0, 63, 255, 255, 255, 255, 255, 255, 255, 0, 0,
|
||||
0, 0, 224, 240, 248, 248, 252, 254, 255, 255, 255, 127, 63, 63, 31, 15, 7,
|
||||
7, 1, 0, 0, 63, 63, 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 3, 3, 7, 7, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 3, 3, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 0, 0, 0, 1, 3, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 7, 7, 7,
|
||||
7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 1, 3, 3, 7, 135, 135, 135, 192, 192, 0, 0, 7,
|
||||
7, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15,
|
||||
31, 127, 127, 127, 255, 255, 252, 252, 252, 248, 240, 240, 240, 224, 224,
|
||||
224, 192, 192, 192, 192, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 128, 128, 128, 128, 128, 128, 128, 192, 192, 192, 192, 192,
|
||||
224, 224, 224, 224, 240, 240, 240, 240, 248, 248, 248, 248, 252, 252, 252,
|
||||
254, 254, 255, 255, 255, 255, 255, 255, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
3, 3, 3, 7, 7, 7, 15, 15, 31, 31, 31, 63, 63, 63, 63, 63, 127, 127, 127,
|
||||
127, 127, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
|
||||
255, 255, 255, 255, 255, 255, 255, 127, 127, 127, 127, 127, 127, 127, 127,
|
||||
63, 63, 63, 63, 63, 31, 31, 31, 31, 31, 15, 15, 15, 15, 7, 7, 7, 7, 3, 3,
|
||||
3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::SSD1308 *lcd = new upm::SSD1308 (BUS_NUMBER, DEVICE_ADDRESS);
|
||||
//! [Interesting]
|
||||
upm::SSD1308 *lcd = new upm::SSD1308(BUS_NUMBER, DEVICE_ADDRESS);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
// lcd->setCursor (0, 0);
|
||||
// lcd->write ("Hello World");
|
||||
lcd->clear();
|
||||
lcd->draw(intel_logo, 1024);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
lcd->clear ();
|
||||
lcd->draw (SeeedLogo, 1024);
|
||||
|
||||
lcd->close ();
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
@ -106,21 +106,19 @@ static uint8_t SeeedLogo[] ={
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
upm::SSD1327 *lcd = new upm::SSD1327 (BUS_NUMBER, 0x3C);
|
||||
//! [Interesting]
|
||||
upm::SSD1327 *lcd = new upm::SSD1327(BUS_NUMBER, 0x3C);
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
for(uint8_t i = 0; i < 12 ; i++) {
|
||||
lcd->setCursor (i, 0);
|
||||
lcd->setGrayLevel (i);
|
||||
lcd->write ("Hello World");
|
||||
// Simple print hello world
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
lcd->setCursor(i, 0);
|
||||
lcd->setGrayLevel(i);
|
||||
lcd->write("Hello World");
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple print hello world
|
||||
*/
|
||||
lcd->draw (SeeedLogo, 96 * 96 / 8);
|
||||
// Simple print hello world
|
||||
lcd->draw(SeeedLogo, 96 * 96 / 8);
|
||||
|
||||
lcd->close ();
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
61
examples/pulsensor.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "pulsensor.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
pulsensor_context sensor_ctx;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handler (clbk_data data) {
|
||||
printf ("callback data (%d)\n", data);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
init_pulsensor (&sensor_ctx, handler);
|
||||
|
||||
start_sampler (&sensor_ctx);
|
||||
while (!doWork) {
|
||||
usleep (5);
|
||||
}
|
||||
stop_sampler (&sensor_ctx);
|
||||
//! [Interesting]
|
||||
return 0;
|
||||
}
|
74
examples/python/make_oled_pic.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from PIL import Image
|
||||
import sys
|
||||
|
||||
# Pixels are arranged in one byte for 8 vertical pixels and not addressed individually
|
||||
# We convert the image to greysacle and end up making it monochrome where we
|
||||
# consider that every pixel that is '40' is black.
|
||||
|
||||
width = 128
|
||||
height = 64
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print('Please specify an image to use as the only argument')
|
||||
exit(1)
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
im = im.convert('L').resize((width, height))
|
||||
|
||||
data = list(im.getdata())
|
||||
|
||||
byteblock = [0 for i in range(width)]
|
||||
widthblock = [list(byteblock) for i in range(int(height/8))]
|
||||
numblock = 0
|
||||
pixcount = 0
|
||||
i = 0
|
||||
|
||||
# we split the list by width * 8, to create data chunks of 8rows
|
||||
datachunks=[data[x:x+(width*8)] for x in range(0, len(data), (width*8))]
|
||||
|
||||
# grab every pixel of image (or datachunk)
|
||||
while i < len(widthblock):
|
||||
pixcount = 0
|
||||
for y in datachunks[i]:
|
||||
xcoor = pixcount % width
|
||||
ycoor = int(pixcount/width)
|
||||
blknum = xcoor % len(widthblock)
|
||||
blkycoor = ycoor
|
||||
|
||||
# 40 is what we consider 'black'
|
||||
if y > 40:
|
||||
widthblock[i][xcoor] |= (1 << blkycoor)
|
||||
|
||||
pixcount += 1
|
||||
i += 1
|
||||
|
||||
flatlist = [y for x in widthblock for y in x]
|
||||
|
||||
carray = 'static uint8_t image[] = {\n' + ', '.join(str(x) for x in flatlist)
|
||||
print(carray + '\n};')
|
31
examples/python/using_carrays.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||
# Copyright (c) 2014 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
import pyupm_mic
|
||||
|
||||
mymic = pyupm_mic.Microphone(1)
|
||||
# careful this is an unitialised array with no bounds checking!
|
||||
x = pyupm_mic.uint16Array(3)
|
||||
mymic.getSampledWindow(100, 3, x)
|
||||
|
@ -27,6 +27,7 @@
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
|
||||
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
|
||||
lcd->setCursor(0,0);
|
||||
@ -34,4 +35,5 @@ main(int argc, char **argv)
|
||||
lcd->setCursor(1,2);
|
||||
lcd->write("Hello World");
|
||||
lcd->close();
|
||||
//! [Interesting]
|
||||
}
|
||||
|
79
examples/st7735.cxx
Normal 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
@ -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;
|
||||
}
|
62
examples/tcs3414cs-example.cxx
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 "tcs3414cs.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::TCS3414CS *sensor = NULL;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
doWork = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
upm::tcs3414sc_rgb_t rgb;
|
||||
sensor = new upm::TCS3414CS ();
|
||||
|
||||
while (!doWork) {
|
||||
sensor->readRGB (&rgb);
|
||||
std::cout << (int)rgb.r << ", " << (int)rgb.g << ", " << (int)rgb.b << ", " << rgb.clr << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
64
examples/th02-example.cxx
Normal 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 "th02.h"
|
||||
#include <signal.h>
|
||||
|
||||
int doWork = 0;
|
||||
upm::TH02 *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]
|
||||
float temperature = 0.0;
|
||||
float humidity = 0.0;
|
||||
sensor = new upm::TH02 ();
|
||||
|
||||
while (!doWork) {
|
||||
temperature = sensor->getTemperature ();
|
||||
// humidity = sensor->getHumidity ();
|
||||
std::cout << "Temperature = " << temperature << ", Humidity = " << humidity << std::endl;
|
||||
usleep (500000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
std::cout << "exiting application" << std::endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
set (libname "4digitdisplay")
|
||||
add_library (4digitdisplay SHARED tm1637.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (4digitdisplay ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES tm1637.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm 4 Digit Buzzer")
|
||||
endif()
|
@ -8,6 +8,121 @@ macro(subdirlist result curdir)
|
||||
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 AND BUILDSWIG)
|
||||
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 AND BUILDSWIG)
|
||||
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
|
||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION"
|
||||
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)
|
||||
if (BUILDSWIG)
|
||||
add_dependencies (_pyupm_${libname} ${libname}doc_i)
|
||||
else ()
|
||||
add_dependencies (${libname} doc)
|
||||
endif ()
|
||||
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()
|
||||
endif()
|
||||
if (BUILDDOC)
|
||||
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})
|
||||
|
@ -1,12 +1,5 @@
|
||||
set (libname "buzzer")
|
||||
add_library (buzzer SHARED buzzer.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (buzzer ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES buzzer.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm buzzer")
|
||||
endif()
|
||||
set (libdescription "upm buzzer")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
||||
|
@ -30,22 +30,22 @@
|
||||
using namespace upm;
|
||||
|
||||
Buzzer::Buzzer (int pinNumber) {
|
||||
m_pwm_context = maa_pwm_init (pinNumber);
|
||||
m_pwm_context = mraa_pwm_init (pinNumber);
|
||||
m_name = "Buzzer";
|
||||
}
|
||||
|
||||
int Buzzer::playSound (int note) {
|
||||
maa_pwm_enable (m_pwm_context, 1);
|
||||
maa_pwm_period_us (m_pwm_context, note);
|
||||
maa_pwm_write (m_pwm_context, 50.0);
|
||||
usleep (10000);
|
||||
maa_pwm_enable (m_pwm_context, 0);
|
||||
int Buzzer::playSound (int note, int delay) {
|
||||
mraa_pwm_enable (m_pwm_context, 1);
|
||||
mraa_pwm_period_us (m_pwm_context, note);
|
||||
mraa_pwm_pulsewidth_us (m_pwm_context, note / 2);
|
||||
usleep (delay);
|
||||
mraa_pwm_enable (m_pwm_context, 0);
|
||||
|
||||
return 0;
|
||||
return note;
|
||||
}
|
||||
|
||||
Buzzer::~Buzzer() {
|
||||
maa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed maa_pwm_close" << std::endl;
|
||||
mraa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed mraa_pwm_close" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
#define DO 3830000 // 261 Hz
|
||||
#define RE 3400000 // 294 Hz
|
||||
#define MI 3038000 // 329 Hz
|
||||
#define FA 2864000 // 349 Hz
|
||||
#define SOL 2550000 // 392 Hz
|
||||
#define LA 2272000 // 440 Hz
|
||||
#define SI 2028000 // 493 Hz
|
||||
#define DO 3300 // 261 Hz 3830
|
||||
#define RE 2930 // 294 Hz
|
||||
#define MI 2600 // 329 Hz
|
||||
#define FA 2460 // 349 Hz
|
||||
#define SOL 2190 // 392 Hz
|
||||
#define LA 1960 // 440 Hz
|
||||
#define SI 1750 // 493 Hz
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -41,7 +41,7 @@ namespace upm {
|
||||
*
|
||||
* This file defines the Buzzer C++ interface for libbuzzer
|
||||
*
|
||||
* @snippet es08a.cxx Interesting
|
||||
* @snippet buzzer-sound.cxx Interesting
|
||||
*
|
||||
*/
|
||||
class Buzzer {
|
||||
@ -49,7 +49,7 @@ class Buzzer {
|
||||
/**
|
||||
* Instanciates a Buzzer object
|
||||
*
|
||||
* @param pin Buzzer pin number
|
||||
* @param pinNumber Buzzer pin number
|
||||
*/
|
||||
Buzzer (int pinNumber);
|
||||
|
||||
@ -62,8 +62,9 @@ class Buzzer {
|
||||
* Play chords.
|
||||
*
|
||||
* @param note chords (DO, RE, ME, etc...)
|
||||
* @param delay time in microsec for playing the sound
|
||||
*/
|
||||
int playSound (int note);
|
||||
int playSound (int note, int delay);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
@ -75,6 +76,6 @@ class Buzzer {
|
||||
protected:
|
||||
std::string m_name;
|
||||
private:
|
||||
maa_pwm_context m_pwm_context;
|
||||
mraa_pwm_context m_pwm_context;
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_buzzer
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_buzzer
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
3
src/carrays_uint16_t.i
Normal file
@ -0,0 +1,3 @@
|
||||
%include "stdint.i"
|
||||
%include "carrays.i"
|
||||
%array_class(uint16_t, uint16Array);
|
5
src/ecs1030/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "ecs1030")
|
||||
set (libdescription "Non-invasive current sensor")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
101
src/ecs1030/ecs1030.cxx
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 "ecs1030.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
struct ECS1030Exception : public std::exception {
|
||||
std::string message;
|
||||
ECS1030Exception (std::string msg) : message (msg) { }
|
||||
~ECS1030Exception () throw () { }
|
||||
const char* what() const throw () { return message.c_str(); }
|
||||
};
|
||||
|
||||
ECS1030::ECS1030 (uint8_t pinNumber) {
|
||||
m_dataPinCtx = mraa_aio_init(pinNumber);
|
||||
if (m_dataPinCtx == NULL) {
|
||||
throw ECS1030Exception ("GPIO failed to initilize");
|
||||
}
|
||||
|
||||
m_calibration = 111.1;
|
||||
}
|
||||
|
||||
ECS1030::~ECS1030 () {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
error = mraa_aio_close (m_dataPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
ECS1030::getCurrency_A () {
|
||||
int sensorValue = 0;
|
||||
float rLoad = 0;
|
||||
float volt = 0;
|
||||
float rms = 0;
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
|
||||
sensorValue = mraa_aio_read (m_dataPinCtx);
|
||||
volt = (VOLT_M * sensorValue) - 2.5;
|
||||
volt = volt * volt;
|
||||
rms = rms + volt;
|
||||
usleep (DELAY_MS);
|
||||
}
|
||||
|
||||
rms = rms / (float)NUMBER_OF_SAMPLES;
|
||||
rms = sqrt(rms);
|
||||
return rms / R_LOAD;
|
||||
}
|
||||
|
||||
double
|
||||
ECS1030::getCurrency_B () {
|
||||
double sumCurrency = 0;
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_SAMPLES; i++) {
|
||||
m_lastSample = m_sample;
|
||||
m_sample = mraa_aio_read (m_dataPinCtx);
|
||||
m_lastFilter = m_filteredSample;
|
||||
m_filteredSample = 0.996 * (m_lastFilter + m_sample - m_lastSample);
|
||||
sumCurrency += (m_filteredSample * m_filteredSample);
|
||||
}
|
||||
|
||||
double ratio = m_calibration * ((SUPPLYVOLTAGE / 1000.0) / (ADC_RESOLUTION));
|
||||
return ( ratio * sqrt(sumCurrency / NUMBER_OF_SAMPLES) );
|
||||
}
|
||||
|
||||
double
|
||||
ECS1030::getPower_A () {
|
||||
return 220.0 * getCurrency_A ();
|
||||
}
|
||||
|
||||
double
|
||||
ECS1030::getPower_B () {
|
||||
return 220.0 * getCurrency_B ();
|
||||
}
|
97
src/ecs1030/ecs1030.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 <math.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#define NUMBER_OF_SAMPLES 500
|
||||
#define ADC_RESOLUTION 1024
|
||||
#define SUPPLYVOLTAGE 5100
|
||||
#define CURRENT_RATIO 2000.0
|
||||
|
||||
#define HIGH 1
|
||||
#define LOW 0
|
||||
|
||||
#define TRUE HIGH
|
||||
#define FALSE LOW
|
||||
|
||||
namespace upm {
|
||||
class ECS1030 {
|
||||
public:
|
||||
static const uint8_t DELAY_MS = 20000 / NUMBER_OF_SAMPLES; /* 1/50Hz is 20ms period */
|
||||
static const uint8_t VOLT_M = 5.1 / 1023;
|
||||
static const uint8_t R_LOAD = 2000.0 / CURRENT_RATIO;
|
||||
|
||||
/**
|
||||
* Instanciates a ECS1030 (current sensor) object
|
||||
*
|
||||
* @param pinNumber number of the data pin
|
||||
*/
|
||||
ECS1030 (uint8_t pinNumber);
|
||||
|
||||
/**
|
||||
* ECS1030 object destructor, basicaly it close the GPIO.
|
||||
*/
|
||||
~ECS1030 ();
|
||||
|
||||
/**
|
||||
* Return currency data for the sampled period
|
||||
*/
|
||||
double getCurrency_A ();
|
||||
|
||||
/**
|
||||
* Return power data for the sampled period
|
||||
*/
|
||||
double getPower_A ();
|
||||
|
||||
/**
|
||||
* Return currency data for the sampled period
|
||||
*/
|
||||
double getCurrency_B ();
|
||||
|
||||
/**
|
||||
* Return power data for the sampled period
|
||||
*/
|
||||
double getPower_B ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name() {
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
mraa_aio_context m_dataPinCtx;
|
||||
|
||||
double m_calibration;
|
||||
int m_lastSample;
|
||||
double m_lastFilter;
|
||||
int m_sample;
|
||||
double m_filteredSample;
|
||||
};
|
||||
}
|
8
src/ecs1030/jsupm_ecs1030.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_ecs1030
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "ecs1030.h"
|
||||
%}
|
||||
|
||||
%include "ecs1030.h"
|
11
src/ecs1030/pyupm_ecs1030.i
Normal file
@ -0,0 +1,11 @@
|
||||
%module pyupm_ecs1030
|
||||
%include "../upm.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "ecs1030.h"
|
||||
%{
|
||||
#include "ecs1030.h"
|
||||
%}
|
5
src/gas/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "gas")
|
||||
set (libdescription "Gas sensors")
|
||||
set (module_src ${libname}.cxx mq2.cxx mq3.cxx mq5.cxx mq9.cxx)
|
||||
set (module_h ${libname}.h mq2.h mq3.h mq5.h mq9.h)
|
||||
upm_module_init()
|
6
src/gas/README.txt
Normal file
@ -0,0 +1,6 @@
|
||||
Grove - Gas Sensor(MQ-2):Combustible Gas Smoke [middle sensitivity]
|
||||
Grove - Gas Sensor(MQ-3):Alcohol and Benzine [HIGH sensitivity] Long warmup
|
||||
Grove - Gas Sensor(MQ-5):LPG, Natural Gas, Town Gas [high sensitivity]
|
||||
Grove - Gas Sensor(MQ-9):LPG, CO, CH4 [low sensitivity]
|
||||
|
||||
Note - Gas sensor need to be heated, first minute the data is incorrect.
|
105
src/gas/gas.cxx
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 "gas.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Gas::Gas(int gasPin) {
|
||||
// initialise analog gas input
|
||||
m_gasCtx = mraa_aio_init(gasPin);
|
||||
}
|
||||
|
||||
Gas::~Gas() {
|
||||
// close analog input
|
||||
mraa_result_t error;
|
||||
error = mraa_aio_close(m_gasCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print(error);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Gas::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_gasCtx);
|
||||
usleep(freqMS * 1000);
|
||||
}
|
||||
|
||||
return sampleIdx;
|
||||
}
|
||||
|
||||
int
|
||||
Gas::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;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Gas::getSampledData (thresholdContext* ctx) {
|
||||
return ctx->runningAverage;
|
||||
}
|
||||
|
||||
int
|
||||
Gas::getSample (thresholdContext* ctx) {
|
||||
return mraa_aio_read (m_gasCtx);
|
||||
}
|
||||
|
||||
void
|
||||
Gas::printGraph (thresholdContext* ctx, uint8_t resolution) {
|
||||
std::cout << "(" << ctx->runningAverage << ") | ";
|
||||
for (int i = 0; i < ctx->runningAverage / resolution; i++)
|
||||
std::cout << "*";
|
||||
std::cout << std::endl;
|
||||
}
|
104
src/gas/gas.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 Gas sensors
|
||||
*
|
||||
* This file defines the Gas Analog sensors virtual functions
|
||||
*/
|
||||
class Gas {
|
||||
public:
|
||||
/**
|
||||
* Instanciates a Gas object
|
||||
*
|
||||
* @param gasPin pin where gas is connected
|
||||
*/
|
||||
Gas(int gasPin);
|
||||
|
||||
/**
|
||||
* Gas object destructor
|
||||
*/
|
||||
~Gas();
|
||||
|
||||
/**
|
||||
* Get samples from gas sensor according to provided window and
|
||||
* number of samples
|
||||
*
|
||||
* @param freqMS time between each sample (in microseconds)
|
||||
* @param numberOfSamples number of sample to sample for this window
|
||||
* @param buffer bufer with sampled data
|
||||
*/
|
||||
virtual int getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, uint16_t * buffer);
|
||||
|
||||
/**
|
||||
* Given sampled buffer this method will return TRUE/FALSE if threshold
|
||||
* was reached
|
||||
*
|
||||
* @param ctx threshold context
|
||||
* @param threshold sample threshold
|
||||
* @param buffer buffer with samples
|
||||
* @param len bufer len
|
||||
*/
|
||||
virtual int findThreshold (thresholdContext* ctx, unsigned int threshold, uint16_t * buffer, unsigned int len);
|
||||
|
||||
/**
|
||||
* Return avarage data for the sampled window
|
||||
*
|
||||
* @param ctx threshold context
|
||||
*/
|
||||
virtual int getSampledData (thresholdContext* ctx);
|
||||
|
||||
/**
|
||||
* Return one sample from the sensor
|
||||
*
|
||||
* @param ctx threshold context
|
||||
*/
|
||||
virtual int getSample (thresholdContext* ctx);
|
||||
|
||||
/**
|
||||
*
|
||||
* Print running average of threshold context
|
||||
*
|
||||
* @param ctx threshold context
|
||||
*/
|
||||
virtual void printGraph (thresholdContext* ctx, uint8_t resolution);
|
||||
|
||||
protected:
|
||||
mraa_aio_context m_gasCtx;
|
||||
};
|
||||
|
||||
}
|
9
src/gas/jsupm_gas.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_gas
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint16_t.i"
|
||||
|
||||
%{
|
||||
#include "gas.h"
|
||||
%}
|
||||
|
||||
%include "gas.h"
|
33
src/gas/mq2.cxx
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "mq2.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MQ2::MQ2 (int gasPin) : Gas (gasPin) {
|
||||
}
|
||||
|
||||
MQ2::~MQ2 () {
|
||||
}
|
66
src/gas/mq2.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
#include "gas.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief C++ API for MQ2 gas sensor
|
||||
*
|
||||
* The Grove - Gas Sensor (MQ2) module is useful for gas leakage detecting
|
||||
* (in home and industry). It can detect LPG, i-butane, methane, alcohol,
|
||||
* Hydrogen, smoke and other combustible gases. It's a medium sensitivity
|
||||
* sensor with a detect concentration of 300-10000ppm.
|
||||
*
|
||||
* @snippet mq2-example.cxx Interesting
|
||||
* @image html grovegas.jpeg
|
||||
*/
|
||||
class MQ2 : public Gas {
|
||||
public:
|
||||
/**
|
||||
* MQ2 constructor
|
||||
*
|
||||
* @param gasPin analog pin where sensor connected
|
||||
*/
|
||||
MQ2 (int gasPin);
|
||||
|
||||
/**
|
||||
* MQ2 destructor
|
||||
*/
|
||||
~MQ2 ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
33
src/gas/mq3.cxx
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "mq3.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MQ3::MQ3 (int gasPin) : Gas (gasPin) {
|
||||
}
|
||||
|
||||
MQ3::~MQ3 () {
|
||||
}
|
66
src/gas/mq3.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
#include "gas.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief C++ API for MQ3 gas sensor
|
||||
*
|
||||
* The Grove MQ3 Gas Sensor module is useful for gas leakage detecting (in
|
||||
* home and industry). It can detect Alcohol Vapour and Benzine. It's
|
||||
* highly sensitive but has a long warmup time of about 1minute. It's
|
||||
* detect rate is of 0.04-4mg/L Alcohol.
|
||||
*
|
||||
* @snippet mq3-example.cxx Interesting
|
||||
* @image html grovegas.jpeg
|
||||
*/
|
||||
class MQ3 : public Gas {
|
||||
public:
|
||||
/**
|
||||
* MQ3 constructor
|
||||
*
|
||||
* @param gasPin analog pin where sensor connected
|
||||
*/
|
||||
MQ3 (int gasPin);
|
||||
|
||||
/**
|
||||
* MQ3 destructor
|
||||
*/
|
||||
~MQ3 ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
33
src/gas/mq5.cxx
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "mq5.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MQ5::MQ5 (int gasPin) : Gas (gasPin) {
|
||||
}
|
||||
|
||||
MQ5::~MQ5 () {
|
||||
}
|
66
src/gas/mq5.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
#include "gas.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief C++ API for MQ5 gas sensor
|
||||
*
|
||||
* The Grove - Gas Sensor (MQ5) module is useful for gas leakage detecting
|
||||
* (in home and industry). It can detect LPG, natural gas, town gas and so
|
||||
* on. It is highly sensitive and has a detection concentration of
|
||||
* 300-10000ppm.
|
||||
*
|
||||
* @snippet mq5-example.cxx Interesting
|
||||
* @image html grovegas.jpeg
|
||||
*/
|
||||
class MQ5 : public Gas {
|
||||
public:
|
||||
/**
|
||||
* MQ5 constructor
|
||||
*
|
||||
* @param gasPin analog pin where sensor connected
|
||||
*/
|
||||
MQ5 (int gasPin);
|
||||
|
||||
/**
|
||||
* MQ9 destructor
|
||||
*/
|
||||
~MQ5 ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
33
src/gas/mq9.cxx
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "mq9.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MQ9::MQ9 (int gasPin) : Gas (gasPin) {
|
||||
}
|
||||
|
||||
MQ9::~MQ9 () {
|
||||
}
|
65
src/gas/mq9.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 <iostream>
|
||||
#include <string>
|
||||
#include "gas.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @brief C++ API for MQ9 gas sensor
|
||||
*
|
||||
* The Grove MQ9 Gas Sensor module is useful for gas leakage detecting (in
|
||||
* home and industry). It can detect Carbon Monoxide, Coal Gas and
|
||||
* Liquefied Gas. It's sensitivty is 10-1000ppmCO 100-10000PPm Gas.
|
||||
*
|
||||
* @snippet mq9-example.cxx Interesting
|
||||
* @image html mq9.jpeg
|
||||
*/
|
||||
class MQ9 : public Gas {
|
||||
public:
|
||||
/**
|
||||
* Jhd1313m1 constructor
|
||||
*
|
||||
* @param gasPin analog pin where sensor connected
|
||||
*/
|
||||
MQ9 (int gasPin);
|
||||
|
||||
/**
|
||||
* MQ9 destructor
|
||||
*/
|
||||
~MQ9 ();
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
*/
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
}
|
12
src/gas/pyupm_gas.i
Normal file
@ -0,0 +1,12 @@
|
||||
%module pyupm_gas
|
||||
%include "../upm.i"
|
||||
%include "../carrays_uint16_t.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "gas.h"
|
||||
%{
|
||||
#include "gas.h"
|
||||
%}
|
@ -1,47 +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 ()
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES grove.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm grove libary")
|
||||
endif()
|
||||
set (libdescription "upm grove module")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
||||
|
@ -33,31 +33,31 @@ using namespace upm;
|
||||
|
||||
GroveLed::GroveLed(int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_gpio = maa_gpio_init(pin);
|
||||
maa_gpio_dir(m_gpio, MAA_GPIO_OUT);
|
||||
mraa_init();
|
||||
m_gpio = mraa_gpio_init(pin);
|
||||
mraa_gpio_dir(m_gpio, MRAA_GPIO_OUT);
|
||||
m_name = "LED Socket";
|
||||
}
|
||||
|
||||
GroveLed::~GroveLed()
|
||||
{
|
||||
maa_gpio_close(m_gpio);
|
||||
mraa_gpio_close(m_gpio);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::write(int value)
|
||||
mraa_result_t GroveLed::write(int value)
|
||||
{
|
||||
if (value >= 1) {
|
||||
return maa_gpio_write(m_gpio, 1);
|
||||
return mraa_gpio_write(m_gpio, 1);
|
||||
}
|
||||
return maa_gpio_write(m_gpio, 0);
|
||||
return mraa_gpio_write(m_gpio, 0);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::on()
|
||||
mraa_result_t GroveLed::on()
|
||||
{
|
||||
return write(1);
|
||||
}
|
||||
|
||||
maa_result_t GroveLed::off()
|
||||
mraa_result_t GroveLed::off()
|
||||
{
|
||||
return write(0);
|
||||
}
|
||||
@ -66,19 +66,19 @@ maa_result_t GroveLed::off()
|
||||
|
||||
GroveTemp::GroveTemp(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Temperature Sensor";
|
||||
}
|
||||
|
||||
GroveTemp::~GroveTemp()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveTemp::value ()
|
||||
{
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
float r = (float)(1023-a)*10000/a;
|
||||
float t = 1/(logf(r/10000)/3975 + 1/298.15)-273.15;
|
||||
return (int) t;
|
||||
@ -86,32 +86,32 @@ int GroveTemp::value ()
|
||||
|
||||
float GroveTemp::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
||||
//// GroveLight ////
|
||||
|
||||
GroveLight::GroveLight(unsigned int pin)
|
||||
{
|
||||
maa_init();
|
||||
m_aio = maa_aio_init(pin);
|
||||
mraa_init();
|
||||
m_aio = mraa_aio_init(pin);
|
||||
m_name = "Light Sensor";
|
||||
}
|
||||
|
||||
GroveLight::~GroveLight()
|
||||
{
|
||||
maa_aio_close(m_aio);
|
||||
mraa_aio_close(m_aio);
|
||||
}
|
||||
|
||||
int GroveLight::value ()
|
||||
{
|
||||
// rough conversion to Lux
|
||||
int a = maa_aio_read(m_aio);
|
||||
int a = mraa_aio_read(m_aio);
|
||||
a = 10000/(((1023-a)*10/a)*15)^(4/3);
|
||||
return a;
|
||||
}
|
||||
|
||||
float GroveLight::raw_value()
|
||||
{
|
||||
return (float) maa_aio_read(m_aio);
|
||||
return (float) mraa_aio_read(m_aio);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -40,35 +40,76 @@ class Grove {
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove LED
|
||||
*
|
||||
* Very basic UPM module for grove LED, or any LED for that matter
|
||||
*
|
||||
* @snippet groveled.cxx Interesting
|
||||
*/
|
||||
class GroveLed: public Grove {
|
||||
public:
|
||||
GroveLed(int pin);
|
||||
~GroveLed();
|
||||
maa_result_t write(int value);
|
||||
maa_result_t off();
|
||||
maa_result_t on();
|
||||
mraa_result_t write(int value);
|
||||
mraa_result_t off();
|
||||
mraa_result_t on();
|
||||
private:
|
||||
maa_gpio_context m_gpio;
|
||||
mraa_gpio_context m_gpio;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove Temperature sensor
|
||||
*
|
||||
* Very basic UPM module for grove temperature sensor on analog
|
||||
*
|
||||
* @snippet grovetemp.cxx Interesting
|
||||
*/
|
||||
class GroveTemp: public Grove {
|
||||
public:
|
||||
GroveTemp(unsigned int pin);
|
||||
~GroveTemp();
|
||||
/**
|
||||
* Get raw value from AIO pin
|
||||
*
|
||||
* @return the raw value from the ADC
|
||||
*/
|
||||
float raw_value();
|
||||
/**
|
||||
* Get the temperature from the sensor
|
||||
*
|
||||
* @return the normalised temperature
|
||||
*/
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief C++ API for Grove light sensor
|
||||
*
|
||||
* Very basic UPM module for grove Light sensor on analog
|
||||
*
|
||||
* @snippet grovelight.cxx Interesting
|
||||
*/
|
||||
class GroveLight: public Grove {
|
||||
public:
|
||||
GroveLight(unsigned int pin);
|
||||
~GroveLight();
|
||||
/**
|
||||
* Get raw value from AIO pin
|
||||
*
|
||||
* @return the raw value from the ADC
|
||||
*/
|
||||
float raw_value();
|
||||
/**
|
||||
* Get the light value from the sensor
|
||||
*
|
||||
* @return the normalised light reading
|
||||
*/
|
||||
int value();
|
||||
private:
|
||||
maa_aio_context m_aio;
|
||||
mraa_aio_context m_aio;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_grove
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "grove.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_grove
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|
5
src/gy65/CMakeLists.txt
Normal 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
@ -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;
|
||||
}
|
162
src/gy65/gy65.h
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 address of used i2c device
|
||||
* @param mode BMP085 mode
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
8
src/gy65/jsupm_gy65.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_gy65
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "gy65.h"
|
||||
%}
|
||||
|
||||
%include "gy65.h"
|
11
src/gy65/pyupm_gy65.i
Normal file
@ -0,0 +1,11 @@
|
||||
%module pyupm_gy65
|
||||
%include "../upm.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "gy65.h"
|
||||
%{
|
||||
#include "gy65.h"
|
||||
%}
|
@ -1,12 +1,5 @@
|
||||
set (libname "hcsr04")
|
||||
add_library (hcsr04 SHARED hcsr04.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (hcsr04 ${MAA_LIBRARIES})
|
||||
|
||||
install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname})
|
||||
install (FILES hcsr04.h DESTINATION include/upm COMPONENT ${libname})
|
||||
|
||||
if (IPK)
|
||||
cpack_add_component (${libname} DISPLAY_NAME ${libname} REQUIRED INSTALL_TYPES all)
|
||||
set(CPACK_COMPONENT_${libname}_DESCRIPTION "libupm proximity sensor")
|
||||
endif()
|
||||
set (libdescription "upm proximity sensor")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
||||
|
@ -31,44 +31,44 @@
|
||||
|
||||
using namespace upm;
|
||||
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void)) {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
m_name = "HCSR04";
|
||||
|
||||
m_pwmTriggerCtx = maa_pwm_init (triggerPin);
|
||||
m_pwmTriggerCtx = mraa_pwm_init (triggerPin);
|
||||
if (m_pwmTriggerCtx == NULL) {
|
||||
std::cout << "PWM context is NULL" << std::endl;
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_init();
|
||||
m_echoPinCtx = maa_gpio_init(echoPin);
|
||||
mraa_init();
|
||||
m_echoPinCtx = mraa_gpio_init(echoPin);
|
||||
if (m_echoPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", echoPin);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
maa_gpio_dir(m_echoPinCtx, MAA_GPIO_IN);
|
||||
gpio_edge_t edge = MAA_GPIO_EDGE_BOTH;
|
||||
maa_gpio_isr (m_echoPinCtx, edge, fptr);
|
||||
mraa_gpio_dir(m_echoPinCtx, MRAA_GPIO_IN);
|
||||
gpio_edge_t edge = MRAA_GPIO_EDGE_BOTH;
|
||||
mraa_gpio_isr (m_echoPinCtx, edge, fptr, NULL);
|
||||
}
|
||||
|
||||
HCSR04::~HCSR04 () {
|
||||
maa_result_t error = MAA_SUCCESS;
|
||||
mraa_result_t error = MRAA_SUCCESS;
|
||||
|
||||
maa_pwm_close (m_pwmTriggerCtx);
|
||||
error = maa_gpio_close (m_echoPinCtx);
|
||||
if (error != MAA_SUCCESS) {
|
||||
maa_result_print (error);
|
||||
mraa_pwm_close (m_pwmTriggerCtx);
|
||||
error = mraa_gpio_close (m_echoPinCtx);
|
||||
if (error != MRAA_SUCCESS) {
|
||||
mraa_result_print (error);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
HCSR04::getDistance () {
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
maa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
maa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
maa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 1);
|
||||
mraa_pwm_period_us (m_pwmTriggerCtx, MAX_PERIOD);
|
||||
mraa_pwm_pulsewidth_us (m_pwmTriggerCtx, TRIGGER_PULSE);
|
||||
mraa_pwm_enable (m_pwmTriggerCtx, 0);
|
||||
|
||||
m_doWork = 0;
|
||||
m_InterruptCounter = 0;
|
||||
|
@ -24,9 +24,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/aio.h>
|
||||
#include <maa/gpio.h>
|
||||
#include <maa/pwm.h>
|
||||
#include <mraa/aio.h>
|
||||
#include <mraa/gpio.h>
|
||||
#include <mraa/pwm.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define HIGH 1
|
||||
@ -55,7 +55,7 @@ class HCSR04 {
|
||||
* @param fptr function pointer for handling raising and
|
||||
* falling interrupts
|
||||
*/
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void));
|
||||
HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *));
|
||||
|
||||
/**
|
||||
* HCSR04 object destructor.
|
||||
@ -85,8 +85,8 @@ class HCSR04 {
|
||||
}
|
||||
|
||||
private:
|
||||
maa_pwm_context m_pwmTriggerCtx;
|
||||
maa_gpio_context m_echoPinCtx;
|
||||
mraa_pwm_context m_pwmTriggerCtx;
|
||||
mraa_gpio_context m_echoPinCtx;
|
||||
|
||||
uint8_t m_waitEcho;
|
||||
long m_RisingTimeStamp;
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module jsupm_hcsr04
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "hcsr04.h"
|
||||
|
@ -1,4 +1,5 @@
|
||||
%module pyupm_hcsr04
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
|