Added wordmap and remove wordclock module.

This commit is contained in:
Matthias Mitscherlich
2023-01-19 15:49:32 +01:00
parent 7cb84d1660
commit 699b9ecce8
9 changed files with 178 additions and 372 deletions
+149 -25
View File
@@ -1,3 +1,22 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file main
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "string.h"
#include "freertos/FreeRTOS.h"
@@ -12,6 +31,7 @@
#include "driver/gpio.h"
#include "driver/rmt_tx.h"
#include "driver/uart_select.h"
#include "driver/gptimer.h"
#include "inc/gpio.h"
#include "inc/led_strip_encoder.h"
@@ -20,20 +40,73 @@
#include "inc/wifi.h"
#include "clock.h"
#include "wordclock.h"
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_GPIO_NUM 0
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static const uart_port_t uartPort = UART_NUM_0;
static TaskHandle_t devTaskHandle = NULL;
static void devTask(void* parameters);
static GPIO gpio0(4, GPIO_DIRECTION_OUTPUT);
static GPIO gpio1(18, GPIO_DIRECTION_OUTPUT);
// GPIOs
static GPIO led_rgb_red(3, GPIO_DIRECTION_OUTPUT);
static GPIO led_rgb_green(4, GPIO_DIRECTION_OUTPUT);
static GPIO led_rgb_blue(5, GPIO_DIRECTION_OUTPUT);
static GPIO led_orange(18, GPIO_DIRECTION_OUTPUT);
// -------------------------------------------------------
// LED Matrix components
static rmt_channel_handle_t led_chan = NULL;
static rmt_transmit_config_t tx_config;
static rmt_encoder_handle_t led_encoder = NULL;
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_GPIO_NUM 0
static LEDMatrix_Parameters_t ledmatrix_parameters =
{
LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT,
LEDMATRIX_ORIENTATION_COLUM_DOWN_UP,
LEDMATRIX_ORIENTATION_COLUM,
11,
10,
&led_chan,
&led_encoder,
&tx_config
};
static LEDMatrix LEDMatrix(&ledmatrix_parameters);
static Wordmap map(&LEDMatrix);
static gptimer_handle_t matrixRefreshTimer = NULL;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// Simple countdown on display
static void countdown(void);
// Timer Callback for the LEDMatrix refresh
static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data);
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
extern "C" void app_main(void)
{
@@ -104,20 +177,30 @@ extern "C" void app_main(void)
//--------------------------------------------
// LED Matrix
//
LEDMatrix_Parameters_t ledmatrix_parameters;
ledmatrix_parameters.columOrientation = LEDMATRIX_ORIENTATION_COLUM_DOWN_UP;
ledmatrix_parameters.height = 10;
ledmatrix_parameters.matrixOrientation = LEDMATRIX_ORIENTATION_COLUM;
ledmatrix_parameters.rmtChannel = &led_chan;
ledmatrix_parameters.rmtConfig = &tx_config;
ledmatrix_parameters.rmtEncoder = &led_encoder;
ledmatrix_parameters.rowOrientation = LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT;
ledmatrix_parameters.width = 11;
LEDMatrix LEDMatrix(&ledmatrix_parameters);
// Set an initial colour map
LEDMatrix.setGlobalColour(0x10, 0, 0x04);
//--------------------------------------------
// GP Timer for automatic matrix re-draw trigger
//
gptimer_config_t timer_config = { };
gptimer_event_callbacks_t cbs = { };
gptimer_alarm_config_t alarm_config = { };
timer_config.clk_src = GPTIMER_CLK_SRC_DEFAULT;
timer_config.direction = GPTIMER_COUNT_UP;
timer_config.resolution_hz = 1000000; // 1 MHz
cbs.on_alarm = timerCallback;
alarm_config.reload_count = 0;
alarm_config.alarm_count = timer_config.resolution_hz / 60;
alarm_config.flags.auto_reload_on_alarm = true;
ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &matrixRefreshTimer));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(matrixRefreshTimer, &cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(matrixRefreshTimer));
ESP_ERROR_CHECK(gptimer_set_alarm_action(matrixRefreshTimer, &alarm_config));
ESP_ERROR_CHECK(gptimer_start(matrixRefreshTimer));
// Create the development task
if(xTaskCreate(devTask, "DevTask", 2048, NULL, 3, &devTaskHandle) != pdPASS)
{
@@ -130,31 +213,72 @@ extern "C" void app_main(void)
Clock clock;
Clock::TimeStructure time;
Wordclock wordclock(&LEDMatrix);
countdown();
while (true)
{
time = clock.updateTime();
wordclock.update(&time);
// Update the clock every second (1000 ms)
vTaskDelay(1000);
}
}
static void devTask(void* parameters)
{
uint32_t counter = 0;
printf("DevTask created");
while (true)
{
(void)gpio0.SetOutput((GPIO_Value_t)(counter % 2));
(void)gpio1.SetOutput((GPIO_Value_t)(counter % 7));
(void)led_orange.SetOutput((GPIO_Value_t)(counter % 2));
counter++;
vTaskDelay(100);
vTaskDelay(500);
}
}
static void countdown(void)
{
map.setWord(Wordmap::Language_t::NL, "ten", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "ten", false);
map.setWord(Wordmap::Language_t::NL, "nine", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "nine", false);
map.setWord(Wordmap::Language_t::NL, "eight", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "eight", false);
map.setWord(Wordmap::Language_t::NL, "seven", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "seven", false);
map.setWord(Wordmap::Language_t::NL, "six", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "six", false);
map.setWord(Wordmap::Language_t::NL, "five", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "five", false);
map.setWord(Wordmap::Language_t::NL, "four", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "four", false);
map.setWord(Wordmap::Language_t::NL, "three", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "three", false);
map.setWord(Wordmap::Language_t::NL, "two", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "two", false);
map.setWord(Wordmap::Language_t::NL, "one", true);
vTaskDelay(1000);
map.setWord(Wordmap::Language_t::NL, "one", false);
}
static bool IRAM_ATTR timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xHigherPriorityTaskWoken = LEDMatrix.tick();
return xHigherPriorityTaskWoken == pdTRUE;
}