1
0
Fork 0

Add new App : Sysinfo. It displays various info about the running system : version, date/time, battery, brightness and resetreason. It contains placeholder for future use (like mac address, uptime,...).

This commit is contained in:
JF 2020-03-22 12:03:17 +01:00
parent 8ed6ffaaf8
commit fb64ba8fb6
15 changed files with 276 additions and 41 deletions

View file

@ -213,6 +213,8 @@ list(APPEND SOURCE_FILES
DisplayApp/Screens/BatteryIcon.cpp DisplayApp/Screens/BatteryIcon.cpp
DisplayApp/Screens/BleIcon.cpp DisplayApp/Screens/BleIcon.cpp
DisplayApp/Screens/Brightness.cpp DisplayApp/Screens/Brightness.cpp
DisplayApp/Screens/ScreenList.cpp
DisplayApp/Screens/Label.cpp
main.cpp main.cpp
drivers/St7789.cpp drivers/St7789.cpp
drivers/SpiMaster.cpp drivers/SpiMaster.cpp
@ -253,7 +255,8 @@ set(INCLUDE_FILES
DisplayApp/Screens/BatteryIcon.h DisplayApp/Screens/BatteryIcon.h
DisplayApp/Screens/BleIcon.cpp DisplayApp/Screens/BleIcon.cpp
DisplayApp/Screens/Brightness.h DisplayApp/Screens/Brightness.h
# DisplayApp/Screens/Tab.h DisplayApp/Screens/ScreenList.h
DisplayApp/Screens/Label.h
drivers/St7789.h drivers/St7789.h
drivers/SpiMaster.h drivers/SpiMaster.h
drivers/Watchdog.h drivers/Watchdog.h

View file

@ -36,8 +36,8 @@ void Battery::Update() {
voltage = (value * 2.0f) / (1024/3.0f); voltage = (value * 2.0f) / (1024/3.0f);
percentRemaining = ((voltage - 3.55)*100)*3.9; percentRemaining = ((voltage - 3.55)*100)*3.9;
NRF_LOG_INFO("BATTERY " NRF_LOG_FLOAT_MARKER " %% - " NRF_LOG_FLOAT_MARKER " v", NRF_LOG_FLOAT(percentRemaining), NRF_LOG_FLOAT(voltage)); // NRF_LOG_INFO("BATTERY " NRF_LOG_FLOAT_MARKER " %% - " NRF_LOG_FLOAT_MARKER " v", NRF_LOG_FLOAT(percentRemaining), NRF_LOG_FLOAT(voltage));
NRF_LOG_INFO("POWER Charging : %d - Power : %d", isCharging, isPowerPresent); // NRF_LOG_INFO("POWER Charging : %d - Power : %d", isCharging, isPowerPresent);
} }
void Battery::SaadcEventHandler(nrfx_saadc_evt_t const * event) { void Battery::SaadcEventHandler(nrfx_saadc_evt_t const * event) {

View file

@ -14,6 +14,7 @@
#include <DisplayApp/Screens/Meter.h> #include <DisplayApp/Screens/Meter.h>
#include <DisplayApp/Screens/Gauge.h> #include <DisplayApp/Screens/Gauge.h>
#include <DisplayApp/Screens/Brightness.h> #include <DisplayApp/Screens/Brightness.h>
#include <DisplayApp/Screens/ScreenList.h>
#include "../SystemTask/SystemTask.h" #include "../SystemTask/SystemTask.h"
using namespace Pinetime::Applications; using namespace Pinetime::Applications;
@ -24,13 +25,15 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd,
Controllers::Battery &batteryController, Controllers::Battery &batteryController,
Controllers::Ble &bleController, Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController, Controllers::DateTime &dateTimeController,
Pinetime::Drivers::WatchdogView& watchdog,
Pinetime::System::SystemTask& systemTask) : Pinetime::System::SystemTask& systemTask) :
lcd{lcd}, lcd{lcd},
lvgl{lvgl}, lvgl{lvgl},
touchPanel{touchPanel},
batteryController{batteryController}, batteryController{batteryController},
bleController{bleController}, bleController{bleController},
dateTimeController{dateTimeController}, dateTimeController{dateTimeController},
watchdog{watchdog},
touchPanel{touchPanel},
currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController) }, currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController) },
systemTask{systemTask} { systemTask{systemTask} {
msgQueue = xQueueCreate(queueSize, itemSize); msgQueue = xQueueCreate(queueSize, itemSize);
@ -167,7 +170,8 @@ void DisplayApp::RunningState() {
currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController));
onClockApp = true; onClockApp = true;
break; break;
case Apps::Test: currentScreen.reset(new Screens::Message(this)); break; // case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, watchdog)); break;
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break; case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break; case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break;
@ -221,3 +225,16 @@ TouchEvents DisplayApp::OnTouchEvent() {
void DisplayApp::StartApp(DisplayApp::Apps app) { void DisplayApp::StartApp(DisplayApp::Apps app) {
nextApp = app; nextApp = app;
} }
void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
switch(direction){
case DisplayApp::FullRefreshDirections::Down:
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down);
break;
case DisplayApp::FullRefreshDirections::Up:
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up);
break;
default: break;
}
}

