2020-08-14 03:46:37 -04:00
|
|
|
#include "SystemInfo.h"
|
2020-11-15 10:49:36 -05:00
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include "../DisplayApp.h"
|
|
|
|
#include "Label.h"
|
|
|
|
#include "Version.h"
|
|
|
|
#include "components/battery/BatteryController.h"
|
|
|
|
#include "components/ble/BleController.h"
|
|
|
|
#include "components/brightness/BrightnessController.h"
|
|
|
|
#include "components/datetime/DateTimeController.h"
|
|
|
|
#include "drivers/Watchdog.h"
|
2020-03-22 07:03:17 -04:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp *app,
|
|
|
|
Pinetime::Controllers::DateTime &dateTimeController,
|
|
|
|
Pinetime::Controllers::Battery& batteryController,
|
|
|
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
2020-06-08 15:51:34 -04:00
|
|
|
Pinetime::Controllers::Ble& bleController,
|
2020-08-14 03:46:37 -04:00
|
|
|
Pinetime::Drivers::WatchdogView& watchdog) :
|
2020-03-22 07:03:17 -04:00
|
|
|
Screen(app),
|
2020-06-08 15:51:34 -04:00
|
|
|
dateTimeController{dateTimeController}, batteryController{batteryController},
|
2020-08-14 03:46:37 -04:00
|
|
|
brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog},
|
2021-02-24 14:40:24 -05:00
|
|
|
screens{app,
|
|
|
|
0,
|
|
|
|
{
|
2020-08-14 03:46:37 -04:00
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen1(); },
|
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen2(); },
|
2021-04-03 22:08:51 -04:00
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); },
|
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen4(); }
|
2021-02-24 14:40:24 -05:00
|
|
|
},
|
|
|
|
Screens::ScreenListModes::UpDown
|
2020-08-14 03:46:37 -04:00
|
|
|
} {}
|
2020-03-22 07:03:17 -04:00
|
|
|
|
2020-03-22 07:14:38 -04:00
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
SystemInfo::~SystemInfo() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInfo::Refresh() {
|
|
|
|
screens.Refresh();
|
|
|
|
return running;
|
|
|
|
}
|
2020-03-22 07:03:17 -04:00
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
bool SystemInfo::OnButtonPushed() {
|
|
|
|
running = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInfo::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|
|
|
return screens.OnTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
void SystemInfo::CreateContainer() {
|
|
|
|
|
|
|
|
if ( container1 ) {
|
|
|
|
container1 = lv_cont_create(lv_scr_act(), nullptr);
|
|
|
|
|
|
|
|
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
|
|
|
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
|
|
|
|
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
|
|
|
|
|
|
|
|
lv_obj_set_pos(container1, 0, 0);
|
|
|
|
lv_obj_set_width(container1, LV_HOR_RES - 10);
|
|
|
|
lv_obj_set_height(container1, LV_VER_RES);
|
|
|
|
lv_cont_set_layout(container1, LV_LAYOUT_CENTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
|
2021-04-03 22:08:51 -04:00
|
|
|
CreateContainer();
|
|
|
|
|
|
|
|
lv_obj_t * label = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#FFFF00 InfiniTime#\n\n"
|
|
|
|
"#444444 Version# %ld.%ld.%ld\n\n"
|
|
|
|
"#444444 Build date#\n"
|
|
|
|
"\t%s\n"
|
|
|
|
"\t%s\n",
|
|
|
|
Version::Major(), Version::Minor(), Version::Patch(),
|
|
|
|
__DATE__, __TIME__);
|
|
|
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(0, 4, app, label));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
|
|
|
CreateContainer();
|
|
|
|
|
2020-11-18 00:00:33 -05:00
|
|
|
auto batteryPercent = static_cast<uint8_t>(batteryController.PercentRemaining());
|
2021-04-03 22:08:51 -04:00
|
|
|
float batteryVoltage = batteryController.Voltage();
|
2020-03-22 07:03:17 -04:00
|
|
|
|
2020-08-14 03:46:37 -04:00
|
|
|
auto resetReason = [this]() {
|
2020-03-22 07:03:17 -04:00
|
|
|
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 "?";
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
2020-06-07 14:04:43 -04:00
|
|
|
// 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
|
2020-03-22 07:03:17 -04:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
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(container1, nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_text_fmt(label,
|
|
|
|
"#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",
|
2020-08-17 10:31:00 -04:00
|
|
|
dateTimeController.Day(), static_cast<uint8_t>(dateTimeController.Month()), dateTimeController.Year(),
|
2020-08-14 03:46:37 -04:00
|
|
|
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(),
|
|
|
|
uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds,
|
2021-04-03 22:08:51 -04:00
|
|
|
batteryPercent, batteryVoltageBytes[1], batteryVoltageBytes[0], brightnessController.ToString(), resetReason
|
|
|
|
);
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(1, 4, app, label));
|
2020-08-14 03:46:37 -04:00
|
|
|
|
|
|
|
}
|
2020-03-22 07:03:17 -04:00
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
|
|
|
|
lv_mem_monitor_t mon;
|
|
|
|
lv_mem_monitor(&mon);
|
|
|
|
CreateContainer();
|
|
|
|
|
|
|
|
lv_obj_t * label = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
2020-06-08 15:51:34 -04:00
|
|
|
auto& bleAddr = bleController.Address();
|
2021-04-03 22:08:51 -04:00
|
|
|
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 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.frag_pct,
|
|
|
|
(int)mon.free_biggest_size,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(2, 4, app, label));
|
2020-03-22 07:03:17 -04:00
|
|
|
}
|
|
|
|
|
2021-04-03 22:08:51 -04:00
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
|
|
|
|
CreateContainer();
|
|
|
|
lv_obj_t * label = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_recolor(label, true);
|
|
|
|
lv_label_set_text_static(label,
|
2020-12-28 02:45:24 -05:00
|
|
|
"Software Licensed\n"
|
|
|
|
"under the terms of\n"
|
|
|
|
"the GNU General\n"
|
|
|
|
"Public License v3\n"
|
2021-04-03 22:08:51 -04:00
|
|
|
"#444444 Source code#\n"
|
|
|
|
"#FFFF00 https://github.com/#\n"
|
|
|
|
"#FFFF00 JF002/InfiniTime#");
|
|
|
|
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(3, 4, app, label));
|
|
|
|
}
|