This repository has been archived on 2020-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
arduino_universal_serial_ad.../Universal_Serial_Adapter/UI.cpp

131 lines
2.3 KiB
C++
Raw Normal View History

/*
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
#include <Metro.h>
2013-04-07 05:32:42 +00:00
#include "Project.h"
#include "UI.h"
UI::UI() {
#if DEBUG == 2
serialPort0.println("Config::UI()");
#endif
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();
2013-04-07 05:32:42 +00:00
uiTimeout = new Metro(config->getTimeoutMilis());
2013-04-07 05:32:42 +00:00
startUI();
}
void UI::blinkOKButton() {
if (config->isUIEnabled()) {
okButton->turnOffLed();
okButton->turnOnLed();
}
else {
okButton->turnOnLed();
okButton->turnOffLed();
}
}
void UI::blinkCancelButton() {
if (config->isUIEnabled()) {
cancelButton->turnOffLed();
cancelButton->turnOnLed();
}
else {
cancelButton->turnOnLed();
cancelButton->turnOffLed();
}
}
void UI::setLCDTimeout() {
uiTimeout->interval(config->getTimeoutMilis());
}
void UI::resetTimeout() {
uiTimeout->reset();
}
2013-04-07 05:32:42 +00:00
void UI::startUI() {
#if DEBUG == 2
serialPort0.println("Config::startUI()");
#endif
2013-04-07 05:32:42 +00:00
enableUI();
lcd->start();
}
void UI::disableUI() {
#if DEBUG == 2
serialPort0.println("Config::disableUI()");
#endif
2013-04-07 05:32:42 +00:00
config->disableUI();
lcd->turnOff();
okButton->turnOffLed();
cancelButton->turnOffLed();
}
void UI::enableUI() {
#if DEBUG == 2
serialPort0.println("Config::enableUI()");
#endif
2013-04-07 05:32:42 +00:00
config->enableUI();
lcd->turnOn();
okButton->turnOnLed();
cancelButton->turnOnLed();
uiTimeout->reset();
}
void UI::processTimeoutEvents() {
if (uiTimeout->check()) {
disableUI();
}
2013-04-07 05:32:42 +00:00
}
void UI::processInputEvents() {
joyStickEvent = pspJoystick->direction();
if (joyStickEvent != joyNone) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
#if DEBUG == 2
serialPort0.print("Joystick Event: ");
serialPort0.println(joyStickEvent);
#endif
resetTimeout();
2013-04-07 05:32:42 +00:00
lcd->handleJoystickEvent(joyStickEvent);
}
if (okButton->isPressed()) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
resetTimeout();
2013-04-07 05:32:42 +00:00
lcd->handleOkButtonEvent();
}
if (cancelButton->isPressed()) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
resetTimeout();
2013-04-07 05:32:42 +00:00
lcd->handleCancelButtonEvent();
}
}