From 7f561019d794c466becb8a460f327b24abbadb48 Mon Sep 17 00:00:00 2001 From: PloopyCo Date: Fri, 15 Nov 2019 17:41:04 -0500 Subject: [PATCH] fixed hysteretic scroll --- firmware/production/Scroller.cpp | 47 +++++++++++++++++++++----------- firmware/production/Scroller.h | 13 ++++++--- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/firmware/production/Scroller.cpp b/firmware/production/Scroller.cpp index c23b96c..22500d0 100644 --- a/firmware/production/Scroller.cpp +++ b/firmware/production/Scroller.cpp @@ -23,27 +23,29 @@ Scroller::Scroller(void) { state = HIHI; lohif = false; hilof = false; - lowA = 50; - highA = 150; - lowB = 50; - highB = 150; - calculateThreshold(lowA, lowB); + lowA = 1023; + highA = 0; + lowB = 1023; + highB = 0; + scrollThresholdA = 0; + scrollThresholdB = 0; } int Scroller::scroll(int curA, int curB) { - calculateThreshold(curA, curB); + calculateThresholdA(curA); + calculateThresholdB(curB); bool LO = false; bool HI = true; bool sA, sB; int ret = 0; - if (curA < scrollThreshold) + if (curA < scrollThresholdA) sA = LO; else sA = HI; - if (curB < scrollThreshold) + if (curB < scrollThresholdB) sB = LO; else sB = HI; @@ -107,23 +109,36 @@ int Scroller::scroll(int curA, int curB) { return ret; } -int Scroller::getScrollThreshold(void) { - return scrollThreshold; +int Scroller::getScrollThresholdA(void) { + return scrollThresholdA; } -int Scroller::calculateThreshold(int curA, int curB) { +int Scroller::al(void) { + return lowA; +} + +int Scroller::ah(void) { + return highA; +} + +int Scroller::getScrollThresholdB(void) { + return scrollThresholdB; +} + +int Scroller::calculateThresholdA(int curA) { if (curA < lowA) lowA = curA; else if (curA > highA) highA = curA; + scrollThresholdA = ((highA - lowA) / 3) + lowA; +} + +int Scroller::calculateThresholdB(int curB) { if (curB < lowB) lowB = curB; else if (curB > highB) highB = curB; - int avgA = ((highA - lowA) / 3) + lowA; - int avgB = ((highB - lowB) / 3) + lowB; - - scrollThreshold = (avgA + avgB) / 2; -} \ No newline at end of file + scrollThresholdB = ((highB - lowB) / 3) + lowB; +} diff --git a/firmware/production/Scroller.h b/firmware/production/Scroller.h index 2c44a8d..016a781 100644 --- a/firmware/production/Scroller.h +++ b/firmware/production/Scroller.h @@ -30,12 +30,17 @@ class Scroller { int highA; int lowB; int highB; - int scrollThreshold; - int calculateThreshold(int, int); + int scrollThresholdA; + int scrollThresholdB; + int calculateThresholdA(int); + int calculateThresholdB(int); public: Scroller(void); int scroll(int, int); - int getScrollThreshold(void); + int getScrollThresholdA(void); + int getScrollThresholdB(void); + int al(void); + int ah(void); }; -#endif \ No newline at end of file +#endif