[apps] Extinction and backlight timers

Change-Id: I91daf6ab78fff9ec4bc924915a17a559f9ddfa63
This commit is contained in:
Émilie Feral
2017-04-24 16:57:52 +02:00
parent 3d0917070e
commit c2b6777b58
10 changed files with 94 additions and 7 deletions

View File

@@ -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\

View File

@@ -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);

View File

@@ -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

View File

@@ -0,0 +1,10 @@
#include "backlight_dimming_timer.h"
BacklightDimmingTimer::BacklightDimmingTimer() :
Timer(k_idleBeforeDimmingDuration/Timer::TickDuration)
{
}
void BacklightDimmingTimer::fire() {
Ion::Backlight::setBrightness(k_dimBacklightBrightness);
}

View File

@@ -0,0 +1,16 @@
#ifndef APPS_BACKLIGHT_DIMMING_TIMER_H
#define APPS_BACKLIGHT_DIMMING_TIMER_H
#include <escher.h>
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

12
apps/suspend_timer.cpp Normal file
View File

@@ -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();
}

18
apps/suspend_timer.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef APPS_SUSPEND_TIMER_H
#define APPS_SUSPEND_TIMER_H
#include <escher.h>
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

View File

@@ -6,6 +6,7 @@
namespace Ion {
namespace Backlight {
constexpr uint8_t MaxBrightness = 240;
void setBrightness(uint8_t b);
uint8_t brightness();

View File

@@ -1,4 +1,5 @@
objs += $(addprefix ion/src/simulator/, \
backlight.o\
battery.o\
init.o\
led.o\

View File

@@ -0,0 +1,9 @@
#include <ion/backlight.h>
uint8_t Ion::Backlight::brightness() {
return 0;
}
void Ion::Backlight::setBrightness(uint8_t b) {
return;
}