[apps/hardware_test] Redesign hardware test

Change-Id: Id2c55fe66ca68ce617ea131f5cfb77d78557860b
This commit is contained in:
Émilie Feral
2017-06-01 09:43:22 +02:00
parent 3ef5b67162
commit 6afa7cd3fd
19 changed files with 586 additions and 162 deletions

View File

@@ -1,9 +1,13 @@
app_objs += $(addprefix apps/hardware_test/,\
app.o\
battery_test_controller.o\
keyboard_test_controller.o\
keyboard_view.o\
led_test_controller.o\
pattern.o\
pattern_view.o\
pop_up_controller.o\
reset_controller.o\
screen_test_controller.o\
)

View File

@@ -0,0 +1,115 @@
#include "battery_test_controller.h"
#include "../constant.h"
extern "C" {
#include <assert.h>
}
#include <poincare.h>
using namespace Poincare;
namespace HardwareTest {
BatteryTestController::BatteryTestController(Responder * parentResponder) :
ViewController(parentResponder),
m_view(),
m_resetController(this)
{
}
View * BatteryTestController::view() {
return &m_view;
}
bool BatteryTestController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK) {
if (strcmp(m_view.batteryStateTextView()->text(), k_batteryOKText) == 0) {
ModalViewController * modal = (ModalViewController *)parentResponder();
modal->displayModalViewController(&m_resetController, 0.0f, 0.0f);
}
}
return true;
}
void BatteryTestController::viewWillAppear() {
const char * text = Ion::Battery::voltage() < k_batteryThreshold ? k_batteryNeedChargingText : k_batteryOKText;
KDColor color = Ion::Battery::voltage() < k_batteryThreshold ? KDColorRed : KDColorGreen;
m_view.setColor(color);
m_view.batteryStateTextView()->setText(text);
updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
}
void BatteryTestController::updateBatteryState(float batteryLevel, bool batteryCharging) {
char bufferLevel[ContentView::k_maxNumberOfCharacters + Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
const char * legend = "Battery level: ";
int legendLength = strlen(legend);
strlcpy(bufferLevel, legend, legendLength+1);
Complex::convertFloatToText(batteryLevel, bufferLevel+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_view.batteryLevelTextView()->setText(bufferLevel);
char bufferCharging[ContentView::k_maxNumberOfCharacters + Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
int numberOfChars = 0;
legend = "Battery charging: ";
legendLength = strlen(legend);
strlcpy(bufferCharging, legend, legendLength+1);
numberOfChars += legendLength;
legend = "no";
if (batteryCharging) {
legend = "yes";
}
legendLength = strlen(legend);
strlcpy(bufferCharging+numberOfChars, legend, legendLength+1);
numberOfChars += legendLength;
bufferCharging[numberOfChars] = 0;
m_view.batteryChargingTextView()->setText(bufferCharging);
}
BatteryTestController::ContentView::ContentView() :
SolidColorView(KDColorWhite),
m_batteryStateView(KDText::FontSize::Large),
m_batteryLevelView(KDText::FontSize::Small),
m_batteryChargingView(KDText::FontSize::Small)
{
}
BufferTextView * BatteryTestController::ContentView::batteryStateTextView() {
return &m_batteryStateView;
}
BufferTextView * BatteryTestController::ContentView::batteryLevelTextView() {
return &m_batteryLevelView;
}
BufferTextView * BatteryTestController::ContentView::batteryChargingTextView() {
return &m_batteryChargingView;
}
void BatteryTestController::ContentView::setColor(KDColor color) {
SolidColorView::setColor(color);
m_batteryStateView.setBackgroundColor(color);
m_batteryLevelView.setBackgroundColor(color);
m_batteryChargingView.setBackgroundColor(color);
}
void BatteryTestController::ContentView::layoutSubviews() {
m_batteryStateView.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height/2));
KDSize textSize = KDText::stringSize(" ", KDText::FontSize::Small);
m_batteryLevelView.setFrame(KDRect(0, Ion::Display::Height-2*textSize.height(), Ion::Display::Width, textSize.height()));
m_batteryChargingView.setFrame(KDRect(0, Ion::Display::Height-textSize.height(), Ion::Display::Width, textSize.height()));
}
int BatteryTestController::ContentView::numberOfSubviews() const {
return 3;
}
View * BatteryTestController::ContentView::subviewAtIndex(int index) {
if (index == 0) {
return &m_batteryStateView;
}
if (index == 1) {
return &m_batteryLevelView;
}
return &m_batteryChargingView;
}
}