View file

@ -15,6 +15,7 @@
#include "LittleVgl.h" #include "LittleVgl.h"
#include <date/date.h> #include <date/date.h>
#include <DisplayApp/Screens/Clock.h> #include <DisplayApp/Screens/Clock.h>
#include <drivers/Watchdog.h>
#include "TouchEvents.h" #include "TouchEvents.h"
@ -26,7 +27,9 @@ namespace Pinetime {
class DisplayApp { class DisplayApp {
public: public:
enum class States {Idle, Running}; enum class States {Idle, Running};
enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed} ; enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed};
enum class FullRefreshDirections { None, Up, Down };
DisplayApp(Pinetime::Drivers::St7789& lcd, DisplayApp(Pinetime::Drivers::St7789& lcd,
Pinetime::Components::LittleVgl& lvgl, Pinetime::Components::LittleVgl& lvgl,
@ -34,13 +37,15 @@ namespace Pinetime {
Controllers::Battery &batteryController, Controllers::Battery &batteryController,
Controllers::Ble &bleController, Controllers::Ble &bleController,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Pinetime::Drivers::WatchdogView& watchdog,
Pinetime::System::SystemTask& systemTask); Pinetime::System::SystemTask& systemTask);
void Start(); void Start();
void PushMessage(Messages msg); void PushMessage(Messages msg);
enum class Apps {None, Launcher, Clock, Test, Meter, Gauge, Brightness}; enum class Apps {None, Launcher, Clock, SysInfo, Meter, Gauge, Brightness};
void StartApp(Apps app); void StartApp(Apps app);
void SetFullRefresh(FullRefreshDirections direction);
private: private:
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
static void Process(void* instance); static void Process(void* instance);
@ -60,6 +65,7 @@ namespace Pinetime {
Pinetime::Controllers::Battery &batteryController; Pinetime::Controllers::Battery &batteryController;
Pinetime::Controllers::Ble &bleController; Pinetime::Controllers::Ble &bleController;
Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Drivers::WatchdogView& watchdog;
Pinetime::Drivers::Cst816S& touchPanel; Pinetime::Drivers::Cst816S& touchPanel;
TouchEvents OnTouchEvent(); TouchEvents OnTouchEvent();

View file

@ -37,23 +37,6 @@ Clock::Clock(DisplayApp* app,
lv_img_set_src(bleIcon, BleIcon::GetIcon(false)); lv_img_set_src(bleIcon, BleIcon::GetIcon(false));
lv_obj_align(bleIcon, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0); lv_obj_align(bleIcon, batteryIcon, LV_ALIGN_OUT_LEFT_MID, 0, 0);
// label_battery = lv_label_create(lv_scr_act(), NULL);
// lv_obj_align(label_battery, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -80, 0);
// labelStyle = const_cast<lv_style_t *>(lv_label_get_style(label_battery, LV_LABEL_STYLE_MAIN));
// labelStyle->text.font = &jetbrains_mono_bold_20;
//
// lv_style_copy(&labelBigStyle, labelStyle);
// labelBigStyle.text.font = &jetbrains_mono_extrabold_compressed;
//
// lv_label_set_style(label_battery, LV_LABEL_STYLE_MAIN, labelStyle);
// label_ble = lv_label_create(lv_scr_act(), NULL);
// lv_label_set_style(label_ble, LV_LABEL_STYLE_MAIN, labelStyle);
// lv_obj_align(label_ble, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 10, 0);
label_date = lv_label_create(lv_scr_act(), NULL); label_date = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);

View file

@ -0,0 +1,28 @@
#include <libs/lvgl/lvgl.h>
#include "Label.h"
using namespace Pinetime::Applications::Screens;
Label::Label(const char* text) : text{text} {
}
Label::~Label() {
}
void Label::Refresh() {
}
void Label::Show() {
label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_align(label, LV_LABEL_ALIGN_LEFT);
lv_obj_set_size(label, 240, 240);
lv_label_set_text(label, text);
}
void Label::Hide() {
lv_obj_clean(lv_scr_act());
}

View file

@ -0,0 +1,24 @@
#pragma once
#include <vector>
#include "Screen.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class Label {
public:
Label() = default;
explicit Label(const char* text);
~Label();
void Refresh();
void Hide();
void Show();
private:
lv_obj_t * label = nullptr;
const char* text = nullptr;
};
}
}
}

