upm  1.6.0
Sensor/Actuator repository for libmraa (v1.9.0)
mcp9808.hpp
1 /*
2  * Author: Marc Graham <marc@m2ag.net>
3  * Copyright (c) 2015 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 
25 
26 
27 #pragma once
28 
29 #include <iostream>
30 #include <string>
31 
32 #define MCP9808_REG_CONFIG 0x01
33 #define MCP9808_REG_AMBIENT_TEMP 0x05
34 #define MCP9808_REG_MANUF_ID 0x06
35 #define MCP9808_REG_DEVICE_ID 0x07
36 #define MCP9808_REG_RESOLUTION 0x08
37 #define MCP9808_CONFIG_SHUTDOWN 0x0001
38 #define MCP9808_CONFIG_CRITLOCKED 0x8000
39 #define MCP9808_CONFIG_WINLOCKED 0x4000
40 #define MCP9808_CONFIG_INTCLR 0x2000
41 
42 namespace mraa { class I2c;}
43 
44 namespace upm {
78  class MCP9808 {
79 
80  public:
90  typedef enum
91  {
92  UPPER_TEMP = 0x02,
93  LOWER_TEMP = 0x03,
94  CRIT_TEMP = 0x04,
95  } MCP9808_REG;
96 
107  typedef enum
108  {
109  RES_LOW = 0x00,
110  RES_MEDIUM = 0x01,
111  RES_HIGH = 0x02,
112  RES_PRECISION = 0x03
114 
141  typedef enum
142  {
143  ALERTSTAT = 0x1000,
144  ALERTCTRL = 0x0800,
145  ALERTSEL = 0x0400,
146  ALERTPOL = 0x0200,
147  ALERTMODE = 0x0100,
148  HYST_0 = 0x0000,
149  HYST_1_5 = 0x0002,
150  HYST_3_0 = 0x0004,
151  HYST_6_0 = 0x0006
152  } MCP9808_CONFIG;
153 
160  MCP9808 (int bus, uint8_t address = 0x18);
161 
165  ~MCP9808 ();
166 
170  std::string name()
171  {
172  return m_name;
173  }
174 
178  float getTemp(void);
179 
185  void shutDown(bool sleep = true);
186 
193  void setMode(bool celsius = true)
194  {
195  m_celsius = celsius;
196  }
197 
202  bool isCelsius(void)
203  {
204  return m_celsius;
205  }
206 
212  bool isTcrit()
213  {
214  return m_tcrit;
215  }
216 
222  bool isTupper()
223  {
224  return m_tupper;
225  }
226 
232  bool isTlower()
233  {
234  return m_tlower;
235  }
236 
244  void setMonitorReg(MCP9808_REG reg, float value);
245 
253  float getMonitorReg(MCP9808_REG reg);
254 
259  void clearInterrupt(void);
260 
268  void setAlertMode(uint16_t command);
269 
273  void clearAlertMode(void);
274 
281  void setHysteresis(MCP9808_CONFIG value);
282 
286  float getHysteresis();
287 
297  void setResolution(MCP9808_RESOLUTION value);
298 
303  float getResolution();
304 
308  uint16_t getManufacturer();
309 
314  uint16_t getDevicedId();
315 
316  private:
317  /* Disable implicit copy and assignment operators */
318  MCP9808(const MCP9808&) = delete;
319  MCP9808 &operator=(const MCP9808&) = delete;
320 
321  std::string m_name;
322  bool m_celsius;
323  bool m_tcrit;
324  bool m_tupper;
325  bool m_tlower;
326 
327  mraa::I2c* i2c;
328 
329  float getTempValue(uint16_t value);
330  void updateConfigRegister(uint16_t update, bool on = true);
331  uint16_t swapWord(uint16_t value);
332  };
333 }
bool isTupper()
Definition: mcp9808.hpp:222
MCP9808_RESOLUTION
uint8_t enum containing the four possible values for MCP9808 resolution register. ...
Definition: mcp9808.hpp:107
C++ API for the kxtj3 driver.
Definition: a110x.hpp:29
void setMode(bool celsius=true)
Definition: mcp9808.hpp:193
Definition: ads1x15.hpp:30
MCP9808_REG
uint8_t enum containing register addresses used for setting temp thresholds for MCP9808 ...
Definition: mcp9808.hpp:90
std::string name()
Definition: mcp9808.hpp:170
API for MCP9808 precision temprature sensor.
Definition: mcp9808.hpp:78
bool isTlower()
Definition: mcp9808.hpp:232
bool isTcrit()
Definition: mcp9808.hpp:212
bool isCelsius(void)
Definition: mcp9808.hpp:202
MCP9808_CONFIG
uint16_t enum containing alert and hysteresis options for config register.
Definition: mcp9808.hpp:141