2020-08-14 07:46:37 +00:00
|
|
|
#include "SystemInfo.h"
|
2020-11-15 15:49:36 +00: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 11:03:17 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp *app,
|
|
|
|
Pinetime::Controllers::DateTime &dateTimeController,
|
|
|
|
Pinetime::Controllers::Battery& batteryController,
|
|
|
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
2020-06-08 19:51:34 +00:00
|
|
|
Pinetime::Controllers::Ble& bleController,
|
2020-08-14 07:46:37 +00:00
|
|
|
Pinetime::Drivers::WatchdogView& watchdog) :
|
2020-03-22 11:03:17 +00:00
|
|
|
Screen(app),
|
2020-06-08 19:51:34 +00:00
|
|
|
dateTimeController{dateTimeController}, batteryController{batteryController},
|
2020-08-14 07:46:37 +00:00
|
|
|
brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog},
|
|
|
|
screens{app, {
|
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen1(); },
|
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen2(); },
|
|
|
|
[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); }
|
|
|
|
}
|
|
|
|
} {}
|
2020-03-22 11:03:17 +00:00
|
|
|
|
2020-03-22 11:14:38 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
SystemInfo::~SystemInfo() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInfo::Refresh() {
|
|
|
|
screens.Refresh();
|
|
|
|
return running;
|
|
|
|
}
|
2020-03-22 11:03:17 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
bool SystemInfo::OnButtonPushed() {
|
|
|
|
running = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInfo::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|
|
|
return screens.OnTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
|
2020-11-18 05:00:33 +00:00
|
|
|
auto batteryPercent = static_cast<uint8_t>(batteryController.PercentRemaining());
|
2020-03-22 11:03:17 +00:00
|
|
|
|
|
|
|
uint8_t brightness = 0;
|
|
|
|
switch(brightnessController.Level()) {
|
2020-08-17 14:31:00 +00:00
|
|
|
case Controllers::BrightnessController::Levels::Off: brightness = 0; break;
|
2020-03-22 11:03:17 +00:00
|
|
|
case Controllers::BrightnessController::Levels::Low: brightness = 1; break;
|
|
|
|
case Controllers::BrightnessController::Levels::Medium: brightness = 2; break;
|
|
|
|
case Controllers::BrightnessController::Levels::High: brightness = 3; break;
|
|
|
|
}
|
2020-08-14 07:46:37 +00:00
|
|
|
auto resetReason = [this]() {
|
2020-03-22 11:03:17 +00: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 18:04:43 +00: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 11:03:17 +00:00
|
|
|
|
|
|
|
sprintf(t1, "Pinetime\n"
|
2020-08-17 14:31:00 +00:00
|
|
|
"Version:%ld.%ld.%ld\n"
|
2020-06-07 18:16:39 +00:00
|
|
|
"Build: %s\n"
|
|
|
|
" %s\n"
|
2020-08-22 18:43:14 +00:00
|
|
|
"Date: %02d/%02d/%04d\n"
|
2020-03-22 11:03:17 +00:00
|
|
|
"Time: %02d:%02d:%02d\n"
|
2020-06-07 18:04:43 +00:00
|
|
|
"Uptime: %02lud %02lu:%02lu:%02lu\n"
|
2020-03-22 11:03:17 +00:00
|
|
|
"Battery: %d%%\n"
|
|
|
|
"Backlight: %d/3\n"
|
2020-06-07 18:16:39 +00:00
|
|
|
"Last reset: %s\n",
|
2020-08-14 07:46:37 +00:00
|
|
|
Version::Major(), Version::Minor(), Version::Patch(),
|
|
|
|
__DATE__, __TIME__,
|
2020-08-17 14:31:00 +00:00
|
|
|
dateTimeController.Day(), static_cast<uint8_t>(dateTimeController.Month()), dateTimeController.Year(),
|
2020-08-14 07:46:37 +00:00
|
|
|
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(),
|
|
|
|
uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds,
|
2020-11-18 05:00:33 +00:00
|
|
|
batteryPercent, brightness, resetReason);
|
2020-08-14 07:46:37 +00:00
|
|
|
|
2020-08-14 08:05:44 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(app, t1));
|
2020-08-14 07:46:37 +00:00
|
|
|
}
|
2020-03-22 11:03:17 +00:00
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
2020-06-08 19:51:34 +00:00
|
|
|
auto& bleAddr = bleController.Address();
|
2020-10-12 03:12:31 +00:00
|
|
|
sprintf(t2, "BLE MAC: \n %02x:%02x:%02x:%02x:%02x:%02x",
|
2020-06-08 19:51:34 +00:00
|
|
|
bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]);
|
2020-08-14 08:05:44 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(app, t2));
|
2020-03-22 11:03:17 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 07:46:37 +00:00
|
|
|
std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
|
2020-12-28 07:45:24 +00:00
|
|
|
sprintf(t3, "Hello from\nthe developer!\n"
|
|
|
|
"Software Licensed\n"
|
|
|
|
"under the terms of\n"
|
|
|
|
"the GNU General\n"
|
|
|
|
"Public License v3\n"
|
|
|
|
"Source code:\n"
|
|
|
|
"https://github.com/\n"
|
|
|
|
" JF002/Pinetime");
|
2020-08-14 08:05:44 +00:00
|
|
|
return std::unique_ptr<Screen>(new Screens::Label(app, t3));
|
2020-03-22 11:03:17 +00:00
|
|
|
}
|