@@ -406,13 +406,36 @@ void Wippersnapper_AnalogIO::update() {
406
406
WS_DEBUG_PRINTLN (F (" \t ADC did not pass hysteresis" ));
407
407
}
408
408
409
+
410
+
411
+ // new plan - add 100 then use 0.1 as the hysteresis, ten percent of current raw value
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+ // take diff in raw value and convert to bits in native resolution, then check for more than 4 bit change (0 to 8 is the noise floor, scaled)
422
+ float diff = abs (pinValRaw - _analog_input_pins[i].prvPinVal );
423
+ // convert diff to original resolution
424
+ diff = diff * (1 << (getADCresolution () - getNativeResolution ()));
425
+ if (diff > 4 ) {
426
+ passed_hysterisys = true ;
427
+ WS_DEBUG_PRINTLN (F (" \t ADC passed hysteresis" ));
428
+ } else {
429
+ WS_DEBUG_PRINTLN (F (" \t ADC did not pass hysteresis" ));
430
+ }
431
+
409
432
// old technique
410
433
uint16_t _pinValThreshHi =
411
434
_analog_input_pins[i].prvPinVal +
412
- (_analog_input_pins[i].prvPinVal * DEFAULT_HYSTERISIS);
435
+ (_analog_input_pins[i].prvPinVal * 0.02 ); // DEFAULT_HYSTERISIS);
413
436
uint16_t _pinValThreshLow =
414
437
_analog_input_pins[i].prvPinVal -
415
- (_analog_input_pins[i].prvPinVal * DEFAULT_HYSTERISIS);
438
+ (_analog_input_pins[i].prvPinVal * 0.02 ); // DEFAULT_HYSTERISIS);
416
439
WS_DEBUG_PRINT (F (" PinValThreshHi: " ));
417
440
WS_DEBUG_PRINT (_pinValThreshHi);
418
441
WS_DEBUG_PRINT (F (" PinValThreshLow: " ));
@@ -435,7 +458,10 @@ void Wippersnapper_AnalogIO::update() {
435
458
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode_ANALOG_READ_MODE_PIN_VALUE) {
436
459
// already fetched raw value, just print it
437
460
WS_DEBUG_PRINT (F (" PinValRaw: " ));
438
- WS_DEBUG_PRINTLN (pinValRaw);
461
+ WS_DEBUG_PRINT (pinValRaw);
462
+ WS_DEBUG_PRINT (F (" PinValPrev: " ));
463
+ WS_DEBUG_PRINTLN (_analog_input_pins[i].prvPinVal );
464
+
439
465
} else {
440
466
WS_DEBUG_PRINTLN (" ERROR: Unable to read pin value, cannot determine "
441
467
" analog read mode!" );
0 commit comments