diff options
author | alaviss <leorize+oss@disroot.org> | 2022-08-13 18:01:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-13 11:01:44 -0700 |
commit | b1fe7621ebb086a519778030381eb5729e949523 (patch) | |
tree | d429fd6b14e1b3f6c4b6d14b267a956b99398893 /keyboards/ploopyco/opt_encoder.c | |
parent | 4c6ce12d2a671b4e4270648989b7c74ac2876882 (diff) |
RFC: add a simple implementation of the ploopy optical encoder (#17912)
Diffstat (limited to 'keyboards/ploopyco/opt_encoder.c')
-rw-r--r-- | keyboards/ploopyco/opt_encoder.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/keyboards/ploopyco/opt_encoder.c b/keyboards/ploopyco/opt_encoder.c index 8698351c26..226db0a809 100644 --- a/keyboards/ploopyco/opt_encoder.c +++ b/keyboards/ploopyco/opt_encoder.c @@ -15,6 +15,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "opt_encoder.h" +#include <stdbool.h> + +enum State { HIHI, HILO, LOLO, LOHI }; enum State state; @@ -44,6 +47,12 @@ int arHighA[SCROLLER_AR_SIZE]; int arLowB[SCROLLER_AR_SIZE]; int arHighB[SCROLLER_AR_SIZE]; +void calculateThresholdA(int curA); +void calculateThresholdB(int curB); +int calculateThreshold(int cur, int* low, int* high, bool* cLow, bool* cHigh, int arLow[], int arHigh[], int* lowIndex, int* highIndex, bool* lowOverflow, bool* highOverflow); +int thresholdEquation(int lo, int hi); +void incrementIndex(int* index, bool* ovflw); + /* Setup function for the scroll wheel. Initializes the relevant variables. */ void opt_encoder_init(void) { @@ -70,7 +79,7 @@ void opt_encoder_init(void) { scrollThresholdB = 0; } -int opt_encoder_handler(int curA, int curB) { +int8_t opt_encoder_handler(uint16_t curA, uint16_t curB) { if (lowOverflowA == false || highOverflowA == false) calculateThresholdA(curA); if (lowOverflowB == false || highOverflowB == false) calculateThresholdB(curB); |