upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ds18b20.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016-2017 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 <map>
29 
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 
34 #include <mraa/common.hpp>
35 #include <mraa/uart_ow.hpp>
36 
37 #include <ds18b20.h>
38 
39 #define DS18B20_DEFAULT_UART 0
40 
41 namespace upm {
114  class DS18B20 {
115  public:
116 
128  DS18B20(int uart=DS18B20_DEFAULT_UART);
129 
133  ~DS18B20();
134 
139  void init();
140 
148  void update(int index=-1);
149 
160  float getTemperature(unsigned int index, bool fahrenheit=false);
161 
170  void setResolution(unsigned int index, DS18B20_RESOLUTIONS_T res);
171 
178  void copyScratchPad(unsigned int index);
179 
188  void recallEEPROM(unsigned int index);
189 
197  {
198  return ds18b20_devices_found(m_ds18b20);
199  }
200 
209  std::string getId(unsigned int index);
210 
211  protected:
212  ds18b20_context m_ds18b20;
213 
214  private:
215  /* Disable implicit copy and assignment operators */
216  DS18B20(const DS18B20&) = delete;
217  DS18B20 &operator=(const DS18B20&) = delete;
218  };
219 }
unsigned int ds18b20_devices_found(const ds18b20_context dev)
Definition: ds18b20.c:382
DS18B20(int uart=DS18B20_DEFAULT_UART)
Definition: ds18b20.cxx:39
float getTemperature(unsigned int index, bool fahrenheit=false)
Definition: ds18b20.cxx:66
int devicesFound()
Definition: ds18b20.hpp:196
~DS18B20()
Definition: ds18b20.cxx:47
void copyScratchPad(unsigned int index)
Definition: ds18b20.cxx:89
API for the DS18B20 1-Wire Temperature Sensor.
Definition: ds18b20.hpp:114
C API for the DS18B20 1-Wire Temperature Sensor.
Definition: ds18b20.h:52
void recallEEPROM(unsigned int index)
Definition: ds18b20.cxx:100
void setResolution(unsigned int index, DS18B20_RESOLUTIONS_T res)
Definition: ds18b20.cxx:78
void init()
Definition: ds18b20.cxx:52
std::string getId(unsigned int index)
Definition: ds18b20.cxx:111
void update(int index=-1)
Definition: ds18b20.cxx:57