Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
ds18s20.h
1 /*
2  * ds18s20.h
3  *
4  * Created on: 01-09-2015
5  * Author: flexiti and Anakod
6  */
7 
8 #ifndef READFROMDS_H_
9 #define READFROMDS_H_
10 
18 #include "../../SmingCore/Wire.h"
19 
20 #define MAX_SENSORS 4
21 
22 // OneWire commands
23 
24 #define COPYSCRATCH 0x48 // Copy EEPROM
25 #define READSCRATCH 0xBE // Read EEPROM
26 #define WRITESCRATCH 0x4E // Write EEPROM
27 #define RECALLSCRATCH 0xB8 // Reload last
28 #define READPOWERSUPPLY 0xB4 // parasite power
29 #define ALARMSEARCH 0xEC // Query for alarm
30 #define STARTCONVO 0x44 // temperature reading
31 
32 #define DS1820_WORK_PIN 2 // default DS1820 on GPIO2, can be changed by Init
33 
38 
41 class DS18S20
42 {
43 public:
46  DS18S20(uint8_t workPin = DS1820_WORK_PIN);
47 
51  void Init(uint8_t);
52 
56  void StartMeasure();
57 
63 
66  void UnRegisterCallback(); //Unset conversion end function
67 
73  float GetCelsius(uint8_t);
74 
80  float GetFahrenheit(uint8_t);
81 
88  bool IsValidTemperature(uint8_t);
89 
93  bool MeasureStatus();
94 
99  uint64_t GetSensorID(uint8_t);
100 
105  uint8_t GetSensorsCount(); //how many the sensors detected
106 
107  virtual ~DS18S20();
108 
109 private:
110 
111  void DoMeasure();
112  void DoSearch();
113  void StartReadNext();
114  uint8_t FindAlladdresses();
115 
116 private:
117  bool InProgress = false;
118  bool ValidTemperature[MAX_SENSORS];
119  uint8_t addr[8];
120  uint8_t type_s[MAX_SENSORS];
121  uint8_t data[12];
122  uint64_t addresses[MAX_SENSORS];
123  uint8_t numberOf=0;
124  uint8_t numberOfread=0;
125 
126  DS18S20CompletedDelegate readEndCallback;
127 
128  Timer DelaysTimer;
129 
130 
131  float celsius[MAX_SENSORS], fahrenheit[MAX_SENSORS];
132 
133  OneWire* ds = nullptr;
134 };
135 
138 #endif /* READFROMDS_H_ */
139 
Definition: OneWire.h:134
bool MeasureStatus()
Check if measurement is in progress.
uint8_t GetSensorsCount()
Get the quantity of sensors detected during last measurement.
bool IsValidTemperature(uint8_t)
Check if the last measurement for a sensor is valid.
uint64_t GetSensorID(uint8_t)
Get the ID (1-wire address) of a sensor.
void Init(uint8_t)
Initiate communication on 1-wire bus.
void StartMeasure()
Start measurement of all connected sensors.
void RegisterEndCallback(DS18S20CompletedDelegate)
Register the callback function that is run when measurement is complete.
Delegate< void()> DS18S20CompletedDelegate
Definition of callback function called on completion of measurement of all DS18S20 sensors...
Definition: ds18s20.h:37
float GetCelsius(uint8_t)
Get the value of the last measurment from a sensor.
float GetFahrenheit(uint8_t)
Get the value of the last measurment from a sensor.
This class implements access to the DS18x20 range of temperature sensors.
Definition: ds18s20.h:41
Definition: Timer.h:26
#define MAX_SENSORS
Maximum quantity of sensors to read.
Definition: ds18s20.h:20
void UnRegisterCallback()
Unregister the callback function to avoid activity after measurement is complete. ...
DS18S20(uint8_t workPin=DS1820_WORK_PIN)
Instantiate a DS18S20 object.