View File

@@ -0,0 +1,44 @@
#ifndef HARDWARE_TEST_BATTERY_TEST_CONTROLLER_H
#define HARDWARE_TEST_BATTERY_TEST_CONTROLLER_H
#include <escher.h>
#include "reset_controller.h"
namespace HardwareTest {
class BatteryTestController : public ViewController {
public:
BatteryTestController(Responder * parentResponder);
View * view() override;
bool handleEvent(Ion::Events::Event event) override;
void viewWillAppear() override;
private:
class ContentView : public SolidColorView {
public:
ContentView();
BufferTextView * batteryStateTextView();
BufferTextView * batteryLevelTextView();
BufferTextView * batteryChargingTextView();
constexpr static int k_maxNumberOfCharacters = 20;
void setColor(KDColor color) override;
private:
void layoutSubviews() override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
constexpr static int k_margin = 4;
BufferTextView m_batteryStateView;
BufferTextView m_batteryLevelView;
BufferTextView m_batteryChargingView;
};
constexpr static float k_batteryThreshold = 3.7f;
constexpr static const char * k_batteryOKText = "BATTERY: OK";
constexpr static const char * k_batteryNeedChargingText = "BATTERY: NEED RECHARGE";
void updateBatteryState(float batteryLevel, bool batteryCharging);
ContentView m_view;
ResetController m_resetController;
};
}
#endif

View File

