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

View file

@ -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,26 +142,51 @@ void UILCD::mainScreenHilight(joyDirection direction) {
currentLine -= 1;
// Skip blank lines
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);
}
if (direction == joyDown) {
// Don't go past the last line
if (config->getSerialMode() == ttl) {
if (currentLine == 8) {
return;
}
}
else {
if (currentLine == 7) {
return;
}
}
unHilightLine(currentLine);
currentLine += 1;
// Skip blank lines
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;
if (!keepCurrentLine) {
currentLine = 3;
}
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
@ -208,16 +249,27 @@ void UILCD::drawConnectionScreen() {
tft->println();
for (int i=0; i<maxserialmode; i++) {
if (config->getSerialMode() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" ");
tft->println(modeToText[i]);
tft->setTextColor(TEXT);
}
if (keepCurrentLine) {
hilightLine(currentLine);
}
else {
hilightLine(3);
}
}
void UILCD::drawLineSpeedScreen() {
void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
currentScreen = lineSpeedScreen;
if (!keepCurrentLine) {
currentLine = 3;
}
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
@ -229,16 +281,27 @@ void UILCD::drawLineSpeedScreen() {
tft->println();
for (int i=0; i<maxlinespeed; i++) {
if (config->getLineSpeed() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" ");
tft->println(linespeeds[i].description);
tft->setTextColor(TEXT);
}
if (keepCurrentLine) {
hilightLine(currentLine);
}
else {
hilightLine(3);
}
}
void UILCD::drawVoltageScreen() {
void UILCD::drawVoltageScreen(bool keepCurrentLine) {
currentScreen = voltageScreen;
if (!keepCurrentLine) {
currentLine = 3;
}
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
@ -250,11 +313,20 @@ void UILCD::drawVoltageScreen() {
tft->println();
for (int i=0; i<maxvoltage; i++) {
if (config->getVoltage() == i) {
tft->setTextColor(HILIGHT);
}
tft->print(" ");
tft->println(voltageToText[i]);
tft->setTextColor(TEXT);
}
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);
}

View file

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

View file

@ -9,6 +9,7 @@
*/
#include "Project.h"
#include "Config.h"
#include "UIButton.h"
#include "UIJoystickPSP.h"
#include "UILCD.h"
@ -18,33 +19,29 @@
#include <SD.h>
#include <SPI.h>
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();
}