@@ -87,7 +87,8 @@ void Wippersnapper_AnalogIO::setADCResolution(int resolution) {
87
87
analogReadResolution (16 );
88
88
_nativeResolution = 12 ;
89
89
#elif defined(ARDUINO_ARCH_ESP32)
90
- scaleAnalogRead = false ; // should be false, handled in bsp (analogReadResolution)
90
+ scaleAnalogRead =
91
+ false ; // should be false, handled in bsp (analogReadResolution)
91
92
analogReadResolution (resolution); // 16 bit values (shifted from 12 or 13bit)
92
93
#if defined(ESP32S3)
93
94
_nativeResolution = 13 ; // S3 ADC is 13-bit, others are 12-bit
@@ -323,12 +324,12 @@ bool Wippersnapper_AnalogIO::encodePinEvent(
323
324
@returns True if pin's period expired, False otherwise.
324
325
*/
325
326
/* *********************************************************/
326
- bool Wippersnapper_AnalogIO::timerExpired (long currentTime,
327
- analogInputPin pin, long periodOffset) {
327
+ bool Wippersnapper_AnalogIO::timerExpired (long currentTime, analogInputPin pin,
328
+ long periodOffset) {
328
329
if (pin.period + periodOffset != 0L &&
329
- currentTime - pin.prvPeriod > (pin.period + periodOffset)) {
330
- return true ;
331
- }
330
+ currentTime - pin.prvPeriod > (pin.period + periodOffset)) {
331
+ return true ;
332
+ }
332
333
return false ;
333
334
}
334
335
@@ -348,7 +349,7 @@ void Wippersnapper_AnalogIO::update() {
348
349
349
350
// Does the pin execute on-period?
350
351
if (_analog_input_pins[i].period != 0L &&
351
- timerExpired (millis (), _analog_input_pins[i])) {
352
+ timerExpired (millis (), _analog_input_pins[i])) {
352
353
WS_DEBUG_PRINT (" Executing periodic event on A" );
353
354
WS_DEBUG_PRINTLN (_analog_input_pins[i].pinName );
354
355
@@ -376,18 +377,17 @@ void Wippersnapper_AnalogIO::update() {
376
377
// Does the pin execute on_change?
377
378
else if (_analog_input_pins[i].period == 0L ) {
378
379
379
- // TODO: after testing combine these two conditionals to just send the event and not debug print.
380
+ // TODO: after testing combine these two conditionals to just send the
381
+ // event and not debug print.
380
382
if (_analog_input_pins[i].prvPeriod == 0L ) {
381
- // first time reading pin, no previous timestamp so send event + update prvPeriod
382
- // WS_DEBUG_PRINT("First time reading pin A");
383
+ // first time reading pin, no previous timestamp so send event +
384
+ // update prvPeriod WS_DEBUG_PRINT("First time reading pin A");
383
385
// WS_DEBUG_PRINTLN(_analog_input_pins[i].pinName);
384
- }
385
- else if (timerExpired (millis (), _analog_input_pins[i], 500 )) {
386
+ } else if (timerExpired (millis (), _analog_input_pins[i], 500 )) {
386
387
// timer expired, send event + update prvPeriod
387
388
// WS_DEBUG_PRINT("Timer passed for pin A");
388
389
// WS_DEBUG_PRINTLN(_analog_input_pins[i].pinName);
389
- }
390
- else {
390
+ } else {
391
391
// last event was too recently, skip this one...
392
392
// WS_DEBUG_PRINTLN("Timer has not expired, continue...");
393
393
continue ;
@@ -397,12 +397,14 @@ void Wippersnapper_AnalogIO::update() {
397
397
// pin value
398
398
uint16_t pinValRaw = getPinValue (_analog_input_pins[i].pinName );
399
399
400
- // All boards ADC values scaled to 16bit, in future we may need to adjust dynamically
400
+ // All boards ADC values scaled to 16bit, in future we may need to
401
+ // adjust dynamically
401
402
uint16_t maxDecimalValue = 65535 ;
402
403
403
- // Calculate threshold values - using DEFAULT_HYSTERISIS for first third (1/3) of the range,
404
- // then 2x DEFAULT_HYSTERISIS for the middle 1/3, and 4x DEFAULT_HYSTERISIS for the last 1/3.
405
- // This should allow a more wifi blip tolerant threshold for the both ends of the range.
404
+ // Calculate threshold values - using DEFAULT_HYSTERISIS for first third
405
+ // (1/3) of the range, then 2x DEFAULT_HYSTERISIS for the middle 1/3,
406
+ // and 4x DEFAULT_HYSTERISIS for the last 1/3. This should allow a more
407
+ // wifi blip tolerant threshold for the both ends of the range.
406
408
float CURRENT_HYSTERISIS;
407
409
if (pinValRaw < maxDecimalValue / 3 ) {
408
410
CURRENT_HYSTERISIS = maxDecimalValue * DEFAULT_HYSTERISIS;
@@ -412,15 +414,14 @@ void Wippersnapper_AnalogIO::update() {
412
414
CURRENT_HYSTERISIS = maxDecimalValue * DEFAULT_HYSTERISIS * 4 ;
413
415
}
414
416
415
-
416
-
417
417
// get the threshold values for previous pin value
418
418
uint16_t _pinValThreshHi =
419
419
_analog_input_pins[i].prvPinVal + CURRENT_HYSTERISIS;
420
420
uint16_t _pinValThreshLow =
421
421
_analog_input_pins[i].prvPinVal - CURRENT_HYSTERISIS;
422
422
423
- if (_analog_input_pins[i].prvPeriod == 0 || pinValRaw > _pinValThreshHi || pinValRaw < _pinValThreshLow) {
423
+ if (_analog_input_pins[i].prvPeriod == 0 ||
424
+ pinValRaw > _pinValThreshHi || pinValRaw < _pinValThreshLow) {
424
425
// Perform voltage conversion if we need to
425
426
if (_analog_input_pins[i].readMode ==
426
427
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode_ANALOG_READ_MODE_PIN_VOLTAGE) {
0 commit comments