@@ -1,5 +1,4 @@
#include "keyboard_test_controller.h"
#include "../apps_container.h"
extern "C" {
#include <assert.h>
}
@@ -9,32 +8,23 @@ using namespace Poincare;
namespace HardwareTest {
constexpr KDColor KeyboardTestController::k_LEDColors[k_numberOfColors];
KeyboardTestController::KeyboardTestController(Responder * parentResponder) :
ViewController(parentResponder),
m_view(),
m_LEDColorIndex(0),
m_keyboardView(),
m_screenTestController(nullptr)
{
}
View * KeyboardTestController::view() {
return &m_view;
return &m_keyboardView;
}
bool KeyboardTestController::handleEvent(Ion::Events::Event event) {
Ion::Keyboard::State state = Ion::Keyboard::scan();
setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
if (m_LEDColorIndex == k_numberOfColors) {
m_LEDColorIndex = 0;
}
updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
Ion::Keyboard::State onlyKeyDown = Ion::Keyboard::State(Ion::Keyboard::ValidKeys[m_view.keyboardView()->testedKeyIndex()]);
Ion::Keyboard::State onlyKeyDown = Ion::Keyboard::State(Ion::Keyboard::ValidKeys[m_keyboardView.testedKeyIndex()]);
if (state == onlyKeyDown) {
m_view.keyboardView()->setTestedKeyIndex(m_view.keyboardView()->testedKeyIndex()+1);
if (m_view.keyboardView()->testedKeyIndex() == Ion::Keyboard::NumberOfValidKeys) {
setLEDColor(KDColorBlack);
m_keyboardView.setTestedKeyIndex(m_keyboardView.testedKeyIndex()+1);
if (m_keyboardView.testedKeyIndex() == Ion::Keyboard::NumberOfValidKeys) {
ModalViewController * modal = (ModalViewController *)parentResponder();
modal->displayModalViewController(&m_screenTestController, 0.0f, 0.0f);
}
@@ -43,119 +33,7 @@ bool KeyboardTestController::handleEvent(Ion::Events::Event event) {
}
void KeyboardTestController::viewWillAppear() {
m_LEDColorIndex = 0;
setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
m_view.keyboardView()->setTestedKeyIndex(0);
}
void KeyboardTestController::updateBatteryState(float batteryLevel, bool batteryCharging) {
char bufferLevel[ContentView::k_maxNumberOfCharacters + Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
const char * legend = "Battery level: ";
int legendLength = strlen(legend);
strlcpy(bufferLevel, legend, legendLength+1);
Complex::convertFloatToText(batteryLevel, bufferLevel+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_view.batteryLevelTextView()->setText(bufferLevel);
char bufferCharging[ContentView::k_maxNumberOfCharacters + Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
int numberOfChars = 0;
legend = "Battery charging: ";
legendLength = strlen(legend);
strlcpy(bufferCharging, legend, legendLength+1);
numberOfChars += legendLength;
legend = "no";
if (batteryCharging) {
legend = "yes";
}
legendLength = strlen(legend);
strlcpy(bufferCharging+numberOfChars, legend, legendLength+1);
numberOfChars += legendLength;
bufferCharging[numberOfChars] = 0;
m_view.batteryChargingTextView()->setText(bufferCharging);
}
void KeyboardTestController::setLEDColor(KDColor color) {
Ion::LED::setColor(color);
char ledLevel[ContentView::k_maxNumberOfCharacters];
const char * legend = "LED color: ";
int legendLength = strlen(legend);
int numberOfChar = legendLength;
strlcpy(ledLevel, legend, legendLength+1);
legend = "Off";
if (color == KDColorWhite) {
legend = "White";
}
if (color == KDColorRed) {
legend = "Red";
}
if (color == KDColorBlue) {
legend = "Blue";
}
if (color == KDColorGreen) {
legend = "Green";
}
legendLength = strlen(legend);
strlcpy(ledLevel+numberOfChar, legend, legendLength+1);
m_view.LEDStateTextView()->setText(ledLevel);
}
KDColor KeyboardTestController::LEDColorAtIndex(int i) {
assert(i >= 0 && i < k_numberOfColors);
return k_LEDColors[i];
}
KeyboardTestController::ContentView::ContentView() :
m_keyboardView(),
m_batteryLevelView(KDText::FontSize::Small),
m_batteryChargingView(KDText::FontSize::Small),
m_ledStateView(KDText::FontSize::Small)
{
}
KeyboardView * KeyboardTestController::ContentView::keyboardView() {
return &m_keyboardView;
}
BufferTextView * KeyboardTestController::ContentView::batteryLevelTextView() {
return &m_batteryLevelView;
}
BufferTextView * KeyboardTestController::ContentView::batteryChargingTextView() {
return &m_batteryChargingView;
}
BufferTextView * KeyboardTestController::ContentView::LEDStateTextView() {
return &m_ledStateView;
}
void KeyboardTestController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
}
void KeyboardTestController::ContentView::layoutSubviews() {
m_keyboardView.setFrame(KDRect(0, 0, 130, bounds().height()));
KDSize textSize = KDText::stringSize(" ", KDText::FontSize::Small);
m_batteryLevelView.setFrame(KDRect(130, k_margin, bounds().width()-130, textSize.height()));
m_batteryChargingView.setFrame(KDRect(130, k_margin+2*textSize.height(), bounds().width()-130, textSize.height()));
m_ledStateView.setFrame(KDRect(130, k_margin+5*textSize.height(), bounds().width()-130, textSize.height()));
}
int KeyboardTestController::ContentView::numberOfSubviews() const {
return 4;
}
View * KeyboardTestController::ContentView::subviewAtIndex(int index) {
if (index == 0) {
return &m_keyboardView;
}
if (index == 1) {
return &m_batteryLevelView;
}
if (index == 2) {
return &m_batteryChargingView;
}
return &m_ledStateView;
m_keyboardView.setTestedKeyIndex(0);
}
}

View File

@@ -14,32 +14,7 @@ public:
bool handleEvent(Ion::Events::Event event) override;
void viewWillAppear() override;
private:
class ContentView : public View {
public:
ContentView();
KeyboardView * keyboardView();
BufferTextView * batteryLevelTextView();
BufferTextView * batteryChargingTextView();
BufferTextView * LEDStateTextView();
constexpr static int k_maxNumberOfCharacters = 20;
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
void layoutSubviews() override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
constexpr static int k_margin = 4;
KeyboardView m_keyboardView;
BufferTextView m_batteryLevelView;
BufferTextView m_batteryChargingView;
BufferTextView m_ledStateView;
};
void updateBatteryState(float batteryLevel, bool batteryCharging);
void setLEDColor(KDColor color);
constexpr static int k_numberOfColors = 5;
constexpr static KDColor k_LEDColors[k_numberOfColors] = {KDColorBlack, KDColorRed, KDColorBlue, KDColorGreen, KDColorWhite};
static KDColor LEDColorAtIndex(int i);
ContentView m_view;
int m_LEDColorIndex;
KeyboardView m_keyboardView;
ScreenTestController m_screenTestController;
};

View File

@@ -0,0 +1,102 @@
#include "led_test_controller.h"
extern "C" {
#include <assert.h>
}
namespace HardwareTest {
constexpr KDColor LEDTestController::k_LEDColors[k_numberOfColors];
LEDTestController::LEDTestController(Responder * parentResponder) :
ViewController(parentResponder),
m_view(),
m_LEDColorIndex(0),
m_batteryTestController(this)
{
}
View * LEDTestController::view() {
return &m_view;
}
bool LEDTestController::handleEvent(Ion::Events::Event event) {
setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
if (m_LEDColorIndex == k_numberOfColors) {
ModalViewController * modal = (ModalViewController *)parentResponder();
modal->displayModalViewController(&m_batteryTestController, 0.0f, 0.0f);
}
return true;
}
void LEDTestController::viewWillAppear() {
m_LEDColorIndex = 0;
setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
}
void LEDTestController::setLEDColor(KDColor color) {
Ion::LED::setColor(color);
m_view.LEDColorIndicatorView()->setColor(color);
}
KDColor LEDTestController::LEDColorAtIndex(int i) {
assert(i >= 0 && i < k_numberOfColors);
return k_LEDColors[i];
}
const uint8_t arrowMask[10][9] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF},
{0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF},
{0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
{0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};
LEDTestController::ContentView::ContentView() :
m_ledColorIndicatorView(KDColorBlack),
m_ledColorOutlineView(KDColorBlack),
m_ledView(KDText::FontSize::Large)
{
m_ledView.setText("LED");
}
SolidColorView * LEDTestController::ContentView::LEDColorIndicatorView() {
return &m_ledColorIndicatorView;
}
KDColor s_arrowWorkingBuffer[10*9];
void LEDTestController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
ctx->fillRect(KDRect((Ion::Display::Width-k_arrowThickness)/2, k_arrowMargin+k_arrowHeight, k_arrowThickness, k_arrowLength), KDColorBlack);
KDRect frame((Ion::Display::Width-k_arrowWidth)/2, k_arrowMargin, k_arrowWidth, k_arrowHeight);
ctx->blendRectWithMask(frame, KDColorBlack, (const uint8_t *)arrowMask, s_arrowWorkingBuffer);
}
void LEDTestController::ContentView::layoutSubviews() {
KDSize ledSize = m_ledView.minimalSizeForOptimalDisplay();
m_ledView.setFrame(KDRect((Ion::Display::Width-ledSize.width()-k_indicatorSize-k_indicatorMargin)/2, k_arrowHeight+k_arrowLength+2*k_arrowMargin, ledSize.width(), ledSize.height()));
m_ledColorIndicatorView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2, k_arrowHeight+k_arrowLength+2*k_arrowMargin, k_indicatorSize, k_indicatorSize));
m_ledColorOutlineView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2-1, k_arrowHeight+k_arrowLength+2*k_arrowMargin-1, k_indicatorSize+2, k_indicatorSize+2));
}
int LEDTestController::ContentView::numberOfSubviews() const {
return 3;
}
View * LEDTestController::ContentView::subviewAtIndex(int index) {
if (index == 0) {
return &m_ledView;
}
if (index == 1) {
return &m_ledColorOutlineView;
}
return &m_ledColorIndicatorView;
}
}

