From ceb50fbdb54a986161bb6e30180d1124d6755bb0 Mon Sep 17 00:00:00 2001 From: Mike C Date: Sat, 6 Apr 2013 23:20:17 -0400 Subject: [PATCH] Added configuration tracking and management to UI Also added timeout option --- Universal_Serial_Adapter/Config.cpp | 48 +++++++ Universal_Serial_Adapter/Config.h | 34 +++++ Universal_Serial_Adapter/Project.h | 10 +- Universal_Serial_Adapter/UILCD.cpp | 121 ++++++++++++++---- Universal_Serial_Adapter/UILCD.h | 10 +- .../Universal_Serial_Adapter.ino | 19 ++- 6 files changed, 195 insertions(+), 47 deletions(-) create mode 100644 Universal_Serial_Adapter/Config.cpp create mode 100644 Universal_Serial_Adapter/Config.h diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp new file mode 100644 index 0000000..42932ee --- /dev/null +++ b/Universal_Serial_Adapter/Config.cpp @@ -0,0 +1,48 @@ +/* + Serial Adapter Project: Dynamic serial TTY passthroughs + by: Mike Crosson + Nusku Networks + date: 2013/03/09 + license: CC-BY SA 3.0 - Creative commons share-alike 3.0 + use this code however you'd like, just keep this license and + attribute. + */ + +#include "Project.h" +#include "Config.h" + +Config::Config() { + currentMode = none; + currentLineSpeed = zero; + currentVoltage = negOne; +} + +serialmode Config::getSerialMode() { + return currentMode; +} + +linespeed Config::getLineSpeed() { + return currentLineSpeed; +} + +ttlvoltage Config::getVoltage() { + return currentVoltage; +} + +void Config::setMode(serialmode mode) { + currentMode = mode; +} + +void Config::setLineSpeed(linespeed speed) { + currentLineSpeed = speed; +} + +void Config::setVoltage(ttlvoltage voltage) { + currentVoltage = voltage; +} + +void Config::setDefaults() { + setMode(ttl); + setLineSpeed(oneNineteenTwoK); + setVoltage(onePointEight); +} \ No newline at end of file diff --git a/Universal_Serial_Adapter/Config.h b/Universal_Serial_Adapter/Config.h new file mode 100644 index 0000000..9a10a35 --- /dev/null +++ b/Universal_Serial_Adapter/Config.h @@ -0,0 +1,34 @@ +/* + Serial Adapter Project: Dynamic serial TTY passthroughs + by: Mike Crosson + Nusku Networks + date: 2013/03/09 + license: CC-BY SA 3.0 - Creative commons share-alike 3.0 + use this code however you'd like, just keep this license and + attribute. + */ + +#include "Project.h" + +#ifndef Config_h +#define Config_h + +class Config { +private: + // Mode info needed + serialmode currentMode; + linespeed currentLineSpeed; + ttlvoltage currentVoltage; + +public: + Config(); + void setDefaults(); + void setMode(serialmode mode); + void setLineSpeed(linespeed speed); + void setVoltage(ttlvoltage voltage); + serialmode getSerialMode(); + linespeed getLineSpeed(); + ttlvoltage getVoltage(); +}; + +#endif \ No newline at end of file diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index 9ac8b37..783feda 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -63,7 +63,7 @@ enum linespeed { zero=-1 }; -enum voltage { +enum ttlvoltage { onePointEight, threePointThree, five, @@ -82,12 +82,4 @@ struct linespeedinfo { // Known and supported line speeds extern linespeedinfo linespeeds[]; -// Mode info needed -extern serialmode currentMode; -extern serialmode selectedMode; -extern linespeed currentLineSpeed; -extern linespeed selectedLineSpeed; -extern voltage currentVoltage; -extern voltage selectedVoltage; - #endif diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp index 014c0e5..c0c5669 100644 --- a/Universal_Serial_Adapter/UILCD.cpp +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -19,7 +19,9 @@ #include "UILCD.h" #include "UIJoystickPSP.h" -UILCD::UILCD() { +UILCD::UILCD(Config* config) { + this->config = config; + tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST); tft->initR(INITR_BLACKTAB); tft->setRotation(3); @@ -62,6 +64,18 @@ void UILCD::handleOkButtonEvent() { case 1: // enum screen -> mainScreen mainScreenOkButton(); break; + case 2: // connectionScreen + config->setMode((serialmode)(currentLine - 3)); + drawConnectionScreen(true); + break; + case 3: // lineSpeedScreen + config->setLineSpeed((linespeed)(currentLine - 3)); + drawLineSpeedScreen(true); + break; + case 4: // voltageScreen + config->setVoltage((ttlvoltage)(currentLine - 3)); + drawVoltageScreen(true); + break; } } @@ -85,13 +99,13 @@ void UILCD::handleCancelButtonEvent() { void UILCD::mainScreenOkButton() { switch(currentLine) { case 0: // Connection Type - drawConnectionScreen(); + drawConnectionScreen(false); break; case 1: // Line speed - drawLineSpeedScreen(); + drawLineSpeedScreen(false); break; case 2: // Voltage - drawVoltageScreen(); + drawVoltageScreen(false); break; // case 4: // start data log // break; @@ -128,8 +142,17 @@ void UILCD::mainScreenHilight(joyDirection direction) { currentLine -= 1; // Skip blank lines - if (currentLine == 3 || currentLine == 6) { - currentLine -= 1; + if (config->getSerialMode() == ttl) { + Serial.println("Serial ttl blank line skip"); + if (currentLine == 3 || currentLine == 6) { + currentLine -= 1; + } + } + else { + Serial.println("Non-serial ttl blank line skip"); + if (currentLine == 2 || currentLine == 5) { + currentLine -= 1; + } } hilightLine(currentLine); @@ -137,16 +160,32 @@ void UILCD::mainScreenHilight(joyDirection direction) { if (direction == joyDown) { // Don't go past the last line - if (currentLine == 7) { - return; + if (config->getSerialMode() == ttl) { + if (currentLine == 8) { + return; + } + } + else { + if (currentLine == 7) { + return; + } } unHilightLine(currentLine); currentLine += 1; // Skip blank lines - if (currentLine == 3 || currentLine == 6) { - currentLine += 1; + if (config->getSerialMode() == ttl) { + Serial.println("Serial ttl blank line skip"); + if (currentLine == 3 || currentLine == 6) { + currentLine += 1; + } + } + else { + Serial.println("Non-serial ttl blank line skip"); + if (currentLine == 2 || currentLine == 5) { + currentLine += 1; + } } hilightLine(currentLine); @@ -194,9 +233,11 @@ void UILCD::configScreenHighlight(joyDirection direction) { } } -void UILCD::drawConnectionScreen() { +void UILCD::drawConnectionScreen(bool keepCurrentLine) { currentScreen = connectionScreen; - currentLine = 3; + if (!keepCurrentLine) { + currentLine = 3; + } tft->setCursor(0,0); tft->fillScreen(BACKGROUND); @@ -208,16 +249,27 @@ void UILCD::drawConnectionScreen() { tft->println(); for (int i=0; igetSerialMode() == i) { + tft->setTextColor(HILIGHT); + } tft->print(" "); tft->println(modeToText[i]); + tft->setTextColor(TEXT); } - hilightLine(3); + if (keepCurrentLine) { + hilightLine(currentLine); + } + else { + hilightLine(3); + } } -void UILCD::drawLineSpeedScreen() { +void UILCD::drawLineSpeedScreen(bool keepCurrentLine) { currentScreen = lineSpeedScreen; - currentLine = 3; + if (!keepCurrentLine) { + currentLine = 3; + } tft->setCursor(0,0); tft->fillScreen(BACKGROUND); @@ -229,16 +281,27 @@ void UILCD::drawLineSpeedScreen() { tft->println(); for (int i=0; igetLineSpeed() == i) { + tft->setTextColor(HILIGHT); + } tft->print(" "); tft->println(linespeeds[i].description); + tft->setTextColor(TEXT); } - hilightLine(3); + if (keepCurrentLine) { + hilightLine(currentLine); + } + else { + hilightLine(3); + } } -void UILCD::drawVoltageScreen() { +void UILCD::drawVoltageScreen(bool keepCurrentLine) { currentScreen = voltageScreen; - currentLine = 3; + if (!keepCurrentLine) { + currentLine = 3; + } tft->setCursor(0,0); tft->fillScreen(BACKGROUND); @@ -250,11 +313,20 @@ void UILCD::drawVoltageScreen() { tft->println(); for (int i=0; igetVoltage() == i) { + tft->setTextColor(HILIGHT); + } tft->print(" "); tft->println(voltageToText[i]); + tft->setTextColor(TEXT); } - hilightLine(3); + if (keepCurrentLine) { + hilightLine(currentLine); + } + else { + hilightLine(3); + } } void UILCD::drawMainScreen() { @@ -267,11 +339,13 @@ void UILCD::drawMainScreen() { tft->setTextWrap(true); tft->print(" Con Typ: "); - tft->println(modeToText[1]); // TODO: This should be pulled from the config + tft->println(modeToText[config->getSerialMode()]); // TODO: This should be pulled from the config tft->print(" Line Speed: "); - tft->println(linespeeds[4].description); // TODO: This should be pulled out from the config - tft->print(" Voltage (TTL Only): "); // TODO: Show this only if in TTL mode - tft->println(voltageToText[2]); // TODO: This should be pulled from the config + tft->println(linespeeds[config->getLineSpeed()].description); + if (config->getSerialMode() == ttl) { + tft->print(" Voltage (TTL Only): "); + tft->println(voltageToText[config->getVoltage()]); + } tft->println(); tft->println(" Start data logging"); @@ -279,6 +353,7 @@ void UILCD::drawMainScreen() { tft->println(); tft->println(" Configure RTC / Clock"); + tft->println(" Configure timeout"); hilightLine(0); } diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h index fc7296e..f6d312e 100644 --- a/Universal_Serial_Adapter/UILCD.h +++ b/Universal_Serial_Adapter/UILCD.h @@ -17,6 +17,7 @@ #include "Project.h" #include "UIJoystickPSP.h" +#include "Config.h" #ifndef UILCD_h #define UILCD_h @@ -34,6 +35,7 @@ enum screen { class UILCD { private: Adafruit_ST7735* tft; + Config* config; int currentLine; screen currentScreen; @@ -43,9 +45,9 @@ private: void drawSplashScreen(); void drawMainScreen(); - void drawConnectionScreen(); - void drawLineSpeedScreen(); - void drawVoltageScreen(); + void drawConnectionScreen(bool keepCurrentLine); + void drawLineSpeedScreen(bool keepCurrentLine); + void drawVoltageScreen(bool keepCurrentLine); void hilightLine(int line); void unHilightLine(int line); void mainScreenHilight(joyDirection direction); @@ -54,7 +56,7 @@ private: void mainScreenCancelButton(); public: - UILCD(); + UILCD(Config* config); void bmpDraw(char *filename, uint8_t x, uint8_t y); void startUI(); void handleJoystickEvent(joyDirection aDirection); diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 9231b56..9dc2236 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -9,6 +9,7 @@ */ #include "Project.h" +#include "Config.h" #include "UIButton.h" #include "UIJoystickPSP.h" #include "UILCD.h" @@ -18,33 +19,29 @@ #include #include +UILCD* lcd; +Config* config; + UIButton* okButton; UIButton* cancelButton; UIJoystickPSP* pspJoystick; -UILCD* lcd; joyDirection joyStickEvent; -// Defaults -void setDefaults() { - //FIXME: Re-enable once new LCD is online - //setMode(phone); - //setSelection(phone); - //setLineSpeed(oneNineteenTwoK); -} + void setup() { Serial.begin(9600); Serial.println("Setup!"); - // Setup defaults - setDefaults(); + config = new Config(); + config->setDefaults(); okButton = new UIButton(okButtonPin, okButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); pspJoystick = new UIJoystickPSP(pspXPin, pspYPin); - lcd = new UILCD(); + lcd = new UILCD(config); lcd->startUI(); }