diff --git a/apps/hardware_test/Makefile b/apps/hardware_test/Makefile index 6921f94ed..339b8887c 100644 --- a/apps/hardware_test/Makefile +++ b/apps/hardware_test/Makefile @@ -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 \ diff --git a/apps/hardware_test/keyboard_model.cpp b/apps/hardware_test/keyboard_model.cpp new file mode 100644 index 000000000..0bc9b5084 --- /dev/null +++ b/apps/hardware_test/keyboard_model.cpp @@ -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; +} + +} diff --git a/apps/hardware_test/keyboard_model.h b/apps/hardware_test/keyboard_model.h new file mode 100644 index 000000000..8c0c8e47b --- /dev/null +++ b/apps/hardware_test/keyboard_model.h @@ -0,0 +1,37 @@ +#ifndef HARDWARE_TEST_KEYBOARD_MODEL_H +#define HARDWARE_TEST_KEYBOARD_MODEL_H + +#include + +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 + diff --git a/apps/hardware_test/keyboard_test_controller.cpp b/apps/hardware_test/keyboard_test_controller.cpp index 730b2340c..c787ec289 100644 --- a/apps/hardware_test/keyboard_test_controller.cpp +++ b/apps/hardware_test/keyboard_test_controller.cpp @@ -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; } diff --git a/apps/hardware_test/keyboard_view.cpp b/apps/hardware_test/keyboard_view.cpp index 41c2cb694..1b15f28df 100644 --- a/apps/hardware_test/keyboard_view.cpp +++ b/apps/hardware_test/keyboard_view.cpp @@ -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; +} + } diff --git a/apps/hardware_test/keyboard_view.h b/apps/hardware_test/keyboard_view.h index 47d36abff..1d02b0b5f 100644 --- a/apps/hardware_test/keyboard_view.h +++ b/apps/hardware_test/keyboard_view.h @@ -2,17 +2,19 @@ #define HARDWARE_TEST_KEYBOARD_VIEW_H #include +#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; }; }