Advertisement
hakbraley

QMK OLED Screensaver

Jan 27th, 2023
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/10m0zw8/qmk_timeout_image_on_oled_screens/
  2.  *  Code to enable a screensaver for an OLED display.
  3.  *  Code to actually animate the screensaver is not included here.
  4.  */
  5.  
  6.  
  7. // config.h -------------------------------------------------------------------
  8.  
  9. #define MINUTE_TO_MS 60000  // 60 seconds * 1000 milliseconds
  10.  
  11. #ifdef OLED_ENABLE
  12.     #define OLED_SCREENSAVER_TIMEOUT  1 * MINUTE_TO_MS  // 1 minute of no activity to turn on OLED screensaver
  13.     #define OLED_TIMEOUT             10 * MINUTE_TO_MS  // 10 minutes of no activity to turn OLED off
  14. #endif
  15.  
  16.  
  17.  
  18. // keymap.c ----------------------------------------------------------------
  19.  
  20. #ifdef OLED_ENABLE
  21.  
  22. bool oled_screensaver_active = false;
  23.  
  24. bool oled_task_user(void) {
  25.     // if oled is off, make sure screensaver is disabled, and do nothing else
  26.     if (!is_oled_on()) {
  27.         oled_screensaver_active = false;
  28.         return true;
  29.     }
  30.    
  31.     // if oled is on and it has been longer than OLED_SCREENSAVER_TIMEOUT since last matrix or encoder change, activate screensaver
  32.     if (is_oled_on()  &&  last_input_activity_elapsed() > OLED_SCREENSAVER_TIMEOUT) {
  33.         oled_screensaver_active = true;
  34.     }
  35.    
  36.     if (oled_screensaver_active) {
  37.         // matrix rain animation code goes here
  38.         // ...
  39.        
  40.         return true;
  41.     }
  42.    
  43.     // normal oled display code goes here
  44.     // ...
  45.    
  46.     return true;
  47. }
  48.  
  49. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement