From 3a40c0b091e5e1d9c637b7e5be099b24b4d6878b Mon Sep 17 00:00:00 2001 From: faxe1008 Date: Thu, 10 Aug 2023 15:03:08 +0200 Subject: [PATCH] EXPERIMENTAL: DNM Add temporary timeline debug view --- src/components/ble/weather/WeatherService.h | 4 ++ src/displayapp/Apps.h | 1 + src/displayapp/DisplayApp.cpp | 3 +- src/displayapp/screens/ApplicationList.h | 2 +- src/displayapp/screens/Weather.cpp | 76 +++++++++++++++++++++ src/displayapp/screens/Weather.h | 4 +- 6 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/components/ble/weather/WeatherService.h b/src/components/ble/weather/WeatherService.h index 52979f99ae..341d1ba508 100644 --- a/src/components/ble/weather/WeatherService.h +++ b/src/components/ble/weather/WeatherService.h @@ -87,6 +87,10 @@ namespace Pinetime { */ bool HasTimelineEventOfType(WeatherData::eventtype type) const; + const std::vector>& GetEventTimeline() const { + return timeline; + } + private: // 00040000-78fc-48fe-8e23-433b3a1942d0 static constexpr ble_uuid128_t BaseUuid() { diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index f253bc0387..7da6e12f02 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -37,6 +37,7 @@ namespace Pinetime { SettingChimes, SettingShakeThreshold, SettingBluetooth, + Weather, Error }; } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index a930fe961c..3ddb9371a1 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -540,11 +540,10 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio case Apps::Metronome: currentScreen = std::make_unique(motorController, *systemTask); break; - /* Weather debug app + /* Weather debug app*/ case Apps::Weather: currentScreen = std::make_unique(this, systemTask->nimble().weather()); break; - */ case Apps::Steps: currentScreen = std::make_unique(motionController, settingsController); break; diff --git a/src/displayapp/screens/ApplicationList.h b/src/displayapp/screens/ApplicationList.h index 7bdd115408..4da665152d 100644 --- a/src/displayapp/screens/ApplicationList.h +++ b/src/displayapp/screens/ApplicationList.h @@ -52,7 +52,7 @@ namespace Pinetime { {"2", Apps::Twos}, {Symbols::drum, Apps::Metronome}, {Symbols::map, Apps::Navigation}, - {Symbols::none, Apps::None}, + {"W", Apps::Weather}, // {"M", Apps::Motion}, }}; diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp index 4921174c7a..97ee054c29 100644 --- a/src/displayapp/screens/Weather.cpp +++ b/src/displayapp/screens/Weather.cpp @@ -31,6 +31,9 @@ Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers: screens {app, 0, {[this]() -> std::unique_ptr { + return CreateTimelineStatsPage(); + }, + [this]() -> std::unique_ptr { return CreateScreenTemperature(); }, [this]() -> std::unique_ptr { @@ -67,6 +70,79 @@ bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return screens.OnTouchEvent(event); } +std::unique_ptr Weather::CreateTimelineStatsPage() { + static constexpr uint8_t maxTimelineCount = 8; + + const auto& timeline = weatherService.GetEventTimeline(); + + lv_obj_t* count_label = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_fmt(count_label, "Size: %u, Cap: %u", timeline.size(), timeline.capacity()); + + lv_obj_t* timelineTable = lv_table_create(lv_scr_act(), nullptr); + lv_obj_align(timelineTable, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 25); + lv_table_set_col_cnt(timelineTable, 3); + lv_table_set_row_cnt(timelineTable, maxTimelineCount + 1); + lv_obj_set_style_local_pad_all(timelineTable, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_border_color(timelineTable, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); + + lv_table_set_cell_value(timelineTable, 0, 0, "#"); + lv_table_set_col_width(timelineTable, 0, 30); + lv_table_set_cell_value(timelineTable, 0, 1, "Type"); // State + lv_table_set_col_width(timelineTable, 1, 50); + lv_table_set_cell_value(timelineTable, 0, 2, "Expires"); + lv_table_set_col_width(timelineTable, 2, 150); + + for (uint8_t i = 0; i < timeline.size() && i < maxTimelineCount; i++) { + char buffer[12] = {0}; + + sprintf(buffer, "%u", i); + lv_table_set_cell_value(timelineTable, i + 1, 0, buffer); + + auto& header = timeline[i]; + switch (header->eventType) { + case Controllers::WeatherData::eventtype::Obscuration: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Obsc"); + break; + case Controllers::WeatherData::eventtype::Precipitation: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Prec"); + break; + case Controllers::WeatherData::eventtype::Wind: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Wind"); + break; + case Controllers::WeatherData::eventtype::Temperature: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Temp"); + break; + case Controllers::WeatherData::eventtype::AirQuality: + lv_table_set_cell_value(timelineTable, i + 1, 1, "AirQ"); + break; + case Controllers::WeatherData::eventtype::Special: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Spec"); + break; + case Controllers::WeatherData::eventtype::Pressure: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Press"); + break; + case Controllers::WeatherData::eventtype::Location: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Loc"); + break; + case Controllers::WeatherData::eventtype::Clouds: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Cloud"); + break; + case Controllers::WeatherData::eventtype::Humidity: + lv_table_set_cell_value(timelineTable, i + 1, 1, "Humi"); + break; + default: + lv_table_set_cell_value(timelineTable, i + 1, 1, "????"); + break; + } + memset(buffer, 0, sizeof(buffer)); + uint64_t expired_at = header->timestamp + header->expires; + sprintf(buffer, "%lu", static_cast(expired_at)); + lv_table_set_cell_value(timelineTable, i + 1, 2, buffer); + } + + return std::make_unique(3, 5, timelineTable); +} + std::unique_ptr Weather::CreateScreenTemperature() { lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr); lv_label_set_recolor(label, true); diff --git a/src/displayapp/screens/Weather.h b/src/displayapp/screens/Weather.h index 459534aa2a..a5313f28c3 100644 --- a/src/displayapp/screens/Weather.h +++ b/src/displayapp/screens/Weather.h @@ -28,7 +28,9 @@ namespace Pinetime { Controllers::WeatherService& weatherService; - ScreenList<5> screens; + ScreenList<6> screens; + + std::unique_ptr CreateTimelineStatsPage(); std::unique_ptr CreateScreenTemperature();