Skip to content

Commit 3cbb1be

Browse files
committed
Cleanup
1 parent a16f9d1 commit 3cbb1be

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

examples/Alarm/Alarm.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void setup()
1212
Serial.begin(57600);
1313
while (!Serial);
1414

15-
// Set sensor alarm triggers (20..25 C) and resolution (10 bits)
16-
// Iterate though all thermometers and configure.
15+
// Set thermometer sensor alarm triggers (20..25 C) and resolution
16+
// (10 bits). Iterate all sensors and write configuration.
1717
uint8_t* rom = sensor.rom();
1818
int8_t last = owi.FIRST;
1919
do {
@@ -28,8 +28,9 @@ void setup()
2828
void loop()
2929
{
3030
// Check if any thermometer sersors have exceeded thresholds.
31-
// Broadcast a convert request to all thermometer sensors.
32-
// Print timestamp and sensor identity and temperature.
31+
// Broadcast a convert request to all sensors: Print timestamp,
32+
// sensor identity (rom) and temperature for all that report an
33+
// alarm
3334

3435
int8_t last = owi.FIRST;
3536
uint8_t* rom = sensor.rom();

src/Driver/DS18B20.h

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DS18B20 : public OWI::Device {
137137
}
138138

139139
/**
140-
* Return remaining convertion time in milliseconds.
140+
* Return remaining conversion time in milliseconds.
141141
* @return milliseconds remaining.
142142
*/
143143
uint16_t conversion_time()
@@ -150,6 +150,18 @@ class DS18B20 : public OWI::Device {
150150
return (0);
151151
}
152152

153+
/**
154+
* Check if the temperature conversion is completed.
155+
* @return true(1) if ready otherwise false(0).
156+
*/
157+
bool convert_ready()
158+
{
159+
if (!m_converting) return (true);
160+
bool res = m_owi.read(1);
161+
if (res) m_converting = false;
162+
return (res);
163+
}
164+
153165
/**
154166
* Delay until the temperature conversion is completed
155167
* by polling the sensors.
@@ -158,16 +170,15 @@ class DS18B20 : public OWI::Device {
158170
bool convert_await()
159171
{
160172
if (!m_converting) return (false);
161-
while (m_owi.read(1) == 0) delayMicroseconds(100);
162-
m_converting = false;
173+
while (!convert_ready()) delay(1);
163174
return (true);
164175
}
165176

166177
/**
167-
* Read the contents of the scratchpad to local memory. An internal
168-
* delay will occur if a convert_request() is pending. The delay is
169-
* at most max conversion time (750 ms). Call with match parameter
170-
* false if used with search_rom().
178+
* Read the contents of the scratchpad to local memory. Call
179+
* convert_ready(), convert_await() or delay with amount from
180+
* conversion_time() before reading. Call with match parameter false
181+
* if used with search_rom().
171182
* @param[in] match rom code (default true).
172183
* @return true(1) if successful otherwise false(0).
173184
*/
@@ -180,7 +191,9 @@ class DS18B20 : public OWI::Device {
180191

181192
/**
182193
* Write the contents of the scratchpad triggers and configuration
183-
* (3 bytes) to device.
194+
* (3 bytes) to device. Call with match parameter false if used with
195+
* search_rom().
196+
* @param[in] match rom code (default true).
184197
* @return true(1) if successful otherwise false(0).
185198
*/
186199
bool write_scratchpad(bool match = true)
@@ -192,23 +205,26 @@ class DS18B20 : public OWI::Device {
192205

193206
/**
194207
* Copy device scratchpad triggers and configuration data to device
195-
* EEPROM.
208+
* EEPROM. Call with match parameter false if used with search_rom().
209+
* @param[in] match rom code (default true).
196210
* @return true(1) if successful otherwise false(0).
197211
*/
198-
bool copy_scratchpad()
212+
bool copy_scratchpad(bool match = true)
199213
{
200-
if (!m_owi.match_rom(m_rom)) return (false);
214+
if (match && !m_owi.match_rom(m_rom)) return (false);
201215
m_owi.write(COPY_SCRATCHPAD);
202216
return (true);
203217
}
204218

205219
/**
206220
* Recall the alarm triggers and configuration from device EEPROM.
221+
* Call with match parameter false if used with search_rom().
222+
* @param[in] match rom code (default true).
207223
* @return true(1) if successful otherwise false(0).
208224
*/
209-
bool recall()
225+
bool recall(bool match = true)
210226
{
211-
if (!m_owi.match_rom(m_rom)) return (false);
227+
if (match && !m_owi.match_rom(m_rom)) return (false);
212228
m_owi.write(RECALL_E);
213229
return (true);
214230
}

0 commit comments

Comments
 (0)