From 5064d01d63b9bbfbea58ea42627c0b2352b48faa Mon Sep 17 00:00:00 2001 From: jcdeA <31413538+JcdeA@users.noreply.github.com> Date: Sat, 22 Aug 2020 08:43:16 +0900 Subject: [PATCH 1/2] Optimize code --- keyboards/annepro2/annepro2.c | 25 ++++++++++++ keyboards/annepro2/annepro2.h | 9 ++++- .../annepro2/keymaps/codetector/keymap.c | 28 -------------- keyboards/annepro2/keymaps/default/keymap.c | 38 +------------------ 4 files changed, 34 insertions(+), 66 deletions(-) diff --git a/keyboards/annepro2/annepro2.c b/keyboards/annepro2/annepro2.c index 42523acae0df..87d78ff317bf 100644 --- a/keyboards/annepro2/annepro2.c +++ b/keyboards/annepro2/annepro2.c @@ -2,6 +2,7 @@ #include "hal.h" #include "annepro2.h" #include "annepro2_ble.h" +#include "qmk_ap2_led.h" static const SerialConfig ledUartConfig = { .speed = 115200, @@ -52,21 +53,45 @@ bool OVERRIDE process_record_kb(uint16_t keycode, keyrecord_t *record) { case KC_AP2_BT1: annepro2_ble_broadcast(0); return false; + case KC_AP2_BT2: annepro2_ble_broadcast(1); return false; + case KC_AP2_BT3: annepro2_ble_broadcast(2); return false; + case KC_AP2_BT4: annepro2_ble_broadcast(3); return false; + case KC_AP2_USB: annepro2_ble_disconnect(); return false; + case KC_AP2_BT_UNPAIR: annepro2_ble_unpair(); return false; + + case KC_AP_LED_OFF: + annepro2LedDisable(); + annepro2LedPrevProfile(); + return false; + + case KC_AP_LED_ON: + annepro2LedNextProfile(); + annepro2LedEnable(); + return false; + + case KC_AP_LED_NEXT_PROFILE: + annepro2LedNextProfile(); + return false; + + case KC_AP_LED_PREV_PROFILE: + annepro2LedPrevProfile(); + return false; + default: break; } diff --git a/keyboards/annepro2/annepro2.h b/keyboards/annepro2/annepro2.h index 8c6b58fcf403..1a81861147c2 100644 --- a/keyboards/annepro2/annepro2.h +++ b/keyboards/annepro2/annepro2.h @@ -16,7 +16,7 @@ */ #pragma once - +#include "annepro2.h" #include "quantum.h" #define OVERRIDE __attribute__ ((noinline)) @@ -32,3 +32,10 @@ enum AP2KeyCodes { KC_AP2_USB, AP2_SAFE_RANGE, }; + +enum custom_keys { + KC_AP_LED_ON = AP2_SAFE_RANGE, + KC_AP_LED_OFF, + KC_AP_LED_NEXT_PROFILE, + KC_AP_LED_PREV_PROFILE +}; diff --git a/keyboards/annepro2/keymaps/codetector/keymap.c b/keyboards/annepro2/keymaps/codetector/keymap.c index f1af4cdcb394..9b32e3dd8831 100644 --- a/keyboards/annepro2/keymaps/codetector/keymap.c +++ b/keyboards/annepro2/keymaps/codetector/keymap.c @@ -9,11 +9,6 @@ enum anne_pro_layers { _FN_LAYER, }; -enum custom_keys { - KC_AP_LED_ON = AP2_SAFE_RANGE, - KC_AP_LED_OFF, -}; - const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [_BASE_LAYER] = KEYMAP( /* Base */ KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, @@ -58,26 +53,3 @@ void matrix_scan_user(void) { layer_state_t layer_state_set_user(layer_state_t layer) { return layer; } - -/*! - * @returns false processing for this keycode has been completed. - */ -bool process_record_user(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case KC_AP_LED_OFF: - if (record->event.pressed) { - annepro2LedDisable(); - annepro2LedPrevProfile(); - } - return false; - case KC_AP_LED_ON: - if (record->event.pressed) { - annepro2LedEnable(); - annepro2LedNextProfile(); - } - return false; - default: - break; - } - return true; -} diff --git a/keyboards/annepro2/keymaps/default/keymap.c b/keyboards/annepro2/keymaps/default/keymap.c index e4818e5d2561..a5053d6563e7 100644 --- a/keyboards/annepro2/keymaps/default/keymap.c +++ b/keyboards/annepro2/keymaps/default/keymap.c @@ -7,12 +7,7 @@ enum anne_pro_layers { _FN1_LAYER, _FN2_LAYER, }; -enum custom_keys { - KC_AP_LED_ON = AP2_SAFE_RANGE, - KC_AP_LED_OFF, - KC_AP_LED_NEXT_PROFILE, - KC_AP_LED_PREV_PROFILE -}; + /* * Layer _BASE_LAYER * ,-----------------------------------------------------------------------------------------. @@ -105,34 +100,3 @@ void matrix_scan_user(void) { layer_state_t layer_state_set_user(layer_state_t layer) { return layer; } - -/*! - * @returns false processing for this keycode has been completed. - */ -bool process_record_user(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case KC_AP_LED_OFF: - if (record->event.pressed) { - annepro2LedDisable(); - annepro2LedPrevProfile(); - } - return false; - case KC_AP_LED_ON: - if (record->event.pressed) { - annepro2LedEnable(); - annepro2LedNextProfile(); - } - return false; - case KC_AP_LED_NEXT_PROFILE: - if (record->event.pressed) - annepro2LedNextProfile(); - return false; - case KC_AP_LED_PREV_PROFILE: - if (record->event.pressed) - annepro2LedPrevProfile(); - return false; - default: - break; - } - return true; -} From 061045e96f311d4850ae92059c8654c78242353f Mon Sep 17 00:00:00 2001 From: jcdeA <31413538+JcdeA@users.noreply.github.com> Date: Sat, 22 Aug 2020 10:19:55 +0900 Subject: [PATCH 2/2] switch to prev profile before turning leds off --- keyboards/annepro2/annepro2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/annepro2/annepro2.c b/keyboards/annepro2/annepro2.c index 87d78ff317bf..fd180695916b 100644 --- a/keyboards/annepro2/annepro2.c +++ b/keyboards/annepro2/annepro2.c @@ -75,8 +75,8 @@ bool OVERRIDE process_record_kb(uint16_t keycode, keyrecord_t *record) { return false; case KC_AP_LED_OFF: - annepro2LedDisable(); annepro2LedPrevProfile(); + annepro2LedDisable(); return false; case KC_AP_LED_ON: