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

View file

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

View file

@ -45,9 +45,67 @@ void UILCD::handleJoystickEvent(joyDirection direction) {
case 1: // enum screen -> mainScreen case 1: // enum screen -> mainScreen
mainScreenHilight(direction); mainScreenHilight(direction);
break; 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) { void UILCD::unHilightLine(int line) {
tft->setCursor(0, line * FONT_HEIGHT); tft->setCursor(0, line * FONT_HEIGHT);
tft->fillRect(0, line * FONT_HEIGHT, FONT_WIDTH, FONT_HEIGHT, BACKGROUND); 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) { void UILCD::mainScreenHilight(joyDirection direction) {
if (direction == joyUp) { if (direction == joyUp) {
// Don't go up past the 1st line // Don't go up past the 1st line
if (previousLine == 0) { if (currentLine == 0) {
return; return;
} }
unHilightLine(previousLine); unHilightLine(currentLine);
previousLine -= 1; currentLine -= 1;
// Skip blank lines // Skip blank lines
if (previousLine == 3 || previousLine == 6) { if (currentLine == 3 || currentLine == 6) {
previousLine -= 1; currentLine -= 1;
} }
hilightLine(previousLine); hilightLine(currentLine);
} }
if (direction == joyDown) { if (direction == joyDown) {
// Don't go past the last line // Don't go past the last line
if (previousLine == 7) { if (currentLine == 7) {
return; return;
} }
unHilightLine(previousLine); unHilightLine(currentLine);
previousLine += 1; currentLine += 1;
// Skip blank lines // Skip blank lines
if (previousLine == 3 || previousLine == 6) { if (currentLine == 3 || currentLine == 6) {
previousLine += 1; 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() { void UILCD::drawMainScreen() {
currentScreen = mainScreen; currentScreen = mainScreen;
previousLine = 0; currentLine = 0;
tft->setCursor(0,0);
tft->fillScreen(BACKGROUND); tft->fillScreen(BACKGROUND);
tft->setTextColor(TEXT); tft->setTextColor(TEXT);
tft->setTextWrap(true); tft->setTextWrap(true);
@ -121,6 +284,7 @@ void UILCD::drawMainScreen() {
} }
void UILCD::drawSplashScreen() { void UILCD::drawSplashScreen() {
tft->setCursor(0,0);
tft->fillScreen(SPLASH_BACKGROUND); tft->fillScreen(SPLASH_BACKGROUND);
bmpDraw("splash.bmp", 13, 0); bmpDraw("splash.bmp", 13, 0);
delay(1250); delay(1250);

View file

@ -25,14 +25,17 @@
enum screen { enum screen {
splashScreen, splashScreen,
mainScreen mainScreen,
connectionScreen,
lineSpeedScreen,
voltageScreen
}; };
class UILCD { class UILCD {
private: private:
Adafruit_ST7735* tft; Adafruit_ST7735* tft;
int previousLine; int currentLine;
screen currentScreen; screen currentScreen;
uint32_t read32(File f); uint32_t read32(File f);
@ -40,15 +43,23 @@ private:
void drawSplashScreen(); void drawSplashScreen();
void drawMainScreen(); void drawMainScreen();
void drawConnectionScreen();
void drawLineSpeedScreen();
void drawVoltageScreen();
void hilightLine(int line); void hilightLine(int line);
void unHilightLine(int line); void unHilightLine(int line);
void mainScreenHilight(joyDirection direction); void mainScreenHilight(joyDirection direction);
void configScreenHighlight(joyDirection direction);
void mainScreenOkButton();
void mainScreenCancelButton();
public: public:
UILCD(); UILCD();
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);
void handleOkButtonEvent();
void handleCancelButtonEvent();
}; };
#endif #endif

View file

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