Initialize SystemTask, DisplayApp and HeartRateTask as global static variable instead of variables on the heap. We don't need them on the heap as we know their size at build time, it'll reduce memory fragmentation and it'll make memory analysis easier.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "drivers/St7789.h"
|
||||
#include "drivers/Watchdog.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include "systemtask/Messages.h"
|
||||
|
||||
#include "displayapp/screens/settings/QuickSettings.h"
|
||||
#include "displayapp/screens/settings/Settings.h"
|
||||
@@ -51,7 +52,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||
Controllers::Ble& bleController,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Drivers::WatchdogView& watchdog,
|
||||
System::SystemTask& systemTask,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Pinetime::Controllers::HeartRateController& heartRateController,
|
||||
Controllers::Settings& settingsController,
|
||||
@@ -65,7 +65,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||
bleController {bleController},
|
||||
dateTimeController {dateTimeController},
|
||||
watchdog {watchdog},
|
||||
systemTask {systemTask},
|
||||
notificationManager {notificationManager},
|
||||
heartRateController {heartRateController},
|
||||
settingsController {settingsController},
|
||||
@@ -130,7 +129,7 @@ void DisplayApp::Refresh() {
|
||||
vTaskDelay(100);
|
||||
}
|
||||
lcd.DisplayOff();
|
||||
systemTask.PushMessage(System::SystemTask::Messages::OnDisplayTaskSleeping);
|
||||
PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping);
|
||||
state = States::Idle;
|
||||
break;
|
||||
case Messages::GoToRunning:
|
||||
@@ -139,7 +138,7 @@ void DisplayApp::Refresh() {
|
||||
state = States::Running;
|
||||
break;
|
||||
case Messages::UpdateTimeOut:
|
||||
systemTask.PushMessage(System::SystemTask::Messages::UpdateTimeOut);
|
||||
PushMessageToSystemTask(System::Messages::UpdateTimeOut);
|
||||
break;
|
||||
case Messages::UpdateBleConnection:
|
||||
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
|
||||
@@ -176,7 +175,7 @@ void DisplayApp::Refresh() {
|
||||
LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
|
||||
break;
|
||||
case TouchEvents::DoubleTap:
|
||||
systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
|
||||
PushMessageToSystemTask(System::Messages::GoToSleep);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -188,7 +187,7 @@ void DisplayApp::Refresh() {
|
||||
} break;
|
||||
case Messages::ButtonPushed:
|
||||
if (currentApp == Apps::Clock) {
|
||||
systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
|
||||
PushMessageToSystemTask(System::Messages::GoToSleep);
|
||||
} else {
|
||||
if (!currentScreen->OnButtonPushed()) {
|
||||
LoadApp(returnToApp, returnDirection);
|
||||
@@ -267,12 +266,12 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||
|
||||
case Apps::Notifications:
|
||||
currentScreen = std::make_unique<Screens::Notifications>(
|
||||
this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal);
|
||||
this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Normal);
|
||||
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
|
||||
break;
|
||||
case Apps::NotificationsPreview:
|
||||
currentScreen = std::make_unique<Screens::Notifications>(
|
||||
this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview);
|
||||
this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Preview);
|
||||
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
|
||||
break;
|
||||
case Apps::Timer:
|
||||
@@ -321,7 +320,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||
//
|
||||
|
||||
case Apps::FlashLight:
|
||||
currentScreen = std::make_unique<Screens::FlashLight>(this, systemTask, brightnessController);
|
||||
currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController);
|
||||
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
|
||||
break;
|
||||
case Apps::StopWatch:
|
||||
@@ -337,13 +336,13 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||
currentScreen = std::make_unique<Screens::Paddle>(this, lvgl);
|
||||
break;
|
||||
case Apps::Music:
|
||||
currentScreen = std::make_unique<Screens::Music>(this, systemTask.nimble().music());
|
||||
currentScreen = std::make_unique<Screens::Music>(this, systemTask->nimble().music());
|
||||
break;
|
||||
case Apps::Navigation:
|
||||
currentScreen = std::make_unique<Screens::Navigation>(this, systemTask.nimble().navigation());
|
||||
currentScreen = std::make_unique<Screens::Navigation>(this, systemTask->nimble().navigation());
|
||||
break;
|
||||
case Apps::HeartRate:
|
||||
currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, systemTask);
|
||||
currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, *systemTask);
|
||||
break;
|
||||
case Apps::Motion:
|
||||
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
|
||||
@@ -425,3 +424,12 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
|
||||
void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) {
|
||||
touchMode = mode;
|
||||
}
|
||||
|
||||
void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
|
||||
if(systemTask != nullptr)
|
||||
systemTask->PushMessage(message);
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
|
||||
this->systemTask = systemTask;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <queue.h>
|
||||
#include <task.h>
|
||||
#include <memory>
|
||||
#include <systemtask/Messages.h>
|
||||
#include "Apps.h"
|
||||
#include "LittleVgl.h"
|
||||
#include "TouchEvents.h"
|
||||
@@ -49,7 +50,6 @@ namespace Pinetime {
|
||||
Controllers::Ble& bleController,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Drivers::WatchdogView& watchdog,
|
||||
System::SystemTask& systemTask,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Pinetime::Controllers::HeartRateController& heartRateController,
|
||||
Controllers::Settings& settingsController,
|
||||
@@ -64,6 +64,8 @@ namespace Pinetime {
|
||||
void SetFullRefresh(FullRefreshDirections direction);
|
||||
void SetTouchMode(TouchModes mode);
|
||||
|
||||
void Register(Pinetime::System::SystemTask* systemTask);
|
||||
|
||||
private:
|
||||
Pinetime::Drivers::St7789& lcd;
|
||||
Pinetime::Components::LittleVgl& lvgl;
|
||||
@@ -72,7 +74,7 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Controllers::DateTime& dateTimeController;
|
||||
Pinetime::Drivers::WatchdogView& watchdog;
|
||||
Pinetime::System::SystemTask& systemTask;
|
||||
Pinetime::System::SystemTask* systemTask = nullptr;
|
||||
Pinetime::Controllers::NotificationManager& notificationManager;
|
||||
Pinetime::Controllers::HeartRateController& heartRateController;
|
||||
Pinetime::Controllers::Settings& settingsController;
|
||||
@@ -108,6 +110,7 @@ namespace Pinetime {
|
||||
void Refresh();
|
||||
void ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction, TouchEvents touchEvent);
|
||||
void LoadApp(Apps app, DisplayApp::FullRefreshDirections direction);
|
||||
void PushMessageToSystemTask(Pinetime::System::Messages message);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -39,14 +39,14 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
|
||||
backgroundAction->user_data = this;
|
||||
lv_obj_set_event_cb(backgroundAction, event_handler);
|
||||
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::DisableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
||||
}
|
||||
|
||||
FlashLight::~FlashLight() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000));
|
||||
brightness.Restore();
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::EnableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
||||
}
|
||||
|
||||
void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
|
||||
|
@@ -63,12 +63,12 @@ HeartRate::HeartRate(Pinetime::Applications::DisplayApp* app,
|
||||
label_startStop = lv_label_create(btn_startStop, nullptr);
|
||||
UpdateStartStopButton(isHrRunning);
|
||||
if (isHrRunning)
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::DisableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
||||
}
|
||||
|
||||
HeartRate::~HeartRate() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::EnableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
||||
}
|
||||
|
||||
bool HeartRate::Refresh() {
|
||||
@@ -95,12 +95,12 @@ void HeartRate::OnStartStopEvent(lv_event_t event) {
|
||||
if (heartRateController.State() == Controllers::HeartRateController::States::Stopped) {
|
||||
heartRateController.Start();
|
||||
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::DisableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
|
||||
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
||||
} else {
|
||||
heartRateController.Stop();
|
||||
UpdateStartStopButton(heartRateController.State() != Controllers::HeartRateController::States::Stopped);
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::EnableSleeping);
|
||||
systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
|
||||
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||
}
|
||||
}
|
||||
|
@@ -15,12 +15,17 @@ namespace Pinetime {
|
||||
public:
|
||||
ScreenList(DisplayApp* app,
|
||||
uint8_t initScreen,
|
||||
std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens,
|
||||
const std::array<std::function<std::unique_ptr<Screen>()>, N>&& screens,
|
||||
ScreenListModes mode)
|
||||
: Screen(app), initScreen {initScreen}, screens {std::move(screens)}, mode {mode}, current {this->screens[initScreen]()} {
|
||||
screenIndex = initScreen;
|
||||
: Screen(app), initScreen {initScreen}, screens {std::move(screens)}, mode {mode}, screenIndex{initScreen}, current {this->screens[initScreen]()} {
|
||||
|
||||
}
|
||||
|
||||
ScreenList(const ScreenList&) = delete;
|
||||
ScreenList& operator=(const ScreenList&) = delete;
|
||||
ScreenList(ScreenList&&) = delete;
|
||||
ScreenList& operator=(ScreenList&&) = delete;
|
||||
|
||||
~ScreenList() override {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
@@ -97,7 +102,7 @@ namespace Pinetime {
|
||||
|
||||
private:
|
||||
uint8_t initScreen = 0;
|
||||
std::array<std::function<std::unique_ptr<Screen>()>, N> screens;
|
||||
const std::array<std::function<std::unique_ptr<Screen>()>, N> screens;
|
||||
ScreenListModes mode = ScreenListModes::UpDown;
|
||||
|
||||
uint8_t screenIndex = 0;
|
||||
|
@@ -7,12 +7,12 @@ using namespace Pinetime::Applications::Screens;
|
||||
|
||||
namespace {
|
||||
static void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||
QuickSettings* screen = static_cast<QuickSettings*>(obj->user_data);
|
||||
auto* screen = static_cast<QuickSettings*>(obj->user_data);
|
||||
screen->OnButtonEvent(obj, event);
|
||||
}
|
||||
|
||||
static void lv_update_task(struct _lv_task_t* task) {
|
||||
auto user_data = static_cast<QuickSettings*>(task->user_data);
|
||||
auto* user_data = static_cast<QuickSettings*>(task->user_data);
|
||||
user_data->UpdateScreen();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user