max31723 :: added new temperature sensor (HAVE ISSUES WITH SPI)

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
Kiveisha Yevgeniy 2014-08-04 18:01:21 +00:00
parent b31e88c233
commit 45f85e9944
7 changed files with 291 additions and 0 deletions

View File

@ -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})

60
examples/max31723.cxx Normal file
View File

@ -0,0 +1,60 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "max31723.h"
#include <signal.h>
int doWork = 0;
upm::MAX31723 *sensor = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
doWork = 1;
}
}
int
main(int argc, char **argv)
{
//! [Interesting]
sensor = new upm::MAX31723(7);
// while (!doWork) {
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
// usleep (3000000);
// }
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

View File

@ -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()

View File

@ -0,0 +1,8 @@
%module jsupm_max31723
%include "../upm.i"
%{
#include "max31723.h"
%}
%include "max31723.h"

116
src/max31723/max31723.cxx Normal file
View File

@ -0,0 +1,116 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include "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);
}

90
src/max31723/max31723.h Normal file
View File

@ -0,0 +1,90 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <mraa/aio.h>
#include <mraa/gpio.h>
#include <mraa/spi.h>
#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 ();
};
}

View File

@ -0,0 +1,9 @@
%module pyupm_max31723
%include "../upm.i"
%feature("autodoc", "3");
%include "max31723.h"
%{
#include "max31723.h"
%}