1 #include "satisfaction75.h"
3 void pre_encoder_mode_change(){
4 if(encoder_mode == ENC_MODE_CLOCK_SET){
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, ×pec);
16 void 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;
27 void change_encoder_mode(bool negative){
28 pre_encoder_mode_change();
31 if (encoder_mode == 0){
32 encoder_mode = _NUM_ENCODER_MODES - 1;
34 encoder_mode = encoder_mode - 1;
37 encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES;
39 } while(((1 << encoder_mode) & enabled_encoder_modes) == 0);
40 post_encoder_mode_change();
43 void 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){
49 hour_config = (hour_config + increment) % 24;
55 minute_config = (minute_config + increment) % 60;
56 if (minute_config < 0){
61 year_config += increment;
64 month_config = (month_config % 12) + increment;
65 if (month_config <= 0){
70 if (month_config == 9 || month_config == 4 || month_config == 6 || month_config == 11){
72 } else if(month_config == 2){
73 day_limit = adjusted_year % 4 == 0 && !(adjusted_year % 100 == 0 && adjusted_year % 400 != 0) ? 29 : 28;
75 day_config = (day_config % day_limit) + increment;
77 day_config += day_limit;
83 uint16_t handle_encoder_clockwise(){
84 uint16_t mapped_code = 0;
88 mapped_code = KC_VOLU;
91 mapped_code = KC_MEDIA_NEXT_TRACK;
94 mapped_code = KC_WH_D;
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;
102 backlight_set(kb_backlight_config.level);
104 case ENC_MODE_BRIGHTNESS:
105 mapped_code = KC_BRIGHTNESS_UP;
107 case ENC_MODE_CLOCK_SET:
108 update_time_config(1);
109 queue_for_send = true;
115 uint16_t handle_encoder_ccw(){
116 uint16_t mapped_code = 0;
117 switch(encoder_mode){
119 case ENC_MODE_VOLUME:
120 mapped_code = KC_VOLD;
123 mapped_code = KC_MEDIA_PREV_TRACK;
125 case ENC_MODE_SCROLL:
126 mapped_code = KC_WH_U;
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;
133 backlight_set(kb_backlight_config.level);
135 case ENC_MODE_BRIGHTNESS:
136 mapped_code = KC_BRIGHTNESS_DOWN;
138 case ENC_MODE_CLOCK_SET:
139 update_time_config(-1);
140 queue_for_send = true;
146 uint16_t handle_encoder_press(){
147 uint16_t mapped_code = 0;
148 switch(encoder_mode){
149 case ENC_MODE_VOLUME:
150 mapped_code = KC_MUTE;
153 mapped_code = KC_MEDIA_PLAY_PAUSE;
155 case ENC_MODE_SCROLL:
156 mapped_code = KC_BTN3;
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){
167 case ENC_MODE_CLOCK_SET:
168 time_config_idx = (time_config_idx + 1) % 5;
170 case ENC_MODE_BRIGHTNESS: