-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds18b20.h
168 lines (144 loc) · 7.4 KB
/
ds18b20.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* ds18b20.h
*
* Copyright (C) 2020 Matjaz Verbole
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#ifndef DS18B20_H_INCLUDED
#define DS18B20_H_INCLUDED
typedef enum {
RES_9_BIT = 0x00,
RES_10_BIT = 0x01,
RES_11_BIT = 0x02,
RES_12_BIT = 0x03
} thermRes;
#define USE_EEPROM_FOR_ALARM 1
/**
* Initialize library and set data pin.
* @param GPIO data pin which will be used for communication
* @return 'true' if initialized successfully, 'false' otherwise
*/
bool ds18b20_init(uint8_t GPIO);
/**
* Temperature sensor may use parasite power or have its own power.
* This function returns true if a sensor uses parasite power.
* @return 'true' if a sensor uses parasite power, 'false' otherwise
*/
bool ds18b20_is_parasite_power_mode(void);
/**
* There may be more than one temperature sensor connected to a bus.
* This function searches for all ROM codes of a sensors and saves
* their address in address parameter.
* @param address pointer to an array which will be populated with a 8 byte ROM code of a sensor
* @return 'true' if a next sensor address was found, 'false' otherwise (it returns 'false' also if there are no sensors on a bus)
*/
bool ds18b20_search_ROM(uint8_t *address);
/**
* This function checks if there is a temperature alarm triggered on any of connected sensors.
* It saves their address in address parameter.
* @param address pointer to an array which will be populated with a 8 byte ROM code of a sensor with alarm triggered
* @return 'true' if a next sensor address was found, 'false' otherwise (it returns 'false' also if there are no sensors on a bus)
*/
bool ds18b20_alarm_search(uint8_t *address);
/**
* This function may be use if there is only one sensor connected on a bus. Otherwise there will be data collision because
* multiple sensors will give a reply. Function populates code with a family code of a sensor.
* @param code will be populated with a family code if sensor will be found
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_single_get_family_code(uint8_t *code);
/**
* This function may be use if there is only one sensor connected on a bus. Otherwise there will be data collision because
* multiple sensors will give a reply. Function populates serialNumber with a serial number of a sensor.
* @param serialNumber will be populated with a serial number if sensor will be found
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_single_get_serial_number(uint8_t *serialNumber);
/**
* Function gets and returns a measured temperature of a sensor.
* It saves temperature in a temperature parameter.
* @param temperature parameter will be populated with measured temperature of a sensor
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_get_temperature(float *temperature, uint8_t *address);
/**
* Function gets thermometer resolution.
* It saves resolution in a res parameter.
* @param res parameter will be populated with a thermometer resolution
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_get_thermometer_resolution(thermRes *res, uint8_t *address);
/**
* Function sets thermometer resolution.
* @param res wanted resolution for a sensors thermometer (it may be 9, 10, 11 or 12 bit)
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_set_thermometer_resolution(thermRes res, uint8_t *address);
#if USE_EEPROM_FOR_ALARM
/**
* Function sets high and low alarm temperatures. Temperatures are in a degree Celsius.
* @param temperatureHigh high alarm temperature to be set
* @param temperatureLow low alarm temperature to be set
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_set_alarm_temperature(int8_t temperatureHigh, int8_t temperatureLow, uint8_t *address);
/**
* Function sets high alarm temperature. Temperature is in a degree Celsius.
* @param temperatureHigh high alarm temperature to be set
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_set_alarm_temperature_high(int8_t temperatureHigh, uint8_t *address);
/**
* Function sets low alarm temperature. Temperature is in a degree Celsius.
* @param temperatureLow low alarm temperature to be set
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_set_alarm_temperature_low(int8_t temperatureLow, uint8_t *address);
/**
* Function gets high and low alarm temperatures. Temperatures are in a degree Celsius.
* @param temperatureHigh parameter will be populated with a high alarm temperature of a sensor
* @param temperatureLow parameter will be populated with a low alarm temperature of a sensor
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_get_alarm_temperature(int8_t *temperatureHigh, int8_t *temperatureLow, uint8_t *address);
/**
* Function gets high alarm temperature. Temperature is in a degree Celsius.
* @param temperatureHigh parameter will be populated with a high alarm temperature of a sensor
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_get_alarm_temperature_high(int8_t *temperatureHigh, uint8_t *address);
/**
* Function gets low alarm temperature. Temperature is in a degree Celsius.
* @param temperatureLow parameter will be populated with a low alarm temperature of a sensor
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_get_alarm_temperature_low(int8_t *temperatureLow, uint8_t *address);
#else
/**
* Function writes 16 bit number to a sensors EEPROM. If user does not need
* temperature alarm functionality, EEPROM may be used as 2 byte external storage.
* @param data 16 bit number to be stored to an EEPROM
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_single_set_data_EEPROM(uint16_t data, uint8_t *address);
/**
* Function reads 16 bit number from a sensors EEPROM. If user does not need
* temperature alarm functionality, EEPROM may be used as 2 byte external storage.
* @param data 16 bit number to be read from an EEPROM
* @param address if only one sensor is attached on a bus NULL parameter may be used, otherwise it is an 8 byte address of a sensor
* @return 'true' if succeeded, 'false' otherwise
*/
bool ds18b20_single_read_data_EEPROM(uint16_t *data, uint8_t *address);
#endif
#endif /* DS18B20_H_INCLUDED */