qmk_firmware/keyboards/nuphy/air75_v2/ansi/ansi.c
2024-04-01 20:14:28 +08:00

277 lines
7.4 KiB
C

/*
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/>.
*/
#include "user_kb.h"
#include "ansi.h"
#include "usb_main.h"
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;
extern uint16_t rf_linking_time;
extern kb_config_t kb_config;
extern DEV_INFO_STRUCT dev_info;
/* qmk process record */
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if(!process_record_user(keycode, record)){
return false;
}
no_act_time = 0;
rf_linking_time = 0;
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) {
if(kb_config.sleep_enable) kb_config.sleep_enable = false;
else kb_config.sleep_enable = true;
f_sleep_show = 1;
eeconfig_update_kb_datablock(&kb_config);
}
return false;
case BAT_SHOW:
if (record->event.pressed) {
f_bat_hold = !f_bat_hold;
}
return false;
case BAT_NUM:
f_bat_num_show = record->event.pressed;
return false;
case RGB_TEST:
f_rgb_test_press = record->event.pressed;
return false;
default:
return true;
}
return true;
}
bool rgb_matrix_indicators_kb(void)
{
if(!rgb_matrix_indicators_user()){
return false;
}
if(f_bat_num_show) {
num_led_show();
}
// fix power-on brightness is abnormal
rgb_matrix_set_color(RGB_MATRIX_LED_COUNT-1, 0, 0, 0);
return true;
}
/* qmk keyboard post init */
void keyboard_post_init_kb(void) {
gpio_init();
rf_uart_init();
wait_ms(500);
rf_device_init();
break_all_key();
dial_sw_fast_scan();
londing_eeprom_data();
keyboard_post_init_user();
}
/* qmk housekeeping task */
void housekeeping_task_kb(void) {
timer_pro();
uart_receive_pro();
uart_send_report_repeat();
dev_sts_sync();
long_press_key();
dial_sw_scan();
side_led_show();
sleep_handle();
housekeeping_task_user();
}