@@ -33,6 +33,13 @@ namespace {
3333 }
3434}
3535
36+ void DimTimerCallback (TimerHandle_t xTimer) {
37+
38+ NRF_LOG_INFO (" DimTimerCallback" );
39+ auto sysTask = static_cast <SystemTask*>(pvTimerGetTimerID (xTimer));
40+ sysTask->OnDim ();
41+ }
42+
3643void IdleTimerCallback (TimerHandle_t xTimer) {
3744
3845 NRF_LOG_INFO (" IdleTimerCallback" );
@@ -105,7 +112,7 @@ void SystemTask::Work() {
105112 APP_GPIOTE_INIT (2 );
106113
107114 app_timer_init ();
108-
115+
109116 spi.Init ();
110117 spiNorFlash.Init ();
111118 spiNorFlash.Wakeup ();
@@ -114,7 +121,6 @@ void SystemTask::Work() {
114121
115122 nimbleController.Init ();
116123 nimbleController.StartAdvertising ();
117- brightnessController.Init ();
118124 lcd.Init ();
119125
120126 twiMaster.Init ();
@@ -179,8 +185,9 @@ void SystemTask::Work() {
179185 nrf_gpio_cfg_sense_input (pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
180186 }
181187
182- idleTimer = xTimerCreate (" idleTimer" , pdMS_TO_TICKS (settingsController.GetScreenTimeOut ()), pdFALSE, this , IdleTimerCallback);
183- xTimerStart (idleTimer, 0 );
188+ idleTimer = xTimerCreate (" idleTimer" , pdMS_TO_TICKS (2000 ), pdFALSE, this , IdleTimerCallback);
189+ dimTimer = xTimerCreate (" dimTimer" , pdMS_TO_TICKS (settingsController.GetScreenTimeOut () - 2000 ), pdFALSE, this , DimTimerCallback);
190+ xTimerStart (dimTimer, 0 );
184191
185192// Suppress endless loop diagnostic
186193#pragma clang diagnostic push
@@ -208,7 +215,7 @@ void SystemTask::Work() {
208215 doNotGoToSleep = true ;
209216 break ;
210217 case Messages::UpdateTimeOut:
211- xTimerChangePeriod (idleTimer , pdMS_TO_TICKS (settingsController.GetScreenTimeOut ()), 0 );
218+ xTimerChangePeriod (dimTimer , pdMS_TO_TICKS (settingsController.GetScreenTimeOut () - 2000 ), 0 );
212219 break ;
213220 case Messages::GoToRunning:
214221 spi.Wakeup ();
@@ -220,7 +227,7 @@ void SystemTask::Work() {
220227 }
221228
222229 nimbleController.StartAdvertising ();
223- xTimerStart (idleTimer , 0 );
230+ xTimerStart (dimTimer , 0 );
224231 spiNorFlash.Wakeup ();
225232 lcd.Wakeup ();
226233
@@ -230,6 +237,7 @@ void SystemTask::Work() {
230237
231238 isSleeping = false ;
232239 isWakingUp = false ;
240+ isDimmed = false ;
233241 break ;
234242 case Messages::TouchWakeUp: {
235243 twiMaster.Wakeup ();
@@ -246,6 +254,7 @@ void SystemTask::Work() {
246254 isGoingToSleep = true ;
247255 NRF_LOG_INFO (" [systemtask] Going to sleep" );
248256 xTimerStop (idleTimer, 0 );
257+ xTimerStop (dimTimer, 0 );
249258 displayApp.PushMessage (Pinetime::Applications::Display::Messages::GoToSleep);
250259 heartRateApp.PushMessage (Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
251260 break ;
@@ -283,13 +292,15 @@ void SystemTask::Work() {
283292 NVIC_SystemReset ();
284293 }
285294 doNotGoToSleep = false ;
286- xTimerStart (idleTimer , 0 );
295+ xTimerStart (dimTimer , 0 );
287296 break ;
288297 case Messages::OnTouchEvent:
289298 ReloadIdleTimer ();
299+ displayApp.PushMessage (Pinetime::Applications::Display::Messages::TouchEvent);
290300 break ;
291301 case Messages::OnButtonEvent:
292302 ReloadIdleTimer ();
303+ displayApp.PushMessage (Pinetime::Applications::Display::Messages::ButtonPushed);
293304 break ;
294305 case Messages::OnDisplayTaskSleeping:
295306 if (BootloaderVersion::IsValid ()) {
@@ -381,7 +392,6 @@ void SystemTask::OnButtonPushed() {
381392 if (!isSleeping) {
382393 NRF_LOG_INFO (" [systemtask] Button pushed" );
383394 PushMessage (Messages::OnButtonEvent);
384- displayApp.PushMessage (Pinetime::Applications::Display::Messages::ButtonPushed);
385395 } else {
386396 if (!isWakingUp) {
387397 NRF_LOG_INFO (" [systemtask] Button pushed, waking up" );
@@ -402,7 +412,6 @@ void SystemTask::OnTouchEvent() {
402412 return ;
403413 if (!isSleeping) {
404414 PushMessage (Messages::OnTouchEvent);
405- displayApp.PushMessage (Pinetime::Applications::Display::Messages::TouchEvent);
406415 } else if (!isWakingUp) {
407416 if (settingsController.isWakeUpModeOn (Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
408417 settingsController.isWakeUpModeOn (Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
@@ -430,15 +439,29 @@ void SystemTask::PushMessage(System::Messages msg) {
430439 }
431440}
432441
442+ void SystemTask::OnDim () {
443+ if (doNotGoToSleep)
444+ return ;
445+ NRF_LOG_INFO (" Dim timeout -> Dim screen" )
446+ displayApp.PushMessage (Pinetime::Applications::Display::Messages::DimScreen);
447+ xTimerStart (idleTimer, 0 );
448+ isDimmed = true ;
449+ }
450+
433451void SystemTask::OnIdle () {
434452 if (doNotGoToSleep)
435453 return ;
436454 NRF_LOG_INFO (" Idle timeout -> Going to sleep" )
437455 PushMessage (Messages::GoToSleep);
438456}
439457
440- void SystemTask::ReloadIdleTimer () const {
458+ void SystemTask::ReloadIdleTimer () {
441459 if (isSleeping || isGoingToSleep)
442460 return ;
443- xTimerReset (idleTimer, 0 );
461+ if (isDimmed) {
462+ displayApp.PushMessage (Pinetime::Applications::Display::Messages::RestoreBrightness);
463+ isDimmed = false ;
464+ }
465+ xTimerReset (dimTimer, 0 );
466+ xTimerStop (idleTimer, 0 );
444467}
0 commit comments