From 9762887d4564bb26bbf633d1c8ba6111259af593 Mon Sep 17 00:00:00 2001 From: bluepython508 Date: Thu, 14 Mar 2024 10:44:18 +0000 Subject: [PATCH] Formatting --- .clang-format | 2 +- .../kyria/rev3/keymaps/bluepython508/keymap.c | 228 +++++++++--------- 2 files changed, 110 insertions(+), 120 deletions(-) diff --git a/.clang-format b/.clang-format index ce145e2..62f68b6 100644 --- a/.clang-format +++ b/.clang-format @@ -13,7 +13,7 @@ AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: 'false' BinPackArguments: 'true' BinPackParameters: 'true' -ColumnLimit: '1000' +ColumnLimit: '100' IndentCaseLabels: 'true' IndentPPDirectives: AfterHash IndentWidth: '4' diff --git a/keyboards/splitkb/kyria/rev3/keymaps/bluepython508/keymap.c b/keyboards/splitkb/kyria/rev3/keymaps/bluepython508/keymap.c index 4b47d41..bbcd261 100644 --- a/keyboards/splitkb/kyria/rev3/keymaps/bluepython508/keymap.c +++ b/keyboards/splitkb/kyria/rev3/keymaps/bluepython508/keymap.c @@ -16,19 +16,19 @@ #include QMK_KEYBOARD_H enum keycodes { - OS_LSFT = SAFE_RANGE, - OS_LCTL, - OS_LALT, - OS_LGUI, + OS_LSFT = SAFE_RANGE, + OS_LCTL, + OS_LALT, + OS_LGUI, }; enum layers { - _TYPE = 0, - _GAME, - _SYM, - _NUM, - _NAV, - _FUN, + _TYPE = 0, + _GAME, + _SYM, + _NUM, + _NAV, + _FUN, }; // Aliases for readability @@ -91,10 +91,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ // ), }; +// clang-format on void keyboard_pre_init_user(void) { - setPinOutput(24); - writePinHigh(24); + setPinOutput(24); + writePinHigh(24); } typedef enum { @@ -106,131 +107,120 @@ typedef enum { } oneshot_mode_t; typedef struct { - uint16_t time; - uint16_t mod; - uint16_t trigger; - oneshot_mode_t mode; + uint16_t time; + uint16_t mod; + uint16_t trigger; + oneshot_mode_t mode; } oneshot_state_t; -oneshot_state_t oneshot_state[4] = { - { 0, KC_LSFT, OS_LSFT, os_up_unqueued }, - { 0, KC_LCTL, OS_LCTL, os_up_unqueued }, - { 0, KC_LALT, OS_LALT, os_up_unqueued }, - { 0, KC_LGUI, OS_LGUI, os_up_unqueued } -}; +oneshot_state_t oneshot_state[4] = {{0, KC_LSFT, OS_LSFT, os_up_unqueued}, + {0, KC_LCTL, OS_LCTL, os_up_unqueued}, + {0, KC_LALT, OS_LALT, os_up_unqueued}, + {0, KC_LGUI, OS_LGUI, os_up_unqueued}}; bool is_oneshot_ignored_key(uint16_t keycode) { - switch (keycode) { - case OS_LSFT: - case OS_LCTL: - case OS_LALT: - case OS_LGUI: - case NAV: - case SYM: - case NUM: - case FUN: - return true; - default: - return false; - } + switch (keycode) { + case OS_LSFT: + case OS_LCTL: + case OS_LALT: + case OS_LGUI: + case NAV: + case SYM: + case NUM: + case FUN: + return true; + default: + return false; + } } bool is_oneshot_cancel_key(uint16_t keycode) { - switch (keycode) { - case KC_NO: - return true; - default: - return false; - } + return keycode == KC_NO; } -// Based on https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c -void update_oneshot( - oneshot_state_t *state, - uint16_t keycode, - keyrecord_t *record - ) { - if (keycode == state->trigger) { - if (record->event.pressed) { - // Trigger keydown - switch (state->mode) { - case os_up_queued: - state->mode = os_locked; - break; - case os_up_unqueued: - register_code(state->mod); - state->time = timer_read(); - state->mode = os_down_unused; - break; - case os_locked: - state->mode = os_down_used; - break; - default: - state->mode = os_down_unused; - break; - } - } else { - // Trigger keyup - switch (state->mode) { - case os_down_unused: - // If we didn't use the mod while trigger was held, queue it. - if (timer_elapsed(state->time) < 1000) { - state->mode = os_up_queued; +// Based on +// https://github.com/qmk/qmk_firmware/blob/user-keymaps-still-present/users/callum/oneshot.c +void update_oneshot(oneshot_state_t *state, uint16_t keycode, keyrecord_t *record) { + if (keycode == state->trigger) { + if (record->event.pressed) { + // Trigger keydown + switch (state->mode) { + case os_up_queued: + state->mode = os_locked; + break; + case os_up_unqueued: + register_code(state->mod); + state->time = timer_read(); + state->mode = os_down_unused; + break; + case os_locked: + state->mode = os_down_used; + break; + default: + state->mode = os_down_unused; + break; + } } else { - state->mode = os_up_unqueued; - unregister_code(state->mod); + // Trigger keyup + switch (state->mode) { + case os_down_unused: + // If we didn't use the mod while trigger was held, queue it. + if (timer_elapsed(state->time) < 1000) { + state->mode = os_up_queued; + } else { + state->mode = os_up_unqueued; + unregister_code(state->mod); + } + break; + case os_down_used: + // If we did use the mod while trigger was held, unregister it. + state->mode = os_up_unqueued; + unregister_code(state->mod); + break; + default: + break; + } } - break; - case os_down_used: - // If we did use the mod while trigger was held, unregister it. - state->mode = os_up_unqueued; - unregister_code(state->mod); - break; - default: - break; - } - } - } else { - if (record->event.pressed) { - if (is_oneshot_cancel_key(keycode) && state->mode != os_up_unqueued) { - // Cancel oneshot on designated cancel keydown. - state->mode = os_up_unqueued; - unregister_code(state->mod); - } } else { - if (!is_oneshot_ignored_key(keycode)) { - // On non-ignored keyup, consider the oneshot used. - switch (state->mode) { - case os_down_unused: - state->mode = os_down_used; - break; - case os_up_queued: - state->mode = os_up_unqueued; - unregister_code(state->mod); - break; - default: - break; + if (record->event.pressed) { + if (is_oneshot_cancel_key(keycode) && state->mode != os_up_unqueued) { + // Cancel oneshot on designated cancel keydown. + state->mode = os_up_unqueued; + unregister_code(state->mod); + } + } else { + if (!is_oneshot_ignored_key(keycode)) { + // On non-ignored keyup, consider the oneshot used. + switch (state->mode) { + case os_down_unused: + state->mode = os_down_used; + break; + case os_up_queued: + state->mode = os_up_unqueued; + unregister_code(state->mod); + break; + default: + break; + } + } } - } } - } } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - update_oneshot(&oneshot_state[0], keycode, record); - update_oneshot(&oneshot_state[1], keycode, record); - update_oneshot(&oneshot_state[2], keycode, record); - update_oneshot(&oneshot_state[3], keycode, record); + update_oneshot(&oneshot_state[0], keycode, record); + update_oneshot(&oneshot_state[1], keycode, record); + update_oneshot(&oneshot_state[2], keycode, record); + update_oneshot(&oneshot_state[3], keycode, record); - if (oneshot_state[0].mode == os_locked && keycode == KC_SPACE) { - if (record->event.pressed) { - register_code(KC_MINUS); - } else { - unregister_code(KC_MINUS); + if (oneshot_state[0].mode == os_locked && keycode == KC_SPACE) { + if (record->event.pressed) { + register_code(KC_MINUS); + } else { + unregister_code(KC_MINUS); + } + return false; } - return false; - } - return true; + return true; } -