[hardware_test] Keyboard test: check only a subset of keys

This commit is contained in:
Émilie Feral
2019-12-03 11:51:47 +01:00
committed by LeaNumworks
parent a515160470
commit b36f9416b4
6 changed files with 74 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ app_hardware_test_src = $(addprefix apps/hardware_test/,\
colors_lcd_test_controller.cpp \
dead_pixels_test_controller.cpp \
keyboard_test_controller.cpp \
keyboard_model.cpp \
keyboard_view.cpp \
lcd_data_test_controller.cpp \
lcd_timing_test_controller.cpp \

View File

@@ -0,0 +1,16 @@
#include "keyboard_model.h"
namespace HardwareTest {
constexpr Ion::Keyboard::Key KeyboardModel::TestedKeys[KeyboardModel::NumberOfTestedKeys];
bool KeyboardModel::belongsToTestedKeysSubset(Ion::Keyboard::Key key) const {
for (int i = 0; i < NumberOfTestedKeys; i++) {
if (TestedKeys[i] == key) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,37 @@
#ifndef HARDWARE_TEST_KEYBOARD_MODEL_H
#define HARDWARE_TEST_KEYBOARD_MODEL_H
#include <ion/keyboard.h>
namespace HardwareTest {
class KeyboardModel {
public:
KeyboardModel() : m_testedKeyIndex(0) {}
Ion::Keyboard::Key testedKey() const { return TestedKeys[m_testedKeyIndex]; }
int testedKeyIndex() const { return m_testedKeyIndex; }
void setTestedKeyIndex(int i) {
assert(i >= 0 && i < NumberOfTestedKeys);
m_testedKeyIndex = i;
}
bool belongsToTestedKeysSubset(Ion::Keyboard::Key key) const;
static constexpr int NumberOfTestedKeys = 20;
static constexpr Ion::Keyboard::Key TestedKeys[KeyboardModel::NumberOfTestedKeys] = {
Ion::Keyboard::Key::Left, Ion::Keyboard::Key::Up, Ion::Keyboard::Key::Down, Ion::Keyboard::Key::Right, Ion::Keyboard::Key::OK, Ion::Keyboard::Key::Back,
Ion::Keyboard::Key::Home, Ion::Keyboard::Key::OnOff,
Ion::Keyboard::Key::Shift, Ion::Keyboard::Key::Alpha, Ion::Keyboard::Key::XNT, Ion::Keyboard::Key::Var, Ion::Keyboard::Key::Toolbox, Ion::Keyboard::Key::Backspace,
Ion::Keyboard::Key::Power,
Ion::Keyboard::Key::Square,
Ion::Keyboard::Key::RightParenthesis,
Ion::Keyboard::Key::Division,
Ion::Keyboard::Key::Minus,
Ion::Keyboard::Key::EXE
};
private:
int m_testedKeyIndex;
};
}
#endif

View File

@@ -17,10 +17,10 @@ View * KeyboardTestController::view() {
bool KeyboardTestController::handleEvent(Ion::Events::Event event) {
Ion::Keyboard::State state = Ion::Keyboard::scan();
Ion::Keyboard::State onlyKeyDown = Ion::Keyboard::State(Ion::Keyboard::ValidKeys[m_keyboardView.testedKeyIndex()]);
Ion::Keyboard::State onlyKeyDown = Ion::Keyboard::State(KeyboardModel::TestedKeys[m_keyboardView.testedKeyIndex()]);
if (state == onlyKeyDown) {
m_keyboardView.setTestedKeyIndex(m_keyboardView.testedKeyIndex()+1);
if (m_keyboardView.testedKeyIndex() == Ion::Keyboard::NumberOfValidKeys) {
m_keyboardView.setTestedKeyIndex(m_keyboardView.testedKeyIndex() + 1);
if (m_keyboardView.testedKeyIndex() == KeyboardModel::NumberOfTestedKeys) {
// Returning false will go to the next step in the WizardViewController
return false;
}

View File

@@ -3,17 +3,8 @@
namespace HardwareTest {
KeyboardView::KeyboardView() :
m_testedKeyIndex(0)
{
}
int KeyboardView::testedKeyIndex() const {
return m_testedKeyIndex;
}
void KeyboardView::setTestedKeyIndex(int i) {
m_testedKeyIndex = i;
m_keyboardModel.setTestedKeyIndex(i);
markRectAsDirty(bounds());
}
@@ -26,11 +17,8 @@ void KeyboardView::drawRect(KDContext * ctx, KDRect rect) const {
}
void KeyboardView::drawKey(int keyIndex, KDContext * ctx, KDRect rect) const {
KDColor color = keyIndex < m_testedKeyIndex ? KDColorGreen: KDColorBlack;
if (keyIndex == m_testedKeyIndex) {
color = KDColorBlue;
}
Ion::Keyboard::Key key = Ion::Keyboard::ValidKeys[keyIndex];
KDColor color = keyColor(key);
/* the key is on the cross */
if ((uint8_t)key < 4) {
KDCoordinate x = (uint8_t)key == 1 || (uint8_t)key == 2 ? k_margin + k_smallSquareSize : k_margin;
@@ -69,4 +57,14 @@ void KeyboardView::drawKey(int keyIndex, KDContext * ctx, KDRect rect) const {
}
}
KDColor KeyboardView::keyColor(Ion::Keyboard::Key key) const {
if (!m_keyboardModel.belongsToTestedKeysSubset(key)) {
return Palette::GreyBright;
}
if (m_keyboardModel.testedKey() == key) {
return KDColorBlue;
}
return (uint8_t)key < (uint8_t)m_keyboardModel.testedKey() ? KDColorGreen : KDColorBlack;
}
}

View File

@@ -2,17 +2,19 @@
#define HARDWARE_TEST_KEYBOARD_VIEW_H
#include <escher.h>
#include "keyboard_model.h"
namespace HardwareTest {
class KeyboardView : public View {
public:
KeyboardView();
int testedKeyIndex() const;
KeyboardView() : m_keyboardModel() {}
int testedKeyIndex() const { return m_keyboardModel.testedKeyIndex(); }
void setTestedKeyIndex(int i);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
void drawKey(int key, KDContext * ctx, KDRect rect) const;
KDColor keyColor(Ion::Keyboard::Key key) const;
constexpr static int k_margin = 4;
constexpr static int k_smallSquareSize = 8;
constexpr static int k_bigSquareSize = 14;
@@ -20,7 +22,7 @@ private:
constexpr static int k_smallRectWidth = 16;
constexpr static int k_bigRectHeight = 14;
constexpr static int k_bigRectWidth = 20;
int m_testedKeyIndex;
KeyboardModel m_keyboardModel;
};
}