[apps] Timers access the shared container directly

This commit is contained in:
Ruben Dashyan
2019-05-17 10:50:53 +02:00
committed by EmilieNumworks
parent 652cbae9ac
commit 5548767809
5 changed files with 14 additions and 20 deletions

View File

@@ -64,8 +64,8 @@ AppsContainer::AppsContainer() :
#elif EPSILON_BOOT_PROMPT == EPSILON_UPDATE_PROMPT
m_promptController(sPromptMessages, sPromptColors, 6),
#endif
m_batteryTimer(BatteryTimer(this)),
m_suspendTimer(SuspendTimer(this)),
m_batteryTimer(),
m_suspendTimer(),
m_backlightDimmingTimer(),
m_homeSnapshot(),
m_onBoardingSnapshot(),

View File

@@ -1,16 +1,16 @@
#include "battery_timer.h"
#include "apps_container.h"
BatteryTimer::BatteryTimer(AppsContainer * container) :
Timer(1),
m_container(container)
BatteryTimer::BatteryTimer() :
Timer(1)
{
}
bool BatteryTimer::fire() {
bool needRedrawing = m_container->updateBatteryState();
AppsContainer * container = AppsContainer::sharedAppsContainer();
bool needRedrawing = container->updateBatteryState();
if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
m_container->shutdownDueToLowBattery();
container->shutdownDueToLowBattery();
}
return needRedrawing;
}

View File

@@ -3,14 +3,11 @@
#include <escher.h>
class AppsContainer;
class BatteryTimer : public Timer {
public:
BatteryTimer(AppsContainer * container);
BatteryTimer();
private:
bool fire() override;
AppsContainer * m_container;
};
#endif

View File

@@ -1,16 +1,16 @@
#include "suspend_timer.h"
#include "apps_container.h"
SuspendTimer::SuspendTimer(AppsContainer * container) :
Timer(k_idleBeforeSuspendDuration/Timer::TickDuration),
m_container(container)
SuspendTimer::SuspendTimer() :
Timer(k_idleBeforeSuspendDuration/Timer::TickDuration)
{
}
bool SuspendTimer::fire() {
/* We could just call m_container->suspend(), but we want to notify all
/* We could just call container->suspend(), but we want to notify all
* responders in the responder chain that the calculator will be switched off,
* so we use an event to switch off the calculator. */
m_container->dispatchEvent(Ion::Events::OnOff);
AppsContainer * container = AppsContainer::sharedAppsContainer();
container->dispatchEvent(Ion::Events::OnOff);
return false;
}

View File

@@ -3,15 +3,12 @@
#include <escher.h>
class AppsContainer;
class SuspendTimer : public Timer {
public:
SuspendTimer(AppsContainer * container);
SuspendTimer();
private:
constexpr static int k_idleBeforeSuspendDuration = 5*60*1000; // In miliseconds
bool fire() override;
AppsContainer * m_container;
};
#endif