@@ -79,93 +79,93 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
79
79
bool ConfigureAndPrintSensorInfo (bool extendedInsteadOfMedicalRange = false ) {
80
80
// Reset the device
81
81
if (!_mlx90632->reset ()) {
82
- WS_PRINTER. println (F (" Device reset failed" ));
82
+ WS_DEBUG_PRINTLN (F (" Device reset failed" ));
83
83
while (1 ) {
84
84
delay (10 );
85
85
}
86
86
}
87
- WS_PRINTER. println (F (" Device reset: SUCCESS" ));
87
+ WS_DEBUG_PRINTLN (F (" Device reset: SUCCESS" ));
88
88
89
89
uint64_t productID = _mlx90632->getProductID ();
90
- WS_PRINTER. print (F (" Product ID: 0x" ));
91
- WS_PRINTER. print ((uint32_t )(productID >> 32 ), HEX);
92
- WS_PRINTER. println ((uint32_t )(productID & 0xFFFFFFFF ), HEX);
90
+ WS_DEBUG_PRINT (F (" Product ID: 0x" ));
91
+ WS_DEBUG_PRINT ((uint32_t )(productID >> 32 ), HEX);
92
+ WS_DEBUG_PRINTLN ((uint32_t )(productID & 0xFFFFFFFF ), HEX);
93
93
94
94
uint16_t productCode = _mlx90632->getProductCode ();
95
- WS_PRINTER. print (F (" Product Code: 0x" ));
96
- WS_PRINTER. println (productCode, HEX);
95
+ WS_DEBUG_PRINT (F (" Product Code: 0x" ));
96
+ WS_DEBUG_PRINTLN (productCode, HEX);
97
97
98
98
uint16_t eepromVersion = _mlx90632->getEEPROMVersion ();
99
- WS_PRINTER. print (F (" EEPROM Version: 0x" ));
100
- WS_PRINTER. println (eepromVersion, HEX);
99
+ WS_DEBUG_PRINT (F (" EEPROM Version: 0x" ));
100
+ WS_DEBUG_PRINTLN (eepromVersion, HEX);
101
101
102
102
// Decode product code bits
103
103
uint8_t fov = (productCode >> 8 ) & 0x3 ;
104
104
uint8_t package = (productCode >> 5 ) & 0x7 ;
105
105
uint8_t accuracy = productCode & 0x1F ;
106
106
107
- WS_PRINTER. print (F (" FOV: " ));
108
- WS_PRINTER. println (fov == 0 ? F (" 50°" ) : F (" Unknown" ));
107
+ WS_DEBUG_PRINT (F (" FOV: " ));
108
+ WS_DEBUG_PRINTLN (fov == 0 ? F (" 50°" ) : F (" Unknown" ));
109
109
110
- WS_PRINTER. print (F (" Package: " ));
111
- WS_PRINTER. println (package == 1 ? F (" SFN 3x3" ) : F (" Unknown" ));
110
+ WS_DEBUG_PRINT (F (" Package: " ));
111
+ WS_DEBUG_PRINTLN (package == 1 ? F (" SFN 3x3" ) : F (" Unknown" ));
112
112
113
- WS_PRINTER. print (F (" Accuracy: " ));
113
+ WS_DEBUG_PRINT (F (" Accuracy: " ));
114
114
if (accuracy == 1 ) {
115
- WS_PRINTER. println (F (" Medical" ));
115
+ WS_DEBUG_PRINTLN (F (" Medical" ));
116
116
} else if (accuracy == 2 ) {
117
- WS_PRINTER. println (F (" Standard" ));
117
+ WS_DEBUG_PRINTLN (F (" Standard" ));
118
118
} else {
119
- WS_PRINTER. println (F (" Unknown" ));
119
+ WS_DEBUG_PRINTLN (F (" Unknown" ));
120
120
}
121
121
122
122
// Set and get mode - choose one:
123
- WS_PRINTER. println (F (" \n --- Mode Settings ---" ));
123
+ WS_DEBUG_PRINTLN (F (" \n --- Mode Settings ---" ));
124
124
if (!_mlx90632->setMode (MLX90632_MODE_CONTINUOUS)) {
125
125
// if (!_mlx90632->setMode(MLX90632_MODE_STEP)) { // Uncomment
126
126
// for step mode testing if
127
127
// (!_mlx90632->setMode(MLX90632_MODE_SLEEPING_STEP)) { // Uncomment for
128
128
// sleeping step mode testing
129
- WS_PRINTER. println (F (" Failed to set mode" ));
129
+ WS_DEBUG_PRINTLN (F (" Failed to set mode" ));
130
130
while (1 ) {
131
131
delay (10 );
132
132
}
133
133
}
134
134
135
135
// TODO: use Step mode?
136
136
mlx90632_mode_t currentMode = _mlx90632->getMode ();
137
- WS_PRINTER. print (F (" Current mode: " ));
137
+ WS_DEBUG_PRINT (F (" Current mode: " ));
138
138
switch (currentMode) {
139
139
case MLX90632_MODE_HALT:
140
- WS_PRINTER. println (F (" Halt" ));
140
+ WS_DEBUG_PRINTLN (F (" Halt" ));
141
141
break ;
142
142
case MLX90632_MODE_SLEEPING_STEP:
143
- WS_PRINTER. println (F (" Sleeping Step" ));
143
+ WS_DEBUG_PRINTLN (F (" Sleeping Step" ));
144
144
break ;
145
145
case MLX90632_MODE_STEP:
146
- WS_PRINTER. println (F (" Step" ));
146
+ WS_DEBUG_PRINTLN (F (" Step" ));
147
147
break ;
148
148
case MLX90632_MODE_CONTINUOUS:
149
- WS_PRINTER. println (F (" Continuous" ));
149
+ WS_DEBUG_PRINTLN (F (" Continuous" ));
150
150
break ;
151
151
default :
152
- WS_PRINTER. println (F (" Unknown" ));
152
+ WS_DEBUG_PRINTLN (F (" Unknown" ));
153
153
}
154
154
155
155
// set accuracy mode based on medical if detected
156
156
if (accuracy == 1 ) {
157
157
// Set and get measurement select (medical)
158
- WS_PRINTER. println (F (" \n --- Measurement Select Settings ---" ));
158
+ WS_DEBUG_PRINTLN (F (" \n --- Measurement Select Settings ---" ));
159
159
if (!extendedInsteadOfMedicalRange &&
160
160
!_mlx90632->setMeasurementSelect (MLX90632_MEAS_MEDICAL)) {
161
- WS_PRINTER. println (F (" Failed to set measurement select to Medical" ));
161
+ WS_DEBUG_PRINTLN (F (" Failed to set measurement select to Medical" ));
162
162
while (1 ) {
163
163
delay (10 );
164
164
}
165
165
} else if (extendedInsteadOfMedicalRange &&
166
166
!_mlx90632->setMeasurementSelect (
167
167
MLX90632_MEAS_EXTENDED_RANGE)) {
168
- WS_PRINTER. println (
168
+ WS_DEBUG_PRINTLN (
169
169
F (" Failed to set measurement select to Extended Range" ));
170
170
while (1 ) {
171
171
delay (10 );
@@ -174,63 +174,63 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
174
174
175
175
mlx90632_meas_select_t currentMeasSelect =
176
176
_mlx90632->getMeasurementSelect ();
177
- WS_PRINTER. print (F (" Current measurement select: " ));
177
+ WS_DEBUG_PRINT (F (" Current measurement select: " ));
178
178
switch (currentMeasSelect) {
179
179
case MLX90632_MEAS_MEDICAL:
180
- WS_PRINTER. println (F (" Medical" ));
180
+ WS_DEBUG_PRINTLN (F (" Medical" ));
181
181
break ;
182
182
case MLX90632_MEAS_EXTENDED_RANGE:
183
- WS_PRINTER. println (F (" Extended Range" ));
183
+ WS_DEBUG_PRINTLN (F (" Extended Range" ));
184
184
break ;
185
185
default :
186
- WS_PRINTER. println (F (" Unknown" ));
186
+ WS_DEBUG_PRINTLN (F (" Unknown" ));
187
187
}
188
188
}
189
189
190
190
// Set and get refresh rate (default to 2Hz)
191
- WS_PRINTER. println (F (" \n --- Refresh Rate Settings ---" ));
191
+ WS_DEBUG_PRINTLN (F (" \n --- Refresh Rate Settings ---" ));
192
192
if (!_mlx90632->setRefreshRate (MLX90632_REFRESH_2HZ)) {
193
- WS_PRINTER. println (F (" Failed to set refresh rate to 2Hz" ));
193
+ WS_DEBUG_PRINTLN (F (" Failed to set refresh rate to 2Hz" ));
194
194
while (1 ) {
195
195
delay (10 );
196
196
}
197
197
}
198
198
199
199
mlx90632_refresh_rate_t currentRefreshRate = _mlx90632->getRefreshRate ();
200
- WS_PRINTER. print (F (" Current refresh rate: " ));
200
+ WS_DEBUG_PRINT (F (" Current refresh rate: " ));
201
201
switch (currentRefreshRate) {
202
202
case MLX90632_REFRESH_0_5HZ:
203
- WS_PRINTER. println (F (" 0.5 Hz" ));
203
+ WS_DEBUG_PRINTLN (F (" 0.5 Hz" ));
204
204
break ;
205
205
case MLX90632_REFRESH_1HZ:
206
- WS_PRINTER. println (F (" 1 Hz" ));
206
+ WS_DEBUG_PRINTLN (F (" 1 Hz" ));
207
207
break ;
208
208
case MLX90632_REFRESH_2HZ:
209
- WS_PRINTER. println (F (" 2 Hz" ));
209
+ WS_DEBUG_PRINTLN (F (" 2 Hz" ));
210
210
break ;
211
211
case MLX90632_REFRESH_4HZ:
212
- WS_PRINTER. println (F (" 4 Hz" ));
212
+ WS_DEBUG_PRINTLN (F (" 4 Hz" ));
213
213
break ;
214
214
case MLX90632_REFRESH_8HZ:
215
- WS_PRINTER. println (F (" 8 Hz" ));
215
+ WS_DEBUG_PRINTLN (F (" 8 Hz" ));
216
216
break ;
217
217
case MLX90632_REFRESH_16HZ:
218
- WS_PRINTER. println (F (" 16 Hz" ));
218
+ WS_DEBUG_PRINTLN (F (" 16 Hz" ));
219
219
break ;
220
220
case MLX90632_REFRESH_32HZ:
221
- WS_PRINTER. println (F (" 32 Hz" ));
221
+ WS_DEBUG_PRINTLN (F (" 32 Hz" ));
222
222
break ;
223
223
case MLX90632_REFRESH_64HZ:
224
- WS_PRINTER. println (F (" 64 Hz" ));
224
+ WS_DEBUG_PRINTLN (F (" 64 Hz" ));
225
225
break ;
226
226
default :
227
- WS_PRINTER. println (F (" Unknown" ));
227
+ WS_DEBUG_PRINTLN (F (" Unknown" ));
228
228
}
229
229
230
230
// Clear new data flag before starting continuous measurements
231
- WS_PRINTER. println (F (" \\ n--- Starting Continuous Measurements ---" ));
231
+ WS_DEBUG_PRINTLN (F (" \\ n--- Starting Continuous Measurements ---" ));
232
232
if (!_mlx90632->resetNewData ()) {
233
- WS_PRINTER. println (F (" Failed to reset new data flag" ));
233
+ WS_DEBUG_PRINTLN (F (" Failed to reset new data flag" ));
234
234
while (1 ) {
235
235
delay (10 );
236
236
}
@@ -256,36 +256,39 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
256
256
/* ******************************************************************************/
257
257
bool ReadSensorData () {
258
258
bool result = false ;
259
+ if (HasBeenReadInLast200ms ()) {
260
+ WS_DEBUG_PRINTLN (F (" Sensor was read recently, using cached data" ));
261
+ return true ;
262
+ }
259
263
260
264
// Only check new data flag - much more efficient for continuous mode
261
265
if (_mlx90632->isNewData ()) {
262
- WS_PRINTER. print (F (" New Data Available - Cycle Position: " ));
263
- WS_PRINTER. println (_mlx90632->readCyclePosition ());
266
+ WS_DEBUG_PRINT (F (" New Data Available - Cycle Position: " ));
267
+ WS_DEBUG_PRINTLN (_mlx90632->readCyclePosition ());
264
268
265
269
// Read ambient temperature
266
270
_deviceTemp = _mlx90632->getAmbientTemperature ();
267
- WS_PRINTER. print (F (" Ambient Temperature: " ));
268
- WS_PRINTER. print (_deviceTemp, 4 );
269
- WS_PRINTER. println (F (" °C" ));
271
+ WS_DEBUG_PRINT (F (" Ambient Temperature: " ));
272
+ WS_DEBUG_PRINT (_deviceTemp, 4 );
273
+ WS_DEBUG_PRINTLN (F (" °C" ));
270
274
271
275
// Read object temperature
272
276
_objectTemp = _mlx90632->getObjectTemperature ();
273
- WS_PRINTER. print (F (" Object Temperature: " ));
277
+ WS_DEBUG_PRINT (F (" Object Temperature: " ));
274
278
if (isnan (_objectTemp)) {
275
- WS_PRINTER. println (F (" NaN (invalid cycle position)" ));
279
+ WS_DEBUG_PRINTLN (F (" NaN (invalid cycle position)" ));
276
280
} else {
277
- WS_PRINTER. print (_objectTemp, 4 );
278
- WS_PRINTER. println (F (" °C" ));
281
+ WS_DEBUG_PRINT (_objectTemp, 4 );
282
+ WS_DEBUG_PRINTLN (F (" °C" ));
279
283
}
280
284
result = true ;
285
+ _lastRead = millis ();
281
286
// Reset new data flag after reading
282
287
if (!_mlx90632->resetNewData ()) {
283
- WS_PRINTER. println (F (" Failed to reset new data flag" ));
288
+ WS_DEBUG_PRINTLN (F (" Failed to reset new data flag" ));
284
289
}
285
-
286
- WS_PRINTER.println (); // Add blank line between readings
287
290
} else {
288
- WS_PRINTER. println (F (" No new data available, skipping read" ));
291
+ WS_DEBUG_PRINTLN (F (" No new data available, skipping read" ));
289
292
}
290
293
291
294
// Check if we need to trigger a new measurement for step modes
@@ -294,11 +297,9 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
294
297
currentMode == MLX90632_MODE_SLEEPING_STEP) {
295
298
// Trigger single measurement (SOC bit) for step modes
296
299
if (!_mlx90632->startSingleMeasurement ()) {
297
- WS_PRINTER. println (F (" Failed to start single measurement" ));
300
+ WS_DEBUG_PRINTLN (F (" Failed to start single measurement" ));
298
301
}
299
302
}
300
-
301
- _lastRead = millis ();
302
303
return result;
303
304
}
304
305
@@ -315,7 +316,7 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
315
316
if (ReadSensorData () && _deviceTemp != NAN) {
316
317
// TODO: check max/min or error values in datasheet
317
318
// if (_deviceTemp < -40 || _deviceTemp > 125) {
318
- // WS_PRINTER.println (F("Invalid ambient temperature"));
319
+ // WS_DEBUG_PRINTLN (F("Invalid ambient temperature"));
319
320
// return false;
320
321
// }
321
322
// if the sensor was read recently, return the cached temperature
0 commit comments