mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Warn & Suspend when the battery is too low
Change-Id: I814697b36f6111198dc367d4591371e6a6e260d8
This commit is contained in:
@@ -16,8 +16,9 @@ app_objs += $(addprefix apps/,\
|
||||
battery_timer.o\
|
||||
battery_view.o\
|
||||
constant.o\
|
||||
global_preferences.o\
|
||||
empty_battery_window.o\
|
||||
exam_pop_up_controller.o\
|
||||
global_preferences.o\
|
||||
i18n.o\
|
||||
led_timer.o\
|
||||
main.o\
|
||||
|
||||
@@ -12,6 +12,7 @@ using namespace Shared;
|
||||
AppsContainer::AppsContainer() :
|
||||
Container(),
|
||||
m_window(AppsWindow()),
|
||||
m_emptyBatteryWindow(EmptyBatteryWindow()),
|
||||
m_homeApp(this),
|
||||
m_graphApp(this, &m_globalContext),
|
||||
m_probabilityApp(this),
|
||||
@@ -29,6 +30,7 @@ AppsContainer::AppsContainer() :
|
||||
m_USBTimer(USBTimer(this))
|
||||
{
|
||||
refreshPreferences();
|
||||
m_emptyBatteryWindow.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
|
||||
}
|
||||
|
||||
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() {
|
||||
return &m_window;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "settings/app.h"
|
||||
#include "statistics/app.h"
|
||||
#include "apps_window.h"
|
||||
#include "empty_battery_window.h"
|
||||
#include "math_toolbox.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include "exam_pop_up_controller.h"
|
||||
@@ -38,12 +39,14 @@ public:
|
||||
void updateBatteryState();
|
||||
void refreshPreferences();
|
||||
void displayExamModePopUp(bool activate, bool forceRedrawWindow);
|
||||
void shutdownDueToLowBattery();
|
||||
private:
|
||||
Window * window() override;
|
||||
int numberOfTimers() override;
|
||||
Timer * timerAtIndex(int i) override;
|
||||
static constexpr int k_numberOfApps = 9;
|
||||
AppsWindow m_window;
|
||||
EmptyBatteryWindow m_emptyBatteryWindow;
|
||||
Home::App m_homeApp;
|
||||
Graph::App m_graphApp;
|
||||
Probability::App m_probabilityApp;
|
||||
|
||||
@@ -9,4 +9,7 @@ BatteryTimer::BatteryTimer(AppsContainer * container) :
|
||||
|
||||
void BatteryTimer::fire() {
|
||||
m_container->updateBatteryState();
|
||||
if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
|
||||
m_container->shutdownDueToLowBattery();
|
||||
}
|
||||
}
|
||||
|
||||
19
apps/empty_battery_window.cpp
Normal file
19
apps/empty_battery_window.cpp
Normal 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);
|
||||
}
|
||||
|
||||
12
apps/empty_battery_window.h
Normal file
12
apps/empty_battery_window.h
Normal 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
|
||||
@@ -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 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"},
|
||||
{"Valider", "Confirm", "Confirmar"},
|
||||
{"Annuler", "Cancel", "Cancelar"},
|
||||
{"Suivant", "Next", "Siguiente"},
|
||||
{"Attention a la syntaxe", "Syntax error", "Error sintactico"},
|
||||
{"Erreur mathematique", "Math error", "Error matematico"},
|
||||
{"Batterie faible", "Low battery", "Bateria baja"},
|
||||
|
||||
/* Variables */
|
||||
{"Variables", "Variables", "Variables"},
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace I18n {
|
||||
Next = 3,
|
||||
SyntaxError,
|
||||
MathError,
|
||||
LowBattery,
|
||||
|
||||
/* Variables */
|
||||
Variables,
|
||||
|
||||
Reference in New Issue
Block a user