View file

@ -0,0 +1,125 @@
#include <libs/lvgl/lvgl.h>
#include <DisplayApp/DisplayApp.h>
#include "ScreenList.h"
using namespace Pinetime::Applications::Screens;
// TODO this class must be improved to receive the list of "sub screens" via pointer or
// move operation.
// It should accept many type of "sub screen" (it only supports Label for now).
// The number of sub screen it supports must be dynamic.
ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController,
Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Drivers::WatchdogView& watchdog) :
Screen(app),
dateTimeController{dateTimeController}, batteryController{batteryController}, brightnessController{brightnessController}, watchdog{watchdog} {
screens.reserve(3);
// TODO all of this is far too heavy (string processing). This should be improved.
// TODO the info (battery, time,...) should be updated in the Refresh method.
char t1[200];
auto batteryPercent = static_cast<int16_t>(batteryController.PercentRemaining());
if(batteryPercent > 100) batteryPercent = 100;
else if(batteryPercent < 0) batteryPercent = 0;
uint8_t brightness = 0;
switch(brightnessController.Level()) {
case Controllers::BrightnessController::Levels::Low: brightness = 1; break;
case Controllers::BrightnessController::Levels::Medium: brightness = 2; break;
case Controllers::BrightnessController::Levels::High: brightness = 3; break;
}
auto resetReason = [&watchdog]() {
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 "?";
}
}();
sprintf(t1, "Pinetime\n"
"Version:%d.%d.%d\n"
"Build: xx/xx/xxxx\n"
"Time: %02d:%02d:%02d\n"
"date: %02d/%02d/%04d\n"
"Uptime: xd xxhxx:xx\n"
"Battery: %d%%\n"
"Backlight: %d/3\n"
"Last reset: %s\n"
"BLE MAC: \n AA:BB:CC:DD:EE:FF", Version::Major(), Version::Minor(), Version::Patch(),
dateTimeController.Hours(), dateTimeController.Minutes(), dateTimeController.Seconds(),
dateTimeController.Day(), dateTimeController.Month(), dateTimeController.Year(),
batteryPercent, brightness, resetReason);
/*
auto t1 = "Pinetime\n"
"Version:\n"
"Build: 23/03/2020\n"
"Time: 17:23:12\n"
"date: 23/03/2020\n"
"Uptime: 2d 13h52:21\n"
"Battery: 3.56v/82%\n"
"Backlight: 2/3\n"
"Last reset: wtdg\n"
"BLE MAC: \n AA:BB:CC:DD:EE:FF";*/
screens.emplace_back(t1);
auto t2 = "Hello from\nthe developper!";
screens.emplace_back(t2);
auto t3 = "Place holder\nin case we need\nmore room!";
screens.emplace_back(t3);
auto &screen = screens[screenIndex];
screen.Show();
}
ScreenList::~ScreenList() {
lv_obj_clean(lv_scr_act());
}
bool ScreenList::Refresh() {
auto &screen = screens[screenIndex];
screen.Refresh();
return running;
}
bool ScreenList::OnButtonPushed() {
running = false;
return true;
}
bool ScreenList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
switch (event) {
case TouchEvents::SwipeDown:
if (screenIndex > 0) {
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
auto &oldScreen = screens[screenIndex];
oldScreen.Hide();
screenIndex--;
auto &newScreen = screens[screenIndex];
newScreen.Show();
}
return true;
case TouchEvents::SwipeUp:
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
if (screenIndex < screens.size() - 1) {
auto &oldScreen = screens[screenIndex];
oldScreen.Hide();
screenIndex++;
auto &newScreen = screens[screenIndex];
newScreen.Show();
}
return true;
default:
return false;
}
return false;
}

