diff --git a/apps/Makefile b/apps/Makefile index 6a76e3d2d..b856014c9 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -16,6 +16,7 @@ app_objs += $(addprefix apps/,\ battery_timer.o\ battery_view.o\ constant.o\ + backlight_dimming_timer.o\ empty_battery_window.o\ exam_pop_up_controller.o\ global_preferences.o\ @@ -24,6 +25,7 @@ app_objs += $(addprefix apps/,\ main.o\ math_toolbox.o\ node.o\ + suspend_timer.o\ title_bar_view.o\ toolbox_node.o\ usb_timer.o\ diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 4227eb7ea..473b517e9 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -27,7 +27,9 @@ AppsContainer::AppsContainer() : m_examPopUpController(ExamPopUpController()), m_ledTimer(LedTimer()), m_batteryTimer(BatteryTimer(this)), - m_USBTimer(USBTimer(this)) + m_USBTimer(USBTimer(this)), + m_suspendTimer(SuspendTimer(this)), + m_backlightDimmingTimer(BacklightDimmingTimer()) { refreshPreferences(); m_emptyBatteryWindow.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height)); @@ -75,18 +77,25 @@ VariableBoxController * AppsContainer::variableBoxController() { return &m_variableBoxController; } +void AppsContainer::suspend() { + Ion::Power::suspend(); + /* Ion::Power::suspend() completely shuts down the LCD controller. Therefore + * the frame memory is lost. That's why we need to force a window redraw + * upon wakeup, otherwise the screen is filled with noise. */ + window()->redraw(true); +} + bool AppsContainer::dispatchEvent(Ion::Events::Event event) { + m_backlightDimmingTimer.reset(); + m_suspendTimer.reset(); + Ion::Backlight::setBrightness(Ion::Backlight::MaxBrightness); // Home and Power buttons are not sent to apps. We handle them straight away. if (event == Ion::Events::Home && activeApp() != &m_hardwareTestApp) { switchTo(appAtIndex(0)); return true; } if (event == Ion::Events::OnOff && activeApp() != &m_hardwareTestApp) { - Ion::Power::suspend(); - /* Ion::Power::suspend() completely shuts down the LCD controller. Therefore - * the frame memory is lost. That's why we need to force a window redraw - * upon wakeup, otherwise the screen is filled with noise. */ - window()->redraw(true); + suspend(); return true; } bool didProcessEvent = Container::dispatchEvent(event); @@ -134,7 +143,7 @@ Window * AppsContainer::window() { } int AppsContainer::numberOfTimers() { - return 2+(GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate); + return 4+(GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate); } Timer * AppsContainer::timerAtIndex(int i) { @@ -144,6 +153,10 @@ Timer * AppsContainer::timerAtIndex(int i) { case 1: return &m_USBTimer; case 2: + return &m_suspendTimer; + case 3: + return &m_backlightDimmingTimer; + case 4: return &m_ledTimer; default: assert(false); diff --git a/apps/apps_container.h b/apps/apps_container.h index 258e81a8b..5337d5aec 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -18,6 +18,8 @@ #include "led_timer.h" #include "battery_timer.h" #include "usb_timer.h" +#include "suspend_timer.h" +#include "backlight_dimming_timer.h" #define USE_PIC_VIEW_APP 0 #if USE_PIC_VIEW_APP @@ -35,6 +37,7 @@ public: Poincare::Context * globalContext(); MathToolbox * mathToolbox(); VariableBoxController * variableBoxController(); + void suspend(); virtual bool dispatchEvent(Ion::Events::Event event) override; void switchTo(App * app) override; void updateBatteryState(); @@ -67,6 +70,8 @@ private: LedTimer m_ledTimer; BatteryTimer m_batteryTimer; USBTimer m_USBTimer; + SuspendTimer m_suspendTimer; + BacklightDimmingTimer m_backlightDimmingTimer; }; #endif diff --git a/apps/backlight_dimming_timer.cpp b/apps/backlight_dimming_timer.cpp new file mode 100644 index 000000000..58be974eb --- /dev/null +++ b/apps/backlight_dimming_timer.cpp @@ -0,0 +1,10 @@ +#include "backlight_dimming_timer.h" + +BacklightDimmingTimer::BacklightDimmingTimer() : + Timer(k_idleBeforeDimmingDuration/Timer::TickDuration) +{ +} + +void BacklightDimmingTimer::fire() { + Ion::Backlight::setBrightness(k_dimBacklightBrightness); +} diff --git a/apps/backlight_dimming_timer.h b/apps/backlight_dimming_timer.h new file mode 100644 index 000000000..85e8138ea --- /dev/null +++ b/apps/backlight_dimming_timer.h @@ -0,0 +1,16 @@ +#ifndef APPS_BACKLIGHT_DIMMING_TIMER_H +#define APPS_BACKLIGHT_DIMMING_TIMER_H + +#include + +class BacklightDimmingTimer : public Timer { +public: + BacklightDimmingTimer(); +private: + constexpr static int k_idleBeforeDimmingDuration = 30*1000; // In miliseconds + constexpr static int k_dimBacklightBrightness = 0; // Intensity value from 0 to 15 + void fire() override; +}; + +#endif + diff --git a/apps/suspend_timer.cpp b/apps/suspend_timer.cpp new file mode 100644 index 000000000..48fa53fc2 --- /dev/null +++ b/apps/suspend_timer.cpp @@ -0,0 +1,12 @@ +#include "suspend_timer.h" +#include "apps_container.h" + +SuspendTimer::SuspendTimer(AppsContainer * container) : + Timer(k_idleBeforeSuspendDuration/Timer::TickDuration), + m_container(container) +{ +} + +void SuspendTimer::fire() { + m_container->suspend(); +} diff --git a/apps/suspend_timer.h b/apps/suspend_timer.h new file mode 100644 index 000000000..3124fc246 --- /dev/null +++ b/apps/suspend_timer.h @@ -0,0 +1,18 @@ +#ifndef APPS_SUSPEND_TIMER_H +#define APPS_SUSPEND_TIMER_H + +#include + +class AppsContainer; + +class SuspendTimer : public Timer { +public: + SuspendTimer(AppsContainer * container); +private: + constexpr static int k_idleBeforeSuspendDuration = 5*60*1000; // In miliseconds + void fire() override; + AppsContainer * m_container; +}; + +#endif + diff --git a/ion/include/ion/backlight.h b/ion/include/ion/backlight.h index bf464fb43..8c650128e 100644 --- a/ion/include/ion/backlight.h +++ b/ion/include/ion/backlight.h @@ -6,6 +6,7 @@ namespace Ion { namespace Backlight { +constexpr uint8_t MaxBrightness = 240; void setBrightness(uint8_t b); uint8_t brightness(); diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index 04147327c..5b78d82bd 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -1,4 +1,5 @@ objs += $(addprefix ion/src/simulator/, \ + backlight.o\ battery.o\ init.o\ led.o\ diff --git a/ion/src/simulator/backlight.cpp b/ion/src/simulator/backlight.cpp new file mode 100644 index 000000000..6c7a0d02c --- /dev/null +++ b/ion/src/simulator/backlight.cpp @@ -0,0 +1,9 @@ +#include + +uint8_t Ion::Backlight::brightness() { + return 0; +} + +void Ion::Backlight::setBrightness(uint8_t b) { + return; +}