diff --git a/main/drivers/CMakeLists.txt b/main/drivers/CMakeLists.txt index fa0c42f..ecca240 100644 --- a/main/drivers/CMakeLists.txt +++ b/main/drivers/CMakeLists.txt @@ -16,6 +16,7 @@ set(SOURCES "state_tracking.cpp" "tft.cpp" "wires.cpp" + "wlvgl.cpp" ) target_sources(${COMPONENT_LIB} PRIVATE ${SOURCES}) diff --git a/main/drivers/leds.cpp b/main/drivers/leds.cpp index a30317e..7afb60e 100644 --- a/main/drivers/leds.cpp +++ b/main/drivers/leds.cpp @@ -8,11 +8,11 @@ static const char* TAG = "leds"; static led_strip_handle_t leds; +// TODO: rename these to playback_handler static bool replay_handler(const char* event, char* arg) { if (strcmp(event, "LED_SET") == 0) { uint32_t led = atoi(strtok(arg, ",")); uint32_t color = atoi(strtok(NULL, ",")); - ESP_LOGI("leds", "color: %ld", color); led_set(led, color); return true; } diff --git a/main/drivers/state_tracking.cpp b/main/drivers/state_tracking.cpp index 93521cb..e152d6d 100644 --- a/main/drivers/state_tracking.cpp +++ b/main/drivers/state_tracking.cpp @@ -1,6 +1,7 @@ #include "state_tracking.h" #include #include +#include "wlvgl.h" static const char* PLAYBACK_TAG = "playback"; @@ -171,6 +172,7 @@ bool start_recording() { state = STATE_RECORDING; recording_start_time = xTaskGetTickCount(); xTaskCreate(flush_file_task, "flush_recording", 2048, NULL, 2, &flush_file_task_handle); + reset_wlv_tables(); // TODO: generify this return true; } @@ -198,6 +200,7 @@ bool start_playback() { state = STATE_PLAYBACK; playback_start_time = xTaskGetTickCount(); xTaskCreate(playback_task, "playback", 4096, NULL, 2, &playback_task_handle); + reset_wlv_tables(); // TODO: generify this return true; } diff --git a/main/drivers/tft.cpp b/main/drivers/tft.cpp index 023fa97..dd015ff 100644 --- a/main/drivers/tft.cpp +++ b/main/drivers/tft.cpp @@ -26,7 +26,7 @@ static bool notify_lvgl_flush_ready( esp_lcd_panel_io_event_data_t *edata, void *user_ctx ) { - lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx; + lv_disp_drv_t* disp_driver = (lv_disp_drv_t *)user_ctx; lv_disp_flush_ready(disp_driver); return false; } diff --git a/main/drivers/wlvgl.cpp b/main/drivers/wlvgl.cpp new file mode 100644 index 0000000..1a215ac --- /dev/null +++ b/main/drivers/wlvgl.cpp @@ -0,0 +1,55 @@ +#include "wlvgl.h" +#include + +/// A table that maps an incrementing integer to a style reference +static std::vector style_table; + +/// A table that maps an incrementing integer to a style reference +static std::vector obj_table; + +void reset_wlv_tables() { + style_table.clear(); + obj_table.clear(); +} + +lv_obj_t wlv_obj_create(lv_obj_t* parent) { + // initialize the obj + lv_obj_t value = lv_obj_create(parent); + + if (is_state_tracking()) { + // add the style to the table + obj_table.push_back(value); + size_t obj_index = obj_table.size(); + + char buf[8]; + sprintf(buf, "%d", obj_index); + event_occured("lv_obj_create", buf); + } + return value; +} + +void wlv_style_init(lv_style_t* style) { + // initialize the style + lv_style_init(style); + + if (is_state_tracking()) { + // add the style to the table + style_table.push_back(style); + size_t style_index = style_table.size(); + + char buf[8]; + sprintf(buf, "%d", style_index); + event_occured("lv_style_init", buf); + } +} + +void wlv_obj_set_style_bg_color(lv_obj_t* obj, lv_color_t value, lv_style_selector_t selector) { + lv_obj_set_style_bg_color(obj, value, selector); + + if (is_state_tracking()) { + char buf[8]; + sprintf(buf, "%d", style_index); + event_occured("lv_obj_set_style_bg_color", buf); + } +} + diff --git a/main/drivers/wlvgl.h b/main/drivers/wlvgl.h new file mode 100644 index 0000000..2ec8ac9 --- /dev/null +++ b/main/drivers/wlvgl.h @@ -0,0 +1,13 @@ +#ifndef WLVGL_H +#define WLVGL_H + +#include "lvgl.h" +#include "state_tracking.h" + +void reset_wlv_tables(); + +void wlv_obj_create(lv_obj_t* parent); +void wlv_style_init(lv_style_t* style); +void wlv_obj_set_style_bg_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); + +#endif /* WLVGL_H */ \ No newline at end of file diff --git a/main/helper.cpp b/main/helper.cpp index 9c935ff..5a5ad95 100644 --- a/main/helper.cpp +++ b/main/helper.cpp @@ -120,7 +120,6 @@ void display_game_results(void) { lv_style_init(&game_results_style); lv_style_set_text_color(&game_results_style, lv_color_white()); - // lv_style_set_bg_color(&game_results_style, lv_color_black()); lv_style_set_text_align(&game_results_style, LV_TEXT_ALIGN_LEFT); overall_results_label = lv_label_create(scr);