Implemented configuration screens and further navigation

This commit is contained in:
Mike C 2013-04-06 22:24:15 -04:00
parent 171bf68d36
commit 1cda1fe0b7
5 changed files with 201 additions and 16 deletions

View file

@ -11,7 +11,7 @@
#include "Project.h"
// Map a mode -> text value
char* modeToText[4] = {
char* modeToText[3] = {
"Serial TTL",
"DB9 - Null Mdm",
"Cisco console"

View file

@ -43,6 +43,7 @@ enum serialmode {
ttl,
db9_null,
cisco,
maxserialmode,
none=-1
};
@ -66,6 +67,7 @@ enum voltage {
onePointEight,
threePointThree,
five,
maxvoltage,
negOne=-1
};

View file

@ -45,9 +45,67 @@ void UILCD::handleJoystickEvent(joyDirection direction) {
case 1: // enum screen -> mainScreen
mainScreenHilight(direction);
break;
default: // config screens
configScreenHighlight(direction);
break;
}
}
void UILCD::handleOkButtonEvent() {
if (DEBUG) {
Serial.println("begin UILCD::handleOkButtonEvent");
Serial.print("Current Screen: ");
Serial.println(currentScreen);
}
switch (currentScreen) {
case 1: // enum screen -> mainScreen
mainScreenOkButton();
break;
}
}
void UILCD::handleCancelButtonEvent() {
if (DEBUG) {
Serial.println("begin UILCD::handleCancelButtonEvent");
Serial.print("Current Screen: ");
Serial.println(currentScreen);
}
switch (currentScreen) {
case 1: // enum screen -> mainScreen
mainScreenCancelButton();
break;
default:
drawMainScreen();
break;
}
}
void UILCD::mainScreenOkButton() {
switch(currentLine) {
case 0: // Connection Type
drawConnectionScreen();
break;
case 1: // Line speed
drawLineSpeedScreen();
break;
case 2: // Voltage
drawVoltageScreen();
break;
// case 4: // start data log
// break;
// case 5: // view serial data
// break;
// case 7: // configure rtc
// break;
}
}
void UILCD::mainScreenCancelButton() {
// Do nothing for now
}
void UILCD::unHilightLine(int line) {
tft->setCursor(0, line * FONT_HEIGHT);
tft->fillRect(0, line * FONT_HEIGHT, FONT_WIDTH, FONT_HEIGHT, BACKGROUND);
@ -62,43 +120,148 @@ void UILCD::hilightLine(int line) {
void UILCD::mainScreenHilight(joyDirection direction) {
if (direction == joyUp) {
// Don't go up past the 1st line
if (previousLine == 0) {
if (currentLine == 0) {
return;
}
unHilightLine(previousLine);
unHilightLine(currentLine);
previousLine -= 1;
currentLine -= 1;
// Skip blank lines
if (previousLine == 3 || previousLine == 6) {
previousLine -= 1;
if (currentLine == 3 || currentLine == 6) {
currentLine -= 1;
}
hilightLine(previousLine);
hilightLine(currentLine);
}
if (direction == joyDown) {
// Don't go past the last line
if (previousLine == 7) {
if (currentLine == 7) {
return;
}
unHilightLine(previousLine);
unHilightLine(currentLine);
previousLine += 1;
currentLine += 1;
// Skip blank lines
if (previousLine == 3 || previousLine == 6) {
previousLine += 1;
if (currentLine == 3 || currentLine == 6) {
currentLine += 1;
}
hilightLine(previousLine);
hilightLine(currentLine);
}
}
void UILCD::configScreenHighlight(joyDirection direction) {
if (direction == joyUp) {
// Don't go up past the 1st line
if (currentLine == 3) {
return;
}
unHilightLine(currentLine);
currentLine -= 1;
hilightLine(currentLine);
}
if (direction == joyDown) {
// Don't go past the last line
switch (currentScreen) {
case 2: // connectionScreen
if (currentLine == maxserialmode + 2) {
return;
}
break;
case 3: // lineSpeedScreen
if (currentLine == maxlinespeed + 2) {
return;
}
break;
case 4: // voltageScreen
if (currentLine == maxvoltage + 2) {
return;
}
break;
}
unHilightLine(currentLine);
currentLine += 1;
hilightLine(currentLine);
}
}
void UILCD::drawConnectionScreen() {
currentScreen = connectionScreen;
currentLine = 3;
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
tft->setTextColor(TEXT);
tft->setTextWrap(true);
tft->println("Type Selection");
tft->println(" Current value is yellow");
tft->println();
for (int i=0; i<maxserialmode; i++) {
tft->print(" ");
tft->println(modeToText[i]);
}
hilightLine(3);
}
void UILCD::drawLineSpeedScreen() {
currentScreen = lineSpeedScreen;
currentLine = 3;
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
tft->setTextColor(TEXT);
tft->setTextWrap(true);
tft->println("Speed Selection");
tft->println(" Current value is yellow");
tft->println();
for (int i=0; i<maxlinespeed; i++) {
tft->print(" ");
tft->println(linespeeds[i].description);
}
hilightLine(3);
}
void UILCD::drawVoltageScreen() {
currentScreen = voltageScreen;
currentLine = 3;
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
tft->setTextColor(TEXT);
tft->setTextWrap(true);
tft->println("Voltage Selection");
tft->println(" Current value is yellow");
tft->println();
for (int i=0; i<maxvoltage; i++) {
tft->print(" ");
tft->println(voltageToText[i]);
}
hilightLine(3);
}
void UILCD::drawMainScreen() {
currentScreen = mainScreen;
previousLine = 0;
currentLine = 0;
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND);
tft->setTextColor(TEXT);
tft->setTextWrap(true);
@ -121,6 +284,7 @@ void UILCD::drawMainScreen() {
}
void UILCD::drawSplashScreen() {
tft->setCursor(0,0);
tft->fillScreen(SPLASH_BACKGROUND);
bmpDraw("splash.bmp", 13, 0);
delay(1250);

View file

@ -25,14 +25,17 @@
enum screen {
splashScreen,
mainScreen
mainScreen,
connectionScreen,
lineSpeedScreen,
voltageScreen
};
class UILCD {
private:
Adafruit_ST7735* tft;
int previousLine;
int currentLine;
screen currentScreen;
uint32_t read32(File f);
@ -40,15 +43,23 @@ private:
void drawSplashScreen();
void drawMainScreen();
void drawConnectionScreen();
void drawLineSpeedScreen();
void drawVoltageScreen();
void hilightLine(int line);
void unHilightLine(int line);
void mainScreenHilight(joyDirection direction);
void configScreenHighlight(joyDirection direction);
void mainScreenOkButton();
void mainScreenCancelButton();
public:
UILCD();
void bmpDraw(char *filename, uint8_t x, uint8_t y);
void startUI();
void handleJoystickEvent(joyDirection aDirection);
void handleOkButtonEvent();
void handleCancelButtonEvent();
};
#endif

View file

@ -57,5 +57,13 @@ void loop() {
}
lcd->handleJoystickEvent(joyStickEvent);
}
if (okButton->isPressed()) {
lcd->handleOkButtonEvent();
}
if (cancelButton->isPressed()) {
lcd->handleCancelButtonEvent();
}
}