Skip to content

Commit

Permalink
EXPERIMENTAL: DNM Add temporary timeline debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
faxe1008 committed Aug 10, 2023
1 parent d29f89e commit cf21190
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/components/ble/weather/WeatherService.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ namespace Pinetime {
*/
bool HasTimelineEventOfType(WeatherData::eventtype type) const;

const std::vector<std::unique_ptr<WeatherData::TimelineHeader>>& GetEventTimeline() const {
return timeline;
}

private:
// 00040000-78fc-48fe-8e23-433b3a1942d0
static constexpr ble_uuid128_t BaseUuid() {
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingBluetooth,
Weather,
Error
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,10 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::Metronome:
currentScreen = std::make_unique<Screens::Metronome>(motorController, *systemTask);
break;
/* Weather debug app
/* Weather debug app*/
case Apps::Weather:
currentScreen = std::make_unique<Screens::Weather>(this, systemTask->nimble().weather());
break;
*/
case Apps::Steps:
currentScreen = std::make_unique<Screens::Steps>(motionController, settingsController);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/ApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}};
Expand Down
76 changes: 76 additions & 0 deletions src/displayapp/screens/Weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers:
screens {app,
0,
{[this]() -> std::unique_ptr<Screen> {
return CreateTimelineStatsPage();
},
[this]() -> std::unique_ptr<Screen> {
return CreateScreenTemperature();
},
[this]() -> std::unique_ptr<Screen> {
Expand Down Expand Up @@ -67,6 +70,79 @@ bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return screens.OnTouchEvent(event);
}

std::unique_ptr<Screen> 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;
}

uint64_t expired_at = header->timestamp + header->expires;
sprintf(buffer, "%llu", expired_at);
lv_table_set_cell_value(timelineTable, i + 1, 2, buffer);
}

return std::make_unique<Screens::Label>(3, 5, timelineTable);
}

std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label, true);
Expand Down
4 changes: 3 additions & 1 deletion src/displayapp/screens/Weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace Pinetime {

Controllers::WeatherService& weatherService;

ScreenList<5> screens;
ScreenList<6> screens;

std::unique_ptr<Screen> CreateTimelineStatsPage();

std::unique_ptr<Screen> CreateScreenTemperature();

Expand Down

0 comments on commit cf21190

Please sign in to comment.