View file

@ -0,0 +1,34 @@
#pragma once
#include <vector>
#include "Screen.h"
#include "Label.h"
namespace Pinetime {
namespace Applications {
namespace Screens {
class ScreenList : public Screen {
public:
explicit ScreenList(DisplayApp* app,
Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Battery& batteryController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Drivers::WatchdogView& watchdog);
~ScreenList() override;
bool Refresh() override;
bool OnButtonPushed() override;
bool OnTouchEvent(TouchEvents event) override;
private:
bool running = true;
uint8_t screenIndex = 0;
// TODO choose another container without dynamic alloc
std::vector<Screens::Label> screens;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::BrightnessController& brightnessController;
Pinetime::Drivers::WatchdogView& watchdog;
};
}
}
}

View file

@ -126,7 +126,7 @@ void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) {
modal->Show(); modal->Show();
break; break;
case 4: case 4:
tile->StartTestApp(); tile->StartSysInfoApp();
break; break;
case 5: case 5:
tile->StartBrightnessApp(); tile->StartBrightnessApp();
@ -148,8 +148,8 @@ void Tile::StartClockApp() {
running = false; running = false;
} }
void Tile::StartTestApp() { void Tile::StartSysInfoApp() {
app->StartApp(DisplayApp::Apps::Test); app->StartApp(DisplayApp::Apps::SysInfo);
running = false; running = false;
} }

View file

@ -52,7 +52,7 @@ namespace Pinetime {
uint32_t clickCount = 0 ; uint32_t clickCount = 0 ;
uint32_t previousClickCount = 0; uint32_t previousClickCount = 0;
void StartClockApp(); void StartClockApp();
void StartTestApp(); void StartSysInfoApp();
void StartMeterApp(); void StartMeterApp();
void StartGaugeApp(); void StartGaugeApp();
bool running = true; bool running = true;

View file

@ -13,7 +13,9 @@ SystemTask::SystemTask(Pinetime::Drivers::SpiMaster &spi, Pinetime::Drivers::St7
Pinetime::Drivers::Cst816S &touchPanel, Pinetime::Components::LittleVgl &lvgl, Pinetime::Drivers::Cst816S &touchPanel, Pinetime::Components::LittleVgl &lvgl,
Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController, Pinetime::Controllers::Battery &batteryController, Pinetime::Controllers::Ble &bleController,
Pinetime::Controllers::DateTime& dateTimeController) : Pinetime::Controllers::DateTime& dateTimeController) :
spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController} { spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
bleController{bleController}, dateTimeController{dateTimeController},
watchdog{}, watchdogView{watchdog}{
systemTaksMsgQueue = xQueueCreate(10, 1); systemTaksMsgQueue = xQueueCreate(10, 1);
} }
@ -42,7 +44,7 @@ void SystemTask::Work() {
touchPanel.Init(); touchPanel.Init();
batteryController.Init(); batteryController.Init();
displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, *this)); displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, watchdogView, *this));
displayApp->Start(); displayApp->Start();
batteryController.Update(); batteryController.Update();

