Author: John Crawford <coffeeboi47@protonmail.com>
aod: integrate with display timeout
src/displayapp/screens/settings/SettingDisplay.cpp | 37 +++++++++------ src/displayapp/screens/settings/SettingDisplay.h | 4 + src/systemtask/SystemTask.cpp | 4
diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index 760f1e9e0f9e2dc868127119c7d67a45ade11655..12d0f561f1b4e0a6b8c27270acaffeadf2bdb7aa 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -9,13 +9,20 @@ using namespace Pinetime::Applications::Screens; namespace { - void event_handler(lv_obj_t* obj, lv_event_t event) { + void TimeoutEventHandler(lv_obj_t* obj, lv_event_t event) { auto* screen = static_cast<SettingDisplay*>(obj->user_data); screen->UpdateSelected(obj, event); } + + void AlwaysOnEventHandler(lv_obj_t* obj, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + auto* screen = static_cast<SettingDisplay*>(obj->user_data); + screen->ToggleAlwaysOn(); + } + } } -constexpr std::array<uint16_t, 7> SettingDisplay::options; +constexpr std::array<uint16_t, 6> SettingDisplay::options; SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) : app {app}, settingsController {settingsController} { @@ -46,20 +53,23 @@ char buffer[4]; for (unsigned int i = 0; i < options.size(); i++) { cbOption[i] = lv_checkbox_create(container1, nullptr); - if (options[i] == 0) { - sprintf(buffer, "%s", "Always On"); - } else { - sprintf(buffer, "%2ds", options[i] / 1000); - } + snprintf(buffer, sizeof(buffer), "%2" PRIu16 "s", options[i] / 1000); lv_checkbox_set_text(cbOption[i], buffer); cbOption[i]->user_data = this; - lv_obj_set_event_cb(cbOption[i], event_handler); + lv_obj_set_event_cb(cbOption[i], TimeoutEventHandler); SetRadioButtonStyle(cbOption[i]); if (settingsController.GetScreenTimeOut() == options[i]) { lv_checkbox_set_checked(cbOption[i], true); } } + + alwaysOnCheckbox = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(alwaysOnCheckbox, "Always On"); + lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplay()); + lv_obj_add_state(alwaysOnCheckbox, LV_STATE_DEFAULT); + alwaysOnCheckbox->user_data = this; + lv_obj_set_event_cb(alwaysOnCheckbox, AlwaysOnEventHandler); } SettingDisplay::~SettingDisplay() { @@ -67,13 +77,12 @@ lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } -void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (settingsController.GetScreenTimeOut() == 0) { - settingsController.SetAlwaysOnDisplay(true); - } else { - settingsController.SetAlwaysOnDisplay(false); - } +void SettingDisplay::ToggleAlwaysOn() { + settingsController.SetAlwaysOnDisplay(!settingsController.GetAlwaysOnDisplay()); + lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplay()); +} +void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_CLICKED) { for (unsigned int i = 0; i < options.size(); i++) { if (object == cbOption[i]) { diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h index a43704637f57ae0d83e539aa5d533f15988fd81e..b6d147c829156d671651d9816cc4b6f0543d3ac2 100644 --- a/src/displayapp/screens/settings/SettingDisplay.h +++ b/src/displayapp/screens/settings/SettingDisplay.h @@ -18,13 +18,15 @@ SettingDisplay(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); ~SettingDisplay() override; void UpdateSelected(lv_obj_t* object, lv_event_t event); + void ToggleAlwaysOn(); private: DisplayApp* app; - static constexpr std::array<uint16_t, 7> options = {5000, 7000, 10000, 15000, 20000, 30000, 0}; + static constexpr std::array<uint16_t, 6> options = {5000, 7000, 10000, 15000, 20000, 30000}; Controllers::Settings& settingsController; lv_obj_t* cbOption[options.size()]; + lv_obj_t* alwaysOnCheckbox; }; } } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 0dea5f9813f42a7c96c873efb0d3efe49f2c029e..5bd71c389d3ad879486ac1efc6aa3ffcb1d7b868 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -236,7 +236,7 @@ } break; } case Messages::GoToSleep: - if (doNotGoToSleep or settingsController.GetAlwaysOnDisplay()) { + if (doNotGoToSleep) { break; } state = SystemTaskState::GoingToSleep; // Already set in PushMessage() @@ -512,7 +512,7 @@ } } void SystemTask::PushMessage(System::Messages msg) { - if (msg == Messages::GoToSleep && !doNotGoToSleep && !settingsController.GetAlwaysOnDisplay()) { + if (msg == Messages::GoToSleep && !doNotGoToSleep) { state = SystemTaskState::GoingToSleep; }