[apps] Warn & Suspend when the battery is too low

Change-Id: I814697b36f6111198dc367d4591371e6a6e260d8
This commit is contained in:
Émilie Feral
2017-04-13 14:46:23 +02:00
parent e5610b2916
commit 9ecb2c0c53
8 changed files with 53 additions and 2 deletions

View File

@@ -16,8 +16,9 @@ app_objs += $(addprefix apps/,\
battery_timer.o\ battery_timer.o\
battery_view.o\ battery_view.o\
constant.o\ constant.o\
global_preferences.o\ empty_battery_window.o\
exam_pop_up_controller.o\ exam_pop_up_controller.o\
global_preferences.o\
i18n.o\ i18n.o\
led_timer.o\ led_timer.o\
main.o\ main.o\

View File

@@ -12,6 +12,7 @@ using namespace Shared;
AppsContainer::AppsContainer() : AppsContainer::AppsContainer() :
Container(), Container(),
m_window(AppsWindow()), m_window(AppsWindow()),
m_emptyBatteryWindow(EmptyBatteryWindow()),
m_homeApp(this), m_homeApp(this),
m_graphApp(this, &m_globalContext), m_graphApp(this, &m_globalContext),
m_probabilityApp(this), m_probabilityApp(this),
@@ -29,6 +30,7 @@ AppsContainer::AppsContainer() :
m_USBTimer(USBTimer(this)) m_USBTimer(USBTimer(this))
{ {
refreshPreferences(); refreshPreferences();
m_emptyBatteryWindow.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
} }
int AppsContainer::numberOfApps() { int AppsContainer::numberOfApps() {
@@ -115,6 +117,15 @@ void AppsContainer::displayExamModePopUp(bool activate, bool forceWindowRedraw)
} }
} }
void AppsContainer::shutdownDueToLowBattery() {
while (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
m_emptyBatteryWindow.redraw(true);
Ion::msleep(3000);
Ion::Power::suspend();
}
window()->redraw(true);
}
Window * AppsContainer::window() { Window * AppsContainer::window() {
return &m_window; return &m_window;
} }

View File

@@ -11,6 +11,7 @@
#include "settings/app.h" #include "settings/app.h"
#include "statistics/app.h" #include "statistics/app.h"
#include "apps_window.h" #include "apps_window.h"
#include "empty_battery_window.h"
#include "math_toolbox.h" #include "math_toolbox.h"
#include "variable_box_controller.h" #include "variable_box_controller.h"
#include "exam_pop_up_controller.h" #include "exam_pop_up_controller.h"
@@ -38,12 +39,14 @@ public:
void updateBatteryState(); void updateBatteryState();
void refreshPreferences(); void refreshPreferences();
void displayExamModePopUp(bool activate, bool forceRedrawWindow); void displayExamModePopUp(bool activate, bool forceRedrawWindow);
void shutdownDueToLowBattery();
private: private:
Window * window() override; Window * window() override;
int numberOfTimers() override; int numberOfTimers() override;
Timer * timerAtIndex(int i) override; Timer * timerAtIndex(int i) override;
static constexpr int k_numberOfApps = 9; static constexpr int k_numberOfApps = 9;
AppsWindow m_window; AppsWindow m_window;
EmptyBatteryWindow m_emptyBatteryWindow;
Home::App m_homeApp; Home::App m_homeApp;
Graph::App m_graphApp; Graph::App m_graphApp;
Probability::App m_probabilityApp; Probability::App m_probabilityApp;

View File

@@ -9,4 +9,7 @@ BatteryTimer::BatteryTimer(AppsContainer * container) :
void BatteryTimer::fire() { void BatteryTimer::fire() {
m_container->updateBatteryState(); m_container->updateBatteryState();
if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
m_container->shutdownDueToLowBattery();
}
} }

View File

@@ -0,0 +1,19 @@
#include "empty_battery_window.h"
#include "i18n.h"
#include "global_preferences.h"
extern "C" {
#include <assert.h>
}
EmptyBatteryWindow::EmptyBatteryWindow() :
Window()
{
}
void EmptyBatteryWindow::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
const char * warningMessage = I18n::translate(I18n::Message::LowBattery, GlobalPreferences::sharedGlobalPreferences()->language());
KDSize warningSize = KDText::stringSize(warningMessage, KDText::FontSize::Large);
ctx->drawString(warningMessage, KDPoint((Ion::Display::Width - warningSize.width())/2, (Ion::Display::Height - warningSize.height())/2), KDText::FontSize::Large);
}

View File

@@ -0,0 +1,12 @@
#ifndef APPS_EMPTY_BATTERY_WINDOW_H
#define APPS_EMPTY_BATTERY_WINDOW_H
#include <escher.h>
class EmptyBatteryWindow : public Window {
public:
EmptyBatteryWindow();
void drawRect(KDContext * ctx, KDRect rect) const;
};
#endif

View File

@@ -17,13 +17,14 @@ constexpr static char deviationFrenchDefinition[] = {Ion::Charset::SmallSigma, '
constexpr static char deviationEnglishDefinition[] = {Ion::Charset::SmallSigma, ' ', ':', ' ', 'S', 't', 'a', 'n', 'd', 'a', 'r', 'd', ' ','d','e', 'v', 'i', 'a', 't','i','o','n', 0}; constexpr static char deviationEnglishDefinition[] = {Ion::Charset::SmallSigma, ' ', ':', ' ', 'S', 't', 'a', 'n', 'd', 'a', 'r', 'd', ' ','d','e', 'v', 'i', 'a', 't','i','o','n', 0};
constexpr static char deviationSpanishDefinition[] = {Ion::Charset::SmallSigma, ' ', ':', ' ', 'D', 'e','s','v','i','a','c','i','o','n',' ','t','i','p','i','c','a',0}; constexpr static char deviationSpanishDefinition[] = {Ion::Charset::SmallSigma, ' ', ':', ' ', 'D', 'e','s','v','i','a','c','i','o','n',' ','t','i','p','i','c','a',0};
const char * messages[210][3] { const char * messages[211][3] {
{"Attention", "Warning", "Cuidado"}, {"Attention", "Warning", "Cuidado"},
{"Valider", "Confirm", "Confirmar"}, {"Valider", "Confirm", "Confirmar"},
{"Annuler", "Cancel", "Cancelar"}, {"Annuler", "Cancel", "Cancelar"},
{"Suivant", "Next", "Siguiente"}, {"Suivant", "Next", "Siguiente"},
{"Attention a la syntaxe", "Syntax error", "Error sintactico"}, {"Attention a la syntaxe", "Syntax error", "Error sintactico"},
{"Erreur mathematique", "Math error", "Error matematico"}, {"Erreur mathematique", "Math error", "Error matematico"},
{"Batterie faible", "Low battery", "Bateria baja"},
/* Variables */ /* Variables */
{"Variables", "Variables", "Variables"}, {"Variables", "Variables", "Variables"},

View File

@@ -11,6 +11,7 @@ namespace I18n {
Next = 3, Next = 3,
SyntaxError, SyntaxError,
MathError, MathError,
LowBattery,
/* Variables */ /* Variables */
Variables, Variables,