app: make rgb panel optional
This commit is contained in:
parent
851c25ffe0
commit
ae394561e2
@ -28,6 +28,8 @@
|
||||
#include <libopencm3/stm32/dma.h> // DMA library
|
||||
#include <libopencm3/usb/dwc/otg_fs.h> // USB definitions
|
||||
|
||||
#define RGBPANEL_ENABLE 0 // if RGB panel is used
|
||||
|
||||
/* own libraries */
|
||||
#include "global.h" // board definitions
|
||||
#include "print.h" // printing utilities
|
||||
@ -35,7 +37,12 @@
|
||||
#include "terminal.h" // handle the terminal interface
|
||||
#include "menu.h" // menu utilities
|
||||
#include "font.h" // to draw text
|
||||
#if RGBPANEL_ENABLE
|
||||
#include "led_rgbpanel.h" // to control RGB panels
|
||||
#else
|
||||
#define RGBPANEL_WIDTH 0
|
||||
#define RGBPANEL_HEIGHT 0
|
||||
#endif
|
||||
#include "led_ws2812b.h" // control WS2812b LEDs
|
||||
#include "radio_esp8266.h" // to receive ARTnet
|
||||
|
||||
@ -124,6 +131,44 @@ static void drv8825_speed(int16_t speed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** set color of the LED on the WS2812b panel
|
||||
* @param[in] ws false to display on RGB matrix, true on WS2812b panel
|
||||
* @param[in] x horizontal position (0 = left)
|
||||
* @param[in] y vertical position (0 = top)
|
||||
* @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
|
||||
*/
|
||||
static void wsmatrix_set(int16_t x, int16_t y, bool r, bool g, bool b)
|
||||
{
|
||||
if (x < 0 || x >= WSMATRIX_WIDTH) {
|
||||
return;
|
||||
}
|
||||
if (y < 0 || y >= WSMATRIX_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
#define WSMATRIX_BRIGHTNESS 0x20
|
||||
uint8_t col = 0, row = 0;
|
||||
if (y < WSMATRIX_HEIGHT / 2) {
|
||||
col = WSMATRIX_WIDTH - 1 - x;
|
||||
if (1 == x % 2) {
|
||||
row = WSMATRIX_HEIGHT / 2 - 1 - y;
|
||||
} else {
|
||||
row = y;
|
||||
}
|
||||
} else {
|
||||
col = x + WSMATRIX_WIDTH;
|
||||
y -= WSMATRIX_HEIGHT / 2;
|
||||
if (1 == x % 2) {
|
||||
row = WSMATRIX_HEIGHT / 2 - 1 - y;
|
||||
} else {
|
||||
row = y;
|
||||
}
|
||||
}
|
||||
led_ws2812b_set_rgb(col * (WSMATRIX_HEIGHT / 2U) + row, g * WSMATRIX_BRIGHTNESS, r * WSMATRIX_BRIGHTNESS, b * WSMATRIX_BRIGHTNESS);
|
||||
}
|
||||
|
||||
/** set color of the LED on the RGB matrix or WS2812b panel
|
||||
* @param[in] ws false to display on RGB matrix, true on WS2812b panel
|
||||
* @param[in] x horizontal position (0 = left)
|
||||
@ -134,34 +179,12 @@ static void drv8825_speed(int16_t speed)
|
||||
*/
|
||||
static void matrix_set(bool ws, int16_t x, int16_t y, bool r, bool g, bool b)
|
||||
{
|
||||
if (x < 0 || x >= (ws ? WSMATRIX_WIDTH : RGBPANEL_WIDTH)) {
|
||||
return;
|
||||
}
|
||||
if (y < 0 || y >= (ws ? WSMATRIX_HEIGHT : RGBPANEL_HEIGHT)) {
|
||||
return;
|
||||
}
|
||||
if (ws) {
|
||||
#define WSMATRIX_BRIGHTNESS 0x20
|
||||
uint8_t col = 0, row = 0;
|
||||
if (y < WSMATRIX_HEIGHT / 2) {
|
||||
col = WSMATRIX_WIDTH - 1 - x;
|
||||
if (1 == x % 2) {
|
||||
row = WSMATRIX_HEIGHT / 2 - 1 - y;
|
||||
} else {
|
||||
row = y;
|
||||
}
|
||||
} else {
|
||||
col = x + WSMATRIX_WIDTH;
|
||||
y -= WSMATRIX_HEIGHT / 2;
|
||||
if (1 == x % 2) {
|
||||
row = WSMATRIX_HEIGHT / 2 - 1 - y;
|
||||
} else {
|
||||
row = y;
|
||||
}
|
||||
}
|
||||
led_ws2812b_set_rgb(col * (WSMATRIX_HEIGHT / 2U) + row, g * WSMATRIX_BRIGHTNESS, r * WSMATRIX_BRIGHTNESS, b * WSMATRIX_BRIGHTNESS);
|
||||
wsmatrix_set(x, y, r, g, b); // set LED color
|
||||
#if RGBPANEL_ENABLE
|
||||
} else {
|
||||
rgbpanel_set(x, y, r, g, b); // set LED color
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,6 +200,12 @@ static void matrix_set(bool ws, int16_t x, int16_t y, bool r, bool g, bool b)
|
||||
*/
|
||||
static void matrix_putc(bool ws, int16_t x, int16_t y, char c, enum font_name font, bool red, bool green, bool blue)
|
||||
{
|
||||
#if (0 == RGBPANEL_ENABLE)
|
||||
if (!ws) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// sanity checks
|
||||
if (font >= FONT_MAX) {
|
||||
return;
|
||||
@ -217,6 +246,12 @@ static void matrix_putc(bool ws, int16_t x, int16_t y, char c, enum font_name fo
|
||||
*/
|
||||
static void matrix_puts(bool ws, int16_t x, int16_t y, const char* str, enum font_name font, bool red, bool green, bool blue)
|
||||
{
|
||||
#if (0 == RGBPANEL_ENABLE)
|
||||
if (!ws) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// sanity checks
|
||||
if (NULL == str) {
|
||||
return;
|
||||
@ -943,9 +978,11 @@ void main(void)
|
||||
led_ws2812b_setup(); // configure peripheral for communication with WS2812b LEDs
|
||||
puts_debug("OK\n");
|
||||
|
||||
#if RGBPANEL_ENABLE
|
||||
puts_debug("setup RGB matrix: ");
|
||||
rgbpanel_setup();
|
||||
puts_debug("OK\n");
|
||||
#endif
|
||||
|
||||
// setup LED strips
|
||||
puts_debug("setup RGBW LED strips: ");
|
||||
@ -1045,7 +1082,9 @@ void main(void)
|
||||
}
|
||||
if (wakeup_flag) { // time to do periodic checks
|
||||
wakeup_flag = false; // clear flag
|
||||
#if RGBPANEL_ENABLE
|
||||
rgbpanel_clear();
|
||||
#endif
|
||||
matrix_puts(false, scroll_pos, 8, scroll_text, FONT_KING14, true, true, true);
|
||||
if (scroll_pos < -1 * (int16_t)strlen(scroll_text) * (fonts[FONT_KING14].width + 1)) {
|
||||
scroll_pos = 64;
|
||||
|
Loading…
Reference in New Issue
Block a user