@@ -192,74 +192,60 @@ void DS18X20Controller::update() {
192
192
continue ;
193
193
}
194
194
195
- // Create a new sensor_event
196
- _DS18X20_model->InitDS18x20EventMsg ();
197
-
198
- // Are we reading the temperature in Celsius, Fahrenheit, or both?
199
- if (temp_dsx_driver.is_read_temp_c ) {
200
- unsigned long temp_c_start_time = millis ();
201
-
202
- WS_DEBUG_PRINTLN (" Reading temperature in Celsius" ); // TODO: Debug remove
203
195
// Attempt to read the temperature in Celsius
196
+ #ifdef DEBUG_PROFILE
197
+ unsigned long temp_c_start_time = millis ();
198
+ #endif
204
199
if (!temp_dsx_driver.ReadTemperatureC ()) {
205
200
WS_DEBUG_PRINTLN (" ERROR: Unable to read temperature in Celsius" );
206
201
continue ;
207
202
}
203
+ #ifdef DEBUG_PROFILE
204
+ unsigned long temp_c_end_time = millis ();
205
+ WS_DEBUG_PRINT (" Read temperature Celsius time: " );
206
+ WS_DEBUG_PRINTLN (temp_c_end_time - temp_c_start_time);
207
+ #endif
208
+
209
+ // We got a temperature value from the hardware, let's create a new sensor_event
210
+ _DS18X20_model->InitDS18x20EventMsg ();
211
+
212
+ // Are we reading the temperature in Celsius, Fahrenheit, or both?
213
+ if (temp_dsx_driver.is_read_temp_c ) {
208
214
float temp_c = temp_dsx_driver.GetTemperatureC ();
209
215
_DS18X20_model->addSensorEvent (
210
216
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE,
211
217
temp_c);
212
-
213
- unsigned long temp_c_end_time = millis ();
214
- WS_DEBUG_PRINT (" Read temperature Celsius time: " );
215
- WS_DEBUG_PRINTLN (temp_c_end_time - temp_c_start_time);
216
218
}
217
219
if (temp_dsx_driver.is_read_temp_f ) {
218
- unsigned long temp_f_start_time = millis ();
219
-
220
- WS_DEBUG_PRINTLN (" Reading temperature in Fahrenheit" ); // TODO: Debug remove
221
- // Attempt to read the temperature in Fahrenheit
222
- if (!temp_dsx_driver.ReadTemperatureF ()) {
223
- WS_DEBUG_PRINTLN (" ERROR: Unable to read temperature in Fahrenheit" );
224
- continue ;
225
- }
226
220
float temp_f = temp_dsx_driver.GetTemperatureF ();
227
221
_DS18X20_model->addSensorEvent (
228
222
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT,
229
223
temp_f);
230
-
231
- unsigned long temp_f_end_time = millis ();
232
- WS_DEBUG_PRINT (" Read temperature Fahrenheit time: " );
233
- WS_DEBUG_PRINTLN (temp_f_end_time - temp_f_start_time);
234
224
}
235
225
236
- // Get and print out the SensorEvent message's contents
237
- wippersnapper_ds18x20_Ds18x20Event event_msg =
238
- *_DS18X20_model-> GetDS18x20EventMsg () ;
239
- pb_size_t event_count = event_msg. sensor_events_count ;
226
+ // Get the Ds18x20Event message
227
+ wippersnapper_ds18x20_Ds18x20Event* event_msg = _DS18X20_model-> GetDS18x20EventMsg ();
228
+ pb_size_t event_count = event_msg-> sensor_events_count ;
229
+
240
230
231
+ // Print the message's content out for debugging
241
232
WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
242
233
WS_DEBUG_PRINT (temp_dsx_driver.GetOneWirePin ());
243
234
WS_DEBUG_PRINT (" got " );
244
235
WS_DEBUG_PRINT (event_count);
245
236
WS_DEBUG_PRINTLN (" sensor events" );
246
237
for (int i = 0 ; i < event_count; i++) {
247
238
WS_DEBUG_PRINT (" Sensor value: " );
248
- WS_DEBUG_PRINTLN (event_msg. sensor_events [i].value .float_value );
239
+ WS_DEBUG_PRINT (event_msg-> sensor_events [i].value .float_value );
249
240
}
250
241
251
242
// Encode the Ds18x20Event message
252
- unsigned long encode_start_time = millis ();
253
243
if (!_DS18X20_model->EncodeDs18x20Event ()) {
254
244
WS_DEBUG_PRINTLN (" ERROR: Failed to encode Ds18x20Event message" );
255
245
continue ;
256
246
}
257
- unsigned long encode_end_time = millis ();
258
- WS_DEBUG_PRINT (" Encode event message time: " );
259
- WS_DEBUG_PRINTLN (encode_end_time - encode_start_time);
260
247
261
248
// Publish the Ds18x20Event message to the broker
262
- unsigned long publish_start_time = millis ();
263
249
WS_DEBUG_PRINT (" Publishing Ds18x20Event message to broker..." );
264
250
if (!WsV2.PublishSignal (
265
251
wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
@@ -268,16 +254,20 @@ void DS18X20Controller::update() {
268
254
continue ;
269
255
}
270
256
WS_DEBUG_PRINTLN (" Published!" );
271
- unsigned long publish_end_time = millis ();
272
- WS_DEBUG_PRINT (" Publish event message time: " );
273
- WS_DEBUG_PRINTLN (publish_end_time - publish_start_time);
274
257
258
+ #ifdef DEBUG_PROFILE
275
259
unsigned long sensor_end_time = millis ();
276
260
WS_DEBUG_PRINT (" Total sensor processing time: " );
277
261
WS_DEBUG_PRINTLN (sensor_end_time - sensor_start_time);
262
+ #endif
278
263
}
279
264
265
+ #ifdef DEBUG_PROFILE
280
266
unsigned long total_end_time = millis ();
281
- WS_DEBUG_PRINT (" Total update() execution time: " );
282
- WS_DEBUG_PRINTLN (total_end_time - total_start_time);
267
+ if (total_end_time - total_start_time != 0 ) {
268
+ WS_DEBUG_PRINT (" Total update() execution time: " );
269
+ WS_DEBUG_PRINTLN (total_end_time - total_start_time);
270
+ }
271
+ #endif
272
+
283
273
}
0 commit comments