upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
tex00.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 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 <iostream>
28 #include <vector>
29 
30 #include <mraa/aio.hpp>
31 
32 #define TEX00_DEFAULT_AREF 5.0
33 
34 namespace upm {
77  class TEX00 {
78  public:
79 
80  typedef enum {
81  STYPE_THERMISTOR_TED = 0, // 10k type 2
82  STYPE_THERMISTOR_TEB, // 100 Ohm
83  STYPE_THERMISTOR_TEC, // 1000 Ohm
84  STYPE_THERMISTOR_TEI, // 1000 Ohm
85  STYPE_THERMISTOR_TEE, // 2.2k
86  STYPE_THERMISTOR_TEF, // 3k
87  STYPE_THERMISTOR_TEH, // 10k type 3
88  STYPE_THERMISTOR_TEJ, // 10k Dale
89  STYPE_THERMISTOR_TES, // 10k 3A221
90  STYPE_THERMISTOR_TER, // 10k "G" US
91  STYPE_THERMISTOR_TEM, // 20k NTC
92  STYPE_THERMISTOR_TEU, // 20k "D"
93  STYPE_THERMISTOR_TET // 100k
94  } SENSOR_TYPES_T;
95 
105  TEX00(int tPin, float balanceResistor, SENSOR_TYPES_T stype,
106  float aref=TEX00_DEFAULT_AREF);
107 
111  ~TEX00();
112 
118  void update();
119 
129  float getTemperature(bool fahrenheit=false);
130 
138  float getTemperatureRangeMin();
139 
147  float getTemperatureRangeMax();
148 
158  {
159  return m_outOfRange;
160  }
161 
162  protected:
163  mraa::Aio m_aioTemp;
164 
165  // compute the temperature based on the resistance of the thermistor
166  float thermistor(float ohms);
167 
168  private:
169  float m_aref;
170  int m_aResTemp;
171 
172  // in Celsius
173  float m_temperature;
174  // temp reading out of range
175  bool m_outOfRange;
176 
177  // resistance of the other half of our voltage divider
178  float m_balanceResistor;
179 
180  int average(int samples);
181 
182  // Negative Temperature Coefficient (NTC) or Positive Temperature
183  // Coefficient (PTC)
184  bool m_isNTC;
185 
186  // This may generate a SWIG warning. It can be safely ignored
187  // since this structure is never exposed outside the class.
188  struct tempEntry
189  {
190  tempEntry(float o, float t) : ohms(o), temp(t) {};
191 
192  float ohms;
193  float temp; // in C
194  };
195 
196  // ohms/temperature table store
197  std::vector<tempEntry> m_tempVector;
198 
199  // table temperature init functions
200  void initThermistorTED();
201  void initThermistorTEB();
202  void initThermistorTEC();
203  void initThermistorTEI();
204  void initThermistorTEE();
205  void initThermistorTEF();
206  void initThermistorTEH();
207  void initThermistorTEJ();
208  void initThermistorTES();
209  void initThermistorTER();
210  void initThermistorTEM();
211  void initThermistorTEU();
212  void initThermistorTET();
213  };
214 }
215 
216 
API for the Veris TEX00 Temperature Sensor.
Definition: tex00.hpp:77
float getTemperature(bool fahrenheit=false)
Definition: tex00.cxx:136
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
~TEX00()
Definition: tex00.cxx:119
bool isOutOfRange()
Definition: tex00.hpp:157
float getTemperatureRangeMax()
Definition: tex00.cxx:235
float getTemperatureRangeMin()
Definition: tex00.cxx:224
TEX00(int tPin, float balanceResistor, SENSOR_TYPES_T stype, float aref=TEX00_DEFAULT_AREF)
Definition: tex00.cxx:43
void update()
Definition: tex00.cxx:123