Files
Upsilon/apps/hardware_test/keyboard_controller.cpp
Émilie Feral 96733dbbdc [apps] Rule of 5 (3)
Change-Id: Ia85b23a09e9debd62b4f3590463a4f16454ef4b7
2017-05-09 14:33:53 +02:00

65 lines
1.5 KiB
C++

#include "keyboard_controller.h"
#include "../apps_container.h"
extern "C" {
#include <assert.h>
}
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) {
m_view.updateLEDState(m_color);
m_color = nextColor(m_color);
m_view.updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
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);
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;
}
}