2021-11-28 13:33:06 +00:00
|
|
|
/* 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/>.
|
|
|
|
*/
|
2021-06-09 21:44:49 +00:00
|
|
|
#include "Weather.h"
|
|
|
|
#include <lvgl/lvgl.h>
|
2021-06-24 22:18:56 +00:00
|
|
|
#include <components/ble/weather/WeatherService.h>
|
2021-06-09 21:44:49 +00:00
|
|
|
#include "Label.h"
|
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
#include "components/ble/BleController.h"
|
|
|
|
#include "components/ble/weather/WeatherData.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-06-24 22:18:56 +00:00
|
|
|
Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::WeatherService& weather)
|
2021-06-09 21:44:49 +00:00
|
|
|
: Screen(app),
|
|
|
|
dateTimeController {dateTimeController},
|
2021-06-24 22:18:56 +00:00
|
|
|
weatherService(weather),
|
2021-06-09 21:44:49 +00:00
|
|
|
screens {app,
|
|
|
|
0,
|
|
|
|
{[this]() -> std::unique_ptr<Screen> {
|
2021-06-24 22:18:56 +00:00
|
|
|
return CreateScreenTemperature();
|
2021-06-09 21:44:49 +00:00
|
|
|
},
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
2021-11-30 22:45:28 +00:00
|
|
|
return CreateScreenAir();
|
2021-06-09 21:44:49 +00:00
|
|
|
},
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
2021-11-30 22:45:28 +00:00
|
|
|
return CreateScreenClouds();
|
2021-06-09 21:44:49 +00:00
|
|
|
},
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
2021-11-30 22:45:28 +00:00
|
|
|
return CreateScreenPrecipitation();
|
2021-06-09 21:44:49 +00:00
|
|
|
},
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
2021-11-30 22:45:28 +00:00
|
|
|
return CreateScreenHumidity();
|
2021-06-09 21:44:49 +00:00
|
|
|
}},
|
|
|
|
Screens::ScreenListModes::UpDown} {
|
|
|
|
}
|
|
|
|
|
|
|
|
Weather::~Weather() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-11-28 13:33:06 +00:00
|
|
|
void Weather::Refresh() {
|
2021-06-09 21:44:49 +00:00
|
|
|
if (running) {
|
2021-11-28 13:33:06 +00:00
|
|
|
// screens.Refresh();
|
2021-06-09 21:44:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Weather::OnButtonPushed() {
|
|
|
|
running = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|
|
|
return screens.OnTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-06-24 22:18:56 +00:00
|
|
|
std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Controllers::WeatherData::Temperature>& current = weatherService.GetCurrentTemperature();
|
|
|
|
if (current->timestamp == 0) {
|
|
|
|
// Do not use the data, it's invalid
|
2021-11-30 23:15:11 +00:00
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 Temperature#\n\n"
|
2021-12-03 15:06:30 +00:00
|
|
|
"#444444 %d#°C \n\n"
|
2021-11-30 23:15:11 +00:00
|
|
|
"#444444 %d#\n\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d\n",
|
2021-12-03 15:06:30 +00:00
|
|
|
0,
|
2021-11-30 23:15:11 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2021-11-30 22:45:28 +00:00
|
|
|
} else {
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 Temperature#\n\n"
|
2021-12-03 15:06:30 +00:00
|
|
|
"#444444 %d#°C \n\n"
|
2021-11-30 22:45:28 +00:00
|
|
|
"#444444 %hd#\n\n"
|
|
|
|
"%llu\n"
|
|
|
|
"%lu\n",
|
2021-12-03 15:06:30 +00:00
|
|
|
current->temperature / 100,
|
2021-11-30 22:45:28 +00:00
|
|
|
current->dewPoint,
|
|
|
|
current->timestamp,
|
|
|
|
current->expires);
|
|
|
|
}
|
2021-06-09 21:44:49 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Screen> Weather::CreateScreenAir() {
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Controllers::WeatherData::AirQuality>& current = weatherService.GetCurrentQuality();
|
|
|
|
if (current->timestamp == 0) {
|
|
|
|
// Do not use the data, it's invalid
|
2021-11-30 23:15:11 +00:00
|
|
|
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);
|
2021-11-30 22:45:28 +00:00
|
|
|
} 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);
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
2021-11-30 22:45:28 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
2021-06-09 21:44:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Screen> Weather::CreateScreenClouds() {
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Controllers::WeatherData::Clouds>& current = weatherService.GetCurrentClouds();
|
|
|
|
if (current->timestamp == 0) {
|
|
|
|
// Do not use the data, it's invalid
|
2021-12-01 13:50:36 +00:00
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 Clouds#\n\n"
|
|
|
|
"#444444 %d%%#\n\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d\n",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2021-11-30 22:45:28 +00:00
|
|
|
} 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);
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
2021-11-30 22:45:28 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
2021-06-09 21:44:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 22:45:28 +00:00
|
|
|
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
|
2021-12-01 13:50:36 +00:00
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 Precipitation#\n\n"
|
|
|
|
"#444444 %d%%#\n\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d\n",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2021-11-30 22:45:28 +00:00
|
|
|
} 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));
|
2021-06-09 21:44:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Screen> Weather::CreateScreenHumidity() {
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
2021-11-30 22:45:28 +00:00
|
|
|
std::unique_ptr<Controllers::WeatherData::Humidity>& current = weatherService.GetCurrentHumidity();
|
|
|
|
if (current->timestamp == 0) {
|
|
|
|
// Do not use the data, it's invalid
|
2021-12-01 13:50:36 +00:00
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 Humidity#\n\n"
|
|
|
|
"#444444 %d%%#\n\n"
|
|
|
|
"%d\n"
|
|
|
|
"%d\n",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
2021-11-30 22:45:28 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2021-06-09 21:44:49 +00:00
|
|
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
2021-11-30 22:45:28 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
2021-08-21 18:58:03 +00:00
|
|
|
}
|