ExamMode types

This commit is contained in:
Quentin Guidée
2020-02-16 20:22:05 +01:00
parent 83ea330220
commit fac5b0c416
16 changed files with 38 additions and 68 deletions

View File

@@ -31,8 +31,8 @@ app_src += $(addprefix apps/,\
variable_box_empty_controller.cpp \
)
tests_src += apps/exam_mode_configuration_official.cpp
apps_official += apps/exam_mode_configuration_official.cpp
tests_src += apps/exam_mode_configuration_non_official.cpp
apps_official += apps/exam_mode_configuration_non_official.cpp
apps_non_official += apps/exam_mode_configuration_non_official.cpp
apps_launch_on_boarding_src += apps/apps_container_launch_on_boarding.cpp

View File

@@ -3,7 +3,8 @@
using namespace Poincare;
constexpr Settings::SettingsMessageTree s_ledColorChildren[] = {Settings::SettingsMessageTree(I18n::Message::ColorRed), Settings::SettingsMessageTree(I18n::Message::ColorWhite), Settings::SettingsMessageTree(I18n::Message::ColorGreen), Settings::SettingsMessageTree(I18n::Message::ColorBlue), Settings::SettingsMessageTree(I18n::Message::ColorYellow), Settings::SettingsMessageTree(I18n::Message::ColorPurple), Settings::SettingsMessageTree(I18n::Message::ColorOrange)};
constexpr Settings::SettingsMessageTree ExamModeConfiguration::s_modelExamChildren[] = {Settings::SettingsMessageTree(I18n::Message::LEDColor, s_ledColorChildren), Settings::SettingsMessageTree(I18n::Message::ExamModeModeStandard), Settings::SettingsMessageTree(I18n::Message::ExamModeModeNoSym)};
constexpr Settings::SettingsMessageTree s_examModeMode[] = {Settings::SettingsMessageTree(I18n::Message::ExamModeModeStandard), Settings::SettingsMessageTree(I18n::Message::ExamModeModeNoSym), Settings::SettingsMessageTree(I18n::Message::ExamModeModeNoSymNoText)};
constexpr Settings::SettingsMessageTree ExamModeConfiguration::s_modelExamChildren[] = {Settings::SettingsMessageTree(I18n::Message::LEDColor, s_ledColorChildren), Settings::SettingsMessageTree(I18n::Message::ExamModeMode, s_examModeMode), Settings::SettingsMessageTree(I18n::Message::ActivateExamMode)};
int ExamModeConfiguration::numberOfAvailableExamMode() {
return 3;
@@ -22,13 +23,13 @@ I18n::Message ExamModeConfiguration::examModeActivationWarningMessage(GlobalPref
I18n::Message warnings[] = {I18n::Message::ExitExamMode1, I18n::Message::ExitExamMode2, I18n::Message::Default};
return warnings[line];
}
assert(mode == GlobalPreferences::ExamMode::Standard || mode == GlobalPreferences::ExamMode::NoSym);
assert(mode == GlobalPreferences::ExamMode::Standard || mode == GlobalPreferences::ExamMode::NoSym || mode == GlobalPreferences::ExamMode::NoSymNoText);
I18n::Message warnings[] = {I18n::Message::ActiveExamModeMessage1, I18n::Message::ActiveExamModeMessage2, I18n::Message::ActiveExamModeMessage3};
return warnings[line];
}
KDColor ExamModeConfiguration::examModeColor(GlobalPreferences::ExamMode mode) {
assert(mode == GlobalPreferences::ExamMode::Standard || mode == GlobalPreferences::ExamMode::NoSym);
assert(mode == GlobalPreferences::ExamMode::Standard || mode == GlobalPreferences::ExamMode::NoSym || mode == GlobalPreferences::ExamMode::NoSymNoText);
Preferences * preferences = Preferences::sharedPreferences();
switch((int) preferences->colorOfLED()) {

View File

@@ -1,56 +0,0 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
// Caution: Dutch exam mode is subject to a compliance certification by a government agency. Distribution of a non-certified Dutch exam mode is illegal.
#include "exam_mode_configuration.h"
constexpr Settings::SettingsMessageTree s_ledColorChildren[7] = {Settings::SettingsMessageTree(I18n::Message::ColorRed), Settings::SettingsMessageTree(I18n::Message::ColorWhite), Settings::SettingsMessageTree(I18n::Message::ColorGreen), Settings::SettingsMessageTree(I18n::Message::ColorBlue), Settings::SettingsMessageTree(I18n::Message::ColorYellow), Settings::SettingsMessageTree(I18n::Message::ColorPurple), Settings::SettingsMessageTree(I18n::Message::ColorOrange)};
constexpr Settings::SettingsMessageTree s_examModeMode[3] = {Settings::SettingsMessageTree(I18n::Message::ExamModeModeStandard), Settings::SettingsMessageTree(I18n::Message::ExamModeModeNoSym), Settings::SettingsMessageTree(I18n::Message::ExamModeModeDutch)};
constexpr Settings::SettingsMessageTree ExamModeConfiguration::s_modelExamChildren[3] = {Settings::SettingsMessageTree(I18n::Message::LEDColor, s_ledColorChildren), Settings::SettingsMessageTree(I18n::Message::ExamModeMode, s_examModeMode), Settings::SettingsMessageTree(I18n::Message::ActivateExamMode)};
int ExamModeConfiguration::numberOfAvailableExamMode() {
if (GlobalPreferences::sharedGlobalPreferences()->language() != I18n::Language::EN || GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
return 1;
}
return 2;
}
GlobalPreferences::ExamMode ExamModeConfiguration::examModeAtIndex(int index) {
return index == 0 ? GlobalPreferences::ExamMode::Standard : GlobalPreferences::ExamMode::Dutch;
}
I18n::Message ExamModeConfiguration::examModeActivationMessage(int index) {
return index == 0 ? I18n::Message::ActivateExamMode : I18n::Message::ActivateDutchExamMode;
}
I18n::Message ExamModeConfiguration::examModeActivationWarningMessage(GlobalPreferences::ExamMode mode, int line) {
if (mode == GlobalPreferences::ExamMode::Off) {
I18n::Message warnings[] = {I18n::Message::ExitExamMode1, I18n::Message::ExitExamMode2, I18n::Message::Default};
return warnings[line];
} else if (mode == GlobalPreferences::ExamMode::Standard || mode == GlobalPreferences::ExamMode::NoSym) {
I18n::Message warnings[] = {I18n::Message::ActiveExamModeMessage1, I18n::Message::ActiveExamModeMessage2, I18n::Message::ActiveExamModeMessage3};
return warnings[line];
}
assert(mode == GlobalPreferences::ExamMode::Dutch);
I18n::Message warnings[] = {I18n::Message::ActiveDutchExamModeMessage1, I18n::Message::ActiveDutchExamModeMessage2, I18n::Message::ActiveDutchExamModeMessage3};
return warnings[line];
}
KDColor ExamModeConfiguration::examModeColor(GlobalPreferences::ExamMode mode) {
/* The Dutch exam mode LED is supposed to be orange but we can only make
* blink "pure" colors: with RGB leds on or off (as the PWM is used for
* blinking). The closest "pure" color is Yellow. Moreover, Orange LED is
* already used when the battery is charging. Using yellow, we can assert
* that the yellow LED only means that Dutch exam mode is on and avoid
* confusing states when the battery is charging and states when the Dutch
* exam mode is on. */
return mode == GlobalPreferences::ExamMode::Dutch ? KDColorYellow : KDColorRed;
}
bool ExamModeConfiguration::appIsForbiddenInExamMode(I18n::Message appName, GlobalPreferences::ExamMode mode) {
return appName == I18n::Message::CodeApp && mode == GlobalPreferences::ExamMode::Dutch;
}
bool ExamModeConfiguration::exactExpressionsAreForbidden(GlobalPreferences::ExamMode mode) {
return mode == GlobalPreferences::ExamMode::Dutch;
}

View File

@@ -8,7 +8,7 @@ GlobalPreferences * GlobalPreferences::sharedGlobalPreferences() {
GlobalPreferences::ExamMode GlobalPreferences::examMode() const {
if (m_examMode == ExamMode::Unknown) {
uint8_t mode = Ion::ExamMode::FetchExamMode();
assert(mode >= 0 && mode < 4); // mode can be cast in ExamMode (Off, Standard, NoSym or Dutch)
assert(mode >= 0 && mode < 5); // mode can be cast in ExamMode (Off, Standard, NoSym, Dutch or NoSymNoText)
m_examMode = (ExamMode)mode;
}
return m_examMode;

View File

@@ -10,7 +10,8 @@ public:
Off = 0,
Standard = 1,
NoSym = 2,
Dutch = 3,
NoSymNoText = 3,
Dutch = 4,
};
static GlobalPreferences * sharedGlobalPreferences();
I18n::Language language() const { return m_language; }

View File

@@ -59,7 +59,7 @@ bool Controller::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
AppsContainer * container = AppsContainer::sharedAppsContainer();
::App::Snapshot * selectedSnapshot = container->appSnapshotAtIndex(selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1);
if ((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch && selectedSnapshot->descriptor()->examinationLevel() < 2) ||
if (((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSymNoText) && selectedSnapshot->descriptor()->examinationLevel() < 2) ||
((GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Standard || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSym) && selectedSnapshot->descriptor()->examinationLevel() < 1)) {
App::app()->displayWarning(I18n::Message::ForbidenAppInExamMode1, I18n::Message::ForbidenAppInExamMode2);
} else {

View File

@@ -48,6 +48,7 @@ LEDColor = "LEDs farbe"
ExamModeMode = "Modus"
ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Ohne symbolisch "
ExamModeModeNoSymNoText = "No sym no text "
ExamModeModeDutch = "Niederländisch "
ColorRed = "Rot "
ColorWhite = "Weiss "

View File

@@ -48,6 +48,7 @@ LEDColor = "LED color"
ExamModeMode = "Mode"
ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "No sym "
ExamModeModeNoSymNoText = "No sym no text "
ExamModeModeDutch = "Dutch "
ColorRed = "Red "
ColorWhite = "White "

View File

@@ -48,6 +48,7 @@ LEDColor = "Color del LED"
ExamModeMode = "Modo"
ExamModeModeStandard = "Estándar "
ExamModeModeNoSym = "Sin simbólico "
ExamModeModeNoSymNoText = "sin simbolismo sin texto "
ExamModeModeDutch = "Holandés "
ColorRed = "Rojo "
ColorWhite = "Blanco "

View File

@@ -48,6 +48,7 @@ LEDColor = "Couleur LED"
ExamModeMode = "Mode"
ExamModeModeStandard = "Standard "
ExamModeModeNoSym = "Sans symbolique "
ExamModeModeNoSymNoText = "Sans symbolique ni texte "
ExamModeModeDutch = "Néerlandais "
ColorRed = "Rouge "
ColorWhite = "Blanc "

View File

@@ -48,6 +48,7 @@ LEDColor = "LED szín"
ExamModeMode = "Üzemmód"
ExamModeModeStandard = "Normál"
ExamModeModeNoSym = "Nincs sym"
ExamModeModeNoSymNoText = "No Symbolic no text "
ExamModeModeDutch = "Holland "
ColorRed = "Piros "
ColorWhite = "Fehér "

View File

@@ -48,6 +48,7 @@ LEDColor = "Cor LED"
ExamModeMode = "Modo"
ExamModeModeStandard = "Padrão "
ExamModeModeNoSym = "Sem simbólico "
ExamModeModeNoSymNoText = "Sem simbólico sem texto "
ExamModeModeDutch = "Holandês "
ColorRed = "Vermelho "
ColorWhite = "Branco "

View File

@@ -18,7 +18,9 @@ ExamModeController::ExamModeController(Responder * parentResponder) :
m_contentView(&m_selectableTableView),
m_cell{},
m_ledController(this),
m_ledColorCell(KDFont::LargeFont, KDFont::SmallFont)
m_examModeModeController(this),
m_ledColorCell(KDFont::LargeFont, KDFont::SmallFont),
m_examModeCell(KDFont::LargeFont, KDFont::SmallFont)
{
for (int i = 0; i < k_maxNumberOfCells; i++) {
m_cell[i].setMessage(ExamModeConfiguration::examModeActivationMessage(i));
@@ -33,6 +35,11 @@ bool ExamModeController::handleEvent(Ion::Events::Event event) {
StackViewController * stack = stackController();
stack->push(&m_ledController);
return true;
} else if (m_messageTreeModel->children(selectedRow())->label() == I18n::Message::ExamModeMode) {
(&m_examModeModeController)->setMessageTreeModel(m_messageTreeModel->children(selectedRow()));
StackViewController * stack = stackController();
stack->push(&m_examModeModeController);
return true;
} else {
AppsContainer::sharedAppsContainer()->displayExamModePopUp(examMode());
return true;
@@ -69,6 +76,9 @@ HighlightCell * ExamModeController::reusableCell(int index, int type) {
if (m_messageTreeModel->children(index)->label() == I18n::Message::LEDColor) {
return &m_ledColorCell;
}
if (m_messageTreeModel->children(index)->label() == I18n::Message::ExamModeMode) {
return &m_examModeCell;
}
return &m_cell[index];
}
@@ -112,7 +122,7 @@ int ExamModeController::initialSelectedRow() const {
}
GlobalPreferences::ExamMode ExamModeController::examMode() {
GlobalPreferences::ExamMode mode = ExamModeConfiguration::examModeAtIndex(selectedRow());
GlobalPreferences::ExamMode mode = GlobalPreferences::sharedGlobalPreferences()->tempExamMode();
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
// If the exam mode is already on, this re-activate the same exam mode
mode = GlobalPreferences::sharedGlobalPreferences()->examMode();

View File

@@ -28,7 +28,9 @@ private:
SelectableViewWithMessages m_contentView;
MessageTableCell m_cell[k_maxNumberOfCells];
PreferencesController m_ledController;
PreferencesController m_examModeModeController;
MessageTableCellWithChevronAndMessage m_ledColorCell;
MessageTableCellWithChevronAndMessage m_examModeCell;
};
}

View File

@@ -155,6 +155,11 @@ Layout PreferencesController::layoutForPreferences(I18n::Message message) {
const char * text = " ";
return LayoutHelper::String(text, strlen(text), k_layoutFont);
}
case I18n::Message::ExamModeModeNoSymNoText:
{
const char * text = " ";
return LayoutHelper::String(text, strlen(text), k_layoutFont);
}
case I18n::Message::ExamModeModeDutch:
{
const char * text = " ";

View File

@@ -23,8 +23,9 @@ char ones[Config::ExamModeBufferSize]
* leading 0 bits. If it is equal to:
* - 0[3]: the exam mode is off;
* - 1[3]: the standard exam mode is activated;
* - 2[3]: the NoSym exam mode is activated.
* - 3[3]: the Dutch exam mode is activated. */
* - 2[3]: the NoSym exam mode is activated;
* - 3[3]: the Dutch exam mode is activated;
* - 4[3]: the NoSymNoText exam mode is activated. */
/* significantExamModeAddress returns the first uint32_t * in the exam mode
* flash sector that does not point to 0. If this flash sector has only 0s or