Skip to content

Commit 8611024

Browse files
committed
WIP: stash - swapping to battery test
1 parent 1119470 commit 8611024

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/components/analogIO/Wippersnapper_AnalogIO.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,36 @@ void Wippersnapper_AnalogIO::update() {
406406
WS_DEBUG_PRINTLN(F("\tADC did not pass hysteresis"));
407407
}
408408

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("\tADC passed hysteresis"));
428+
} else {
429+
WS_DEBUG_PRINTLN(F("\tADC did not pass hysteresis"));
430+
}
431+
409432
// old technique
410433
uint16_t _pinValThreshHi =
411434
_analog_input_pins[i].prvPinVal +
412-
(_analog_input_pins[i].prvPinVal * DEFAULT_HYSTERISIS);
435+
(_analog_input_pins[i].prvPinVal * 0.02);// DEFAULT_HYSTERISIS);
413436
uint16_t _pinValThreshLow =
414437
_analog_input_pins[i].prvPinVal -
415-
(_analog_input_pins[i].prvPinVal * DEFAULT_HYSTERISIS);
438+
(_analog_input_pins[i].prvPinVal * 0.02);//DEFAULT_HYSTERISIS);
416439
WS_DEBUG_PRINT(F("PinValThreshHi: "));
417440
WS_DEBUG_PRINT(_pinValThreshHi);
418441
WS_DEBUG_PRINT(F("PinValThreshLow: "));
@@ -435,7 +458,10 @@ void Wippersnapper_AnalogIO::update() {
435458
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode_ANALOG_READ_MODE_PIN_VALUE) {
436459
// already fetched raw value, just print it
437460
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+
439465
} else {
440466
WS_DEBUG_PRINTLN("ERROR: Unable to read pin value, cannot determine "
441467
"analog read mode!");

src/components/analogIO/Wippersnapper_AnalogIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "Wippersnapper.h"
2020

21-
#define DEFAULT_HYSTERISIS 0.04 ///< Default DEFAULT_HYSTERISIS of 0.04 (log10)
21+
#define DEFAULT_HYSTERISIS 0.3 ///< Default DEFAULT_HYSTERISIS of 0.3 (log10)
2222

2323
/** Data about an analog input pin */
2424
struct analogInputPin {

0 commit comments

Comments
 (0)