View File

@@ -0,0 +1,48 @@
#ifndef HARDWARE_TEST_LED_TEST_CONTROLLER_H
#define HARDWARE_TEST_LED_TEST_CONTROLLER_H
#include <escher.h>
#include "battery_test_controller.h"
namespace HardwareTest {
class LEDTestController : public ViewController {
public:
LEDTestController(Responder * parentResponder);
View * view() override;
bool handleEvent(Ion::Events::Event event) override;
void viewWillAppear() override;
private:
class ContentView : public View {
public:
ContentView();
SolidColorView * LEDColorIndicatorView();
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
void layoutSubviews() override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
SolidColorView m_ledColorIndicatorView;
SolidColorView m_ledColorOutlineView;
BufferTextView m_ledView;
};
void setLEDColor(KDColor color);
constexpr static KDCoordinate k_arrowThickness = 3;
constexpr static KDCoordinate k_arrowLength = 100;
constexpr static KDCoordinate k_arrowMargin = 20;
constexpr static KDCoordinate k_indicatorSize = 20;
constexpr static KDCoordinate k_indicatorMargin = 8;
constexpr static KDCoordinate k_arrowHeight = 10;
constexpr static KDCoordinate k_arrowWidth = 9;
constexpr static int k_numberOfColors = 5;
constexpr static KDColor k_LEDColors[k_numberOfColors] = {KDColorWhite, KDColorRed, KDColorBlue, KDColorGreen, KDColorBlack};
static KDColor LEDColorAtIndex(int i);
ContentView m_view;
int m_LEDColorIndex;
BatteryTestController m_batteryTestController;
};
}
#endif

