Fix keyboard pet OLED timeout logic (#17189)

The animation itself turns the screen on, preventing the normal timeout
from ever triggering.
This commit is contained in:
Jouke Witteveen 2022-09-30 22:24:43 +02:00 committed by GitHub
parent ff1aa6be9a
commit 8bd73d4455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 72 deletions

View File

@ -273,7 +273,6 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
# define ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024 # define ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024
/* timers */ /* timers */
uint32_t anim_timer = 0; uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
/* current frame */ /* current frame */
uint8_t current_frame = 0; uint8_t current_frame = 0;
/* status variables */ /* status variables */
@ -351,19 +350,19 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
current_frame = (current_frame + 1) % 2; current_frame = (current_frame + 1) % 2;
/* draw */ /* draw */
if (isBarking) { if (isBarking) {
oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) { } else if (isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) { } else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) { } else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }
/* animation timer */ /* animation timer */

View File

@ -68,7 +68,6 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
/* timers */ /* timers */
uint32_t anim_timer = 0; uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
/* current frame */ /* current frame */
uint8_t current_frame = 0; uint8_t current_frame = 0;
@ -160,35 +159,37 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
/* current status */ /* current status */
if (led_usb_state.caps_lock) { if (led_usb_state.caps_lock) {
oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) { } else if (isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) { } else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) { } else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }
# if OLED_TIMEOUT > 0
/* the animation prevents the normal timeout from occuring */
if (last_input_activity_elapsed() > OLED_TIMEOUT && last_led_activity_elapsed() > OLED_TIMEOUT) {
oled_off();
return;
} else {
oled_on();
}
# endif
/* animation timer */ /* animation timer */
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32(); anim_timer = timer_read32();
animate_luna(); animate_luna();
} }
/* this fixes the screen on and off bug */
if (current_wpm > 0) {
oled_on();
anim_sleep = timer_read32();
} else if (timer_elapsed32(anim_sleep) > OLED_TIMEOUT) {
oled_off();
}
} }

View File

@ -78,7 +78,6 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
/* timers */ /* timers */
uint32_t anim_timer = 0; uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
/* current frame */ /* current frame */
uint8_t current_frame = 0; uint8_t current_frame = 0;
@ -170,38 +169,39 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
/* current status */ /* current status */
if (led_usb_state.caps_lock) { if (led_usb_state.caps_lock) {
oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) { } else if (isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) { } else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) { } else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }
# if OLED_TIMEOUT > 0
/* the animation prevents the normal timeout from occuring */
if (last_input_activity_elapsed() > OLED_TIMEOUT && last_led_activity_elapsed() > OLED_TIMEOUT) {
oled_off();
return;
} else {
oled_on();
}
# endif
/* animation timer */ /* animation timer */
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32(); anim_timer = timer_read32();
animate_luna(); animate_luna();
} }
/* this fixes the screen on and off bug */
if (current_wpm > 0) {
oled_on();
anim_sleep = timer_read32();
} else if (timer_elapsed32(anim_sleep) > OLED_TIMEOUT) {
oled_off();
}
} }
/* KEYBOARD PET END */ /* KEYBOARD PET END */
static void print_status_narrow(void) { static void print_status_narrow(void) {

View File

@ -156,16 +156,16 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
current_frame = (current_frame + 1) % 2; current_frame = (current_frame + 1) % 2;
if(isSneaking) { if(isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if(current_wpm <= MIN_WALK_SPEED) { } else if(current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if(current_wpm <= MIN_RUN_SPEED) { } else if(current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }

View File

@ -188,7 +188,6 @@ static uint16_t held_shift = 0;
/* timers */ /* timers */
uint32_t anim_timer = 0; uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
/* current frame */ /* current frame */
uint8_t current_frame = 0; uint8_t current_frame = 0;
@ -280,35 +279,37 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
/* current status */ /* current status */
if (led_usb_state.caps_lock) { if (led_usb_state.caps_lock) {
oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) { } else if (isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) { } else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) { } else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }
# if OLED_TIMEOUT > 0
/* the animation prevents the normal timeout from occuring */
if (last_input_activity_elapsed() > OLED_TIMEOUT && last_led_activity_elapsed() > OLED_TIMEOUT) {
oled_off();
return;
} else {
oled_on();
}
# endif
/* animation timer */ /* animation timer */
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32(); anim_timer = timer_read32();
animate_luna(); animate_luna();
} }
/* this fixes the screen on and off bug */
if (current_wpm > 0) {
oled_on();
anim_sleep = timer_read32();
} else if (timer_elapsed32(anim_sleep) > OLED_TIMEOUT) {
oled_off();
}
} }
/* KEYBOARD PET END */ /* KEYBOARD PET END */

View File

@ -167,7 +167,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
#ifdef OLED_ENABLE #ifdef OLED_ENABLE
bool show_lock = true; // this is used to display the lock icon and disable keypresses when the keyboard is locked bool show_lock = true; // this is used to display the lock icon and disable keypresses when the keyboard is locked
bool animate = true; // this variable is used to fix the flickering bug
static void render_logo(void) { static void render_logo(void) {
static const char PROGMEM no_qmk[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, static const char PROGMEM no_qmk[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -230,7 +229,6 @@ static const char PROGMEM mac_logo[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
/* timers */ /* timers */
uint32_t anim_timer = 0; uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
/* current frame */ /* current frame */
uint8_t current_frame = 0; uint8_t current_frame = 0;
@ -322,37 +320,37 @@ static void render_luna(int LUNA_X, int LUNA_Y) {
/* current status */ /* current status */
if (led_usb_state.caps_lock) { if (led_usb_state.caps_lock) {
oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) { } else if (isSneaking) {
oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) { } else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) { } else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else { } else {
oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); oled_write_raw_P(run[current_frame], ANIM_SIZE);
} }
} }
/* animation timer, stops the animation logic when the oled is turned off */ # if OLED_TIMEOUT > 0
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION && animate == true) { /* the animation prevents the normal timeout from occuring */
if (last_input_activity_elapsed() > OLED_TIMEOUT && last_led_activity_elapsed() > OLED_TIMEOUT) {
oled_off();
return;
} else {
oled_on();
}
# endif
/* animation timer */
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32(); anim_timer = timer_read32();
animate_luna(); animate_luna();
} }
/* this fixes the screen on and off bug by disabling the animation logic when the oled is off */
if (current_wpm > 0) {
oled_on();
anim_sleep = timer_read32();
animate = true;
} else if (timer_elapsed32(anim_sleep) > OLED_TIMEOUT) {
oled_off();
animate = false;
}
} }
/* KEYBOARD PET END */ /* KEYBOARD PET END */