diff options
Diffstat (limited to 'keyboards/ploopyco/opt_encoder.h')
-rw-r--r-- | keyboards/ploopyco/opt_encoder.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/keyboards/ploopyco/opt_encoder.h b/keyboards/ploopyco/opt_encoder.h new file mode 100644 index 000000000..23a170d59 --- /dev/null +++ b/keyboards/ploopyco/opt_encoder.h | |||
@@ -0,0 +1,66 @@ | |||
1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | ||
2 | * Copyright 2020 Ploopy Corporation | ||
3 | * | ||
4 | * This program is free software: you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation, either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | #pragma once | ||
18 | |||
19 | #include <stdbool.h> | ||
20 | |||
21 | #ifndef SCROLLER_AR_SIZE | ||
22 | # define SCROLLER_AR_SIZE 31 | ||
23 | #endif | ||
24 | |||
25 | #ifndef SCROLL_THRESH_RANGE_LIM | ||
26 | # define SCROLL_THRESH_RANGE_LIM 10 | ||
27 | #endif | ||
28 | |||
29 | enum State { HIHI, HILO, LOLO, LOHI }; | ||
30 | |||
31 | enum State state; | ||
32 | |||
33 | /* Variables used for scroll wheel functionality. */ | ||
34 | bool lohif; | ||
35 | bool hilof; | ||
36 | int lowA; | ||
37 | int highA; | ||
38 | bool cLowA; | ||
39 | bool cHighA; | ||
40 | int lowIndexA; | ||
41 | int highIndexA; | ||
42 | bool lowOverflowA; | ||
43 | bool highOverflowA; | ||
44 | int lowB; | ||
45 | int highB; | ||
46 | bool cLowB; | ||
47 | bool cHighB; | ||
48 | int lowIndexB; | ||
49 | int highIndexB; | ||
50 | bool lowOverflowB; | ||
51 | bool highOverflowB; | ||
52 | int scrollThresholdA; | ||
53 | int scrollThresholdB; | ||
54 | int arLowA[SCROLLER_AR_SIZE]; | ||
55 | int arHighA[SCROLLER_AR_SIZE]; | ||
56 | int arLowB[SCROLLER_AR_SIZE]; | ||
57 | int arHighB[SCROLLER_AR_SIZE]; | ||
58 | |||
59 | void calculateThresholdA(int curA); | ||
60 | void calculateThresholdB(int curB); | ||
61 | int calculateThreshold(int cur, int* low, int* high, bool* cLow, bool* cHigh, int arLow[], int arHigh[], int* lowIndex, int* highIndex, bool* lowOverflow, bool* highOverflow); | ||
62 | int thresholdEquation(int lo, int hi); | ||
63 | void incrementIndex(int* index, bool* ovflw); | ||
64 | |||
65 | void opt_encoder_init(void); | ||
66 | int opt_encoder_handler(int curA, int curB); | ||