View File

@@ -0,0 +1,113 @@
#include "pop_up_controller.h"
#include "../i18n.h"
#include "../apps_container.h"
#include <assert.h>
namespace HardwareTest {
PopUpController::PopUpController() :
ViewController(nullptr),
m_contentView(this)
{
}
View * PopUpController::view() {
return &m_contentView;
}
void PopUpController::didBecomeFirstResponder() {
m_contentView.setSelectedButton(0);
}
bool PopUpController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Left && m_contentView.selectedButton() == 1) {
m_contentView.setSelectedButton(0);
return true;
}
if (event == Ion::Events::Right && m_contentView.selectedButton() == 0) {
m_contentView.setSelectedButton(1);
return true;
}
return false;
}
PopUpController::ContentView::ContentView(Responder * parentResponder) :
Responder(parentResponder),
m_cancelButton(this, I18n::Message::Cancel, Invocation([](void * context, void * sender) {
PopUpController::ContentView * view = (PopUpController::ContentView *)context;
view->app()->dismissModalViewController();
}, this), KDText::FontSize::Small),
m_okButton(this, I18n::Message::Ok, Invocation([](void * context, void * sender) {
PopUpController::ContentView * view = (PopUpController::ContentView *)context;
AppsContainer * appsContainer = (AppsContainer *)view->app()->container();
appsContainer->switchTo(appsContainer->hardwareTestAppSnapshot());
}, this), KDText::FontSize::Small),
m_warningTextView(KDText::FontSize::Small, I18n::Message::Warning, 0.5, 0.5, KDColorWhite, KDColorBlack),
m_messageTextView1(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch1, 0.5, 0.5, KDColorWhite, KDColorBlack),
m_messageTextView2(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch2, 0.5, 0.5, KDColorWhite, KDColorBlack),
m_messageTextView3(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch3, 0.5, 0.5, KDColorWhite, KDColorBlack),
m_messageTextView4(KDText::FontSize::Small, I18n::Message::HardwareTestLaunch4, 0.5, 0.5, KDColorWhite, KDColorBlack)
{
}
void PopUpController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorBlack);
}
void PopUpController::ContentView::setSelectedButton(int selectedButton) {
m_cancelButton.setHighlighted(selectedButton == 0);
m_okButton.setHighlighted(selectedButton == 1);
if (selectedButton == 0) {
app()->setFirstResponder(&m_cancelButton);
} else {
app()->setFirstResponder(&m_okButton);
}
}
int PopUpController::ContentView::selectedButton() {
if (m_cancelButton.isHighlighted()) {
return 0;
}
return 1;
}
int PopUpController::ContentView::numberOfSubviews() const {
return 7;
}
View * PopUpController::ContentView::subviewAtIndex(int index) {
switch (index) {
case 0:
return &m_warningTextView;
case 1:
return &m_messageTextView1;
case 2:
return &m_messageTextView2;
case 3:
return &m_messageTextView3;
case 4:
return &m_messageTextView4;
case 5:
return &m_cancelButton;
case 6:
return &m_okButton;
default:
assert(false);
return nullptr;
}
}
void PopUpController::ContentView::layoutSubviews() {
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height();
m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight));
m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight));
m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight));
m_messageTextView3.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+3*textHeight, width, textHeight));
m_messageTextView4.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+4*textHeight, width, textHeight));
m_cancelButton.setFrame(KDRect(k_buttonMargin, height-k_buttonMargin-k_buttonHeight, (width-3*k_buttonMargin)/2, k_buttonHeight));
m_okButton.setFrame(KDRect(2*k_buttonMargin+(width-3*k_buttonMargin)/2, height-k_buttonMargin-k_buttonHeight, (width-3*k_buttonMargin)/2, k_buttonHeight));
}
}

