2023-12-25 14:16:06 +00:00
|
|
|
/*
|
|
|
|
Copyright 2023 @ Nuphy <https://nuphy.com/>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-12-27 17:03:37 +00:00
|
|
|
#include "user_kb.h"
|
2023-12-25 14:16:06 +00:00
|
|
|
#include "ansi.h"
|
|
|
|
#include "usb_main.h"
|
|
|
|
|
2023-12-27 17:03:37 +00:00
|
|
|
extern bool f_rf_sw_press;
|
|
|
|
extern bool f_sleep_show;
|
|
|
|
extern bool f_dev_reset_press;
|
|
|
|
extern bool f_bat_num_show;
|
|
|
|
extern bool f_rgb_test_press;
|
|
|
|
extern bool f_bat_hold;
|
|
|
|
extern uint16_t no_act_time;
|
|
|
|
extern uint8_t rf_sw_temp;
|
|
|
|
extern uint16_t rf_sw_press_delay;
|
2024-01-08 14:52:14 +00:00
|
|
|
extern uint16_t rf_linking_time;
|
2024-04-01 12:14:28 +00:00
|
|
|
extern kb_config_t kb_config;
|
2023-12-27 17:03:37 +00:00
|
|
|
extern DEV_INFO_STRUCT dev_info;
|
2023-12-25 14:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* qmk process record */
|
2024-01-24 07:21:18 +00:00
|
|
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
|
|
|
if(!process_record_user(keycode, record)){
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-25 14:16:06 +00:00
|
|
|
no_act_time = 0;
|
2024-01-08 14:52:14 +00:00
|
|
|
rf_linking_time = 0;
|
|
|
|
|
2023-12-25 14:16:06 +00:00
|
|
|
switch (keycode) {
|
|
|
|
case RF_DFU:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (dev_info.link_mode != LINK_USB) return false;
|
|
|
|
uart_send_cmd(CMD_RF_DFU, 10, 20);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case LNK_USB:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
break_all_key();
|
|
|
|
} else {
|
|
|
|
dev_info.link_mode = LINK_USB;
|
|
|
|
uart_send_cmd(CMD_SET_LINK, 10, 10);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case LNK_RF:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (dev_info.link_mode != LINK_USB) {
|
|
|
|
rf_sw_temp = LINK_RF_24;
|
|
|
|
f_rf_sw_press = 1;
|
|
|
|
break_all_key();
|
|
|
|
}
|
|
|
|
} else if (f_rf_sw_press) {
|
|
|
|
f_rf_sw_press = 0;
|
|
|
|
|
|
|
|
if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) {
|
|
|
|
dev_info.link_mode = rf_sw_temp;
|
|
|
|
dev_info.rf_channel = rf_sw_temp;
|
|
|
|
dev_info.ble_channel = rf_sw_temp;
|
|
|
|
uart_send_cmd(CMD_SET_LINK, 10, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case LNK_BLE1:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (dev_info.link_mode != LINK_USB) {
|
|
|
|
rf_sw_temp = LINK_BT_1;
|
|
|
|
f_rf_sw_press = 1;
|
|
|
|
break_all_key();
|
|
|
|
}
|
|
|
|
} else if (f_rf_sw_press) {
|
|
|
|
f_rf_sw_press = 0;
|
|
|
|
|
|
|
|
if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) {
|
|
|
|
dev_info.link_mode = rf_sw_temp;
|
|
|
|
dev_info.rf_channel = rf_sw_temp;
|
|
|
|
dev_info.ble_channel = rf_sw_temp;
|
|
|
|
uart_send_cmd(CMD_SET_LINK, 10, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case LNK_BLE2:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (dev_info.link_mode != LINK_USB) {
|
|
|
|
rf_sw_temp = LINK_BT_2;
|
|
|
|
f_rf_sw_press = 1;
|
|
|
|
break_all_key();
|
|
|
|
}
|
|
|
|
} else if (f_rf_sw_press) {
|
|
|
|
f_rf_sw_press = 0;
|
|
|
|
|
|
|
|
if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) {
|
|
|
|
dev_info.link_mode = rf_sw_temp;
|
|
|
|
dev_info.rf_channel = rf_sw_temp;
|
|
|
|
dev_info.ble_channel = rf_sw_temp;
|
|
|
|
uart_send_cmd(CMD_SET_LINK, 10, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case LNK_BLE3:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
if (dev_info.link_mode != LINK_USB) {
|
|
|
|
rf_sw_temp = LINK_BT_3;
|
|
|
|
f_rf_sw_press = 1;
|
|
|
|
break_all_key();
|
|
|
|
}
|
|
|
|
} else if (f_rf_sw_press) {
|
|
|
|
f_rf_sw_press = 0;
|
|
|
|
|
|
|
|
if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) {
|
|
|
|
dev_info.link_mode = rf_sw_temp;
|
|
|
|
dev_info.rf_channel = rf_sw_temp;
|
|
|
|
dev_info.ble_channel = rf_sw_temp;
|
|
|
|
uart_send_cmd(CMD_SET_LINK, 10, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case MAC_VOICE:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
host_consumer_send(0xcf);
|
|
|
|
} else {
|
|
|
|
host_consumer_send(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case MAC_DND:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
host_system_send(0x9b);
|
|
|
|
} else {
|
|
|
|
host_system_send(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_VAI:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_light_contol(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_VAD:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_light_contol(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_MOD:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_mode_control(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_HUI:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_colour_control(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_SPI:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_speed_contol(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SIDE_SPD:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
side_speed_contol(0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case DEV_RESET:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
f_dev_reset_press = 1;
|
|
|
|
break_all_key();
|
|
|
|
} else {
|
|
|
|
f_dev_reset_press = 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case SLEEP_MODE:
|
|
|
|
if (record->event.pressed) {
|
2024-04-01 12:14:28 +00:00
|
|
|
if(kb_config.sleep_enable) kb_config.sleep_enable = false;
|
|
|
|
else kb_config.sleep_enable = true;
|
2023-12-25 14:16:06 +00:00
|
|
|
f_sleep_show = 1;
|
2024-04-01 12:14:28 +00:00
|
|
|
eeconfig_update_kb_datablock(&kb_config);
|
2023-12-25 14:16:06 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case BAT_SHOW:
|
|
|
|
if (record->event.pressed) {
|
|
|
|
f_bat_hold = !f_bat_hold;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case BAT_NUM:
|
2024-02-05 01:38:43 +00:00
|
|
|
f_bat_num_show = record->event.pressed;
|
2023-12-25 14:16:06 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case RGB_TEST:
|
2024-02-05 01:38:43 +00:00
|
|
|
f_rgb_test_press = record->event.pressed;
|
2023-12-25 14:16:06 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-24 07:21:18 +00:00
|
|
|
return true;
|
2023-12-25 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-05 01:38:43 +00:00
|
|
|
bool rgb_matrix_indicators_kb(void)
|
2023-12-25 14:16:06 +00:00
|
|
|
{
|
2024-02-05 01:38:43 +00:00
|
|
|
if(!rgb_matrix_indicators_user()){
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-25 14:16:06 +00:00
|
|
|
if(f_bat_num_show) {
|
|
|
|
num_led_show();
|
|
|
|
}
|
2024-01-08 14:52:14 +00:00
|
|
|
|
|
|
|
// fix power-on brightness is abnormal
|
2023-12-25 14:16:06 +00:00
|
|
|
rgb_matrix_set_color(RGB_MATRIX_LED_COUNT-1, 0, 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* qmk keyboard post init */
|
2024-02-05 01:38:43 +00:00
|
|
|
void keyboard_post_init_kb(void) {
|
|
|
|
|
2023-12-25 14:16:06 +00:00
|
|
|
gpio_init();
|
|
|
|
rf_uart_init();
|
|
|
|
wait_ms(500);
|
|
|
|
rf_device_init();
|
|
|
|
|
|
|
|
break_all_key();
|
|
|
|
dial_sw_fast_scan();
|
|
|
|
londing_eeprom_data();
|
2024-02-05 01:38:43 +00:00
|
|
|
keyboard_post_init_user();
|
2023-12-25 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* qmk housekeeping task */
|
2024-02-05 01:38:43 +00:00
|
|
|
void housekeeping_task_kb(void) {
|
|
|
|
|
2023-12-25 14:16:06 +00:00
|
|
|
timer_pro();
|
|
|
|
|
|
|
|
uart_receive_pro();
|
|
|
|
|
2024-01-08 14:52:14 +00:00
|
|
|
uart_send_report_repeat();
|
2023-12-25 14:16:06 +00:00
|
|
|
|
|
|
|
dev_sts_sync();
|
|
|
|
|
|
|
|
long_press_key();
|
|
|
|
|
|
|
|
dial_sw_scan();
|
|
|
|
|
|
|
|
side_led_show();
|
|
|
|
|
|
|
|
sleep_handle();
|
2024-02-05 01:38:43 +00:00
|
|
|
|
|
|
|
housekeeping_task_user();
|
2023-12-25 14:16:06 +00:00
|
|
|
}
|