From ac1b4881707d78aab3870583ace7d7970f05da27 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 4 Aug 2024 20:34:57 +0100 Subject: [PATCH] Refactor printedpad (#24236) --- keyboards/printedpad/keymaps/default/keymap.c | 27 +++++++++- keyboards/printedpad/keymaps/via/keymap.c | 27 +++++++++- keyboards/printedpad/oled.c | 40 ++++++++++++--- keyboards/printedpad/post_rules.mk | 3 ++ keyboards/printedpad/printedpad.c | 51 +------------------ keyboards/printedpad/printedpad.h | 16 ------ keyboards/printedpad/rules.mk | 1 - 7 files changed, 88 insertions(+), 77 deletions(-) create mode 100644 keyboards/printedpad/post_rules.mk delete mode 100644 keyboards/printedpad/printedpad.h delete mode 100644 keyboards/printedpad/rules.mk diff --git a/keyboards/printedpad/keymaps/default/keymap.c b/keyboards/printedpad/keymaps/default/keymap.c index 2126dc593f..97893af0e0 100644 --- a/keyboards/printedpad/keymaps/default/keymap.c +++ b/keyboards/printedpad/keymaps/default/keymap.c @@ -42,4 +42,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_ENT ) -}; \ No newline at end of file +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch(keycode) { + case LT(0, KC_NO): + if (record->event.pressed) { + // on tap + if (record->tap.count) { + if (get_highest_layer(layer_state) >= 3) { + layer_clear(); + } else { + layer_move(get_highest_layer(layer_state) + 1); + } + } +#ifdef OLED_ENABLE + // on hold + else { + void oled_display_mode_step(void); + oled_display_mode_step(); + } +#endif + } + return false; + } + return true; +} diff --git a/keyboards/printedpad/keymaps/via/keymap.c b/keyboards/printedpad/keymaps/via/keymap.c index 2126dc593f..97893af0e0 100644 --- a/keyboards/printedpad/keymaps/via/keymap.c +++ b/keyboards/printedpad/keymaps/via/keymap.c @@ -42,4 +42,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_ENT ) -}; \ No newline at end of file +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch(keycode) { + case LT(0, KC_NO): + if (record->event.pressed) { + // on tap + if (record->tap.count) { + if (get_highest_layer(layer_state) >= 3) { + layer_clear(); + } else { + layer_move(get_highest_layer(layer_state) + 1); + } + } +#ifdef OLED_ENABLE + // on hold + else { + void oled_display_mode_step(void); + oled_display_mode_step(); + } +#endif + } + return false; + } + return true; +} diff --git a/keyboards/printedpad/oled.c b/keyboards/printedpad/oled.c index a41fad7767..e5abcbfc0a 100644 --- a/keyboards/printedpad/oled.c +++ b/keyboards/printedpad/oled.c @@ -1,15 +1,22 @@ // Copyright 2023 Noah Beidelman (@noahbei) // SPDX-License-Identifier: GPL-2.0-or-later -#include "printedpad.h" - -#ifdef OLED_ENABLE -static void flash_current_layer(void); +#include "quantum.h" #define FRAME_DURATION 200 -uint32_t animation_timer = 0; -uint8_t current_frame = 0; +static uint32_t animation_timer = 0; +static uint8_t current_frame = 0; + +static uint32_t flash_timer = 0; +static bool layer_changed = false; + +static uint8_t current_display_mode = 0; + +static bool key_pressed = false; + +static void flash_current_layer(void); + static void render_animation(void) { // 'monkeylong26', 128x32px @@ -1391,12 +1398,16 @@ static void render_logo(void) { oled_write_raw_P(prota, sizeof(prota)); } -bool logo_rendered = false; +void oled_display_mode_step(void) { + current_display_mode = (current_display_mode + 1) % 3; +} bool oled_task_kb(void) { if (!oled_task_user()) { return false; } + + static bool logo_rendered = false; if (!logo_rendered) { render_logo(); if (timer_read() > 2500) @@ -1417,4 +1428,17 @@ bool oled_task_kb(void) { } return false; } -#endif + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + key_pressed = record->event.pressed; + + return process_record_user(keycode, record); +} + +// when the layer is changed, flash the layer number on the screen +layer_state_t layer_state_set_kb(layer_state_t state) { + flash_timer = timer_read(); + layer_changed = true; + + return layer_state_set_user(state); +} diff --git a/keyboards/printedpad/post_rules.mk b/keyboards/printedpad/post_rules.mk new file mode 100644 index 0000000000..1c8e68dfd0 --- /dev/null +++ b/keyboards/printedpad/post_rules.mk @@ -0,0 +1,3 @@ +ifeq ($(strip $(OLED_ENABLE)), yes) + SRC += oled.c +endif diff --git a/keyboards/printedpad/printedpad.c b/keyboards/printedpad/printedpad.c index 4e3354c028..a91e8d5ea4 100644 --- a/keyboards/printedpad/printedpad.c +++ b/keyboards/printedpad/printedpad.c @@ -1,57 +1,8 @@ // Copyright 2023 Noah Beidelman (@noahbei) // SPDX-License-Identifier: GPL-2.0-or-later -#include QMK_KEYBOARD_H -#include "printedpad.h" +#include "quantum.h" void board_init(void) { SYSCFG->CFGR1 |= SYSCFG_CFGR1_I2C1_DMA_RMP; } - -const uint8_t max_layer = 3; -uint8_t current_display_mode = 0; - -bool key_pressed = false; - -bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - if (!process_record_user(keycode, record)) { - return false; - } -#ifdef OLED_ENABLE - key_pressed = record->event.pressed; -#endif - switch(keycode) { - case LT(0, KC_NO): - if (record->event.pressed) { - // on tap - if (record->tap.count) { - if (get_highest_layer(layer_state) >= max_layer) { - layer_clear(); - } else { - layer_move(get_highest_layer(layer_state) + 1); - } - } -#ifdef OLED_ENABLE - // on hold - else { - current_display_mode = (current_display_mode + 1) % 3; - } -#endif - } - return false; - } - return true; -} - -#ifdef OLED_ENABLE -uint32_t flash_timer = 0; -bool layer_changed = false; - -// when the layer is changed, flash the layer number on the screen -layer_state_t layer_state_set_kb(layer_state_t state) { - flash_timer = timer_read(); - layer_changed = true; - - return layer_state_set_user(state); -} -#endif \ No newline at end of file diff --git a/keyboards/printedpad/printedpad.h b/keyboards/printedpad/printedpad.h deleted file mode 100644 index 17c23be69b..0000000000 --- a/keyboards/printedpad/printedpad.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2023 Noah Beidelman (@noahbei) -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "quantum.h" - -//for oled key press -extern bool key_pressed; - -// for changing oled display mode -extern uint8_t current_display_mode; - -//for determining when the layer is changed and having a timer for how long we flash the layer -extern uint32_t flash_timer; -extern bool layer_changed; diff --git a/keyboards/printedpad/rules.mk b/keyboards/printedpad/rules.mk deleted file mode 100644 index 5ab52a55a0..0000000000 --- a/keyboards/printedpad/rules.mk +++ /dev/null @@ -1 +0,0 @@ -SRC += oled.c \ No newline at end of file