Implemented UI timeout

This commit is contained in:
Mike C 2013-04-07 01:32:42 -04:00
parent d96b20c81d
commit 7ba91945ee
9 changed files with 155 additions and 33 deletions

View file

@ -18,6 +18,18 @@ Config::Config() {
currentTimeout = never;
}
bool Config::isUIEnabled() {
return uiEnabled;
}
void Config::enableUI() {
uiEnabled = true;
}
void Config::disableUI() {
uiEnabled = false;
}
serialmode Config::getSerialMode() {
return currentMode;
}
@ -34,6 +46,20 @@ timeout Config::getTimeout() {
return currentTimeout;
}
long Config::getTimeoutMilis() {
switch (currentTimeout) {
case 0: // tenseconds
return 10000;
case 1: // thirtyseconds
return 30000;
case 2: // oneminute
return 60000;
case 3: // fiveminutes
return 300000;
}
return -1;
}
void Config::setMode(serialmode mode) {
currentMode = mode;
}
@ -55,4 +81,4 @@ void Config::setDefaults() {
setLineSpeed(oneNineteenTwoK);
setVoltage(onePointEight);
setTimeout(thirtyseconds);
}
}

View file

@ -20,6 +20,9 @@ private:
linespeed currentLineSpeed;
ttlvoltage currentVoltage;
timeout currentTimeout;
bool uiEnabled;
public:
Config();
@ -32,6 +35,10 @@ public:
linespeed getLineSpeed();
ttlvoltage getVoltage();
timeout getTimeout();
long getTimeoutMilis();
void disableUI();
void enableUI();
bool isUIEnabled();
};
#endif
#endif

View file

@ -21,6 +21,7 @@
#define pspXPin 0 // After GND / @ edge
#define pspYPin 1 // Between VCC and gnd
// LCD Pinouts
#define LCD_LITE 26 // Backlight pin
#define SD_CS 7 // Chip select line for SD card
#define LCD_CS 53 // Chip select line for TFT display
#define LCD_DC 9 // Data/command line for TFT

View file

@ -7,4 +7,68 @@
use this code however you'd like, just keep this license and
attribute.
*/
#include "Project.h"
#include "UI.h"
UI::UI(Config* aConfig) {
config = aConfig;
okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
lcd = new UILCD(config);
startUI();
}
void UI::startUI() {
enableUI();
lcd->start();
}
void UI::disableUI() {
config->disableUI();
lcd->turnOff();
okButton->turnOffLed();
cancelButton->turnOffLed();
}
void UI::enableUI() {
config->enableUI();
lcd->turnOn();
okButton->turnOnLed();
cancelButton->turnOnLed();
}
void UI::processInputEvents() {
joyStickEvent = pspJoystick->direction();
if (joyStickEvent != joyNone) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
if (DEBUG) {
Serial.print("Joystick Event: ");
Serial.println(joyStickEvent);
}
lcd->handleJoystickEvent(joyStickEvent);
}
if (okButton->isPressed()) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
lcd->handleOkButtonEvent();
}
if (cancelButton->isPressed()) {
if (!config->isUIEnabled()) {
enableUI();
return;
}
lcd->handleCancelButtonEvent();
}
}

View file

@ -16,3 +16,31 @@
// Button's controlling UI
// UIButton* okButton = new UIButton(22, 23);
// UIButton* cancelButton = new UIButton(24, 25);
#include "Project.h"
#include "UIButton.h"
#include "UIJoystickPSP.h"
#include "UILCD.h"
#include "Config.h"
class UI {
private:
UIButton* okButton;
UIButton* cancelButton;
UIJoystickPSP* pspJoystick;
joyDirection joyStickEvent;
UILCD* lcd;
Config* config;
public:
UI(Config* aConfig);
void startUI();
void processInputEvents();
void disableUI();
void enableUI();
};

View file

@ -21,8 +21,6 @@ UIButton::UIButton(int buttonPin, int ledPin) {
void UIButton::setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
turnOnLed();
}
void UIButton::turnOnLed() {

View file

@ -20,6 +20,8 @@
#include "UIJoystickPSP.h"
UILCD::UILCD(Config* config) {
pinMode(LCD_LITE, OUTPUT);
this->config = config;
tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST);
@ -31,11 +33,19 @@ UILCD::UILCD(Config* config) {
}
}
void UILCD::startUI() {
void UILCD::start() {
drawSplashScreen();
drawMainScreen();
}
void UILCD::turnOn() {
digitalWrite(LCD_LITE, HIGH);
}
void UILCD::turnOff() {
digitalWrite(LCD_LITE, LOW);
}
void UILCD::handleJoystickEvent(joyDirection direction) {
if (DEBUG) {
Serial.println("begin UILCD::handleJoystickEvent");

View file

@ -60,10 +60,12 @@ private:
public:
UILCD(Config* config);
void bmpDraw(char *filename, uint8_t x, uint8_t y);
void startUI();
void handleJoystickEvent(joyDirection aDirection);
void handleOkButtonEvent();
void handleCancelButtonEvent();
void turnOff();
void turnOn();
void start();
};
#endif

View file

@ -13,20 +13,19 @@
#include "UIButton.h"
#include "UIJoystickPSP.h"
#include "UILCD.h"
#include "UI.h"
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SD.h>
#include <SPI.h>
UILCD* lcd;
#include <Metro.h>
UI* ui;
Config* config;
UIButton* okButton;
UIButton* cancelButton;
UIJoystickPSP* pspJoystick;
joyDirection joyStickEvent;
Metro* uiTimeout;
void setup() {
Serial.begin(9600);
@ -35,30 +34,17 @@ void setup() {
config = new Config();
config->setDefaults();
okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
lcd = new UILCD(config);
lcd->startUI();
ui = new UI(config);
uiTimeout = new Metro(config->getTimeoutMilis(), false);
}
void loop() {
joyStickEvent = pspJoystick->direction();
if (joyStickEvent != joyNone) {
if (DEBUG) {
Serial.print("Joystick Event: ");
Serial.println(joyStickEvent);
}
lcd->handleJoystickEvent(joyStickEvent);
// FIXME: Move timer to UI under its own method
if (uiTimeout->check()) {
ui->disableUI();
}
if (okButton->isPressed()) {
lcd->handleOkButtonEvent();
}
if (cancelButton->isPressed()) {
lcd->handleCancelButtonEvent();
}
ui->processInputEvents();
}