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; currentTimeout = never;
} }
bool Config::isUIEnabled() {
return uiEnabled;
}
void Config::enableUI() {
uiEnabled = true;
}
void Config::disableUI() {
uiEnabled = false;
}
serialmode Config::getSerialMode() { serialmode Config::getSerialMode() {
return currentMode; return currentMode;
} }
@ -34,6 +46,20 @@ timeout Config::getTimeout() {
return currentTimeout; 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) { void Config::setMode(serialmode mode) {
currentMode = mode; currentMode = mode;
} }
@ -55,4 +81,4 @@ void Config::setDefaults() {
setLineSpeed(oneNineteenTwoK); setLineSpeed(oneNineteenTwoK);
setVoltage(onePointEight); setVoltage(onePointEight);
setTimeout(thirtyseconds); setTimeout(thirtyseconds);
} }

View file

@ -20,6 +20,9 @@ private:
linespeed currentLineSpeed; linespeed currentLineSpeed;
ttlvoltage currentVoltage; ttlvoltage currentVoltage;
timeout currentTimeout; timeout currentTimeout;
bool uiEnabled;
public: public:
Config(); Config();
@ -32,6 +35,10 @@ public:
linespeed getLineSpeed(); linespeed getLineSpeed();
ttlvoltage getVoltage(); ttlvoltage getVoltage();
timeout getTimeout(); 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 pspXPin 0 // After GND / @ edge
#define pspYPin 1 // Between VCC and gnd #define pspYPin 1 // Between VCC and gnd
// LCD Pinouts // LCD Pinouts
#define LCD_LITE 26 // Backlight pin
#define SD_CS 7 // Chip select line for SD card #define SD_CS 7 // Chip select line for SD card
#define LCD_CS 53 // Chip select line for TFT display #define LCD_CS 53 // Chip select line for TFT display
#define LCD_DC 9 // Data/command line for TFT #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 use this code however you'd like, just keep this license and
attribute. 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 // Button's controlling UI
// UIButton* okButton = new UIButton(22, 23); // UIButton* okButton = new UIButton(22, 23);
// UIButton* cancelButton = new UIButton(24, 25); // 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() { void UIButton::setup() {
pinMode(buttonPin, INPUT); pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
turnOnLed();
} }
void UIButton::turnOnLed() { void UIButton::turnOnLed() {

View file

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

View file

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

View file

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