From a1da462852247a74902f99a9e5253c645ee8a9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 25 May 2022 20:14:50 +0200 Subject: [PATCH] app: add function to draw text on RGB panel --- application.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/application.c b/application.c index d3c2c64..335f2fe 100644 --- a/application.c +++ b/application.c @@ -229,6 +229,38 @@ static void rgbmatrix_putc(uint8_t x, uint8_t y, char c, enum font_name font, bo } } +/** draw text on RGB matrix + * @param[in] x horizontal position (0 = left) + * @param[in] y vertical position (0 = top) + * @param[in] str text to draw + * @param[in] font font to use + * @param[in] r if the character should be drawn in red + * @param[in] g if the character should be drawn in green + * @param[in] b if the character should be drawn in blue + */ +static void rgbmatrix_puts(uint8_t x, uint8_t y, char* str, enum font_name font, bool red, bool green, bool blue) +{ + // sanity checks + if (NULL == str) { + return; + } + if (font >= FONT_MAX) { + return; + } + if (y >= RGBMATRIX_HEIGHT) { + return; + } + + const uint8_t len = strlen(str); + for (uint8_t i = 0; i < len; i++) { + if (x >= RGBMATRIX_WIDTH) { + return; + } + rgbmatrix_putc(x, y, str[i], font, red, green, blue); + x += fonts[font].width + 1; + } +} + size_t putc(char c) { size_t length = 0; // number of characters printed @@ -840,7 +872,9 @@ void main(void) command_speed(&speed); // draw welcome text - rgbmatrix_putc(1, 1, 'D', FONT_KING14, false, true, false); + rgbmatrix_puts(1, 1, "DACHBODEN", FONT_KING10, false, true, false); + rgbmatrix_puts(1, 12, "ZEIT", FONT_KING10, false, true, true); + rgbmatrix_puts(1, 23, "MASCHINE", FONT_KING10, true, true, false); // start main loop bool action = false; // if an action has been performed don't go to sleep