mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/hardware_test] Add solid color views at the end of the hardware
test Change-Id: I48e75048d11e71f5198e1b70de6d9150f852919b
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
app_objs += $(addprefix apps/hardware_test/,\
|
||||
app.o\
|
||||
color_controller.o\
|
||||
color_view.o\
|
||||
keyboard_controller.o\
|
||||
keyboard_view.o\
|
||||
)
|
||||
|
||||
52
apps/hardware_test/color_controller.cpp
Normal file
52
apps/hardware_test/color_controller.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "color_controller.h"
|
||||
#include "../apps_container.h"
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
23
apps/hardware_test/color_controller.h
Normal file
23
apps/hardware_test/color_controller.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef HARDWARE_TEST_COLOR_CONTROLLER_H
|
||||
#define HARDWARE_TEST_COLOR_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#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
|
||||
|
||||
32
apps/hardware_test/color_view.cpp
Normal file
32
apps/hardware_test/color_view.cpp
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
24
apps/hardware_test/color_view.h
Normal file
24
apps/hardware_test/color_view.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef HARDWARE_TEST_COLOR_VIEW_H
|
||||
#define HARDWARE_TEST_COLOR_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <escher.h>
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user