From 75fd92cebfdc121100e49af5dae9238334cf76e6 Mon Sep 17 00:00:00 2001 From: Mike C Date: Sat, 6 Apr 2013 20:42:58 -0400 Subject: [PATCH] Added rudamentary handling of joystick events on the main UI screen -- not tested --- Universal_Serial_Adapter/Project.h | 8 ++ Universal_Serial_Adapter/UILCD.cpp | 94 ++++++++++++++++++- Universal_Serial_Adapter/UILCD.h | 18 +++- .../Universal_Serial_Adapter.ino | 8 +- 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index eff0a91..85125d8 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -26,9 +26,17 @@ #define LCD_DC 9 // Data/command line for TFT #define LCD_RST 8 // Reset line for TFT (or connect to +5V) +#define SPLASH_BACKGROUND ST7735_WHITE +#define BACKGROUND ST7735_BLACK +#define TEXT ST7735_WHITE +#define HILIGHT ST7735_YELLOW + // Don't change anything below here // ----------------------------------------------------------------------------- +#define FONT_WIDTH 6 +#define FONT_HEIGHT 8 + // Serial modes supported // Abused in for loops / lookup tables -- DO NOT CHANGE none or set values enum serialmode { diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp index 61ac1bb..4ee1948 100644 --- a/Universal_Serial_Adapter/UILCD.cpp +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -17,6 +17,7 @@ #include "Project.h" #include "UILCD.h" +#include "UIJoystickPSP.h" UILCD::UILCD() { tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST); @@ -28,9 +29,99 @@ UILCD::UILCD() { } } +void UILCD::startUI() { + splashScreen(); + mainScreen(); +} + +void UILCD::handleJoystickEvent(joyDirection direction) { + switch (currentScreen) { + case 1: // enum screen -> mainScreen + mainScreenHilight(direction); + break; + } +} + +void UILCD::unHilightLine(int line) { + tft->setCursor(0, line * FONT_HEIGHT); + tft->setTextColor(HILIGHT); + tft->print(" "); +} + +void UILCD::hilightLine(int line) { + tft->setCursor(0, line * FONT_HEIGHT); + tft->setTextColor(HILIGHT); + tft->print("*"); +} + +void UILCD::mainScreenHilight(joyDirection direction) { + if (direction == joyUp) { + // Don't go up past the 1st line + if (previousLine == 0) { + return; + } + unHilightLine(previousLine); + + previousLine -= 1; + + // Skip blank lines + if (previousLine == 3 || previousLine == 6) { + previousLine -= 1; + } + + hilightLine(previousLine); + } + + if (direction == joyDown) { + // Don't go past the last line + if (previousLine == 7) { + return; + } + unHilightLine(previousLine); + + previousLine += 1; + + // Skip blank lines + if (previousLine == 3 || previousLine == 6) { + previousLine += 1; + } + + hilightLine(previousLine); + } +} + +void UILCD::mainScreen() { + previousLine = 0; + + tft->fillScreen(BACKGROUND); + tft->setTextColor(TEXT); + tft->setTextWrap(true); + + tft->print(" Con Typ: "); + tft->println(modeToText[1]); // 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(); + tft->println(" Start data logging"); + tft->println(" View serial data"); + + tft->println(); + tft->println(" Configure RTC / Clock"); + + hilightLine(0); +} + void UILCD::splashScreen() { - tft->fillScreen(ST7735_WHITE); + tft->fillScreen(SPLASH_BACKGROUND); bmpDraw("splash.bmp", 13, 0); + delay(1250); + for (int16_t y=0; y < tft->height(); y+=1) { + tft->drawFastHLine(0, y, tft->width(), BACKGROUND); + delay(10); + } } void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) { @@ -134,6 +225,7 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) { r = sdbuffer[buffidx++]; tft->pushColor(tft->Color565(r,g,b)); } // end pixel + delay(5); } // end scanline Serial.print("Loaded in "); Serial.print(millis() - startTime); diff --git a/Universal_Serial_Adapter/UILCD.h b/Universal_Serial_Adapter/UILCD.h index 9edf146..efb3a24 100644 --- a/Universal_Serial_Adapter/UILCD.h +++ b/Universal_Serial_Adapter/UILCD.h @@ -16,23 +16,39 @@ #include #include "Project.h" +#include "UIJoystickPSP.h" #ifndef UILCD_h #define UILCD_h #define BUFFPIXEL 20 +enum screen { + splashScreen, + mainScreen +}; + class UILCD { private: Adafruit_ST7735* tft; + int previousLine; + screen currentScreen; + uint32_t read32(File f); uint16_t read16(File f); + void splashScreen(); + void mainScreen(); + void hilightLine(int line); + void unHilightLine(int line); + void mainScreenHilight(joyDirection direction); + public: UILCD(); void bmpDraw(char *filename, uint8_t x, uint8_t y); - void splashScreen(); + void startUI(); + void handleJoystickEvent(joyDirection aDirection); }; #endif diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index 9f6e30b..2286b95 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -23,6 +23,8 @@ UIButton* cancelButton; UIJoystickPSP* pspJoystick; UILCD* lcd; +joyDirection joyStickEvent; + // Defaults void setDefaults() { //FIXME: Re-enable once new LCD is online @@ -43,9 +45,13 @@ void setup() { pspJoystick = new UIJoystickPSP(pspXPin, pspYPin); lcd = new UILCD(); - lcd->splashScreen(); + lcd->startUI(); } void loop() { + joyStickEvent = pspJoystick->direction(); + if (joyStickEvent != joyNone) { + lcd->handleJoystickEvent(joyStickEvent); + } }