upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
mcp9808.h
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 #include "mraa.hpp"
32 #include "mraa/i2c.hpp"
33 
34 #define MCP9808_REG_CONFIG 0x01
35 #define MCP9808_REG_AMBIENT_TEMP 0x05
36 #define MCP9808_REG_MANUF_ID 0x06
37 #define MCP9808_REG_DEVICE_ID 0x07
38 #define MCP9808_REG_RESOLUTION 0x08
39 #define MCP9808_CONFIG_SHUTDOWN 0x0001
40 #define MCP9808_CONFIG_CRITLOCKED 0x8000
41 #define MCP9808_CONFIG_WINLOCKED 0x4000
42 #define MCP9808_CONFIG_INTCLR 0x2000
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  std::string m_name;
318  bool m_celsius;
319  bool m_tcrit;
320  bool m_tupper;
321  bool m_tlower;
322 
323  mraa::I2c* i2c;
324 
325  float getTempValue(uint16_t value);
326  void updateConfigRegister(uint16_t update, bool on = true);
327  uint16_t swapWord(uint16_t value);
328  };
329 }
bool isTupper()
Definition: mcp9808.h:222
void setAlertMode(uint16_t command)
Definition: mcp9808.cxx:105
float getTemp(void)
Definition: mcp9808.cxx:57
MCP9808_RESOLUTION
uint8_t enum containing the four possible values for MCP9808 resolution register. ...
Definition: mcp9808.h:107
void clearAlertMode(void)
Definition: mcp9808.cxx:110
void shutDown(bool sleep=true)
Definition: mcp9808.cxx:71
void setResolution(MCP9808_RESOLUTION value)
Definition: mcp9808.cxx:134
MCP9808(int bus, uint8_t address=0x18)
Definition: mcp9808.cxx:33
void setHysteresis(MCP9808_CONFIG value)
Definition: mcp9808.cxx:118
uint16_t getManufacturer()
Definition: mcp9808.cxx:149
void clearInterrupt(void)
Definition: mcp9808.cxx:100
void setMode(bool celsius=true)
Definition: mcp9808.h:193
~MCP9808()
Definition: mcp9808.cxx:158
uint16_t getDevicedId()
Definition: mcp9808.cxx:154
void setMonitorReg(MCP9808_REG reg, float value)
Definition: mcp9808.cxx:78
float getMonitorReg(MCP9808_REG reg)
Definition: mcp9808.cxx:92
MCP9808_REG
uint8_t enum containing register addresses used for setting temp thresholds for MCP9808 ...
Definition: mcp9808.h:90
std::string name()
Definition: mcp9808.h:170
API for MCP9808 precision temprature sensor.
Definition: mcp9808.h:78
bool isTlower()
Definition: mcp9808.h:232
float getResolution()
Definition: mcp9808.cxx:142
bool isTcrit()
Definition: mcp9808.h:212
float getHysteresis()
Definition: mcp9808.cxx:125
bool isCelsius(void)
Definition: mcp9808.h:202
MCP9808_CONFIG
uint16_t enum containing alert and hysteresis options for config register.
Definition: mcp9808.h:141