From e65c9fa18138e8623d5f8e5e8f25fcf0e3d3cf67 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 10 Feb 2020 21:05:33 +0100 Subject: Integration of lvgl : continued... --- src/DisplayApp/LittleVgl.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/DisplayApp/LittleVgl.cpp (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp new file mode 100644 index 00000000..7830953a --- /dev/null +++ b/src/DisplayApp/LittleVgl.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "LittleVgl.h" + +using namespace Pinetime::Components; + +static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) { + auto* lvgl = static_cast(disp_drv->user_data); + lvgl->FlushDisplay(area, color_p); +} + +LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd{lcd} { + lv_init(); + lv_theme_t* theme = lv_theme_night_init(10, NULL); + lv_theme_set_current(theme); + + lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 2); /*Initialize the display buffer*/ + lv_disp_drv_init(&disp_drv); /*Basic initialization*/ + + /*Set up the functions to access to your display*/ + + /*Set the resolution of the display*/ + disp_drv.hor_res = 240; + disp_drv.ver_res = 240; + + /*Used to copy the buffer's content to the display*/ + disp_drv.flush_cb = disp_flush; + /*Set a display buffer*/ + disp_drv.buffer = &disp_buf_2; + disp_drv.user_data = this; + + /*Finally register the driver*/ + lv_disp_drv_register(&disp_drv); + + +} + +void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { + auto x = area->x1; + auto y = area->y1; + auto width = (area->x2-area->x1)+1; + auto height = (area->y2-area->y1)+1; + lcd.BeginDrawBuffer(x, y, width, height); + lcd.NextDrawBuffer(reinterpret_cast(color_p), width * height*2) ; + + ulTaskNotifyTake(pdTRUE, 500); + + /* IMPORTANT!!! + * Inform the graphics library that you are ready with the flushing*/ + lv_disp_flush_ready(&disp_drv); +} -- cgit v1.2.3-70-g09d2 From 167a0ffc873a2442af43d0347efd00f84932b8cc Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 16 Feb 2020 18:32:36 +0100 Subject: Add touch panel port to lvgl. PoC of user interaction with 3 screen (clock, menu and app). --- src/CMakeLists.txt | 17 ++++ src/Components/DateTime/DateTimeController.cpp | 2 +- src/DisplayApp/DisplayApp.cpp | 46 +++++++--- src/DisplayApp/DisplayApp.h | 8 +- src/DisplayApp/LittleVgl.cpp | 38 +++++++- src/DisplayApp/LittleVgl.h | 12 ++- src/DisplayApp/Screens/Clock.cpp | 57 ++++++++++-- src/DisplayApp/Screens/Clock.h | 11 ++- src/DisplayApp/Screens/Message.cpp | 77 +++++++++++++--- src/DisplayApp/Screens/Message.h | 12 ++- src/DisplayApp/Screens/Screen.h | 9 +- src/DisplayApp/Screens/Tab.cpp | 67 ++++++++++++++ src/DisplayApp/Screens/Tab.h | 28 ++++++ src/DisplayApp/Screens/Tile.cpp | 118 +++++++++++++++++++++++++ src/DisplayApp/Screens/Tile.h | 56 ++++++++++++ src/drivers/Cst816s.cpp | 40 ++++----- src/libs/lv_conf.h | 2 +- src/main.cpp | 8 +- 18 files changed, 540 insertions(+), 68 deletions(-) create mode 100644 src/DisplayApp/Screens/Tab.cpp create mode 100644 src/DisplayApp/Screens/Tab.h create mode 100644 src/DisplayApp/Screens/Tile.cpp create mode 100644 src/DisplayApp/Screens/Tile.h (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0b220423..a5971f27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,19 @@ set(LVGL_SRC libs/lvgl/src/lv_themes/lv_theme_night.h libs/lvgl/src/lv_themes/lv_theme_night.c + libs/lvgl/src/lv_objx/lv_list.c + libs/lvgl/src/lv_objx/lv_list.h + libs/lvgl/src/lv_objx/lv_tileview.c + libs/lvgl/src/lv_objx/lv_tileview.h + libs/lvgl/src/lv_objx/lv_tabview.c + libs/lvgl/src/lv_objx/lv_tabview.h + libs/lvgl/src/lv_objx/lv_btnm.c + libs/lvgl/src/lv_objx/lv_btnm.h + libs/lvgl/src/lv_objx/lv_page.c + libs/lvgl/src/lv_objx/lv_page.h + libs/lvgl/src/lv_objx/lv_img.c + libs/lvgl/src/lv_objx/lv_img.h + ) list(APPEND SOURCE_FILES @@ -148,6 +161,8 @@ list(APPEND SOURCE_FILES DisplayApp/Screens/Screen.cpp DisplayApp/Screens/Clock.cpp DisplayApp/Screens/Message.cpp + DisplayApp/Screens/Tile.cpp + DisplayApp/Screens/Tab.cpp main.cpp drivers/St7789.cpp drivers/SpiMaster.cpp @@ -177,6 +192,8 @@ set(INCLUDE_FILES DisplayApp/Screens/Screen.h DisplayApp/Screens/Clock.h DisplayApp/Screens/Message.h + DisplayApp/Screens/Tile.h + DisplayApp/Screens/Tab.h drivers/St7789.h drivers/SpiMaster.h Components/Gfx/Gfx.h diff --git a/src/Components/DateTime/DateTimeController.cpp b/src/Components/DateTime/DateTimeController.cpp index 81d45416..ed6d70fb 100644 --- a/src/Components/DateTime/DateTimeController.cpp +++ b/src/Components/DateTime/DateTimeController.cpp @@ -49,7 +49,7 @@ void DateTime::UpdateTime(uint32_t systickCounter) { previousSystickCounter = 0xffffff - (rest - systickCounter); } - currentDateTime += std::chrono::milliseconds (systickDelta*10); + currentDateTime += std::chrono::seconds (correctedDelta); auto dp = date::floor(currentDateTime); auto time = date::make_time(currentDateTime-dp); diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 365855ed..959c84a0 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include using namespace Pinetime::Applications; @@ -29,14 +31,12 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - clockScreen{gfx}, - messageScreen{gfx}{ + currentScreen{new Screens::Tile(this, gfx) } { msgQueue = xQueueCreate(queueSize, itemSize); - currentScreen = &clockScreen; } void DisplayApp::Start() { - if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 1024, this, 0, &taskHandle)) + if (pdPASS != xTaskCreate(DisplayApp::Process, "DisplayApp", 512, this, 0, &taskHandle)) APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } @@ -73,7 +73,7 @@ void DisplayApp::Refresh() { break; case States::Running: RunningState(); - queueTimeout = 1000; + queueTimeout = 20; break; } @@ -104,15 +104,17 @@ void DisplayApp::Refresh() { case Messages::UpdateDateTime: break; case Messages::UpdateBleConnection: - clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); +// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); break; case Messages::UpdateBatteryLevel: - clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); +// clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining()); break; case Messages::TouchEvent: if(state != States::Running) break; OnTouchEvent(); break; + case Messages::ButtonPushed: + currentScreen->OnButtonPushed(); } } } @@ -120,10 +122,26 @@ void DisplayApp::Refresh() { bool first = true; void DisplayApp::RunningState() { - clockScreen.SetCurrentDateTime(dateTimeController.CurrentDateTime()); +// clockScreen.SetCurrentDateTime(dateTimeController.CurrentDateTime()); if(currentScreen != nullptr) { currentScreen->Refresh(first); + if(currentScreen->GetNextScreen() != Screens::Screen::NextScreen::None) { + switch(currentScreen->GetNextScreen()) { + case Screens::Screen::NextScreen::Clock: + currentScreen.reset(nullptr); + currentScreen.reset(new Screens::Clock(this, gfx, dateTimeController)); + break; + case Screens::Screen::NextScreen::Menu: + currentScreen.reset(nullptr); + currentScreen.reset(new Screens::Tile(this, gfx)); + break; + case Screens::Screen::NextScreen::App: + currentScreen.reset(nullptr); + currentScreen.reset(new Screens::Message(this, gfx)); + break; + } + } first = false; } } @@ -144,10 +162,10 @@ void DisplayApp::PushMessage(DisplayApp::Messages msg) { static uint16_t pointColor = 0x07e0; void DisplayApp::OnTouchEvent() { - auto info = touchPanel.GetTouchInfo(); - - if(info.isTouch) { - gfx.FillRectangle(info.x-10, info.y-10, 20,20, pointColor); - pointColor+=10; - } +// auto info = touchPanel.GetTouchInfo(); +// +// if(info.isTouch) { +// gfx.FillRectangle(info.x-10, info.y-10, 20,20, pointColor); +// pointColor+=10; +// } } diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 8cd26ce8..f8101536 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -23,7 +23,7 @@ namespace Pinetime { class DisplayApp { public: enum class States {Idle, Running}; - enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent} ; + enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ; DisplayApp(Pinetime::Drivers::St7789& lcd, Pinetime::Components::Gfx& gfx, Pinetime::Components::LittleVgl& lvgl, @@ -60,12 +60,12 @@ namespace Pinetime { Pinetime::Drivers::Cst816S& touchPanel; void OnTouchEvent(); - Screens::Clock clockScreen; - Screens::Message messageScreen; - Screens::Screen* currentScreen = nullptr; + std::unique_ptr currentScreen; static constexpr uint8_t pinLcdBacklight1 = 14; static constexpr uint8_t pinLcdBacklight2 = 22; static constexpr uint8_t pinLcdBacklight3 = 23; + + bool isClock = true; }; } } diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index 7830953a..50744acc 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -17,8 +17,18 @@ static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_colo lvgl->FlushDisplay(area, color_p); } -LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd{lcd} { +bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { + auto* lvgl = static_cast(indev_drv->user_data); + return lvgl->GetTouchPadInfo(data); +} + +LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel} { lv_init(); + InitDisplay(); + InitTouchpad(); +} + +void LittleVgl::InitDisplay() { lv_theme_t* theme = lv_theme_night_init(10, NULL); lv_theme_set_current(theme); @@ -39,8 +49,16 @@ LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd{lcd} { /*Finally register the driver*/ lv_disp_drv_register(&disp_drv); +} +void LittleVgl::InitTouchpad() { + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = touchpad_read; + indev_drv.user_data = this; + lv_indev_drv_register(&indev_drv); } void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { @@ -57,3 +75,21 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { * Inform the graphics library that you are ready with the flushing*/ lv_disp_flush_ready(&disp_drv); } + +bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { + auto info = touchPanel.GetTouchInfo(); + + if((previousClick.x != info.x || previousClick.y != info.y) && + (info.gesture == Drivers::Cst816S::Gestures::SingleTap)) { + ptr->state = LV_INDEV_STATE_PR; + previousClick.x = ptr->point.x; + previousClick.y = ptr->point.y; + } + else { + ptr->state = LV_INDEV_STATE_REL; + } + + ptr->point.x = info.x; + ptr->point.y = info.y; + return false; +} diff --git a/src/DisplayApp/LittleVgl.h b/src/DisplayApp/LittleVgl.h index cff1c3b1..ef104969 100644 --- a/src/DisplayApp/LittleVgl.h +++ b/src/DisplayApp/LittleVgl.h @@ -2,26 +2,36 @@ #include #include +#include static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); +static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); namespace Pinetime { namespace Components { class LittleVgl { public: - LittleVgl(Pinetime::Drivers::St7789& lcd); + LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel); void FlushDisplay(const lv_area_t * area, lv_color_t * color_p); + bool GetTouchPadInfo(lv_indev_data_t *ptr); private: + void InitDisplay(); + void InitTouchpad(); + Pinetime::Drivers::St7789& lcd; + Pinetime::Drivers::Cst816S& touchPanel; + lv_disp_buf_t disp_buf_2; lv_color_t buf2_1[LV_HOR_RES_MAX * 2]; lv_color_t buf2_2[LV_HOR_RES_MAX * 2]; lv_disp_drv_t disp_drv; + lv_point_t previousClick; + }; } diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index a413476a..8513d3ed 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -4,12 +4,24 @@ #include #include #include "Clock.h" +#include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; -Clock::Clock(Pinetime::Components::Gfx &gfx) : Screen(gfx), currentDateTime{{}}, version {{}} { +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Clock* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +Clock::Clock(DisplayApp* app, Pinetime::Components::Gfx &gfx, Controllers::DateTime& dateTimeController) : Screen(app, gfx), currentDateTime{{}}, version {{}}, dateTimeController{dateTimeController} { + displayedChar[0] = 0; + displayedChar[1] = 0; + displayedChar[2] = 0; + displayedChar[3] = 0; + displayedChar[4] = 0; + label_battery = lv_label_create(lv_scr_act(), NULL); lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0); @@ -38,11 +50,24 @@ Clock::Clock(Pinetime::Components::Gfx &gfx) : Screen(gfx), currentDateTime{{}}, lv_label_set_style(label_version, LV_LABEL_STYLE_MAIN, labelStyle); lv_obj_align(label_version, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 100); + backgroundLabel = lv_label_create(lv_scr_act(), NULL); + backgroundLabel->user_data = this; + lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_set_click(backgroundLabel, true); + lv_obj_set_event_cb(backgroundLabel, event_handler); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); +} + +Clock::~Clock() { + lv_obj_clean(lv_scr_act()); } void Clock::Refresh(bool fullRefresh) { if(fullRefresh) { - auto dummy = currentDateTime.Get(); + auto currentDateTime = dateTimeController.CurrentDateTime(); } if (fullRefresh || batteryPercentRemaining.IsUpdated()) { @@ -62,6 +87,8 @@ void Clock::Refresh(bool fullRefresh) { // TODO color } + currentDateTime = dateTimeController.CurrentDateTime(); + if(fullRefresh || currentDateTime.IsUpdated()) { auto newDateTime = currentDateTime.Get(); @@ -86,10 +113,17 @@ void Clock::Refresh(bool fullRefresh) { char timeStr[6]; sprintf(timeStr, "%c%c:%c%c", hoursChar[0],hoursChar[1],minutesChar[0], minutesChar[1]); - lv_label_set_text(label_time, timeStr); + + if(hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] || minutesChar[1] != displayedChar[3]) { + displayedChar[0] = hoursChar[0]; + displayedChar[1] = hoursChar[1]; + displayedChar[2] = minutesChar[0]; + displayedChar[3] = minutesChar[1]; + + lv_label_set_text(label_time, timeStr); + } if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { - gfx.FillRectangle(0,180, 240, 15, 0x0000); char dateStr[22]; sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(dayOfWeek), day, MonthToString(month), year); lv_label_set_text(label_date, dateStr); @@ -103,9 +137,10 @@ void Clock::Refresh(bool fullRefresh) { } if(fullRefresh || version.IsUpdated()) { - char version[20]; - sprintf(version, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); - lv_label_set_text(label_version, version); + auto dummy = version.Get(); + char versionStr[20]; + sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); + lv_label_set_text(label_version, versionStr); } } @@ -145,4 +180,12 @@ char const *Clock::MonthsString[] = { "DEC" }; +void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(obj == backgroundLabel) { + if (event == LV_EVENT_CLICKED) { + nextScreen = NextScreen::Menu; + } + } +} + diff --git a/src/DisplayApp/Screens/Clock.h b/src/DisplayApp/Screens/Clock.h index f5328535..d6e5a288 100644 --- a/src/DisplayApp/Screens/Clock.h +++ b/src/DisplayApp/Screens/Clock.h @@ -21,7 +21,7 @@ namespace Pinetime { explicit DirtyValue(T v) { value = v; } explicit DirtyValue(T& v) { value = v; } bool IsUpdated() const { return isUpdated; } - T& Get() { return value; this->isUpdated = false;} + T& Get() { this->isUpdated = false; return value; } DirtyValue& operator=(const T& other) { this->value = other; @@ -35,19 +35,23 @@ namespace Pinetime { class Clock : public Screen{ public: enum class BleConnectionStates{ NotConnected, Connected}; - Clock(Components::Gfx& gfx); + Clock(DisplayApp* app, Components::Gfx& gfx, Controllers::DateTime& dateTimeController); + ~Clock() override; void Refresh(bool fullRefresh) override; void SetBatteryPercentRemaining(uint8_t percent) { batteryPercentRemaining = percent; } void SetBleConnectionState(BleConnectionStates state) { bleState = state; } void SetCurrentDateTime(const std::chrono::time_point& tp) { currentDateTime = tp;} + void OnObjectEvent(lv_obj_t *pObj, lv_event_t i); private: static const char* MonthToString(Pinetime::Controllers::DateTime::Months month); static const char* DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek); static char const *DaysString[]; static char const *MonthsString[]; + char displayedChar[5]; + const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data}; const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data}; @@ -69,6 +73,9 @@ namespace Pinetime { lv_obj_t* label_time; lv_obj_t* label_date; lv_obj_t* label_version; + lv_obj_t* backgroundLabel; + + Controllers::DateTime& dateTimeController; }; } diff --git a/src/DisplayApp/Screens/Message.cpp b/src/DisplayApp/Screens/Message.cpp index 8ffad413..c9e0938f 100644 --- a/src/DisplayApp/Screens/Message.cpp +++ b/src/DisplayApp/Screens/Message.cpp @@ -5,24 +5,77 @@ #include #include #include +#include #include "Message.h" +#include + using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Message* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +Message::Message(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { + + backgroundLabel = lv_label_create(lv_scr_act(), NULL); + backgroundLabel->user_data = this; + + labelStyle = const_cast(lv_label_get_style(backgroundLabel, LV_LABEL_STYLE_MAIN)); + labelStyle->text.font = &jetbrains_mono_bold_20; + + lv_label_set_style(backgroundLabel, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_set_click(backgroundLabel, true); + lv_obj_set_event_cb(backgroundLabel, event_handler); + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundLabel, 240, 240); + lv_obj_set_pos(backgroundLabel, 0, 0); + lv_label_set_text(backgroundLabel, ""); +// lv_obj_align(backgroundLabel, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + + button = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_event_cb(button, event_handler); + lv_obj_align(button, NULL, LV_ALIGN_CENTER, 0, -40); + button->user_data = this; + + label = lv_label_create(button, NULL); + lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle); + lv_label_set_text(label, "Hello!"); + + labelClick = lv_label_create(lv_scr_act(), NULL); + lv_label_set_style(labelClick, LV_LABEL_STYLE_MAIN, labelStyle); + lv_obj_align(labelClick, button, LV_ALIGN_OUT_BOTTOM_MID, 0, 30); + lv_label_set_text(labelClick, "0"); +} + +Message::~Message() { + lv_obj_clean(lv_scr_act()); +} -lv_obj_t * label; -int x = 0; void Message::Refresh(bool fullRefresh) { - if(fullRefresh) { - label = lv_label_create(lv_scr_act(), NULL); /*Add a label to the button*/ - labelStyle = const_cast(lv_label_get_style(label, LV_LABEL_STYLE_MAIN)); - labelStyle->text.font = &jetbrains_mono_extrabold_compressedextrabold_compressed; - lv_label_set_style(label, LV_LABEL_STYLE_MAIN, labelStyle); - lv_label_set_text(label, "01:23"); /*Set the labels text*/ - } else { - lv_obj_set_pos(label, 0, x++); - if(x > 200) x = 0; + if(previousClickCount != clickCount) { + lv_label_set_text_fmt(labelClick, "%d", clickCount); + previousClickCount = clickCount; } +} +void Message::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(obj == backgroundLabel) { + if(event == LV_EVENT_CLICKED) { + app->PushMessage(DisplayApp::Messages::SwitchScreen); + NRF_LOG_INFO("SCREEN"); + } + return ; + } + + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + clickCount++; + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } } diff --git a/src/DisplayApp/Screens/Message.h b/src/DisplayApp/Screens/Message.h index 419c2e62..2f1da942 100644 --- a/src/DisplayApp/Screens/Message.h +++ b/src/DisplayApp/Screens/Message.h @@ -15,14 +15,24 @@ namespace Pinetime { namespace Screens { class Message : public Screen{ public: - Message(Components::Gfx& gfx) : Screen(gfx) {} + explicit Message(DisplayApp* app, Components::Gfx& gfx); + ~Message() override; void Refresh(bool fullRefresh) override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + void OnButtonPushed() override { nextScreen = Screen::NextScreen::Menu; } private: const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data}; const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data}; lv_style_t* labelStyle; + lv_obj_t * label; + lv_obj_t* backgroundLabel; + lv_obj_t * button; + lv_obj_t * labelClick; + + uint32_t clickCount = 0 ; + uint32_t previousClickCount = 0; }; } } diff --git a/src/DisplayApp/Screens/Screen.h b/src/DisplayApp/Screens/Screen.h index 5e2fa43e..57b8ea2a 100644 --- a/src/DisplayApp/Screens/Screen.h +++ b/src/DisplayApp/Screens/Screen.h @@ -4,14 +4,21 @@ namespace Pinetime { namespace Applications { + class DisplayApp; namespace Screens { class Screen { public: - Screen(Components::Gfx& gfx) : gfx{gfx} {} + enum class NextScreen {None, Clock, Menu, App}; + Screen(DisplayApp* app, Components::Gfx& gfx) : app{app}, gfx{gfx} {} + virtual ~Screen() = default; virtual void Refresh(bool fullRefresh) = 0; + NextScreen GetNextScreen() {return nextScreen;} + virtual void OnButtonPushed() {}; protected: + DisplayApp* app; Components::Gfx& gfx; + NextScreen nextScreen = NextScreen::None; }; } } diff --git a/src/DisplayApp/Screens/Tab.cpp b/src/DisplayApp/Screens/Tab.cpp new file mode 100644 index 00000000..adc32578 --- /dev/null +++ b/src/DisplayApp/Screens/Tab.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "Tab.h" +#include + + +using namespace Pinetime::Applications::Screens; + +extern lv_font_t jetbrains_mono_bold_20; + +//static void event_handler(lv_obj_t * obj, lv_event_t event) { +// Tile* screen = static_cast(obj->user_data); +// screen->OnObjectEvent(obj, event); +//} + +Tab::Tab(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { +/*Create a Tab view object*/ + lv_obj_t *tabview; + tabview = lv_tabview_create(lv_scr_act(), NULL); + + /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/ + lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1"); + lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2"); + lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3"); + + + /*Add content to the tabs*/ + lv_obj_t * label = lv_label_create(tab1, NULL); + lv_label_set_text(label, "This the first tab\n\n" + "If the content\n" + "of a tab\n" + "become too long\n" + "the it \n" + "automatically\n" + "become\n" + "scrollable."); + + label = lv_label_create(tab2, NULL); + lv_label_set_text(label, "Second tab"); + + label = lv_label_create(tab3, NULL); + lv_label_set_text(label, "Third tab"); + +} + +Tab::~Tab() { + lv_obj_clean(lv_scr_act()); +} + +void Tab::Refresh(bool fullRefresh) { + +} + +void Tab::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } +} diff --git a/src/DisplayApp/Screens/Tab.h b/src/DisplayApp/Screens/Tab.h new file mode 100644 index 00000000..1af956f4 --- /dev/null +++ b/src/DisplayApp/Screens/Tab.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include "Screen.h" +#include +#include "../Fonts/lcdfont14.h" +#include "../Fonts/lcdfont70.h" +#include "../../Version.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Tab : public Screen { + public: + explicit Tab(DisplayApp* app, Components::Gfx& gfx); + ~Tab() override; + void Refresh(bool fullRefresh) override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + + private: + + }; + } + } +} diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp new file mode 100644 index 00000000..d89562c7 --- /dev/null +++ b/src/DisplayApp/Screens/Tile.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "Tile.h" +#include +#include + + +using namespace Pinetime::Applications::Screens; + +extern lv_font_t jetbrains_mono_bold_20; + +static void event_handler(lv_obj_t * obj, lv_event_t event) { + Tile* screen = static_cast(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +//static const char * btnm_map1[] = {"App1", "App2", "App3", "\n", "App4", "App5", "App11", ""}; +//static const char * btnm_map2[] = {"App6", "App7", "App8", "\n", "App9", "App10", "App22",""}; +static const char * btnm_map1[] = {"App1", ""}; + +Tile::Tile(DisplayApp* app, Pinetime::Components::Gfx &gfx) : Screen(app, gfx) { + + static lv_point_t valid_pos[] = {{0,0}, {LV_COORD_MIN, LV_COORD_MIN}}; + tileview = lv_tileview_create(lv_scr_act(), NULL); + lv_tileview_set_valid_positions(tileview, valid_pos, 1); + lv_tileview_set_edge_flash(tileview, false); + + tile1 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile1, 0, 0); + lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile1); + + btnm1 = lv_btnm_create(tile1, NULL); + lv_btnm_set_map(btnm1, btnm_map1); + lv_obj_set_size(btnm1, LV_HOR_RES, LV_VER_RES); + + labelStyle = const_cast(lv_label_get_style(btnm1, LV_BTNM_STYLE_BTN_REL)); + labelStyle->text.font = &jetbrains_mono_bold_20; + labelStyle->body.grad_color = labelStyle->body.main_color; + lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_REL, labelStyle); + lv_btnm_set_style(btnm1, LV_BTNM_STYLE_BTN_PR, labelStyle); + + lv_obj_align(btnm1, tile1, LV_ALIGN_CENTER, 0, 0); + btnm1->user_data = this; + lv_obj_set_event_cb(btnm1, event_handler); +/* + tile2 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile2, 0, LV_VER_RES); + lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile2); + + btnm2 = lv_btnm_create(tileview, NULL); + lv_btnm_set_map(btnm2, btnm_map2); + lv_obj_align(btnm2, tile2, LV_ALIGN_CENTER, 0, 0); +*/ +/* + tile1 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile1, 0, 0); + lv_obj_set_size(tile1, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile1); + + btn1 = lv_btn_create(tile1, NULL); + lv_obj_align(btn1, tile1, LV_ALIGN_CENTER, 0, 0); + + label1 = lv_label_create(btn1, NULL); + lv_label_set_text(label1, "Button1"); +*/ +/* + tile2 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile2, 0, LV_VER_RES); + lv_obj_set_size(tile2, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile2); + + btn2 = lv_btn_create(tile2, NULL); + lv_obj_align(btn2, tile2, LV_ALIGN_CENTER, 0, 0); + + + label2 = lv_label_create(btn2, NULL); + lv_label_set_text(label2, "Button2"); + + tile3 = lv_obj_create(tileview, NULL); + lv_obj_set_pos(tile3, 0, LV_VER_RES*2); + lv_obj_set_size(tile3, LV_HOR_RES, LV_VER_RES); + lv_tileview_add_element(tileview, tile3); + + btn3 = lv_btn_create(tile3, NULL); + lv_obj_align(btn3, tile3, LV_ALIGN_CENTER, 0, 0); + + + label3 = lv_label_create(btn3, NULL); + lv_label_set_text(label3, "Button3"); +*/ +} + +Tile::~Tile() { + lv_obj_clean(lv_scr_act()); +} + +void Tile::Refresh(bool fullRefresh) { + +} + +void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event) { + if(event == LV_EVENT_CLICKED) { + NRF_LOG_INFO("Clicked"); + nextScreen = Screen::NextScreen::App; + clickCount++; + } + else if(event == LV_EVENT_VALUE_CHANGED) { + NRF_LOG_INFO("Toggled"); + } +} diff --git a/src/DisplayApp/Screens/Tile.h b/src/DisplayApp/Screens/Tile.h new file mode 100644 index 00000000..c9de2c5c --- /dev/null +++ b/src/DisplayApp/Screens/Tile.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include "Screen.h" +#include +#include "../Fonts/lcdfont14.h" +#include "../Fonts/lcdfont70.h" +#include "../../Version.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Tile : public Screen { + public: + explicit Tile(DisplayApp* app, Components::Gfx& gfx); + ~Tile() override; + void Refresh(bool fullRefresh) override; + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + + void OnButtonPushed() override {nextScreen = NextScreen::Clock;} + + private: + const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data}; + const FONT_INFO smallFont {lCD_14ptFontInfo.height, lCD_14ptFontInfo.startChar, lCD_14ptFontInfo.endChar, lCD_14ptFontInfo.spacePixels, lCD_14ptFontInfo.charInfo, lCD_14ptFontInfo.data}; + + lv_style_t* labelStyle; + lv_obj_t * label1; + lv_obj_t * label2; + lv_obj_t * label3; + + lv_obj_t* backgroundLabel; + lv_obj_t * button; + lv_obj_t * labelClick; + + lv_obj_t *tileview; + lv_obj_t * tile1; + lv_obj_t * tile2; + lv_obj_t * list; + lv_obj_t * list_btn; + lv_obj_t * tile3; + lv_obj_t * btn1; + lv_obj_t * btn2; + lv_obj_t * btn3; + + lv_obj_t * btnm1; + lv_obj_t * btnm2; + + uint32_t clickCount = 0 ; + uint32_t previousClickCount = 0; + }; + } + } +} diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index b1af12d4..61bce94c 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -78,26 +78,26 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { info.action = action; info.gesture = static_cast(touchData[gestureIndex]); - NRF_LOG_INFO("---------------") - NRF_LOG_INFO("ID : %d", pointId); - NRF_LOG_INFO("NB : %d", nbTouchPoints); - NRF_LOG_INFO("X/Y :%d / %d", info.x, info.y); - NRF_LOG_INFO("Action : %d", action); - NRF_LOG_INFO("Finger : %d", finger); - NRF_LOG_INFO("Pressure : %d", pressure); - NRF_LOG_INFO("area : %d", area); - NRF_LOG_INFO("Touch : %s", info.isTouch?"Yes" : "No"); - switch(info.gesture) {// gesture - case Gestures::None: NRF_LOG_INFO("Gesture : None"); break; - case Gestures::SlideDown: NRF_LOG_INFO("Gesture : Slide Down"); break; - case Gestures::SlideUp: NRF_LOG_INFO("Gesture : Slide Up"); break; - case Gestures::SlideLeft: NRF_LOG_INFO("Gesture : Slide Left"); break; - case Gestures::SlideRight: NRF_LOG_INFO("Gesture : Slide Right"); break; - case Gestures::SingleTap: NRF_LOG_INFO("Gesture : Single click"); break; - case Gestures::DoubleTap: NRF_LOG_INFO("Gesture : Double click"); break; - case Gestures::LongPress: NRF_LOG_INFO("Gesture : Long press"); break; - default : NRF_LOG_INFO("Unknown"); break; - } +// NRF_LOG_INFO("---------------") +// NRF_LOG_INFO("ID : %d", pointId); +// NRF_LOG_INFO("NB : %d", nbTouchPoints); +// NRF_LOG_INFO("X/Y :%d / %d", info.x, info.y); +// NRF_LOG_INFO("Action : %d", action); +// NRF_LOG_INFO("Finger : %d", finger); +// NRF_LOG_INFO("Pressure : %d", pressure); +// NRF_LOG_INFO("area : %d", area); +// NRF_LOG_INFO("Touch : %s", info.isTouch?"Yes" : "No"); +// switch(info.gesture) {// gesture +// case Gestures::None: NRF_LOG_INFO("Gesture : None"); break; +// case Gestures::SlideDown: NRF_LOG_INFO("Gesture : Slide Down"); break; +// case Gestures::SlideUp: NRF_LOG_INFO("Gesture : Slide Up"); break; +// case Gestures::SlideLeft: NRF_LOG_INFO("Gesture : Slide Left"); break; +// case Gestures::SlideRight: NRF_LOG_INFO("Gesture : Slide Right"); break; +// case Gestures::SingleTap: NRF_LOG_INFO("Gesture : Single click"); break; +// case Gestures::DoubleTap: NRF_LOG_INFO("Gesture : Double click"); break; +// case Gestures::LongPress: NRF_LOG_INFO("Gesture : Long press"); break; +// default : NRF_LOG_INFO("Unknown"); break; +// } } diff --git a/src/libs/lv_conf.h b/src/libs/lv_conf.h index 603339ee..8d7a6f7e 100644 --- a/src/libs/lv_conf.h +++ b/src/libs/lv_conf.h @@ -563,7 +563,7 @@ typedef void * lv_obj_user_data_t; #define LV_USE_TILEVIEW 1 #if LV_USE_TILEVIEW /*Time of slide animation [ms] (0: no animation)*/ -# define LV_TILEVIEW_DEF_ANIM_TIME 300 +# define LV_TILEVIEW_DEF_ANIM_TIME 0 #endif /*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ diff --git a/src/main.cpp b/src/main.cpp index 0d374c6b..2a272677 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,7 @@ extern "C" { void DebounceTimerCallback(TimerHandle_t xTimer) { xTimerStop(xTimer, 0); - if(isSleeping) { + /*if(isSleeping) { SystemTask_PushMessage(SystemTaskMessages::GoToRunning); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToRunning); isSleeping = false; @@ -93,7 +93,8 @@ void DebounceTimerCallback(TimerHandle_t xTimer) { SystemTask_PushMessage(SystemTaskMessages::GoToSleep); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep); isSleeping = true; - } + }*/ + displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::ButtonPushed); } void SystemTask_PushMessage(SystemTaskMessages message) { @@ -126,8 +127,9 @@ void SystemTask(void *) { lcd.reset(new Pinetime::Drivers::St7789(*spi, pinLcdDataCommand)); gfx.reset(new Pinetime::Components::Gfx(*lcd)); - lvgl.reset(new Pinetime::Components::LittleVgl(*lcd)); touchPanel.reset(new Pinetime::Drivers::Cst816S()); + + lvgl.reset(new Pinetime::Components::LittleVgl(*lcd, *touchPanel)); ptrLcd = lcd.get(); spi->Init(); -- cgit v1.2.3-70-g09d2 From e285ba9972fc2e0c74457b01db28dba9cb88c4e2 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 15:57:58 +0100 Subject: Fix double-buffering for spi display (it's actually using double-buffering, now) --- src/DisplayApp/DisplayApp.cpp | 3 +++ src/DisplayApp/LittleVgl.cpp | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 2519f40e..316312ed 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -45,6 +45,9 @@ void DisplayApp::Process(void *instance) { NRF_LOG_INFO("DisplayApp task started!"); app->InitHw(); + // Send a dummy notification to unlock the lvgl display driver for the first iteration + xTaskNotifyGive(xTaskGetCurrentTaskHandle()); + while (1) { app->Refresh(); diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index 50744acc..95794546 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -62,6 +62,8 @@ void LittleVgl::InitTouchpad() { } void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { + ulTaskNotifyTake(pdTRUE, 500); + auto x = area->x1; auto y = area->y1; auto width = (area->x2-area->x1)+1; -- cgit v1.2.3-70-g09d2 From 6d288b905acfe8bbb5e0b6ea493e25c7143cebd5 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 15:59:17 +0100 Subject: Configure lvgl theme and use 2*4lines buffers as video buffer (2 lines was not enough and caused perf issues) --- src/DisplayApp/LittleVgl.cpp | 624 ++++++++++++++++++++++++++++++++++++++++++- src/DisplayApp/LittleVgl.h | 65 ++++- 2 files changed, 680 insertions(+), 9 deletions(-) (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index 95794546..c4fa1793 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -24,15 +24,13 @@ bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel} { lv_init(); + InitTheme(); InitDisplay(); InitTouchpad(); } void LittleVgl::InitDisplay() { - lv_theme_t* theme = lv_theme_night_init(10, NULL); - lv_theme_set_current(theme); - - lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 2); /*Initialize the display buffer*/ + lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 4); /*Initialize the display buffer*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*Set up the functions to access to your display*/ @@ -71,8 +69,6 @@ void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) { lcd.BeginDrawBuffer(x, y, width, height); lcd.NextDrawBuffer(reinterpret_cast(color_p), width * height*2) ; - ulTaskNotifyTake(pdTRUE, 500); - /* IMPORTANT!!! * Inform the graphics library that you are ready with the flushing*/ lv_disp_flush_ready(&disp_drv); @@ -95,3 +91,619 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { ptr->point.y = info.y; return false; } + +void LittleVgl::InitTheme() { + uint16_t i; + lv_style_t ** style_p = (lv_style_t **)&theme.style; + for(i = 0; i < LV_THEME_STYLE_COUNT; i++) { + *style_p = &def; + style_p++; + } + + InitBaseTheme(); + InitThemeContainer(); + InitThemeButton(); + InitThemeLabel(); + InitThemeLine(); + InitThemeLed(); + InitThemeImage(); + InitThemeBar(); + InitThemeSlider(); + InitThemeSwitch(); + InitThemeMeter(); + InitThemeGauge(); + InitThemeArc(); + InitThemePreload(); + InitThemeChart(); + InitThemeCalendar(); + InitThemeCheckBox(); + InitThemeButtonMatrix(); + InitThemeKnob(); + InitThemeMessageBox(); + InitThemePage(); + InitThemeTextArea(); + InitThemeSpinBox(); + InitThemeList(); + InitThemeDropDownList(); + InitThemeRoller(); + InitThemeTabView(); + InitThemeTileView(); + InitThemeTable(); + InitThemeWindow(); + + lv_theme_set_current(&theme); +} + +void LittleVgl::InitBaseTheme() { + if(font == nullptr) font = LV_FONT_DEFAULT; + + lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/ + def.text.font = font; + + lv_style_copy(&bg, &lv_style_plain); + bg.body.main_color = LV_COLOR_BLACK; + bg.body.grad_color = LV_COLOR_BLACK; + bg.text.color = LV_COLOR_WHITE; + bg.text.font = font; + bg.image.color = LV_COLOR_WHITE; + + lv_style_copy(&scr, &bg); + scr.body.padding.bottom = 0; + scr.body.padding.top = 0; + scr.body.padding.left = 0; + scr.body.padding.right = 0; + + lv_style_copy(&sb, &def); + sb.body.main_color = lv_color_hsv_to_rgb(hue, 30, 60); + sb.body.grad_color = lv_color_hsv_to_rgb(hue, 30, 60); + sb.body.border.width = 0; + sb.body.padding.inner = LV_DPI / 20; + sb.body.padding.left = 0; + sb.body.padding.right = 0; + sb.body.padding.top = 0; + sb.body.padding.bottom = 0; + sb.body.radius = LV_DPI / 30; + sb.body.opa = LV_OPA_COVER; + + lv_style_copy(&panel, &bg); + panel.body.main_color = lv_color_hsv_to_rgb(hue, 11, 18); + panel.body.grad_color = lv_color_hsv_to_rgb(hue, 11, 18); + panel.body.radius = LV_DPI / 20; + panel.body.border.color = lv_color_hsv_to_rgb(hue, 10, 25); + panel.body.border.width = 1; + panel.body.border.opa = LV_OPA_COVER; + panel.body.padding.left = LV_DPI / 10; + panel.body.padding.right = LV_DPI / 10; + panel.body.padding.top = LV_DPI / 10; + panel.body.padding.bottom = LV_DPI / 10; + panel.line.color = lv_color_hsv_to_rgb(hue, 20, 40); + panel.line.width = 1; + + theme.style.scr = &scr; + theme.style.bg = &bg; + theme.style.panel = &def; +} + +void LittleVgl::InitThemeContainer() { + theme.style.cont = &panel; +} + +void LittleVgl::InitThemeButton() { + + + lv_style_copy(&btn_rel, &def); + btn_rel.body.main_color = lv_color_hsv_to_rgb(hue, 10, 40); + btn_rel.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 20); + btn_rel.body.border.color = lv_color_hex3(0x111); + btn_rel.body.border.width = 1; + btn_rel.body.border.opa = LV_OPA_70; + btn_rel.body.padding.left = LV_DPI / 4; + btn_rel.body.padding.right = LV_DPI / 4; + btn_rel.body.padding.top = LV_DPI / 8; + btn_rel.body.padding.bottom = LV_DPI / 8; + btn_rel.body.shadow.type = LV_SHADOW_BOTTOM; + btn_rel.body.shadow.color = lv_color_hex3(0x111); + btn_rel.body.shadow.width = LV_DPI / 30; + btn_rel.text.color = lv_color_hex3(0xeee); + btn_rel.image.color = lv_color_hex3(0xeee); + + lv_style_copy(&btn_pr, &btn_rel); + btn_pr.body.main_color = lv_color_hsv_to_rgb(hue, 10, 30); + btn_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 10); + + lv_style_copy(&btn_tgl_rel, &btn_rel); + btn_tgl_rel.body.main_color = lv_color_hsv_to_rgb(hue, 10, 20); + btn_tgl_rel.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 40); + btn_tgl_rel.body.shadow.width = LV_DPI / 40; + btn_tgl_rel.text.color = lv_color_hex3(0xddd); + btn_tgl_rel.image.color = lv_color_hex3(0xddd); + + lv_style_copy(&btn_tgl_pr, &btn_rel); + btn_tgl_pr.body.main_color = lv_color_hsv_to_rgb(hue, 10, 10); + btn_tgl_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 30); + btn_tgl_pr.body.shadow.width = LV_DPI / 30; + btn_tgl_pr.text.color = lv_color_hex3(0xddd); + btn_tgl_pr.image.color = lv_color_hex3(0xddd); + + lv_style_copy(&btn_ina, &btn_rel); + btn_ina.body.main_color = lv_color_hsv_to_rgb(hue, 10, 20); + btn_ina.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 20); + btn_ina.body.shadow.width = 0; + btn_ina.text.color = lv_color_hex3(0xaaa); + btn_ina.image.color = lv_color_hex3(0xaaa); + + theme.style.btn.rel = &btn_rel; + theme.style.btn.pr = &btn_pr; + theme.style.btn.tgl_rel = &btn_tgl_rel; + theme.style.btn.tgl_pr = &btn_tgl_pr; + theme.style.btn.ina = &btn_ina; +} + +void LittleVgl::InitThemeLabel() { + lv_style_copy(&prim, &bg); + prim.text.color = lv_color_hsv_to_rgb(hue, 5, 95); + + lv_style_copy(&sec, &bg); + sec.text.color = lv_color_hsv_to_rgb(hue, 15, 65); + + lv_style_copy(&hint, &bg); + hint.text.color = lv_color_hsv_to_rgb(hue, 20, 55); + + theme.style.label.prim = &prim; + theme.style.label.sec = &sec; + theme.style.label.hint = &hint; +} + +void LittleVgl::InitThemeLine() { + theme.style.line.decor = &def; +} + +void LittleVgl::InitThemeLed() { + lv_style_copy(&led, &def); + led.body.shadow.width = LV_DPI / 10; + led.body.radius = LV_RADIUS_CIRCLE; + led.body.border.width = LV_DPI / 30; + led.body.border.opa = LV_OPA_30; + led.body.main_color = lv_color_hsv_to_rgb(hue, 100, 100); + led.body.grad_color = lv_color_hsv_to_rgb(hue, 100, 40); + led.body.border.color = lv_color_hsv_to_rgb(hue, 60, 60); + led.body.shadow.color = lv_color_hsv_to_rgb(hue, 100, 100); + + theme.style.led = &led; +} + +void LittleVgl::InitThemeImage() { + theme.style.img.light = &def; + theme.style.img.dark = &def; +} + +void LittleVgl::InitThemeBar() { + lv_style_copy(&bar_bg, &panel); + bar_bg.body.padding.left = LV_DPI / 16; + bar_bg.body.padding.right = LV_DPI / 16; + bar_bg.body.padding.top = LV_DPI / 16; + bar_bg.body.padding.bottom = LV_DPI / 16; + bar_bg.body.radius = LV_RADIUS_CIRCLE; + + lv_style_copy(&bar_indic, &def); + bar_indic.body.main_color = lv_color_hsv_to_rgb(hue, 80, 70); + bar_indic.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 70); + bar_indic.body.border.color = lv_color_hsv_to_rgb(hue, 20, 15); + bar_indic.body.border.width = 1; + bar_indic.body.border.opa = LV_OPA_COVER; + bar_indic.body.radius = LV_RADIUS_CIRCLE; + bar_indic.body.padding.left = 0; + bar_indic.body.padding.right = 0; + bar_indic.body.padding.top = 0; + bar_indic.body.padding.bottom = 0; + + theme.style.bar.bg = &bar_bg; + theme.style.bar.indic = &bar_indic; +} + +void LittleVgl::InitThemeSlider() { + lv_style_copy(&slider_knob, theme.style.btn.rel); + slider_knob.body.radius = LV_RADIUS_CIRCLE; + + theme.style.slider.bg = theme.style.bar.bg; + theme.style.slider.indic = theme.style.bar.indic; + theme.style.slider.knob = &slider_knob; +} + +void LittleVgl::InitThemeSwitch() { + theme.style.sw.bg = theme.style.bar.bg; + theme.style.sw.indic = theme.style.bar.indic; + theme.style.sw.knob_off = theme.style.slider.knob; + theme.style.sw.knob_on = theme.style.slider.knob; +} + +void LittleVgl::InitThemeMeter() { + static lv_style_t lmeter_bg; + lv_style_copy(&lmeter_bg, &def); + lmeter_bg.body.main_color = lv_color_hsv_to_rgb(hue, 10, 70); + lmeter_bg.body.grad_color = lv_color_hsv_to_rgb(hue, 95, 90); + lmeter_bg.body.padding.left = LV_DPI / 10; /*Scale line length*/ + lmeter_bg.body.padding.inner = LV_DPI / 10; /*Text padding*/ + lmeter_bg.body.border.color = lv_color_hex3(0x333); + lmeter_bg.line.color = lv_color_hex3(0x555); + lmeter_bg.line.width = 1; + lmeter_bg.text.color = lv_color_hex3(0xddd); + + theme.style.lmeter = &lmeter_bg; +} + +void LittleVgl::InitThemeGauge() { + static lv_style_t gauge_bg; + lv_style_copy(&gauge_bg, &def); + gauge_bg.body.main_color = lv_color_hsv_to_rgb(hue, 10, 70); + gauge_bg.body.grad_color = gauge_bg.body.main_color; + gauge_bg.line.color = lv_color_hsv_to_rgb(hue, 80, 75); + gauge_bg.line.width = 1; + gauge_bg.text.color = lv_color_hex3(0xddd); + + theme.style.gauge = &gauge_bg; +} + +void LittleVgl::InitThemeArc() { + lv_style_copy(&arc, &def); + arc.line.width = 8; + arc.line.color = lv_color_hsv_to_rgb(hue, 80, 70); + arc.line.rounded = 1; + + /*For preloader*/ + arc.body.border.width = 7; + arc.body.border.color = lv_color_hsv_to_rgb(hue, 11, 48); + arc.body.padding.left = 1; + arc.body.padding.right = 1; + arc.body.padding.top = 1; + arc.body.padding.bottom = 1; + + theme.style.arc = &arc; +} + +void LittleVgl::InitThemePreload() { +// theme.style.preload = theme.style.arc; +} + +void LittleVgl::InitThemeChart() { + theme.style.chart = &panel; +} + +void LittleVgl::InitThemeCalendar() { + + lv_style_copy(&cal_bg, &bg); + cal_bg.body.main_color = lv_color_hsv_to_rgb(hue, 10, 40); + cal_bg.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 40); + cal_bg.body.border.color = lv_color_hex3(0x333); + cal_bg.body.border.width = 1; + cal_bg.body.radius = LV_DPI / 20; + cal_bg.body.padding.left = LV_DPI / 10; + cal_bg.body.padding.right = LV_DPI / 10; + cal_bg.body.padding.top = LV_DPI / 10; + cal_bg.body.padding.bottom = LV_DPI / 10; + + + lv_style_copy(&cal_header, &bg); + cal_header.body.main_color = lv_color_hsv_to_rgb(hue, 10, 20); + cal_header.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 20); + cal_header.body.radius = 0; + cal_header.body.border.width = 1; + cal_header.body.border.color = lv_color_hex3(0x333); + cal_header.body.padding.left = LV_DPI / 10; + cal_header.body.padding.right = LV_DPI / 10; + cal_header.body.padding.top = LV_DPI / 10; + cal_header.body.padding.bottom = LV_DPI / 10; + + + lv_style_copy(&week_box, &panel); + week_box.body.main_color = lv_color_hsv_to_rgb(hue, 30, 45); + week_box.body.grad_color = lv_color_hsv_to_rgb(hue, 30, 45); + week_box.body.radius = LV_DPI / 20; + week_box.body.border.width = 1; + week_box.body.padding.left = LV_DPI / 20; + week_box.body.padding.right = LV_DPI / 20; + week_box.body.padding.top = LV_DPI / 25; + week_box.body.padding.bottom = LV_DPI / 25; + + lv_style_copy(&today_box, &week_box); + today_box.body.main_color = lv_color_hsv_to_rgb(hue, 80, 70); + today_box.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 70); + today_box.body.radius = LV_DPI / 20; + today_box.body.padding.left = LV_DPI / 14; + today_box.body.padding.right = LV_DPI / 14; + today_box.body.padding.top = LV_DPI / 14; + today_box.body.padding.bottom = LV_DPI / 14; + + lv_style_copy(&highlighted_days, &bg); + highlighted_days.text.color = lv_color_hsv_to_rgb(hue, 40, 80); + + lv_style_copy(&ina_days, &bg); + ina_days.text.color = lv_color_hsv_to_rgb(hue, 0, 60); + + theme.style.calendar.bg = &cal_bg; + theme.style.calendar.header = &cal_header; + theme.style.calendar.week_box = &week_box; + theme.style.calendar.today_box = &today_box; + theme.style.calendar.highlighted_days = &highlighted_days; + theme.style.calendar.day_names = &cal_bg; + theme.style.calendar.inactive_days = &ina_days; +} + +void LittleVgl::InitThemeCheckBox() { + + lv_style_copy(&rel, &def); + rel.body.radius = LV_DPI / 20; + rel.body.main_color = lv_color_hsv_to_rgb(hue, 10, 95); + rel.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 95); + rel.body.border.color = lv_color_hsv_to_rgb(hue, 10, 50); + rel.body.border.width = 2; + ; + + lv_style_copy(&pr, &rel); + pr.body.main_color = lv_color_hsv_to_rgb(hue, 10, 80); + pr.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 80); + pr.body.border.color = lv_color_hsv_to_rgb(hue, 10, 20); + pr.body.border.width = 1; + ; + + lv_style_copy(&tgl_rel, &rel); + tgl_rel.body.main_color = lv_color_hsv_to_rgb(hue, 80, 90); + tgl_rel.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 90); + tgl_rel.body.border.color = lv_color_hsv_to_rgb(hue, 80, 50); + + lv_style_copy(&tgl_pr, &tgl_rel); + tgl_pr.body.main_color = lv_color_hsv_to_rgb(hue, 80, 70); + tgl_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 70); + tgl_pr.body.border.color = lv_color_hsv_to_rgb(hue, 80, 30); + tgl_pr.body.border.width = 1; + ; + + lv_style_copy(&ina, &rel); + ina.body.main_color = lv_color_hex3(0x777); + ina.body.grad_color = lv_color_hex3(0x777); + ina.body.border.width = 0; + + theme.style.cb.bg = &lv_style_transp; + theme.style.cb.box.rel = &rel; + theme.style.cb.box.pr = ≺ + theme.style.cb.box.tgl_rel = &tgl_rel; + theme.style.cb.box.tgl_pr = &tgl_pr; + theme.style.cb.box.ina = &def; +} + +void LittleVgl::InitThemeButtonMatrix() { + + lv_style_copy(&btnm_bg, theme.style.btn.rel); + btnm_bg.body.padding.left = 2; + btnm_bg.body.padding.right = 2; + btnm_bg.body.padding.top = 2; + btnm_bg.body.padding.bottom = 2; + btnm_bg.body.padding.inner = 0; + btnm_bg.body.border.width = 1; + + lv_style_copy(&btnm_rel, theme.style.btn.rel); + btnm_rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL; + btnm_rel.body.border.width = 1; + btnm_rel.body.radius = 2; + + lv_style_copy(&btnm_pr, theme.style.btn.pr); + btnm_pr.body.border.part = btnm_rel.body.border.part; + btnm_pr.body.border.width = btnm_rel.body.border.width; + btnm_pr.body.radius = btnm_rel.body.radius; + + lv_style_copy(&btnm_tgl_rel, theme.style.btn.tgl_rel); + btnm_tgl_rel.body.border.part = btnm_rel.body.border.part; + btnm_tgl_rel.body.border.width = btnm_rel.body.border.width; + btnm_tgl_rel.body.radius = btnm_rel.body.radius; + + lv_style_copy(&btnm_tgl_pr, theme.style.btn.pr); + btnm_tgl_pr.body.border.part = btnm_rel.body.border.part; + btnm_tgl_pr.body.border.width = btnm_rel.body.border.width; + btnm_tgl_pr.body.radius = btnm_rel.body.radius; + + lv_style_copy(&btnm_ina, theme.style.btn.ina); + btnm_ina.body.border.part = btnm_rel.body.border.part; + btnm_ina.body.border.width = btnm_rel.body.border.width; + btnm_ina.body.radius = btnm_rel.body.radius; + + theme.style.btnm.bg = &btnm_bg; + theme.style.btnm.btn.rel = &btnm_rel; + theme.style.btnm.btn.pr = &btnm_pr; + theme.style.btnm.btn.tgl_rel = &btnm_tgl_rel; + theme.style.btnm.btn.tgl_pr = &btnm_tgl_pr; + theme.style.btnm.btn.ina = &btnm_ina; +} + +void LittleVgl::InitThemeKnob() { + theme.style.kb.bg = &bg; + theme.style.kb.btn.rel = theme.style.btn.rel; + theme.style.kb.btn.pr = theme.style.btn.pr; + theme.style.kb.btn.tgl_rel = theme.style.btn.tgl_rel; + theme.style.kb.btn.tgl_pr = theme.style.btn.tgl_pr; + theme.style.kb.btn.ina = theme.style.btn.ina; +} + +void LittleVgl::InitThemeMessageBox() { + lv_style_copy(&mbox_bg, &bg); + mbox_bg.body.main_color = lv_color_hsv_to_rgb(hue, 30, 30); + mbox_bg.body.grad_color = lv_color_hsv_to_rgb(hue, 30, 30); + mbox_bg.body.border.color = lv_color_hsv_to_rgb(hue, 11, 20); + mbox_bg.body.border.width = 1; + mbox_bg.body.shadow.width = LV_DPI / 10; + mbox_bg.body.shadow.color = lv_color_hex3(0x222); + mbox_bg.body.radius = LV_DPI / 20; + theme.style.mbox.bg = &mbox_bg; + theme.style.mbox.btn.bg = &lv_style_transp; + theme.style.mbox.btn.rel = theme.style.btn.rel; + theme.style.mbox.btn.pr = theme.style.btn.pr; +} + +void LittleVgl::InitThemePage() { + lv_style_copy(&page_scrl, &bg); + page_scrl.body.main_color = lv_color_hsv_to_rgb(hue, 10, 40); + page_scrl.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 40); + page_scrl.body.border.color = lv_color_hex3(0x333); + page_scrl.body.border.width = 1; + page_scrl.body.radius = LV_DPI / 20; + + theme.style.page.bg = &panel; + theme.style.page.scrl = &page_scrl; + theme.style.page.sb = &sb; +} + +void LittleVgl::InitThemeTextArea() { + theme.style.ta.area = &panel; + theme.style.ta.oneline = &panel; + theme.style.ta.cursor = NULL; + theme.style.ta.sb = &def; +} + +void LittleVgl::InitThemeSpinBox() { + theme.style.spinbox.bg = &panel; + theme.style.spinbox.cursor = theme.style.ta.cursor; + theme.style.spinbox.sb = theme.style.ta.sb; +} + +void LittleVgl::InitThemeList() { + + lv_style_copy(&list_bg, &panel); + list_bg.body.padding.top = 0; + list_bg.body.padding.bottom = 0; + list_bg.body.padding.left = 0; + list_bg.body.padding.right = 0; + list_bg.body.padding.inner = 0; + + lv_style_copy(&list_btn_rel, &bg); + list_btn_rel.body.opa = LV_OPA_TRANSP; + list_btn_rel.body.border.part = LV_BORDER_BOTTOM; + list_btn_rel.body.border.color = lv_color_hsv_to_rgb(hue, 10, 5); + list_btn_rel.body.border.width = 1; + list_btn_rel.body.radius = LV_DPI / 10; + list_btn_rel.text.color = lv_color_hsv_to_rgb(hue, 5, 80); + list_btn_rel.image.color = lv_color_hsv_to_rgb(hue, 5, 80); + list_btn_rel.body.padding.top = LV_DPI / 6; + list_btn_rel.body.padding.bottom = LV_DPI / 6; + list_btn_rel.body.padding.left = LV_DPI / 8; + list_btn_rel.body.padding.right = LV_DPI / 8; + + lv_style_copy(&list_btn_pr, theme.style.btn.pr); + list_btn_pr.body.main_color = lv_color_hsv_to_rgb(hue, 10, 5); + list_btn_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 5); + list_btn_pr.body.border.color = lv_color_hsv_to_rgb(hue, 10, 5); + list_btn_pr.body.border.width = 0; + list_btn_pr.body.padding.top = LV_DPI / 6; + list_btn_pr.body.padding.bottom = LV_DPI / 6; + list_btn_pr.body.padding.left = LV_DPI / 8; + list_btn_pr.body.padding.right = LV_DPI / 8; + list_btn_pr.text.color = lv_color_hsv_to_rgb(hue, 5, 80); + list_btn_pr.image.color = lv_color_hsv_to_rgb(hue, 5, 80); + + lv_style_copy(&list_btn_tgl_rel, &list_btn_rel); + list_btn_tgl_rel.body.opa = LV_OPA_COVER; + list_btn_tgl_rel.body.main_color = lv_color_hsv_to_rgb(hue, 80, 70); + list_btn_tgl_rel.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 70); + list_btn_tgl_rel.body.border.color = lv_color_hsv_to_rgb(hue, 60, 40); + list_btn_tgl_rel.body.radius = list_bg.body.radius; + + lv_style_copy(&list_btn_tgl_pr, &list_btn_tgl_rel); + list_btn_tgl_pr.body.main_color = lv_color_hsv_to_rgb(hue, 80, 60); + list_btn_tgl_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 80, 60); + + theme.style.list.sb = &sb; + theme.style.list.bg = &list_bg; + theme.style.list.scrl = &lv_style_transp_tight; + theme.style.list.btn.rel = &list_btn_rel; + theme.style.list.btn.pr = &list_btn_pr; + theme.style.list.btn.tgl_rel = &list_btn_tgl_rel; + theme.style.list.btn.tgl_pr = &list_btn_tgl_pr; + theme.style.list.btn.ina = &def; +} + +void LittleVgl::InitThemeDropDownList() { + lv_style_copy(&ddlist_bg, theme.style.btn.rel); + ddlist_bg.text.line_space = LV_DPI / 8; + ddlist_bg.body.padding.top = LV_DPI / 8; + ddlist_bg.body.padding.bottom = LV_DPI / 8; + ddlist_bg.body.padding.left = LV_DPI / 8; + ddlist_bg.body.padding.right = LV_DPI / 8; + ddlist_bg.body.radius = LV_DPI / 30; + + lv_style_copy(&ddlist_sel, theme.style.btn.rel); + ddlist_sel.body.main_color = lv_color_hsv_to_rgb(hue, 20, 50); + ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(hue, 20, 50); + ddlist_sel.body.radius = 0; + + theme.style.ddlist.bg = &ddlist_bg; + theme.style.ddlist.sel = &ddlist_sel; + theme.style.ddlist.sb = &def; +} + +void LittleVgl::InitThemeRoller() { + lv_style_t roller_bg; + + lv_style_copy(&roller_bg, theme.style.ddlist.bg); + roller_bg.body.main_color = lv_color_hsv_to_rgb(hue, 10, 20); + roller_bg.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 40); + roller_bg.text.color = lv_color_hsv_to_rgb(hue, 5, 70); + roller_bg.text.opa = LV_OPA_60; + + theme.style.roller.bg = &roller_bg; + theme.style.roller.sel = theme.style.ddlist.sel; +} + +void LittleVgl::InitThemeTabView() { + theme.style.tabview.bg = &bg; + theme.style.tabview.indic = &lv_style_transp; + theme.style.tabview.btn.bg = &lv_style_transp; + theme.style.tabview.btn.rel = theme.style.btn.rel; + theme.style.tabview.btn.pr = theme.style.btn.pr; + theme.style.tabview.btn.tgl_rel = theme.style.btn.tgl_rel; + theme.style.tabview.btn.tgl_pr = theme.style.btn.tgl_pr; +} + +void LittleVgl::InitThemeTileView() { + theme.style.tileview.bg = &lv_style_transp_tight; + theme.style.tileview.scrl = &lv_style_transp_tight; + theme.style.tileview.sb = theme.style.page.sb; +} + +void LittleVgl::InitThemeTable() { + lv_style_copy(&cell, &panel); + cell.body.radius = 0; + cell.body.border.width = 1; + cell.body.padding.left = LV_DPI / 12; + cell.body.padding.right = LV_DPI / 12; + cell.body.padding.top = LV_DPI / 12; + cell.body.padding.bottom = LV_DPI / 12; + + theme.style.table.bg = &lv_style_transp_tight; + theme.style.table.cell = &cell; +} + +void LittleVgl::InitThemeWindow() { +// lv_style_copy(&win_bg, &bg); +// win_bg.body.border.color = lv_color_hex3(0x333); +// win_bg.body.border.width = 1; +// +// lv_style_copy(&win_header, &win_bg); +// win_header.body.main_color = lv_color_hsv_to_rgb(hue, 10, 20); +// win_header.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 20); +// win_header.body.radius = 0; +// win_header.body.padding.left = 0; +// win_header.body.padding.right = 0; +// win_header.body.padding.top = 0; +// win_header.body.padding.bottom = 0; +// +// lv_style_copy(&win_btn_pr, &def); +// win_btn_pr.body.main_color = lv_color_hsv_to_rgb(hue, 10, 10); +// win_btn_pr.body.grad_color = lv_color_hsv_to_rgb(hue, 10, 10); +// win_btn_pr.text.color = lv_color_hex3(0xaaa); +// win_btn_pr.image.color = lv_color_hex3(0xaaa); +// +// theme.style.win.bg = &win_bg; +// theme.style.win.sb = &sb; +// theme.style.win.header = &win_header; +// theme.style.win.content = &lv_style_transp; +// theme.style.win.btn.rel = &lv_style_transp; +// theme.style.win.btn.pr = &win_btn_pr; +} diff --git a/src/DisplayApp/LittleVgl.h b/src/DisplayApp/LittleVgl.h index ef104969..e356a89c 100644 --- a/src/DisplayApp/LittleVgl.h +++ b/src/DisplayApp/LittleVgl.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -20,19 +22,76 @@ namespace Pinetime { private: void InitDisplay(); void InitTouchpad(); + void InitTheme(); + void InitBaseTheme(); + void InitThemeContainer(); + void InitThemeButton(); + void InitThemeLabel(); + void InitThemeLine(); + void InitThemeLed(); + void InitThemeImage(); + void InitThemeBar(); + void InitThemeSlider(); + void InitThemeSwitch(); + void InitThemeMeter(); + void InitThemeGauge(); + void InitThemeArc(); + void InitThemePreload(); + void InitThemeChart(); + void InitThemeCalendar(); + void InitThemeCheckBox(); + void InitThemeButtonMatrix(); + void InitThemeKnob(); + void InitThemeMessageBox(); + void InitThemePage(); + void InitThemeTextArea(); + void InitThemeSpinBox(); + void InitThemeList(); + void InitThemeDropDownList(); + void InitThemeRoller(); + void InitThemeTabView(); + void InitThemeTileView(); + void InitThemeTable(); + void InitThemeWindow(); Pinetime::Drivers::St7789& lcd; Pinetime::Drivers::Cst816S& touchPanel; lv_disp_buf_t disp_buf_2; - lv_color_t buf2_1[LV_HOR_RES_MAX * 2]; - lv_color_t buf2_2[LV_HOR_RES_MAX * 2]; + lv_color_t buf2_1[LV_HOR_RES_MAX * 4]; + lv_color_t buf2_2[LV_HOR_RES_MAX * 4]; lv_disp_drv_t disp_drv; lv_point_t previousClick; - + lv_style_t def; + lv_style_t scr, bg, sb, panel; + lv_font_t * font = nullptr; + uint16_t hue = 10; + lv_theme_t theme; + lv_style_t btn_rel, btn_pr, btn_tgl_rel, btn_tgl_pr, btn_ina; + lv_style_t prim, sec, hint; + lv_style_t led; + lv_style_t bar_bg, bar_indic; + lv_style_t slider_knob; + lv_style_t arc; + lv_style_t cal_bg; + lv_style_t cal_header; + lv_style_t week_box; + lv_style_t today_box; + lv_style_t highlighted_days; + lv_style_t ina_days; + lv_style_t rel, pr, tgl_rel, tgl_pr, ina; + lv_style_t btnm_bg, btnm_rel, btnm_pr, btnm_tgl_rel, btnm_tgl_pr, btnm_ina; + lv_style_t mbox_bg; + lv_style_t page_scrl; + lv_style_t list_bg, list_btn_rel, list_btn_pr, list_btn_tgl_rel, list_btn_tgl_pr; + lv_style_t ddlist_bg, ddlist_sel; + lv_style_t cell; + lv_style_t win_bg; + lv_style_t win_header; + lv_style_t win_btn_pr; }; } } -- cgit v1.2.3-70-g09d2 From 5bc0640b735573b465cfef16fb729ad5f5149eb4 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 1 Mar 2020 19:09:59 +0100 Subject: Fix typo in the name of the font "jetbrains_mono_extrabold_compressed" + use it as the default font. --- src/DisplayApp/DisplayApp.cpp | 11 +++++++++++ src/DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c | 10 +++++----- src/DisplayApp/LittleVgl.cpp | 8 ++++++-- src/DisplayApp/Screens/Clock.cpp | 4 ++-- src/DisplayApp/Screens/Gauge.cpp | 2 +- src/DisplayApp/Screens/Meter.cpp | 2 +- src/DisplayApp/Screens/Modal.cpp | 2 +- 7 files changed, 27 insertions(+), 12 deletions(-) (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 316312ed..d7d62dde 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -120,6 +120,17 @@ void DisplayApp::Refresh() { if(!currentScreen->OnButtonPushed()) { systemTask.PushMessage(System::SystemTask::Messages::GoToSleep); } +// currentScreen.reset(nullptr); +// if(toggle) { +// modal.Show(); +//// currentScreen.reset(new Screens::Tile(this)); +// toggle = false; +// } else { +// modal.Hide(); +//// currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); +// toggle = true; +// } + break; } } diff --git a/src/DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c b/src/DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c index c850cd91..c9917e40 100644 --- a/src/DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c +++ b/src/DisplayApp/Fonts/jetbrains_mono_extrabold_compressed.c @@ -6,11 +6,11 @@ * Opts: ******************************************************************************/ -#ifndef JETBRAINS_MONO_EXTRABOLD_COMPRESSEDEXTRABOLD_COMPRESSED -#define JETBRAINS_MONO_EXTRABOLD_COMPRESSEDEXTRABOLD_COMPRESSED 1 +#ifndef JETBRAINS_MONO_EXTRABOLD_COMPRESSED +#define JETBRAINS_MONO_EXTRABOLD_COMPRESSED 1 #endif -#if JETBRAINS_MONO_EXTRABOLD_COMPRESSEDEXTRABOLD_COMPRESSED +#if JETBRAINS_MONO_EXTRABOLD_COMPRESSED /*----------------- * BITMAPS @@ -492,7 +492,7 @@ static lv_font_fmt_txt_dsc_t font_dsc = { *----------------*/ /*Initialize a public general font descriptor*/ -lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed = { +lv_font_t jetbrains_mono_extrabold_compressed = { .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/ .line_height = 60, /*The maximum line height required by the font*/ @@ -503,5 +503,5 @@ lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed = { .dsc = &font_dsc /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */ }; -#endif /*#if JETBRAINS_MONO_EXTRABOLD_COMPRESSEDEXTRABOLD_COMPRESSED*/ +#endif /*#if JETBRAINS_MONO_EXTRABOLD_COMPRESSED*/ diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index c4fa1793..59334931 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -12,6 +12,11 @@ using namespace Pinetime::Components; +extern "C" { +LV_FONT_DECLARE(jetbrains_mono_extrabold_compressed) +LV_FONT_DECLARE(jetbrains_mono_bold_20) +} + static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) { auto* lvgl = static_cast(disp_drv->user_data); lvgl->FlushDisplay(area, color_p); @@ -135,8 +140,7 @@ void LittleVgl::InitTheme() { } void LittleVgl::InitBaseTheme() { - if(font == nullptr) font = LV_FONT_DEFAULT; - + if(font == nullptr) font = &jetbrains_mono_bold_20; lv_style_copy(&def, &lv_style_plain); /*Initialize the default style*/ def.text.font = font; diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index f0bd8338..1dff88c2 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -7,7 +7,7 @@ #include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; static void event_handler(lv_obj_t * obj, lv_event_t event) { @@ -33,7 +33,7 @@ Clock::Clock(DisplayApp* app, labelStyle->text.font = &jetbrains_mono_bold_20; lv_style_copy(&labelBigStyle, labelStyle); - labelBigStyle.text.font = &jetbrains_mono_extrabold_compressedextrabold_compressed; + labelBigStyle.text.font = &jetbrains_mono_extrabold_compressed; lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle); diff --git a/src/DisplayApp/Screens/Gauge.cpp b/src/DisplayApp/Screens/Gauge.cpp index 33f76a74..4c4cccd9 100644 --- a/src/DisplayApp/Screens/Gauge.cpp +++ b/src/DisplayApp/Screens/Gauge.cpp @@ -3,7 +3,7 @@ #include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; diff --git a/src/DisplayApp/Screens/Meter.cpp b/src/DisplayApp/Screens/Meter.cpp index 9daafad3..c74b8bdf 100644 --- a/src/DisplayApp/Screens/Meter.cpp +++ b/src/DisplayApp/Screens/Meter.cpp @@ -3,7 +3,7 @@ #include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp index 13bd42fa..7a0264e3 100644 --- a/src/DisplayApp/Screens/Modal.cpp +++ b/src/DisplayApp/Screens/Modal.cpp @@ -3,7 +3,7 @@ #include "../DisplayApp.h" using namespace Pinetime::Applications::Screens; -extern lv_font_t jetbrains_mono_extrabold_compressedextrabold_compressed; +extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app) { -- cgit v1.2.3-70-g09d2 From d88ec8c2f06c55a01395fcdab0b816b717d9c685 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 2 Mar 2020 20:48:58 +0100 Subject: Workaround for the first touch that is taken twice into account. --- src/DisplayApp/LittleVgl.cpp | 12 ++++++++---- src/DisplayApp/LittleVgl.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src/DisplayApp/LittleVgl.cpp') diff --git a/src/DisplayApp/LittleVgl.cpp b/src/DisplayApp/LittleVgl.cpp index 59334931..905c00ba 100644 --- a/src/DisplayApp/LittleVgl.cpp +++ b/src/DisplayApp/LittleVgl.cpp @@ -27,7 +27,7 @@ bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { return lvgl->GetTouchPadInfo(data); } -LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel} { +LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::Cst816S& touchPanel) : lcd{lcd}, touchPanel{touchPanel}, previousClick{0,0} { lv_init(); InitTheme(); InitDisplay(); @@ -84,9 +84,13 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t *ptr) { if((previousClick.x != info.x || previousClick.y != info.y) && (info.gesture == Drivers::Cst816S::Gestures::SingleTap)) { - ptr->state = LV_INDEV_STATE_PR; - previousClick.x = ptr->point.x; - previousClick.y = ptr->point.y; + // TODO For an unknown reason, the first touch is taken twice into account. + // 'firstTouch' is a quite'n'dirty workaound until I find a better solution + if(firstTouch) ptr->state = LV_INDEV_STATE_REL; + else ptr->state = LV_INDEV_STATE_PR; + firstTouch = false; + previousClick.x = info.x; + previousClick.y = info.y; } else { ptr->state = LV_INDEV_STATE_REL; diff --git a/src/DisplayApp/LittleVgl.h b/src/DisplayApp/LittleVgl.h index e356a89c..40fb1809 100644 --- a/src/DisplayApp/LittleVgl.h +++ b/src/DisplayApp/LittleVgl.h @@ -92,6 +92,8 @@ namespace Pinetime { lv_style_t win_bg; lv_style_t win_header; lv_style_t win_btn_pr; + + bool firstTouch = true; }; } } -- cgit v1.2.3-70-g09d2