Added rudamentary handling of joystick events on the main UI screen -- not tested
This commit is contained in:
parent
abfa9f6269
commit
75fd92cebf
|
@ -26,9 +26,17 @@
|
||||||
#define LCD_DC 9 // Data/command line for TFT
|
#define LCD_DC 9 // Data/command line for TFT
|
||||||
#define LCD_RST 8 // Reset line for TFT (or connect to +5V)
|
#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
|
// Don't change anything below here
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define FONT_WIDTH 6
|
||||||
|
#define FONT_HEIGHT 8
|
||||||
|
|
||||||
// Serial modes supported
|
// Serial modes supported
|
||||||
// Abused in for loops / lookup tables -- DO NOT CHANGE none or set values
|
// Abused in for loops / lookup tables -- DO NOT CHANGE none or set values
|
||||||
enum serialmode {
|
enum serialmode {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "UILCD.h"
|
#include "UILCD.h"
|
||||||
|
#include "UIJoystickPSP.h"
|
||||||
|
|
||||||
UILCD::UILCD() {
|
UILCD::UILCD() {
|
||||||
tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST);
|
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() {
|
void UILCD::splashScreen() {
|
||||||
tft->fillScreen(ST7735_WHITE);
|
tft->fillScreen(SPLASH_BACKGROUND);
|
||||||
bmpDraw("splash.bmp", 13, 0);
|
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) {
|
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++];
|
r = sdbuffer[buffidx++];
|
||||||
tft->pushColor(tft->Color565(r,g,b));
|
tft->pushColor(tft->Color565(r,g,b));
|
||||||
} // end pixel
|
} // end pixel
|
||||||
|
delay(5);
|
||||||
} // end scanline
|
} // end scanline
|
||||||
Serial.print("Loaded in ");
|
Serial.print("Loaded in ");
|
||||||
Serial.print(millis() - startTime);
|
Serial.print(millis() - startTime);
|
||||||
|
|
|
@ -16,23 +16,39 @@
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
|
#include "UIJoystickPSP.h"
|
||||||
|
|
||||||
#ifndef UILCD_h
|
#ifndef UILCD_h
|
||||||
#define UILCD_h
|
#define UILCD_h
|
||||||
|
|
||||||
#define BUFFPIXEL 20
|
#define BUFFPIXEL 20
|
||||||
|
|
||||||
|
enum screen {
|
||||||
|
splashScreen,
|
||||||
|
mainScreen
|
||||||
|
};
|
||||||
|
|
||||||
class UILCD {
|
class UILCD {
|
||||||
private:
|
private:
|
||||||
Adafruit_ST7735* tft;
|
Adafruit_ST7735* tft;
|
||||||
|
|
||||||
|
int previousLine;
|
||||||
|
screen currentScreen;
|
||||||
|
|
||||||
uint32_t read32(File f);
|
uint32_t read32(File f);
|
||||||
uint16_t read16(File f);
|
uint16_t read16(File f);
|
||||||
|
|
||||||
|
void splashScreen();
|
||||||
|
void mainScreen();
|
||||||
|
void hilightLine(int line);
|
||||||
|
void unHilightLine(int line);
|
||||||
|
void mainScreenHilight(joyDirection direction);
|
||||||
|
|
||||||
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 splashScreen();
|
void startUI();
|
||||||
|
void handleJoystickEvent(joyDirection aDirection);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,6 +23,8 @@ UIButton* cancelButton;
|
||||||
UIJoystickPSP* pspJoystick;
|
UIJoystickPSP* pspJoystick;
|
||||||
UILCD* lcd;
|
UILCD* lcd;
|
||||||
|
|
||||||
|
joyDirection joyStickEvent;
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
void setDefaults() {
|
void setDefaults() {
|
||||||
//FIXME: Re-enable once new LCD is online
|
//FIXME: Re-enable once new LCD is online
|
||||||
|
@ -43,9 +45,13 @@ void setup() {
|
||||||
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
|
pspJoystick = new UIJoystickPSP(pspXPin, pspYPin);
|
||||||
|
|
||||||
lcd = new UILCD();
|
lcd = new UILCD();
|
||||||
lcd->splashScreen();
|
lcd->startUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
joyStickEvent = pspJoystick->direction();
|
||||||
|
if (joyStickEvent != joyNone) {
|
||||||
|
lcd->handleJoystickEvent(joyStickEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue