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 
36 
39 class DS18S20
40 {
41 public:
44  DS18S20();
45 
49  void Init(uint8_t);
50 
54  void StartMeasure();
55 
61 
64  void UnRegisterCallback(); //Unset conversion end function
65 
71  float GetCelsius(uint8_t);
72 
78  float GetFahrenheit(uint8_t);
79 
86  bool IsValidTemperature(uint8_t);
87 
91  bool MeasureStatus();
92 
97  uint64_t GetSensorID(uint8_t);
98 
103  uint8_t GetSensorsCount(); //how many the sensors detected
104 
105  virtual ~DS18S20();
106 
107 private:
108 
109  void DoMeasure();
110  void DoSearch();
111  void StartReadNext();
112  uint8_t FindAlladdresses();
113 
114 private:
115  bool InProgress = false;
116  bool ValidTemperature[MAX_SENSORS];
117  uint8_t addr[8];
118  uint8_t type_s[MAX_SENSORS];
119  uint8_t data[12];
120  uint64_t addresses[MAX_SENSORS];
121  uint8_t numberOf=0;
122  uint8_t numberOfread=0;
123 
124  DS18S20CompletedDelegate readEndCallback;
125 
126  Timer DelaysTimer;
127 
128 
129  float celsius[MAX_SENSORS], fahrenheit[MAX_SENSORS];
130 };
131 
134 #endif /* READFROMDS_H_ */
135 
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.
DS18S20()
Instantiate a DS18S20 object.
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:35
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:39
Definition: Timer.h:29
#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. ...