mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] First version of keyboard hardware test
Change-Id: Ic322575f22f1576eacf0068bc3aa09257e2ae3f4
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
include apps/calculation/Makefile
|
||||
include apps/graph/Makefile
|
||||
include apps/home/Makefile
|
||||
include apps/hardware_test/Makefile
|
||||
include apps/probability/Makefile
|
||||
include apps/regression/Makefile
|
||||
include apps/sequence/Makefile
|
||||
|
||||
@@ -14,6 +14,7 @@ AppsContainer::AppsContainer() :
|
||||
m_graphApp(this, &m_globalContext),
|
||||
m_probabilityApp(this),
|
||||
m_calculationApp(this, &m_globalContext),
|
||||
m_hardwareTestApp(this),
|
||||
m_regressionApp(this),
|
||||
m_sequenceApp(this, &m_globalContext),
|
||||
m_settingsApp(this),
|
||||
@@ -34,7 +35,7 @@ App * AppsContainer::appAtIndex(int index) {
|
||||
&m_calculationApp,
|
||||
&m_graphApp,
|
||||
&m_sequenceApp,
|
||||
&m_graphApp,
|
||||
&m_hardwareTestApp,
|
||||
&m_statisticsApp,
|
||||
&m_probabilityApp,
|
||||
&m_regressionApp,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "graph/app.h"
|
||||
#include "probability/app.h"
|
||||
#include "calculation/app.h"
|
||||
#include "hardware_test/app.h"
|
||||
#include "regression/app.h"
|
||||
#include "sequence/app.h"
|
||||
#include "settings/app.h"
|
||||
@@ -38,6 +39,7 @@ private:
|
||||
Graph::App m_graphApp;
|
||||
Probability::App m_probabilityApp;
|
||||
Calculation::App m_calculationApp;
|
||||
HardwareTest::App m_hardwareTestApp;
|
||||
Regression::App m_regressionApp;
|
||||
Sequence::App m_sequenceApp;
|
||||
Settings::App m_settingsApp;
|
||||
|
||||
7
apps/hardware_test/Makefile
Normal file
7
apps/hardware_test/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
app_objs += $(addprefix apps/hardware_test/,\
|
||||
app.o\
|
||||
keyboard_controller.o\
|
||||
keyboard_view.o\
|
||||
)
|
||||
|
||||
|
||||
16
apps/hardware_test/app.cpp
Normal file
16
apps/hardware_test/app.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "app.h"
|
||||
#include "../apps_container.h"
|
||||
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
App::App(AppsContainer * container) :
|
||||
::App(container, &m_keyboardController),
|
||||
m_keyboardController(KeyboardController(&m_modalViewController))
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
21
apps/hardware_test/app.h
Normal file
21
apps/hardware_test/app.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef HARDWARE_TEST_APP_H
|
||||
#define HARDWARE_TEST_APP_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "keyboard_controller.h"
|
||||
|
||||
class AppsContainer;
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
class App : public ::App {
|
||||
public:
|
||||
App(AppsContainer * container);
|
||||
private:
|
||||
KeyboardController m_keyboardController;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
31
apps/hardware_test/keyboard_controller.cpp
Normal file
31
apps/hardware_test/keyboard_controller.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "keyboard_controller.h"
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
KeyboardController::KeyboardController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_view(KeyboardView())
|
||||
{
|
||||
}
|
||||
|
||||
View * KeyboardController::view() {
|
||||
return &m_view;
|
||||
}
|
||||
|
||||
bool KeyboardController::handleEvent(Ion::Events::Event event) {
|
||||
if (event != Ion::Events::Event::PlainKey(m_view.testedKey())) {
|
||||
m_view.setDefectiveKey(m_view.testedKey());
|
||||
}
|
||||
m_view.setNextKey();
|
||||
return true;
|
||||
}
|
||||
|
||||
void KeyboardController::didBecomeFirstResponder() {
|
||||
m_view.resetTestedKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
apps/hardware_test/keyboard_controller.h
Normal file
24
apps/hardware_test/keyboard_controller.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef HARDWARE_TEST_KEYBOARD_CONTROLLER_H
|
||||
#define HARDWARE_TEST_KEYBOARD_CONTROLLER_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "keyboard_view.h"
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
class KeyboardController : public ViewController {
|
||||
public:
|
||||
KeyboardController(Responder * parentResponder);
|
||||
|
||||
View * view() override;
|
||||
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void didBecomeFirstResponder() override;
|
||||
private:
|
||||
KeyboardView m_view;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
88
apps/hardware_test/keyboard_view.cpp
Normal file
88
apps/hardware_test/keyboard_view.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "keyboard_view.h"
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
KeyboardView::KeyboardView() :
|
||||
m_testedKey(Ion::Keyboard::Key::A1)
|
||||
{
|
||||
for (int i = 0; i < Ion::Keyboard::NumberOfKeys; i++) {
|
||||
m_defectiveKey[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Ion::Keyboard::Key KeyboardView::testedKey() const {
|
||||
return m_testedKey;
|
||||
}
|
||||
|
||||
void KeyboardView::setDefectiveKey(Ion::Keyboard::Key key) {
|
||||
m_defectiveKey[(int)key] = 1;
|
||||
}
|
||||
|
||||
void KeyboardView::setNextKey() {
|
||||
m_testedKey = (Ion::Keyboard::Key)((int)m_testedKey+1);
|
||||
int keyIndex = (int)m_testedKey;
|
||||
if (keyIndex == 54) {
|
||||
resetTestedKey();
|
||||
}
|
||||
if ((keyIndex > 7 && keyIndex < 12) || keyIndex == 35 || keyIndex == 41 || keyIndex == 47 || keyIndex == 53) {
|
||||
setNextKey();
|
||||
}
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void KeyboardView::resetTestedKey() {
|
||||
m_testedKey = Ion::Keyboard::Key::A1;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
|
||||
void KeyboardView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), KDColorWhite);
|
||||
for (int i = 0; i < Ion::Keyboard::NumberOfKeys; i++) {
|
||||
drawKey(i, ctx, rect);
|
||||
}
|
||||
}
|
||||
|
||||
void KeyboardView::drawKey(int keyIndex, KDContext * ctx, KDRect rect) const {
|
||||
KDColor color = keyIndex == (int)m_testedKey ? KDColorBlue: KDColorBlack;
|
||||
if (keyIndex < (int)m_testedKey) {
|
||||
color = m_defectiveKey[keyIndex] == 0 ? KDColorGreen : KDColorRed;
|
||||
}
|
||||
/* the key is on the cross */
|
||||
if (keyIndex < 4) {
|
||||
KDCoordinate x = keyIndex == 1 || keyIndex == 2 ? k_margin + k_smallSquareSize : k_margin;
|
||||
x = keyIndex == 3 ? x + 2*k_smallSquareSize : x;
|
||||
KDCoordinate y = keyIndex == 0 || keyIndex == 3 ? k_margin + k_smallSquareSize : k_margin;
|
||||
y = keyIndex == 2 ? y + 2*k_smallSquareSize : y;
|
||||
ctx->fillRect(KDRect(x, y, k_smallSquareSize, k_smallSquareSize), color);
|
||||
}
|
||||
/* the key is a "OK" or "back" */
|
||||
if (keyIndex >= 4 && keyIndex < 6) {
|
||||
KDCoordinate x = keyIndex == 4 ? 5*k_margin + 3*k_smallSquareSize + 2*k_bigRectWidth : 6*k_margin + 3*k_smallSquareSize + 2*k_bigRectWidth + k_bigSquareSize;
|
||||
KDCoordinate y = 2*k_margin;
|
||||
ctx->fillRect(KDRect(x, y, k_bigSquareSize, k_bigSquareSize), color);
|
||||
}
|
||||
/* the key is a "home" or "power" */
|
||||
if (keyIndex >= 6 && keyIndex < 8) {
|
||||
KDCoordinate x = 3*k_margin + 3*k_smallSquareSize;
|
||||
KDCoordinate y = keyIndex == 6 ? k_margin : 2*k_margin + k_bigRectHeight;
|
||||
ctx->fillRect(KDRect(x, y, k_bigRectWidth, k_bigRectHeight), color);
|
||||
}
|
||||
/* the key is a small key as "shift", "alpha" ...*/
|
||||
if (keyIndex >= 12 && keyIndex < 30) {
|
||||
int j = (keyIndex - 12)/6;
|
||||
int i = (keyIndex - 12) - 6*j;
|
||||
KDCoordinate x = (i+1)*k_margin + i*k_smallRectWidth;
|
||||
KDCoordinate y = 2*k_bigRectHeight + (j+3)*k_margin + j*k_smallRectHeight;
|
||||
ctx->fillRect(KDRect(x, y, k_smallRectWidth, k_smallRectHeight), color);
|
||||
}
|
||||
/* the key is a big key as "7", "Ans" ...*/
|
||||
if (keyIndex >= 30 && keyIndex != 35 && keyIndex != 41 && keyIndex != 47 && keyIndex != 53) {
|
||||
int j = (keyIndex - 30)/6;
|
||||
int i = (keyIndex - 30) - 6*j;
|
||||
KDCoordinate x = (i+1)*k_margin + i*k_bigRectWidth;
|
||||
KDCoordinate y = 2*k_bigRectHeight + 3*k_smallRectHeight + (j+6)*k_margin + j*k_bigRectHeight;
|
||||
ctx->fillRect(KDRect(x, y, k_bigRectWidth, k_bigRectHeight), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
apps/hardware_test/keyboard_view.h
Normal file
32
apps/hardware_test/keyboard_view.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef HARDWARE_TEST_KEYBOARD_VIEW_H
|
||||
#define HARDWARE_TEST_KEYBOARD_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
namespace HardwareTest {
|
||||
|
||||
class KeyboardView : public View {
|
||||
public:
|
||||
KeyboardView();
|
||||
Ion::Keyboard::Key testedKey() const;
|
||||
void setDefectiveKey(Ion::Keyboard::Key key);
|
||||
void setNextKey();
|
||||
void resetTestedKey();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
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;
|
||||
constexpr static int k_smallRectHeight = 8;
|
||||
constexpr static int k_smallRectWidth = 16;
|
||||
constexpr static int k_bigRectHeight = 14;
|
||||
constexpr static int k_bigRectWidth = 20;
|
||||
Ion::Keyboard::Key m_testedKey;
|
||||
int m_defectiveKey[Ion::Keyboard::NumberOfKeys];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user