Skip to content

Commit

Permalink
Refactor printedpad (qmk#24236)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored Aug 4, 2024
1 parent b5b4e93 commit ac1b488
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 77 deletions.
27 changes: 26 additions & 1 deletion keyboards/printedpad/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
};
};

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;
}
27 changes: 26 additions & 1 deletion keyboards/printedpad/keymaps/via/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
};
};

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;
}
40 changes: 32 additions & 8 deletions keyboards/printedpad/oled.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
3 changes: 3 additions & 0 deletions keyboards/printedpad/post_rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ifeq ($(strip $(OLED_ENABLE)), yes)
SRC += oled.c
endif
51 changes: 1 addition & 50 deletions keyboards/printedpad/printedpad.c
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions keyboards/printedpad/printedpad.h

This file was deleted.

1 change: 0 additions & 1 deletion keyboards/printedpad/rules.mk

This file was deleted.

0 comments on commit ac1b488

Please sign in to comment.