diff options
Diffstat (limited to 'src/displayapp')
24 files changed, 446 insertions, 131 deletions
diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 59b45ce2..c77bd29f 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -25,6 +25,8 @@ namespace Pinetime { Metronome, Motion, Steps, + Weather, + PassKey, QuickSettings, Settings, SettingWatchFace, diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 1819eed9..ff70363a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -29,6 +29,7 @@ #include "displayapp/screens/FlashLight.h" #include "displayapp/screens/BatteryInfo.h" #include "displayapp/screens/Steps.h" +#include "displayapp/screens/PassKey.h" #include "displayapp/screens/Error.h" #include "drivers/Cst816s.h" @@ -213,6 +214,9 @@ void DisplayApp::Refresh() { } else { LoadApp(Apps::Alarm, DisplayApp::FullRefreshDirections::None); } + case Messages::ShowPairingKey: + LoadApp(Apps::PassKey, DisplayApp::FullRefreshDirections::Up); + break; case Messages::TouchEvent: { if (state != States::Running) { break; @@ -350,6 +354,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); break; + case Apps::PassKey: + currentScreen = std::make_unique<Screens::PassKey>(this, bleController.GetPairingKey()); + ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; + case Apps::Notifications: currentScreen = std::make_unique<Screens::Notifications>( this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Normal); @@ -492,8 +501,9 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) { } void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) { - if (systemTask != nullptr) + if (systemTask != nullptr) { systemTask->PushMessage(message); + } } void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index 29e09eb3..b22d6c3c 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -19,6 +19,7 @@ namespace Pinetime { UpdateTimeOut, DimScreen, RestoreBrightness, + ShowPairingKey, AlarmTriggered }; } diff --git a/src/displayapp/lv_pinetime_theme.c b/src/displayapp/lv_pinetime_theme.c index 1780e64b..b74b2fd7 100644 --- a/src/displayapp/lv_pinetime_theme.c +++ b/src/displayapp/lv_pinetime_theme.c @@ -119,7 +119,6 @@ static void basic_init(void) { lv_style_set_bg_color(&style_btn, LV_STATE_DISABLED | LV_STATE_CHECKED, lv_color_hex3(0x888)); lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 0); - lv_style_set_border_opa(&style_btn, LV_STATE_CHECKED, LV_OPA_TRANSP); lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, lv_color_hex(0xffffff)); lv_style_set_text_color(&style_btn, LV_STATE_CHECKED, lv_color_hex(0xffffff)); diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 772e5d45..537ac0e0 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -36,7 +36,7 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController) alarmHours = alarmController.Hours(); alarmMinutes = alarmController.Minutes(); - lv_label_set_text_fmt(time, "%02lu:%02lu", alarmHours, alarmMinutes); + lv_label_set_text_fmt(time, "%02hhu:%02hhu", alarmHours, alarmMinutes); lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -25); @@ -223,7 +223,7 @@ void Alarm::ShowInfo() { auto secToAlarm = timeToAlarm % 60; lv_label_set_text_fmt( - txtMessage, "Time to\nalarm:\n%2d Days\n%2d Hours\n%2d Minutes\n%2d Seconds", daysToAlarm, hrsToAlarm, minToAlarm, secToAlarm); + txtMessage, "Time to\nalarm:\n%2lu Days\n%2lu Hours\n%2lu Minutes\n%2lu Seconds", daysToAlarm, hrsToAlarm, minToAlarm, secToAlarm); } else { lv_label_set_text(txtMessage, "Alarm\nis not\nset."); } diff --git a/src/displayapp/screens/FirmwareValidation.cpp b/src/displayapp/screens/FirmwareValidation.cpp index ea417135..c7a5b27e 100644 --- a/src/displayapp/screens/FirmwareValidation.cpp +++ b/src/displayapp/screens/FirmwareValidation.cpp @@ -18,7 +18,7 @@ FirmwareValidation::FirmwareValidation(Pinetime::Applications::DisplayApp* app, : Screen {app}, validator {validator} { labelVersion = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(labelVersion, - "Version : %d.%d.%d\n" + "Version : %lu.%lu.%lu\n" "ShortRef : %s", Version::Major(), Version::Minor(), diff --git a/src/displayapp/screens/PassKey.cpp b/src/displayapp/screens/PassKey.cpp new file mode 100644 index 00000000..9e43a541 --- /dev/null +++ b/src/displayapp/screens/PassKey.cpp @@ -0,0 +1,24 @@ +#include "PassKey.h" +#include "displayapp/DisplayApp.h" + +using namespace Pinetime::Applications::Screens; + +PassKey::PassKey(Pinetime::Applications::DisplayApp* app, uint32_t key) : Screen(app) { + passkeyLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(passkeyLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFF00)); + lv_obj_set_style_local_text_font(passkeyLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(passkeyLabel, "%06u", key); + lv_obj_align(passkeyLabel, nullptr, LV_ALIGN_CENTER, 0, -20); + + backgroundLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_click(backgroundLabel, true); + 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, ""); +} + +PassKey::~PassKey() { + lv_obj_clean(lv_scr_act()); +} + diff --git a/src/displayapp/screens/PassKey.h b/src/displayapp/screens/PassKey.h new file mode 100644 index 00000000..16e72a3c --- /dev/null +++ b/src/displayapp/screens/PassKey.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Screen.h" +#include <lvgl/lvgl.h> + +namespace Pinetime { + namespace Applications { + namespace Screens { + + class PassKey : public Screen { + public: + PassKey(DisplayApp* app, uint32_t key); + ~PassKey() override; + + private: + lv_obj_t* passkeyLabel; + lv_obj_t* backgroundLabel; + }; + } + } +} diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index fae3c4ab..b2b972dc 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -71,19 +71,19 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorBG())); lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_size(timebar, 200, 240); - lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 5, 0); + lv_obj_align(timebar, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); // Display the time timeDD1 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorTime())); - lv_label_set_text(timeDD1, "12"); + lv_label_set_text(timeDD1, "00"); lv_obj_align(timeDD1, timebar, LV_ALIGN_IN_TOP_MID, 5, 5); timeDD2 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &open_sans_light); lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorTime())); - lv_label_set_text(timeDD2, "34"); + lv_label_set_text(timeDD2, "00"); lv_obj_align(timeDD2, timebar, LV_ALIGN_IN_BOTTOM_MID, 5, -5); timeAMPM = lv_label_create(lv_scr_act(), nullptr); @@ -107,12 +107,12 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_set_auto_realign(batteryIcon, true); bleIcon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - lv_obj_align(bleIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 25); + lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_label_set_text(bleIcon, ""); notificationIcon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 50); + lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_label_set_text(notificationIcon, ""); // Calendar icon calendarOuter = lv_obj_create(lv_scr_act(), nullptr); @@ -342,6 +342,17 @@ void PineTimeStyle::SetBatteryIcon() { lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); } +void PineTimeStyle::AlignIcons() { + if (notificationState.Get() && bleState.Get()) { + lv_obj_align(bleIcon, sidebar, LV_ALIGN_IN_TOP_MID, 8, 25); + lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, -8, 25); + } else if (notificationState.Get() && !bleState.Get()) { + lv_obj_align(notificationIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 25); + } else { + lv_obj_align(bleIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 25); + } +} + void PineTimeStyle::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { @@ -361,13 +372,13 @@ void PineTimeStyle::Refresh() { bleState = bleController.IsConnected(); if (bleState.IsUpdated()) { lv_label_set_text(bleIcon, BleIcon::GetIcon(bleState.Get())); - lv_obj_realign(bleIcon); + AlignIcons(); } notificationState = notificatioManager.AreNewNotificationsAvailable(); if (notificationState.IsUpdated()) { lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); - lv_obj_realign(notificationIcon); + AlignIcons(); } currentDateTime = dateTimeController.CurrentDateTime(); diff --git a/src/displayapp/screens/PineTimeStyle.h b/src/displayapp/screens/PineTimeStyle.h index c6436887..df8b7d5a 100644 --- a/src/displayapp/screens/PineTimeStyle.h +++ b/src/displayapp/screens/PineTimeStyle.h @@ -99,6 +99,7 @@ namespace Pinetime { void SetBatteryIcon(); void CloseMenu(); + void AlignIcons(); lv_task_t* taskRefresh; }; diff --git a/src/displayapp/screens/Styles.cpp b/src/displayapp/screens/Styles.cpp new file mode 100644 index 00000000..7f43fb99 --- /dev/null +++ b/src/displayapp/screens/Styles.cpp @@ -0,0 +1,8 @@ +#include "Styles.h" + +void Pinetime::Applications::Screens::SetRadioButtonStyle(lv_obj_t* checkbox) { + lv_obj_set_style_local_radius(checkbox, LV_CHECKBOX_PART_BULLET, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); + lv_obj_set_style_local_border_width(checkbox, LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, 9); + lv_obj_set_style_local_border_color(checkbox, LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_GREEN); + lv_obj_set_style_local_bg_color(checkbox, LV_CHECKBOX_PART_BULLET, LV_STATE_CHECKED, LV_COLOR_WHITE); +} diff --git a/src/displayapp/screens/Styles.h b/src/displayapp/screens/Styles.h new file mode 100644 index 00000000..a5fbb9f6 --- /dev/null +++ b/src/displayapp/screens/Styles.h @@ -0,0 +1,9 @@ +#include <lvgl/lvgl.h> + +namespace Pinetime { + namespace Applications { + namespace Screens { + void SetRadioButtonStyle(lv_obj_t* checkbox); + } + } +} diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index c363e2dd..e0138f86 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -1,3 +1,5 @@ +#include <FreeRTOS.h> +#include <task.h> #include "displayapp/screens/SystemInfo.h" #include <lvgl/lvgl.h> #include "displayapp/DisplayApp.h" @@ -41,8 +43,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app, brightnessController {brightnessController}, bleController {bleController}, watchdog {watchdog}, - motionController{motionController}, - touchPanel{touchPanel}, + motionController {motionController}, + touchPanel {touchPanel}, screens {app, 0, {[this]() -> std::unique_ptr<Screen> { @@ -182,7 +184,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() { " #444444 used# %d (%d%%)\n" " #444444 max used# %lu\n" " #444444 frag# %d%%\n" - " #444444 free# %d", + " #444444 free# %d", bleAddr[5], bleAddr[4], bleAddr[3], @@ -274,4 +276,4 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen5() { lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); return std::make_unique<Screens::Label>(4, 5, app, label); -} +}
\ No newline at end of file diff --git a/src/displayapp/screens/Twos.cpp b/src/displayapp/screens/Twos.cpp index a1f0ba25..b15332f1 100644 --- a/src/displayapp/screens/Twos.cpp +++ b/src/displayapp/screens/Twos.cpp @@ -129,7 +129,7 @@ bool Twos::placeNewTile() { return true; } -bool Twos::tryMerge(Tile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol) { +bool Twos::tryMerge(TwosTile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol) { if ((grid[newRow][newCol].value == grid[oldRow][oldCol].value)) { if ((newCol != oldCol) || (newRow != oldRow)) { if (!grid[newRow][newCol].merged) { @@ -146,7 +146,7 @@ bool Twos::tryMerge(Tile grid[][4], int& newRow, int& newCol, int oldRow, int ol return false; } -bool Twos::tryMove(Tile grid[][4], int newRow, int newCol, int oldRow, int oldCol) { +bool Twos::tryMove(TwosTile grid[][4], int newRow, int newCol, int oldRow, int oldCol) { if (((newCol >= 0) && (newCol != oldCol)) || ((newRow >= 0) && (newRow != oldRow))) { grid[newRow][newCol].value = grid[oldRow][oldCol].value; grid[oldRow][oldCol].value = 0; @@ -261,7 +261,7 @@ bool Twos::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } -void Twos::updateGridDisplay(Tile grid[][4]) { +void Twos::updateGridDisplay(TwosTile grid[][4]) { for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { if (grid[row][col].value) { diff --git a/src/displayapp/screens/Twos.h b/src/displayapp/screens/Twos.h index 48ea0794..5a0c4350 100644 --- a/src/displayapp/screens/Twos.h +++ b/src/displayapp/screens/Twos.h @@ -5,7 +5,7 @@ namespace Pinetime { namespace Applications { - struct Tile { + struct TwosTile { bool merged = false; unsigned int value = 0; }; @@ -26,11 +26,11 @@ namespace Pinetime { lv_obj_t* scoreText; lv_obj_t* gridDisplay; - Tile grid[4][4]; + TwosTile grid[4][4]; unsigned int score = 0; - void updateGridDisplay(Tile grid[][4]); - bool tryMerge(Tile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol); - bool tryMove(Tile grid[][4], int newRow, int newCol, int oldRow, int oldCol); + void updateGridDisplay(TwosTile grid[][4]); + bool tryMerge(TwosTile grid[][4], int& newRow, int& newCol, int oldRow, int oldCol); + bool tryMove(TwosTile grid[][4], int newRow, int newCol, int oldRow, int oldCol); bool placeNewTile(); }; } diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp new file mode 100644 index 00000000..1d0a83bd --- /dev/null +++ b/src/displayapp/screens/Weather.cpp @@ -0,0 +1,222 @@ +/* Copyright (C) 2021 Avamander + + This file is part of InfiniTime. + + InfiniTime is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + InfiniTime is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ +#include "Weather.h" +#include <lvgl/lvgl.h> +#include <components/ble/weather/WeatherService.h> +#include "Label.h" +#include "components/battery/BatteryController.h" +#include "components/ble/BleController.h" +#include "components/ble/weather/WeatherData.h" + +using namespace Pinetime::Applications::Screens; + +Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::WeatherService& weather) + : Screen(app), + dateTimeController {dateTimeController}, + weatherService(weather), + screens {app, + 0, + {[this]() -> std::unique_ptr<Screen> { + return CreateScreenTemperature(); + }, + [this]() -> std::unique_ptr<Screen> { + return CreateScreenAir(); + }, + [this]() -> std::unique_ptr<Screen> { + return CreateScreenClouds(); + }, + [this]() -> std::unique_ptr<Screen> { + return CreateScreenPrecipitation(); + }, + [this]() -> std::unique_ptr<Screen> { + return CreateScreenHumidity(); + }}, + Screens::ScreenListModes::UpDown} { +} + +Weather::~Weather() { + lv_obj_clean(lv_scr_act()); +} + +void Weather::Refresh() { + if (running) { + // screens.Refresh(); + } +} + +bool Weather::OnButtonPushed() { + running = false; + return true; +} + +bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return screens.OnTouchEvent(event); +} + +std::unique_ptr<Screen> Weather::CreateScreenTemperature() { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label, true); + std::unique_ptr<Controllers::WeatherData::Temperature>& current = weatherService.GetCurrentTemperature(); + if (current->timestamp == 0) { + // Do not use the data, it's invalid + lv_label_set_text_fmt(label, + "#FFFF00 Temperature#\n\n" + "#444444 %d#°C \n\n" + "#444444 %d#\n\n" + "%d\n" + "%d\n", + 0, + 0, + 0, + 0); + } else { + lv_label_set_text_fmt(label, + "#FFFF00 Temperature#\n\n" + "#444444 %d#°C \n\n" + "#444444 %hd#\n\n" + "%llu\n" + "%lu\n", + current->temperature / 100, + current->dewPoint, + current->timestamp, + current->expires); + } + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label)); +} + +std::unique_ptr<Screen> Weather::CreateScreenAir() { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label, true); + std::unique_ptr<Controllers::WeatherData::AirQuality>& current = weatherService.GetCurrentQuality(); + if (current->timestamp == 0) { + // Do not use the data, it's invalid + lv_label_set_text_fmt(label, + "#FFFF00 Air quality#\n\n" + "#444444 %s#\n" + "#444444 %d#\n\n" + "%d\n" + "%d\n", + "", + 0, + 0, + 0); + } else { + lv_label_set_text_fmt(label, + "#FFFF00 Air quality#\n\n" + "#444444 %s#\n" + "#444444 %lu#\n\n" + "%llu\n" + "%lu\n", + current->polluter.c_str(), + (current->amount / 100), + current->timestamp, + current->expires); + } + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label)); +} + +std::unique_ptr<Screen> Weather::CreateScreenClouds() { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label, true); + std::unique_ptr<Controllers::WeatherData::Clouds>& current = weatherService.GetCurrentClouds(); + if (current->timestamp == 0) { + // Do not use the data, it's invalid + lv_label_set_text_fmt(label, + "#FFFF00 Clouds#\n\n" + "#444444 %d%%#\n\n" + "%d\n" + "%d\n", + 0, + 0, + 0); + } else { + lv_label_set_text_fmt(label, + "#FFFF00 Clouds#\n\n" + "#444444 %hhu%%#\n\n" + "%llu\n" + "%lu\n", + current->amount, + current->timestamp, + current->expires); + } + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label)); +} + +std::unique_ptr<Screen> Weather::CreateScreenPrecipitation() { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label, true); + std::unique_ptr<Controllers::WeatherData::Precipitation>& current = weatherService.GetCurrentPrecipitation(); + if (current->timestamp == 0) { + // Do not use the data, it's invalid + lv_label_set_text_fmt(label, + "#FFFF00 Precipitation#\n\n" + "#444444 %d%%#\n\n" + "%d\n" + "%d\n", + 0, + 0, + 0); + } else { + lv_label_set_text_fmt(label, + "#FFFF00 Precipitation#\n\n" + "#444444 %hhu%%#\n\n" + "%llu\n" + "%lu\n", + current->amount, + current->timestamp, + current->expires); + } + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label)); +} + +std::unique_ptr<Screen> Weather::CreateScreenHumidity() { + lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_recolor(label, true); + std::unique_ptr<Controllers::WeatherData::Humidity>& current = weatherService.GetCurrentHumidity(); + if (current->timestamp == 0) { + // Do not use the data, it's invalid + lv_label_set_text_fmt(label, + "#FFFF00 Humidity#\n\n" + "#444444 %d%%#\n\n" + "%d\n" + "%d\n", + 0, + 0, + 0); + } else { + lv_label_set_text_fmt(label, + "#FFFF00 Humidity#\n\n" + "#444444 %hhu%%#\n\n" + "%llu\n" + "%lu\n", + current->humidity, + current->timestamp, + current->expires); + } + lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); + lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); + return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label)); +} diff --git a/src/displayapp/screens/Weather.h b/src/displayapp/screens/Weather.h new file mode 100644 index 00000000..34f95fce --- /dev/null +++ b/src/displayapp/screens/Weather.h @@ -0,0 +1,45 @@ +#pragma once + +#include <memory> +#include <components/ble/weather/WeatherService.h> +#include "Screen.h" +#include "ScreenList.h" + +namespace Pinetime { + namespace Applications { + class DisplayApp; + + namespace Screens { + class Weather : public Screen { + public: + explicit Weather(DisplayApp* app, Pinetime::Controllers::WeatherService& weather); + + ~Weather() override; + + void Refresh() override; + + bool OnButtonPushed() override; + + bool OnTouchEvent(TouchEvents event) override; + + private: + bool running = true; + + Pinetime::Controllers::DateTime& dateTimeController; + Controllers::WeatherService& weatherService; + + ScreenList<5> screens; + + std::unique_ptr<Screen> CreateScreenTemperature(); + + std::unique_ptr<Screen> CreateScreenAir(); + + std::unique_ptr<Screen> CreateScreenClouds(); + + std::unique_ptr<Screen> CreateScreenPrecipitation(); + + std::unique_ptr<Screen> CreateScreenHumidity(); + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 666dfb80..9e972afc 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -2,6 +2,7 @@ #include <lvgl/lvgl.h> #include "displayapp/DisplayApp.h" #include "displayapp/Messages.h" +#include "displayapp/screens/Styles.h" #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" @@ -14,6 +15,8 @@ namespace { } } +constexpr std::array<uint16_t, 4> SettingDisplay::options; + SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : Screen(app), settingsController {settingsController} { @@ -40,39 +43,19 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 5 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 5000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 15 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 15000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 20 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 20000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 30 seconds"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetScreenTimeOut() == 30000) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + char buffer[12]; + for (unsigned int i = 0; i < options.size(); i++) { + cbOption[i] = lv_checkbox_create(container1, nullptr); + sprintf(buffer, "%3d seconds", options[i] / 1000); + lv_checkbox_set_text(cbOption[i], buffer); + cbOption[i]->user_data = this; + lv_obj_set_event_cb(cbOption[i], event_handler); + SetRadioButtonStyle(cbOption[i]); + + if (settingsController.GetScreenTimeOut() == options[i]) { + lv_checkbox_set_checked(cbOption[i], true); + } } - optionsTotal++; } SettingDisplay::~SettingDisplay() { @@ -82,25 +65,11 @@ SettingDisplay::~SettingDisplay() { void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_CLICKED) { - for (int i = 0; i < optionsTotal; i++) { + for (unsigned int i = 0; i < options.size(); i++) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); - - if (i == 0) { - settingsController.SetScreenTimeOut(5000); - }; - if (i == 1) { - settingsController.SetScreenTimeOut(15000); - }; - if (i == 2) { - settingsController.SetScreenTimeOut(20000); - }; - if (i == 3) { - settingsController.SetScreenTimeOut(30000); - }; - + settingsController.SetScreenTimeOut(options[i]); app->PushMessage(Applications::Display::Messages::UpdateTimeOut); - } else { lv_checkbox_set_checked(cbOption[i], false); } diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h index 51b23aca..dc56419d 100644 --- a/src/displayapp/screens/settings/SettingDisplay.h +++ b/src/displayapp/screens/settings/SettingDisplay.h @@ -1,7 +1,9 @@ #pragma once +#include <array> #include <cstdint> #include <lvgl/lvgl.h> + #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" @@ -18,9 +20,10 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + static constexpr std::array<uint16_t, 4> options = {5000, 15000, 20000, 30000}; + Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[4]; + lv_obj_t* cbOption[options.size()]; }; } } diff --git a/src/displayapp/screens/settings/SettingSteps.cpp b/src/displayapp/screens/settings/SettingSteps.cpp index 149840df..5ca3eecd 100644 --- a/src/displayapp/screens/settings/SettingSteps.cpp +++ b/src/displayapp/screens/settings/SettingSteps.cpp @@ -6,8 +6,8 @@ using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t * obj, lv_event_t event) { - SettingSteps* screen = static_cast<SettingSteps *>(obj->user_data); + void event_handler(lv_obj_t* obj, lv_event_t event) { + SettingSteps* screen = static_cast<SettingSteps*>(obj->user_data); screen->UpdateSelected(obj, event); } } @@ -30,33 +30,32 @@ SettingSteps::SettingSteps( lv_obj_set_height(container1, LV_VER_RES - 60); lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title,"Daily steps goal"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text_static(icon, Symbols::shoe); lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - - stepValue = lv_label_create(lv_scr_act(), NULL); + stepValue = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(stepValue, "%lu", settingsController.GetStepsGoal()); lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER); lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, -10); - btnPlus = lv_btn_create(lv_scr_act(), NULL); + btnPlus = lv_btn_create(lv_scr_act(), nullptr); btnPlus->user_data = this; lv_obj_set_size(btnPlus, 80, 50); lv_obj_align(btnPlus, lv_scr_act(), LV_ALIGN_CENTER, 55, 80); lv_obj_set_style_local_value_str(btnPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnPlus, event_handler); - btnMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinus = lv_btn_create(lv_scr_act(), nullptr); btnMinus->user_data = this; lv_obj_set_size(btnMinus, 80, 50); lv_obj_set_event_cb(btnMinus, event_handler); diff --git a/src/displayapp/screens/settings/SettingTimeFormat.cpp b/src/displayapp/screens/settings/SettingTimeFormat.cpp index c6bdf401..bd9af156 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.cpp +++ b/src/displayapp/screens/settings/SettingTimeFormat.cpp @@ -1,6 +1,7 @@ #include "displayapp/screens/settings/SettingTimeFormat.h" #include <lvgl/lvgl.h> #include "displayapp/DisplayApp.h" +#include "displayapp/screens/Styles.h" #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" @@ -13,6 +14,8 @@ namespace { } } +constexpr std::array<const char*, 2> SettingTimeFormat::options; + SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : Screen(app), settingsController {settingsController} { @@ -39,24 +42,19 @@ SettingTimeFormat::SettingTimeFormat(Pinetime::Applications::DisplayApp* app, Pi lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 12-hour"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + for (unsigned int i = 0; i < options.size(); i++) { + cbOption[i] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(cbOption[i], options[i]); + cbOption[i]->user_data = this; + lv_obj_set_event_cb(cbOption[i], event_handler); + SetRadioButtonStyle(cbOption[i]); } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " 24-hour"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + lv_checkbox_set_checked(cbOption[0], true); + } else if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { + lv_checkbox_set_checked(cbOption[1], true); } - optionsTotal++; } SettingTimeFormat::~SettingTimeFormat() { @@ -66,7 +64,7 @@ SettingTimeFormat::~SettingTimeFormat() { void SettingTimeFormat::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_VALUE_CHANGED) { - for (int i = 0; i < optionsTotal; i++) { + for (unsigned int i = 0; i < options.size(); i++) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); diff --git a/src/displayapp/screens/settings/SettingTimeFormat.h b/src/displayapp/screens/settings/SettingTimeFormat.h index eac4bdc9..818edf0c 100644 --- a/src/displayapp/screens/settings/SettingTimeFormat.h +++ b/src/displayapp/screens/settings/SettingTimeFormat.h @@ -1,7 +1,9 @@ #pragma once +#include <array> #include <cstdint> #include <lvgl/lvgl.h> + #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" @@ -18,9 +20,9 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + static constexpr std::array<const char*, 2> options = {" 12-hour", " 24-hour"}; Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[2]; + lv_obj_t* cbOption[options.size()]; }; } } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 8e6e7cf4..a24eaa15 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -2,6 +2,7 @@ #include <lvgl/lvgl.h> #include "displayapp/DisplayApp.h" #include "displayapp/screens/Screen.h" +#include "displayapp/screens/Styles.h" #include "displayapp/screens/Symbols.h" using namespace Pinetime::Applications::Screens; @@ -13,6 +14,8 @@ namespace { } } +constexpr std::array<const char*, 3> SettingWatchFace::options; + SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : Screen(app), settingsController {settingsController} { @@ -40,34 +43,17 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Digital face"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockFace() == 0) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Analog face"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockFace() == 1) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } + for (unsigned int i = 0; i < options.size(); i++) { + cbOption[i] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(cbOption[i], options[i]); + cbOption[i]->user_data = this; + lv_obj_set_event_cb(cbOption[i], event_handler); + SetRadioButtonStyle(cbOption[i]); - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " PineTimeStyle"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetClockFace() == 2) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); + if (settingsController.GetClockFace() == i) { + lv_checkbox_set_checked(cbOption[i], true); + } } - - optionsTotal++; } SettingWatchFace::~SettingWatchFace() { @@ -77,7 +63,7 @@ SettingWatchFace::~SettingWatchFace() { void SettingWatchFace::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_VALUE_CHANGED) { - for (uint8_t i = 0; i < optionsTotal; i++) { + for (unsigned int i = 0; i < options.size(); i++) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); settingsController.SetClockFace(i); diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index d4a96c6d..ccba7d13 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -1,7 +1,9 @@ #pragma once +#include <array> #include <cstdint> #include <lvgl/lvgl.h> + #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" @@ -18,9 +20,10 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); private: + static constexpr std::array<const char*, 3> options = {" Digital face", " Analog face", " PineTimeStyle"}; Controllers::Settings& settingsController; - uint8_t optionsTotal; - lv_obj_t* cbOption[2]; + + lv_obj_t* cbOption[options.size()]; }; } } |