aboutsummaryrefslogtreecommitdiff
path: root/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c')
-rw-r--r--keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c174
1 files changed, 174 insertions, 0 deletions
diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
new file mode 100644
index 000000000..88996f829
--- /dev/null
+++ b/keyboards/cannonkeys/satisfaction75/satisfaction_encoder.c
@@ -0,0 +1,174 @@
1#include "satisfaction75.h"
2
3void pre_encoder_mode_change(){
4 if(encoder_mode == ENC_MODE_CLOCK_SET){
5 RTCDateTime timespec;
6 timespec.year = year_config;
7 timespec.month = month_config;
8 timespec.day = day_config;
9 // timespec.dayofweek = last_timespec.dayofweek;
10 // timespec.dstflag = last_timespec.dstflag;
11 timespec.millisecond = (hour_config * 60 + minute_config) * 60 * 1000;
12 rtcSetTime(&RTCD1, &timespec);
13 }
14}
15
16void post_encoder_mode_change(){
17 if(encoder_mode == ENC_MODE_CLOCK_SET){
18 hour_config = (last_minute / 60);
19 minute_config = last_minute % 60;
20 year_config = last_timespec.year;
21 month_config = last_timespec.month;
22 day_config = last_timespec.day;
23 time_config_idx = 0;
24 }
25}
26
27void change_encoder_mode(bool negative){
28 pre_encoder_mode_change();
29 do {
30 if(negative){
31 if (encoder_mode == 0){
32 encoder_mode = _NUM_ENCODER_MODES - 1;
33 } else{
34 encoder_mode = encoder_mode - 1;
35 }
36 } else {
37 encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES;
38 }
39 } while(((1 << encoder_mode) & enabled_encoder_modes) == 0);
40 post_encoder_mode_change();
41}
42
43void update_time_config(int8_t increment){
44 uint8_t day_limit = 31;
45 uint16_t adjusted_year = 1980 + year_config;
46 switch(time_config_idx){
47 case 0: // hour
48 default:
49 hour_config = (hour_config + increment) % 24;
50 if (hour_config < 0){
51 hour_config += 24;
52 }
53 break;
54 case 1: // minute
55 minute_config = (minute_config + increment) % 60;
56 if (minute_config < 0){
57 minute_config += 60;
58 }
59 break;
60 case 2: // year
61 year_config += increment;
62 break;
63 case 3: // month
64 month_config = (month_config % 12) + increment;
65 if (month_config <= 0){
66 month_config += 12;
67 }
68 break;
69 case 4: //day
70 if (month_config == 9 || month_config == 4 || month_config == 6 || month_config == 11){
71 day_limit = 30;
72 } else if(month_config == 2){
73 day_limit = adjusted_year % 4 == 0 && !(adjusted_year % 100 == 0 && adjusted_year % 400 != 0) ? 29 : 28;
74 }
75 day_config = (day_config % day_limit) + increment;
76 if(day_config <= 0){
77 day_config += day_limit;
78 }
79 break;
80 }
81}
82
83uint16_t handle_encoder_clockwise(){
84 uint16_t mapped_code = 0;
85 switch(encoder_mode){
86 default:
87 case ENC_MODE_VOLUME:
88 mapped_code = KC_VOLU;
89 break;
90 case ENC_MODE_MEDIA:
91 mapped_code = KC_MEDIA_NEXT_TRACK;
92 break;
93 case ENC_MODE_SCROLL:
94 mapped_code = KC_WH_D;
95 break;
96 case ENC_MODE_BACKLIGHT:
97 // mapped_code = BL_INC;
98 kb_backlight_config.level = kb_backlight_config.level + 1;
99 if(kb_backlight_config.level > BACKLIGHT_LEVELS){
100 kb_backlight_config.level = BACKLIGHT_LEVELS;
101 }
102 backlight_set(kb_backlight_config.level);
103 break;
104 case ENC_MODE_BRIGHTNESS:
105 mapped_code = KC_BRIGHTNESS_UP;
106 break;
107 case ENC_MODE_CLOCK_SET:
108 update_time_config(1);
109 queue_for_send = true;
110 break;
111 }
112 return mapped_code;
113}
114
115uint16_t handle_encoder_ccw(){
116 uint16_t mapped_code = 0;
117 switch(encoder_mode){
118 default:
119 case ENC_MODE_VOLUME:
120 mapped_code = KC_VOLD;
121 break;
122 case ENC_MODE_MEDIA:
123 mapped_code = KC_MEDIA_PREV_TRACK;
124 break;
125 case ENC_MODE_SCROLL:
126 mapped_code = KC_WH_U;
127 break;
128 case ENC_MODE_BACKLIGHT:
129 // mapped_code = BL_DEC;
130 if(kb_backlight_config.level != 0){
131 kb_backlight_config.level = kb_backlight_config.level - 1;
132 }
133 backlight_set(kb_backlight_config.level);
134 break;
135 case ENC_MODE_BRIGHTNESS:
136 mapped_code = KC_BRIGHTNESS_DOWN;
137 break;
138 case ENC_MODE_CLOCK_SET:
139 update_time_config(-1);
140 queue_for_send = true;
141 break;
142 }
143 return mapped_code;
144}
145
146uint16_t handle_encoder_press(){
147 uint16_t mapped_code = 0;
148 switch(encoder_mode){
149 case ENC_MODE_VOLUME:
150 mapped_code = KC_MUTE;
151 break;
152 case ENC_MODE_MEDIA:
153 mapped_code = KC_MEDIA_PLAY_PAUSE;
154 break;
155 case ENC_MODE_SCROLL:
156 mapped_code = KC_BTN3;
157 break;
158 case ENC_MODE_BACKLIGHT:
159 // mapped_code = BL_TOGG;
160 kb_backlight_config.breathing = !kb_backlight_config.breathing;
161 if(!kb_backlight_config.breathing){
162 breathing_disable();
163 } else{
164 breathing_enable();
165 }
166 break;
167 case ENC_MODE_CLOCK_SET:
168 time_config_idx = (time_config_idx + 1) % 5;
169 default:
170 case ENC_MODE_BRIGHTNESS:
171 break;
172 }
173 return mapped_code;
174}