View File

@@ -0,0 +1,43 @@
#ifndef HARDWARE_TEST_POP_UP_CONTROLLER_H
#define HARDWARE_TEST_POP_UP_CONTROLLER_H
#include <escher.h>
namespace HardwareTest {
class PopUpController : public ViewController {
public:
PopUpController();
View * view() override;
void didBecomeFirstResponder() override;
bool handleEvent(Ion::Events::Event event) override;
private:
class ContentView : public View, public Responder {
public:
ContentView(Responder * parentResponder);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setSelectedButton(int selectedButton);
int selectedButton();
private:
constexpr static KDCoordinate k_buttonMargin = 10;
constexpr static KDCoordinate k_buttonHeight = 20;
constexpr static KDCoordinate k_topMargin = 8;
constexpr static KDCoordinate k_paragraphHeight = 20;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;
Button m_cancelButton;
Button m_okButton;
MessageTextView m_warningTextView;
MessageTextView m_messageTextView1;
MessageTextView m_messageTextView2;
MessageTextView m_messageTextView3;
MessageTextView m_messageTextView4;
};
ContentView m_contentView;
};
}
#endif

View File

@@ -0,0 +1,44 @@
#include "reset_controller.h"
extern "C" {
#include <assert.h>
}
#include <poincare.h>
using namespace Poincare;
namespace HardwareTest {
ResetController::ResetController(Responder * parentResponder) :
ViewController(parentResponder),
m_view()
{
}
View * ResetController::view() {
return &m_view;
}
bool ResetController::handleEvent(Ion::Events::Event event) {
return true;
}
ResetController::ContentView::ContentView() :
m_resetTextView()
{
m_resetTextView.setText("RESET");
}
void ResetController::ContentView::layoutSubviews() {
m_resetTextView.setFrame(bounds());
}
int ResetController::ContentView::numberOfSubviews() const {
return 1;
}
View * ResetController::ContentView::subviewAtIndex(int index) {
return &m_resetTextView;
}
}

View File

@@ -0,0 +1,30 @@
#ifndef HARDWARE_TEST_RESET_CONTROLLER_H
#define HARDWARE_TEST_RESET_CONTROLLER_H
#include <escher.h>
namespace HardwareTest {
class ResetController : public ViewController {
public:
ResetController(Responder * parentResponder);
View * view() override;
bool handleEvent(Ion::Events::Event event) override;
private:
class ContentView : public View {
public:
ContentView();
BufferTextView * resetTextView();
private:
void layoutSubviews() override;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
BufferTextView m_resetTextView;
};
ContentView m_view;
};
}
#endif

View File

@@ -1,5 +1,4 @@
#include "screen_test_controller.h"
#include "../apps_container.h"
extern "C" {
#include <assert.h>
}
@@ -9,7 +8,8 @@ namespace HardwareTest {
ScreenTestController::ScreenTestController(Responder * parentResponder) :
ViewController(parentResponder),
m_patternIndex(0),
m_view()
m_view(),
m_ledTestController(this)
{
}
@@ -18,9 +18,12 @@ View * ScreenTestController::view() {
}
bool ScreenTestController::handleEvent(Ion::Events::Event event) {
if (event != Ion::Events::OK) {
return true;
}
if (m_patternIndex == Pattern::numberOfPatterns()) {
AppsContainer * container = (AppsContainer *)app()->container();
container->switchTo(container->appSnapshotAtIndex(0));
ModalViewController * modal = (ModalViewController *)parentResponder();
modal->displayModalViewController(&m_ledTestController, 0.0f, 0.0f);
} else {
showNextPattern();
}

View File

@@ -2,6 +2,7 @@
#define HARDWARE_TEST_SCREEN_TEST_CONTROLLER_H
#include <escher.h>
#include "led_test_controller.h"
#include "pattern_view.h"
#include "pattern.h"
@@ -17,6 +18,7 @@ private:
void showNextPattern();
int m_patternIndex;
PatternView m_view;
LEDTestController m_ledTestController;
};
}

