1 /* 2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com> 3 * Copyright (c) 2014 Intel Corporation. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 #pragma once 25 26 #include <string> 27 #include <mraa/i2c.hpp> 28 29 #define DEVICE_ADDR 0x5A // device address 30 31 // RAM 32 #define MLX90614_RAWIR1 0x04 33 #define MLX90614_RAWIR2 0x05 34 #define MLX90614_TA 0x06 35 #define MLX90614_TOBJ1 0x07 36 #define MLX90614_TOBJ2 0x08 37 // EEPROM 38 #define MLX90614_TOMAX 0x20 39 #define MLX90614_TOMIN 0x21 40 #define MLX90614_PWMCTRL 0x22 41 #define MLX90614_TARANGE 0x23 42 #define MLX90614_EMISS 0x24 43 #define MLX90614_CONFIG 0x25 44 #define MLX90614_ADDR 0x0E 45 #define MLX90614_ID1 0x3C 46 #define MLX90614_ID2 0x3D 47 #define MLX90614_ID3 0x3E 48 #define MLX90614_ID4 0x3F 49 50 #define HIGH 1 51 #define LOW 0 52 53 namespace upm { 54 55 /** 56 * @brief MLX90614 Temperature Sensor library 57 * @defgroup mlx90614 libupm-mlx90614 58 * @ingroup generic i2c temperature 59 */ 60 /** 61 * @library mlx90614 62 * @sensor mlx90614 63 * @comname MLX90614 Temperature Sensor 64 * @type temperature 65 * @man generic 66 * @con i2c 67 * 68 * @brief API for the MLX90614 Temperature Sensor 69 * 70 * This module defines the MLX90614 interface for libmlx90614 71 * 72 * @image html mlx90614.jpg 73 * @snippet mlx90614.cxx Interesting 74 */ 75 class MLX90614 { 76 public: 77 78 /** 79 * Instantiates an MLX90614 object 80 * 81 * @param bus Number of the used bus 82 * @param devAddr Address of the used I2C device 83 */ 84 MLX90614 (int bus=0, int devAddr=0x5A); 85 86 /** 87 * Reads the object temperature in Fahrenheit 88 */ 89 float readObjectTempF(void); 90 91 /** 92 * Reads the ambient temperature in Fahrenheit 93 */ 94 float readAmbientTempF(void); 95 /** 96 * Reads the object temperature in Celsius 97 */ 98 float readObjectTempC(void); 99 100 /** 101 * Reads the ambient temperature in Celsius 102 */ 103 float readAmbientTempC(void); 104 105 /** 106 * Returns the name of the component 107 */ name()108 std::string name() 109 { 110 return m_name; 111 } 112 private: 113 std::string m_name; 114 115 int m_i2cAddr; 116 int m_bus; 117 mraa::I2c m_i2Ctx; 118 119 uint16_t i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer); 120 mraa::Result i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer); 121 float readTemperature (uint8_t address); 122 }; 123 124 } 125