View file

@ -43,6 +43,7 @@ namespace Pinetime {
QueueHandle_t systemTaksMsgQueue; QueueHandle_t systemTaksMsgQueue;
bool isSleeping = false; bool isSleeping = false;
Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::Watchdog watchdog;
Pinetime::Drivers::WatchdogView watchdogView;
static constexpr uint8_t pinSpiSck = 2; static constexpr uint8_t pinSpiSck = 2;

View file

@ -19,6 +19,8 @@ void Watchdog::Setup(uint8_t timeoutSeconds) {
/* Enable reload requests */ /* Enable reload requests */
NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos);
resetReason = ActualResetReason();
} }
void Watchdog::Start() { void Watchdog::Start() {
@ -29,18 +31,18 @@ void Watchdog::Kick() {
NRF_WDT->RR[0] = WDT_RR_RR_Reload; NRF_WDT->RR[0] = WDT_RR_RR_Reload;
} }
Watchdog::ResetReasons Watchdog::ResetReason() { Watchdog::ResetReasons Watchdog::ActualResetReason() const {
uint32_t resetReason; uint32_t resetReason;
sd_power_reset_reason_get(&resetReason); sd_power_reset_reason_get(&resetReason);
sd_power_reset_reason_clr(0xFFFFFFFF); sd_power_reset_reason_clr(0xFFFFFFFF);
if(resetReason & 0x01) return ResetReasons::ResetPin; if(resetReason & 0x01u) return ResetReasons::ResetPin;
if((resetReason >> 1) & 0x01) return ResetReasons::Watchdog; if((resetReason >> 1u) & 0x01u) return ResetReasons::Watchdog;
if((resetReason >> 2) & 0x01) return ResetReasons::SoftReset; if((resetReason >> 2u) & 0x01u) return ResetReasons::SoftReset;
if((resetReason >> 3) & 0x01) return ResetReasons::CpuLockup; if((resetReason >> 3u) & 0x01u) return ResetReasons::CpuLockup;
if((resetReason >> 16) & 0x01) return ResetReasons::SystemOff; if((resetReason >> 16u) & 0x01u) return ResetReasons::SystemOff;
if((resetReason >> 17) & 0x01) return ResetReasons::LpComp; if((resetReason >> 17u) & 0x01u) return ResetReasons::LpComp;
if((resetReason >> 18) & 0x01) return ResetReasons::DebugInterface; if((resetReason >> 18u) & 0x01u) return ResetReasons::DebugInterface;
if((resetReason >> 19) & 0x01) return ResetReasons::NFC; if((resetReason >> 19u) & 0x01u) return ResetReasons::NFC;
return ResetReasons::HardReset; return ResetReasons::HardReset;
} }

View file

@ -8,10 +8,20 @@ namespace Pinetime {
void Setup(uint8_t timeoutSeconds); void Setup(uint8_t timeoutSeconds);
void Start(); void Start();
void Kick(); void Kick();
ResetReasons ResetReason() const { return resetReason; }
ResetReasons ResetReason();
static const char* ResetReasonToString(ResetReasons reason); static const char* ResetReasonToString(ResetReasons reason);
private:
ResetReasons resetReason;
ResetReasons ActualResetReason() const;
};
class WatchdogView {
public:
WatchdogView(const Watchdog& watchdog) : watchdog{watchdog} { }
Watchdog::ResetReasons ResetReason() const { return watchdog.ResetReason();}
private:
const Watchdog& watchdog;
}; };
} }
} }