2013-04-05 16:41:21 +00:00
|
|
|
/*
|
|
|
|
Serial Adapter Project: Dynamic serial TTY passthroughs
|
|
|
|
by: Mike Crosson
|
|
|
|
Nusku Networks
|
|
|
|
date: 2013/03/09
|
|
|
|
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
|
|
|
use this code however you'd like, just keep this license and
|
|
|
|
attribute.
|
|
|
|
*/
|
2013-04-07 05:32:42 +00:00
|
|
|
|
2013-04-09 21:56:19 +00:00
|
|
|
#include <Metro.h>
|
|
|
|
|
2013-04-07 05:32:42 +00:00
|
|
|
#include "Project.h"
|
|
|
|
#include "UI.h"
|
|
|
|
|
2013-04-17 23:59:03 +00:00
|
|
|
UI::UI() {
|
2013-04-17 02:02:09 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Serial.println("Config::UI()");
|
|
|
|
}
|
2013-04-07 05:32:42 +00:00
|
|
|
|
|
|
|
okButton = new UIButton(okButtonPin, okButtonLed);
|
|
|
|
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
|
|
|
|
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
|
|
|
|
|
|
|
|
lcd = new UILCD(config);
|
|
|
|
|
2013-04-09 21:56:19 +00:00
|
|
|
uiTimeout = new Metro(config->getTimeoutMilis());
|
|
|
|
|
2013-04-07 05:32:42 +00:00
|
|
|
startUI();
|
|
|
|
}
|
|
|
|
|
2013-04-17 23:59:03 +00:00
|
|
|
void UI::setLCDTimeout() {
|
|
|
|
uiTimeout->interval(config->getTimeoutMilis());
|
|
|
|
}
|
|
|
|
|
2013-04-18 00:06:53 +00:00
|
|
|
void UI::resetTimeout() {
|
|
|
|
uiTimeout->reset();
|
|
|
|
}
|
|
|
|
|
2013-04-07 05:32:42 +00:00
|
|
|
void UI::startUI() {
|
2013-04-17 02:02:09 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Serial.println("Config::startUI()");
|
|
|
|
}
|
2013-04-07 05:32:42 +00:00
|
|
|
enableUI();
|
|
|
|
lcd->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::disableUI() {
|
2013-04-17 02:02:09 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Serial.println("Config::disableUI()");
|
|
|
|
}
|
2013-04-07 05:32:42 +00:00
|
|
|
config->disableUI();
|
|
|
|
lcd->turnOff();
|
|
|
|
okButton->turnOffLed();
|
|
|
|
cancelButton->turnOffLed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::enableUI() {
|
2013-04-17 02:02:09 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Serial.println("Config::enableUI()");
|
|
|
|
}
|
2013-04-07 05:32:42 +00:00
|
|
|
config->enableUI();
|
|
|
|
lcd->turnOn();
|
|
|
|
okButton->turnOnLed();
|
|
|
|
cancelButton->turnOnLed();
|
2013-04-09 21:56:19 +00:00
|
|
|
uiTimeout->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI::processTimeoutEvents() {
|
2013-04-17 23:59:03 +00:00
|
|
|
if (uiTimeout->check()) {
|
2013-04-09 21:56:19 +00:00
|
|
|
disableUI();
|
|
|
|
}
|
2013-04-07 05:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UI::processInputEvents() {
|
|
|
|
joyStickEvent = pspJoystick->direction();
|
|
|
|
if (joyStickEvent != joyNone) {
|
|
|
|
if (!config->isUIEnabled()) {
|
|
|
|
enableUI();
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 00:06:53 +00:00
|
|
|
|
2013-04-07 05:32:42 +00:00
|
|
|
if (DEBUG) {
|
|
|
|
Serial.print("Joystick Event: ");
|
|
|
|
Serial.println(joyStickEvent);
|
|
|
|
}
|
2013-04-18 00:06:53 +00:00
|
|
|
resetTimeout();
|
2013-04-07 05:32:42 +00:00
|
|
|
lcd->handleJoystickEvent(joyStickEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (okButton->isPressed()) {
|
|
|
|
if (!config->isUIEnabled()) {
|
|
|
|
enableUI();
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 00:06:53 +00:00
|
|
|
resetTimeout();
|
2013-04-07 05:32:42 +00:00
|
|
|
lcd->handleOkButtonEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cancelButton->isPressed()) {
|
|
|
|
if (!config->isUIEnabled()) {
|
|
|
|
enableUI();
|
|
|
|
return;
|
|
|
|
}
|
2013-04-18 00:06:53 +00:00
|
|
|
resetTimeout();
|
2013-04-07 05:32:42 +00:00
|
|
|
lcd->handleCancelButtonEvent();
|
|
|
|
}
|
|
|
|
}
|