From: Kiveisha Yevgeniy Date: Mon, 4 Aug 2014 18:01:21 +0000 (+0000) Subject: max31723 :: added new temperature sensor (HAVE ISSUES WITH SPI) X-Git-Tag: v0.1.6~12 X-Git-Url: http://review.tizen.org/git/?p=contrib%2Fupm.git;a=commitdiff_plain;h=45f85e99442cbb50da3724dee609f051bc6bdd68 max31723 :: added new temperature sensor (HAVE ISSUES WITH SPI) Signed-off-by: Kiveisha Yevgeniy --- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9fc6ffa..5d14ecd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -22,6 +22,7 @@ add_executable (pulsensor-example pulsensor.cxx) add_executable (mic-example mic-example.cxx) add_executable (mpu9150-example mpu9150-example.cxx) add_executable (maxds3231m-example maxds3231m.cxx) +add_executable (max31723-example max31723.cxx) include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l) include_directories (${PROJECT_SOURCE_DIR}/src/grove) @@ -42,6 +43,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/pulsensor) include_directories (${PROJECT_SOURCE_DIR}/src/mic) include_directories (${PROJECT_SOURCE_DIR}/src/mpu9150) include_directories (${PROJECT_SOURCE_DIR}/src/maxds3231m) +include_directories (${PROJECT_SOURCE_DIR}/src/max31723) target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT}) @@ -67,3 +69,4 @@ target_link_libraries (pulsensor-example pulsensor ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (mic-example mic ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (mpu9150-example mpu9150 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (maxds3231m-example maxds3231m ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries (max31723-example max31723 ${CMAKE_THREAD_LIBS_INIT}) diff --git a/examples/max31723.cxx b/examples/max31723.cxx new file mode 100644 index 0000000..a1c413b --- /dev/null +++ b/examples/max31723.cxx @@ -0,0 +1,60 @@ +/* + * Author: Yevgeniy Kiveisha + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include "max31723.h" +#include + +int doWork = 0; +upm::MAX31723 *sensor = NULL; + +void +sig_handler(int signo) +{ + printf("got signal\n"); + if (signo == SIGINT) { + printf("exiting application\n"); + doWork = 1; + } +} + +int +main(int argc, char **argv) +{ + //! [Interesting] + sensor = new upm::MAX31723(7); + + // while (!doWork) { + std::cout << "Temperature " << sensor->getTemperature() << std::endl; + // usleep (3000000); + // } + //! [Interesting] + + std::cout << "exiting application" << std::endl; + + delete sensor; + + return 0; +} diff --git a/src/max31723/CMakeLists.txt b/src/max31723/CMakeLists.txt new file mode 100644 index 0000000..911b374 --- /dev/null +++ b/src/max31723/CMakeLists.txt @@ -0,0 +1,5 @@ +set (libname "max31723") +set (libdescription "Very accurate temperature sensor") +set (module_src ${libname}.cxx) +set (module_h ${libname}.h) +upm_module_init() diff --git a/src/max31723/jsupm_max31723.i b/src/max31723/jsupm_max31723.i new file mode 100644 index 0000000..e35ead5 --- /dev/null +++ b/src/max31723/jsupm_max31723.i @@ -0,0 +1,8 @@ +%module jsupm_max31723 +%include "../upm.i" + +%{ + #include "max31723.h" +%} + +%include "max31723.h" diff --git a/src/max31723/max31723.cxx b/src/max31723/max31723.cxx new file mode 100644 index 0000000..69bc6d7 --- /dev/null +++ b/src/max31723/max31723.cxx @@ -0,0 +1,116 @@ +/* + * Author: Yevgeniy Kiveisha + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include + +#include "max31723.h" + +using namespace upm; + +struct MAX31723Exception : public std::exception { + std::string message; + MAX31723Exception (std::string msg) : message (msg) { } + ~MAX31723Exception () throw () { } + const char* what() const throw () { return message.c_str(); } +}; + +MAX31723::MAX31723 (int csn) { + mraa_result_t error = MRAA_SUCCESS; + m_name = "MAX31723"; + + m_csnPinCtx = mraa_gpio_init (csn); + if (m_csnPinCtx == NULL) { + throw MAX31723Exception ("GPIO failed to initilize"); + } + + error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT); + if (error != MRAA_SUCCESS) { + throw MAX31723Exception ("GPIO failed to initilize"); + } + + m_spi = mraa_spi_init (0); + if (m_spi == NULL) { + throw MAX31723Exception ("SPI failed to initilize"); + } + + CSOff (); +} + +MAX31723::~MAX31723() { + mraa_result_t error = MRAA_SUCCESS; + + error = mraa_spi_stop(m_spi); + if (error != MRAA_SUCCESS) { + mraa_result_print(error); + } + error = mraa_gpio_close (m_csnPinCtx); + if (error != MRAA_SUCCESS) { + mraa_result_print(error); + } +} + +uint16_t +MAX31723::getTemperature () { + uint8_t lsb = 0; + uint8_t msb = 0; + uint8_t buf[2] = { 0x01, 0x00}; + + CSOn (); + + uint8_t* x = mraa_spi_write_buf(m_spi, buf, 2); + + printf ("%d\n", (uint16_t)*x); + + /*mraa_spi_write (m_spi, R_TEMPERATURE_LSB); + lsb = mraa_spi_write (m_spi, lsb); + lsb >>= 4;*/ + + /*mraa_spi_write (m_spi, R_TEMPERATURE_MSB); + msb = mraa_spi_write (m_spi, msb); + + if ((msb & 0x80) != 0) + msb |= ~((1 << 8) - 1);*/ + + CSOff (); + + return msb; +} + +/* + * ************** + * private area + * ************** + */ + +mraa_result_t +MAX31723::CSOn () { + return mraa_gpio_write (m_csnPinCtx, HIGH); +} + +mraa_result_t +MAX31723::CSOff () { + return mraa_gpio_write (m_csnPinCtx, LOW); +} diff --git a/src/max31723/max31723.h b/src/max31723/max31723.h new file mode 100644 index 0000000..e187707 --- /dev/null +++ b/src/max31723/max31723.h @@ -0,0 +1,90 @@ +/* + * Author: Yevgeniy Kiveisha + * Copyright (c) 2014 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#include +#include +#include +#include + +#define HIGH 1 +#define LOW 0 + +namespace upm { + +/** + * @brief C++ API for MAX31723 chip (Temperature sensor) + * + * This file defines the MAX31723 C++ interface for libmax31723 + * + */ +class MAX31723 { + public: + static const uint8_t R_STS_READ_CMD = 0x00; + static const uint8_t R_STS_WRITE_CMD = 0x80; + static const uint8_t R_TEMPERATURE_LSB = 0x01; + static const uint8_t R_TEMPERATURE_MSB = 0x02; + + /** + * Instanciates a MAX31723 object + * + * @param bus number of used bus + * @param devAddr addres of used i2c device + */ + MAX31723 (int csn); + + /** + * MAXDS3231M object destructor, basicaly it close i2c connection. + */ + ~MAX31723 (); + + /** + * Get on board temperature. + */ + uint16_t getTemperature (); + + /** + * Return name of the component + */ + std::string name() + { + return m_name; + } + private: + std::string m_name; + mraa_spi_context m_spi; + mraa_gpio_context m_csnPinCtx; + + /** + * Set chip select pin LOW + */ + mraa_result_t CSOn (); + + /** + * Set chip select pin HIGH + */ + mraa_result_t CSOff (); +}; + +} diff --git a/src/max31723/pyupm_max31723.i b/src/max31723/pyupm_max31723.i new file mode 100644 index 0000000..9c13c95 --- /dev/null +++ b/src/max31723/pyupm_max31723.i @@ -0,0 +1,9 @@ +%module pyupm_max31723 +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "max31723.h" +%{ + #include "max31723.h" +%}