From 12b2ab699156d86856760ed7f53b89fa031730bd Mon Sep 17 00:00:00 2001 From: Kiveisha Yevgeniy Date: Tue, 10 Jun 2014 13:34:27 +0000 Subject: [PATCH] max44000: Added swig to the module and set i2c methods as public Signed-off-by: Kiveisha Yevgeniy --- src/max44000/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ src/max44000/max44000.cxx | 6 +++--- src/max44000/max44000.h | 21 +++++++++++++++------ src/max44000/pyupm_max44000.i | 2 ++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/max44000/CMakeLists.txt b/src/max44000/CMakeLists.txt index ab75f7c..666c527 100644 --- a/src/max44000/CMakeLists.txt +++ b/src/max44000/CMakeLists.txt @@ -3,6 +3,41 @@ add_library (max44000 SHARED max44000.cxx) include_directories (${MAA_INCLUDE_DIR}) target_link_libraries (max44000 ${MAA_LIBRARIES}) +if (SWIG_FOUND) + find_package (PythonLibs) + + include_directories ( + ${PYTHON_INCLUDE_PATH} + ${PYTHON_INCLUDE_DIRS} + ${MAA_INCLUDE_DIR} + . + ) + + set_source_files_properties (pyupm_max44000.i PROPERTIES CPLUSPLUS ON) + set_source_files_properties (jsupm_max44000.i PROPERTIES CPLUSPLUS ON) + set_source_files_properties (jsupm_max44000.i PROPERTIES SWIG_FLAGS "-node") + + swig_add_module (pyupm_max44000 python pyupm_max44000.i max44000.cxx) +# swig_add_module (jsupm_grove javascript jsupm_grove.i grove.cxx) + + swig_link_libraries (pyupm_max44000 ${PYTHON_LIBRARIES} ${MAA_LIBRARIES}) +# swig_link_libraries (jsupm_grove ${MAA_LIBRARIES}) + + if (DOXYGEN_FOUND) + set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) + add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n + ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml + ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i + DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml + ) + add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i) + add_dependencies (${libname}doc_i doc) + add_dependencies (${SWIG_MODULE_pyupm_grove_REAL_NAME} ${libname}doc_i) + endif () + +endif () + install (TARGETS ${libname} DESTINATION lib/upm COMPONENT ${libname}) install (FILES max44000.h DESTINATION include/upm COMPONENT ${libname}) diff --git a/src/max44000/max44000.cxx b/src/max44000/max44000.cxx index 4205fc6..d755a76 100644 --- a/src/max44000/max44000.cxx +++ b/src/max44000/max44000.cxx @@ -43,8 +43,8 @@ MAX44000::MAX44000 (int bus, int devAddr) { fprintf(stderr, "Messed up i2c bus\n"); } - i2cWriteReg (MCR, 0x2C); - i2cWriteReg (TCR, 0x6); + // i2cWriteReg (MCR, 0x2C); + // i2cWriteReg (TCR, 0x6); } MAX44000::~MAX44000() { @@ -64,7 +64,7 @@ MAX44000::getProximity () { uint16_t MAX44000::getAmbient () { uint16_t data = 0; - + data = (i2cReadReg_8 (ALSDATA_HIGH) & 0x7F) << 8; data = data | i2cReadReg_8 (ALSDATA_LOW); diff --git a/src/max44000/max44000.h b/src/max44000/max44000.h index 88b997c..d2d4ff7 100644 --- a/src/max44000/max44000.h +++ b/src/max44000/max44000.h @@ -29,12 +29,23 @@ #define ADDR 0x4A // device address // registers address -#define ALSDATA_HIGH 0x04 // ambient sensor data high byte -#define ALSDATA_LOW 0x05 // ambient sensor data low byte -#define PRXDATA 0x15 // proximity sensor data +#define ISR 0x00 // Interrupt Status Register #define MCR 0x01 // Main Configuration Register #define RCR 0x02 // Receive Configuration Register #define TCR 0x03 // Transmit Configuration Register +#define ALSDATA_HIGH 0x04 // ambient sensor data high byte +#define ALSDATA_LOW 0x05 // ambient sensor data low byte +#define PRXDATA 0x15 // proximity sensor data + +#define ALS_UP_THRESH_HIGH 0x06 // ALS Interrupt Threshold Registers High +#define ALS_UP_THRESH_LOW 0x07 // ALS Interrupt Threshold Registers LOW +#define ALS_LO_THRESH_HIGH 0x08 // ALS Interrupt Threshold Registers High +#define ALS_LO_THRESH_LOW 0x09 // ALS Interrupt Threshold Registers Low +#define TPTR 0x0A // ALS/PROX Threshold Persist Timer Register +#define PROX_THRESH_IND 0x0B // Proximity Threshold Register +#define PROX_THRESH 0x0C // Proximity Threshold Register +#define TRIM_GAIN_GREEN 0x0F // Digital Gain Trim Register +#define TRIM_GAIN_IR 0x10 // Digital Gain Trim Register #define HIGH 1 #define LOW 0 @@ -90,14 +101,12 @@ class MAX44000 { { return m_name; } - private: - uint16_t getALSData (); - uint16_t getPRXData (); uint8_t i2cReadReg_8 (int reg); uint16_t i2cReadReg_16 (int reg); maa_result_t i2cWriteReg (uint8_t reg, uint8_t value); + private: std::string m_name; int m_maxControlAddr; diff --git a/src/max44000/pyupm_max44000.i b/src/max44000/pyupm_max44000.i index 3d38b76..4ed0c77 100644 --- a/src/max44000/pyupm_max44000.i +++ b/src/max44000/pyupm_max44000.i @@ -1,5 +1,7 @@ %module pyupm_max44000 +%include "stdint.i" + %feature("autodoc", "3"); %include "max44000.h" -- 2.7.4