diff --git a/apps/hardware_test/Makefile b/apps/hardware_test/Makefile index 8a26e2629..f1f6ad15c 100644 --- a/apps/hardware_test/Makefile +++ b/apps/hardware_test/Makefile @@ -1,5 +1,7 @@ app_objs += $(addprefix apps/hardware_test/,\ app.o\ + color_controller.o\ + color_view.o\ keyboard_controller.o\ keyboard_view.o\ ) diff --git a/apps/hardware_test/color_controller.cpp b/apps/hardware_test/color_controller.cpp new file mode 100644 index 000000000..0d22be314 --- /dev/null +++ b/apps/hardware_test/color_controller.cpp @@ -0,0 +1,52 @@ +#include "color_controller.h" +#include "../apps_container.h" +extern "C" { +#include +} + +namespace HardwareTest { + +ColorController::ColorController(Responder * parentResponder) : + ViewController(parentResponder), + m_view(ColorView()) +{ +} + +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->appAtIndex(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 new file mode 100644 index 000000000..a79b39c7c --- /dev/null +++ b/apps/hardware_test/color_controller.h @@ -0,0 +1,23 @@ +#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 new file mode 100644 index 000000000..57744fc72 --- /dev/null +++ b/apps/hardware_test/color_view.cpp @@ -0,0 +1,32 @@ +#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 new file mode 100644 index 000000000..aedb9b715 --- /dev/null +++ b/apps/hardware_test/color_view.h @@ -0,0 +1,24 @@ +#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 index c6e8d49ae..08c1b6f42 100644 --- a/apps/hardware_test/keyboard_controller.cpp +++ b/apps/hardware_test/keyboard_controller.cpp @@ -9,7 +9,8 @@ namespace HardwareTest { KeyboardController::KeyboardController(Responder * parentResponder) : ViewController(parentResponder), m_view(KeyboardView()), - m_color(KDColorBlack) + m_color(KDColorBlack), + m_colorController(ColorController(nullptr)) { } @@ -21,13 +22,14 @@ bool KeyboardController::handleEvent(Ion::Events::Event event) { m_view.updateLEDState(m_color); m_color = nextColor(m_color); m_view.updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging()); - if (event != Ion::Events::Event::PlainKey(m_view.testedKey()) && event != Ion::Events::Event::ShiftKey(m_view.testedKey()) && event != Ion::Events::Event::AlphaKey(m_view.testedKey()) && event != Ion::Events::Event::ShiftAlphaKey(m_view.testedKey())) { + Ion::Keyboard::State state = Ion::Keyboard::scan(); + if (!Ion::Keyboard::keyDown(m_view.testedKey(), state)) { m_view.setDefectiveKey(m_view.testedKey()); } if (!m_view.setNextKey()) { m_view.updateLEDState(KDColorBlack); - AppsContainer * container = (AppsContainer *)app()->container(); - container->switchTo(container->appAtIndex(0)); + ModalViewController * modal = (ModalViewController *)parentResponder(); + modal->displayModalViewController(&m_colorController, 0.0f, 0.0f); } return true; } diff --git a/apps/hardware_test/keyboard_controller.h b/apps/hardware_test/keyboard_controller.h index ae02c1178..bc79a6487 100644 --- a/apps/hardware_test/keyboard_controller.h +++ b/apps/hardware_test/keyboard_controller.h @@ -3,6 +3,7 @@ #include #include "keyboard_view.h" +#include "color_controller.h" namespace HardwareTest { @@ -16,6 +17,7 @@ private: static KDColor nextColor(KDColor color); KeyboardView m_view; KDColor m_color; + ColorController m_colorController; }; }