bcat_oled_pet.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2021 Jonathan Rascher
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /* Common interface for an OLED pet (animated critter that reacts to typing).
  17. * Please link exactly one accompanying .c file to implement these functions.
  18. */
  19. #pragma once
  20. #include <stdbool.h>
  21. #include <stdint.h>
  22. #include "bcat_oled.h"
  23. /* Opaque token representing a single frame of the OLED pet animation.
  24. * Different pet implementations have different valid state values, but the
  25. * zero value must always represent the default state of the pet at startup.
  26. */
  27. typedef uint16_t oled_pet_state_t;
  28. /* Returns the number of bytes used to represent the animation frame (in
  29. * oled_write_raw_P format). Note that every state the pet supports is expected
  30. * to have the same frame size.
  31. */
  32. uint16_t oled_pet_frame_bytes(void);
  33. /* Returns the number of lines of the OLED occupied by the animation. Note that
  34. * every state the pet supports is expected to have the same frame size. The
  35. * returned value does not include the one line of padding that render_oled_pet
  36. * uses to account for "jumping".
  37. */
  38. uint8_t oled_pet_frame_lines(void);
  39. /* Returns whether or not the OLED pet should "jump" when the spacebar is
  40. * pressed. (The render_oled_pet implementation shifts the animation frame up
  41. * one line when this happens.)
  42. */
  43. bool oled_pet_can_jump(void);
  44. /* Returns the delay before the next animation frame should be displayed. */
  45. uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state);
  46. /* Returns the state of the pet to be animated on the next animation tick. */
  47. oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state);
  48. /* Called after the OLED pet is rendered during each OLED task invocation.
  49. * Receives the same keyboard state as render_oled_pet. The redraw param
  50. * indicates whether or not an OLED frame was just redrawn, allowing a specific
  51. * pet implementation to draw custom things atop its animation frames.
  52. *
  53. * When this function is called, the cursor will be in an unspecified location,
  54. * not necessarily the top-left corner of the OLED pet.
  55. */
  56. void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw);
  57. /* Returns a PROGMEM pointer to the specified frame buffer for the specified
  58. * state. The animation frame has length given by oled_pet_frame_bytes and is
  59. * formatted as expected by oled_write_raw_P.
  60. */
  61. const char *oled_pet_frame(oled_pet_state_t state);