diff --git a/Universal_Serial_Adapter/Project.cpp b/Universal_Serial_Adapter/Project.cpp index a4ca947..5bb9506 100644 --- a/Universal_Serial_Adapter/Project.cpp +++ b/Universal_Serial_Adapter/Project.cpp @@ -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" diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index 85125d8..9ac8b37 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -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 }; diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp index 9ca2ee2..014c0e5 100644 --- a/Universal_Serial_Adapter/UILCD.cpp +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -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; iprint(" "); + 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; iprint(" "); + 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; iprint(" "); + 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); diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h index ca94fea..fc7296e 100644 --- a/Universal_Serial_Adapter/UILCD.h +++ b/Universal_Serial_Adapter/UILCD.h @@ -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 diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 2257d8e..9231b56 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -57,5 +57,13 @@ void loop() { } lcd->handleJoystickEvent(joyStickEvent); } + + if (okButton->isPressed()) { + lcd->handleOkButtonEvent(); + } + + if (cancelButton->isPressed()) { + lcd->handleCancelButtonEvent(); + } }