Added configuration tracking and management to UI

Also added timeout option
This commit is contained in:
Mike C 2013-04-06 23:20:17 -04:00
parent 1cda1fe0b7
commit ceb50fbdb5
6 changed files with 195 additions and 47 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -63,7 +63,7 @@ enum linespeed {
zero=-1 zero=-1
}; };
enum voltage { enum ttlvoltage {
onePointEight, onePointEight,
threePointThree, threePointThree,
five, five,
@ -82,12 +82,4 @@ struct linespeedinfo {
// Known and supported line speeds // Known and supported line speeds
extern linespeedinfo linespeeds[]; 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 #endif

View file

@ -19,7 +19,9 @@
#include "UILCD.h" #include "UILCD.h"
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
UILCD::UILCD() { UILCD::UILCD(Config* config) {
this->config = config;
tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST); tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST);
tft->initR(INITR_BLACKTAB); tft->initR(INITR_BLACKTAB);
tft->setRotation(3); tft->setRotation(3);
@ -62,6 +64,18 @@ void UILCD::handleOkButtonEvent() {
case 1: // enum screen -> mainScreen case 1: // enum screen -> mainScreen
mainScreenOkButton(); mainScreenOkButton();
break; 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() { void UILCD::mainScreenOkButton() {
switch(currentLine) { switch(currentLine) {
case 0: // Connection Type case 0: // Connection Type
drawConnectionScreen(); drawConnectionScreen(false);
break; break;
case 1: // Line speed case 1: // Line speed
drawLineSpeedScreen(); drawLineSpeedScreen(false);
break; break;
case 2: // Voltage case 2: // Voltage
drawVoltageScreen(); drawVoltageScreen(false);
break; break;
// case 4: // start data log // case 4: // start data log
// break; // break;
@ -128,26 +142,51 @@ void UILCD::mainScreenHilight(joyDirection direction) {
currentLine -= 1; currentLine -= 1;
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) {
Serial.println("Serial ttl blank line skip");
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine -= 1; currentLine -= 1;
} }
}
else {
Serial.println("Non-serial ttl blank line skip");
if (currentLine == 2 || currentLine == 5) {
currentLine -= 1;
}
}
hilightLine(currentLine); hilightLine(currentLine);
} }
if (direction == joyDown) { if (direction == joyDown) {
// Don't go past the last line // Don't go past the last line
if (config->getSerialMode() == ttl) {
if (currentLine == 8) {
return;
}
}
else {
if (currentLine == 7) { if (currentLine == 7) {
return; return;
} }
}
unHilightLine(currentLine); unHilightLine(currentLine);
currentLine += 1; currentLine += 1;
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) {
Serial.println("Serial ttl blank line skip");
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine += 1; currentLine += 1;
} }
}
else {
Serial.println("Non-serial ttl blank line skip");
if (currentLine == 2 || currentLine == 5) {
currentLine += 1;
}
}
hilightLine(currentLine); hilightLine(currentLine);
} }
@ -194,9 +233,11 @@ void UILCD::configScreenHighlight(joyDirection direction) {
} }
} }
void UILCD::drawConnectionScreen() { void UILCD::drawConnectionScreen(bool keepCurrentLine) {
currentScreen = connectionScreen; currentScreen = connectionScreen;
if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
}
tft->setCursor(0,0); tft->setCursor(0,0);
tft->fillScreen(BACKGROUND); tft->fillScreen(BACKGROUND);
@ -208,16 +249,27 @@ void UILCD::drawConnectionScreen() {
tft->println(); tft->println();
for (int i=0; i<maxserialmode; i++) { for (int i=0; i<maxserialmode; i++) {
if (config->getSerialMode() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" "); tft->print(" ");
tft->println(modeToText[i]); tft->println(modeToText[i]);
tft->setTextColor(TEXT);
} }
if (keepCurrentLine) {
hilightLine(currentLine);
}
else {
hilightLine(3); hilightLine(3);
} }
}
void UILCD::drawLineSpeedScreen() { void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
currentScreen = lineSpeedScreen; currentScreen = lineSpeedScreen;
if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
}
tft->setCursor(0,0); tft->setCursor(0,0);
tft->fillScreen(BACKGROUND); tft->fillScreen(BACKGROUND);
@ -229,16 +281,27 @@ void UILCD::drawLineSpeedScreen() {
tft->println(); tft->println();
for (int i=0; i<maxlinespeed; i++) { for (int i=0; i<maxlinespeed; i++) {
if (config->getLineSpeed() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" "); tft->print(" ");
tft->println(linespeeds[i].description); tft->println(linespeeds[i].description);
tft->setTextColor(TEXT);
} }
if (keepCurrentLine) {
hilightLine(currentLine);
}
else {
hilightLine(3); hilightLine(3);
} }
}
void UILCD::drawVoltageScreen() { void UILCD::drawVoltageScreen(bool keepCurrentLine) {
currentScreen = voltageScreen; currentScreen = voltageScreen;
if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
}
tft->setCursor(0,0); tft->setCursor(0,0);
tft->fillScreen(BACKGROUND); tft->fillScreen(BACKGROUND);
@ -250,12 +313,21 @@ void UILCD::drawVoltageScreen() {
tft->println(); tft->println();
for (int i=0; i<maxvoltage; i++) { for (int i=0; i<maxvoltage; i++) {
if (config->getVoltage() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" "); tft->print(" ");
tft->println(voltageToText[i]); tft->println(voltageToText[i]);
tft->setTextColor(TEXT);
} }
if (keepCurrentLine) {
hilightLine(currentLine);
}
else {
hilightLine(3); hilightLine(3);
} }
}
void UILCD::drawMainScreen() { void UILCD::drawMainScreen() {
currentScreen = mainScreen; currentScreen = mainScreen;
@ -267,11 +339,13 @@ void UILCD::drawMainScreen() {
tft->setTextWrap(true); tft->setTextWrap(true);
tft->print(" Con Typ: "); 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->print(" Line Speed: ");
tft->println(linespeeds[4].description); // TODO: This should be pulled out from the config tft->println(linespeeds[config->getLineSpeed()].description);
tft->print(" Voltage (TTL Only): "); // TODO: Show this only if in TTL mode if (config->getSerialMode() == ttl) {
tft->println(voltageToText[2]); // TODO: This should be pulled from the config tft->print(" Voltage (TTL Only): ");
tft->println(voltageToText[config->getVoltage()]);
}
tft->println(); tft->println();
tft->println(" Start data logging"); tft->println(" Start data logging");
@ -279,6 +353,7 @@ void UILCD::drawMainScreen() {
tft->println(); tft->println();
tft->println(" Configure RTC / Clock"); tft->println(" Configure RTC / Clock");
tft->println(" Configure timeout");
hilightLine(0); hilightLine(0);
} }

View file

@ -17,6 +17,7 @@
#include "Project.h" #include "Project.h"
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
#include "Config.h"
#ifndef UILCD_h #ifndef UILCD_h
#define UILCD_h #define UILCD_h
@ -34,6 +35,7 @@ enum screen {
class UILCD { class UILCD {
private: private:
Adafruit_ST7735* tft; Adafruit_ST7735* tft;
Config* config;
int currentLine; int currentLine;
screen currentScreen; screen currentScreen;
@ -43,9 +45,9 @@ private:
void drawSplashScreen(); void drawSplashScreen();
void drawMainScreen(); void drawMainScreen();
void drawConnectionScreen(); void drawConnectionScreen(bool keepCurrentLine);
void drawLineSpeedScreen(); void drawLineSpeedScreen(bool keepCurrentLine);
void drawVoltageScreen(); void drawVoltageScreen(bool keepCurrentLine);
void hilightLine(int line); void hilightLine(int line);
void unHilightLine(int line); void unHilightLine(int line);
void mainScreenHilight(joyDirection direction); void mainScreenHilight(joyDirection direction);
@ -54,7 +56,7 @@ private:
void mainScreenCancelButton(); void mainScreenCancelButton();
public: public:
UILCD(); UILCD(Config* config);
void bmpDraw(char *filename, uint8_t x, uint8_t y); void bmpDraw(char *filename, uint8_t x, uint8_t y);
void startUI(); void startUI();
void handleJoystickEvent(joyDirection aDirection); void handleJoystickEvent(joyDirection aDirection);

View file

@ -9,6 +9,7 @@
*/ */
#include "Project.h" #include "Project.h"
#include "Config.h"
#include "UIButton.h" #include "UIButton.h"
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
#include "UILCD.h" #include "UILCD.h"
@ -18,33 +19,29 @@
#include <SD.h> #include <SD.h>
#include <SPI.h> #include <SPI.h>
UILCD* lcd;
Config* config;
UIButton* okButton; UIButton* okButton;
UIButton* cancelButton; UIButton* cancelButton;
UIJoystickPSP* pspJoystick; UIJoystickPSP* pspJoystick;
UILCD* lcd;
joyDirection joyStickEvent; joyDirection joyStickEvent;
// Defaults
void setDefaults() {
//FIXME: Re-enable once new LCD is online
//setMode(phone);
//setSelection(phone);
//setLineSpeed(oneNineteenTwoK);
}
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Serial.println("Setup!"); Serial.println("Setup!");
// Setup defaults config = new Config();
setDefaults(); config->setDefaults();
okButton = new UIButton(okButtonPin, okButtonLed); okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin); pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
lcd = new UILCD(); lcd = new UILCD(config);
lcd->startUI(); lcd->startUI();
} }