Compare commits
10 Commits
gpiofix
...
pythonmult
Author | SHA1 | Date | |
---|---|---|---|
|
8ce214ae86 | ||
|
8329bcab62 | ||
|
e8d6f38ee0 | ||
|
a177a3f729 | ||
|
99841419ab | ||
|
1cfdfcddc6 | ||
|
a321d6707f | ||
|
b6e6374370 | ||
|
bcf1584fbe | ||
|
a9de84b74a |
@@ -75,7 +75,6 @@ option (IMRAA "Add Imraa support to mraa." OFF)
|
||||
option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF)
|
||||
option (IPK "Generate IPK using CPack" OFF)
|
||||
option (RPM "Generate RPM using CPack" OFF)
|
||||
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||
option (ENABLEEXAMPLES "Disable building of examples" ON)
|
||||
option (INSTALLGPIOTOOL "Install gpio tool" OFF)
|
||||
option (INSTALLTOOLS "Install all tools" OFF)
|
||||
@@ -109,12 +108,7 @@ else ()
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||
if (BUILDPYTHON3)
|
||||
set (PYTHONBUILD_VERSION 3)
|
||||
else ()
|
||||
set (PYTHONBUILD_VERSION 2.7)
|
||||
endif ()
|
||||
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
include (cmake/modules/OpenCVDetectPython.cmake)
|
||||
endif ()
|
||||
|
||||
if (BUILDDOC)
|
||||
@@ -202,9 +196,7 @@ if (IMRAA)
|
||||
add_subdirectory (imraa)
|
||||
endif ()
|
||||
|
||||
if (BUILDTESTS)
|
||||
if (${PYTHONINTERP_FOUND})
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
if (BUILDTESTS AND PYTHON_DEFAULT_EXECUTABLE)
|
||||
enable_testing ()
|
||||
add_subdirectory (tests)
|
||||
endif ()
|
||||
|
@@ -47,13 +47,26 @@ class Aio
|
||||
*
|
||||
* @param pin channel number to read ADC inputs
|
||||
*/
|
||||
Aio(unsigned int pin)
|
||||
Aio(int pin)
|
||||
{
|
||||
m_aio = mraa_aio_init(pin);
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO pin specified - do you have an ADC?");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio Constructor, takes a pointer to the AIO context and initialises
|
||||
* the AIO class
|
||||
*
|
||||
* @param void * to an AIO context
|
||||
*/
|
||||
Aio(void* aio_context)
|
||||
{
|
||||
m_aio = (mraa_aio_context) aio_context;
|
||||
if (m_aio == NULL) {
|
||||
throw std::invalid_argument("Invalid AIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Aio destructor
|
||||
*/
|
||||
|
@@ -293,6 +293,19 @@ mraa_result_t mraa_add_subplatform(mraa_platform_t subplatformtype, const char*
|
||||
*/
|
||||
mraa_result_t mraa_remove_subplatform(mraa_platform_t subplatformtype);
|
||||
|
||||
/**
|
||||
* Create IO using a description in the format:
|
||||
* [io]-[pin]
|
||||
* [io]-[raw]-[pin]
|
||||
* [io]-[raw]-[id]-[pin]
|
||||
* [io]-[raw]-[path]
|
||||
*
|
||||
* @param IO description
|
||||
*
|
||||
* @return void* to IO context or NULL
|
||||
*/
|
||||
void* mraa_init_io(const char* desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -309,4 +309,22 @@ removeSubplatform(Platform subplatformtype)
|
||||
return (Result) mraa_remove_subplatform((mraa_platform_t) subplatformtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create IO using a description in the format:
|
||||
* [io]-[pin]
|
||||
* [io]-[raw]-[pin]
|
||||
* [io]-[raw]-[id]-[pin]
|
||||
* [io]-[raw]-[path]
|
||||
*
|
||||
* @param IO description
|
||||
*
|
||||
* @return class T initialised using pointer to IO or NULL
|
||||
*/
|
||||
template <class T>
|
||||
inline T*
|
||||
initIo(std::string desc)
|
||||
{
|
||||
return new T(mraa_init_io(desc.c_str()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -107,6 +107,19 @@ class Gpio
|
||||
mraa_gpio_owner(m_gpio, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio Constructor, takes a pointer to the GPIO context and initialises
|
||||
* the GPIO class
|
||||
*
|
||||
* @param void * to GPIO context
|
||||
*/
|
||||
Gpio(void* gpio_context)
|
||||
{
|
||||
m_gpio = (mraa_gpio_context) gpio_context;
|
||||
if (m_gpio == NULL) {
|
||||
throw std::invalid_argument("Invalid GPIO context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gpio object destructor, this will only unexport the gpio if we where
|
||||
* the owner
|
||||
|
@@ -62,6 +62,18 @@ class I2c
|
||||
throw std::invalid_argument("Invalid i2c bus");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* I2C constructor, takes a pointer to a I2C context and initialises the I2C class
|
||||
*
|
||||
* @param void * to an I2C context
|
||||
*/
|
||||
I2c(void* i2c_context)
|
||||
{
|
||||
m_i2c = (mraa_i2c_context) i2c_context;
|
||||
if (m_i2c == NULL) {
|
||||
throw std::invalid_argument("Invalid I2C context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the I2c Bus used. This does not guarrantee the bus will not
|
||||
|
@@ -66,6 +66,20 @@ class Pwm
|
||||
mraa_pwm_owner(m_pwm, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pwm constructor, takes a pointer to the PWM context and
|
||||
* initialises the class
|
||||
*
|
||||
* @param void * to a PWM context
|
||||
*/
|
||||
Pwm(void* pwm_context)
|
||||
{
|
||||
m_pwm = (mraa_pwm_context) pwm_context;
|
||||
if (m_pwm == NULL) {
|
||||
throw std::invalid_argument("Invalid PWM context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pwm destructor
|
||||
*/
|
||||
|
@@ -79,6 +79,20 @@ class Spi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spi Constructor, takes a pointer to a SPI context and initialises
|
||||
* the SPI class
|
||||
*
|
||||
* @param void * to SPI context
|
||||
*/
|
||||
Spi(void* spi_context)
|
||||
{
|
||||
m_spi = (mraa_spi_context) spi_context;
|
||||
if (m_spi == NULL) {
|
||||
throw std::invalid_argument("Invalid SPI context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes spi bus
|
||||
*/
|
||||
|
@@ -75,6 +75,20 @@ class Uart
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uart Constructor, takes a pointer to the UART context and initialises
|
||||
* the UART class
|
||||
*
|
||||
* @param void * to a UART context
|
||||
*/
|
||||
Uart(void* uart_context)
|
||||
{
|
||||
m_uart = (mraa_uart_context) uart_context;
|
||||
|
||||
if (m_uart == NULL) {
|
||||
throw std::invalid_argument("Invalid UART context");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Uart destructor
|
||||
*/
|
||||
|
158
cmake/modules/OpenCVDetectPython.cmake
Normal file
158
cmake/modules/OpenCVDetectPython.cmake
Normal file
@@ -0,0 +1,158 @@
|
||||
# Find specified Python version
|
||||
# Arguments:
|
||||
# preferred_version (value): Version to check for first
|
||||
# min_version (value): Minimum supported version
|
||||
# library_env (value): Name of Python library ENV variable to check
|
||||
# include_dir_env (value): Name of Python include directory ENV variable to check
|
||||
# found (variable): Set if interpreter found
|
||||
# executable (variable): Output of executable found
|
||||
# version_string (variable): Output of found version
|
||||
# version_major (variable): Output of found major version
|
||||
# version_minor (variable): Output of found minor version
|
||||
# libs_found (variable): Set if libs found
|
||||
# libs_version_string (variable): Output of found libs version
|
||||
# libraries (variable): Output of found Python libraries
|
||||
# library (variable): Output of found Python library
|
||||
# debug_libraries (variable): Output of found Python debug libraries
|
||||
# debug_library (variable): Output of found Python debug library
|
||||
# include_path (variable): Output of found Python include path
|
||||
# include_dir (variable): Output of found Python include dir
|
||||
# include_dir2 (variable): Output of found Python include dir2
|
||||
# packages_path (variable): Output of found Python packages path
|
||||
function(find_python preferred_version min_version library_env include_dir_env
|
||||
found executable version_string version_major version_minor
|
||||
libs_found libs_version_string libraries library debug_libraries
|
||||
debug_library include_path include_dir include_dir2 packages_path)
|
||||
if(NOT ${found})
|
||||
if(${executable})
|
||||
set(PYTHON_EXECUTABLE "${${executable}}")
|
||||
endif()
|
||||
|
||||
find_package(PythonInterp "${preferred_version}")
|
||||
if(NOT PYTHONINTERP_FOUND)
|
||||
find_package(PythonInterp "${min_version}")
|
||||
endif()
|
||||
|
||||
if(PYTHONINTERP_FOUND)
|
||||
# Copy outputs
|
||||
set(_found ${PYTHONINTERP_FOUND})
|
||||
set(_executable ${PYTHON_EXECUTABLE})
|
||||
set(_version_string ${PYTHON_VERSION_STRING})
|
||||
set(_version_major ${PYTHON_VERSION_MAJOR})
|
||||
set(_version_minor ${PYTHON_VERSION_MINOR})
|
||||
set(_version_patch ${PYTHON_VERSION_PATCH})
|
||||
|
||||
# Clear find_host_package side effects
|
||||
unset(PYTHONINTERP_FOUND)
|
||||
unset(PYTHON_EXECUTABLE CACHE)
|
||||
unset(PYTHON_VERSION_STRING)
|
||||
unset(PYTHON_VERSION_MAJOR)
|
||||
unset(PYTHON_VERSION_MINOR)
|
||||
unset(PYTHON_VERSION_PATCH)
|
||||
endif()
|
||||
|
||||
if(_found)
|
||||
set(_version_major_minor "${_version_major}.${_version_minor}")
|
||||
|
||||
if(NOT ANDROID AND NOT APPLE_FRAMEWORK)
|
||||
# not using _version_string here, because it might not conform to the CMake version format
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
# builder version can differ from target, matching base version (e.g. 2.7)
|
||||
find_package(PythonLibs "${_version_major_minor}")
|
||||
else()
|
||||
find_package(PythonLibs "${_version_major_minor}.${_version_patch}" EXACT)
|
||||
endif()
|
||||
|
||||
if(PYTHONLIBS_FOUND)
|
||||
# Copy outputs
|
||||
set(_libs_found ${PYTHONLIBS_FOUND})
|
||||
set(_libraries ${PYTHON_LIBRARIES})
|
||||
set(_include_path ${PYTHON_INCLUDE_PATH})
|
||||
set(_include_dirs ${PYTHON_INCLUDE_DIRS})
|
||||
set(_debug_libraries ${PYTHON_DEBUG_LIBRARIES})
|
||||
set(_libs_version_string ${PYTHONLIBS_VERSION_STRING})
|
||||
set(_debug_library ${PYTHON_DEBUG_LIBRARY})
|
||||
set(_library ${PYTHON_LIBRARY})
|
||||
set(_library_debug ${PYTHON_LIBRARY_DEBUG})
|
||||
set(_library_release ${PYTHON_LIBRARY_RELEASE})
|
||||
set(_include_dir ${PYTHON_INCLUDE_DIR})
|
||||
set(_include_dir2 ${PYTHON_INCLUDE_DIR2})
|
||||
|
||||
# Clear find_package side effects
|
||||
unset(PYTHONLIBS_FOUND)
|
||||
unset(PYTHON_LIBRARIES)
|
||||
unset(PYTHON_INCLUDE_PATH)
|
||||
unset(PYTHON_INCLUDE_DIRS)
|
||||
unset(PYTHON_DEBUG_LIBRARIES)
|
||||
unset(PYTHONLIBS_VERSION_STRING)
|
||||
unset(PYTHON_DEBUG_LIBRARY CACHE)
|
||||
unset(PYTHON_LIBRARY)
|
||||
unset(PYTHON_LIBRARY_DEBUG)
|
||||
unset(PYTHON_LIBRARY_RELEASE)
|
||||
unset(PYTHON_LIBRARY CACHE)
|
||||
unset(PYTHON_LIBRARY_DEBUG CACHE)
|
||||
unset(PYTHON_LIBRARY_RELEASE CACHE)
|
||||
unset(PYTHON_INCLUDE_DIR CACHE)
|
||||
unset(PYTHON_INCLUDE_DIR2 CACHE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${_executable} -c "from distutils.sysconfig import *; print(get_python_lib())"
|
||||
RESULT_VARIABLE _cvpy_process
|
||||
OUTPUT_VARIABLE _std_packages_path
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if("${_std_packages_path}" MATCHES "site-packages")
|
||||
set(_packages_path "python${_version_major_minor}/site-packages")
|
||||
else() #debian based assumed, install to the dist-packages.
|
||||
set(_packages_path "python${_version_major_minor}/dist-packages")
|
||||
endif()
|
||||
if(EXISTS "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${${packages_path}}")
|
||||
set(_packages_path "lib${LIB_SUFFIX}/${_packages_path}")
|
||||
else()
|
||||
set(_packages_path "lib/${_packages_path}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Export return values
|
||||
set(${found} "${_found}" CACHE INTERNAL "")
|
||||
set(${executable} "${_executable}" CACHE FILEPATH "Path to Python interpretor")
|
||||
set(${version_string} "${_version_string}" CACHE INTERNAL "")
|
||||
set(${version_major} "${_version_major}" CACHE INTERNAL "")
|
||||
set(${version_minor} "${_version_minor}" CACHE INTERNAL "")
|
||||
set(${libs_found} "${_libs_found}" CACHE INTERNAL "")
|
||||
set(${libs_version_string} "${_libs_version_string}" CACHE INTERNAL "")
|
||||
set(${libraries} "${_libraries}" CACHE INTERNAL "Python libraries")
|
||||
set(${library} "${_library}" CACHE FILEPATH "Path to Python library")
|
||||
set(${debug_libraries} "${_debug_libraries}" CACHE INTERNAL "")
|
||||
set(${debug_library} "${_debug_library}" CACHE FILEPATH "Path to Python debug")
|
||||
set(${include_path} "${_include_path}" CACHE INTERNAL "")
|
||||
set(${include_dir} "${_include_dir}" CACHE PATH "Python include dir")
|
||||
set(${include_dir2} "${_include_dir2}" CACHE PATH "Python include dir 2")
|
||||
set(${packages_path} "${_packages_path}" CACHE PATH "Where to install the python packages.")
|
||||
endif()
|
||||
endfunction(find_python)
|
||||
|
||||
find_python(2.7 "${MIN_VER_PYTHON2}" PYTHON2_LIBRARY PYTHON2_INCLUDE_DIR
|
||||
PYTHON2INTERP_FOUND PYTHON2_EXECUTABLE PYTHON2_VERSION_STRING
|
||||
PYTHON2_VERSION_MAJOR PYTHON2_VERSION_MINOR PYTHON2LIBS_FOUND
|
||||
PYTHON2LIBS_VERSION_STRING PYTHON2_LIBRARIES PYTHON2_LIBRARY
|
||||
PYTHON2_DEBUG_LIBRARIES PYTHON2_LIBRARY_DEBUG PYTHON2_INCLUDE_PATH
|
||||
PYTHON2_INCLUDE_DIR PYTHON2_INCLUDE_DIR2 PYTHON2_PACKAGES_PATH)
|
||||
|
||||
find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
|
||||
PYTHON3INTERP_FOUND PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING
|
||||
PYTHON3_VERSION_MAJOR PYTHON3_VERSION_MINOR PYTHON3LIBS_FOUND
|
||||
PYTHON3LIBS_VERSION_STRING PYTHON3_LIBRARIES PYTHON3_LIBRARY
|
||||
PYTHON3_DEBUG_LIBRARIES PYTHON3_LIBRARY_DEBUG PYTHON3_INCLUDE_PATH
|
||||
PYTHON3_INCLUDE_DIR PYTHON3_INCLUDE_DIR2 PYTHON3_PACKAGES_PATH)
|
||||
|
||||
|
||||
if(PYTHON_DEFAULT_EXECUTABLE)
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
|
||||
elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
|
||||
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
|
||||
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
|
||||
endif()
|
@@ -92,10 +92,6 @@ Building doc, this will require [SPHINX](http://sphinx-doc.org) &
|
||||
[Doxygen](http://doxygen.org):
|
||||
`-DBUILDDOC=ON`
|
||||
|
||||
Building with Python 3 (careful you need to clear CMake cache between Python
|
||||
version switches!)
|
||||
`-DBUILDPYTHON3=ON`
|
||||
|
||||
Override build architecture (this is useful because on x86 ARM code is not
|
||||
compiled so use this flag to force the target arch)
|
||||
`-DBUILDARCH=arm`
|
||||
|
17
jsstub/Gruntfile.js
Normal file
17
jsstub/Gruntfile.js
Normal file
@@ -0,0 +1,17 @@
|
||||
module.exports = function(grunt) {
|
||||
grunt.loadNpmTasks('grunt-mocha-test');
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
mochaTest: {
|
||||
test: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
src: ['test/*.js']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
grunt.registerTask('test', ['mochaTest:test']);
|
||||
};
|
52
jsstub/README.md
Normal file
52
jsstub/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
mraaStub - JavaScript simulation and stubs for mraa
|
||||
====================
|
||||
|
||||
This project enables simulation of a device which might be accessed via mraa.
|
||||
Currently this library supports I2c, SPI, and GPIO. This project provides
|
||||
several benefits:
|
||||
|
||||
1. Prevent crashes in nodejs applications using mraa on unsuported or
|
||||
misconfigured hardware.
|
||||
2. Enable basic simulation of mraa-accessible devices for unit testing.
|
||||
|
||||
## Examples
|
||||
|
||||
The following example is based on an imaginary 'light bulb' device abstraction,
|
||||
which exposes a value of brightness over a mraa-provided interface. Please see
|
||||
the `test/index.js` file for an example.
|
||||
|
||||
## Installation
|
||||
|
||||
mraaStub is not yet in npm so has to be installed from git. In the future
|
||||
you'll be able to install `mraaStub` from npm like this:
|
||||
|
||||
```
|
||||
npm install mraaStub
|
||||
```
|
||||
|
||||
Since we often switch between a mraaStub and the real mraa library, we
|
||||
suggest creating an `index.js` file inside a `lib/mraaSwitcher` folder.
|
||||
|
||||
```js
|
||||
/* index.js - file for switching between mraa and mraaStub
|
||||
*/
|
||||
|
||||
// Define the conditions under which the mraaStub should be loaded
|
||||
var platform = require('os').platform();
|
||||
var m;
|
||||
|
||||
if (platform === 'win32') {
|
||||
m = require('mraaStub');
|
||||
} else {
|
||||
m = require('mraa');
|
||||
}
|
||||
|
||||
module.exports = m;
|
||||
```
|
||||
|
||||
You can add this to your project in its own `lib/mraaSwitcher/index.js` file
|
||||
and use `require('../mraaSwitcher')` everywhere!
|
||||
|
||||
## License
|
||||
|
||||
See [COPYING file](../COPYING) in the root of this repository.
|
223
jsstub/index.js
Normal file
223
jsstub/index.js
Normal file
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* @fileoverview This file implements a fake mraa stub which enables testing
|
||||
* as well as the ability to run on Windows.
|
||||
*/
|
||||
|
||||
var m;
|
||||
var winston = require('winston');
|
||||
var logger = new winston.Logger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: 'error',
|
||||
handleExceptions: false,
|
||||
json: false,
|
||||
colorize: true})
|
||||
],
|
||||
exitOnError: false
|
||||
});
|
||||
|
||||
/**
|
||||
* @class mraaStub
|
||||
* @classdesc This class is designed to stub out libmraa so we can run
|
||||
* test code on unsupported platforms (specifically Windows).
|
||||
*/
|
||||
var mraaStub = function() {
|
||||
var verison = '0.0.1';
|
||||
var self = this;
|
||||
self.EDGE_BOTH = 1;
|
||||
self.EDGE_NONE = 2;
|
||||
self.EDGE_RISING = 3;
|
||||
self.EDGE_FALLING = 4;
|
||||
self.DIR_IN = 1;
|
||||
self.DIR_OUT = 2;
|
||||
|
||||
self.getVersion = function() {
|
||||
return "mraaStub " + version;
|
||||
};
|
||||
|
||||
// Stub out GPIO
|
||||
function Gpio(num) {
|
||||
this.num = num;
|
||||
this._callback = null;
|
||||
this._dir = null;
|
||||
this._isr_mode = self.EDGE_NONE;
|
||||
}
|
||||
|
||||
var logGpio = false;
|
||||
Gpio.prototype._callIsr = function() {
|
||||
if(this.isr_mode === self.EDGE_NONE) {
|
||||
logger.log('info',"Could not call ISR. Not set up for triggering");
|
||||
}
|
||||
this._callback();
|
||||
};
|
||||
|
||||
Gpio.prototype.isr = function(mode, handler){
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " isr stub invoked.");
|
||||
}
|
||||
this._isr_mode = self.EDGE_NONE;
|
||||
this._callback = handler;
|
||||
};
|
||||
|
||||
Gpio.prototype.dir = function(d) {
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " dir stub invoked.");
|
||||
}
|
||||
this._dir = d;
|
||||
};
|
||||
Gpio.prototype.write = function(z) {
|
||||
if(logGpio) {
|
||||
logger.log('logger',"GPIO " + this.num + " write stub invoked.");
|
||||
}
|
||||
if(this._dir !== self.DIR_OUT) {
|
||||
logger.log('info',"GPIO " + this.num + " write called without DIR_OUT set.");
|
||||
}
|
||||
};
|
||||
Gpio.prototype.read = function() {
|
||||
if(logGpio) {
|
||||
logger.log('info',"GPIO " + this.num + " read stub invoked.");
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Stub out SPI
|
||||
function Spi(num) {
|
||||
var self = this;
|
||||
this.num = num;
|
||||
this._buffer = new Buffer(29);
|
||||
this._buffer.fill(0);
|
||||
this._loopback = false;
|
||||
}
|
||||
|
||||
Spi.prototype._setOutput = function(buf) {
|
||||
this._buffer = buf;
|
||||
};
|
||||
|
||||
Spi.prototype._enableLoopback = function(x) {
|
||||
if(x === true) {
|
||||
this._loopback = true;
|
||||
} else {
|
||||
this._loopback = false;
|
||||
}
|
||||
};
|
||||
|
||||
Spi.prototype.write = function(b) {
|
||||
logger.log('info',"SPI write stub invoked.");
|
||||
if(this._loopback === true) {
|
||||
return b;
|
||||
}
|
||||
return new Buffer(this._buffer);
|
||||
};
|
||||
|
||||
Spi.prototype.frequency = function(f) {
|
||||
logger.log('info',"SPI frequency stub invoked.");
|
||||
return f;
|
||||
};
|
||||
|
||||
Spi.prototype.lsbmode = function(t) {
|
||||
logger.log('info',"SPI lsbmode stub invoked.");
|
||||
};
|
||||
|
||||
Spi.prototype.mode = function(x) {
|
||||
logger.log('info',"SPI mode stub invoked.");
|
||||
};
|
||||
|
||||
function I2c(num) {
|
||||
this._num = num;
|
||||
this._regMapInitialized = false;
|
||||
}
|
||||
|
||||
/* This function sets an internal register map for the I2c device.
|
||||
*/
|
||||
I2c.prototype._setRegisterMapInternal = function(buffer) {
|
||||
this._regMapInitialized = true;
|
||||
this._buffer = buffer;
|
||||
};
|
||||
|
||||
I2c.prototype.frequency = function(freq) {
|
||||
// Do nothing. We don't care.
|
||||
};
|
||||
|
||||
I2c.prototype.address = function(address) {
|
||||
var self = this;
|
||||
self.address = address;
|
||||
};
|
||||
|
||||
I2c.prototype.readReg = function(regAddr) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.readUInt8(regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.readWordReg = function(regAddr) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.readUInt16LE(regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.readBytesReg = function(regAddr, len) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
return this._buffer.slice(regAddr,regAddr+len);
|
||||
};
|
||||
|
||||
I2c.prototype.write = function(buf) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
var regAddr = buf[0];
|
||||
var newBuf = buf.slice(1);
|
||||
newBuf.copy(this._buffer, regAddr);
|
||||
};
|
||||
|
||||
I2c.prototype.writeReg = function(regAddr, data) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
this._buffer.writeUInt8(regAddr,data);
|
||||
};
|
||||
|
||||
I2c.prototype.writeWordReg = function(regAddr, dataWord) {
|
||||
if(!this._regMapInitialized) {
|
||||
logger.log('error', "Need to set reg map");
|
||||
}
|
||||
if(!this.address) {
|
||||
logger.log('error', "Need to set address");
|
||||
}
|
||||
|
||||
this._buffer.writeUInt16LE(regAddr,data);
|
||||
};
|
||||
|
||||
// Export our stubs
|
||||
self.Gpio = Gpio;
|
||||
self.Spi = Spi;
|
||||
self.I2c = I2c;
|
||||
|
||||
};
|
||||
|
||||
m = new mraaStub();
|
||||
|
||||
module.exports = m;
|
34
jsstub/package.json
Normal file
34
jsstub/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "mraaStub",
|
||||
"version": "0.0.1",
|
||||
"description": "Enables simulation of mraa interfaces for testing purposes",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/intel-iot-devkit/mraa.git"
|
||||
},
|
||||
"keywords": [
|
||||
"mraa",
|
||||
"iot",
|
||||
"intel",
|
||||
"libmraa",
|
||||
"test",
|
||||
"galileo",
|
||||
"edison"
|
||||
],
|
||||
"author": "David A Antler <david.a.antler@intel.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/intel-iot-devkit/mraa/issues"
|
||||
},
|
||||
"homepage": "https://github.com/intel-iot-devkit/mraa#readme",
|
||||
"devDependencies": {
|
||||
"expect.js": "^0.3.1",
|
||||
"grunt": "^1.0.1",
|
||||
"grunt-mocha-test": "^0.12.7",
|
||||
"mocha": "^2.4.5"
|
||||
}
|
||||
}
|
32
jsstub/test/index.js
Normal file
32
jsstub/test/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
var expect = require('expect.js');
|
||||
var m = require('../index');
|
||||
var LightBulb = require('./lightbulb');
|
||||
|
||||
describe('LightBulb', function() {
|
||||
|
||||
/** Model the internal data of LightBulb as a buffer */
|
||||
var bufferFullBrightness = new Buffer(
|
||||
[ 'N', // Four bytes allocated for name
|
||||
'a',
|
||||
'm',
|
||||
'e',
|
||||
95 // One byte allocated for brightness. Stuff in '95' value!
|
||||
]);
|
||||
|
||||
it('getBrightness() function should return 95', function() {
|
||||
|
||||
// Create a fake I2c bus based on the 'full brightness' data model
|
||||
var testI2cBus = new m.I2c(0);
|
||||
testI2cBus._setRegisterMapInternal(bufferFullBrightness);
|
||||
|
||||
// Create a new LightBulb that opens the testI2cBus, instead of a real
|
||||
// mraa I2c bus.
|
||||
var lightBulbI2c = new LightBulb(testI2cBus);
|
||||
|
||||
// presumably getBrightness will gather data from I2C and get '95'
|
||||
var brightness = lightBulbI2c.getBrightness();
|
||||
|
||||
expect(brightness).to.be(95);
|
||||
})
|
||||
});
|
||||
|
32
jsstub/test/lightbulb.js
Normal file
32
jsstub/test/lightbulb.js
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @fileoverview Implementation of a LightBulb class abstraction
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = (function() {
|
||||
"use strict";
|
||||
var m = require('../index');
|
||||
|
||||
/**
|
||||
* Constructor for a new LightBulb
|
||||
* @class LightBulb
|
||||
*
|
||||
* @classdesc This class abstracts access to the control and data registers
|
||||
* on an imaginary lightbulb.
|
||||
* @param {Object} A libmraa I2c object, initialized
|
||||
*/
|
||||
function LightBulb (i2cInterface) {
|
||||
var self = this;
|
||||
self._i2cInterface = i2cInterface;
|
||||
|
||||
self.getBrightness = function() {
|
||||
// Presume our brightness data is one byte at offset 4
|
||||
return self._i2cInterface.readReg(4);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
return LightBulb;
|
||||
})();
|
||||
|
@@ -193,6 +193,8 @@ if (BUILDSWIG)
|
||||
add_subdirectory (python)
|
||||
endif ()
|
||||
if (BUILDSWIGJAVA)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/java/manifest.txt.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/java/manifest.txt)
|
||||
add_subdirectory (java)
|
||||
endif ()
|
||||
if (BUILDSWIGNODE)
|
||||
|
@@ -33,7 +33,7 @@ add_custom_command (TARGET mraajava
|
||||
COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mraa
|
||||
COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND cmake -E echo "Creating jar"
|
||||
COMMAND ${JAR} cvf mraa.jar mraa
|
||||
COMMAND ${JAR} cvmf manifest.txt mraa.jar mraa
|
||||
)
|
||||
|
||||
if (DOXYGEN_FOUND)
|
||||
|
9
src/java/manifest.txt.in
Normal file
9
src/java/manifest.txt.in
Normal file
@@ -0,0 +1,9 @@
|
||||
Manifest-version: 1.0
|
||||
|
||||
Name: mraa/
|
||||
Specification-Title: mraa
|
||||
Specification-Version: @VERSION_SHORT@
|
||||
Specification-Vendor: Intel Corp.
|
||||
Package-Title: mraa
|
||||
Package-Version: @VERSION_SHORT@
|
||||
Package-Vendor: Intel Corp.
|
@@ -96,5 +96,34 @@ class Spi;
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String javaAPIVersion = mraa.class.getPackage().getSpecificationVersion();
|
||||
String nativeAPIVersion = mraa.getVersion().substring(1);
|
||||
|
||||
String javaMajor = javaAPIVersion.substring(0, javaAPIVersion.indexOf('.'));
|
||||
String nativeMajor = nativeAPIVersion.substring(0, nativeAPIVersion.indexOf('.'));
|
||||
|
||||
if(Integer.parseInt(javaMajor) < Integer.parseInt(nativeMajor)){
|
||||
System.err.println("Java library is out of date. Please update the Java library.");
|
||||
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
|
||||
System.exit(1);
|
||||
}
|
||||
if(Integer.parseInt(javaMajor) > Integer.parseInt(nativeMajor)){
|
||||
System.err.println("Native library is out of date. Please update the Native library.");
|
||||
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String javaMinor = javaAPIVersion.substring(javaMajor.length() + 1, javaAPIVersion.indexOf('.', javaMajor.length() + 1));
|
||||
String nativeMinor = nativeAPIVersion.substring(nativeMajor.length() + 1, nativeAPIVersion.indexOf('.', nativeMajor.length() + 1));
|
||||
|
||||
if(Integer.parseInt(javaMinor) < Integer.parseInt(nativeMinor)){
|
||||
System.err.println("Java library is out of date. Please consider updating the Java library.");
|
||||
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
|
||||
}
|
||||
if(Integer.parseInt(javaMinor) > Integer.parseInt(nativeMinor)){
|
||||
System.err.println("Native library is out of date. Please consider updating the Native library.");
|
||||
System.err.println("Native library version is " + nativeAPIVersion + ". Java library version is " + javaAPIVersion + ".");
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
157
src/mraa.c
157
src/mraa.c
@@ -41,6 +41,9 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#if defined(IMRAA)
|
||||
#include <json-c/json.h>
|
||||
@@ -52,6 +55,12 @@
|
||||
#include "firmata/firmata_mraa.h"
|
||||
#include "gpio.h"
|
||||
#include "version.h"
|
||||
#include "i2c.h"
|
||||
#include "pwm.h"
|
||||
#include "aio.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
|
||||
|
||||
#define IIO_DEVICE_WILDCARD "iio:device*"
|
||||
mraa_board_t* plat = NULL;
|
||||
@@ -1073,3 +1082,151 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
mraa_to_upper(char* s)
|
||||
{
|
||||
char* t = s;
|
||||
for (; *t; ++t) {
|
||||
*t = toupper(*t);
|
||||
}
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_atoi(char* intStr, int* value)
|
||||
{
|
||||
char* end;
|
||||
// here 10 determines the number base in which strol is to work
|
||||
long val = strtol(intStr, &end, 10);
|
||||
if (*end != '\0' || errno == ERANGE || end == intStr || val > INT_MAX || val < INT_MIN) {
|
||||
*value = 0;
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
*value = (int) val;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_init_io_helper(char** str, int* value, const char* delim)
|
||||
{
|
||||
// This function is a result of a repeated pattern within mraa_init_io
|
||||
// when determining if a value can be derived from a string
|
||||
char* token;
|
||||
token = strsep(str, delim);
|
||||
// check to see if empty string returned
|
||||
if (token == NULL) {
|
||||
*value = 0;
|
||||
return MRAA_ERROR_NO_DATA_AVAILABLE;
|
||||
}
|
||||
return mraa_atoi(token, value);
|
||||
}
|
||||
|
||||
void*
|
||||
mraa_init_io(const char* desc)
|
||||
{
|
||||
const char* delim = "-";
|
||||
int length = 0, raw = 0;
|
||||
int pin = 0, id = 0;
|
||||
// 256 denotes the maximum size of our buffer
|
||||
// 8 denotes the maximum size of our type rounded to the nearest power of 2
|
||||
// max size is 4 + 1 for the \0 = 5 rounded to 8
|
||||
char buffer[256] = { 0 }, type[8] = { 0 };
|
||||
char *token = 0, *str = 0;
|
||||
length = strlen(desc);
|
||||
// Check to see the length is less than or equal to 255 which means
|
||||
// byte 256 is supposed to be \0
|
||||
if (length > 255 || desc == NULL || length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
strncpy(buffer, desc, length);
|
||||
|
||||
str = buffer;
|
||||
token = strsep(&str, delim);
|
||||
length = strlen(token);
|
||||
// Check to see they haven't given us a type whose length is greater than the
|
||||
// largest type we know about
|
||||
if (length > 4) {
|
||||
syslog(LOG_ERR, "mraa_init_io: An invalid IO type was provided");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(type, token, length);
|
||||
mraa_to_upper(type);
|
||||
token = strsep(&str, delim);
|
||||
// Check that they've given us more information than just the type
|
||||
if (token == NULL) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Missing information after type");
|
||||
return NULL;
|
||||
}
|
||||
// If we cannot convert the pin to a number maybe it says raw?
|
||||
if (mraa_atoi(token, &pin) != MRAA_SUCCESS) {
|
||||
mraa_to_upper(token);
|
||||
if (strncmp(token, "RAW", 3)) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Description does not adhere to a known format");
|
||||
return NULL;
|
||||
}
|
||||
raw = 1;
|
||||
}
|
||||
if (!raw && str != NULL) {
|
||||
syslog(LOG_ERR, "mraa_init_io: More information than required was provided");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strncmp(type, "GPIO", 4) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
|
||||
return (void*) mraa_gpio_init_raw(pin);
|
||||
}
|
||||
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for GPIO");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_gpio_init(pin);
|
||||
} else if (strncmp(type, "I2C", 3) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &pin, delim) == MRAA_SUCCESS) {
|
||||
return (void*) mraa_i2c_init_raw(pin);
|
||||
}
|
||||
syslog(LOG_ERR, "mraa_init_io: Invalid Raw description for I2C");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_i2c_init(pin);
|
||||
} else if (strncmp(type, "AIO", 3) == 0) {
|
||||
if (raw) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Aio doesn't have a RAW mode");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_aio_init(pin);
|
||||
} else if (strncmp(type, "PWM", 3) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the pin string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_pwm_init_raw(id, pin);
|
||||
}
|
||||
return (void*) mraa_pwm_init(pin);
|
||||
} else if (strncmp(type, "SPI", 3) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the bus string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the cs string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_spi_init_raw(id, pin);
|
||||
}
|
||||
return (void*) mraa_spi_init(pin);
|
||||
} else if (strncmp(type, "UART", 4) == 0) {
|
||||
if (raw) {
|
||||
return (void*) mraa_uart_init_raw(str);
|
||||
}
|
||||
return (void*) mraa_uart_init(pin);
|
||||
}
|
||||
syslog(LOG_ERR, "mraa_init_io: Invalid IO type given.");
|
||||
return NULL;
|
||||
}
|
||||
|
13
src/mraa.i
13
src/mraa.i
@@ -41,6 +41,19 @@
|
||||
%include "types.hpp"
|
||||
|
||||
%include "common.hpp"
|
||||
%template (gpioFromDesc) mraa::initIo<mraa::Gpio>;
|
||||
%template (aioFromDesc) mraa::initIo<mraa::Aio>;
|
||||
%template (uartFromDesc) mraa::initIo<mraa::Uart>;
|
||||
%template (spiFromDesc) mraa::initIo<mraa::Spi>;
|
||||
%template (i2cFromDesc) mraa::initIo<mraa::I2c>;
|
||||
%template (pwmFromDesc) mraa::initIo<mraa::Pwm>;
|
||||
|
||||
%ignore Aio(void* aio_context);
|
||||
%ignore Pwm(void* pwm_context);
|
||||
%ignore Uart(void* uart_context);
|
||||
%ignore Spi(void* spi_context);
|
||||
%ignore I2c(void* i2c_context);
|
||||
%ignore Gpio(void* gpio_context);
|
||||
|
||||
%ignore Gpio::nop(uv_work_t* req);
|
||||
%ignore Gpio::v8isr(uv_work_t* req);
|
||||
|
@@ -1,50 +1,5 @@
|
||||
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||
set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
|
||||
swig_add_module (python-mraa python mraa.i mraapy.c)
|
||||
swig_link_libraries (python-mraa ${PYTHON_LIBRARIES} mraa)
|
||||
|
||||
if (DOXYGEN_FOUND)
|
||||
foreach (_file ${DOCCLASSES})
|
||||
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} ${_file}class_doc_i)
|
||||
endforeach ()
|
||||
add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} common_hpp_doc_i)
|
||||
|
||||
add_custom_target (pydoc
|
||||
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with pydoc" VERBATIM
|
||||
)
|
||||
endif ()
|
||||
|
||||
set_target_properties (${SWIG_MODULE_python-mraa_REAL_NAME} PROPERTIES
|
||||
OUTPUT_NAME _mraa
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
execute_process (
|
||||
COMMAND ${PYTHON_EXECUTABLE} -c
|
||||
"import site, sys; sys.stdout.write(site.PREFIXES[-1])"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX
|
||||
)
|
||||
file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
|
||||
execute_process (
|
||||
COMMAND ${PYTHON_EXECUTABLE} -c
|
||||
"import site, sys; sys.stdout.write(site.getusersitepackages().replace(site.getuserbase(), site.PREFIXES[-1]))"
|
||||
OUTPUT_VARIABLE PYTHON_SITE_DIR
|
||||
)
|
||||
file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
|
||||
string (REGEX REPLACE "^${PYTHON_PREFIX}/" ""
|
||||
PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
|
||||
DESTINATION ${PYTHON_SITE_DIR})
|
||||
|
||||
add_subdirectory (docs)
|
||||
add_subdirectory (python2)
|
||||
add_subdirectory (python3)
|
||||
|
@@ -1,7 +1,3 @@
|
||||
%module(docstring="Python interface to libmraa") mraa
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include typemaps.i
|
||||
%include carrays.i
|
||||
|
39
src/python/python2/CMakeLists.txt
Normal file
39
src/python/python2/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
set_source_files_properties (mraa2.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (mraa2.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
|
||||
|
||||
if (PYTHON2_LIBRARY)
|
||||
message ("PYTHON2 attempting to build!")
|
||||
|
||||
swig_add_module (python2-mraa python mraa2.i ../mraapy.c)
|
||||
swig_link_libraries (python2-mraa ${PYTHON2_LIBRARIES} mraa)
|
||||
|
||||
target_include_directories(${SWIG_MODULE_python2-mraa_REAL_NAME}
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
|
||||
"${PYTHON2_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
if (DOXYGEN_FOUND AND PYTHON2_EXECUTABLE)
|
||||
foreach (_file ${DOCCLASSES})
|
||||
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} ${_file}class_doc_i)
|
||||
endforeach ()
|
||||
add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} common_hpp_doc_i)
|
||||
|
||||
add_custom_target (pydoc
|
||||
pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API documentation with pydoc" VERBATIM
|
||||
)
|
||||
endif ()
|
||||
|
||||
set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
|
||||
OUTPUT_NAME _mraa
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
|
||||
endif()
|
||||
|
||||
add_subdirectory (docs)
|
@@ -36,6 +36,6 @@ if (DOXYGEN_FOUND)
|
||||
COMMENT "Building HTML documentation with Sphinx"
|
||||
)
|
||||
|
||||
add_dependencies (sphinx ${SWIG_MODULE_python-mraa_REAL_NAME})
|
||||
add_dependencies (sphinx ${SWIG_MODULE_python2-mraa_REAL_NAME})
|
||||
endif ()
|
||||
endif ()
|
5
src/python/python2/mraa2.i
Normal file
5
src/python/python2/mraa2.i
Normal file
@@ -0,0 +1,5 @@
|
||||
%module(docstring="Python interface to libmraa") mraa
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include ../mraapython.i
|
24
src/python/python3/CMakeLists.txt
Normal file
24
src/python/python3/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
set_source_files_properties (mraa3.i PROPERTIES CPLUSPLUS ON)
|
||||
set_source_files_properties (mraa3.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
|
||||
|
||||
if (PYTHON3_LIBRARY)
|
||||
message ("PYTHON3 attempting to build!")
|
||||
|
||||
swig_add_module (python3-mraa python mraa3.i ../mraapy.c)
|
||||
swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa)
|
||||
|
||||
target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
|
||||
"${PYTHON3_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
|
||||
OUTPUT_NAME _mraa
|
||||
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
|
||||
)
|
||||
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mraa.py
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH})
|
||||
endif ()
|
3
src/python/python3/mraa3.i
Normal file
3
src/python/python3/mraa3.i
Normal file
@@ -0,0 +1,3 @@
|
||||
%module(docstring="Python interface to libmraa") mraa
|
||||
|
||||
%include ../mraapython.i
|
@@ -1274,8 +1274,9 @@ mraa_intel_edison_fab_c()
|
||||
}
|
||||
|
||||
if (mraa_gpio_read_dir(tristate, &tristate_dir) != MRAA_SUCCESS) {
|
||||
free(b->adv_func);
|
||||
goto error;
|
||||
free(b->pins);
|
||||
free(b->adv_func);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (tristate_dir != MRAA_GPIO_OUT) {
|
||||
|
@@ -378,7 +378,7 @@ mraa_intel_galileo_gen2()
|
||||
b->pins[2].gpio.mux[0].pincmd = PINCMD_SET_DIRECTION;
|
||||
b->pins[2].gpio.mux[0].pin = 35;
|
||||
b->pins[2].gpio.mux[0].value = MRAA_GPIO_IN;
|
||||
b->pins[2].gpio.mux[0].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[2].gpio.mux[1].pincmd = PINCMD_SET_VALUE;
|
||||
b->pins[2].gpio.mux[1].pin = 77;
|
||||
b->pins[2].gpio.mux[1].value = 0;
|
||||
b->pins[2].gpio.complex_cap = (mraa_pin_cap_complex_t){ 1, 1, 0, 1, 1 };
|
||||
|
@@ -126,8 +126,8 @@ mraa_intel_nuc5()
|
||||
}
|
||||
b->i2c_bus_count++;
|
||||
b->i2c_bus[i].bus_id = i2c_num;
|
||||
b->i2c_bus[i].sda = 12 + i;
|
||||
b->i2c_bus[i].scl = 13 + i;
|
||||
b->i2c_bus[i].sda = 12 + (i*2);
|
||||
b->i2c_bus[i].scl = 13 + (i*2);
|
||||
}
|
||||
|
||||
if (b->i2c_bus_count > 0) {
|
||||
|
@@ -9,12 +9,17 @@ if (BUILDSWIGJAVA)
|
||||
endif()
|
||||
|
||||
if (BUILDSWIGPYTHON)
|
||||
add_test (NAME py_general COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
|
||||
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
|
||||
if (PYTHON2INTERP_FOUND)
|
||||
set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python2")
|
||||
elseif (PYTHON3INTERP_FOUND)
|
||||
set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python3")
|
||||
endif ()
|
||||
add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
|
||||
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
||||
add_test (NAME py_platform COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
|
||||
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
|
||||
add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
|
||||
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
||||
add_test (NAME py_gpio COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
|
||||
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_BINARY_DIR}/src/python/")
|
||||
add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
|
||||
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
endif()
|
||||
|
Reference in New Issue
Block a user