summaryrefslogtreecommitdiff
path: root/src/systemtask/SystemTask.cpp
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-07-24 21:29:10 +0300
committerGitHub <noreply@github.com>2021-07-24 20:29:10 +0200
commit34949a47c59e7a4d8f67a0188bba6d08a046340d (patch)
tree0a73f39c35ecc8eb46908ef6bdd4272183ac7387 /src/systemtask/SystemTask.cpp
parentce26ef8a67f75e551975942c3217a4fd6846f591 (diff)
Dim screen before sleep (#464)
* Implement dimming
Diffstat (limited to 'src/systemtask/SystemTask.cpp')
-rw-r--r--src/systemtask/SystemTask.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 7efd1d6b..8915ce74 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -33,6 +33,13 @@ namespace {
}
}
+void DimTimerCallback(TimerHandle_t xTimer) {
+
+ NRF_LOG_INFO("DimTimerCallback");
+ auto sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
+ sysTask->OnDim();
+}
+
void IdleTimerCallback(TimerHandle_t xTimer) {
NRF_LOG_INFO("IdleTimerCallback");
@@ -105,7 +112,7 @@ void SystemTask::Work() {
APP_GPIOTE_INIT(2);
app_timer_init();
-
+
spi.Init();
spiNorFlash.Init();
spiNorFlash.Wakeup();
@@ -114,7 +121,6 @@ void SystemTask::Work() {
nimbleController.Init();
nimbleController.StartAdvertising();
- brightnessController.Init();
lcd.Init();
twiMaster.Init();
@@ -179,8 +185,9 @@ void SystemTask::Work() {
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
}
- idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), pdFALSE, this, IdleTimerCallback);
- xTimerStart(idleTimer, 0);
+ idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
+ dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
+ xTimerStart(dimTimer, 0);
// Suppress endless loop diagnostic
#pragma clang diagnostic push
@@ -208,7 +215,7 @@ void SystemTask::Work() {
doNotGoToSleep = true;
break;
case Messages::UpdateTimeOut:
- xTimerChangePeriod(idleTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), 0);
+ xTimerChangePeriod(dimTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), 0);
break;
case Messages::GoToRunning:
spi.Wakeup();
@@ -220,7 +227,7 @@ void SystemTask::Work() {
}
nimbleController.StartAdvertising();
- xTimerStart(idleTimer, 0);
+ xTimerStart(dimTimer, 0);
spiNorFlash.Wakeup();
lcd.Wakeup();
@@ -230,6 +237,7 @@ void SystemTask::Work() {
isSleeping = false;
isWakingUp = false;
+ isDimmed = false;
break;
case Messages::TouchWakeUp: {
twiMaster.Wakeup();
@@ -246,6 +254,7 @@ void SystemTask::Work() {
isGoingToSleep = true;
NRF_LOG_INFO("[systemtask] Going to sleep");
xTimerStop(idleTimer, 0);
+ xTimerStop(dimTimer, 0);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
break;
@@ -283,13 +292,15 @@ void SystemTask::Work() {
NVIC_SystemReset();
}
doNotGoToSleep = false;
- xTimerStart(idleTimer, 0);
+ xTimerStart(dimTimer, 0);
break;
case Messages::OnTouchEvent:
ReloadIdleTimer();
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::OnButtonEvent:
ReloadIdleTimer();
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
break;
case Messages::OnDisplayTaskSleeping:
if (BootloaderVersion::IsValid()) {
@@ -381,7 +392,6 @@ void SystemTask::OnButtonPushed() {
if (!isSleeping) {
NRF_LOG_INFO("[systemtask] Button pushed");
PushMessage(Messages::OnButtonEvent);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
} else {
if (!isWakingUp) {
NRF_LOG_INFO("[systemtask] Button pushed, waking up");
@@ -402,7 +412,6 @@ void SystemTask::OnTouchEvent() {
return;
if (!isSleeping) {
PushMessage(Messages::OnTouchEvent);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
} else if (!isWakingUp) {
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
@@ -430,6 +439,15 @@ void SystemTask::PushMessage(System::Messages msg) {
}
}
+void SystemTask::OnDim() {
+ if (doNotGoToSleep)
+ return;
+ NRF_LOG_INFO("Dim timeout -> Dim screen")
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::DimScreen);
+ xTimerStart(idleTimer, 0);
+ isDimmed = true;
+}
+
void SystemTask::OnIdle() {
if (doNotGoToSleep)
return;
@@ -437,8 +455,13 @@ void SystemTask::OnIdle() {
PushMessage(Messages::GoToSleep);
}
-void SystemTask::ReloadIdleTimer() const {
+void SystemTask::ReloadIdleTimer() {
if (isSleeping || isGoingToSleep)
return;
- xTimerReset(idleTimer, 0);
+ if (isDimmed) {
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
+ isDimmed = false;
+ }
+ xTimerReset(dimTimer, 0);
+ xTimerStop(idleTimer, 0);
}