diff options
| author | JF <jf@codingfield.com> | 2020-09-26 15:09:24 (GMT) |
|---|---|---|
| committer | Gitea <gitea@fake.local> | 2020-09-26 15:09:24 (GMT) |
| commit | b6a910e52ed98b662e6586f45cfe9c6997f8f158 (patch) | |
| tree | d74185cbf682cde40e5de5bfa2f620ae201565a9 /src/DisplayApp | |
| parent | be05997272b7b1d1b25b122c8162ac6f4c1c12a2 (diff) | |
| parent | 3e612e79ba82bac69258094d468c996c41b29612 (diff) | |
Merge branch 'develop' of JF/PineTime into master
Diffstat (limited to 'src/DisplayApp')
30 files changed, 915 insertions, 378 deletions
diff --git a/src/DisplayApp/Apps.h b/src/DisplayApp/Apps.h new file mode 100644 index 0000000..3842e4e --- /dev/null +++ b/src/DisplayApp/Apps.h @@ -0,0 +1,7 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness, Music, FirmwareValidation, Paint}; + } +}
\ No newline at end of file diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp index 8e35ef5..f6138ec 100644 --- a/src/DisplayApp/DisplayApp.cpp +++ b/src/DisplayApp/DisplayApp.cpp @@ -2,21 +2,22 @@ #include <FreeRTOS.h> #include <task.h> #include <libraries/log/nrf_log.h> -#include <boards.h> #include <nrf_font.h> #include <queue.h> #include <Components/DateTime/DateTimeController.h> #include <drivers/Cst816s.h> #include <string> -#include <lvgl/lvgl.h> #include <DisplayApp/Screens/Tile.h> -#include <DisplayApp/Screens/Message.h> #include <DisplayApp/Screens/Meter.h> #include <DisplayApp/Screens/Gauge.h> #include <DisplayApp/Screens/Brightness.h> -#include <DisplayApp/Screens/ScreenList.h> +#include <DisplayApp/Screens/SystemInfo.h> +#include <DisplayApp/Screens/Music.h> #include <Components/Ble/NotificationManager.h> #include <DisplayApp/Screens/FirmwareUpdate.h> +#include <DisplayApp/Screens/ApplicationList.h> +#include <DisplayApp/Screens/FirmwareValidation.h> +#include <DisplayApp/Screens/InfiniPaint.h> #include "../SystemTask/SystemTask.h" using namespace Pinetime::Applications; @@ -79,6 +80,9 @@ void DisplayApp::Refresh() { RunningState(); queueTimeout = 20; break; + default: + queueTimeout = portMAX_DELAY; + break; } Messages msg; @@ -91,14 +95,10 @@ void DisplayApp::Refresh() { vTaskDelay(100); } lcd.DisplayOff(); - lcd.Sleep(); - touchPanel.Sleep(); + systemTask.PushMessage(System::SystemTask::Messages::OnDisplayTaskSleeping); state = States::Idle; break; case Messages::GoToRunning: - lcd.Wakeup(); - touchPanel.Wakeup(); - lcd.DisplayOn(); brightnessController.Restore(); state = States::Running; @@ -168,6 +168,15 @@ void DisplayApp::Refresh() { break; } } + + if(state != States::Idle && touchMode == TouchModes::Polling) { + auto info = touchPanel.GetTouchInfo(); + if(info.action == 2) {// 2 = contact + if(!currentScreen->OnTouchEvent(info.x, info.y)) { + lvgl.SetNewTapEvent(info.x, info.y); + } + } + } } void DisplayApp::RunningState() { @@ -179,16 +188,19 @@ void DisplayApp::RunningState() { onClockApp = false; switch(nextApp) { case Apps::None: - case Apps::Launcher: currentScreen.reset(new Screens::Tile(this)); break; + case Apps::Launcher: currentScreen.reset(new Screens::ApplicationList(this)); break; case Apps::Clock: currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); onClockApp = true; break; // case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; - case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, bleController, watchdog)); break; + case Apps::SysInfo: currentScreen.reset(new Screens::SystemInfo(this, dateTimeController, batteryController, brightnessController, bleController, watchdog)); break; case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break; case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break; + case Apps::Paint: currentScreen.reset(new Screens::InfiniPaint(this, lvgl)); break; case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; + case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; + case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; } nextApp = Apps::None; } @@ -214,7 +226,8 @@ TouchEvents DisplayApp::OnTouchEvent() { if(info.isTouch) { switch(info.gesture) { case Pinetime::Drivers::Cst816S::Gestures::SingleTap: - lvgl.SetNewTapEvent(info.x, info.y); + if(touchMode == TouchModes::Gestures) + lvgl.SetNewTapEvent(info.x, info.y); return TouchEvents::Tap; case Pinetime::Drivers::Cst816S::Gestures::LongPress: return TouchEvents::LongTap; @@ -236,7 +249,7 @@ TouchEvents DisplayApp::OnTouchEvent() { return TouchEvents::None; } -void DisplayApp::StartApp(DisplayApp::Apps app) { +void DisplayApp::StartApp(Apps app) { nextApp = app; } @@ -252,3 +265,7 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { } } + +void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) { + touchMode = mode; +} diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h index 36f9315..345e06d 100644 --- a/src/DisplayApp/DisplayApp.h +++ b/src/DisplayApp/DisplayApp.h @@ -17,7 +17,9 @@ #include <drivers/Watchdog.h> #include <DisplayApp/Screens/Modal.h> #include <Components/Ble/NotificationManager.h> +#include <Components/FirmwareValidator/FirmwareValidator.h> #include "TouchEvents.h" +#include "Apps.h" namespace Pinetime { @@ -28,11 +30,11 @@ namespace Pinetime { class DisplayApp { public: enum class States {Idle, Running}; - enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed, - NewNotification, BleFirmwareUpdateStarted, BleFirmwareUpdateFinished - }; - enum class FullRefreshDirections { None, Up, Down }; + enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed, + NewNotification, BleFirmwareUpdateStarted }; + enum class FullRefreshDirections { None, Up, Down }; + enum class TouchModes { Gestures, Polling }; DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &, Controllers::Battery &batteryController, Controllers::Ble &bleController, @@ -42,10 +44,11 @@ namespace Pinetime { void Start(); void PushMessage(Messages msg); - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness}; void StartApp(Apps app); void SetFullRefresh(FullRefreshDirections direction); + void SetTouchMode(TouchModes mode); + private: TaskHandle_t taskHandle; static void Process(void* instance); @@ -80,6 +83,8 @@ namespace Pinetime { Controllers::BrightnessController brightnessController; std::unique_ptr<Screens::Modal> modal; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::FirmwareValidator validator; + TouchModes touchMode = TouchModes::Gestures; }; } } diff --git a/src/DisplayApp/Fonts/Readme.md b/src/DisplayApp/Fonts/Readme.md index ddccc82..7ebf2e2 100644 --- a/src/DisplayApp/Fonts/Readme.md +++ b/src/DisplayApp/Fonts/Readme.md @@ -10,7 +10,7 @@ * Bpp : 1 bit-per-pixel * Do not enable font compression and horizontal subpixel hinting * Load the file `JetBrainsMono-Bold.woff` and specify the following range : `0x20-0x7f` - * Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185` + * Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc` * Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts` Add new symbols: diff --git a/src/DisplayApp/Fonts/jetbrains_mono_bold_20.c b/src/DisplayApp/Fonts/jetbrains_mono_bold_20.c index 96e13d6..27ad005 100644 --- a/src/DisplayApp/Fonts/jetbrains_mono_bold_20.c +++ b/src/DisplayApp/Fonts/jetbrains_mono_bold_20.c @@ -433,6 +433,15 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = { /* U+7E "~" */ 0x78, 0xff, 0x3c, 0xff, 0x1e, + /* U+F001 "" */ + 0x0, 0x0, 0x70, 0x0, 0x7f, 0x0, 0x3f, 0xf0, + 0x1f, 0xff, 0x7, 0xff, 0xf0, 0x7f, 0xff, 0x7, + 0xfc, 0x70, 0x7e, 0x7, 0x7, 0x0, 0x70, 0x70, + 0x7, 0x7, 0x0, 0x70, 0x70, 0x7, 0x7, 0x0, + 0x70, 0x70, 0x7f, 0x7, 0xf, 0xf7, 0xf0, 0xff, + 0xff, 0x7, 0xef, 0xf0, 0x0, 0xff, 0x0, 0x3, + 0xc0, 0x0, + /* U+F017 "" */ 0x3, 0xf8, 0x1, 0xff, 0xc0, 0x7f, 0xfc, 0x1f, 0xff, 0xc7, 0xf1, 0xfc, 0xfe, 0x3f, 0x9f, 0xc7, @@ -449,6 +458,14 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = { 0xf, 0x0, 0x0, 0xf3, 0xff, 0xff, 0x3f, 0xff, 0xf0, 0x0, 0x0, + /* U+F069 "" */ + 0x0, 0xe0, 0x0, 0x1c, 0x0, 0x3, 0x80, 0x0, + 0x70, 0x6, 0xe, 0xc, 0xf1, 0xc7, 0x9f, 0xbb, + 0xf1, 0xff, 0xfc, 0xf, 0xfe, 0x0, 0x7f, 0x0, + 0xf, 0xe0, 0x7, 0xff, 0x3, 0xff, 0xf8, 0xfd, + 0xdf, 0x9e, 0x38, 0xf3, 0x7, 0x6, 0x0, 0xe0, + 0x0, 0x1c, 0x0, 0x3, 0x80, 0x0, 0x70, 0x0, + /* U+F129 "" */ 0x3c, 0x7e, 0x7e, 0x7e, 0x3c, 0x0, 0x0, 0xfc, 0xfc, 0xfc, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, @@ -470,6 +487,14 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = { 0x83, 0xfe, 0x3, 0xf8, 0x1, 0xc0, 0x3, 0x80, 0x7, 0x0, 0xe, 0x0, + /* U+F1FC "" */ + 0x0, 0x0, 0xf0, 0x0, 0x1f, 0x0, 0x3, 0xf0, + 0x0, 0x7e, 0x0, 0xf, 0xe0, 0x3, 0xfc, 0x0, + 0x7f, 0xc0, 0xf, 0xf8, 0x0, 0xff, 0x80, 0x1f, + 0xf0, 0x0, 0xfe, 0x0, 0xf, 0xe0, 0xe, 0x7c, + 0x1, 0xf8, 0x0, 0x9f, 0xc0, 0xf, 0xfc, 0x0, + 0x7f, 0xc0, 0x7, 0xf8, 0x0, 0x1f, 0x0, 0x0, + /* U+F21E "" */ 0x1e, 0x7, 0x83, 0xf9, 0xfe, 0x7f, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xfc, @@ -526,6 +551,15 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = { 0x81, 0xf8, 0x6d, 0x99, 0x9a, 0x36, 0x7, 0x80, 0xe0, 0x18, 0x2, 0x0, 0x0, + /* U+F3FD "" */ + 0x0, 0xfe, 0x0, 0x7, 0xff, 0x0, 0x3f, 0xbf, + 0x80, 0xfe, 0x2f, 0x83, 0xfe, 0xcf, 0x8f, 0x3f, + 0x27, 0x9e, 0x7e, 0x4f, 0x3f, 0xfc, 0xfe, 0xff, + 0xf3, 0xff, 0xff, 0xe7, 0xff, 0xff, 0xcf, 0xff, + 0xfe, 0x3f, 0xfe, 0x78, 0x3c, 0xff, 0xf0, 0x7f, + 0xdf, 0xe0, 0xff, 0x3f, 0xff, 0xfe, 0x3f, 0xff, + 0xf8, + /* U+F54B "" */ 0x0, 0xf, 0xf8, 0x1, 0xdf, 0xff, 0x1, 0xef, 0xff, 0xc0, 0xf7, 0xff, 0xf0, 0x7b, 0xff, 0xf8, @@ -534,7 +568,16 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = { 0x0, 0x0, 0x0, 0x7, 0xf8, 0x0, 0xf, 0xfe, 0x3, 0xbf, 0xff, 0x83, 0xdf, 0xff, 0xc1, 0xef, 0xff, 0xe0, 0xf7, 0xff, 0xe0, 0x3b, 0xff, 0xe0, - 0x0, 0x7f, 0xc0, 0x0 + 0x0, 0x7f, 0xc0, 0x0, + + /* U+F560 "" */ + 0x0, 0x0, 0x0, 0x0, 0x60, 0x0, 0xf, 0x0, + 0x1, 0xf0, 0x8, 0x3e, 0x1, 0xc7, 0xc4, 0x1e, + 0xf8, 0xe1, 0xff, 0x1f, 0xf, 0xe3, 0xf0, 0x7c, + 0x7e, 0x23, 0x8f, 0xc7, 0x11, 0xf8, 0xf8, 0x3f, + 0xf, 0xc7, 0xe0, 0x7e, 0xfc, 0x3, 0xff, 0x80, + 0x1f, 0xf0, 0x0, 0xfe, 0x0, 0x7, 0xc0, 0x0, + 0x38, 0x0, 0x1, 0x0, 0x0 }; @@ -639,20 +682,25 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { {.bitmap_index = 1423, .adv_w = 192, .box_w = 3, .box_h = 18, .ofs_x = 5, .ofs_y = -2}, {.bitmap_index = 1430, .adv_w = 192, .box_w = 10, .box_h = 18, .ofs_x = 1, .ofs_y = -2}, {.bitmap_index = 1453, .adv_w = 192, .box_w = 10, .box_h = 4, .ofs_x = 1, .ofs_y = 5}, - {.bitmap_index = 1458, .adv_w = 320, .box_w = 19, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, - {.bitmap_index = 1506, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 1549, .adv_w = 120, .box_w = 8, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, - {.bitmap_index = 1568, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, - {.bitmap_index = 1618, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, - {.bitmap_index = 1654, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1}, - {.bitmap_index = 1697, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, - {.bitmap_index = 1735, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, - {.bitmap_index = 1773, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, - {.bitmap_index = 1811, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, - {.bitmap_index = 1849, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, - {.bitmap_index = 1887, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3}, - {.bitmap_index = 1925, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3}, - {.bitmap_index = 1954, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2} + {.bitmap_index = 1458, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 1508, .adv_w = 320, .box_w = 19, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 1556, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1}, + {.bitmap_index = 1599, .adv_w = 320, .box_w = 19, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 1647, .adv_w = 120, .box_w = 8, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 1666, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 1716, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 1752, .adv_w = 320, .box_w = 20, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 1800, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1}, + {.bitmap_index = 1843, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, + {.bitmap_index = 1881, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, + {.bitmap_index = 1919, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, + {.bitmap_index = 1957, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, + {.bitmap_index = 1995, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1}, + {.bitmap_index = 2033, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3}, + {.bitmap_index = 2071, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3}, + {.bitmap_index = 2100, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1}, + {.bitmap_index = 2149, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2}, + {.bitmap_index = 2209, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3} }; /*--------------------- @@ -660,8 +708,9 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { *--------------------*/ static const uint16_t unicode_list_1[] = { - 0x0, 0x23, 0x112, 0x16e, 0x1cf, 0x207, 0x229, 0x22a, - 0x22b, 0x22c, 0x22d, 0x27c, 0x27d, 0x534 + 0x0, 0x16, 0x39, 0x68, 0x128, 0x184, 0x1e5, 0x1fb, + 0x21d, 0x23f, 0x240, 0x241, 0x242, 0x243, 0x292, 0x293, + 0x3fc, 0x54a, 0x55f }; /*Collect the unicode lists and glyph_id offsets*/ @@ -672,8 +721,8 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY }, { - .range_start = 61463, .range_length = 1333, .glyph_id_start = 96, - .unicode_list = unicode_list_1, .glyph_id_ofs_list = NULL, .list_length = 14, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY + .range_start = 61441, .range_length = 1376, .glyph_id_start = 96, + .unicode_list = unicode_list_1, .glyph_id_ofs_list = NULL, .list_length = 19, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY } }; diff --git a/src/DisplayApp/LittleVgl.h b/src/DisplayApp/LittleVgl.h index 8bd56dd..5c1c443 100644 --- a/src/DisplayApp/LittleVgl.h +++ b/src/DisplayApp/LittleVgl.h @@ -6,10 +6,6 @@ #include <drivers/St7789.h> #include <drivers/Cst816s.h> - -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 { diff --git a/src/DisplayApp/Screens/ApplicationList.cpp b/src/DisplayApp/Screens/ApplicationList.cpp new file mode 100644 index 0000000..eb85be4 --- /dev/null +++ b/src/DisplayApp/Screens/ApplicationList.cpp @@ -0,0 +1,82 @@ +#include <libs/lvgl/lvgl.h> +#include <DisplayApp/DisplayApp.h> +#include <functional> +#include "ApplicationList.h" +#include "Tile.h" +#include "Symbols.h" + +using namespace Pinetime::Applications::Screens; + +ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp *app) : + Screen(app), + screens{app, { + [this]() -> std::unique_ptr<Screen> { return CreateScreen1(); }, + [this]() -> std::unique_ptr<Screen> { return CreateScreen2(); }, + //[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); } + } + } {} + + +ApplicationList::~ApplicationList() { + lv_obj_clean(lv_scr_act()); +} + +bool ApplicationList::Refresh() { + if(running) + running = screens.Refresh(); + return running; +} + +bool ApplicationList::OnButtonPushed() { + running = false; + app->StartApp(Apps::Clock); + return true; +} + +bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); +} + +std::unique_ptr<Screen> ApplicationList::CreateScreen1() { + std::array<Screens::Tile::Applications, 6> applications { + {{Symbols::clock, Apps::Clock}, + {Symbols::music, Apps::Music}, + {Symbols::sun, Apps::Brightness}, + {Symbols::list, Apps::SysInfo}, + {Symbols::check, Apps::FirmwareValidation}, + {Symbols::none, Apps::None} + } + + + }; + + return std::unique_ptr<Screen>(new Screens::Tile(app, applications)); +} + +std::unique_ptr<Screen> ApplicationList::CreateScreen2() { + std::array<Screens::Tile::Applications, 6> applications { + {{Symbols::tachometer, Apps::Gauge}, + {Symbols::asterisk, Apps::Meter}, + {Symbols::paintbrush, Apps::Paint}, + {Symbols::none, Apps::None}, + {Symbols::none, Apps::None}, + {Symbols::none, Apps::None} + } + }; + + return std::unique_ptr<Screen>(new Screens::Tile(app, applications)); +} + +std::unique_ptr<Screen> ApplicationList::CreateScreen3() { + std::array<Screens::Tile::Applications, 6> applications { + {{"A", Apps::Meter}, + {"B", Apps::Gauge}, + {"C", Apps::Clock}, + {"D", Apps::Music}, + {"E", Apps::SysInfo}, + {"F", Apps::Brightness} + } + }; + + return std::unique_ptr<Screen>(new Screens::Tile(app, applications)); +} diff --git a/src/DisplayApp/Screens/ApplicationList.h b/src/DisplayApp/Screens/ApplicationList.h new file mode 100644 index 0000000..a1e6811 --- /dev/null +++ b/src/DisplayApp/Screens/ApplicationList.h @@ -0,0 +1,32 @@ +#pragma once + +#include <vector> +#include <Components/Ble/NimbleController.h> +#include "Screen.h" +#include "Label.h" +#include "ScreenList.h" +#include "Gauge.h" +#include "Meter.h" +#include <functional> + +namespace Pinetime { + namespace Applications { + namespace Screens { + class ApplicationList : public Screen { + public: + explicit ApplicationList(DisplayApp* app); + ~ApplicationList() override; + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; + private: + bool running = true; + + ScreenList<2> screens; + std::unique_ptr<Screen> CreateScreen1(); + std::unique_ptr<Screen> CreateScreen2(); + std::unique_ptr<Screen> CreateScreen3(); + }; + } + } +}
\ No newline at end of file diff --git a/src/DisplayApp/Screens/Clock.cpp b/src/DisplayApp/Screens/Clock.cpp index fc6441e..06fab9a 100644 --- a/src/DisplayApp/Screens/Clock.cpp +++ b/src/DisplayApp/Screens/Clock.cpp @@ -121,13 +121,12 @@ bool Clock::Refresh() { auto hour = time.hours().count(); auto minute = time.minutes().count(); - auto second = time.seconds().count(); char minutesChar[3]; - sprintf(minutesChar, "%02d", minute); + sprintf(minutesChar, "%02d", static_cast<int>(minute)); char hoursChar[3]; - sprintf(hoursChar, "%02d", hour); + sprintf(hoursChar, "%02d", static_cast<int>(hour)); char timeStr[6]; sprintf(timeStr, "%c%c:%c%c", hoursChar[0],hoursChar[1],minutesChar[0], minutesChar[1]); diff --git a/src/DisplayApp/Screens/Clock.h b/src/DisplayApp/Screens/Clock.h index e1e10bd..7363fda 100644 --- a/src/DisplayApp/Screens/Clock.h +++ b/src/DisplayApp/Screens/Clock.h @@ -57,7 +57,7 @@ namespace Pinetime { Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; uint8_t currentDay = 0; - DirtyValue<uint8_t> batteryPercentRemaining {0}; + DirtyValue<float> batteryPercentRemaining {0}; DirtyValue<bool> bleState {false}; DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; DirtyValue<uint32_t> stepCount {0}; diff --git a/src/DisplayApp/Screens/DropDownDemo.cpp b/src/DisplayApp/Screens/DropDownDemo.cpp new file mode 100644 index 0000000..735a0cc --- /dev/null +++ b/src/DisplayApp/Screens/DropDownDemo.cpp @@ -0,0 +1,64 @@ +#include <libs/lvgl/lvgl.h> +#include <libraries/log/nrf_log.h> +#include "DropDownDemo.h" +#include "../DisplayApp.h" + +using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +DropDownDemo::DropDownDemo(Pinetime::Applications::DisplayApp *app) : Screen(app) { + // Create the dropdown object, with many item, and fix its height + ddlist = lv_ddlist_create(lv_scr_act(), NULL); + lv_ddlist_set_options(ddlist, "Apple\n" + "Banana\n" + "Orange\n" + "Melon\n" + "Grape\n" + "Raspberry\n" + "A\n" + "B\n" + "C\n" + "D\n" + "E"); + lv_ddlist_set_fix_width(ddlist, 150); + lv_ddlist_set_draw_arrow(ddlist, true); + lv_ddlist_set_fix_height(ddlist, 150); + lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); +} + +DropDownDemo::~DropDownDemo() { + // Reset the touchmode + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + lv_obj_clean(lv_scr_act()); +} + +bool DropDownDemo::Refresh() { + auto* list = static_cast<lv_ddlist_ext_t *>(ddlist->ext_attr); + + // Switch touchmode to Polling if the dropdown is opened. This will allow to scroll inside the + // dropdown while it is opened. + // Disable the polling mode when the dropdown is closed to be able to handle the gestures. + if(list->opened) + app->SetTouchMode(DisplayApp::TouchModes::Polling); + else + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + return running; +} + +bool DropDownDemo::OnButtonPushed() { + running = false; + return true; +} + +bool DropDownDemo::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + // If the dropdown is opened, notify Display app that it doesn't need to handle the event + // (this will prevent displayApp from going back to the menu or clock scree). + auto* list = static_cast<lv_ddlist_ext_t *>(ddlist->ext_attr); + if(list->opened) { + return true; + } else { + return false; + } +} + diff --git a/src/DisplayApp/Screens/DropDownDemo.h b/src/DisplayApp/Screens/DropDownDemo.h new file mode 100644 index 0000000..7c75efc --- /dev/null +++ b/src/DisplayApp/Screens/DropDownDemo.h @@ -0,0 +1,29 @@ +#pragma once + +#include <cstdint> +#include "Screen.h" +#include <bits/unique_ptr.h> +#include <libs/lvgl/src/lv_core/lv_style.h> +#include <libs/lvgl/src/lv_core/lv_obj.h> + +namespace Pinetime { + namespace Applications { + namespace Screens { + + class DropDownDemo : public Screen{ + public: + DropDownDemo(DisplayApp* app); + ~DropDownDemo() override; + + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; + + private: + lv_obj_t * ddlist; + bool running = true; + bool isDropDownOpened = false; + }; + } + } +} diff --git a/src/DisplayApp/Screens/FirmwareValidation.cpp b/src/DisplayApp/Screens/FirmwareValidation.cpp new file mode 100644 index 0000000..fb2dd95 --- /dev/null +++ b/src/DisplayApp/Screens/FirmwareValidation.cpp @@ -0,0 +1,91 @@ +#include <libs/lvgl/lvgl.h> +#include "FirmwareValidation.h" +#include "../DisplayApp.h" +#include "../../Version.h" +#include "../../Components/FirmwareValidator/FirmwareValidator.h" + +using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +namespace { + static void ButtonEventHandler(lv_obj_t * obj, lv_event_t event) + { + FirmwareValidation* screen = static_cast<FirmwareValidation *>(obj->user_data); + screen->OnButtonEvent(obj, event); + } + +} + +FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp *app, + Pinetime::Controllers::FirmwareValidator &validator) + : Screen{app}, validator{validator} { + labelVersionInfo = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(labelVersionInfo, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_label_set_text(labelVersionInfo, "Version : "); + lv_label_set_align(labelVersionInfo, LV_LABEL_ALIGN_LEFT); + + + labelVersionValue = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(labelVersionValue, labelVersionInfo, LV_ALIGN_OUT_RIGHT_MID, 0, 0); + lv_label_set_recolor(labelVersionValue, true); + sprintf(version, "%ld.%ld.%ld", Version::Major(), Version::Minor(), Version::Patch()); + lv_label_set_text(labelVersionValue, version); + + labelIsValidated = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(labelIsValidated, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 50); + lv_label_set_recolor(labelIsValidated, true); + lv_label_set_long_mode(labelIsValidated, LV_LABEL_LONG_BREAK); + lv_obj_set_width(labelIsValidated, 240); + + if(validator.IsValidated()) + lv_label_set_text(labelIsValidated, "You have already\n#00ff00 validated# this firmware#"); + else { + lv_label_set_text(labelIsValidated, + "Please #00ff00 Validate# this version or\n#ff0000 Reset# to rollback to the previous version."); + + buttonValidate = lv_btn_create(lv_scr_act(), NULL); + lv_obj_align(buttonValidate, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + buttonValidate->user_data = this; + lv_obj_set_event_cb(buttonValidate, ButtonEventHandler); + + labelButtonValidate = lv_label_create(buttonValidate, NULL); + lv_label_set_recolor(labelButtonValidate, true); + lv_label_set_text(labelButtonValidate, "#00ff00 Validate#"); + + buttonReset = lv_btn_create(lv_scr_act(), NULL); + buttonReset->user_data = this; + lv_obj_align(buttonReset, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + lv_obj_set_event_cb(buttonReset, ButtonEventHandler); + + labelButtonReset = lv_label_create(buttonReset, NULL); + lv_label_set_recolor(labelButtonReset, true); + lv_label_set_text(labelButtonReset, "#ff0000 Reset#"); + } +} + + +FirmwareValidation::~FirmwareValidation() { + lv_obj_clean(lv_scr_act()); +} + +bool FirmwareValidation::Refresh() { + return running; +} + +bool FirmwareValidation::OnButtonPushed() { + running = false; + return true; +} + +void FirmwareValidation::OnButtonEvent(lv_obj_t *object, lv_event_t event) { + if(object == buttonValidate && event == LV_EVENT_PRESSED) { + validator.Validate(); + running = false; + } else if(object == buttonReset && event == LV_EVENT_PRESSED) { + validator.Reset(); + } + +} + + diff --git a/src/DisplayApp/Screens/FirmwareValidation.h b/src/DisplayApp/Screens/FirmwareValidation.h new file mode 100644 index 0000000..947f557 --- /dev/null +++ b/src/DisplayApp/Screens/FirmwareValidation.h @@ -0,0 +1,42 @@ +#pragma once + +#include <cstdint> +#include "Screen.h" +#include <bits/unique_ptr.h> +#include <libs/lvgl/src/lv_core/lv_style.h> +#include <libs/lvgl/src/lv_core/lv_obj.h> + +namespace Pinetime { + namespace Controllers { + class FirmwareValidator; + } + + namespace Applications { + namespace Screens { + + class FirmwareValidation : public Screen{ + public: + FirmwareValidation(DisplayApp* app, Pinetime::Controllers::FirmwareValidator& validator); + ~FirmwareValidation() override; + + bool Refresh() override; + bool OnButtonPushed() override; + + void OnButtonEvent(lv_obj_t *object, lv_event_t event); + + private: + Pinetime::Controllers::FirmwareValidator& validator; + + lv_obj_t* labelVersionInfo; + lv_obj_t* labelVersionValue; + char version[9]; + lv_obj_t* labelIsValidated; + lv_obj_t* buttonValidate; + lv_obj_t* labelButtonValidate; + lv_obj_t* buttonReset; + lv_obj_t* labelButtonReset; + bool running = true; + }; + } + } +} diff --git a/src/DisplayApp/Screens/Gauge.cpp b/src/DisplayApp/Screens/Gauge.cpp index 4c4cccd..fd90523 100644 --- a/src/DisplayApp/Screens/Gauge.cpp +++ b/src/DisplayApp/Screens/Gauge.cpp @@ -19,6 +19,7 @@ Gauge::Gauge(Pinetime::Applications::DisplayApp *app) : Screen(app) { style.text.color = LV_COLOR_WHITE; style.line.color = LV_COLOR_RED; /*Line color after the critical value*/ + /*Describe the color for the needles*/ needle_colors[0] = LV_COLOR_ORANGE; diff --git a/src/DisplayApp/Screens/InfiniPaint.cpp b/src/DisplayApp/Screens/InfiniPaint.cpp new file mode 100644 index 0000000..b340f5d --- /dev/null +++ b/src/DisplayApp/Screens/InfiniPaint.cpp @@ -0,0 +1,44 @@ +#include <libs/lvgl/lvgl.h> +#include <libraries/log/nrf_log.h> +#include "InfiniPaint.h" +#include "../DisplayApp.h" + +using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; + +InfiniPaint::InfiniPaint(Pinetime::Applications::DisplayApp *app, Pinetime::Components::LittleVgl& lvgl) : Screen(app), lvgl{lvgl} { + app->SetTouchMode(DisplayApp::TouchModes::Polling); + std::fill(b, b+bufferSize, LV_COLOR_WHITE); +} + +InfiniPaint::~InfiniPaint() { + // Reset the touchmode + app->SetTouchMode(DisplayApp::TouchModes::Gestures); + lv_obj_clean(lv_scr_act()); +} + +bool InfiniPaint::Refresh() { + return running; +} + +bool InfiniPaint::OnButtonPushed() { + running = false; + return true; +} + +bool InfiniPaint::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return true; +} + +bool InfiniPaint::OnTouchEvent(uint16_t x, uint16_t y) { + lv_area_t area; + area.x1 = x-(width/2); + area.y1 = y-(height/2); + area.x2 = x+(width/2)-1; + area.y2 = y+(height/2)-1; + lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None); + lvgl.FlushDisplay(&area, b); + return true; +} + diff --git a/src/DisplayApp/Screens/InfiniPaint.h b/src/DisplayApp/Screens/InfiniPaint.h new file mode 100644 index 0000000..a1592f9 --- /dev/null +++ b/src/DisplayApp/Screens/InfiniPaint.h @@ -0,0 +1,35 @@ +#pragma once + +#include <cstdint> +#include "Screen.h" +#include <bits/unique_ptr.h> +#include <libs/lvgl/src/lv_core/lv_style.h> +#include <libs/lvgl/src/lv_core/lv_obj.h> +#include <drivers/St7789.h> +#include <DisplayApp/LittleVgl.h> + +namespace Pinetime { + namespace Applications { + namespace Screens { + + class InfiniPaint : public Screen{ + public: + InfiniPaint(DisplayApp* app, Pinetime::Components::LittleVgl& lvgl); + ~InfiniPaint() override; + + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; + bool OnTouchEvent(uint16_t x, uint16_t y) override; + + private: + Pinetime::Components::LittleVgl& lvgl; + static constexpr uint16_t width = 10; + static constexpr uint16_t height = 10; + static constexpr uint16_t bufferSize = width*height; + lv_color_t b[bufferSize]; + bool running = true; + }; + } + } +} diff --git a/src/DisplayApp/Screens/Label.cpp b/src/DisplayApp/Screens/Label.cpp index ba35279..780ee88 100644 --- a/src/DisplayApp/Screens/Label.cpp +++ b/src/DisplayApp/Screens/Label.cpp @@ -3,26 +3,13 @@ using namespace Pinetime::Applications::Screens; - -Label::Label(const char* text) : text{text} { - -} - -Label::~Label() { - -} - -void Label::Refresh() { - -} - -void Label::Show() { +Label::Label(Pinetime::Applications::DisplayApp *app, const char *text) : Screen(app), text{text} { label = lv_label_create(lv_scr_act(), NULL); lv_label_set_align(label, LV_LABEL_ALIGN_LEFT); lv_obj_set_size(label, 240, 240); lv_label_set_text(label, text); } -void Label::Hide() { +Label::~Label() { lv_obj_clean(lv_scr_act()); } diff --git a/src/DisplayApp/Screens/Label.h b/src/DisplayApp/Screens/Label.h index b73540f..3e7b379 100644 --- a/src/DisplayApp/Screens/Label.h +++ b/src/DisplayApp/Screens/Label.h @@ -2,19 +2,18 @@ #include <vector> #include "Screen.h" +#include <lvgl/lvgl.h> namespace Pinetime { namespace Applications { namespace Screens { - class Label { + + class Label : public Screen { public: - Label() = default; - explicit Label(const char* text); - ~Label(); - void Refresh(); + Label(DisplayApp* app, const char* text); + ~Label() override; + bool Refresh() override {return false;} - void Hide(); - void Show(); private: lv_obj_t * label = nullptr; const char* text = nullptr; diff --git a/src/DisplayApp/Screens/Message.cpp b/src/DisplayApp/Screens/Message.cpp deleted file mode 100644 index b83cb75..0000000 --- a/src/DisplayApp/Screens/Message.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include <cstdio> -#include <libs/date/includes/date/date.h> -#include <Components/DateTime/DateTimeController.h> -#include <Version.h> -#include <libs/lvgl/src/lv_core/lv_obj.h> -#include <libs/lvgl/src/lv_font/lv_font.h> -#include <libs/lvgl/lvgl.h> -#include <libraries/log/nrf_log.h> -#include "Message.h" -#include <DisplayApp/DisplayApp.h> - - -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) { - Message* screen = static_cast<Message *>(obj->user_data); - screen->OnObjectEvent(obj, event); -} - -Message::Message(DisplayApp* app) : Screen(app) { - - backgroundLabel = lv_label_create(lv_scr_act(), NULL); - backgroundLabel->user_data = this; - - 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, ""); - - 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_text(label, "Hello!"); - - labelClick = lv_label_create(lv_scr_act(), NULL); - 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()); -} - -bool Message::Refresh() { - if(previousClickCount != clickCount) { - lv_label_set_text_fmt(labelClick, "%d", clickCount); - previousClickCount = clickCount; - } - - return running; -} - -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"); - } -} - -bool Message::OnButtonPushed() { - running = false; - return true; -} diff --git a/src/DisplayApp/Screens/Message.h b/src/DisplayApp/Screens/Message.h deleted file mode 100644 index 3ace66f..0000000 --- a/src/DisplayApp/Screens/Message.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include <cstdint> -#include "Screen.h" -#include <bits/unique_ptr.h> -#include <lvgl/src/lv_core/lv_style.h> - -namespace Pinetime { - namespace Applications { - namespace Screens { - class Message : public Screen{ - public: - explicit Message(DisplayApp* app); - ~Message() override; - bool Refresh() override; - bool OnButtonPushed(); - void OnObjectEvent(lv_obj_t* obj, lv_event_t event); - - private: - lv_obj_t * label; - lv_obj_t* backgroundLabel; - lv_obj_t * button; - lv_obj_t * labelClick; - - uint32_t clickCount = 0 ; - uint32_t previousClickCount = 0; - bool running = true; - }; - } - } -} diff --git a/src/DisplayApp/Screens/Music.cpp b/src/DisplayApp/Screens/Music.cpp new file mode 100644 index 0000000..9b7d198 --- /dev/null +++ b/src/DisplayApp/Screens/Music.cpp @@ -0,0 +1,125 @@ +#include <libs/lvgl/lvgl.h> +#include "Music.h" + +using namespace Pinetime::Applications::Screens; +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) +{ + Music* screen = static_cast<Music *>(obj->user_data); + screen->OnObjectEvent(obj, event); +} + +Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::MusicService &music) : Screen(app), musicService(music) { + lv_obj_t * label; + + btnVolDown = lv_btn_create(lv_scr_act(), NULL); + btnVolDown->user_data = this; + lv_obj_set_event_cb(btnVolDown, event_handler); + lv_obj_align(btnVolDown, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10); + label = lv_label_create(btnVolDown, NULL); + lv_label_set_text(label, "v-"); + + btnVolUp = lv_btn_create(lv_scr_act(), NULL); + btnVolUp->user_data = this; + lv_obj_set_event_cb(btnVolUp, event_handler); + lv_obj_align(btnVolUp, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10); + label = lv_label_create(btnVolUp, NULL); + lv_label_set_text(label, "v+"); + + btnPrev = lv_btn_create(lv_scr_act(), NULL); + btnPrev->user_data = this; + lv_obj_set_event_cb(btnPrev, event_handler); + lv_obj_set_size(btnPrev, LV_HOR_RES / 4, LV_VER_RES / 4); + lv_obj_align(btnPrev, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 10,-10); + label = lv_label_create(btnPrev, NULL); + lv_label_set_text(label, "<<"); + + btnPlayPause = lv_btn_create(lv_scr_act(), NULL); + btnPlayPause->user_data = this; + lv_obj_set_event_cb(btnPlayPause, event_handler); + lv_obj_set_size(btnPlayPause, LV_HOR_RES / 4, LV_VER_RES / 4); + lv_obj_align(btnPlayPause, NULL, LV_ALIGN_IN_BOTTOM_MID, 0,-10); + txtPlayPause = lv_label_create(btnPlayPause, NULL); + lv_label_set_text(txtPlayPause, ">"); + + btnNext = lv_btn_create(lv_scr_act(), NULL); + btnNext->user_data = this; + lv_obj_set_event_cb(btnNext, event_handler); + lv_obj_set_size(btnNext, LV_HOR_RES / 4, LV_VER_RES / 4); + lv_obj_align(btnNext, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, -10,-10); + label = lv_label_create(btnNext, NULL); + lv_label_set_text(label, ">>"); + + txtArtist = lv_label_create(lv_scr_act(), NULL); + lv_label_set_long_mode(txtArtist, LV_LABEL_LONG_SROLL); + lv_obj_align(txtArtist, NULL, LV_ALIGN_IN_LEFT_MID, 0,-20); + lv_label_set_text(txtArtist, "Artist Name"); + lv_label_set_align(txtArtist, LV_LABEL_ALIGN_CENTER); + lv_obj_set_width(txtArtist, LV_HOR_RES); + + txtTrack = lv_label_create(lv_scr_act(), NULL); + lv_label_set_long_mode(txtTrack, LV_LABEL_LONG_DOT); + lv_obj_align(txtTrack, NULL, LV_ALIGN_IN_LEFT_MID, 0,20); + lv_label_set_text(txtTrack, "This is a very long track name"); + lv_label_set_align(txtTrack, LV_LABEL_ALIGN_CENTER); + lv_obj_set_width(txtTrack, LV_HOR_RES); + + musicService.event(Controllers::MusicService::EVENT_MUSIC_OPEN); +} + +Music::~Music() { + lv_obj_clean(lv_scr_act()); +} + +bool Music::OnButtonPushed() { + running = false; + return true; +} + +bool Music::Refresh() { + + if (m_artist != musicService.artist()) { + m_artist = musicService.artist(); + lv_label_set_text(txtArtist, m_artist.data()); + } + if (m_track != musicService.track()) { + m_track = musicService.track(); + lv_label_set_text(txtTrack, m_track.data()); + } + if (m_album != musicService.album()) { + m_album = musicService.album(); + } + if (m_status != musicService.status()) { + m_status = musicService.status(); + } + if (m_status == Pinetime::Controllers::MusicService::STATUS_MUSIC_PLAYING) { + lv_label_set_text(txtPlayPause, "||"); + } else { + lv_label_set_text(txtPlayPause, ">"); + } + + return running; +} + +void Music::OnObjectEvent(lv_obj_t* obj, lv_event_t event) +{ + if (event == LV_EVENT_CLICKED) { + if (obj == btnVolDown) { + musicService.event(Controllers::MusicService::EVENT_MUSIC_VOLDOWN); + } else if (obj == btnVolUp) { + musicService.event(Controllers::MusicService::EVENT_MUSIC_VOLUP); + } else if (obj == btnPrev) { + musicService.event(Controllers::MusicService::EVENT_MUSIC_PREV); + } else if (obj == btnPlayPause) { + if (m_status == Pinetime::Controllers::MusicService::STATUS_MUSIC_PLAYING) { + musicService.event(Controllers::MusicService::EVENT_MUSIC_PAUSE); + } else { + musicService.event(Controllers::MusicService::EVENT_MUSIC_PLAY); + } + } else if (obj == btnNext) { + musicService.event(Controllers::MusicService::EVENT_MUSIC_NEXT); + } + } +} diff --git a/src/DisplayApp/Screens/Music.h b/src/DisplayApp/Screens/Music.h new file mode 100644 index 0000000..95cac0f --- /dev/null +++ b/src/DisplayApp/Screens/Music.h @@ -0,0 +1,49 @@ +#pragma once + +#include <cstdint> +#include <chrono> +#include <Components/Gfx/Gfx.h> +#include "Screen.h" +#include <bits/unique_ptr.h> +#include <libs/lvgl/src/lv_core/lv_style.h> +#include <libs/lvgl/src/lv_core/lv_obj.h> +#include <Components/Battery/BatteryController.h> +#include <Components/Ble/BleController.h> +#include "../../Version.h" +#include <Components/Ble/MusicService.h> +#include <string> + +namespace Pinetime { + namespace Applications { + namespace Screens { + + class Music : public Screen{ + public: + Music(DisplayApp* app, Pinetime::Controllers::MusicService &music); + ~Music() override; + + bool Refresh() override; + bool OnButtonPushed() override; + + void OnObjectEvent(lv_obj_t* obj, lv_event_t event); + + private: + lv_obj_t * btnPrev; + lv_obj_t * btnPlayPause; + lv_obj_t * btnNext; + lv_obj_t * btnVolDown; + lv_obj_t * btnVolUp; + lv_obj_t * txtArtist; + lv_obj_t * txtTrack; + lv_obj_t * txtPlayPause; + + bool running = true; + Pinetime::Controllers::MusicService &musicService; + std::string m_artist; + std::string m_album; + std::string m_track; + unsigned char m_status; + }; + } + } +} diff --git a/src/DisplayApp/Screens/Screen.h b/src/DisplayApp/Screens/Screen.h index d890231..dbf81a4 100644 --- a/src/DisplayApp/Screens/Screen.h +++ b/src/DisplayApp/Screens/Screen.h @@ -1,4 +1,6 @@ #pragma once + +#include <cstdint> #include "../TouchEvents.h" namespace Pinetime { @@ -18,6 +20,7 @@ namespace Pinetime { // Return false if the event hasn't been handled by the app, true if it has been handled virtual bool OnTouchEvent(TouchEvents event) { return false; } + virtual bool OnTouchEvent(uint16_t x, uint16_t y) { return false; } protected: DisplayApp* app; diff --git a/src/DisplayApp/Screens/ScreenList.h b/src/DisplayApp/Screens/ScreenList.h index b0ee016..d873336 100644 --- a/src/DisplayApp/Screens/ScreenList.h +++ b/src/DisplayApp/Screens/ScreenList.h @@ -2,40 +2,64 @@ #include <vector> #include <Components/Ble/NimbleController.h> +#include <functional> #include "Screen.h" #include "Label.h" namespace Pinetime { namespace Applications { namespace Screens { + template <size_t N> class ScreenList : public Screen { public: - explicit ScreenList(DisplayApp* app, - Pinetime::Controllers::DateTime& dateTimeController, - Pinetime::Controllers::Battery& batteryController, - Pinetime::Controllers::BrightnessController& brightnessController, - Pinetime::Controllers::Ble& bleController, - Pinetime::Drivers::WatchdogView& watchdog); - ~ScreenList() override; - bool Refresh() override; - bool OnButtonPushed() override; - bool OnTouchEvent(TouchEvents event) override; - private: - bool running = true; - uint8_t screenIndex = 0; + ScreenList(DisplayApp* app, std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens) + : Screen(app), screens{std::move(screens)}, current{this->screens[0]()} { + + } + + ~ScreenList() override { - // TODO choose another container without dynamic alloc - std::vector<Screens::Label> screens; - Pinetime::Controllers::DateTime& dateTimeController; - Pinetime::Controllers::Battery& batteryController; - Pinetime::Controllers::BrightnessController& brightnessController; - Pinetime::Controllers::Ble& bleController; - Pinetime::Drivers::WatchdogView& watchdog; + } + bool Refresh() override { + running = current->Refresh(); + return running; + } - char t1[200]; - char t2[200]; - char t3[30]; + bool OnButtonPushed() override { + running = false; + return true; + } + + bool OnTouchEvent(TouchEvents event) override { + switch (event) { + case TouchEvents::SwipeDown: + if (screenIndex > 0) { + current.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + screenIndex--; + current = screens[screenIndex](); + } + return true; + case TouchEvents::SwipeUp: + if (screenIndex < screens.size() - 1) { + current.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + screenIndex++; + current = screens[screenIndex](); + } + return true; + default: + return false; + } + return false; + } + + private: + bool running = true; + uint8_t screenIndex = 0; + std::array<std::function<std::unique_ptr<Screen>()>, N> screens; + std::unique_ptr<Screen> current; }; } } diff --git a/src/DisplayApp/Screens/Symbols.h b/src/DisplayApp/Screens/Symbols.h index 3104db8..aeea324 100644 --- a/src/DisplayApp/Screens/Symbols.h +++ b/src/DisplayApp/Screens/Symbols.h @@ -4,20 +4,26 @@ namespace Pinetime { namespace Applications { namespace Screens { namespace Symbols { - static constexpr char* batteryFull = "\xEF\x89\x80"; - static constexpr char* batteryEmpty = "\xEF\x89\x84"; - static constexpr char* batteryThreeQuarter = "\xEF\x89\x81"; - static constexpr char* batteryHalf = "\xEF\x89\x82"; - static constexpr char* batteryOneQuarter = "\xEF\x89\x83"; - static constexpr char* heartBeat = "\xEF\x88\x9E"; - static constexpr char* bluetoothFull = "\xEF\x8A\x93"; - static constexpr char* bluetooth = "\xEF\x8A\x94"; - static constexpr char* plug = "\xEF\x87\xA6"; - static constexpr char* shoe = "\xEF\x95\x8B"; - static constexpr char* clock = "\xEF\x80\x97"; - static constexpr char* info = "\xEF\x84\xA9"; - static constexpr char* list = "\xEF\x80\xBA"; - static constexpr char* sun = "\xEF\x86\x85"; + static constexpr const char* none = ""; + static constexpr const char* batteryFull = "\xEF\x89\x80"; + static constexpr const char* batteryEmpty = "\xEF\x89\x84"; + static constexpr const char* batteryThreeQuarter = "\xEF\x89\x81"; + static constexpr const char* batteryHalf = "\xEF\x89\x82"; + static constexpr const char* batteryOneQuarter = "\xEF\x89\x83"; + static constexpr const char* heartBeat = "\xEF\x88\x9E"; + static constexpr const char* bluetoothFull = "\xEF\x8A\x93"; + static constexpr const char* bluetooth = "\xEF\x8A\x94"; + static constexpr const char* plug = "\xEF\x87\xA6"; + static constexpr const char* shoe = "\xEF\x95\x8B"; + static constexpr const char* clock = "\xEF\x80\x97"; + static constexpr const char* info = "\xEF\x84\xA9"; + static constexpr const char* list = "\xEF\x80\xBA"; + static constexpr const char* sun = "\xEF\x86\x85"; + static constexpr const char* check = "\xEF\x95\xA0"; + static constexpr const char* music = "\xEF\x80\x81"; + static constexpr const char* tachometer = "\xEF\x8F\xBD"; + static constexpr const char* asterisk = "\xEF\x81\xA9"; + static constexpr const char* paintbrush = "\xEF\x87\xBC"; } } } diff --git a/src/DisplayApp/Screens/ScreenList.cpp b/src/DisplayApp/Screens/SystemInfo.cpp index 754d5f7..fcafcf7 100644 --- a/src/DisplayApp/Screens/ScreenList.cpp +++ b/src/DisplayApp/Screens/SystemInfo.cpp @@ -1,40 +1,61 @@ #include <libs/lvgl/lvgl.h> #include <DisplayApp/DisplayApp.h> -#include "ScreenList.h" +#include <functional> +#include "SystemInfo.h" #include "../../Version.h" +#include "Tile.h" using namespace Pinetime::Applications::Screens; -// TODO this class must be improved to receive the list of "sub screens" via pointer or -// move operation. -// It should accept many type of "sub screen" (it only supports Label for now). -// The number of sub screen it supports must be dynamic. -ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, - Pinetime::Controllers::DateTime &dateTimeController, - Pinetime::Controllers::Battery& batteryController, - Pinetime::Controllers::BrightnessController& brightnessController, +SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp *app, + Pinetime::Controllers::DateTime &dateTimeController, + Pinetime::Controllers::Battery& batteryController, + Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::Ble& bleController, - Pinetime::Drivers::WatchdogView& watchdog) : + Pinetime::Drivers::WatchdogView& watchdog) : Screen(app), dateTimeController{dateTimeController}, batteryController{batteryController}, - brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog} { - screens.reserve(3); + brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog}, + screens{app, { + [this]() -> std::unique_ptr<Screen> { return CreateScreen1(); }, + [this]() -> std::unique_ptr<Screen> { return CreateScreen2(); }, + [this]() -> std::unique_ptr<Screen> { return CreateScreen3(); } + } + } {} - // TODO all of this is far too heavy (string processing). This should be improved. - // TODO the info (battery, time,...) should be updated in the Refresh method. +SystemInfo::~SystemInfo() { + lv_obj_clean(lv_scr_act()); +} + +bool SystemInfo::Refresh() { + screens.Refresh(); + return running; +} - auto batteryPercent = static_cast<int16_t>(batteryController.PercentRemaining()); - if(batteryPercent > 100) batteryPercent = 100; - else if(batteryPercent < 0) batteryPercent = 0; +bool SystemInfo::OnButtonPushed() { + running = false; + return true; +} + +bool SystemInfo::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); +} + +std::unique_ptr<Screen> SystemInfo::CreateScreen1() { + auto batteryPercentF = batteryController.PercentRemaining(); + uint16_t batteryPercent = 0; + if(batteryPercentF > 100.0f) batteryPercent = 100; + else if(batteryPercentF < 0.0f) batteryPercent = 0; uint8_t brightness = 0; switch(brightnessController.Level()) { + case Controllers::BrightnessController::Levels::Off: brightness = 0; break; case Controllers::BrightnessController::Levels::Low: brightness = 1; break; case Controllers::BrightnessController::Levels::Medium: brightness = 2; break; case Controllers::BrightnessController::Levels::High: brightness = 3; break; } - auto resetReason = [&watchdog]() { + auto resetReason = [this]() { switch (watchdog.ResetReason()) { case Drivers::Watchdog::ResetReasons::Watchdog: return "wtdg"; case Drivers::Watchdog::ResetReasons::HardReset: return "hardr"; @@ -63,7 +84,7 @@ ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, // TODO handle more than 100 days of uptime sprintf(t1, "Pinetime\n" - "Version:%d.%d.%d\n" + "Version:%ld.%ld.%ld\n" "Build: %s\n" " %s\n" "Date: %02d/%02d/%04d\n" @@ -72,68 +93,24 @@ ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, "Battery: %d%%\n" "Backlight: %d/3\n" "Last reset: %s\n", - Version::Major(), Version::Minor(), Version::Patch(), - __DATE__, __TIME__, - dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(), - dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(), - uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds, - batteryPercent, brightness, resetReason); - - screens.emplace_back(t1); + Version::Major(), Version::Minor(), Version::Patch(), + __DATE__, __TIME__, + dateTimeController.Day(), static_cast<uint8_t>(dateTimeController.Month()), dateTimeController.Year(), + dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(), + uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds, + batteryPercent, brightness, resetReason); + + return std::unique_ptr<Screen>(new Screens::Label(app, t1)); +} +std::unique_ptr<Screen> SystemInfo::CreateScreen2() { auto& bleAddr = bleController.Address(); sprintf(t2, "BLE MAC: \n %2x:%2x:%2x:%2x:%2x:%2x", bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]); - screens.emplace_back(t2); - - strncpy(t3, "Hello from\nthe developper!", 27); - - screens.emplace_back(t3); - - auto &screen = screens[screenIndex]; - screen.Show(); -} - -ScreenList::~ScreenList() { - lv_obj_clean(lv_scr_act()); + return std::unique_ptr<Screen>(new Screens::Label(app, t2)); } -bool ScreenList::Refresh() { - auto &screen = screens[screenIndex]; - screen.Refresh(); - - return running; -} - -bool ScreenList::OnButtonPushed() { - running = false; - return true; -} - -bool ScreenList::OnTouchEvent(Pinetime::Applications::TouchEvents event) { - switch (event) { - case TouchEvents::SwipeDown: - if (screenIndex > 0) { - app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - auto &oldScreen = screens[screenIndex]; - oldScreen.Hide(); - screenIndex--; - auto &newScreen = screens[screenIndex]; - newScreen.Show(); - } - return true; - case TouchEvents::SwipeUp: - app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - if (screenIndex < screens.size() - 1) { - auto &oldScreen = screens[screenIndex]; - oldScreen.Hide(); - screenIndex++; - auto &newScreen = screens[screenIndex]; - newScreen.Show(); - } - return true; - default: - return false; - } - return false; +std::unique_ptr<Screen> SystemInfo::CreateScreen3() { + strncpy(t3, "Hello from\nthe developper!", 27); + return std::unique_ptr<Screen>(new Screens::Label(app, t3)); } diff --git a/src/DisplayApp/Screens/SystemInfo.h b/src/DisplayApp/Screens/SystemInfo.h new file mode 100644 index 0000000..ac8abae --- /dev/null +++ b/src/DisplayApp/Screens/SystemInfo.h @@ -0,0 +1,47 @@ +#pragma once + +#include <vector> +#include <Components/Ble/NimbleController.h> +#include "Screen.h" +#include "Label.h" +#include "ScreenList.h" +#include "Gauge.h" +#include "Meter.h" +#include <functional> + +namespace Pinetime { + namespace Applications { + namespace Screens { + class SystemInfo : public Screen { + public: + explicit SystemInfo(DisplayApp* app, + Pinetime::Controllers::DateTime& dateTimeController, + Pinetime::Controllers::Battery& batteryController, + Pinetime::Controllers::BrightnessController& brightnessController, + Pinetime::Controllers::Ble& bleController, + Pinetime::Drivers::WatchdogView& watchdog); + ~SystemInfo() override; + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(TouchEvents event) override; + private: + bool running = true; + + Pinetime::Controllers::DateTime& dateTimeController; + Pinetime::Controllers::Battery& batteryController; + Pinetime::Controllers::BrightnessController& brightnessController; + Pinetime::Controllers::Ble& bleController; + Pinetime::Drivers::WatchdogView& watchdog; + + char t1[200]; + char t2[200]; + char t3[30]; + + ScreenList<3> screens; + std::unique_ptr<Screen> CreateScreen1(); + std::unique_ptr<Screen> CreateScreen2(); + std::unique_ptr<Screen> CreateScreen3(); + }; + } + } +}
\ No newline at end of file diff --git a/src/DisplayApp/Screens/Tile.cpp b/src/DisplayApp/Screens/Tile.cpp index 61e3c01..1447d78 100644 --- a/src/DisplayApp/Screens/Tile.cpp +++ b/src/DisplayApp/Screens/Tile.cpp @@ -17,9 +17,16 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { screen->OnObjectEvent(obj, event, eventData); } -static const char * btnm_map1[] = {Symbols::heartBeat, Symbols::shoe, Symbols::clock, "\n", Symbols::info, Symbols::list, Symbols::sun, ""}; - -Tile::Tile(DisplayApp* app) : Screen(app) { +Tile::Tile(DisplayApp* app, std::array<Applications, 6>& applications) : Screen(app) { + for(int i = 0, appIndex = 0; i < 8; i++) { + if(i == 3) btnm_map1[i] = "\n"; + else if(i == 7) btnm_map1[i] = ""; + else { + btnm_map1[i] = applications[appIndex].icon; + apps[appIndex] = applications[appIndex].application; + appIndex++; + } + } modal.reset(new Modal(app)); btnm1 = lv_btnm_create(lv_scr_act(), NULL); @@ -39,63 +46,16 @@ bool Tile::Refresh() { } void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) { - auto* tile = static_cast<Tile*>(obj->user_data); if(event == LV_EVENT_VALUE_CHANGED) { - switch(buttonId) { - case 0: - tile->StartMeterApp(); - break; - case 1: - tile->StartGaugeApp(); - break; - case 2: - tile->StartClockApp(); - break; - case 3: - char versionStr[20]; - sprintf(versionStr, "VERSION: %d.%d.%d", Version::Major(), Version::Minor(), Version::Patch()); - modal->Show(versionStr); - break; - case 4: - tile->StartSysInfoApp(); - break; - case 5: - tile->StartBrightnessApp(); - - break; - } - clickCount++; + app->StartApp(apps[buttonId]); + running = false; } } bool Tile::OnButtonPushed() { - app->StartApp(DisplayApp::Apps::Clock); + app->StartApp(Apps::Clock); running = false; return true; } -void Tile::StartClockApp() { - app->StartApp(DisplayApp::Apps::Clock); - running = false; -} - -void Tile::StartSysInfoApp() { - app->StartApp(DisplayApp::Apps::SysInfo); - running = false; -} - -void Tile::StartBrightnessApp() { - app->StartApp(DisplayApp::Apps::Brightness); - running = false; -} - -void Tile::StartMeterApp() { - app->StartApp(DisplayApp::Apps::Meter); - running = false; -} - -void Tile::StartGaugeApp() { - app->StartApp(DisplayApp::Apps::Gauge); - running = false; -} diff --git a/src/DisplayApp/Screens/Tile.h b/src/DisplayApp/Screens/Tile.h index a04b58a..3136d89 100644 --- a/src/DisplayApp/Screens/Tile.h +++ b/src/DisplayApp/Screens/Tile.h @@ -5,13 +5,19 @@ #include <bits/unique_ptr.h> #include "Modal.h" #include <lvgl/src/lv_core/lv_style.h> +#include <DisplayApp/Apps.h> namespace Pinetime { namespace Applications { namespace Screens { class Tile : public Screen { public: - explicit Tile(DisplayApp* app); + struct Applications { + const char* icon; + Pinetime::Applications::Apps application; + }; + + explicit Tile(DisplayApp* app, std::array<Applications, 6>& applications); ~Tile() override; bool Refresh() override; @@ -20,40 +26,13 @@ namespace Pinetime { void OnObjectEvent(lv_obj_t* obj, lv_event_t event, uint32_t buttonId); private: - - lv_style_t* labelRelStyle; - lv_style_t* labelPrStyle; - 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; - void StartClockApp(); - void StartSysInfoApp(); - void StartMeterApp(); - void StartGaugeApp(); bool running = true; std::unique_ptr<Modal> modal; - void StartBrightnessApp(); + + const char* btnm_map1[8]; + Pinetime::Applications::Apps apps[6]; }; } } |
