qmk-dactyl-manuform-a/users/bcat/bcat_oled_pet.h

74 lines
3.0 KiB
C
Raw Permalink Normal View History

[Keymap] Update bcat's keymaps/userspace to share logic, add OLED functionality, and set up one of my macropads for WFH (#14702) * Add script to build all bcat keymaps at once * Move userspace RGB to separate source file * Move layer handling logic into userspace * Move keycap aliases into userspace * Add OLED userspace library and Lily58 OLED setup * Add Luna keyboard pet, generic OLED pet framework Luna artwork and original implementation by HellSingCoder, licensed under GPL v2.0. See also: https://github.com/qmk/qmk_firmware/blob/6dfe915e26d7147e6c2bed495d3b01cf5b21e6ec/keyboards/sofle/keymaps/helltm/keymap.c * Use OLED on bcat's Crkbd I had to turn off a few unused features to address firmware size limits. * Remove vestigial NK_TOGG keybindings * Add post-render hook to OLED pet API This enables OLED pets to draw custom widgets (e.g., LED indicator status) on top of their animation frames. * Add Isda keyboard pet For future use on my Unicorne keyboard. Unicorn artwork by sparrow666, licensed under GPL v2.0. See also: https://opengameart.org/content/unicorn-2 * Replace OLED timeout implementation with custom The default implementation never lets the OLED turn off if a continuous animation is in progress. The custom one does. * Move keyboard state for OLED functions into struct No change in firmware size, but makes keymaps read a little nicer and enables more functionality in OLED pets. * Enable continuously running OLED pet (for Luna) * Sync OLED state; enable Bootmagic only when needed The new extensible split transport for Split Common finally allows OLED on/off status to be synced between halves of the keyboard. :) Unfortunately, this required disabling Bootmagic Lite to keep my Crkbd under the firmware size limit. (I now after 28 bytes free on avr-gcc version 8.5.0.) So now I'll enable Bootmagic only on keyboards that actually require it, i.e., ones lacking an accessible reset button. * Update 9-Key macropad keymap for working from home * Remove includes redundant with quantum.h Co-authored-by: Drashna Jaelre <drashna@live.com> * Simplify BCAT_OLED_PET makefile logic * Swap some keys on my 9-Key macropad around * Inline spurious variable in OLED code * Remove max brightness that's now set by default The default max brightness is only 120 rather than 150, but that might actually fix some weirdness I've seen with bright white LED settings. * Enable specific RGBLIGHT modes instead of default The general trend these days seems to be enabling only the modes you want, so I'm manually expanding the ones currently enabled by RGBLIGHT_ANIMATIONS. I'd like to try out the TWINKLE mode too, but it seems not to work at all on ARM right now, and all my usable RGBLIGHT keebs are ARM boards. * Reenable RGB_MATRIX animations after #15018 My Crkbd still has a reasonable amount of free space with these: 27974/28672 (97%, 698 bytes free). The RGB_MATRIX_KEYPRESSES effects would put it over the firmware size limit, but I really don't ever use those anyway. * Use new get_u8_str function for WPM display Co-authored-by: Drashna Jaelre <drashna@live.com>
2021-12-27 04:46:00 +01:00
/* Copyright 2021 Jonathan Rascher
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Common interface for an OLED pet (animated critter that reacts to typing).
* Please link exactly one accompanying .c file to implement these functions.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "bcat_oled.h"
/* Opaque token representing a single frame of the OLED pet animation.
* Different pet implementations have different valid state values, but the
* zero value must always represent the default state of the pet at startup.
*/
typedef uint16_t oled_pet_state_t;
/* Returns the number of bytes used to represent the animation frame (in
* oled_write_raw_P format). Note that every state the pet supports is expected
* to have the same frame size.
*/
uint16_t oled_pet_frame_bytes(void);
/* Returns the number of lines of the OLED occupied by the animation. Note that
* every state the pet supports is expected to have the same frame size. The
* returned value does not include the one line of padding that render_oled_pet
* uses to account for "jumping".
*/
uint8_t oled_pet_frame_lines(void);
/* Returns whether or not the OLED pet should "jump" when the spacebar is
* pressed. (The render_oled_pet implementation shifts the animation frame up
* one line when this happens.)
*/
bool oled_pet_can_jump(void);
/* Returns the delay before the next animation frame should be displayed. */
uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state);
/* Returns the state of the pet to be animated on the next animation tick. */
oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state);
/* Called after the OLED pet is rendered during each OLED task invocation.
* Receives the same keyboard state as render_oled_pet. The redraw param
* indicates whether or not an OLED frame was just redrawn, allowing a specific
* pet implementation to draw custom things atop its animation frames.
*
* When this function is called, the cursor will be in an unspecified location,
* not necessarily the top-left corner of the OLED pet.
*/
void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw);
/* Returns a PROGMEM pointer to the specified frame buffer for the specified
* state. The animation frame has length given by oled_pet_frame_bytes and is
* formatted as expected by oled_write_raw_P.
*/
const char *oled_pet_frame(oled_pet_state_t state);