app: make position on RGB panel more flexibel

This commit is contained in:
King Kévin 2022-05-26 10:38:23 +02:00
parent b0351bcaaf
commit 5e688d467d
1 changed files with 15 additions and 13 deletions

View File

@ -148,12 +148,12 @@ static void rgbmatrix_clear(void)
* @param[in] g if the green LED should be on
* @param[in] b if the blue LED should be on
*/
static void rgbmatrix_set(uint8_t x, uint8_t y, bool r, bool g, bool b)
static void rgbmatrix_set(int16_t x, int16_t y, bool r, bool g, bool b)
{
if (x >= RGBMATRIX_WIDTH) {
if (x < 0 || x >= RGBMATRIX_WIDTH) {
return;
}
if (y >= RGBMATRIX_HEIGHT) {
if (y < 0 || y >= RGBMATRIX_HEIGHT) {
return;
}
const uint8_t row = y % (RGBMATRIX_HEIGHT / 2); // get the actual line/row
@ -199,21 +199,21 @@ static void rgbmatrix_set(uint8_t x, uint8_t y, bool r, bool g, bool b)
* @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)
static void rgbmatrix_putc(int16_t x, int16_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;
}
if (x + fonts[font].width < 0 || x >= RGBMATRIX_WIDTH) {
return;
}
if (y + fonts[font].height < 0 || y >= RGBMATRIX_HEIGHT) {
return;
}
// draw character on buffer
for (uint8_t col = 0; col < fonts[font].width; col++) {
@ -238,7 +238,7 @@ static void rgbmatrix_putc(uint8_t x, uint8_t y, char c, enum font_name font, bo
* @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)
static void rgbmatrix_puts(int16_t x, int16_t y, const char* str, enum font_name font, bool red, bool green, bool blue)
{
// sanity checks
if (NULL == str) {
@ -247,7 +247,7 @@ static void rgbmatrix_puts(uint8_t x, uint8_t y, char* str, enum font_name font,
if (font >= FONT_MAX) {
return;
}
if (y >= RGBMATRIX_HEIGHT) {
if (y + fonts[font].height < 0 || y >= RGBMATRIX_HEIGHT) {
return;
}
@ -256,7 +256,9 @@ static void rgbmatrix_puts(uint8_t x, uint8_t y, char* str, enum font_name font,
if (x >= RGBMATRIX_WIDTH) {
return;
}
rgbmatrix_putc(x, y, str[i], font, red, green, blue);
if (x + fonts[font].width >= 0) {
rgbmatrix_putc(x, y, str[i], font, red, green, blue);
}
x += fonts[font].width + 1;
}
}