Skip to content

Commit

Permalink
Fix OLED timeouts
Browse files Browse the repository at this point in the history
There's an issue with QMK where writing to the last row would prevent
OLED timeouts from kicking in properly.

This patch works around that issue by introducing a custom timer which
tracks keyboard input based on WPM to determine inactivity for the OLED
timeout.
  • Loading branch information
chrisduerr committed Aug 25, 2023
1 parent e805116 commit 4e68acd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions keyboards/undeadsplit/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define USE_SERIAL
#define SOFT_SERIAL_PIN D2
#define SPLIT_WPM_ENABLE
#define SPLIT_OLED_ENABLE

#define FORCE_NKRO

Expand All @@ -14,3 +15,5 @@
#define ENCODERS_PAD_A_RIGHT { F4 }
#define ENCODERS_PAD_B_RIGHT { F5 }
#define ENCODER_RESOLUTION 4

#define OLED_TIMEOUT 5000
27 changes: 27 additions & 0 deletions keyboards/undeadsplit/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ uint8_t logo_y = 15;
// Typing animation toggle flag.
bool flame_big = false;

// Last oled update.
uint32_t last_update = 0;

/// Check if a new key was pressed.
static bool new_key_down(void) {
bool new_key_down = false;
Expand Down Expand Up @@ -139,12 +142,36 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_270;
}

/// Check if display should be turned off
bool should_timeout(uint8_t wpm) {
// Use master side to control timeouts using `SPLIT_OLED_ENABLE`.
if (!is_keyboard_master()) {
return false;
}

uint32_t now = timer_read();

// Reset timer while typing.
if (wpm != 0) {
last_update = now;
}

// Timeout when typing was suspended for at least `OLED_TIMEOUT`.
return wpm == 0 && now - last_update >= OLED_TIMEOUT;
}

/// Main entry point for OLED control.
bool oled_task_user(void) {
uint8_t wpm = get_current_wpm();

if (should_timeout(wpm)) {
oled_off();
return false;
}

render_logo(wpm);

// Render text once animation is done.
if (logo_y == 0) {
render_text(wpm);
}
Expand Down

0 comments on commit 4e68acd

Please sign in to comment.