diff --git a/Universal_Serial_Adapter/UI.cpp b/Universal_Serial_Adapter/UI.cpp index 5966db4..e858599 100644 --- a/Universal_Serial_Adapter/UI.cpp +++ b/Universal_Serial_Adapter/UI.cpp @@ -8,6 +8,8 @@ attribute. */ +#include + #include "Project.h" #include "UI.h" @@ -20,6 +22,8 @@ UI::UI(Config* aConfig) { lcd = new UILCD(config); + uiTimeout = new Metro(config->getTimeoutMilis()); + startUI(); } @@ -40,6 +44,13 @@ void UI::enableUI() { lcd->turnOn(); okButton->turnOnLed(); cancelButton->turnOnLed(); + uiTimeout->reset(); +} + +void UI::processTimeoutEvents() { + if (uiTimeout->check() == 1) { + disableUI(); + } } void UI::processInputEvents() { diff --git a/Universal_Serial_Adapter/UI.h b/Universal_Serial_Adapter/UI.h index 9cbded4..c7fba3c 100644 --- a/Universal_Serial_Adapter/UI.h +++ b/Universal_Serial_Adapter/UI.h @@ -8,14 +8,7 @@ attribute. */ -// UI State machine (current element = config / stats / inline display of data) -// Configuration state machine (speed, pinout, logic level, sd card on/off, boot logo on/off) -// Message to config (element + new value) -// Message to UI (element + success/fail) - -// Button's controlling UI -// UIButton* okButton = new UIButton(22, 23); -// UIButton* cancelButton = new UIButton(24, 25); +#include #include "Project.h" #include "UIButton.h" @@ -35,11 +28,14 @@ private: Config* config; + Metro* uiTimeout; + public: UI(Config* aConfig); void startUI(); void processInputEvents(); + void processTimeoutEvents(); void disableUI(); void enableUI(); diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 4af2da8..f9546db 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -8,6 +8,8 @@ attribute. */ +#include + #include "Project.h" #include "Config.h" #include "UIButton.h" @@ -20,13 +22,9 @@ #include #include -#include - UI* ui; Config* config; -//Metro uiTimeout = Metro(250); - void setup() { Serial.begin(9600); Serial.println("Setup!"); @@ -35,16 +33,10 @@ void setup() { config->setDefaults(); ui = new UI(config); - - //uiTimeout = Metro(config->getTimeoutMilis()); } void loop() { - // FIXME: Move timer to UI under its own method - // if (uiTimeout.check() == 1) { - // ui->disableUI(); - // } - ui->processInputEvents(); + ui->processTimeoutEvents(); }