|
|
@ -1,5 +1,6 @@
|
|
|
|
#include "Weather.h"
|
|
|
|
#include "Weather.h"
|
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
|
|
|
|
#include <components/ble/weather/WeatherService.h>
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "Label.h"
|
|
|
|
#include "Label.h"
|
|
|
|
#include "Version.h"
|
|
|
|
#include "Version.h"
|
|
|
@ -12,22 +13,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
|
|
|
|
Weather::Weather(Pinetime::Applications::DisplayApp* app,
|
|
|
|
Weather::Weather(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::WeatherService& weather)
|
|
|
|
Pinetime::Controllers::DateTime& dateTimeController,
|
|
|
|
|
|
|
|
Pinetime::Controllers::Battery& batteryController,
|
|
|
|
|
|
|
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
|
|
|
|
|
|
|
Pinetime::Controllers::Ble& bleController,
|
|
|
|
|
|
|
|
Pinetime::Drivers::WatchdogView& watchdog)
|
|
|
|
|
|
|
|
: Screen(app),
|
|
|
|
: Screen(app),
|
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
dateTimeController {dateTimeController},
|
|
|
|
batteryController {batteryController},
|
|
|
|
weatherService(weather),
|
|
|
|
brightnessController {brightnessController},
|
|
|
|
|
|
|
|
bleController {bleController},
|
|
|
|
|
|
|
|
watchdog {watchdog},
|
|
|
|
|
|
|
|
screens {app,
|
|
|
|
screens {app,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{[this]() -> std::unique_ptr<Screen> {
|
|
|
|
{[this]() -> std::unique_ptr<Screen> {
|
|
|
|
return CreateScreen1();
|
|
|
|
return CreateScreenTemperature();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
|
|
|
[this]() -> std::unique_ptr<Screen> {
|
|
|
|
return CreateScreen2();
|
|
|
|
return CreateScreen2();
|
|
|
@ -64,101 +57,30 @@ bool Weather::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|
|
|
return screens.OnTouchEvent(event);
|
|
|
|
return screens.OnTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreen1() {
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
|
|
|
|
Controllers::WeatherData::Temperature current = weatherService.GetCurrentTemperature();
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 InfiniTime#\n\n"
|
|
|
|
"#FFFF00 Temperature#\n\n"
|
|
|
|
"#444444 Version# %ld.%ld.%ld\n\n"
|
|
|
|
"#444444 %hd%%#°C \n\n"
|
|
|
|
"#444444 Build date#\n"
|
|
|
|
"#444444 %hd#\n"
|
|
|
|
"%s\n"
|
|
|
|
"%llu\n"
|
|
|
|
"%s\n",
|
|
|
|
"%lu\n",
|
|
|
|
Version::Major(),
|
|
|
|
current.temperature,
|
|
|
|
Version::Minor(),
|
|
|
|
current.dewPoint,
|
|
|
|
Version::Patch(),
|
|
|
|
current.timestamp,
|
|
|
|
__DATE__,
|
|
|
|
current.expires);
|
|
|
|
__TIME__);
|
|
|
|
|
|
|
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreen2() {
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreen2() {
|
|
|
|
auto batteryPercent = static_cast<uint8_t>(batteryController.PercentRemaining());
|
|
|
|
|
|
|
|
float batteryVoltage = batteryController.Voltage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto resetReason = [this]() {
|
|
|
|
|
|
|
|
switch (watchdog.ResetReason()) {
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::Watchdog:
|
|
|
|
|
|
|
|
return "wtdg";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::HardReset:
|
|
|
|
|
|
|
|
return "hardr";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::NFC:
|
|
|
|
|
|
|
|
return "nfc";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::SoftReset:
|
|
|
|
|
|
|
|
return "softr";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::CpuLockup:
|
|
|
|
|
|
|
|
return "cpulock";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::SystemOff:
|
|
|
|
|
|
|
|
return "off";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::LpComp:
|
|
|
|
|
|
|
|
return "lpcomp";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::DebugInterface:
|
|
|
|
|
|
|
|
return "dbg";
|
|
|
|
|
|
|
|
case Drivers::Watchdog::ResetReasons::ResetPin:
|
|
|
|
|
|
|
|
return "rst";
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return "?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// uptime
|
|
|
|
// uptime
|
|
|
|
static constexpr uint32_t secondsInADay = 60 * 60 * 24;
|
|
|
|
|
|
|
|
static constexpr uint32_t secondsInAnHour = 60 * 60;
|
|
|
|
|
|
|
|
static constexpr uint32_t secondsInAMinute = 60;
|
|
|
|
|
|
|
|
uint32_t uptimeSeconds = dateTimeController.Uptime().count();
|
|
|
|
|
|
|
|
uint32_t uptimeDays = (uptimeSeconds / secondsInADay);
|
|
|
|
|
|
|
|
uptimeSeconds = uptimeSeconds % secondsInADay;
|
|
|
|
|
|
|
|
uint32_t uptimeHours = uptimeSeconds / secondsInAnHour;
|
|
|
|
|
|
|
|
uptimeSeconds = uptimeSeconds % secondsInAnHour;
|
|
|
|
|
|
|
|
uint32_t uptimeMinutes = uptimeSeconds / secondsInAMinute;
|
|
|
|
|
|
|
|
uptimeSeconds = uptimeSeconds % secondsInAMinute;
|
|
|
|
|
|
|
|
// TODO handle more than 100 days of uptime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (batteryPercent == -1)
|
|
|
|
|
|
|
|
batteryPercent = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// hack to not use the flot functions from printf
|
|
|
|
|
|
|
|
uint8_t batteryVoltageBytes[2];
|
|
|
|
|
|
|
|
batteryVoltageBytes[1] = static_cast<uint8_t>(batteryVoltage); // truncate whole numbers
|
|
|
|
|
|
|
|
batteryVoltageBytes[0] =
|
|
|
|
|
|
|
|
static_cast<uint8_t>((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
lv_label_set_text_fmt(label, "#444444 Date# %02d\n", dateTimeController.Day());
|
|
|
|
"#444444 Date# %02d/%02d/%04d\n"
|
|
|
|
|
|
|
|
"#444444 Time# %02d:%02d:%02d\n"
|
|
|
|
|
|
|
|
"#444444 Uptime#\n %02lud %02lu:%02lu:%02lu\n"
|
|
|
|
|
|
|
|
"#444444 Battery# %d%%/%1i.%02iv\n"
|
|
|
|
|
|
|
|
"#444444 Backlight# %s\n"
|
|
|
|
|
|
|
|
"#444444 Last reset# %s\n",
|
|
|
|
|
|
|
|
dateTimeController.Day(),
|
|
|
|
|
|
|
|
static_cast<uint8_t>(dateTimeController.Month()),
|
|
|
|
|
|
|
|
dateTimeController.Year(),
|
|
|
|
|
|
|
|
dateTimeController.Hours(),
|
|
|
|
|
|
|
|
dateTimeController.Minutes(),
|
|
|
|
|
|
|
|
dateTimeController.Seconds(),
|
|
|
|
|
|
|
|
uptimeDays,
|
|
|
|
|
|
|
|
uptimeHours,
|
|
|
|
|
|
|
|
uptimeMinutes,
|
|
|
|
|
|
|
|
uptimeSeconds,
|
|
|
|
|
|
|
|
batteryPercent,
|
|
|
|
|
|
|
|
batteryVoltageBytes[1],
|
|
|
|
|
|
|
|
batteryVoltageBytes[0],
|
|
|
|
|
|
|
|
brightnessController.ToString(),
|
|
|
|
|
|
|
|
resetReason);
|
|
|
|
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
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(1, 4, app, label));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -169,28 +91,11 @@ std::unique_ptr<Screen> Weather::CreateScreen3() {
|
|
|
|
|
|
|
|
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_obj_t* label = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
auto& bleAddr = bleController.Address();
|
|
|
|
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#444444 BLE MAC#\n"
|
|
|
|
|
|
|
|
" %02x:%02x:%02x:%02x:%02x:%02x"
|
|
|
|
|
|
|
|
"\n"
|
|
|
|
|
|
|
|
"#444444 Memory#\n"
|
|
|
|
|
|
|
|
" #444444 used# %d (%d%%)\n"
|
|
|
|
|
|
|
|
" #444444 frag# %d%%\n"
|
|
|
|
" #444444 frag# %d%%\n"
|
|
|
|
" #444444 free# %d"
|
|
|
|
" #444444 free# %d",
|
|
|
|
"\n"
|
|
|
|
|
|
|
|
"#444444 Steps# %li",
|
|
|
|
|
|
|
|
bleAddr[5],
|
|
|
|
|
|
|
|
bleAddr[4],
|
|
|
|
|
|
|
|
bleAddr[3],
|
|
|
|
|
|
|
|
bleAddr[2],
|
|
|
|
|
|
|
|
bleAddr[1],
|
|
|
|
|
|
|
|
bleAddr[0],
|
|
|
|
|
|
|
|
(int) mon.total_size - mon.free_size,
|
|
|
|
|
|
|
|
mon.used_pct,
|
|
|
|
mon.used_pct,
|
|
|
|
mon.frag_pct,
|
|
|
|
mon.frag_pct);
|
|
|
|
(int) mon.free_biggest_size,
|
|
|
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(2, 5, app, label));
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(2, 5, app, label));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -201,7 +106,7 @@ bool sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreen4() {
|
|
|
|
std::unique_ptr<Screen> Weather::CreateScreen4() {
|
|
|
|
TaskStatus_t tasksStatus[7];
|
|
|
|
TaskStatus_t tasksStatus[7];
|
|
|
|
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr);
|
|
|
|
lv_table_set_col_cnt(infoTask, 3);
|
|
|
|
lv_table_set_col_cnt(infoTask, 3);
|
|
|
|
lv_table_set_row_cnt(infoTask, 8);
|
|
|
|
lv_table_set_row_cnt(infoTask, 8);
|
|
|
|
lv_obj_set_pos(infoTask, 10, 10);
|
|
|
|
lv_obj_set_pos(infoTask, 10, 10);
|
|
|
|