diff --git a/apps/hardware_test/Makefile b/apps/hardware_test/Makefile index f1f6ad15c..68505a482 100644 --- a/apps/hardware_test/Makefile +++ b/apps/hardware_test/Makefile @@ -1,9 +1,10 @@ app_objs += $(addprefix apps/hardware_test/,\ app.o\ - color_controller.o\ - color_view.o\ - keyboard_controller.o\ + keyboard_test_controller.o\ keyboard_view.o\ + pattern.o\ + pattern_view.o\ + screen_test_controller.o\ ) diff --git a/apps/hardware_test/app.h b/apps/hardware_test/app.h index 70f72ca80..996261b2e 100644 --- a/apps/hardware_test/app.h +++ b/apps/hardware_test/app.h @@ -2,7 +2,7 @@ #define HARDWARE_TEST_APP_H #include -#include "keyboard_controller.h" +#include "keyboard_test_controller.h" class AppsContainer; @@ -17,7 +17,7 @@ public: }; private: App(Container * container, Snapshot * snapshot); - KeyboardController m_keyboardController; + KeyboardTestController m_keyboardController; }; } diff --git a/apps/hardware_test/color_controller.cpp b/apps/hardware_test/color_controller.cpp deleted file mode 100644 index c5c3d38d7..000000000 --- a/apps/hardware_test/color_controller.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "color_controller.h" -#include "../apps_container.h" -extern "C" { -#include -} - -namespace HardwareTest { - -ColorController::ColorController(Responder * parentResponder) : - ViewController(parentResponder), - m_view() -{ -} - -View * ColorController::view() { - return &m_view; -} - -bool ColorController::handleEvent(Ion::Events::Event event) { - m_view.setColors(nextColor(m_view.fillColor()), nextColor(m_view.outlineColor())); - if (m_view.fillColor() == KDColorBlack) { - AppsContainer * container = (AppsContainer *)app()->container(); - container->switchTo(container->appSnapshotAtIndex(0)); - } - return true; -} - -void ColorController::viewWillAppear() { - m_view.setColors(KDColorBlack, KDColorWhite); -} - -KDColor ColorController::nextColor(KDColor color) { - if (color == KDColorBlack) { - return KDColorWhite; - } - if (color == KDColorWhite) { - return KDColorRed; - } - if (color == KDColorRed) { - return KDColorBlue; - } - if (color == KDColorBlue) { - return KDColorGreen; - } - if (color == KDColorGreen) { - return KDColorBlack; - } - return KDColorRed; -} - -} - diff --git a/apps/hardware_test/color_controller.h b/apps/hardware_test/color_controller.h deleted file mode 100644 index a79b39c7c..000000000 --- a/apps/hardware_test/color_controller.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef HARDWARE_TEST_COLOR_CONTROLLER_H -#define HARDWARE_TEST_COLOR_CONTROLLER_H - -#include -#include "color_view.h" - -namespace HardwareTest { - -class ColorController : public ViewController { -public: - ColorController(Responder * parentResponder); - View * view() override; - bool handleEvent(Ion::Events::Event event) override; - void viewWillAppear() override; -private: - static KDColor nextColor(KDColor color); - ColorView m_view; -}; - -} - -#endif - diff --git a/apps/hardware_test/color_view.cpp b/apps/hardware_test/color_view.cpp deleted file mode 100644 index 57744fc72..000000000 --- a/apps/hardware_test/color_view.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "color_view.h" - -namespace HardwareTest { - -ColorView::ColorView() : - m_fillColor(KDColorRed), - m_outlineColor(KDColorGreen) -{ -} - -void ColorView::setColors(KDColor fillColor, KDColor outlineColor) { - if (m_fillColor != fillColor || m_outlineColor != outlineColor) { - m_fillColor = fillColor; - m_outlineColor = outlineColor; - markRectAsDirty(bounds()); - } -} - -KDColor ColorView::fillColor() { - return m_fillColor; -} - -KDColor ColorView::outlineColor() { - return m_outlineColor; -} - -void ColorView::drawRect(KDContext * ctx, KDRect rect) const { - ctx->fillRect(rect, m_outlineColor); - ctx->fillRect(KDRect(k_outlineThickness, k_outlineThickness, bounds().width()-2*k_outlineThickness, bounds().height()-2*k_outlineThickness), m_fillColor); -} - -} diff --git a/apps/hardware_test/color_view.h b/apps/hardware_test/color_view.h deleted file mode 100644 index aedb9b715..000000000 --- a/apps/hardware_test/color_view.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HARDWARE_TEST_COLOR_VIEW_H -#define HARDWARE_TEST_COLOR_VIEW_H - -#include - -namespace HardwareTest { - -class ColorView : public View { -public: - ColorView(); - void setColors(KDColor fillColor, KDColor outlineColor); - KDColor fillColor(); - KDColor outlineColor(); - void drawRect(KDContext * ctx, KDRect rect) const override; -private: - constexpr static KDCoordinate k_outlineThickness = 1; - KDColor m_fillColor; - KDColor m_outlineColor; -}; - -} - -#endif - diff --git a/apps/hardware_test/keyboard_controller.cpp b/apps/hardware_test/keyboard_controller.cpp deleted file mode 100644 index 16e642b0d..000000000 --- a/apps/hardware_test/keyboard_controller.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "keyboard_controller.h" -#include "../apps_container.h" -extern "C" { -#include -} - -namespace HardwareTest { - -KeyboardController::KeyboardController(Responder * parentResponder) : - ViewController(parentResponder), - m_view(), - m_color(KDColorBlack), - m_colorController(nullptr) -{ -} - -View * KeyboardController::view() { - return &m_view; -} - -bool KeyboardController::handleEvent(Ion::Events::Event event) { - Ion::Keyboard::State state = Ion::Keyboard::scan(); - m_view.updateLEDState(m_color); - m_color = nextColor(m_color); - m_view.updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging()); - if (!Ion::Keyboard::keyDown(Ion::Keyboard::ValidKeys[m_view.testedKey()], state)) { - m_view.setDefectiveKey(m_view.testedKey()); - } - if (!m_view.setNextKey()) { - m_view.updateLEDState(KDColorBlack); - ModalViewController * modal = (ModalViewController *)parentResponder(); - modal->displayModalViewController(&m_colorController, 0.0f, 0.0f); - } - return true; -} - -void KeyboardController::viewWillAppear() { - m_view.resetTestedKey(); - m_color = KDColorBlack; - m_view.updateLEDState(m_color); - m_view.updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging()); -} - -KDColor KeyboardController::nextColor(KDColor color) { - if (color == KDColorBlack) { - return KDColorWhite; - } - if (color == KDColorWhite) { - return KDColorRed; - } - if (color == KDColorRed) { - return KDColorBlue; - } - if (color == KDColorBlue) { - return KDColorGreen; - } - if (color == KDColorGreen) { - return KDColorBlack; - } - return KDColorBlack; -} - -} - diff --git a/apps/hardware_test/keyboard_controller.h b/apps/hardware_test/keyboard_controller.h deleted file mode 100644 index bc79a6487..000000000 --- a/apps/hardware_test/keyboard_controller.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef HARDWARE_TEST_KEYBOARD_CONTROLLER_H -#define HARDWARE_TEST_KEYBOARD_CONTROLLER_H - -#include -#include "keyboard_view.h" -#include "color_controller.h" - -namespace HardwareTest { - -class KeyboardController : public ViewController { -public: - KeyboardController(Responder * parentResponder); - View * view() override; - bool handleEvent(Ion::Events::Event event) override; - void viewWillAppear() override; -private: - static KDColor nextColor(KDColor color); - KeyboardView m_view; - KDColor m_color; - ColorController m_colorController; -}; - -} - -#endif - diff --git a/apps/hardware_test/keyboard_test_controller.cpp b/apps/hardware_test/keyboard_test_controller.cpp new file mode 100644 index 000000000..ebb603b02 --- /dev/null +++ b/apps/hardware_test/keyboard_test_controller.cpp @@ -0,0 +1,163 @@ +#include "keyboard_test_controller.h" +#include "../apps_container.h" +extern "C" { +#include +} +#include + +using namespace Poincare; + +namespace HardwareTest { + +constexpr KDColor KeyboardTestController::k_LEDColors[k_numberOfColors]; + +KeyboardTestController::KeyboardTestController(Responder * parentResponder) : + ViewController(parentResponder), + m_view(), + m_LEDColorIndex(0), + m_screenTestController(nullptr) +{ +} + +View * KeyboardTestController::view() { + return &m_view; +} + +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()); + int shift = (uint8_t)Ion::Keyboard::ValidKeys[m_view.keyboardView()->testedKeyIndex()]; + Ion::Keyboard::State onlyKeyDown = (uint64_t)1 << shift; + if (state == onlyKeyDown) { + m_view.keyboardView()->setTestedKeyIndex(m_view.keyboardView()->testedKeyIndex()+1); + if (m_view.keyboardView()->testedKeyIndex() == Ion::Keyboard::NumberOfValidKeys) { + setLEDColor(KDColorBlack); + ModalViewController * modal = (ModalViewController *)parentResponder(); + modal->displayModalViewController(&m_screenTestController, 0.0f, 0.0f); + } + } + return true; +} + +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; +} + +} + diff --git a/apps/hardware_test/keyboard_test_controller.h b/apps/hardware_test/keyboard_test_controller.h new file mode 100644 index 000000000..5c54880f5 --- /dev/null +++ b/apps/hardware_test/keyboard_test_controller.h @@ -0,0 +1,49 @@ +#ifndef HARDWARE_TEST_KEYBOARD_CONTROLLER_H +#define HARDWARE_TEST_KEYBOARD_CONTROLLER_H + +#include +#include "keyboard_view.h" +#include "screen_test_controller.h" + +namespace HardwareTest { + +class KeyboardTestController : public ViewController { +public: + KeyboardTestController(Responder * parentResponder); + View * view() override; + 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; + ScreenTestController m_screenTestController; +}; + +} + +#endif + diff --git a/apps/hardware_test/keyboard_view.cpp b/apps/hardware_test/keyboard_view.cpp index 7ed6db4a8..2e4d0b76c 100644 --- a/apps/hardware_test/keyboard_view.cpp +++ b/apps/hardware_test/keyboard_view.cpp @@ -7,109 +7,31 @@ using namespace Poincare; namespace HardwareTest { KeyboardView::KeyboardView() : - m_testedKey(0), - m_batteryLevelView(KDText::FontSize::Small), - m_batteryChargingView(KDText::FontSize::Small), - m_ledStateView(KDText::FontSize::Small) + m_testedKeyIndex(0) { - for (uint8_t i = 0; i < Ion::Keyboard::NumberOfValidKeys; i++) { - m_defectiveKey[i] = 0; - } } -uint8_t KeyboardView::testedKey() const { - return m_testedKey; +int KeyboardView::testedKeyIndex() const { + return m_testedKeyIndex; } -void KeyboardView::setDefectiveKey(uint8_t key) { - if (key < Ion::Keyboard::NumberOfValidKeys && key >= 0) { - m_defectiveKey[key] = 1; - } -} - -bool KeyboardView::setNextKey() { - m_testedKey = m_testedKey+1; - if (m_testedKey == 46) { - return false; - } - markRectAsDirty(bounds()); - return true; -} - -void KeyboardView::resetTestedKey() { - for (uint8_t i = 0; i < Ion::Keyboard::NumberOfValidKeys; i++) { - m_defectiveKey[i] = 0; - } - m_testedKey = 0; +void KeyboardView::setTestedKeyIndex(int i) { + m_testedKeyIndex = i; markRectAsDirty(bounds()); } -void KeyboardView::updateLEDState(KDColor color) { - Ion::LED::setColor(color); - - char ledLevel[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_ledStateView.setText(ledLevel); - - markRectAsDirty(bounds()); -} - -void KeyboardView::updateBatteryState(float batteryLevel, bool batteryCharging) { - char bufferLevel[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_batteryLevelView.setText(bufferLevel); - - char bufferCharging[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_batteryChargingView.setText(bufferCharging); - - markRectAsDirty(bounds()); -} void KeyboardView::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(bounds(), KDColorWhite); - for (uint8_t i = 0; i < Ion::Keyboard::NumberOfValidKeys; i++) { + for (int i = 0; i < Ion::Keyboard::NumberOfValidKeys; i++) { drawKey(i, ctx, rect); } } -void KeyboardView::drawKey(uint8_t keyIndex, KDContext * ctx, KDRect rect) const { - KDColor color = keyIndex == m_testedKey ? KDColorBlue: KDColorBlack; - if (keyIndex < m_testedKey) { - color = m_defectiveKey[keyIndex] == 0 ? KDColorGreen : KDColorRed; +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]; /* the key is on the cross */ @@ -150,25 +72,4 @@ void KeyboardView::drawKey(uint8_t keyIndex, KDContext * ctx, KDRect rect) const } } -void KeyboardView::layoutSubviews() { - 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 KeyboardView::numberOfSubviews() const { - return 3; -} - -View * KeyboardView::subviewAtIndex(int index) { - if (index == 0) { - return &m_batteryLevelView; - } - if (index == 1) { - return &m_batteryChargingView; - } - return &m_ledStateView; -} - } diff --git a/apps/hardware_test/keyboard_view.h b/apps/hardware_test/keyboard_view.h index 348022e2a..47d36abff 100644 --- a/apps/hardware_test/keyboard_view.h +++ b/apps/hardware_test/keyboard_view.h @@ -8,18 +8,11 @@ namespace HardwareTest { class KeyboardView : public View { public: KeyboardView(); - uint8_t testedKey() const; - void setDefectiveKey(uint8_t key); - bool setNextKey(); - void resetTestedKey(); - void updateLEDState(KDColor color); - void updateBatteryState(float batteryLevel, bool batteryCharging); + int testedKeyIndex() const; + void setTestedKeyIndex(int i); void drawRect(KDContext * ctx, KDRect rect) const override; private: - void drawKey(uint8_t key, KDContext * ctx, KDRect rect) const; - void layoutSubviews() override; - int numberOfSubviews() const override; - View * subviewAtIndex(int index) override; + void drawKey(int key, KDContext * ctx, KDRect rect) const; constexpr static int k_margin = 4; constexpr static int k_smallSquareSize = 8; constexpr static int k_bigSquareSize = 14; @@ -27,14 +20,8 @@ private: constexpr static int k_smallRectWidth = 16; constexpr static int k_bigRectHeight = 14; constexpr static int k_bigRectWidth = 20; - constexpr static int k_maxNumberOfCharacters = 20; - uint8_t m_testedKey; - bool m_defectiveKey[Ion::Keyboard::NumberOfValidKeys]; - BufferTextView m_batteryLevelView; - BufferTextView m_batteryChargingView; - BufferTextView m_ledStateView; + int m_testedKeyIndex; }; - } #endif diff --git a/apps/hardware_test/pattern.cpp b/apps/hardware_test/pattern.cpp new file mode 100644 index 000000000..74f57aa09 --- /dev/null +++ b/apps/hardware_test/pattern.cpp @@ -0,0 +1,29 @@ +#include "pattern.h" + +namespace HardwareTest { + +constexpr KDColor Pattern::k_fillColors[Pattern::k_numberOfPatterns]; +constexpr KDColor Pattern::k_outlineColors[Pattern::k_numberOfPatterns]; + +int Pattern::numberOfPatterns() { + return k_numberOfPatterns; +} + +Pattern Pattern::patternAtIndex(int i) { + return Pattern(i); +} + +KDColor Pattern::fillColor() const { + return k_fillColors[m_i]; +} + +KDColor Pattern::outlineColor() const { + return k_outlineColors[m_i]; +} + +Pattern::Pattern(int i) : + m_i(i) +{ +} + +} diff --git a/apps/hardware_test/pattern.h b/apps/hardware_test/pattern.h new file mode 100644 index 000000000..f38bbedbe --- /dev/null +++ b/apps/hardware_test/pattern.h @@ -0,0 +1,25 @@ +#ifndef HARDWARE_TEST_PATTERN_H +#define HARDWARE_TEST_PATTERN_H + +#include + +namespace HardwareTest { + +class Pattern { +public: + static int numberOfPatterns(); + static Pattern patternAtIndex(int i); + KDColor fillColor() const; + KDColor outlineColor() const; +private: + Pattern(int i); + int m_i; + constexpr static int k_numberOfPatterns = 5; + constexpr static KDColor k_fillColors[k_numberOfPatterns] = {KDColorBlack, KDColorRed, KDColorBlue, KDColorGreen, KDColorWhite}; + constexpr static KDColor k_outlineColors[k_numberOfPatterns] = {KDColorWhite, KDColorGreen, KDColorRed, KDColorRed, KDColorGreen}; +}; + +} + +#endif + diff --git a/apps/hardware_test/pattern_view.cpp b/apps/hardware_test/pattern_view.cpp new file mode 100644 index 000000000..a47fcdd84 --- /dev/null +++ b/apps/hardware_test/pattern_view.cpp @@ -0,0 +1,20 @@ +#include "pattern_view.h" + +namespace HardwareTest { + +PatternView::PatternView() : + m_pattern(Pattern::patternAtIndex(0)) +{ +} + +void PatternView::setPattern(Pattern p) { + m_pattern = p; + markRectAsDirty(bounds()); +} + +void PatternView::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(rect, m_pattern.outlineColor()); + ctx->fillRect(KDRect(k_outlineThickness, k_outlineThickness, bounds().width()-2*k_outlineThickness, bounds().height()-2*k_outlineThickness), m_pattern.fillColor()); +} + +} diff --git a/apps/hardware_test/pattern_view.h b/apps/hardware_test/pattern_view.h new file mode 100644 index 000000000..e26e75340 --- /dev/null +++ b/apps/hardware_test/pattern_view.h @@ -0,0 +1,22 @@ +#ifndef HARDWARE_TEST_PATTERN_VIEW_H +#define HARDWARE_TEST_PATTERN_VIEW_H + +#include +#include "pattern.h" + +namespace HardwareTest { + +class PatternView : public View { +public: + PatternView(); + void setPattern(Pattern p); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + constexpr static KDCoordinate k_outlineThickness = 1; + Pattern m_pattern; +}; + +} + +#endif + diff --git a/apps/hardware_test/screen_test_controller.cpp b/apps/hardware_test/screen_test_controller.cpp new file mode 100644 index 000000000..37115a065 --- /dev/null +++ b/apps/hardware_test/screen_test_controller.cpp @@ -0,0 +1,40 @@ +#include "screen_test_controller.h" +#include "../apps_container.h" +extern "C" { +#include +} + +namespace HardwareTest { + +ScreenTestController::ScreenTestController(Responder * parentResponder) : + ViewController(parentResponder), + m_patternIndex(0), + m_view() +{ +} + +View * ScreenTestController::view() { + return &m_view; +} + +bool ScreenTestController::handleEvent(Ion::Events::Event event) { + if (m_patternIndex == Pattern::numberOfPatterns()) { + AppsContainer * container = (AppsContainer *)app()->container(); + container->switchTo(container->appSnapshotAtIndex(0)); + } else { + showNextPattern(); + } + return true; +} + +void ScreenTestController::viewWillAppear() { + m_patternIndex = 0; + showNextPattern(); +} + +void ScreenTestController::showNextPattern() { + m_view.setPattern(Pattern::patternAtIndex(m_patternIndex++)); +} + +} + diff --git a/apps/hardware_test/screen_test_controller.h b/apps/hardware_test/screen_test_controller.h new file mode 100644 index 000000000..2b9570872 --- /dev/null +++ b/apps/hardware_test/screen_test_controller.h @@ -0,0 +1,25 @@ +#ifndef HARDWARE_TEST_SCREEN_TEST_CONTROLLER_H +#define HARDWARE_TEST_SCREEN_TEST_CONTROLLER_H + +#include +#include "pattern_view.h" +#include "pattern.h" + +namespace HardwareTest { + +class ScreenTestController : public ViewController { +public: + ScreenTestController(Responder * parentResponder); + View * view() override; + bool handleEvent(Ion::Events::Event event) override; + void viewWillAppear() override; +private: + void showNextPattern(); + int m_patternIndex; + PatternView m_view; +}; + +} + +#endif +