diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp index ca841e5..30894d0 100644 --- a/Universal_Serial_Adapter/Config.cpp +++ b/Universal_Serial_Adapter/Config.cpp @@ -12,11 +12,13 @@ #include "Project.h" #include "Config.h" +#include "UI.h" Config::Config() { if (DEBUG) { Serial.println("Config::Config()"); } + currentMode = none; currentLineSpeed = zero; currentVoltage = negOne; @@ -198,6 +200,7 @@ void Config::setLCDTimeout(timeout aTimeout) { Serial.println("Config::setTimeout()"); } currentTimeout = aTimeout; + ui->setLCDTimeout(); } void Config::setDefaults() { diff --git a/Universal_Serial_Adapter/Config.h b/Universal_Serial_Adapter/Config.h index d93d67e..8b22026 100644 --- a/Universal_Serial_Adapter/Config.h +++ b/Universal_Serial_Adapter/Config.h @@ -8,11 +8,18 @@ attribute. */ -#include "Project.h" - #ifndef 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 { private: // Mode info needed diff --git a/Universal_Serial_Adapter/UI.cpp b/Universal_Serial_Adapter/UI.cpp index 9275306..8198a04 100644 --- a/Universal_Serial_Adapter/UI.cpp +++ b/Universal_Serial_Adapter/UI.cpp @@ -13,11 +13,10 @@ #include "Project.h" #include "UI.h" -UI::UI(Config* aConfig) { +UI::UI() { if (DEBUG) { Serial.println("Config::UI()"); } - config = aConfig; okButton = new UIButton(okButtonPin, okButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); @@ -30,6 +29,10 @@ UI::UI(Config* aConfig) { startUI(); } +void UI::setLCDTimeout() { + uiTimeout->interval(config->getTimeoutMilis()); +} + void UI::startUI() { if (DEBUG) { Serial.println("Config::startUI()"); @@ -60,7 +63,7 @@ void UI::enableUI() { } void UI::processTimeoutEvents() { - if (uiTimeout->check() == 1) { + if (uiTimeout->check()) { disableUI(); } } diff --git a/Universal_Serial_Adapter/UI.h b/Universal_Serial_Adapter/UI.h index c7fba3c..38fe0a0 100644 --- a/Universal_Serial_Adapter/UI.h +++ b/Universal_Serial_Adapter/UI.h @@ -8,6 +8,9 @@ attribute. */ +#ifndef UI_h +#define UI_h + #include #include "Project.h" @@ -16,6 +19,13 @@ #include "UILCD.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 { private: UIButton* okButton; @@ -26,12 +36,10 @@ private: UILCD* lcd; - Config* config; - Metro* uiTimeout; public: - UI(Config* aConfig); + UI(); void startUI(); void processInputEvents(); @@ -39,4 +47,8 @@ public: void disableUI(); void enableUI(); + + void setLCDTimeout(); }; + +#endif diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h index c025d85..0dfc97e 100644 --- a/Universal_Serial_Adapter/UILCD.h +++ b/Universal_Serial_Adapter/UILCD.h @@ -8,6 +8,9 @@ attribute. */ +#ifndef UILCD_h +#define UILCD_h + #include "Arduino.h" #include @@ -19,8 +22,8 @@ #include "UIJoystickPSP.h" #include "Config.h" -#ifndef UILCD_h -#define UILCD_h +// Forward declaration of Config +class Config; #define BUFFPIXEL 20 diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 97b3740..dcd3b55 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -31,7 +31,7 @@ void setup() { config = new Config(); config->setDefaults(); - ui = new UI(config); + ui = new UI(); } void loop() {