summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/Weather.cpp
diff options
context:
space:
mode:
authorAvamander <avamander@gmail.com>2021-11-30 22:45:28 (GMT)
committerAvamander <avamander@gmail.com>2021-12-04 20:03:40 (GMT)
commitc870f8ed302823e12018aa196d87937c92966d06 (patch)
tree7b7e8d86dc5b07ae74de768b035d805333fdae6d /src/displayapp/screens/Weather.cpp
parent48beb7c3b18bcfdc369a63be5923a35a2113aa36 (diff)
Bunch of bugs fixed, improved error handling, debug UI addition
Diffstat (limited to 'src/displayapp/screens/Weather.cpp')
-rw-r--r--src/displayapp/screens/Weather.cpp144
1 files changed, 87 insertions, 57 deletions
diff --git a/src/displayapp/screens/Weather.cpp b/src/displayapp/screens/Weather.cpp
index 025a3bd..132bee7 100644
--- a/src/displayapp/screens/Weather.cpp
+++ b/src/displayapp/screens/Weather.cpp
@@ -35,16 +35,16 @@ Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers:
return CreateScreenTemperature();
},
[this]() -> std::unique_ptr<Screen> {
- return CreateScreen2();
+ return CreateScreenAir();
},
[this]() -> std::unique_ptr<Screen> {
- return CreateScreen3();
+ return CreateScreenClouds();
},
[this]() -> std::unique_ptr<Screen> {
- return CreateScreen4();
+ return CreateScreenPrecipitation();
},
[this]() -> std::unique_ptr<Screen> {
- return CreateScreen5();
+ return CreateScreenHumidity();
}},
Screens::ScreenListModes::UpDown} {
}
@@ -71,78 +71,108 @@ bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label, true);
- Controllers::WeatherData::Temperature current = weatherService.GetCurrentTemperature();
- lv_label_set_text_fmt(label,
- "#FFFF00 Temperature#\n\n"
- "#444444 %hd%%#°C \n\n"
- "#444444 %hd#\n"
- "%llu\n"
- "%lu\n",
- current.temperature,
- current.dewPoint,
- current.timestamp,
- current.expires);
+ std::unique_ptr<Controllers::WeatherData::Temperature>& current = weatherService.GetCurrentTemperature();
+ if (current->timestamp == 0) {
+ // Do not use the data, it's invalid
+ } else {
+ lv_label_set_text_fmt(label,
+ "#FFFF00 Temperature#\n\n"
+ "#444444 %hd%%#°C \n\n"
+ "#444444 %hd#\n\n"
+ "%llu\n"
+ "%lu\n",
+ current->temperature,
+ 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::CreateScreen2() {
- // uptime
+std::unique_ptr<Screen> Weather::CreateScreenAir() {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label, true);
- lv_label_set_text_fmt(label, "#444444 Date# %02d\n", dateTimeController.Day());
+ std::unique_ptr<Controllers::WeatherData::AirQuality>& current = weatherService.GetCurrentQuality();
+ if (current->timestamp == 0) {
+ // Do not use the data, it's invalid
+ } 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,
+ 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(1, 4, app, label));
+ return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
}
-std::unique_ptr<Screen> Weather::CreateScreen3() {
- lv_mem_monitor_t mon;
- lv_mem_monitor(&mon);
-
+std::unique_ptr<Screen> Weather::CreateScreenClouds() {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label, true);
- lv_label_set_text_fmt(label,
- " #444444 frag# %d%%\n"
- " #444444 free# %d",
- mon.used_pct,
- mon.frag_pct);
+ std::unique_ptr<Controllers::WeatherData::Clouds>& current = weatherService.GetCurrentClouds();
+ if (current->timestamp == 0) {
+ // Do not use the data, it's invalid
+ } 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(2, 5, app, label));
-}
-
-bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
- return lhs.xTaskNumber < rhs.xTaskNumber;
+ return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
}
-std::unique_ptr<Screen> Weather::CreateScreen4() {
- lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr);
- lv_table_set_col_cnt(infoTask, 3);
- lv_table_set_row_cnt(infoTask, 8);
- lv_obj_set_pos(infoTask, 10, 10);
-
- lv_table_set_cell_value(infoTask, 0, 0, "#");
- lv_table_set_col_width(infoTask, 0, 50);
- lv_table_set_cell_value(infoTask, 0, 1, "Task");
- lv_table_set_col_width(infoTask, 1, 80);
- lv_table_set_cell_value(infoTask, 0, 2, "Free");
- lv_table_set_col_width(infoTask, 2, 90);
-
- return std::unique_ptr<Screen>(new Screens::Label(3, 5, app, infoTask));
+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
+ } 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::CreateScreen5() {
+std::unique_ptr<Screen> Weather::CreateScreenHumidity() {
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_recolor(label, true);
- lv_label_set_text_static(label,
- "Software Licensed\n"
- "under the terms of\n"
- "the GNU General\n"
- "Public License v3\n"
- "#444444 Source code#\n"
- "#FFFF00 https://github.com/#\n"
- "#FFFF00 JF002/InfiniTime#");
+ std::unique_ptr<Controllers::WeatherData::Humidity>& current = weatherService.GetCurrentHumidity();
+ if (current->timestamp == 0) {
+ // Do not use the data, it's invalid
+ } 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(4, 5, app, label));
+ return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
}