mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 12:21:11 +03:00
Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
8734767a5c | |||
b4535a6403 | |||
3d37f957bf | |||
3722dfc780 | |||
b113a46813 | |||
aa30b59e44 | |||
159d2eee07 | |||
7fd9f0c508 | |||
3ca9bfe80f | |||
90983fde9d | |||
ee19daedee | |||
61dbfe4f23 | |||
224a915538 | |||
1aa445b74e | |||
e6ad752a2c | |||
144937995c | |||
0b49cbab9b |
28
.travis.yml
28
.travis.yml
@ -1,8 +1,12 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
compiler:
|
env:
|
||||||
- gcc
|
- CC=gcc CXX=gcc
|
||||||
- clang
|
- CC=clang CXX=clang++
|
||||||
|
- NODE4=true
|
||||||
|
- NODE5=true
|
||||||
|
- NODE012=true
|
||||||
install:
|
install:
|
||||||
|
- if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi
|
||||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
||||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
@ -10,12 +14,24 @@ install:
|
|||||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
- sudo update-java-alternatives -s java-8-oracle
|
||||||
before_script:
|
before_script:
|
||||||
|
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
|
||||||
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
||||||
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
||||||
|
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
script:
|
script:
|
||||||
- git clone --branch=master https://github.com/intel-iot-devkit/mraa.git
|
- git clone --branch=firmata https://github.com/intel-iot-devkit/mraa.git
|
||||||
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include .. && make && make install
|
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
|
||||||
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
||||||
- export CPLUS_INCLUDE_PATH=$PWD/include
|
- export CPLUS_INCLUDE_PATH=$PWD/include
|
||||||
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
||||||
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-precise-3.6
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- clang-3.6
|
||||||
|
- g++-4.8
|
||||||
|
@ -51,6 +51,7 @@ set (CMAKE_SWIG_FLAGS "")
|
|||||||
option (BUILDDOC "Build all doc." OFF)
|
option (BUILDDOC "Build all doc." OFF)
|
||||||
option (BUILDSWIG "Build swig modules." ON)
|
option (BUILDSWIG "Build swig modules." ON)
|
||||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||||
|
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||||
option (BUILDSWIGNODE "Build swig node modules." ON)
|
option (BUILDSWIGNODE "Build swig node modules." ON)
|
||||||
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||||
@ -156,7 +157,7 @@ if (IPK)
|
|||||||
endif ()
|
endif ()
|
||||||
message (INFO " - Package arch is ${TARGET_ARCH}")
|
message (INFO " - Package arch is ${TARGET_ARCH}")
|
||||||
|
|
||||||
set(CPACK_GENERATOR "DEB" "TGZ")
|
set(CPACK_GENERATOR "DEB")
|
||||||
set(OPKG_ARCH ${TARGET_ARCH})
|
set(OPKG_ARCH ${TARGET_ARCH})
|
||||||
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
||||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
||||||
@ -210,10 +211,18 @@ if(BUILDJAVAEXAMPLES)
|
|||||||
add_subdirectory (examples/java)
|
add_subdirectory (examples/java)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILDTESTS)
|
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||||
find_package (PythonInterp REQUIRED)
|
if (BUILDPYTHON3)
|
||||||
if (${PYTHONINTERP_FOUND})
|
set (PYTHONBUILD_VERSION 3)
|
||||||
enable_testing ()
|
else ()
|
||||||
add_subdirectory (tests)
|
set (PYTHONBUILD_VERSION 2.7)
|
||||||
endif ()
|
endif ()
|
||||||
|
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
|
include_directories(${PYTHON_INCLUDE_PATH})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (BUILDTESTS)
|
||||||
|
enable_testing ()
|
||||||
|
add_subdirectory (tests)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
find_program (NODE_EXECUTABLE NAMES node
|
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
|
||||||
|
macro(add_include_dir dir)
|
||||||
|
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
|
||||||
|
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
|
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||||
HINTS
|
HINTS
|
||||||
$ENV{NODE_DIR}
|
$ENV{NODE_DIR}
|
||||||
PATH_SUFFIXES bin
|
PATH_SUFFIXES bin
|
||||||
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
|
|||||||
|
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
# If compat-libuv package exists, it must be at start of include path
|
||||||
PATHS /usr/include/nodejs /usr/local/include/nodejs)
|
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
|
||||||
|
if (UV_ROOT_DIR)
|
||||||
|
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||||
|
add_include_dir(${UV_ROOT_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
set (NODE_INCLUDE_DIRS
|
# Now look for node. Flag an error if not found
|
||||||
${NODE_ROOT_DIR}/src
|
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
||||||
${NODE_ROOT_DIR}/node
|
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
if (NODE_ROOT_DIR)
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
||||||
|
else()
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - node.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check that v8.h is in NODEJS_INCLUDE_DIRS
|
||||||
|
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||||
|
if (NOT V8_ROOT_DIR)
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - v8.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check that uv.h is in NODEJS_INCLUDE_DIRS
|
||||||
|
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||||
|
if (NOT UV_ROOT_DIR)
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - uv.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
||||||
|
NODEJS_EXECUTABLE
|
||||||
|
NODEJS_INCLUDE_DIRS
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package_handle_standard_args (Node DEFAULT_MSG
|
if (NODEJS_EXECUTABLE)
|
||||||
NODE_EXECUTABLE
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||||
NODE_INCLUDE_DIRS
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NODE_EXECUTABLE)
|
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
|
||||||
OUTPUT_VARIABLE _VERSION
|
OUTPUT_VARIABLE _VERSION
|
||||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||||
OUTPUT_VARIABLE _V8_VERSION
|
OUTPUT_VARIABLE _V8_VERSION
|
||||||
RESULT_VARIABLE _V8_RESULT)
|
RESULT_VARIABLE _V8_RESULT)
|
||||||
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
||||||
@ -55,7 +87,11 @@ if (NODE_EXECUTABLE)
|
|||||||
set (V8_VERSION_STRING "3.28.72")
|
set (V8_VERSION_STRING "3.28.72")
|
||||||
message ("defaulted to node 0.10.30")
|
message ("defaulted to node 0.10.30")
|
||||||
endif ()
|
endif ()
|
||||||
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
|
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
||||||
|
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
||||||
|
message ("INFO - Node version is " ${NODE_VERSION_STRING})
|
||||||
|
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
|
||||||
|
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
mark_as_advanced (NODE_EXECUTABLE)
|
mark_as_advanced (NODE_EXECUTABLE)
|
||||||
|
BIN
docs/images/ssd1351.jpg
Normal file
BIN
docs/images/ssd1351.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -10,7 +10,7 @@ macro(get_module_name example_name module_name)
|
|||||||
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
|
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
|
||||||
set (${module_name} "gas")
|
set (${module_name} "gas")
|
||||||
else()
|
else()
|
||||||
set(${module_name} ${example_name})
|
set(${module_name} ${example_name})
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -25,25 +25,25 @@ macro(add_custom_example example_bin example_src example_module_list)
|
|||||||
if (MODULE_LIST)
|
if (MODULE_LIST)
|
||||||
list(FIND MODULE_LIST ${module} index)
|
list(FIND MODULE_LIST ${module} index)
|
||||||
if (${index} EQUAL -1)
|
if (${index} EQUAL -1)
|
||||||
set(found_all_modules FALSE)
|
set(found_all_modules FALSE)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
if (found_all_modules)
|
if (found_all_modules)
|
||||||
add_executable (${example_bin} ${example_src})
|
add_executable (${example_bin} ${example_src})
|
||||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
foreach (module ${example_module_list})
|
foreach (module ${example_module_list})
|
||||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||||
include_directories (${module_dir})
|
include_directories (${module_dir})
|
||||||
if (${module} STREQUAL "lcd")
|
if (${module} STREQUAL "lcd")
|
||||||
set(module "i2clcd")
|
set(module "i2clcd")
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries (${example_bin} ${module})
|
target_link_libraries (${example_bin} ${module})
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
else()
|
||||||
MESSAGE(INFO " Ignored ${example_bin}")
|
MESSAGE(INFO " Ignored ${example_bin}")
|
||||||
set (example_bin "")
|
set (example_bin "")
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
@ -56,13 +56,13 @@ macro(add_example example_name)
|
|||||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
||||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
||||||
AND EXISTS ${module_dir}
|
AND EXISTS ${module_dir}
|
||||||
AND IS_DIRECTORY ${module_dir})
|
AND IS_DIRECTORY ${module_dir})
|
||||||
add_custom_example(${example_bin} ${example_src} ${module_name})
|
add_custom_example(${example_bin} ${example_src} ${module_name})
|
||||||
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
|
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
|
||||||
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
|
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
|
||||||
if (EXISTS ${grove_module_path})
|
if (EXISTS ${grove_module_path})
|
||||||
include_directories(${grove_module_path})
|
include_directories(${grove_module_path})
|
||||||
target_link_libraries (${example_bin} ${example_name})
|
target_link_libraries (${example_bin} ${example_name})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
@ -239,6 +239,10 @@ add_example (hdxxvxta)
|
|||||||
add_example (rhusb)
|
add_example (rhusb)
|
||||||
add_example (apds9930)
|
add_example (apds9930)
|
||||||
add_example (kxcjk1013)
|
add_example (kxcjk1013)
|
||||||
|
add_example (ssd1351)
|
||||||
|
if (HAVE_FIRMATA)
|
||||||
|
add_example (curieimu)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# These are special cases where you specify example binary, source file and module(s)
|
# These are special cases where you specify example binary, source file and module(s)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||||
|
81
examples/c++/curieimu.cxx
Normal file
81
examples/c++/curieimu.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 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 "curieimu.hpp"
|
||||||
|
#include "mraa.h"
|
||||||
|
#include "mraa/firmata.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
mraa_init();
|
||||||
|
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
upm::CurieImu* sensor = new upm::CurieImu();
|
||||||
|
|
||||||
|
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
||||||
|
|
||||||
|
sensor->updateAccel();
|
||||||
|
int x = sensor->getAccelX(),
|
||||||
|
y = sensor->getAccelY(),
|
||||||
|
z = sensor->getAccelZ();
|
||||||
|
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||||
|
|
||||||
|
sensor->updateGyro();
|
||||||
|
int a = sensor->getGyroX(),
|
||||||
|
b = sensor->getGyroY(),
|
||||||
|
c = sensor->getGyroZ();
|
||||||
|
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
||||||
|
|
||||||
|
int axis, direction;
|
||||||
|
sensor->enableShockDetection(true);
|
||||||
|
for(int i=0; i<300; i++) {
|
||||||
|
if (sensor->isShockDetected()) {
|
||||||
|
sensor->getNextShock();
|
||||||
|
axis = sensor->getAxis();
|
||||||
|
direction = sensor->getDirection();
|
||||||
|
printf("shock data is: %d, %d\n", axis, direction);
|
||||||
|
}
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
sensor->updateMotion();
|
||||||
|
int m = sensor->getAccelX(),
|
||||||
|
n = sensor->getAccelY(),
|
||||||
|
o = sensor->getAccelZ(),
|
||||||
|
p = sensor->getGyroX(),
|
||||||
|
q = sensor->getGyroY(),
|
||||||
|
r = sensor->getGyroZ();
|
||||||
|
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
61
examples/c++/ssd1351.cxx
Normal file
61
examples/c++/ssd1351.cxx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "mraa.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "ssd1351.h"
|
||||||
|
|
||||||
|
#define BLACK 0x0000
|
||||||
|
#define WHITE 0xFFFF
|
||||||
|
#define INTEL_BLUE 0x0BF8
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Define colors (16-bit RGB on 5/6/5 bits)
|
||||||
|
int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
|
||||||
|
0x7800, 0x780F, 0x7BE0, 0xC618,
|
||||||
|
0x7BEF, 0x001F, 0x07E0, 0x07FF,
|
||||||
|
0xF800, 0xF81F, 0xFFE0, 0xFFFF};
|
||||||
|
//! [Interesting]
|
||||||
|
// Initialize display with pins
|
||||||
|
// oc = 0, dc = 1, r = 2, si = 11, cl = 13
|
||||||
|
upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
|
||||||
|
|
||||||
|
// Test lines pixel by pixel
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT; i++) {
|
||||||
|
for(int j = 0; j < SSD1351WIDTH; j++) {
|
||||||
|
display->drawPixel(i, j, colors[i/8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test rectangles
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test circles
|
||||||
|
display->fillScreen(0x2104);
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test Text
|
||||||
|
display->fillScreen(INTEL_BLUE);
|
||||||
|
display->setTextColor(WHITE, INTEL_BLUE);
|
||||||
|
display->setTextSize(4);
|
||||||
|
display->setCursor(7, 30);
|
||||||
|
display->print("Intel");
|
||||||
|
display->setCursor(5, 70);
|
||||||
|
display->print("IoTDK");
|
||||||
|
display->refresh();
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
62
examples/java/Ad8232Example.java
Normal file
62
examples/java/Ad8232Example.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 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 upm_ad8232.AD8232;
|
||||||
|
|
||||||
|
public class Ad8232Example {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_ad8232");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||||
|
// and an analog pin, 0 (OUTPUT)
|
||||||
|
AD8232 ad8232 = new AD8232(10, 11, 0);
|
||||||
|
while(true){
|
||||||
|
// Output the raw numbers from the ADC, for plotting elsewhere.
|
||||||
|
// A return of 0 indicates a Lead Off (LO) condition.
|
||||||
|
// In theory, this data could be fed to software like Processing
|
||||||
|
// (https://www.processing.org/) to plot the data just like an
|
||||||
|
// EKG you would see in a hospital.
|
||||||
|
System.out.println(ad8232.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following error has occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -101,6 +101,10 @@ add_example(WaterLevelSensor waterlevel)
|
|||||||
add_example(WT5001Sample wt5001)
|
add_example(WT5001Sample wt5001)
|
||||||
add_example(YG1006Sample yg1006)
|
add_example(YG1006Sample yg1006)
|
||||||
add_example(ZFM20Sample zfm20)
|
add_example(ZFM20Sample zfm20)
|
||||||
|
add_example(Ad8232Example ad8232)
|
||||||
|
add_example(Gp2y0aExample gp2y0a)
|
||||||
|
add_example(Th02Example th02)
|
||||||
|
add_example(FlexSensorExample flex)
|
||||||
|
|
||||||
|
|
||||||
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
||||||
|
41
examples/java/FlexSensorExample.java
Normal file
41
examples/java/FlexSensorExample.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import upm_flex.Flex;
|
||||||
|
|
||||||
|
public class FlexSensorExample {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_flex");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with a Spectra Symbol flex sensor.
|
||||||
|
// We attached a 22K resistor to a breadboard,
|
||||||
|
// with 1 end attached to GND and the other connected to
|
||||||
|
// both the flex sensor and A0.
|
||||||
|
// The flex sensor was connected on 1 pin to the 22K resistor and A0
|
||||||
|
// and on the other pin to 5V.
|
||||||
|
|
||||||
|
// Instantiate a Flex sensor on analog pin A0
|
||||||
|
Flex flex = new Flex(0);
|
||||||
|
while(true){
|
||||||
|
System.out.println("Flex Sensor value is: "+flex.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
examples/java/Gp2y0aExample.java
Normal file
68
examples/java/Gp2y0aExample.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 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 upm_gp2y0a.GP2Y0A;
|
||||||
|
|
||||||
|
public class Gp2y0aExample {
|
||||||
|
|
||||||
|
public static final float GP2Y0A_AREF = 5;
|
||||||
|
public static final short SAMPLES_PER_QUERY = 20;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_gp2y0a");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Note, for the Grove 80cm version of this sensor, due to the way
|
||||||
|
// it is wired, you need to plug this into the A0 port, where it
|
||||||
|
// will use the available A1 pin for data.
|
||||||
|
|
||||||
|
// Instantiate a GP2Y0A on analog pin A1
|
||||||
|
GP2Y0A gp2y0a = new GP2Y0A(1);
|
||||||
|
|
||||||
|
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
|
||||||
|
// the measured voltage will probably not exceed 3.3 volts.
|
||||||
|
// Every second, print the averaged voltage value (averaged over 20 samples).
|
||||||
|
while(true){
|
||||||
|
System.out.println("AREF: " + GP2Y0A_AREF + "\t, Voltage Value (Higher means Closer): "+ gp2y0a.value(GP2Y0A_AREF, SAMPLES_PER_QUERY));
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
examples/java/Th02Example.java
Normal file
59
examples/java/Th02Example.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 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 upm_th02.TH02;
|
||||||
|
|
||||||
|
public class Th02Example {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_th02");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
float temperature = 0;
|
||||||
|
float humidity = 0;
|
||||||
|
|
||||||
|
TH02 sensor = new TH02();
|
||||||
|
while(true){
|
||||||
|
temperature = sensor.getTemperature();
|
||||||
|
humidity = sensor.getHumidity();
|
||||||
|
System.out.println("Temperature = "+temperature+", Humidity = "+humidity);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception has occured: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
examples/javascript/curieimu.js
Normal file
52
examples/javascript/curieimu.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Copyright (c) 2016 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var mraa = require('mraa');
|
||||||
|
console.log('MRAA Version: ' + mraa.getVersion());
|
||||||
|
|
||||||
|
// open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
var curieImu = require('jsupm_curieimu');
|
||||||
|
var myCurie = new curieImu.CurieImu();
|
||||||
|
|
||||||
|
var outputStr;
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
myCurie.updateAccel();
|
||||||
|
outputStr = "accel: x " + myCurie.getAccelX()
|
||||||
|
+ " - y " + myCurie.getAccelY()
|
||||||
|
+ " - z " + myCurie.getAccelZ();
|
||||||
|
console.log(outputStr);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// Print message when exiting
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
console.log("Exiting");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
56
examples/python/curieimu.py
Normal file
56
examples/python/curieimu.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Author: Ron Evans (@deadprogram)
|
||||||
|
# Copyright (c) 2016 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 mraa
|
||||||
|
print (mraa.getVersion())
|
||||||
|
|
||||||
|
# open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_curieimu as curieimu
|
||||||
|
sensor = curieimu.CurieImu()
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
sensor.updateAccel();
|
||||||
|
|
||||||
|
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||||
|
sensor.getAccelX(), sensor.getAccelY(),
|
||||||
|
sensor.getAccelZ())
|
||||||
|
print outputStr
|
||||||
|
|
||||||
|
time.sleep(1)
|
@ -46,16 +46,28 @@ endmacro()
|
|||||||
|
|
||||||
macro(upm_SWIG_NODE)
|
macro(upm_SWIG_NODE)
|
||||||
if (BUILDSWIGNODE AND BUILDSWIG)
|
if (BUILDSWIGNODE AND BUILDSWIG)
|
||||||
|
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
|
||||||
|
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
|
||||||
|
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
|
||||||
|
# we hack together from our findnode module.
|
||||||
|
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
while (V8_VERSION_HEX_length LESS 8)
|
||||||
|
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
endwhile ()
|
||||||
|
|
||||||
|
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
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_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
||||||
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||||
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${NODE_INCLUDE_DIRS}"
|
"${NODE_INCLUDE_DIRS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties (jsupm_${libname} PROPERTIES
|
set_target_properties (jsupm_${libname} PROPERTIES
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}"
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
SUFFIX ".node"
|
SUFFIX ".node"
|
||||||
)
|
)
|
||||||
@ -67,10 +79,24 @@ macro(upm_SWIG_NODE)
|
|||||||
endif()
|
endif()
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||||
|
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
|
||||||
|
endif ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
|
||||||
|
else ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
|
||||||
|
endif ()
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
|
||||||
|
endif ()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
createpackagejson(${libname})
|
createpackagejson(${libname})
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -139,30 +165,25 @@ macro(upm_doxygen)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
if (SWIG_FOUND)
|
if (SWIG_FOUND)
|
||||||
if(BUILDSWIGPYTHON)
|
if (BUILDSWIGNODE)
|
||||||
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)
|
|
||||||
if(NOT NODE_FOUND)
|
if(NOT NODE_FOUND)
|
||||||
find_package(Node)
|
find_package(Node)
|
||||||
endif()
|
endif()
|
||||||
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
||||||
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
find_path (NODE_ROOT_DIR "node/node.h")
|
find_path (NODE_ROOT_DIR "include/node/node.h")
|
||||||
set (NODE_INCLUDE_DIRS
|
set (NODE_INCLUDE_DIRS
|
||||||
${NODE_ROOT_DIR}/src
|
${NODE_ROOT_DIR}/include/src
|
||||||
${NODE_ROOT_DIR}/node
|
${NODE_ROOT_DIR}/include/node
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
${NODE_ROOT_DIR}/include/deps/v8/include
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
${NODE_ROOT_DIR}/include/deps/uv/include
|
||||||
)
|
)
|
||||||
macro(createpackagejson)
|
macro(createpackagejson)
|
||||||
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
endif(BUILDSWIGNODE)
|
endif(BUILDSWIGNODE)
|
||||||
|
11
src/curieimu/CMakeLists.txt
Normal file
11
src/curieimu/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
include (CheckFunctionExists)
|
||||||
|
include (CheckLibraryExists)
|
||||||
|
include (CheckIncludeFiles)
|
||||||
|
check_library_exists (${MRAA_LIBRARIES} mraa_firmata_init "" HAVE_FIRMATA)
|
||||||
|
if (HAVE_FIRMATA)
|
||||||
|
set (libname "curieimu")
|
||||||
|
set (libdescription "upm Curie IMU via Firmata")
|
||||||
|
set (module_src ${libname}.cpp)
|
||||||
|
set (module_h ${libname}.hpp)
|
||||||
|
upm_module_init ()
|
||||||
|
endif ()
|
458
src/curieimu/curieimu.cpp
Normal file
458
src/curieimu/curieimu.cpp
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 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 <string>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
static CurieImu* awaitingReponse;
|
||||||
|
|
||||||
|
CurieImu::CurieImu (int subplatformoffset)
|
||||||
|
{
|
||||||
|
m_firmata = mraa_firmata_init(FIRMATA_CURIE_IMU);
|
||||||
|
if (m_firmata == NULL) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_firmata_init() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_mutex_init(&m_responseLock, NULL)) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": pthread_mutex_init(m_responseLock) failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_cond_init(&m_responseCond, NULL)) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": pthread_cond_init(m_responseCond) failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurieImu::~CurieImu()
|
||||||
|
{
|
||||||
|
pthread_mutex_destroy(&m_responseLock);
|
||||||
|
pthread_cond_destroy(&m_responseCond);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::lock()
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::unlock()
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::waitForResponse()
|
||||||
|
{
|
||||||
|
awaitingReponse = this;
|
||||||
|
pthread_cond_wait(&m_responseCond, &m_responseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::proceed()
|
||||||
|
{
|
||||||
|
pthread_cond_broadcast(&m_responseCond);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::setResults(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
m_results = new char(length);
|
||||||
|
memcpy((void*)m_results, (void*)buf, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handles a single syncronous response being returned from Firmata
|
||||||
|
*
|
||||||
|
* @param buffer the data beinig returned from Firmata
|
||||||
|
* @param length length of results buffer
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
handleSyncResponse(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
awaitingReponse->setResults(buf, length);
|
||||||
|
awaitingReponse->proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handles asyncronous responses being returned from Firmata
|
||||||
|
*
|
||||||
|
* @param buffer the data beinig returned from Firmata
|
||||||
|
* @param length length of results buffer
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
handleAsyncResponses(uint8_t* buf, int length)
|
||||||
|
{
|
||||||
|
awaitingReponse->setResults(buf, length);
|
||||||
|
awaitingReponse->processResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::processResponse()
|
||||||
|
{
|
||||||
|
switch(m_results[2]) {
|
||||||
|
case FIRMATA_CURIE_IMU_SHOCK_DETECT:
|
||||||
|
{
|
||||||
|
IMUDataItem* item = new IMUDataItem();
|
||||||
|
item->axis = m_results[3];
|
||||||
|
item->direction = m_results[4];
|
||||||
|
m_shockData.push(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FIRMATA_CURIE_IMU_STEP_COUNTER:
|
||||||
|
{
|
||||||
|
int count = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_stepData.push(count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FIRMATA_CURIE_IMU_TAP_DETECT:
|
||||||
|
{
|
||||||
|
IMUDataItem* item = new IMUDataItem();
|
||||||
|
item->axis = m_results[3];
|
||||||
|
item->direction = m_results[4];
|
||||||
|
m_tapData.push(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getAccel()
|
||||||
|
{
|
||||||
|
return &m_accel[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelX()
|
||||||
|
{
|
||||||
|
return m_accel[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelY()
|
||||||
|
{
|
||||||
|
return m_accel[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelZ()
|
||||||
|
{
|
||||||
|
return m_accel[Z];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getGyro()
|
||||||
|
{
|
||||||
|
return &m_gyro[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroX()
|
||||||
|
{
|
||||||
|
return m_gyro[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroY()
|
||||||
|
{
|
||||||
|
return m_gyro[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroZ()
|
||||||
|
{
|
||||||
|
return m_gyro[Z];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t*
|
||||||
|
CurieImu::getMotion()
|
||||||
|
{
|
||||||
|
return &m_motion[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateAccel()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_ACCEL;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateGyro()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_GYRO;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::updateMotion()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_MOTION;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
m_motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
m_motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
|
m_motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
m_motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
||||||
|
m_motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
||||||
|
m_motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_accel[i] = m_motion[i];
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_gyro[i] = m_motion[i+3];
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getTemperature()
|
||||||
|
{
|
||||||
|
char message[4];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_READ_TEMP;
|
||||||
|
message[3] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleSyncResponse);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 4);
|
||||||
|
|
||||||
|
waitForResponse();
|
||||||
|
|
||||||
|
int16_t result;
|
||||||
|
result = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
|
result += ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7)) << 8;
|
||||||
|
|
||||||
|
delete m_results;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAxis()
|
||||||
|
{
|
||||||
|
return m_axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getDirection()
|
||||||
|
{
|
||||||
|
return m_direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableShockDetection(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_SHOCK_DETECT;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isShockDetected()
|
||||||
|
{
|
||||||
|
return (m_shockData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::getNextShock()
|
||||||
|
{
|
||||||
|
if (m_shockData.size() > 0) {
|
||||||
|
IMUDataItem* item = m_shockData.front();
|
||||||
|
m_axis = item->axis;
|
||||||
|
m_direction = item->direction;
|
||||||
|
m_shockData.pop();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableStepCounter(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_STEP_COUNTER;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isStepDetected()
|
||||||
|
{
|
||||||
|
return (m_stepData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getStepCount()
|
||||||
|
{
|
||||||
|
int16_t count = 0;
|
||||||
|
if (m_stepData.size() > 0) {
|
||||||
|
count = m_stepData.front();
|
||||||
|
m_stepData.pop();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::enableTapDetection(bool enable)
|
||||||
|
{
|
||||||
|
char message[5];
|
||||||
|
message[0] = FIRMATA_START_SYSEX;
|
||||||
|
message[1] = FIRMATA_CURIE_IMU;
|
||||||
|
message[2] = FIRMATA_CURIE_IMU_TAP_DETECT;
|
||||||
|
message[3] = enable;
|
||||||
|
message[4] = FIRMATA_END_SYSEX;
|
||||||
|
|
||||||
|
lock();
|
||||||
|
|
||||||
|
mraa_firmata_response_stop(m_firmata);
|
||||||
|
mraa_firmata_response(m_firmata, handleAsyncResponses);
|
||||||
|
mraa_firmata_write_sysex(m_firmata, &message[0], 5);
|
||||||
|
|
||||||
|
awaitingReponse = this;
|
||||||
|
unlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CurieImu::isTapDetected()
|
||||||
|
{
|
||||||
|
return (m_tapData.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CurieImu::getNextTap()
|
||||||
|
{
|
||||||
|
if (m_tapData.size() > 0) {
|
||||||
|
IMUDataItem* item = m_tapData.front();
|
||||||
|
m_axis = item->axis;
|
||||||
|
m_direction = item->direction;
|
||||||
|
m_tapData.pop();
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
307
src/curieimu/curieimu.hpp
Normal file
307
src/curieimu/curieimu.hpp
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 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 <mraa/firmata.h>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CurieIMU sensor for Genuino 101 running Firmata
|
||||||
|
* @defgroup curieimu libupm-curieimu
|
||||||
|
* @ingroup firmata
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library curieimu
|
||||||
|
* @sensor curieimu
|
||||||
|
* @comname Curie IMU sensor over Genuino 101 running Firmata
|
||||||
|
* @altname Curie Firmata IMU
|
||||||
|
* @type firmata
|
||||||
|
* @man firmata imu genuino
|
||||||
|
* @con firmata
|
||||||
|
*
|
||||||
|
* @brief API for the Curie IMU via Firmata
|
||||||
|
*
|
||||||
|
* Curie IMU is a 6-axxis acclerometer
|
||||||
|
*
|
||||||
|
* This module has been tested on an Genuino 101 running ConfigurableFirmata with CurieIMU
|
||||||
|
*
|
||||||
|
* @snippet curieimu.cxx Interesting
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define FIRMATA_START_SYSEX 0xF0
|
||||||
|
#define FIRMATA_END_SYSEX 0xF7
|
||||||
|
#define FIRMATA_CURIE_IMU 0x11
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_ACCEL 0x00
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_GYRO 0x01
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_TEMP 0x02
|
||||||
|
#define FIRMATA_CURIE_IMU_SHOCK_DETECT 0x03
|
||||||
|
#define FIRMATA_CURIE_IMU_STEP_COUNTER 0x04
|
||||||
|
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
|
||||||
|
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
|
||||||
|
|
||||||
|
#define X 0
|
||||||
|
#define Y 1
|
||||||
|
#define Z 2
|
||||||
|
|
||||||
|
struct IMUDataItem {
|
||||||
|
int axis;
|
||||||
|
int direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CurieImu {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a CurieImu object
|
||||||
|
*
|
||||||
|
* @param subplatformoffset Subplatform offset
|
||||||
|
*/
|
||||||
|
CurieImu (int subplatform_offset=512);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for CurieImu object
|
||||||
|
*/
|
||||||
|
~CurieImu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the latest accelerometer readings by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the latest gyroscope readings by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the both the latest accelerometer & gyroscope readings
|
||||||
|
* by calling Firmata
|
||||||
|
*/
|
||||||
|
void updateMotion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading X, Y, and Z axis
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t* getAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read gyroscope X, Y, and Z axis
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t* getGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the internal temperature
|
||||||
|
*
|
||||||
|
* @return 16-bit integer containing the scaled temperature reading
|
||||||
|
*/
|
||||||
|
int16_t getTemperature();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
|
||||||
|
*
|
||||||
|
* @return pointer to array with X-axis, Y-axis & Z-axis values for
|
||||||
|
* accelerometer, and then X-axis, Y-axis & Z-axis values for
|
||||||
|
* gyroscope
|
||||||
|
*/
|
||||||
|
int16_t* getMotion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last shock or tap axis reading
|
||||||
|
*
|
||||||
|
* @return axis value
|
||||||
|
*/
|
||||||
|
int16_t getAxis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last shock or tap direction reading
|
||||||
|
*
|
||||||
|
* @return direction value
|
||||||
|
*/
|
||||||
|
int16_t getDirection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns shock detection notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableShockDetection(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a shock detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed shock notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isShockDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets shock detect data from queue. Then m_axis gets axis data, and
|
||||||
|
* m_direction gets direction data
|
||||||
|
*/
|
||||||
|
void getNextShock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns step counter notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableStepCounter(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a step detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed step notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isStepDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets step count data from queue
|
||||||
|
*
|
||||||
|
* @return the total number of steps taken
|
||||||
|
*/
|
||||||
|
int16_t getStepCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns tap detection notifications on/off
|
||||||
|
*
|
||||||
|
* @param enable enables/disables notifications
|
||||||
|
*/
|
||||||
|
void enableTapDetection(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has there been a tap detected?
|
||||||
|
*
|
||||||
|
* @return true if any unprocessed tap notifications are in the queue
|
||||||
|
*/
|
||||||
|
bool isTapDetected();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tap detect data from queue. Then m_axis gets axis data, and
|
||||||
|
* m_direction gets direction data
|
||||||
|
*/
|
||||||
|
void getNextTap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks responses from Firmata
|
||||||
|
*/
|
||||||
|
void lock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlocks responses from Firmata
|
||||||
|
*/
|
||||||
|
void unlock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for a response from Firmata before proceeding
|
||||||
|
*/
|
||||||
|
void waitForResponse();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proceed with original function call now that response
|
||||||
|
* from Firmata has been received
|
||||||
|
*/
|
||||||
|
void proceed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set results being returned from Firmata for processing
|
||||||
|
*
|
||||||
|
* @param buf is the buffer
|
||||||
|
* @param length is the length of results buffer
|
||||||
|
*/
|
||||||
|
void setResults(uint8_t* buf, int length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes asyncronous responses returned from Firmata
|
||||||
|
*/
|
||||||
|
void processResponse();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa_firmata_context m_firmata;
|
||||||
|
pthread_mutex_t m_responseLock;
|
||||||
|
pthread_cond_t m_responseCond;
|
||||||
|
char* m_results;
|
||||||
|
|
||||||
|
std::queue<IMUDataItem*> m_shockData;
|
||||||
|
std::queue<int> m_stepData;
|
||||||
|
std::queue<IMUDataItem*> m_tapData;
|
||||||
|
|
||||||
|
int16_t m_accel[3];
|
||||||
|
int16_t m_gyro[3];
|
||||||
|
int16_t m_motion[6];
|
||||||
|
|
||||||
|
int16_t m_axis;
|
||||||
|
int16_t m_direction;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
42
src/curieimu/javaupm_curieimu.i
Normal file
42
src/curieimu/javaupm_curieimu.i
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
%module javaupm_curieimu
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(jni) int16_t* "jshortArray"
|
||||||
|
%typemap(jstype) int16_t* "short[]"
|
||||||
|
%typemap(jtype) int16_t* "short[]"
|
||||||
|
|
||||||
|
%typemap(javaout) int16_t* {
|
||||||
|
return $jnicall;
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getAccel {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getGyro {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 3);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 3, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) int16_t *getMotion {
|
||||||
|
$result = JCALL1(NewShortArray, jenv, 6);
|
||||||
|
JCALL4(SetShortArrayRegion, jenv, $result, 0, 6, (jshort*)$1);
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "curieimu.hpp"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_curieimu");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
15
src/curieimu/jsupm_curieimu.i
Normal file
15
src/curieimu/jsupm_curieimu.i
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
%module jsupm_curieimu
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "../carrays_int16_t.i"
|
||||||
|
|
||||||
|
// Adding this typemap because SWIG is converting int16 into a short by default
|
||||||
|
// This forces SWIG to convert it correctly
|
||||||
|
%typemap(out) int16_t* {
|
||||||
|
jsresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "curieimu.hpp"
|
21
src/curieimu/pyupm_curieimu.i
Normal file
21
src/curieimu/pyupm_curieimu.i
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_curieimu
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "../carrays_int16_t.i"
|
||||||
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
#ifdef DOXYGEN
|
||||||
|
%include "curieupm_doc.i"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
%typemap(out) int16_t* {
|
||||||
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_int16Array, 0 | 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "curieimu.hpp"
|
||||||
|
%{
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
%}
|
5
src/ssd1351/CMakeLists.txt
Normal file
5
src/ssd1351/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "ssd1351")
|
||||||
|
set (libdescription "libupm SSD1351 SPI LCD")
|
||||||
|
set (module_src gfx.cxx ssd1351.cxx)
|
||||||
|
set (module_h gfx.h ssd1351.h)
|
||||||
|
upm_module_init()
|
218
src/ssd1351/gfx.cxx
Normal file
218
src/ssd1351/gfx.cxx
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 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 "gfx.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
GFX::GFX (int width, int height) : m_width(width), m_height(height),
|
||||||
|
m_textSize(1), m_textColor(0xFFFF), m_textBGColor(0x0000),
|
||||||
|
m_cursorX(0), m_cursorY(0), m_font(font) {
|
||||||
|
}
|
||||||
|
|
||||||
|
GFX::~GFX () {
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::fillScreen (uint16_t color) {
|
||||||
|
fillRect(0, 0, m_width, m_height, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
|
||||||
|
for (int16_t i=x; i<x+w; i++) {
|
||||||
|
drawFastVLine(i, y, h, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
|
||||||
|
drawLine(x, y, x, y+h-1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
|
||||||
|
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
|
||||||
|
|
||||||
|
if (steep) {
|
||||||
|
swap(x0, y0);
|
||||||
|
swap(x1, y1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x0 > x1) {
|
||||||
|
swap(x0, x1);
|
||||||
|
swap(y0, y1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t dx, dy;
|
||||||
|
dx = x1 - x0;
|
||||||
|
dy = abs (y1 - y0);
|
||||||
|
|
||||||
|
int16_t err = dx / 2;
|
||||||
|
int16_t ystep;
|
||||||
|
|
||||||
|
if (y0 < y1) {
|
||||||
|
ystep = 1;
|
||||||
|
} else {
|
||||||
|
ystep = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; x0 <= x1; x0++) {
|
||||||
|
if (steep) {
|
||||||
|
drawPixel(y0, x0, color);
|
||||||
|
} else {
|
||||||
|
drawPixel(x0, y0, color);
|
||||||
|
}
|
||||||
|
err -= dy;
|
||||||
|
if (err < 0) {
|
||||||
|
y0 += ystep;
|
||||||
|
err += dx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
|
||||||
|
drawLine(x0, y0, x1, y1, color);
|
||||||
|
drawLine(x1, y1, x2, y2, color);
|
||||||
|
drawLine(x2, y2, x0, y0, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
|
||||||
|
int16_t f = 1 - r;
|
||||||
|
int16_t ddF_x = 1;
|
||||||
|
int16_t ddF_y = -2 * r;
|
||||||
|
int16_t x = 0;
|
||||||
|
int16_t y = r;
|
||||||
|
|
||||||
|
drawPixel(x0 , y0+r, color);
|
||||||
|
drawPixel(x0 , y0-r, color);
|
||||||
|
drawPixel(x0+r, y0 , color);
|
||||||
|
drawPixel(x0-r, y0 , color);
|
||||||
|
|
||||||
|
while (x<y) {
|
||||||
|
if (f >= 0) {
|
||||||
|
y--;
|
||||||
|
ddF_y += 2;
|
||||||
|
f += ddF_y;
|
||||||
|
}
|
||||||
|
x++;
|
||||||
|
|
||||||
|
ddF_x += 2;
|
||||||
|
f += ddF_x;
|
||||||
|
|
||||||
|
drawPixel(x0 + x, y0 + y, color);
|
||||||
|
drawPixel(x0 - x, y0 + y, color);
|
||||||
|
drawPixel(x0 + x, y0 - y, color);
|
||||||
|
drawPixel(x0 - x, y0 - y, color);
|
||||||
|
drawPixel(x0 + y, y0 + x, color);
|
||||||
|
drawPixel(x0 - y, y0 + x, color);
|
||||||
|
drawPixel(x0 + y, y0 - x, color);
|
||||||
|
drawPixel(x0 - y, y0 - x, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::setCursor (int16_t x, int16_t y) {
|
||||||
|
m_cursorX = x;
|
||||||
|
m_cursorY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::setTextColor (uint16_t textColor, uint16_t textBGColor) {
|
||||||
|
m_textColor = textColor;
|
||||||
|
m_textBGColor = textBGColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::setTextSize (uint8_t size) {
|
||||||
|
m_textSize = (size > 0) ? size : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::setTextWrap (uint8_t wrap) {
|
||||||
|
m_wrap = wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size) {
|
||||||
|
if( (x >= m_width) || // Clip right
|
||||||
|
(y >= m_height) || // Clip bottom
|
||||||
|
((x + 6 * size - 1) < 0) || // Clip left
|
||||||
|
((y + 8 * size - 1) < 0)) // Clip top
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int8_t i=0; i<6; i++ ) {
|
||||||
|
uint8_t line;
|
||||||
|
if (i == 5) {
|
||||||
|
line = 0x0;
|
||||||
|
} else {
|
||||||
|
line = *(m_font+(data * 5)+i);
|
||||||
|
for (int8_t j = 0; j<8; j++) {
|
||||||
|
if (line & 0x1) {
|
||||||
|
if (size == 1) // default size
|
||||||
|
drawPixel (x+i, y+j, color);
|
||||||
|
else { // big size
|
||||||
|
fillRect (x+(i*size), y+(j*size), size, size, color);
|
||||||
|
}
|
||||||
|
} else if (bg != color) {
|
||||||
|
if (size == 1) // default size
|
||||||
|
drawPixel (x+i, y+j, bg);
|
||||||
|
else { // big size
|
||||||
|
fillRect (x+i*size, y+j*size, size, size, bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GFX::print (std::string msg) {
|
||||||
|
int len = msg.length();
|
||||||
|
|
||||||
|
for (int idx = 0; idx < len; idx++) {
|
||||||
|
if (msg[idx] == '\n') {
|
||||||
|
m_cursorY += m_textSize * 8;
|
||||||
|
m_cursorX = 0;
|
||||||
|
} else if (msg[idx] == '\r') {
|
||||||
|
// skip em
|
||||||
|
} else {
|
||||||
|
drawChar(m_cursorX, m_cursorY, msg[idx], m_textColor, m_textBGColor, m_textSize);
|
||||||
|
m_cursorX += m_textSize * 6;
|
||||||
|
if (m_wrap && ((m_cursorX + m_textSize * 6) >= m_width)) {
|
||||||
|
m_cursorY += m_textSize * 8;
|
||||||
|
m_cursorX = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
453
src/ssd1351/gfx.h
Normal file
453
src/ssd1351/gfx.h
Normal file
@ -0,0 +1,453 @@
|
|||||||
|
/*
|
||||||
|
* Authors: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 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 <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define swap(a, b) { int16_t t = a; a = b; b = t; }
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
const unsigned char font[] = {
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
|
||||||
|
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
|
||||||
|
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
|
||||||
|
0x18, 0x3C, 0x7E, 0x3C, 0x18,
|
||||||
|
0x1C, 0x57, 0x7D, 0x57, 0x1C,
|
||||||
|
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
|
||||||
|
0x00, 0x18, 0x3C, 0x18, 0x00,
|
||||||
|
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
|
||||||
|
0x00, 0x18, 0x24, 0x18, 0x00,
|
||||||
|
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
|
||||||
|
0x30, 0x48, 0x3A, 0x06, 0x0E,
|
||||||
|
0x26, 0x29, 0x79, 0x29, 0x26,
|
||||||
|
0x40, 0x7F, 0x05, 0x05, 0x07,
|
||||||
|
0x40, 0x7F, 0x05, 0x25, 0x3F,
|
||||||
|
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
|
||||||
|
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
|
||||||
|
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
|
||||||
|
0x14, 0x22, 0x7F, 0x22, 0x14,
|
||||||
|
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
|
||||||
|
0x06, 0x09, 0x7F, 0x01, 0x7F,
|
||||||
|
0x00, 0x66, 0x89, 0x95, 0x6A,
|
||||||
|
0x60, 0x60, 0x60, 0x60, 0x60,
|
||||||
|
0x94, 0xA2, 0xFF, 0xA2, 0x94,
|
||||||
|
0x08, 0x04, 0x7E, 0x04, 0x08,
|
||||||
|
0x10, 0x20, 0x7E, 0x20, 0x10,
|
||||||
|
0x08, 0x08, 0x2A, 0x1C, 0x08,
|
||||||
|
0x08, 0x1C, 0x2A, 0x08, 0x08,
|
||||||
|
0x1E, 0x10, 0x10, 0x10, 0x10,
|
||||||
|
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
|
||||||
|
0x30, 0x38, 0x3E, 0x38, 0x30,
|
||||||
|
0x06, 0x0E, 0x3E, 0x0E, 0x06,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x5F, 0x00, 0x00,
|
||||||
|
0x00, 0x07, 0x00, 0x07, 0x00,
|
||||||
|
0x14, 0x7F, 0x14, 0x7F, 0x14,
|
||||||
|
0x24, 0x2A, 0x7F, 0x2A, 0x12,
|
||||||
|
0x23, 0x13, 0x08, 0x64, 0x62,
|
||||||
|
0x36, 0x49, 0x56, 0x20, 0x50,
|
||||||
|
0x00, 0x08, 0x07, 0x03, 0x00,
|
||||||
|
0x00, 0x1C, 0x22, 0x41, 0x00,
|
||||||
|
0x00, 0x41, 0x22, 0x1C, 0x00,
|
||||||
|
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
|
||||||
|
0x08, 0x08, 0x3E, 0x08, 0x08,
|
||||||
|
0x00, 0x80, 0x70, 0x30, 0x00,
|
||||||
|
0x08, 0x08, 0x08, 0x08, 0x08,
|
||||||
|
0x00, 0x00, 0x60, 0x60, 0x00,
|
||||||
|
0x20, 0x10, 0x08, 0x04, 0x02,
|
||||||
|
0x3E, 0x51, 0x49, 0x45, 0x3E,
|
||||||
|
0x00, 0x42, 0x7F, 0x40, 0x00,
|
||||||
|
0x72, 0x49, 0x49, 0x49, 0x46,
|
||||||
|
0x21, 0x41, 0x49, 0x4D, 0x33,
|
||||||
|
0x18, 0x14, 0x12, 0x7F, 0x10,
|
||||||
|
0x27, 0x45, 0x45, 0x45, 0x39,
|
||||||
|
0x3C, 0x4A, 0x49, 0x49, 0x31,
|
||||||
|
0x41, 0x21, 0x11, 0x09, 0x07,
|
||||||
|
0x36, 0x49, 0x49, 0x49, 0x36,
|
||||||
|
0x46, 0x49, 0x49, 0x29, 0x1E,
|
||||||
|
0x00, 0x00, 0x14, 0x00, 0x00,
|
||||||
|
0x00, 0x40, 0x34, 0x00, 0x00,
|
||||||
|
0x00, 0x08, 0x14, 0x22, 0x41,
|
||||||
|
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||||
|
0x00, 0x41, 0x22, 0x14, 0x08,
|
||||||
|
0x02, 0x01, 0x59, 0x09, 0x06,
|
||||||
|
0x3E, 0x41, 0x5D, 0x59, 0x4E,
|
||||||
|
0x7C, 0x12, 0x11, 0x12, 0x7C,
|
||||||
|
0x7F, 0x49, 0x49, 0x49, 0x36,
|
||||||
|
0x3E, 0x41, 0x41, 0x41, 0x22,
|
||||||
|
0x7F, 0x41, 0x41, 0x41, 0x3E,
|
||||||
|
0x7F, 0x49, 0x49, 0x49, 0x41,
|
||||||
|
0x7F, 0x09, 0x09, 0x09, 0x01,
|
||||||
|
0x3E, 0x41, 0x41, 0x51, 0x73,
|
||||||
|
0x7F, 0x08, 0x08, 0x08, 0x7F,
|
||||||
|
0x00, 0x41, 0x7F, 0x41, 0x00,
|
||||||
|
0x20, 0x40, 0x41, 0x3F, 0x01,
|
||||||
|
0x7F, 0x08, 0x14, 0x22, 0x41,
|
||||||
|
0x7F, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x7F, 0x02, 0x1C, 0x02, 0x7F,
|
||||||
|
0x7F, 0x04, 0x08, 0x10, 0x7F,
|
||||||
|
0x3E, 0x41, 0x41, 0x41, 0x3E,
|
||||||
|
0x7F, 0x09, 0x09, 0x09, 0x06,
|
||||||
|
0x3E, 0x41, 0x51, 0x21, 0x5E,
|
||||||
|
0x7F, 0x09, 0x19, 0x29, 0x46,
|
||||||
|
0x26, 0x49, 0x49, 0x49, 0x32,
|
||||||
|
0x03, 0x01, 0x7F, 0x01, 0x03,
|
||||||
|
0x3F, 0x40, 0x40, 0x40, 0x3F,
|
||||||
|
0x1F, 0x20, 0x40, 0x20, 0x1F,
|
||||||
|
0x3F, 0x40, 0x38, 0x40, 0x3F,
|
||||||
|
0x63, 0x14, 0x08, 0x14, 0x63,
|
||||||
|
0x03, 0x04, 0x78, 0x04, 0x03,
|
||||||
|
0x61, 0x59, 0x49, 0x4D, 0x43,
|
||||||
|
0x00, 0x7F, 0x41, 0x41, 0x41,
|
||||||
|
0x02, 0x04, 0x08, 0x10, 0x20,
|
||||||
|
0x00, 0x41, 0x41, 0x41, 0x7F,
|
||||||
|
0x04, 0x02, 0x01, 0x02, 0x04,
|
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x00, 0x03, 0x07, 0x08, 0x00,
|
||||||
|
0x20, 0x54, 0x54, 0x78, 0x40,
|
||||||
|
0x7F, 0x28, 0x44, 0x44, 0x38,
|
||||||
|
0x38, 0x44, 0x44, 0x44, 0x28,
|
||||||
|
0x38, 0x44, 0x44, 0x28, 0x7F,
|
||||||
|
0x38, 0x54, 0x54, 0x54, 0x18,
|
||||||
|
0x00, 0x08, 0x7E, 0x09, 0x02,
|
||||||
|
0x18, 0xA4, 0xA4, 0x9C, 0x78,
|
||||||
|
0x7F, 0x08, 0x04, 0x04, 0x78,
|
||||||
|
0x00, 0x44, 0x7D, 0x40, 0x00,
|
||||||
|
0x20, 0x40, 0x40, 0x3D, 0x00,
|
||||||
|
0x7F, 0x10, 0x28, 0x44, 0x00,
|
||||||
|
0x00, 0x41, 0x7F, 0x40, 0x00,
|
||||||
|
0x7C, 0x04, 0x78, 0x04, 0x78,
|
||||||
|
0x7C, 0x08, 0x04, 0x04, 0x78,
|
||||||
|
0x38, 0x44, 0x44, 0x44, 0x38,
|
||||||
|
0xFC, 0x18, 0x24, 0x24, 0x18,
|
||||||
|
0x18, 0x24, 0x24, 0x18, 0xFC,
|
||||||
|
0x7C, 0x08, 0x04, 0x04, 0x08,
|
||||||
|
0x48, 0x54, 0x54, 0x54, 0x24,
|
||||||
|
0x04, 0x04, 0x3F, 0x44, 0x24,
|
||||||
|
0x3C, 0x40, 0x40, 0x20, 0x7C,
|
||||||
|
0x1C, 0x20, 0x40, 0x20, 0x1C,
|
||||||
|
0x3C, 0x40, 0x30, 0x40, 0x3C,
|
||||||
|
0x44, 0x28, 0x10, 0x28, 0x44,
|
||||||
|
0x4C, 0x90, 0x90, 0x90, 0x7C,
|
||||||
|
0x44, 0x64, 0x54, 0x4C, 0x44,
|
||||||
|
0x00, 0x08, 0x36, 0x41, 0x00,
|
||||||
|
0x00, 0x00, 0x77, 0x00, 0x00,
|
||||||
|
0x00, 0x41, 0x36, 0x08, 0x00,
|
||||||
|
0x02, 0x01, 0x02, 0x04, 0x02,
|
||||||
|
0x3C, 0x26, 0x23, 0x26, 0x3C,
|
||||||
|
0x1E, 0xA1, 0xA1, 0x61, 0x12,
|
||||||
|
0x3A, 0x40, 0x40, 0x20, 0x7A,
|
||||||
|
0x38, 0x54, 0x54, 0x55, 0x59,
|
||||||
|
0x21, 0x55, 0x55, 0x79, 0x41,
|
||||||
|
0x21, 0x54, 0x54, 0x78, 0x41,
|
||||||
|
0x21, 0x55, 0x54, 0x78, 0x40,
|
||||||
|
0x20, 0x54, 0x55, 0x79, 0x40,
|
||||||
|
0x0C, 0x1E, 0x52, 0x72, 0x12,
|
||||||
|
0x39, 0x55, 0x55, 0x55, 0x59,
|
||||||
|
0x39, 0x54, 0x54, 0x54, 0x59,
|
||||||
|
0x39, 0x55, 0x54, 0x54, 0x58,
|
||||||
|
0x00, 0x00, 0x45, 0x7C, 0x41,
|
||||||
|
0x00, 0x02, 0x45, 0x7D, 0x42,
|
||||||
|
0x00, 0x01, 0x45, 0x7C, 0x40,
|
||||||
|
0xF0, 0x29, 0x24, 0x29, 0xF0,
|
||||||
|
0xF0, 0x28, 0x25, 0x28, 0xF0,
|
||||||
|
0x7C, 0x54, 0x55, 0x45, 0x00,
|
||||||
|
0x20, 0x54, 0x54, 0x7C, 0x54,
|
||||||
|
0x7C, 0x0A, 0x09, 0x7F, 0x49,
|
||||||
|
0x32, 0x49, 0x49, 0x49, 0x32,
|
||||||
|
0x32, 0x48, 0x48, 0x48, 0x32,
|
||||||
|
0x32, 0x4A, 0x48, 0x48, 0x30,
|
||||||
|
0x3A, 0x41, 0x41, 0x21, 0x7A,
|
||||||
|
0x3A, 0x42, 0x40, 0x20, 0x78,
|
||||||
|
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
|
||||||
|
0x39, 0x44, 0x44, 0x44, 0x39,
|
||||||
|
0x3D, 0x40, 0x40, 0x40, 0x3D,
|
||||||
|
0x3C, 0x24, 0xFF, 0x24, 0x24,
|
||||||
|
0x48, 0x7E, 0x49, 0x43, 0x66,
|
||||||
|
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
|
||||||
|
0xFF, 0x09, 0x29, 0xF6, 0x20,
|
||||||
|
0xC0, 0x88, 0x7E, 0x09, 0x03,
|
||||||
|
0x20, 0x54, 0x54, 0x79, 0x41,
|
||||||
|
0x00, 0x00, 0x44, 0x7D, 0x41,
|
||||||
|
0x30, 0x48, 0x48, 0x4A, 0x32,
|
||||||
|
0x38, 0x40, 0x40, 0x22, 0x7A,
|
||||||
|
0x00, 0x7A, 0x0A, 0x0A, 0x72,
|
||||||
|
0x7D, 0x0D, 0x19, 0x31, 0x7D,
|
||||||
|
0x26, 0x29, 0x29, 0x2F, 0x28,
|
||||||
|
0x26, 0x29, 0x29, 0x29, 0x26,
|
||||||
|
0x30, 0x48, 0x4D, 0x40, 0x20,
|
||||||
|
0x38, 0x08, 0x08, 0x08, 0x08,
|
||||||
|
0x08, 0x08, 0x08, 0x08, 0x38,
|
||||||
|
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
|
||||||
|
0x2F, 0x10, 0x28, 0x34, 0xFA,
|
||||||
|
0x00, 0x00, 0x7B, 0x00, 0x00,
|
||||||
|
0x08, 0x14, 0x2A, 0x14, 0x22,
|
||||||
|
0x22, 0x14, 0x2A, 0x14, 0x08,
|
||||||
|
0xAA, 0x00, 0x55, 0x00, 0xAA,
|
||||||
|
0xAA, 0x55, 0xAA, 0x55, 0xAA,
|
||||||
|
0x00, 0x00, 0x00, 0xFF, 0x00,
|
||||||
|
0x10, 0x10, 0x10, 0xFF, 0x00,
|
||||||
|
0x14, 0x14, 0x14, 0xFF, 0x00,
|
||||||
|
0x10, 0x10, 0xFF, 0x00, 0xFF,
|
||||||
|
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||||
|
0x14, 0x14, 0x14, 0xFC, 0x00,
|
||||||
|
0x14, 0x14, 0xF7, 0x00, 0xFF,
|
||||||
|
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||||
|
0x14, 0x14, 0xF4, 0x04, 0xFC,
|
||||||
|
0x14, 0x14, 0x17, 0x10, 0x1F,
|
||||||
|
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||||
|
0x14, 0x14, 0x14, 0x1F, 0x00,
|
||||||
|
0x10, 0x10, 0x10, 0xF0, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x1F, 0x10,
|
||||||
|
0x10, 0x10, 0x10, 0x1F, 0x10,
|
||||||
|
0x10, 0x10, 0x10, 0xF0, 0x10,
|
||||||
|
0x00, 0x00, 0x00, 0xFF, 0x10,
|
||||||
|
0x10, 0x10, 0x10, 0x10, 0x10,
|
||||||
|
0x10, 0x10, 0x10, 0xFF, 0x10,
|
||||||
|
0x00, 0x00, 0x00, 0xFF, 0x14,
|
||||||
|
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||||
|
0x00, 0x00, 0x1F, 0x10, 0x17,
|
||||||
|
0x00, 0x00, 0xFC, 0x04, 0xF4,
|
||||||
|
0x14, 0x14, 0x17, 0x10, 0x17,
|
||||||
|
0x14, 0x14, 0xF4, 0x04, 0xF4,
|
||||||
|
0x00, 0x00, 0xFF, 0x00, 0xF7,
|
||||||
|
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||||
|
0x14, 0x14, 0xF7, 0x00, 0xF7,
|
||||||
|
0x14, 0x14, 0x14, 0x17, 0x14,
|
||||||
|
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||||
|
0x14, 0x14, 0x14, 0xF4, 0x14,
|
||||||
|
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||||
|
0x00, 0x00, 0x1F, 0x10, 0x1F,
|
||||||
|
0x00, 0x00, 0x00, 0x1F, 0x14,
|
||||||
|
0x00, 0x00, 0x00, 0xFC, 0x14,
|
||||||
|
0x00, 0x00, 0xF0, 0x10, 0xF0,
|
||||||
|
0x10, 0x10, 0xFF, 0x10, 0xFF,
|
||||||
|
0x14, 0x14, 0x14, 0xFF, 0x14,
|
||||||
|
0x10, 0x10, 0x10, 0x1F, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0xF0, 0x10,
|
||||||
|
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
|
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
|
||||||
|
0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||||
|
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||||
|
0x38, 0x44, 0x44, 0x38, 0x44,
|
||||||
|
0x7C, 0x2A, 0x2A, 0x3E, 0x14,
|
||||||
|
0x7E, 0x02, 0x02, 0x06, 0x06,
|
||||||
|
0x02, 0x7E, 0x02, 0x7E, 0x02,
|
||||||
|
0x63, 0x55, 0x49, 0x41, 0x63,
|
||||||
|
0x38, 0x44, 0x44, 0x3C, 0x04,
|
||||||
|
0x40, 0x7E, 0x20, 0x1E, 0x20,
|
||||||
|
0x06, 0x02, 0x7E, 0x02, 0x02,
|
||||||
|
0x99, 0xA5, 0xE7, 0xA5, 0x99,
|
||||||
|
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
|
||||||
|
0x4C, 0x72, 0x01, 0x72, 0x4C,
|
||||||
|
0x30, 0x4A, 0x4D, 0x4D, 0x30,
|
||||||
|
0x30, 0x48, 0x78, 0x48, 0x30,
|
||||||
|
0xBC, 0x62, 0x5A, 0x46, 0x3D,
|
||||||
|
0x3E, 0x49, 0x49, 0x49, 0x00,
|
||||||
|
0x7E, 0x01, 0x01, 0x01, 0x7E,
|
||||||
|
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
|
||||||
|
0x44, 0x44, 0x5F, 0x44, 0x44,
|
||||||
|
0x40, 0x51, 0x4A, 0x44, 0x40,
|
||||||
|
0x40, 0x44, 0x4A, 0x51, 0x40,
|
||||||
|
0x00, 0x00, 0xFF, 0x01, 0x03,
|
||||||
|
0xE0, 0x80, 0xFF, 0x00, 0x00,
|
||||||
|
0x08, 0x08, 0x6B, 0x6B, 0x08,
|
||||||
|
0x36, 0x12, 0x36, 0x24, 0x36,
|
||||||
|
0x06, 0x0F, 0x09, 0x0F, 0x06,
|
||||||
|
0x00, 0x00, 0x18, 0x18, 0x00,
|
||||||
|
0x00, 0x00, 0x10, 0x10, 0x00,
|
||||||
|
0x30, 0x40, 0xFF, 0x01, 0x01,
|
||||||
|
0x00, 0x1F, 0x01, 0x01, 0x1E,
|
||||||
|
0x00, 0x19, 0x1D, 0x17, 0x12,
|
||||||
|
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief GFX helper class
|
||||||
|
*
|
||||||
|
* This file is used by the screen.
|
||||||
|
*/
|
||||||
|
class GFX {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Instantiates a GFX object
|
||||||
|
*
|
||||||
|
* @param width Screen width
|
||||||
|
* @param height Screen height
|
||||||
|
*/
|
||||||
|
GFX (int width, int height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GFX object destructor
|
||||||
|
*/
|
||||||
|
~GFX ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a pixel color (RGB) to the chip. Must be implemented by the
|
||||||
|
* inherited class.
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale
|
||||||
|
* @param y Axis on the vertical scale
|
||||||
|
* @param color RGB value
|
||||||
|
*/
|
||||||
|
virtual void drawPixel (int16_t x, int16_t y, uint16_t color) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the buffer to the chip via the SPI.
|
||||||
|
*/
|
||||||
|
virtual void refresh () = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale
|
||||||
|
* @param y Axis on the vertical scale
|
||||||
|
* @param data Character to write
|
||||||
|
* @param color Character color
|
||||||
|
* @param bg Character background color
|
||||||
|
* @param size Size of the font
|
||||||
|
*/
|
||||||
|
void drawChar (int16_t x, int16_t y, uint8_t data, uint16_t color, uint16_t bg, uint8_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a message on the screen
|
||||||
|
*
|
||||||
|
* @param msg Message to print
|
||||||
|
*/
|
||||||
|
void print (std::string msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the screen with a selected color
|
||||||
|
*
|
||||||
|
* @param color Selected color
|
||||||
|
*/
|
||||||
|
void fillScreen (uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills a rectangle with a selected color
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale (top-left corner)
|
||||||
|
* @param y Axis on the vertical scale (top-left corner)
|
||||||
|
* @param w Distanse from x
|
||||||
|
* @param h Distanse from y
|
||||||
|
* @param color Selected color
|
||||||
|
*/
|
||||||
|
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a line on the vertical scale
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale
|
||||||
|
* @param y Axis on the vertical scale
|
||||||
|
* @param h Distanse from y
|
||||||
|
* @param color Selected color
|
||||||
|
*/
|
||||||
|
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a line from coordinate C0 to coordinate C1
|
||||||
|
*
|
||||||
|
* @param x0 First coordinate
|
||||||
|
* @param y0 First coordinate
|
||||||
|
* @param x1 Second coordinate
|
||||||
|
* @param y1 Second coordinate
|
||||||
|
* @param color selected color
|
||||||
|
*/
|
||||||
|
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a triangle
|
||||||
|
*
|
||||||
|
* @param x0 First coordinate
|
||||||
|
* @param y0 First coordinate
|
||||||
|
* @param x1 Second coordinate
|
||||||
|
* @param y1 Second coordinate
|
||||||
|
* @param x2 Third coordinate
|
||||||
|
* @param y2 Third coordinate
|
||||||
|
* @param color Selected color
|
||||||
|
*/
|
||||||
|
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a circle
|
||||||
|
*
|
||||||
|
* @param x Center of the circle on the horizontal scale
|
||||||
|
* @param y Center of the circle on the vertical scale
|
||||||
|
* @param r Radius of the circle
|
||||||
|
* @param color Color of the circle
|
||||||
|
*/
|
||||||
|
void drawCircle (int16_t x, int16_t y, int16_t r, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cursor for a text message
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale
|
||||||
|
* @param y Axis on the vertical scale
|
||||||
|
*/
|
||||||
|
void setCursor (int16_t x, int16_t y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a text color for a message
|
||||||
|
*
|
||||||
|
* @param textColor Font color
|
||||||
|
* @param textBGColor Background color
|
||||||
|
*/
|
||||||
|
void setTextColor (uint16_t textColor, uint16_t textBGColor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the size of the font
|
||||||
|
*
|
||||||
|
* @param size Font size
|
||||||
|
*/
|
||||||
|
void setTextSize (uint8_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a printed message
|
||||||
|
*
|
||||||
|
* @param wrap True (0x1) or false (0x0)
|
||||||
|
*/
|
||||||
|
void setTextWrap (uint8_t wrap);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int m_width; /**< Screen width */
|
||||||
|
int m_height; /**< Screen height */
|
||||||
|
int m_textSize; /**< Printed text size */
|
||||||
|
int m_textColor; /**< Printed text color */
|
||||||
|
int m_textBGColor; /**< Printed text background color */
|
||||||
|
int m_cursorX; /**< Cursor X coordinate */
|
||||||
|
int m_cursorY; /**< Cursor Y coordinate */
|
||||||
|
int m_wrap; /**< Wrapper flag (true or false) */
|
||||||
|
|
||||||
|
const unsigned char * m_font;
|
||||||
|
};
|
||||||
|
}
|
28
src/ssd1351/javaupm_ssd1351.i
Normal file
28
src/ssd1351/javaupm_ssd1351.i
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
%module javaupm_ssd1351
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
%include "stdint.i"
|
||||||
|
|
||||||
|
%ignore m_map;
|
||||||
|
%ignore font;
|
||||||
|
|
||||||
|
%include "gfx.h"
|
||||||
|
%{
|
||||||
|
#include "gfx.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "ssd1351.h"
|
||||||
|
%{
|
||||||
|
#include "ssd1351.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_ssd1351");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
12
src/ssd1351/jsupm_ssd1351.i
Normal file
12
src/ssd1351/jsupm_ssd1351.i
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
%module jsupm_ssd1351
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%include "gfx.h"
|
||||||
|
%{
|
||||||
|
#include "gfx.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "ssd1351.h"
|
||||||
|
%{
|
||||||
|
#include "ssd1351.h"
|
||||||
|
%}
|
17
src/ssd1351/pyupm_ssd1351.i
Normal file
17
src/ssd1351/pyupm_ssd1351.i
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_ssd1351
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
%rename("printString") print(std::string msg);
|
||||||
|
|
||||||
|
%include "gfx.h"
|
||||||
|
%{
|
||||||
|
#include "gfx.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "ssd1351.h"
|
||||||
|
%{
|
||||||
|
#include "ssd1351.h"
|
||||||
|
%}
|
225
src/ssd1351/ssd1351.cxx
Normal file
225
src/ssd1351/ssd1351.cxx
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Based on Adafruit SSD1351 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "ssd1351.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
SSD1351::SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst) :
|
||||||
|
GFX(SSD1351WIDTH, SSD1351HEIGHT),
|
||||||
|
m_spi(0), m_oc(oc), m_dc(dc), m_rst(rst) {
|
||||||
|
|
||||||
|
m_name = "SSD1351";
|
||||||
|
m_usemap = true;
|
||||||
|
|
||||||
|
// Setup SPI bus
|
||||||
|
m_spi.frequency(8 * 1000000);
|
||||||
|
m_spi.mode(mraa::SPI_MODE3);
|
||||||
|
m_spi.writeByte(0x00); // Need to bring clk high before init
|
||||||
|
|
||||||
|
// Init pins
|
||||||
|
if (m_oc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Could not initialize CS pin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_oc.useMmap(true);
|
||||||
|
if (m_dc.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Could not initialize data/cmd pin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_dc.useMmap(true);
|
||||||
|
if (m_rst.dir(mraa::DIR_OUT) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Could not initialize reset pin");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle reset pin
|
||||||
|
ocLow();
|
||||||
|
m_rst.write(1);
|
||||||
|
usleep(500000);
|
||||||
|
m_rst.write(0);
|
||||||
|
usleep(500000);
|
||||||
|
m_rst.write(1);
|
||||||
|
usleep(500000);
|
||||||
|
|
||||||
|
// Configure and init display
|
||||||
|
writeCommand(SSD1351_CMD_COMMANDLOCK);
|
||||||
|
writeData(0x12);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_COMMANDLOCK);
|
||||||
|
writeData(0xB1);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_DISPLAYOFF);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_CLOCKDIV);
|
||||||
|
writeCommand(0xF1);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_MUXRATIO);
|
||||||
|
writeData(127);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETREMAP);
|
||||||
|
writeData(0x74);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETCOLUMN);
|
||||||
|
writeData(0x00);
|
||||||
|
writeData(0x7F);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETROW);
|
||||||
|
writeData(0x00);
|
||||||
|
writeData(0x7F);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_STARTLINE);
|
||||||
|
if (SSD1351HEIGHT == 96) {
|
||||||
|
writeData(96);
|
||||||
|
} else {
|
||||||
|
writeData(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_DISPLAYOFFSET);
|
||||||
|
writeData(0x0);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETGPIO);
|
||||||
|
writeData(0x00);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_FUNCTIONSELECT);
|
||||||
|
writeData(0x01);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_PRECHARGE);
|
||||||
|
writeCommand(0x32);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_VCOMH);
|
||||||
|
writeCommand(0x05);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_NORMALDISPLAY);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_CONTRASTABC);
|
||||||
|
writeData(0xC8);
|
||||||
|
writeData(0x80);
|
||||||
|
writeData(0xC8);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_CONTRASTMASTER);
|
||||||
|
writeData(0x0F);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETVSL );
|
||||||
|
writeData(0xA0);
|
||||||
|
writeData(0xB5);
|
||||||
|
writeData(0x55);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_PRECHARGE2);
|
||||||
|
writeData(0x01);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_DISPLAYON);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSD1351::~SSD1351() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SSD1351::writeCommand (uint8_t value) {
|
||||||
|
dcLow();
|
||||||
|
m_spi.writeByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SSD1351::writeData (uint8_t value) {
|
||||||
|
dcHigh ();
|
||||||
|
m_spi.writeByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SSD1351::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
|
if ((x < 0) || (y < 0) || (x >= SSD1351WIDTH) || (y >= SSD1351HEIGHT))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(m_usemap) {
|
||||||
|
int index = (y * SSD1351WIDTH + x) * 2;
|
||||||
|
m_map[index] = color >> 8;
|
||||||
|
m_map[index + 1] = color;
|
||||||
|
} else {
|
||||||
|
writeCommand(SSD1351_CMD_SETCOLUMN);
|
||||||
|
writeData(x);
|
||||||
|
writeData(SSD1351WIDTH-1);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_SETROW);
|
||||||
|
writeData(y);
|
||||||
|
writeData(SSD1351HEIGHT-1);
|
||||||
|
|
||||||
|
writeCommand(SSD1351_CMD_WRITERAM);
|
||||||
|
writeData(color >> 8);
|
||||||
|
writeData(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SSD1351::refresh () {
|
||||||
|
writeCommand(SSD1351_CMD_WRITERAM);
|
||||||
|
int blockSize = SSD1351HEIGHT * SSD1351WIDTH * 2 / BLOCKS;
|
||||||
|
dcHigh();
|
||||||
|
for (int block = 0; block < BLOCKS; block++) {
|
||||||
|
m_spi.write(&m_map[block * blockSize], blockSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SSD1351::ocLow() {
|
||||||
|
if (m_oc.write(LOW) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Failed to write CS pin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SSD1351::ocHigh() {
|
||||||
|
if (m_oc.write(HIGH) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Failed to write CS pin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SSD1351::dcLow() {
|
||||||
|
if (m_dc.write(LOW) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Failed to write data/cmd pin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
SSD1351::dcHigh() {
|
||||||
|
if (m_dc.write(HIGH) != mraa::SUCCESS) {
|
||||||
|
throw std::runtime_error(string(__FUNCTION__) +
|
||||||
|
": Failed to write data/cmd pin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void
|
||||||
|
upm::SSD1351::useMemoryMap(bool var) {
|
||||||
|
m_usemap = var;
|
||||||
|
}
|
188
src/ssd1351/ssd1351.h
Normal file
188
src/ssd1351/ssd1351.h
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Based on Adafruit SSD1351 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/common.hpp>
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include <mraa/spi.hpp>
|
||||||
|
#include "gfx.h"
|
||||||
|
|
||||||
|
// Display Size
|
||||||
|
#define SSD1351WIDTH 128
|
||||||
|
#define SSD1351HEIGHT 128 // Set this to 96 for 1.27"
|
||||||
|
|
||||||
|
// SSD1351 Commands
|
||||||
|
#define SSD1351_CMD_SETCOLUMN 0x15
|
||||||
|
#define SSD1351_CMD_SETROW 0x75
|
||||||
|
#define SSD1351_CMD_WRITERAM 0x5C
|
||||||
|
#define SSD1351_CMD_READRAM 0x5D
|
||||||
|
#define SSD1351_CMD_SETREMAP 0xA0
|
||||||
|
#define SSD1351_CMD_STARTLINE 0xA1
|
||||||
|
#define SSD1351_CMD_DISPLAYOFFSET 0xA2
|
||||||
|
#define SSD1351_CMD_DISPLAYALLOFF 0xA4
|
||||||
|
#define SSD1351_CMD_DISPLAYALLON 0xA5
|
||||||
|
#define SSD1351_CMD_NORMALDISPLAY 0xA6
|
||||||
|
#define SSD1351_CMD_INVERTDISPLAY 0xA7
|
||||||
|
#define SSD1351_CMD_FUNCTIONSELECT 0xAB
|
||||||
|
#define SSD1351_CMD_DISPLAYOFF 0xAE
|
||||||
|
#define SSD1351_CMD_DISPLAYON 0xAF
|
||||||
|
#define SSD1351_CMD_PRECHARGE 0xB1
|
||||||
|
#define SSD1351_CMD_DISPLAYENHANCE 0xB2
|
||||||
|
#define SSD1351_CMD_CLOCKDIV 0xB3
|
||||||
|
#define SSD1351_CMD_SETVSL 0xB4
|
||||||
|
#define SSD1351_CMD_SETGPIO 0xB5
|
||||||
|
#define SSD1351_CMD_PRECHARGE2 0xB6
|
||||||
|
#define SSD1351_CMD_SETGRAY 0xB8
|
||||||
|
#define SSD1351_CMD_USELUT 0xB9
|
||||||
|
#define SSD1351_CMD_PRECHARGELEVEL 0xBB
|
||||||
|
#define SSD1351_CMD_VCOMH 0xBE
|
||||||
|
#define SSD1351_CMD_CONTRASTABC 0xC1
|
||||||
|
#define SSD1351_CMD_CONTRASTMASTER 0xC7
|
||||||
|
#define SSD1351_CMD_MUXRATIO 0xCA
|
||||||
|
#define SSD1351_CMD_COMMANDLOCK 0xFD
|
||||||
|
#define SSD1351_CMD_HORIZSCROLL 0x96
|
||||||
|
#define SSD1351_CMD_STOPSCROLL 0x9E
|
||||||
|
#define SSD1351_CMD_STARTSCROLL 0x9F
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
// Number of blocks for SPI transfer of buffer
|
||||||
|
#define BLOCKS 8
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
/**
|
||||||
|
* @brief SSD1351 OLED library
|
||||||
|
* @defgroup ssd1351 libupm-ssd1351
|
||||||
|
* @ingroup adafruit spi display
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @library ssd1351
|
||||||
|
* @sensor ssd1351
|
||||||
|
* @comname SSD1351 OLED
|
||||||
|
* @type display
|
||||||
|
* @man adafruit
|
||||||
|
* @web http://www.adafruit.com/products/1431
|
||||||
|
* @con spi
|
||||||
|
*
|
||||||
|
* @brief API for SSD1351 OLED displays
|
||||||
|
*
|
||||||
|
* This module defines the interface for the SSD1351 display library
|
||||||
|
*
|
||||||
|
* @image html ssd1351.jpg
|
||||||
|
* @snippet ssd1351.cxx Interesting
|
||||||
|
*/
|
||||||
|
class SSD1351 : public GFX{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Instantiates an SSD1351 object
|
||||||
|
*
|
||||||
|
* @param oc LCD chip select pin
|
||||||
|
* @param dc Data/command pin
|
||||||
|
* @param rst Reset pin
|
||||||
|
*/
|
||||||
|
SSD1351 (uint8_t oc, uint8_t dc, uint8_t rst);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SSD1351 object destructor
|
||||||
|
*/
|
||||||
|
~SSD1351();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the component
|
||||||
|
*/
|
||||||
|
std::string name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a command to an SPI bus
|
||||||
|
*
|
||||||
|
* @param value Command
|
||||||
|
*/
|
||||||
|
void writeCommand (uint8_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends data to an SPI bus
|
||||||
|
*
|
||||||
|
* @param value Data
|
||||||
|
*/
|
||||||
|
void writeData (uint8_t value);
|
||||||
|
/**
|
||||||
|
* Sends a pixel color (RGB) to the display buffer or chip
|
||||||
|
*
|
||||||
|
* @param x Axis on the horizontal scale
|
||||||
|
* @param y Axis on the vertical scale
|
||||||
|
* @param color RGB (16-bit) color (R[0-4], G[5-10], B[11-15])
|
||||||
|
*/
|
||||||
|
void drawPixel (int16_t x, int16_t y, uint16_t color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the buffer to the chip via the SPI bus
|
||||||
|
*/
|
||||||
|
void refresh ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set OLED chip select LOW
|
||||||
|
*/
|
||||||
|
void ocLow ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set OLED chip select HIGH
|
||||||
|
*/
|
||||||
|
void ocHigh ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data select LOW
|
||||||
|
*/
|
||||||
|
void dcLow ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data select HIGH
|
||||||
|
*/
|
||||||
|
void dcHigh ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use memory mapped (buffered) writes to the display
|
||||||
|
*
|
||||||
|
* @param var true for yes (default), false for no
|
||||||
|
*/
|
||||||
|
void useMemoryMap (bool var);
|
||||||
|
private:
|
||||||
|
mraa::Spi m_spi;
|
||||||
|
uint8_t m_map[SSD1351HEIGHT * SSD1351WIDTH * 2]; /**< Screen buffer */
|
||||||
|
bool m_usemap;
|
||||||
|
|
||||||
|
mraa::Gpio m_oc;
|
||||||
|
mraa::Gpio m_dc;
|
||||||
|
mraa::Gpio m_rst;
|
||||||
|
|
||||||
|
std::string m_name;
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user