app: add function to draw character on RGB panel
This commit is contained in:
parent
c73600c91f
commit
759cfd577e
@ -35,6 +35,7 @@
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "terminal.h" // handle the terminal interface
|
||||
#include "menu.h" // menu utilities
|
||||
#include "font.h" // to draw text
|
||||
|
||||
/** watchdog period in ms */
|
||||
#define WATCHDOG_PERIOD 10000
|
||||
@ -146,7 +147,6 @@ static void rgbmatrix_clear(void)
|
||||
* @param[in] r if the red LED should be on
|
||||
* @param[in] g if the green LED should be on
|
||||
* @param[in] b if the blue LED should be on
|
||||
* @note this does not send the data to the matrix
|
||||
*/
|
||||
static void rgbmatrix_set(uint8_t x, uint8_t y, bool r, bool g, bool b)
|
||||
{
|
||||
@ -190,6 +190,45 @@ static void rgbmatrix_set(uint8_t x, uint8_t y, bool r, bool g, bool b)
|
||||
rgbmatrix_data[row][col + 1] |= data; // set the LED data on clock high edge
|
||||
}
|
||||
|
||||
/** draw character on RGB matrix
|
||||
* @param[in] x horizontal position (0 = left)
|
||||
* @param[in] y vertical position (0 = top)
|
||||
* @param[in] c character 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_putc(uint8_t x, uint8_t y, char c, enum font_name font, bool red, bool green, bool blue)
|
||||
{
|
||||
// sanity checks
|
||||
if (x >= RGBMATRIX_WIDTH) {
|
||||
return;
|
||||
}
|
||||
if (y >= RGBMATRIX_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
if (font >= FONT_MAX) {
|
||||
return;
|
||||
}
|
||||
if (c < ' ' || c > '~') {
|
||||
return;
|
||||
}
|
||||
|
||||
// draw character on buffer
|
||||
for (uint8_t col = 0; col < fonts[font].width; col++) {
|
||||
const uint16_t column = fonts[font].glyphs[(c - ' ') * fonts[font].width + col];
|
||||
for (uint8_t row = 0; row < fonts[font].height; row++) {
|
||||
const bool dot = (column >> (fonts[font].height - 1 - row)) & 0x01;
|
||||
if (dot) {
|
||||
rgbmatrix_set(x + col, y + row, red, green, blue);
|
||||
} else {
|
||||
rgbmatrix_set(x + col, y + row, false, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t putc(char c)
|
||||
{
|
||||
size_t length = 0; // number of characters printed
|
||||
@ -800,6 +839,9 @@ void main(void)
|
||||
int32_t speed = 300;
|
||||
command_speed(&speed);
|
||||
|
||||
// draw welcome text
|
||||
rgbmatrix_putc(1, 1, 'D', FONT_KING14, false, true, false);
|
||||
|
||||
// start main loop
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
|
Loading…
Reference in New Issue
Block a user