display.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * (c) Philippe G. 2019, philippe_44@outlook.com
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. #pragma once
  19. /*
  20. The displayer is not thread-safe and the caller must ensure use its own
  21. mutexes if it wants something better. Especially, text() line() and draw()
  22. are not protected against each other.
  23. In text mode (text/line) when using DISPLAY_SUSPEND, the displayer will
  24. refreshed line 2 one last time before suspending itself. As a result if it
  25. is in a long sleep (scrolling pause), the refresh will happen after wakeup.
  26. So it can conflict with other display direct writes that have been made during
  27. sleep. Note that if DISPLAY_SHUTDOWN has been called meanwhile, it (almost)
  28. never happens
  29. The display_bus() shall be subscribed by other displayers so that at least
  30. when this one (the main) wants to take control over display, it can signal
  31. that to others
  32. */
  33. #define DISPLAY_CLEAR 0x01
  34. #define DISPLAY_ONLY_EOL 0x02
  35. #define DISPLAY_UPDATE 0x04
  36. #define DISPLAY_MONOSPACE 0x08
  37. // these ones are for 'x' parameter of line() function
  38. #define DISPLAY_LEFT 0
  39. #define DISPLAY_RIGHT 0xff00
  40. #define DISPLAY_CENTER 0xff01
  41. enum display_pos_e { DISPLAY_TOP_LEFT, DISPLAY_MIDDLE_LEFT, DISPLAY_BOTTOM_LEFT, DISPLAY_CENTERED };
  42. enum display_font_e { DISPLAY_FONT_DEFAULT,
  43. DISPLAY_FONT_LINE_1, DISPLAY_FONT_LINE_2, DISPLAY_FONT_SEGMENT,
  44. DISPLAY_FONT_TINY, DISPLAY_FONT_SMALL, DISPLAY_FONT_MEDIUM, DISPLAY_FONT_LARGE, DISPLAY_FONT_HUGE };
  45. enum displayer_cmd_e { DISPLAYER_SHUTDOWN, DISPLAYER_ACTIVATE, DISPLAYER_SUSPEND, DISPLAYER_TIMER_PAUSE, DISPLAYER_TIMER_RUN };
  46. enum displayer_time_e { DISPLAYER_ELAPSED, DISPLAYER_REMAINING };
  47. // don't change anything there w/o changing all drivers init code
  48. extern struct display_s {
  49. int width, height;
  50. bool dirty;
  51. bool (*init)(char *config, char *welcome);
  52. void (*clear)(bool full, ...);
  53. bool (*set_font)(int num, enum display_font_e font, int space);
  54. void (*on)(bool state);
  55. void (*brightness)(uint8_t level);
  56. void (*text)(enum display_font_e font, enum display_pos_e pos, int attribute, char *msg, ...);
  57. bool (*line)(int num, int x, int attribute, char *text);
  58. int (*stretch)(int num, char *string, int max);
  59. void (*update)(void);
  60. void (*draw_raw)(int x1, int y1, int x2, int y2, bool by_column, bool MSb, uint8_t *data);
  61. void (*draw_cbr)(uint8_t *data, int width, int height); // width and height is the # of rows/columns in data, as opposed to display height (0 = display width, 0 = display height)
  62. void (*draw_line)(int x1, int y1, int x2, int y2);
  63. void (*draw_box)( int x1, int y1, int x2, int y2, bool fill);
  64. } *display;
  65. enum display_bus_cmd_e { DISPLAY_BUS_TAKE, DISPLAY_BUS_GIVE };
  66. bool (*display_bus)(void *from, enum display_bus_cmd_e cmd);
  67. void displayer_scroll(char *string, int speed);
  68. void displayer_control(enum displayer_cmd_e cmd, ...);
  69. void displayer_metadata(char *artist, char *album, char *title);
  70. void displayer_timer(enum displayer_time_e mode, int elapsed, int duration);