fixed hysteretic scroll

This commit is contained in:
PloopyCo 2019-11-15 17:41:04 -05:00
parent 82b316027b
commit 7f561019d7
2 changed files with 40 additions and 20 deletions

View File

@ -23,27 +23,29 @@ Scroller::Scroller(void) {
state = HIHI; state = HIHI;
lohif = false; lohif = false;
hilof = false; hilof = false;
lowA = 50; lowA = 1023;
highA = 150; highA = 0;
lowB = 50; lowB = 1023;
highB = 150; highB = 0;
calculateThreshold(lowA, lowB); scrollThresholdA = 0;
scrollThresholdB = 0;
} }
int Scroller::scroll(int curA, int curB) { int Scroller::scroll(int curA, int curB) {
calculateThreshold(curA, curB); calculateThresholdA(curA);
calculateThresholdB(curB);
bool LO = false; bool LO = false;
bool HI = true; bool HI = true;
bool sA, sB; bool sA, sB;
int ret = 0; int ret = 0;
if (curA < scrollThreshold) if (curA < scrollThresholdA)
sA = LO; sA = LO;
else else
sA = HI; sA = HI;
if (curB < scrollThreshold) if (curB < scrollThresholdB)
sB = LO; sB = LO;
else else
sB = HI; sB = HI;
@ -107,23 +109,36 @@ int Scroller::scroll(int curA, int curB) {
return ret; return ret;
} }
int Scroller::getScrollThreshold(void) { int Scroller::getScrollThresholdA(void) {
return scrollThreshold; 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) if (curA < lowA)
lowA = curA; lowA = curA;
else if (curA > highA) else if (curA > highA)
highA = curA; highA = curA;
scrollThresholdA = ((highA - lowA) / 3) + lowA;
}
int Scroller::calculateThresholdB(int curB) {
if (curB < lowB) if (curB < lowB)
lowB = curB; lowB = curB;
else if (curB > highB) else if (curB > highB)
highB = curB; highB = curB;
int avgA = ((highA - lowA) / 3) + lowA; scrollThresholdB = ((highB - lowB) / 3) + lowB;
int avgB = ((highB - lowB) / 3) + lowB;
scrollThreshold = (avgA + avgB) / 2;
} }

View File

@ -30,12 +30,17 @@ class Scroller {
int highA; int highA;
int lowB; int lowB;
int highB; int highB;
int scrollThreshold; int scrollThresholdA;
int calculateThreshold(int, int); int scrollThresholdB;
int calculateThresholdA(int);
int calculateThresholdB(int);
public: public:
Scroller(void); Scroller(void);
int scroll(int, int); int scroll(int, int);
int getScrollThreshold(void); int getScrollThresholdA(void);
int getScrollThresholdB(void);
int al(void);
int ah(void);
}; };
#endif #endif