aod: integrate with display timeout

This commit is contained in:
John Crawford 2023-10-01 10:38:45 -06:00 committed by JF
parent 3dca742b65
commit 85a2181b64
3 changed files with 28 additions and 17 deletions

View file

@ -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 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
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 @@ SettingDisplay::~SettingDisplay() {
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]) {

View file

@ -18,13 +18,15 @@ namespace Pinetime {
~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;
};
}
}

View file

@ -236,7 +236,7 @@ void SystemTask::Work() {
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::OnTouchEvent() {
}
void SystemTask::PushMessage(System::Messages msg) {
if (msg == Messages::GoToSleep && !doNotGoToSleep && !settingsController.GetAlwaysOnDisplay()) {
if (msg == Messages::GoToSleep && !doNotGoToSleep) {
state = SystemTaskState::GoingToSleep;
}