View File

@@ -17,7 +17,7 @@ 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[218][3] {
const char * messages[222][3] {
{"Attention", "Warning", "Cuidado"},
{"Valider", "Confirm", "Confirmar"},
{"Annuler", "Cancel", "Cancelar"},
@@ -266,6 +266,11 @@ const char * messages[218][3] {
{"Numero serie", "Serial number", "Numero serie"},
{"Rappel mise a jour", "Update pop-up", "Pop-up de actualizacion"},
{"Vous allez lancer le test usine.", "You are starting the hardware", "Esta iniciando la prueba"},
{"Pour en sortir vous devrez", " test. At the end of the test, you", "de fabrica. Para quitar"},
{"effectuer un reset qui", "will have to reset the device and", "la prueba, debera resetear"},
{"supprimera vos donnees.", "all your data will be deleted.", "su equipo."},
/* On boarding */
{"MISE A JOUR DISPONIBLE", "UPDATE AVAILABLE", "ACTUALIZACION DISPONIBLE"},
{"Des ameliorations importantes existent", "There are important upgrades", "Hay mejoras importantes"},

View File

@@ -238,6 +238,10 @@ namespace I18n {
SoftwareVersion,
SerialNumber,
UpdatePopUp,
HardwareTestLaunch1,
HardwareTestLaunch2,
HardwareTestLaunch3,
HardwareTestLaunch4,
/* On boarding */
UpdateAvailable,

View File

@@ -51,7 +51,12 @@ View * SubController::view() {
}
void SubController::didEnterResponderChain(Responder * previousResponder) {
selectCellAtLocation(0, valueIndexForPreference(m_nodeModel->label()));
if (previousResponder->commonAncestorWith(this) == parentResponder()) {
/* We want to select the prefered setting node only when the previous page
* was the main setting page. We do not to change the selection when
* dismissing a pop-up for instance. */
selectCellAtLocation(0, valueIndexForPreference(m_nodeModel->label()));
}
if (m_nodeModel->label() == I18n::Message::ExamMode) {
m_selectableTableView.reloadData();
}
@@ -62,8 +67,7 @@ bool SubController::handleEvent(Ion::Events::Event event) {
/* We hide here the activation hardware test app: in the menu "about", by
* clicking on '6' on the serial number row. */
if ((event == Ion::Events::Six || event == Ion::Events::LowerT || event == Ion::Events::UpperT) && m_nodeModel->label() == I18n::Message::About && selectedRow() == 1) {
AppsContainer * appsContainer = (AppsContainer *)app()->container();
appsContainer->switchTo(appsContainer->hardwareTestAppSnapshot());
app()->displayModalViewController(&m_hardwareTestPopUpController, 0.f, 0.f, Metric::ExamPopUpTopMargin, Metric::PopUpRightMargin, Metric::ExamPopUpBottomMargin, Metric::PopUpLeftMargin);
return true;
}
if (event == Ion::Events::OK || event == Ion::Events::EXE) {

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "settings_node.h"
#include "../hardware_test/pop_up_controller.h"
namespace Settings {
@@ -35,6 +36,7 @@ private:
Poincare::ExpressionLayout * m_complexFormatLayout[2];
SelectableTableView m_selectableTableView;
Node * m_nodeModel;
HardwareTest::PopUpController m_hardwareTestPopUpController;
};
}

View File

@@ -6,6 +6,7 @@
class SolidColorView : public View {
public:
SolidColorView(KDColor color);
virtual void setColor(KDColor color);
void drawRect(KDContext * ctx, KDRect rect) const override;
protected:
#if ESCHER_VIEW_LOGGING

View File

@@ -6,6 +6,13 @@ SolidColorView::SolidColorView(KDColor color) :
{
}
void SolidColorView::setColor(KDColor color) {
if (m_color != color) {
m_color = color;
markRectAsDirty(bounds());
}
}
void SolidColorView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, m_color);
}