aod: integrate with display timeout
This commit is contained in:
parent
3dca742b65
commit
85a2181b64
|
@ -9,13 +9,20 @@
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
namespace {
|
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);
|
auto* screen = static_cast<SettingDisplay*>(obj->user_data);
|
||||||
screen->UpdateSelected(obj, event);
|
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)
|
SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||||
: app {app}, settingsController {settingsController} {
|
: app {app}, settingsController {settingsController} {
|
||||||
|
@ -46,20 +53,23 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
for (unsigned int i = 0; i < options.size(); i++) {
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||||
if (options[i] == 0) {
|
snprintf(buffer, sizeof(buffer), "%2" PRIu16 "s", options[i] / 1000);
|
||||||
sprintf(buffer, "%s", "Always On");
|
|
||||||
} else {
|
|
||||||
sprintf(buffer, "%2ds", options[i] / 1000);
|
|
||||||
}
|
|
||||||
lv_checkbox_set_text(cbOption[i], buffer);
|
lv_checkbox_set_text(cbOption[i], buffer);
|
||||||
cbOption[i]->user_data = this;
|
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]);
|
SetRadioButtonStyle(cbOption[i]);
|
||||||
|
|
||||||
if (settingsController.GetScreenTimeOut() == options[i]) {
|
if (settingsController.GetScreenTimeOut() == options[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
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() {
|
SettingDisplay::~SettingDisplay() {
|
||||||
|
@ -67,13 +77,12 @@ SettingDisplay::~SettingDisplay() {
|
||||||
settingsController.SaveSettings();
|
settingsController.SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingDisplay::ToggleAlwaysOn() {
|
||||||
if (settingsController.GetScreenTimeOut() == 0) {
|
settingsController.SetAlwaysOnDisplay(!settingsController.GetAlwaysOnDisplay());
|
||||||
settingsController.SetAlwaysOnDisplay(true);
|
lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplay());
|
||||||
} else {
|
}
|
||||||
settingsController.SetAlwaysOnDisplay(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_CLICKED) {
|
if (event == LV_EVENT_CLICKED) {
|
||||||
for (unsigned int i = 0; i < options.size(); i++) {
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
if (object == cbOption[i]) {
|
if (object == cbOption[i]) {
|
||||||
|
|
|
@ -18,13 +18,15 @@ namespace Pinetime {
|
||||||
~SettingDisplay() override;
|
~SettingDisplay() override;
|
||||||
|
|
||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
void ToggleAlwaysOn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DisplayApp* app;
|
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;
|
Controllers::Settings& settingsController;
|
||||||
lv_obj_t* cbOption[options.size()];
|
lv_obj_t* cbOption[options.size()];
|
||||||
|
lv_obj_t* alwaysOnCheckbox;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Messages::GoToSleep:
|
case Messages::GoToSleep:
|
||||||
if (doNotGoToSleep or settingsController.GetAlwaysOnDisplay()) {
|
if (doNotGoToSleep) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state = SystemTaskState::GoingToSleep; // Already set in PushMessage()
|
state = SystemTaskState::GoingToSleep; // Already set in PushMessage()
|
||||||
|
@ -512,7 +512,7 @@ void SystemTask::OnTouchEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTask::PushMessage(System::Messages msg) {
|
void SystemTask::PushMessage(System::Messages msg) {
|
||||||
if (msg == Messages::GoToSleep && !doNotGoToSleep && !settingsController.GetAlwaysOnDisplay()) {
|
if (msg == Messages::GoToSleep && !doNotGoToSleep) {
|
||||||
state = SystemTaskState::GoingToSleep;
|
state = SystemTaskState::GoingToSleep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user