use namespaces
This commit is contained in:
18
src/main.cpp
18
src/main.cpp
@@ -24,20 +24,26 @@
|
|||||||
#include "lv_i18n/lv_i18n.h"
|
#include "lv_i18n/lv_i18n.h"
|
||||||
#include "ui/screens/launch_screen.h"
|
#include "ui/screens/launch_screen.h"
|
||||||
|
|
||||||
|
void displayRAM()
|
||||||
|
{
|
||||||
|
ESP_LOGI("ram", "Total heap: %d", ESP.getHeapSize());
|
||||||
|
ESP_LOGI("ram", "Free heap: %d", ESP.getFreeHeap());
|
||||||
|
ESP_LOGI("ram", "Total PSRAM: %d", ESP.getPsramSize());
|
||||||
|
ESP_LOGI("ram", "Free PSRAM: %d", ESP.getFreePsram());
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
esp_log_level_set("*", ESP_LOG_VERBOSE);
|
|
||||||
|
|
||||||
lv_i18n_init(lv_i18n_language_pack);
|
lv_i18n_init(lv_i18n_language_pack);
|
||||||
lv_i18n_set_locale("de-DE");
|
lv_i18n_set_locale("de-DE");
|
||||||
|
|
||||||
lv_begin();
|
lv_begin();
|
||||||
|
|
||||||
lv_disp_t *dispp = lv_disp_get_default();
|
lv_disp_t *display = lv_disp_get_default();
|
||||||
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_AMBER), lv_palette_main(LV_PALETTE_RED), false, LV_FONT_DEFAULT);
|
lv_theme_t *theme = lv_theme_default_init(display, lv_palette_main(LV_PALETTE_AMBER), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
|
||||||
lv_disp_set_theme(dispp, theme);
|
lv_disp_set_theme(display, theme);
|
||||||
|
|
||||||
launch_screen_show();
|
LaunchScreen::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@@ -22,34 +22,38 @@
|
|||||||
#include "lv_i18n/lv_i18n.h"
|
#include "lv_i18n/lv_i18n.h"
|
||||||
#include "search_screen.h"
|
#include "search_screen.h"
|
||||||
|
|
||||||
lv_obj_t *screen;
|
LV_IMG_DECLARE(os_railway_icon_lvgl);
|
||||||
|
|
||||||
void timer_xcb(lv_timer_t *timer)
|
namespace LaunchScreen
|
||||||
{
|
{
|
||||||
lv_timer_del(timer);
|
lv_obj_t *screen;
|
||||||
search_screen_init();
|
|
||||||
}
|
void timer_xcb(lv_timer_t *timer)
|
||||||
|
{
|
||||||
void start_timer()
|
lv_timer_del(timer);
|
||||||
{
|
SearchScreen::show();
|
||||||
lv_timer_t *timer = lv_timer_create(timer_xcb, 2000, NULL);
|
}
|
||||||
}
|
|
||||||
|
void start_timer()
|
||||||
void launch_screen_show()
|
{
|
||||||
{
|
lv_timer_t *timer = lv_timer_create(timer_xcb, 2000, NULL);
|
||||||
screen = lv_obj_create(NULL);
|
}
|
||||||
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
lv_obj_set_style_bg_color(screen, backgroundColor, 0);
|
void show()
|
||||||
|
{
|
||||||
LV_IMG_DECLARE(os_railway_icon_lvgl);
|
screen = lv_obj_create(NULL);
|
||||||
auto *logo = lv_img_create(screen);
|
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
lv_img_set_src(logo, &os_railway_icon_lvgl);
|
lv_obj_set_style_bg_color(screen, backgroundColor, 0);
|
||||||
lv_obj_align(logo, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
|
auto *logo = lv_img_create(screen);
|
||||||
auto *label = lv_label_create(screen);
|
lv_img_set_src(logo, &os_railway_icon_lvgl);
|
||||||
lv_label_set_text(label, _("appName"));
|
lv_obj_align(logo, LV_ALIGN_CENTER, 0, 0);
|
||||||
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25);
|
|
||||||
lv_disp_load_scr(screen);
|
auto *label = lv_label_create(screen);
|
||||||
|
lv_label_set_text(label, _("appName"));
|
||||||
start_timer();
|
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25);
|
||||||
|
lv_disp_load_scr(screen);
|
||||||
|
|
||||||
|
start_timer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,4 +20,7 @@
|
|||||||
|
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
|
||||||
void launch_screen_show();
|
namespace LaunchScreen
|
||||||
|
{
|
||||||
|
void show();
|
||||||
|
}
|
||||||
|
@@ -21,85 +21,88 @@
|
|||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "../widgets/status_bar_widget.h"
|
#include "../widgets/status_bar_widget.h"
|
||||||
|
|
||||||
|
namespace SearchScreen
|
||||||
|
{
|
||||||
#define ITEM_CNT 200
|
#define ITEM_CNT 200
|
||||||
|
|
||||||
lv_obj_t *search_screen;
|
lv_obj_t *search_screen;
|
||||||
lv_obj_t *search_data_table;
|
lv_obj_t *search_data_table;
|
||||||
|
|
||||||
static void draw_event_cb(lv_event_t *e)
|
static void draw_event_cb(lv_event_t *e)
|
||||||
{
|
|
||||||
auto *obj = lv_event_get_target(e);
|
|
||||||
auto *dsc = lv_event_get_draw_part_dsc(e);
|
|
||||||
|
|
||||||
if (dsc->part == LV_PART_ITEMS)
|
|
||||||
{
|
{
|
||||||
bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
auto *obj = lv_event_get_target(e);
|
||||||
|
auto *dsc = lv_event_get_draw_part_dsc(e);
|
||||||
|
|
||||||
lv_draw_rect_dsc_t rect_dsc;
|
if (dsc->part == LV_PART_ITEMS)
|
||||||
lv_draw_rect_dsc_init(&rect_dsc);
|
{
|
||||||
rect_dsc.bg_color = chk ? lv_theme_get_color_primary(obj) : lv_palette_lighten(LV_PALETTE_GREY, 2);
|
bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
||||||
rect_dsc.radius = LV_RADIUS_CIRCLE;
|
|
||||||
|
|
||||||
lv_area_t sw_area;
|
lv_draw_rect_dsc_t rect_dsc;
|
||||||
sw_area.x1 = dsc->draw_area->x2 - 50;
|
lv_draw_rect_dsc_init(&rect_dsc);
|
||||||
sw_area.x2 = sw_area.x1 + 40;
|
rect_dsc.bg_color = chk ? lv_theme_get_color_primary(obj) : lv_palette_lighten(LV_PALETTE_GREY, 2);
|
||||||
sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10;
|
rect_dsc.radius = LV_RADIUS_CIRCLE;
|
||||||
sw_area.y2 = sw_area.y1 + 20;
|
|
||||||
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);
|
|
||||||
|
|
||||||
rect_dsc.bg_color = lv_color_white();
|
lv_area_t sw_area;
|
||||||
|
sw_area.x1 = dsc->draw_area->x2 - 50;
|
||||||
|
sw_area.x2 = sw_area.x1 + 40;
|
||||||
|
sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10;
|
||||||
|
sw_area.y2 = sw_area.y1 + 20;
|
||||||
|
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);
|
||||||
|
|
||||||
|
rect_dsc.bg_color = lv_color_white();
|
||||||
|
if (chk)
|
||||||
|
{
|
||||||
|
sw_area.x2 -= 2;
|
||||||
|
sw_area.x1 = sw_area.x2 - 16;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sw_area.x1 += 2;
|
||||||
|
sw_area.x2 = sw_area.x1 + 16;
|
||||||
|
}
|
||||||
|
sw_area.y1 += 2;
|
||||||
|
sw_area.y2 -= 2;
|
||||||
|
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void change_event_cb(lv_event_t *e)
|
||||||
|
{
|
||||||
|
lv_obj_t *obj = lv_event_get_target(e);
|
||||||
|
uint16_t col;
|
||||||
|
uint16_t row;
|
||||||
|
lv_table_get_selected_cell(obj, &row, &col);
|
||||||
|
bool chk = lv_table_has_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
||||||
if (chk)
|
if (chk)
|
||||||
{
|
lv_table_clear_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
||||||
sw_area.x2 -= 2;
|
|
||||||
sw_area.x1 = sw_area.x2 - 16;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
lv_table_add_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
||||||
sw_area.x1 += 2;
|
|
||||||
sw_area.x2 = sw_area.x1 + 16;
|
|
||||||
}
|
|
||||||
sw_area.y1 += 2;
|
|
||||||
sw_area.y2 -= 2;
|
|
||||||
lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void change_event_cb(lv_event_t *e)
|
void show()
|
||||||
{
|
|
||||||
lv_obj_t *obj = lv_event_get_target(e);
|
|
||||||
uint16_t col;
|
|
||||||
uint16_t row;
|
|
||||||
lv_table_get_selected_cell(obj, &row, &col);
|
|
||||||
bool chk = lv_table_has_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
|
||||||
if (chk)
|
|
||||||
lv_table_clear_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
|
||||||
else
|
|
||||||
lv_table_add_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void search_screen_init()
|
|
||||||
{
|
|
||||||
search_screen = lv_obj_create(NULL);
|
|
||||||
lv_obj_clear_flag(search_screen, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
search_data_table = lv_table_create(search_screen);
|
|
||||||
lv_obj_set_size(search_data_table, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
||||||
|
|
||||||
lv_table_set_col_width(search_data_table, 0, SCREEN_WIDTH - 3);
|
|
||||||
lv_table_set_row_cnt(search_data_table, ITEM_CNT); /*Not required but avoids a lot of memory reallocation lv_table_set_set_value*/
|
|
||||||
lv_table_set_col_cnt(search_data_table, 1);
|
|
||||||
|
|
||||||
/*Don't make the cell pressed, we will draw something different in the event*/
|
|
||||||
lv_obj_remove_style(search_data_table, NULL, LV_PART_ITEMS | LV_STATE_PRESSED);
|
|
||||||
|
|
||||||
uint32_t i;
|
|
||||||
for (i = 0; i < ITEM_CNT; i++)
|
|
||||||
{
|
{
|
||||||
lv_table_set_cell_value_fmt(search_data_table, i, 0, "Item\n%" LV_PRIu32, i + 1);
|
search_screen = lv_obj_create(NULL);
|
||||||
|
lv_obj_clear_flag(search_screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
search_data_table = lv_table_create(search_screen);
|
||||||
|
lv_obj_set_size(search_data_table, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
lv_table_set_col_width(search_data_table, 0, SCREEN_WIDTH - 3);
|
||||||
|
lv_table_set_row_cnt(search_data_table, ITEM_CNT); /*Not required but avoids a lot of memory reallocation lv_table_set_set_value*/
|
||||||
|
lv_table_set_col_cnt(search_data_table, 1);
|
||||||
|
|
||||||
|
/*Don't make the cell pressed, we will draw something different in the event*/
|
||||||
|
lv_obj_remove_style(search_data_table, NULL, LV_PART_ITEMS | LV_STATE_PRESSED);
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < ITEM_CNT; i++)
|
||||||
|
{
|
||||||
|
lv_table_set_cell_value_fmt(search_data_table, i, 0, "Item\n%" LV_PRIu32, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(search_data_table, draw_event_cb, LV_EVENT_DRAW_PART_END, NULL);
|
||||||
|
lv_obj_add_event_cb(search_data_table, change_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
|
||||||
|
lv_disp_load_scr(search_screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_add_event_cb(search_data_table, draw_event_cb, LV_EVENT_DRAW_PART_END, NULL);
|
|
||||||
lv_obj_add_event_cb(search_data_table, change_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
|
||||||
|
|
||||||
lv_disp_load_scr(search_screen);
|
|
||||||
}
|
}
|
||||||
|
@@ -20,4 +20,7 @@
|
|||||||
|
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
|
||||||
void search_screen_init();
|
namespace SearchScreen
|
||||||
|
{
|
||||||
|
void show();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user