forked from cora35/dr6p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdr6p.c
1282 lines (1083 loc) · 39.2 KB
/
dr6p.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2024 SDK (@sdk66)
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
#include "control/control.h"
#include "rgb_record/rgb_record.h"
#include "rgb_record/rgb_rgblight.h"
#ifdef WIRELESS_ENABLE
# include "wireless.h"
# include "usb_main.h"
# include "lowpower.h"
#endif
typedef union {
uint32_t raw;
struct {
uint8_t flag : 1;
uint8_t devs : 3;
uint8_t record_channel : 4;
uint8_t record_last_mode;
uint8_t last_btdevs : 3;
};
} confinfo_t;
confinfo_t confinfo;
typedef struct {
bool active;
uint32_t timer;
uint32_t interval;
uint32_t times;
uint8_t index;
RGB rgb;
void (*blink_cb)(uint8_t);
} hs_rgb_indicator_t;
enum layers {
_BL = 0,
_FL,
_MBL,
_MFL,
_FBL,
_FFL,
_FMBL,
_FMFL,
_DEFA
};
hs_rgb_indicator_t hs_rgb_indicators[HS_RGB_INDICATOR_COUNT];
hs_rgb_indicator_t hs_rgb_bat[HS_RGB_BAT_COUNT];
void hs_reset_settings(void);
void rgb_matrix_hs_indicator(void);
void rgb_matrix_hs_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times);
void rgb_matrix_hs_set_remain_time(uint8_t index, uint8_t remain_time);
void hs_system_switch(void);
void hs_rgb_blink(uint8_t hs_index,uint8_t r,uint8_t g,uint8_t b);
void hs_light_choose(void);
#define keymap_is_mac_system() ((get_highest_layer(default_layer_state) == _MBL) || (get_highest_layer(default_layer_state) == _FMBL))
#define keymap_is_base_layer() ((get_highest_layer(default_layer_state) == _BL) || (get_highest_layer(default_layer_state) == _MBL))
uint32_t post_init_timer = 0x00;
bool inqbat_flag = false;
bool mac_status = false;
bool charging_state = false;
bool bat_full_flag = false;
bool hs_right_flag = false;
bool hs_left_flag = false;
bool enable_bat_indicators = true;
uint32_t bat_indicator_cnt = true;
static uint32_t ee_clr_timer = 0;
static uint32_t system_timer = 0;
static uint32_t rec_time;
static bool rec_filp;
bool test_white_light_flag = false;
HSV start_hsv;
bool no_record_fg;
bool lower_sleep = false;
extern bool rk_bat_req_flag;
uint8_t buff[] = {14, 8, 2, 1, 1, 1, 1, 1, 1, 1, 0};
void eeconfig_confinfo_update(uint32_t raw) {
eeconfig_update_kb(raw);
}
uint32_t eeconfig_confinfo_read(void) {
return eeconfig_read_kb();
}
void eeconfig_confinfo_default(void) {
confinfo.flag = true;
confinfo.record_channel = 0;
confinfo.record_last_mode = 0xff;
confinfo.last_btdevs = 1;
#ifdef WIRELESS_ENABLE
confinfo.devs = DEVS_USB;
#endif
eeconfig_init_user_datablock();
eeconfig_confinfo_update(confinfo.raw);
#ifdef RGBLIGHT_ENABLE
rgblight_mode(buff[0]);
#endif
}
void eeconfig_confinfo_init(void) {
confinfo.raw = eeconfig_confinfo_read();
if (!confinfo.raw) {
eeconfig_confinfo_default();
}
}
void lpwr_stop_hook_pre(void){
gpio_write_pin_low(LED_POWER_EN_PIN);
gpio_write_pin_low(LED_ENABLE_PIN);
#ifdef HS_LED_BOOSTING_PIN
gpio_write_pin_low(HS_LED_BOOSTING_PIN);
#endif
if (lower_sleep){
md_send_devctrl(MD_SND_CMD_DEVCTRL_USB);
wait_ms(200);
lpwr_set_sleep_wakeupcd(LPWR_WAKEUP_UART);
}
}
void lpwr_wakeup_hook(void){
hs_mode_scan(false,confinfo.devs,confinfo.last_btdevs);
gpio_write_pin_high(LED_POWER_EN_PIN);
gpio_write_pin_high(LED_ENABLE_PIN);
#ifdef HS_LED_BOOSTING_PIN
gpio_write_pin_high(HS_LED_BOOSTING_PIN);
#endif
}
void keyboard_post_init_kb(void) {
#ifdef CONSOLE_ENABLE
debug_enable = true;
#endif
eeconfig_confinfo_init();
#ifdef LED_POWER_EN_PIN
gpio_set_pin_output(LED_POWER_EN_PIN);
gpio_write_pin_high(LED_POWER_EN_PIN);
#ifdef HS_LED_BOOSTING_PIN
gpio_set_pin_output(HS_LED_BOOSTING_PIN);
gpio_write_pin_high(HS_LED_BOOSTING_PIN);
#endif
#ifdef LED_ENABLE_PIN
gpio_set_pin_output(LED_ENABLE_PIN);
gpio_write_pin_high(LED_ENABLE_PIN);
#endif
#ifdef MM_BT_DEF_PIN
setPinInputHigh(MM_BT_DEF_PIN);
#endif
#ifdef MM_2G4_DEF_PIN
setPinInputHigh(MM_2G4_DEF_PIN);
#endif
#endif
#ifdef USB_POWER_EN_PIN
gpio_write_pin_low(USB_POWER_EN_PIN);
gpio_set_pin_output(USB_POWER_EN_PIN);
#endif
#ifdef HS_BAT_CABLE_PIN
setPinInput(HS_BAT_CABLE_PIN);
#endif
#ifdef HS_RIGHT_LED_PIN
setPinInputHigh(HS_RIGHT_LED_PIN);
#endif
#ifdef HS_LEFT_LED_PIN
setPinInputHigh(HS_LEFT_LED_PIN);
#endif
#ifdef BAT_FULL_PIN
setPinInputHigh(BAT_FULL_PIN);
#endif
#ifdef WIRELESS_ENABLE
wireless_init();
// wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = timer_read32();
#endif
keyboard_post_init_user();
rgbrec_init(confinfo.record_channel);
start_hsv = rgb_matrix_get_hsv();
}
#ifdef WIRELESS_ENABLE
void usb_power_connect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_low(USB_POWER_EN_PIN);
# endif
}
void usb_power_disconnect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_high(USB_POWER_EN_PIN);
# endif
}
void suspend_power_down_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_low(LED_POWER_EN_PIN);
# endif
# ifdef LED_ENABLE_PIN
gpio_write_pin_low(LED_ENABLE_PIN);
# endif
suspend_power_down_user();
}
void suspend_wakeup_init_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_high(LED_POWER_EN_PIN);
# endif
# ifdef LED_ENABLE_PIN
gpio_write_pin_high(LED_ENABLE_PIN);
# endif
wireless_devs_change(wireless_get_current_devs(), wireless_get_current_devs(), false);
suspend_wakeup_init_user();
hs_rgb_blink_set_timer(timer_read32());
}
bool lpwr_is_allow_timeout_hook(void) {
if (wireless_get_current_devs() == DEVS_USB) {
return false;
}
return true;
}
void wireless_post_task(void) {
// auto switching devs
if (post_init_timer && timer_elapsed32(post_init_timer) >= 100) {
md_send_devctrl(MD_SND_CMD_DEVCTRL_FW_VERSION); // get the module fw version.
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_BT_EN); // timeout 30min to sleep in bt mode, enable
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_2G4_EN); // timeout 30min to sleep in 2.4g mode, enable
wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = 0x00;
}
hs_mode_scan(false,confinfo.devs,confinfo.last_btdevs);
}
uint32_t wls_process_long_press(uint32_t trigger_time, void *cb_arg) {
uint16_t keycode = *((uint16_t *)cb_arg);
switch (keycode) {
case KC_BT1: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT1, true);
}
} break;
case KC_BT2: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT2, true);
}
} break;
case KC_BT3: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT3, true);
}
} break;
case KC_2G4: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_2g4) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_2G4, true);
}
} break;
case EE_CLR: {
} break;
default:
break;
}
return 0;
}
bool process_record_wls(uint16_t keycode, keyrecord_t *record) {
static uint16_t keycode_shadow = 0x00;
static deferred_token wls_process_long_press_token = INVALID_DEFERRED_TOKEN;
keycode_shadow = keycode;
# ifndef WLS_KEYCODE_PAIR_TIME
# define WLS_KEYCODE_PAIR_TIME 3000
# endif
# define WLS_KEYCODE_EXEC(wls_dev) \
do { \
if (record->event.pressed) { \
if (wireless_get_current_devs() != wls_dev) \
wireless_devs_change(wireless_get_current_devs(), wls_dev, false); \
if (wls_process_long_press_token == INVALID_DEFERRED_TOKEN) { \
wls_process_long_press_token = defer_exec(WLS_KEYCODE_PAIR_TIME, wls_process_long_press, &keycode_shadow); \
} \
} else { \
cancel_deferred_exec(wls_process_long_press_token); \
wls_process_long_press_token = INVALID_DEFERRED_TOKEN; \
} \
} while (false)
switch (keycode) {
case KC_BT1: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT1);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_BT2: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT2);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_BT3: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT3);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_2G4: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode,confinfo.last_btdevs);
if ((mode == hs_2g4) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_2G4);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_USB: {
if (record->event.pressed) {
wireless_devs_change(wireless_get_current_devs(), DEVS_USB, false);
}
} break;
default:
return true;
}
return false;
}
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (test_white_light_flag && record->event.pressed) {
test_white_light_flag = false;
rgb_matrix_set_color_all(0x00, 0x00, 0x00);
}
if (*md_getp_state() == MD_STATE_CONNECTED){
hs_rgb_blink_set_timer(timer_read32());
}
switch (keycode) {
case MO(_FL):
case MO(_MFL):
case MO(_FFL):
case MO(_FMFL): {
if (!record->event.pressed && rgbrec_is_started()) {
if (no_record_fg == true) {
no_record_fg = false;
rgbrec_register_record(keycode, record);
}
no_record_fg = true;
}
break;
}
case RP_END:
case RP_P0:
case RP_P1:
case RP_P2:
case RGB_MOD:
break;
default: {
if (rgbrec_is_started()) {
if (!IS_QK_MOMENTARY(keycode) && record->event.pressed) {
rgbrec_register_record(keycode, record);
return false;
}
}
} break;
}
if (rgbrec_is_started() && (!(keycode == RP_P0 || keycode == RP_P1 || keycode == RP_P2 || keycode == RP_END || keycode == RGB_MOD || keycode == MO(_FL) ||
keycode == MO(_MFL) || keycode == MO(_FFL) || keycode == MO(_FMFL)))) {
return false;
}
return true;
}
void im_rgblight_increase(void) {
HSV rgb = rgblight_get_hsv();
uint8_t mode = rgblight_get_mode();
static uint8_t current_mode = 0;
if (mode == 1) {
current_mode = (rgb.h == 0 && rgb.s != 0) ? 3 : 9;
switch (rgb.h) {
case 40: current_mode = 4; break;
case 80: current_mode = 5; break;
case 120: current_mode = 6; break;
case 160: current_mode = 7; break;
case 200: current_mode = 8; break;
default: break;
}
}
current_mode = (current_mode + 1) % 11;
if (current_mode == 10) {
rgblight_sethsv(0, 255, rgb.v);
rgblight_disable();
} else {
rgblight_enable();
rgblight_mode(buff[current_mode]);
}
switch (current_mode) {
case 3: rgblight_sethsv(0, 255, rgb.v); break;
case 4: rgblight_sethsv(40, 255, rgb.v); break;
case 5: rgblight_sethsv(80, 255, rgb.v); break;
case 6: rgblight_sethsv(120, 255, rgb.v); break;
case 7: rgblight_sethsv(160, 255, rgb.v); break;
case 8: rgblight_sethsv(200, 255, rgb.v); break;
case 9: rgblight_sethsv(0, 0, rgb.v); break;
case 0: rgblight_set_speed(255); break;
default: rgblight_set_speed(200); break;
}
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (process_record_user(keycode, record) != true) {
return false;
}
#ifdef WIRELESS_ENABLE
if (process_record_wls(keycode, record) != true) {
return false;
}
#endif
switch (keycode) {
case SYS_TOG: {
if (record->event.pressed) {
system_timer = timer_read32();
} else {
system_timer = 0;
}
} break;
case KC_FTOG:{
if (record->event.pressed)
{
mac_status = keymap_is_mac_system();
if (keymap_is_base_layer()) {
if (mac_status) {
set_single_persistent_default_layer(_FMBL);
layer_move(0);
} else {
set_single_persistent_default_layer(_FBL);
layer_move(0);
}
} else {
if (mac_status) {
set_single_persistent_default_layer(_MBL);
layer_move(0);
} else {
set_single_persistent_default_layer(_BL);
layer_move(0);
}
}
eeconfig_confinfo_update(confinfo.raw);
}
return false;
break;
}
case KC_TILD:{
if (record->event.pressed){
register_code(KC_LSFT);
register_code(KC_GRV);
}else{
unregister_code(KC_LSFT);
unregister_code(KC_GRV);
}
return false;
break;
}
case QK_BOOT: {
if (record->event.pressed) {
dprintf("into boot!!!\r\n");
eeconfig_disable();
bootloader_jump();
}
} break;
case KC_TEST: {
if (rgbrec_is_started()) {
return false;
}
if (record->event.pressed) {
test_white_light_flag = true;
}
return false;
} break;
case NK_TOGG: {
if (rgbrec_is_started()) {
return false;
}
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x00, 0x6E, 0x00}, 250, 1);
}
} break;
case RL_MOD: {
if (rgbrec_is_started()) {
return false;
}
if (record->event.pressed) {
im_rgblight_increase();
}
return false;
} break;
case EE_CLR: {
if (record->event.pressed) {
ee_clr_timer = timer_read32();
} else {
ee_clr_timer = 0;
}
return false;
} break;
case RGB_SPI: {
if (record->event.pressed) {
if (rgb_matrix_get_speed() >= (RGB_MATRIX_SPD_STEP * 5)) {
}
}
} break;
case RGB_SPD: {
if (record->event.pressed) {
if (rgb_matrix_get_speed() <= RGB_MATRIX_SPD_STEP) {
rgb_matrix_set_speed(RGB_MATRIX_SPD_STEP);
return false;
}
}
} break;
case RGB_VAI: {
if (record->event.pressed) {
if (rgb_matrix_get_val() >= (RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP)) {
start_hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
}
else{
start_hsv.v = rgb_matrix_get_val() + RGB_MATRIX_VAL_STEP;
}
}
} break;
case RGB_VAD: {
if (record->event.pressed) {
if (rgb_matrix_get_val() <= RGB_MATRIX_VAL_STEP) {
for(uint8_t i = 0; i < RGB_MATRIX_LED_COUNT - RGBLED_NUM;i++){
rgb_matrix_set_color(i,0,0,0);
}
start_hsv.v = 0;
}
else{
start_hsv.v = rgb_matrix_get_val() - RGB_MATRIX_VAL_STEP;
}
}
} break;
case TO(_BL): {
if (record->event.pressed) {
if (keymap_is_mac_system()) {
set_single_persistent_default_layer(_BL);
layer_move(0);
}
}
return false;
} break;
case TO(_MBL): {
if (record->event.pressed) {
if (!keymap_is_mac_system()) {
set_single_persistent_default_layer(_MBL);
layer_move(0);
}
}
return false;
} break;
case TO(_FBL): {
if (record->event.pressed) {
if (keymap_is_mac_system()) {
set_single_persistent_default_layer(_FBL);
layer_move(0);
}
}
return false;
} break;
case TO(_FMBL): {
if (record->event.pressed) {
if (!keymap_is_mac_system()) {
set_single_persistent_default_layer(_FMBL);
layer_move(0);
}
}
return false;
} break;
case RP_P0: {
if (record->event.pressed) {
confinfo.record_channel = 0;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
}
return false;
} break;
case RP_P1: {
if (record->event.pressed) {
confinfo.record_channel = 1;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
}
return false;
} break;
case RP_P2: {
if (record->event.pressed) {
confinfo.record_channel = 2;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
}
return false;
} break;
case RP_END: {
if (record->event.pressed) {
if (rgb_matrix_get_mode() != RGB_MATRIX_CUSTOM_RGBR_PLAY) {
return false;
}
if (!rgbrec_is_started()) {
rgbrec_start(confinfo.record_channel);
no_record_fg = false;
rec_time = timer_read32();
rgbrec_set_close_all(HSV_BLACK);
} else {
rec_time = 0;
rgbrec_end(confinfo.record_channel);
}
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
}
return false;
} break;
case RGB_MOD: {
if (record->event.pressed) {
if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_RGBR_PLAY) {
if (rgbrec_is_started()) {
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
no_record_fg = false;
}
if (confinfo.record_last_mode != 0xFF)
rgb_matrix_mode(confinfo.record_last_mode);
else
rgb_matrix_mode(RGB_MATRIX_DEFAULT_MODE);
eeconfig_confinfo_update(confinfo.raw);
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
start_hsv = rgb_matrix_get_hsv();
return false;
}
record_rgbmatrix_increase(&(confinfo.record_last_mode));
eeconfig_confinfo_update(confinfo.raw);
start_hsv = rgb_matrix_get_hsv();
}
return false;
} break;
case RGB_HUI: {
if (record->event.pressed) {
record_color_hsv(true);
start_hsv = rgb_matrix_get_hsv();
}
return false;
} break;
case KC_LCMD: {
if (keymap_is_mac_system()) {
if (keymap_config.no_gui && !rgbrec_is_started()) {
if (record->event.pressed) {
register_code16(KC_LCMD);
} else {
unregister_code16(KC_LCMD);
}
}
}
return true;
} break;
case KC_RCMD: {
if (keymap_is_mac_system()) {
if (keymap_config.no_gui && !rgbrec_is_started()) {
if (record->event.pressed) {
register_code16(KC_RCMD);
} else {
unregister_code16(KC_RCMD);
}
}
}
return true;
} break;
case HS_BATQ: {
rk_bat_req_flag = (confinfo.devs != DEVS_USB) && record->event.pressed;
return false;
} break;
default:
break;
}
return true;
}
void housekeeping_task_user(void) {
uint8_t hs_now_mode;
static uint32_t hs_current_time;
static bool val_value = false;
charging_state = readPin(HS_BAT_CABLE_PIN);
hs_right_flag = readPin(HS_RIGHT_LED_PIN);
hs_left_flag = readPin(HS_LEFT_LED_PIN);
bat_full_flag = readPin(BAT_FULL_PIN);
if (charging_state && (bat_full_flag)) {
hs_now_mode = MD_SND_CMD_DEVCTRL_CHARGING_DONE;
} else if (charging_state) {
hs_now_mode = MD_SND_CMD_DEVCTRL_CHARGING;
} else {
hs_now_mode = MD_SND_CMD_DEVCTRL_CHARGING_STOP;
}
if (!hs_current_time || timer_elapsed32(hs_current_time) > 1000) {
hs_current_time = timer_read32();
md_send_devctrl(hs_now_mode);
md_send_devctrl(MD_SND_CMD_DEVCTRL_INQVOL);
}
if (charging_state){
#ifdef HS_LED_BOOSTING_PIN
writePin(HS_LED_BOOSTING_PIN,0);
#endif
if(!val_value){
rgb_matrix_sethsv_noeeprom(start_hsv.h,start_hsv.s,150);
}
val_value = true;
}
else{
#ifdef HS_LED_BOOSTING_PIN
writePin(HS_LED_BOOSTING_PIN,1);
#endif
if(val_value){
rgb_matrix_sethsv(start_hsv.h,start_hsv.s,start_hsv.v);
}
val_value = false;
}
}
#ifdef RGB_MATRIX_ENABLE
# ifdef WIRELESS_ENABLE
bool wls_rgb_indicator_reset = false;
uint32_t wls_rgb_indicator_timer = 0x00;
uint32_t wls_rgb_indicator_interval = 0;
uint32_t wls_rgb_indicator_times = 0;
uint32_t wls_rgb_indicator_index = 0;
RGB wls_rgb_indicator_rgb = {0};
void rgb_matrix_wls_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
wls_rgb_indicator_timer = timer_read32();
wls_rgb_indicator_index = index;
wls_rgb_indicator_interval = interval;
wls_rgb_indicator_times = times * 2;
wls_rgb_indicator_rgb = rgb;
}
void wireless_devs_change_kb(uint8_t old_devs, uint8_t new_devs, bool reset) {
wls_rgb_indicator_reset = reset;
if (confinfo.devs != wireless_get_current_devs()) {
confinfo.devs = wireless_get_current_devs();
if (confinfo.devs > 0 && confinfo.devs < 4) confinfo.last_btdevs = confinfo.devs;
eeconfig_confinfo_update(confinfo.raw);
}
switch (new_devs) {
case DEVS_BT1: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT1, (RGB){HS_LBACK_COLOR_BT1}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT1, (RGB){HS_PAIR_COLOR_BT1}, 500, 1);
}
} break;
case DEVS_BT2: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT2, (RGB){HS_LBACK_COLOR_BT2}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT2, (RGB){HS_PAIR_COLOR_BT2}, 500, 1);
}
} break;
case DEVS_BT3: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT3, (RGB){HS_LBACK_COLOR_BT3}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_BT3, (RGB){HS_PAIR_COLOR_BT3}, 500, 1);
}
} break;
case DEVS_2G4: {
if (reset) {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_2G4, (RGB){HS_LBACK_COLOR_2G4}, 200, 1);
} else {
rgb_matrix_wls_indicator_set(HS_RGB_BLINK_INDEX_2G4, (RGB){HS_LBACK_COLOR_2G4}, 500, 1);
}
} break;
default:
break;
}
}
bool rgb_matrix_wls_indicator_cb(void) {
if (*md_getp_state() != MD_STATE_CONNECTED) {
wireless_devs_change_kb(wireless_get_current_devs(), wireless_get_current_devs(), wls_rgb_indicator_reset);
return true;
}
// refresh led
led_wakeup();
return false;
}
void rgb_matrix_wls_indicator(void) {
if (wls_rgb_indicator_timer) {
if (timer_elapsed32(wls_rgb_indicator_timer) >= wls_rgb_indicator_interval) {
wls_rgb_indicator_timer = timer_read32();
if (wls_rgb_indicator_times) {
wls_rgb_indicator_times--;
}
if (wls_rgb_indicator_times <= 0) {
wls_rgb_indicator_timer = 0x00;
if (rgb_matrix_wls_indicator_cb() != true) {
return;
}
}
}
if (wls_rgb_indicator_times % 2) {
rgb_matrix_set_color(wls_rgb_indicator_index, wls_rgb_indicator_rgb.r, wls_rgb_indicator_rgb.g, wls_rgb_indicator_rgb.b);
} else {
rgb_matrix_set_color(wls_rgb_indicator_index, 0x00, 0x00, 0x00);
}
}
}
void rgb_matrix_hs_bat_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
for (int i = 0; i < HS_RGB_BAT_COUNT; i++) {
if (!hs_rgb_bat[i].active) {
hs_rgb_bat[i].active = true;
hs_rgb_bat[i].timer = timer_read32();
hs_rgb_bat[i].interval = interval;
hs_rgb_bat[i].times = times * 2;
hs_rgb_bat[i].index = index;
hs_rgb_bat[i].rgb = rgb;
break;
}
}
}
void rgb_matrix_hs_bat(void) {
for (int i = 0; i < HS_RGB_BAT_COUNT; i++) {
if (hs_rgb_bat[i].active) {
if (timer_elapsed32(hs_rgb_bat[i].timer) >= hs_rgb_bat[i].interval) {
hs_rgb_bat[i].timer = timer_read32();
if (hs_rgb_bat[i].times) {
hs_rgb_bat[i].times--;
}
if (hs_rgb_bat[i].times <= 0) {
hs_rgb_bat[i].active = false;
hs_rgb_bat[i].timer = 0x00;
}
}
if (hs_rgb_bat[i].times % 2) {
rgb_matrix_set_color(hs_rgb_bat[i].index, hs_rgb_bat[i].rgb.r, hs_rgb_bat[i].rgb.g, hs_rgb_bat[i].rgb.b);
} else {
rgb_matrix_set_color(hs_rgb_bat[i].index, 0x00, 0x00, 0x00);
}
}
}
}
# endif
#endif
bool hs_reset_settings_user(void) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){WIITE_B,WIITE_B,WIITE_B}, 250, 3);
return true;
}
void nkr_indicators_hook(uint8_t index) {
if ((hs_rgb_indicators[index].rgb.r == WIITE_B) && (hs_rgb_indicators[index].rgb.g == 0x00) && (hs_rgb_indicators[index].rgb.b == 0x00)) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){WIITE_B, 0x00, 0x00}, 250, 1);
} else if ((hs_rgb_indicators[index].rgb.r == 0x00) && (hs_rgb_indicators[index].rgb.g == 0x6E) && (hs_rgb_indicators[index].rgb.b == 0x00)) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x00, 0x00, WIITE_B}, 250, 1);
}