lvgl testing
- set theme via code - custom table content (custom draw on canvas) - remove classes from ui - use free functions instead - remove provisioning
This commit is contained in:
@@ -577,7 +577,7 @@
|
||||
#if LV_USE_THEME_DEFAULT
|
||||
|
||||
/*0: Light mode; 1: Dark mode*/
|
||||
#define LV_THEME_DEFAULT_DARK 1
|
||||
#define LV_THEME_DEFAULT_DARK 0
|
||||
|
||||
/*1: Enable grow on press*/
|
||||
#define LV_THEME_DEFAULT_GROW 1
|
||||
|
@@ -76,6 +76,8 @@ void print_cb(const char *buf)
|
||||
void lv_begin()
|
||||
{
|
||||
tft.init();
|
||||
tft.initDMA();
|
||||
tft.startWrite();
|
||||
tft.setRotation(1);
|
||||
|
||||
#if LV_USE_LOG
|
||||
|
@@ -33,7 +33,11 @@ void setup()
|
||||
|
||||
lv_begin();
|
||||
|
||||
LaunchScreen().init();
|
||||
lv_disp_t *dispp = 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_disp_set_theme(dispp, theme);
|
||||
|
||||
launch_screen_show();
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@@ -16,9 +16,4 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
void time_widget_init(lv_coord_t x, lv_coord_t y);
|
||||
void time_widget_dispose();
|
||||
#include "esp_now_service.h"
|
@@ -17,5 +17,3 @@
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
void initWiFiTask(void *params);
|
@@ -1,40 +0,0 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// OS-Railway - Remote Control
|
||||
// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "wifi_service.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
void initWiFiTask(void *params)
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
auto start = millis();
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
if (millis() - start > 10000)
|
||||
{
|
||||
Serial.println("Failed to connect to WiFi");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
5
src/theme.h
Normal file
5
src/theme.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
const auto backgroundColor = lv_color_make(0x78, 0x94, 0xa7);
|
@@ -18,14 +18,28 @@
|
||||
//----------------------------------------------------------------------------
|
||||
#include "launch_screen.h"
|
||||
|
||||
#include "theme.h"
|
||||
#include "lv_i18n/lv_i18n.h"
|
||||
#include "search_screen.h"
|
||||
|
||||
void LaunchScreen::init()
|
||||
lv_obj_t *screen;
|
||||
|
||||
void timer_xcb(lv_timer_t *timer)
|
||||
{
|
||||
lv_timer_del(timer);
|
||||
search_screen_init();
|
||||
}
|
||||
|
||||
void start_timer()
|
||||
{
|
||||
lv_timer_t *timer = lv_timer_create(timer_xcb, 2000, NULL);
|
||||
}
|
||||
|
||||
void launch_screen_show()
|
||||
{
|
||||
screen = lv_obj_create(NULL);
|
||||
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_style_bg_color(screen, lv_color_make(0x78, 0x94, 0xa7), 0);
|
||||
lv_obj_set_style_bg_color(screen, backgroundColor, 0);
|
||||
|
||||
LV_IMG_DECLARE(os_railway_icon_lvgl);
|
||||
auto *logo = lv_img_create(screen);
|
||||
@@ -35,25 +49,7 @@ void LaunchScreen::init()
|
||||
auto *label = lv_label_create(screen);
|
||||
lv_label_set_text(label, _("appName"));
|
||||
lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -25);
|
||||
{
|
||||
lv_disp_load_scr(screen);
|
||||
timer();
|
||||
}
|
||||
}
|
||||
lv_disp_load_scr(screen);
|
||||
|
||||
void LaunchScreen::dispose()
|
||||
{
|
||||
lv_obj_del(screen);
|
||||
screen = nullptr;
|
||||
}
|
||||
|
||||
void my_timer(lv_timer_t *timer)
|
||||
{
|
||||
lv_timer_del(timer);
|
||||
SearchScreen().show();
|
||||
}
|
||||
|
||||
void LaunchScreen::timer()
|
||||
{
|
||||
lv_timer_t *timer = lv_timer_create(my_timer, 2000, NULL);
|
||||
start_timer();
|
||||
}
|
@@ -20,13 +20,4 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
class LaunchScreen
|
||||
{
|
||||
private:
|
||||
lv_obj_t *screen;
|
||||
void timer();
|
||||
|
||||
public:
|
||||
void init();
|
||||
void dispose();
|
||||
};
|
||||
void launch_screen_show();
|
||||
|
@@ -1,41 +0,0 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// OS-Railway - Remote Control
|
||||
// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "provisioning_screen.h"
|
||||
|
||||
ProvisioningScreen::ProvisioningScreen()
|
||||
{
|
||||
screen = lv_obj_create(NULL);
|
||||
|
||||
lv_color_t bg_color = lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 5);
|
||||
lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 4);
|
||||
|
||||
lv_obj_t *qr = lv_qrcode_create(screen, 150, fg_color, bg_color);
|
||||
|
||||
const char *data = "{\"ver\":\"v2\",\"name\":\"OSRW_RC\",\"pop\":\"a1000318\",\"transport\":\"ble\"}";
|
||||
lv_qrcode_update(qr, data, strlen(data));
|
||||
lv_obj_center(qr);
|
||||
|
||||
lv_obj_set_style_border_color(qr, bg_color, 0);
|
||||
lv_obj_set_style_border_width(qr, 5, 0);
|
||||
}
|
||||
|
||||
void ProvisioningScreen::show()
|
||||
{
|
||||
lv_disp_load_scr(screen);
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// OS-Railway - Remote Control
|
||||
// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
class ProvisioningScreen
|
||||
{
|
||||
private:
|
||||
lv_obj_t *screen;
|
||||
|
||||
public:
|
||||
ProvisioningScreen();
|
||||
void show();
|
||||
};
|
@@ -18,17 +18,88 @@
|
||||
//----------------------------------------------------------------------------
|
||||
#include "search_screen.h"
|
||||
|
||||
#include "theme.h"
|
||||
#include "../widgets/status_bar_widget.h"
|
||||
|
||||
SearchScreen::SearchScreen()
|
||||
#define ITEM_CNT 200
|
||||
|
||||
lv_obj_t *search_screen;
|
||||
lv_obj_t *search_data_table;
|
||||
|
||||
static void draw_event_cb(lv_event_t *e)
|
||||
{
|
||||
screen = lv_obj_create(NULL);
|
||||
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_style_bg_color(screen, lv_color_make(0x78, 0x94, 0xa7), 0);
|
||||
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);
|
||||
|
||||
lv_draw_rect_dsc_t rect_dsc;
|
||||
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);
|
||||
rect_dsc.radius = LV_RADIUS_CIRCLE;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchScreen::show()
|
||||
static void change_event_cb(lv_event_t *e)
|
||||
{
|
||||
status_bar_widget_init();
|
||||
lv_disp_load_scr(this->screen);
|
||||
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);
|
||||
}
|
||||
|
||||
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,12 +20,4 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
class SearchScreen
|
||||
{
|
||||
private:
|
||||
lv_obj_t *screen;
|
||||
|
||||
public:
|
||||
SearchScreen();
|
||||
void show();
|
||||
};
|
||||
void search_screen_init();
|
||||
|
@@ -20,19 +20,15 @@
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "time_widget.h"
|
||||
|
||||
lv_obj_t *status_bar_widget;
|
||||
|
||||
void status_bar_widget_init()
|
||||
{
|
||||
status_bar_widget = lv_obj_create(lv_layer_top());
|
||||
time_widget_init(10, 10);
|
||||
}
|
||||
|
||||
void status_bar_widget_dispose()
|
||||
{
|
||||
time_widget_dispose();
|
||||
lv_obj_del(status_bar_widget);
|
||||
status_bar_widget = NULL;
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// OS-Railway - Remote Control
|
||||
// Copyright (C) 2023 Peter Siegmund (https://mars3142.dev)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
#include "time_widget.h"
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
lv_obj_t *time_widget;
|
||||
lv_timer_t *time_widget_timer;
|
||||
|
||||
void time_widget_update(lv_timer_t *timer)
|
||||
{
|
||||
lv_obj_t *label = (lv_obj_t *)timer->user_data;
|
||||
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
std::string weekday[] = LV_CALENDAR_DEFAULT_DAY_NAMES;
|
||||
lv_label_set_text_fmt(label, "%s %02d:%02d:%02d\n%d-%02d-%02d", weekday[timeinfo.tm_wday].c_str(), timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday);
|
||||
}
|
||||
|
||||
void time_widget_init(lv_coord_t x, lv_coord_t y)
|
||||
{
|
||||
if (time_widget != NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
time_widget = lv_obj_create(lv_layer_top());
|
||||
lv_obj_align(time_widget, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
lv_obj_set_width(time_widget, 200);
|
||||
lv_obj_set_style_bg_opa(time_widget, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_opa(time_widget, LV_OPA_TRANSP, 0);
|
||||
|
||||
lv_obj_t *label = lv_label_create(time_widget);
|
||||
lv_obj_set_pos(label, -10, -10);
|
||||
|
||||
time_widget_timer = lv_timer_create(time_widget_update, 1000, (void *)label);
|
||||
time_widget_update(time_widget_timer);
|
||||
}
|
||||
|
||||
void time_widget_dispose()
|
||||
{
|
||||
if (time_widget == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lv_timer_del(time_widget_timer);
|
||||
time_widget_timer = NULL;
|
||||
|
||||
lv_obj_del(time_widget);
|
||||
time_widget = NULL;
|
||||
}
|
Reference in New Issue
Block a user