From d96b20c81d91ce24ede35853816b8c3b05405a88 Mon Sep 17 00:00:00 2001 From: Mike C Date: Sun, 7 Apr 2013 00:49:23 -0400 Subject: [PATCH] Added timeout management screen --- Universal_Serial_Adapter/Config.cpp | 10 +++++ Universal_Serial_Adapter/Config.h | 3 ++ Universal_Serial_Adapter/Project.cpp | 10 ++++- Universal_Serial_Adapter/Project.h | 11 +++++ Universal_Serial_Adapter/UILCD.cpp | 44 +++++++++++++++++++ Universal_Serial_Adapter/UILCD.h | 4 +- .../Universal_Serial_Adapter.ino | 2 - 7 files changed, 80 insertions(+), 4 deletions(-) diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp index 42932ee..fcfb3cd 100644 --- a/Universal_Serial_Adapter/Config.cpp +++ b/Universal_Serial_Adapter/Config.cpp @@ -15,6 +15,7 @@ Config::Config() { currentMode = none; currentLineSpeed = zero; currentVoltage = negOne; + currentTimeout = never; } serialmode Config::getSerialMode() { @@ -29,6 +30,10 @@ ttlvoltage Config::getVoltage() { return currentVoltage; } +timeout Config::getTimeout() { + return currentTimeout; +} + void Config::setMode(serialmode mode) { currentMode = mode; } @@ -41,8 +46,13 @@ void Config::setVoltage(ttlvoltage voltage) { currentVoltage = voltage; } +void Config::setTimeout(timeout aTimeout) { + currentTimeout = aTimeout; +} + void Config::setDefaults() { setMode(ttl); setLineSpeed(oneNineteenTwoK); setVoltage(onePointEight); + setTimeout(thirtyseconds); } \ No newline at end of file diff --git a/Universal_Serial_Adapter/Config.h b/Universal_Serial_Adapter/Config.h index 9a10a35..701a45e 100644 --- a/Universal_Serial_Adapter/Config.h +++ b/Universal_Serial_Adapter/Config.h @@ -19,6 +19,7 @@ private: serialmode currentMode; linespeed currentLineSpeed; ttlvoltage currentVoltage; + timeout currentTimeout; public: Config(); @@ -26,9 +27,11 @@ public: void setMode(serialmode mode); void setLineSpeed(linespeed speed); void setVoltage(ttlvoltage voltage); + void setTimeout(timeout aTimeout); serialmode getSerialMode(); linespeed getLineSpeed(); ttlvoltage getVoltage(); + timeout getTimeout(); }; #endif \ No newline at end of file diff --git a/Universal_Serial_Adapter/Project.cpp b/Universal_Serial_Adapter/Project.cpp index 5bb9506..27d34eb 100644 --- a/Universal_Serial_Adapter/Project.cpp +++ b/Universal_Serial_Adapter/Project.cpp @@ -31,4 +31,12 @@ linespeedinfo linespeeds[6] = { { "38.4k", 38400 }, { "57.5k", 57600 }, { "115k", 115200 } -}; \ No newline at end of file +}; + +char* timeoutToText[5] = { + "10s", + "30s", + "1m", + "5m", + "Never" +}; diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index 783feda..c646476 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -82,4 +82,15 @@ struct linespeedinfo { // Known and supported line speeds extern linespeedinfo linespeeds[]; +enum timeout { + tenseconds, + thirtyseconds, + oneminute, + fiveminutes, + never, + maxtimeout +}; + +extern char* timeoutToText[]; + #endif diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp index c0c5669..178b487 100644 --- a/Universal_Serial_Adapter/UILCD.cpp +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -76,6 +76,10 @@ void UILCD::handleOkButtonEvent() { config->setVoltage((ttlvoltage)(currentLine - 3)); drawVoltageScreen(true); break; + case 5: // timeoutScreen + config->setTimeout((timeout)(currentLine - 3)); + drawTimeoutScreen(true); + break; } } @@ -113,6 +117,9 @@ void UILCD::mainScreenOkButton() { // break; // case 7: // configure rtc // break; + case 8: + drawTimeoutScreen(false); + break; } } @@ -223,6 +230,11 @@ void UILCD::configScreenHighlight(joyDirection direction) { return; } break; + case 5: // timeoutScreen + if (currentLine == maxtimeout + 2) { + return; + } + break; } unHilightLine(currentLine); @@ -233,6 +245,38 @@ void UILCD::configScreenHighlight(joyDirection direction) { } } +void UILCD::drawTimeoutScreen(bool keepCurrentLine) { + currentScreen = timeoutscreen; + if (!keepCurrentLine) { + currentLine = 3; + } + + tft->setCursor(0,0); + tft->fillScreen(BACKGROUND); + tft->setTextColor(TEXT); + tft->setTextWrap(true); + + tft->println("Timout selection"); + tft->println(" Current value is yellow"); + tft->println(); + + for (int i=0; igetTimeout() == i) { + tft->setTextColor(HILIGHT); + } + tft->print(" "); + tft->println(timeoutToText[i]); + tft->setTextColor(TEXT); + } + + if (keepCurrentLine) { + hilightLine(currentLine); + } + else { + hilightLine(3); + } +} + void UILCD::drawConnectionScreen(bool keepCurrentLine) { currentScreen = connectionScreen; if (!keepCurrentLine) { diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h index f6d312e..251aa8d 100644 --- a/Universal_Serial_Adapter/UILCD.h +++ b/Universal_Serial_Adapter/UILCD.h @@ -29,7 +29,8 @@ enum screen { mainScreen, connectionScreen, lineSpeedScreen, - voltageScreen + voltageScreen, + timeoutscreen }; class UILCD { @@ -48,6 +49,7 @@ private: void drawConnectionScreen(bool keepCurrentLine); void drawLineSpeedScreen(bool keepCurrentLine); void drawVoltageScreen(bool keepCurrentLine); + void drawTimeoutScreen(bool keepCurrentLine); void hilightLine(int line); void unHilightLine(int line); void mainScreenHilight(joyDirection direction); diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 9dc2236..be60f8e 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -28,8 +28,6 @@ UIJoystickPSP* pspJoystick; joyDirection joyStickEvent; - - void setup() { Serial.begin(9600); Serial.println("Setup!");