aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/opt_encoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ploopyco/opt_encoder.h')
-rw-r--r--keyboards/ploopyco/opt_encoder.h66
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
29enum State { HIHI, HILO, LOLO, LOHI };
30
31enum State state;
32
33/* Variables used for scroll wheel functionality. */
34bool lohif;
35bool hilof;
36int lowA;
37int highA;
38bool cLowA;
39bool cHighA;
40int lowIndexA;
41int highIndexA;
42bool lowOverflowA;
43bool highOverflowA;
44int lowB;
45int highB;
46bool cLowB;
47bool cHighB;
48int lowIndexB;
49int highIndexB;
50bool lowOverflowB;
51bool highOverflowB;
52int scrollThresholdA;
53int scrollThresholdB;
54int arLowA[SCROLLER_AR_SIZE];
55int arHighA[SCROLLER_AR_SIZE];
56int arLowB[SCROLLER_AR_SIZE];
57int arHighB[SCROLLER_AR_SIZE];
58
59void calculateThresholdA(int curA);
60void calculateThresholdB(int curB);
61int calculateThreshold(int cur, int* low, int* high, bool* cLow, bool* cHigh, int arLow[], int arHigh[], int* lowIndex, int* highIndex, bool* lowOverflow, bool* highOverflow);
62int thresholdEquation(int lo, int hi);
63void incrementIndex(int* index, bool* ovflw);
64
65void opt_encoder_init(void);
66int opt_encoder_handler(int curA, int curB);