Fix: timeout configuration is now used to control UI timeout

This commit is contained in:
Mike C 2013-04-17 19:59:03 -04:00
parent 6b4f698d02
commit ebd4ac5d04
6 changed files with 39 additions and 11 deletions

View file

@ -12,11 +12,13 @@
#include "Project.h" #include "Project.h"
#include "Config.h" #include "Config.h"
#include "UI.h"
Config::Config() { Config::Config() {
if (DEBUG) { if (DEBUG) {
Serial.println("Config::Config()"); Serial.println("Config::Config()");
} }
currentMode = none; currentMode = none;
currentLineSpeed = zero; currentLineSpeed = zero;
currentVoltage = negOne; currentVoltage = negOne;
@ -198,6 +200,7 @@ void Config::setLCDTimeout(timeout aTimeout) {
Serial.println("Config::setTimeout()"); Serial.println("Config::setTimeout()");
} }
currentTimeout = aTimeout; currentTimeout = aTimeout;
ui->setLCDTimeout();
} }
void Config::setDefaults() { void Config::setDefaults() {

View file

@ -8,11 +8,18 @@
attribute. attribute.
*/ */
#include "Project.h"
#ifndef Config_h #ifndef Config_h
#define Config_h #define Config_h
#include "Project.h"
#include "UI.h"
// Forward declaration of UI
class UI;
// Use global config and ui objects defined / initialized in main ino file
extern UI* ui;
class Config { class Config {
private: private:
// Mode info needed // Mode info needed

View file

@ -13,11 +13,10 @@
#include "Project.h" #include "Project.h"
#include "UI.h" #include "UI.h"
UI::UI(Config* aConfig) { UI::UI() {
if (DEBUG) { if (DEBUG) {
Serial.println("Config::UI()"); Serial.println("Config::UI()");
} }
config = aConfig;
okButton = new UIButton(okButtonPin, okButtonLed); okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
@ -30,6 +29,10 @@ UI::UI(Config* aConfig) {
startUI(); startUI();
} }
void UI::setLCDTimeout() {
uiTimeout->interval(config->getTimeoutMilis());
}
void UI::startUI() { void UI::startUI() {
if (DEBUG) { if (DEBUG) {
Serial.println("Config::startUI()"); Serial.println("Config::startUI()");
@ -60,7 +63,7 @@ void UI::enableUI() {
} }
void UI::processTimeoutEvents() { void UI::processTimeoutEvents() {
if (uiTimeout->check() == 1) { if (uiTimeout->check()) {
disableUI(); disableUI();
} }
} }

View file

@ -8,6 +8,9 @@
attribute. attribute.
*/ */
#ifndef UI_h
#define UI_h
#include <Metro.h> #include <Metro.h>
#include "Project.h" #include "Project.h"
@ -16,6 +19,13 @@
#include "UILCD.h" #include "UILCD.h"
#include "Config.h" #include "Config.h"
// Forward declaration of Config
class Config;
class UILCD;
// Use global config and ui objects defined / initialized in main ino file
extern Config* config;
class UI { class UI {
private: private:
UIButton* okButton; UIButton* okButton;
@ -26,12 +36,10 @@ private:
UILCD* lcd; UILCD* lcd;
Config* config;
Metro* uiTimeout; Metro* uiTimeout;
public: public:
UI(Config* aConfig); UI();
void startUI(); void startUI();
void processInputEvents(); void processInputEvents();
@ -39,4 +47,8 @@ public:
void disableUI(); void disableUI();
void enableUI(); void enableUI();
void setLCDTimeout();
}; };
#endif

View file

@ -8,6 +8,9 @@
attribute. attribute.
*/ */
#ifndef UILCD_h
#define UILCD_h
#include "Arduino.h" #include "Arduino.h"
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
@ -19,8 +22,8 @@
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
#include "Config.h" #include "Config.h"
#ifndef UILCD_h // Forward declaration of Config
#define UILCD_h class Config;
#define BUFFPIXEL 20 #define BUFFPIXEL 20

View file

@ -31,7 +31,7 @@ void setup() {
config = new Config(); config = new Config();
config->setDefaults(); config->setDefaults();
ui = new UI(config); ui = new UI();
} }
void loop() { void loop() {