Debugging output, bug fixes, code cleanup, working serial data transfer implementation

This commit is contained in:
Mike C 2013-04-16 22:02:09 -04:00
parent db6e6b940d
commit 0998cb4785
8 changed files with 268 additions and 94 deletions

View file

@ -14,64 +14,103 @@
#include "Config.h" #include "Config.h"
Config::Config() { Config::Config() {
if (DEBUG) {
Serial.println("Config::Config()");
}
currentMode = none; currentMode = none;
currentLineSpeed = zero; currentLineSpeed = zero;
currentVoltage = negOne; currentVoltage = negOne;
currentTimeout = never; currentTimeout = never;
pinMode(voltagePinOnePointEight, OUTPUT);
pinMode(voltagePinThreePointThree, OUTPUT);
pinMode(voltagePinFivePointZero, OUTPUT);
if (DEBUG) {
Serial.begin(115200);
}
} }
bool Config::isUIEnabled() { bool Config::isUIEnabled() {
if (DEBUG) {
Serial.println("Config::isUIEnabled()");
}
return uiEnabled; return uiEnabled;
} }
void Config::enableUI() { void Config::enableUI() {
if (DEBUG) {
Serial.println("Config::enableUI()");
}
uiEnabled = true; uiEnabled = true;
} }
void Config::disableUI() { void Config::disableUI() {
if (DEBUG) {
Serial.println("Config::disableUI()");
}
uiEnabled = false; uiEnabled = false;
} }
serialmode Config::getSerialMode() { serialmode Config::getSerialMode() {
if (DEBUG) {
Serial.println("Config::getSerialMode()");
}
return currentMode; return currentMode;
} }
linespeed Config::getLineSpeed() { linespeed Config::getLineSpeed() {
if (DEBUG) {
Serial.println("Config::getLineSpeed()");
}
return currentLineSpeed; return currentLineSpeed;
} }
int Config::getLineSpeedBaud() { float Config::getLineSpeedBaud() {
if (DEBUG) {
Serial.println("Config::getLineSpeedBaud()");
}
switch (currentLineSpeed) { switch (currentLineSpeed) {
case 1: // twentyFourHundredBaud case 0: // twentyFourHundredBaud
return 2400; return 2400;
break; break;
case 2: // ninetySixHundredBaud case 1: // ninetySixHundredBaud
return 9600; return 9600;
break; break;
case 3: // nineteenTwoK case 2: // nineteenTwoK
return 19200; return 19200;
break; break;
case 4: // thirtyeightFourK case 3: // thirtyeightFourK
return 38400; return 38400;
break; break;
case 5: // fiftysevenFiveK case 4: // fiftysevenFiveK
return 57600; return 57600;
break; break;
case 6: // oneNineteenTwoK case 5: // oneNineteenTwoK
return 119200; return 115200;
break; break;
} }
} }
ttlvoltage Config::getVoltage() { ttlvoltage Config::getVoltage() {
if (DEBUG) {
Serial.println("Config::getVoltage()");
}
return currentVoltage; return currentVoltage;
} }
timeout Config::getTimeout() { timeout Config::getTimeout() {
if (DEBUG) {
Serial.println("Config::getTimeout()");
}
return currentTimeout; return currentTimeout;
} }
int Config::getTimeoutMilis() { int Config::getTimeoutMilis() {
if (DEBUG) {
Serial.println("Config::getTimeoutMilis()");
}
switch (currentTimeout) { switch (currentTimeout) {
case 0: // tenseconds case 0: // tenseconds
return 10000; return 10000;
@ -86,92 +125,97 @@ int Config::getTimeoutMilis() {
} }
void Config::setMode(serialmode mode) { void Config::setMode(serialmode mode) {
if (DEBUG) {
Serial.println("Config::setMode()");
Serial.print(" Setting ttl line speed to:");
float baudrate = this->getLineSpeedBaud();
Serial.println(baudrate);
}
switch (currentMode) { switch (currentMode) {
case 1: // ttl case 1: // ttl
Serial1.end(); Serial3.end();
break; break;
case 2: // db9_null case 2: // db9_null
Serial2.end(); Serial2.end();
break; break;
case 3: // cisco case 3: // cisco
Serial3.end(); Serial1.end();
break; break;
} }
switch (mode) { switch (mode) {
case 1: // ttl case 0: // ttl
Serial1.begin(getLineSpeedBaud()); Serial3.begin(getLineSpeedBaud());
break; break;
case 2: // db9_null case 1: // db9_null
Serial2.begin(getLineSpeedBaud()); Serial2.begin(getLineSpeedBaud());
break; break;
case 3: // cisco case 2: // cisco
Serial3.begin(getLineSpeedBaud()); Serial1.begin(getLineSpeedBaud());
break; break;
} }
currentMode = mode; currentMode = mode;
} }
void Config::setLineSpeed(linespeed speed) { void Config::setLineSpeed(linespeed aLineSpeed) {
currentLineSpeed = speed; if (DEBUG) {
Serial.println("Config::setLineSpeed()");
}
currentLineSpeed = aLineSpeed;
Serial.end();
Serial.begin(getLineSpeedBaud());
setMode(currentMode);
} }
void Config::setVoltage(ttlvoltage voltage) { void Config::setVoltage(ttlvoltage voltage) {
if (DEBUG) {
Serial.println("Config::setVoltage()");
}
currentVoltage = voltage; currentVoltage = voltage;
int shiftNumber = shiftOff;
digitalWrite(voltagePinOnePointEight, LOW);
digitalWrite(voltagePinThreePointThree, LOW);
digitalWrite(voltagePinFivePointZero, LOW);
switch (voltage) { switch (voltage) {
case 1: // onePointEight case 0: // onePointEight
shiftNumber = shift18V; digitalWrite(voltagePinOnePointEight, HIGH);
break; break;
case 2: // threePointThree case 1: // threePointThree
shiftNumber = shift33V; digitalWrite(voltagePinThreePointThree, HIGH);
break; break;
case 3: // five case 2: // five
shiftNumber = shift50V; digitalWrite(voltagePinFivePointZero, HIGH);
break; break;
} }
// Use bit shifter to activate the proper voltage regulator
digitalWrite(shifterLatchPin, LOW);
shiftOut(shifterDataPin, shifterClockPin, MSBFIRST, shiftNumber);
digitalWrite(shifterLatchPin, HIGH);
} }
void Config::setTimeout(timeout aTimeout) { void Config::setLCDTimeout(timeout aTimeout) {
if (DEBUG) {
Serial.println("Config::setTimeout()");
}
currentTimeout = aTimeout; currentTimeout = aTimeout;
} }
void Config::setDefaults() { void Config::setDefaults() {
if (DEBUG) {
Serial.println("Config::setDefaults()");
}
setVoltage(onePointEight); setVoltage(onePointEight);
setLineSpeed(oneNineteenTwoK); setLineSpeed(oneFifteenTwoK);
setMode(ttl); setMode(ttl);
setTimeout(thirtyseconds); setLCDTimeout(thirtyseconds);
} }
void Config::processSerialData() { void Config::processSerialData() {
//if (DEBUG) {
// Serial.println("Config::processSerialData()");
//}
switch (currentMode) { switch (currentMode) {
case 1: // ttl case 0: // ttl
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
break;
case 2: // db9_null
if (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial2.write(inByte);
}
break;
case 3: // cisco
if (Serial3.available()) { if (Serial3.available()) {
int inByte = Serial3.read(); int inByte = Serial3.read();
Serial.write(inByte); Serial.write(inByte);
@ -181,5 +225,25 @@ void Config::processSerialData() {
Serial3.write(inByte); Serial3.write(inByte);
} }
break; break;
case 1: // db9_null
if (Serial2.available()) {
int inByte = Serial2.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial2.write(inByte);
}
break;
case 2: // cisco
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
break;
} }
} }

View file

@ -22,21 +22,16 @@ private:
timeout currentTimeout; timeout currentTimeout;
bool uiEnabled; bool uiEnabled;
const static int shiftOff = 0;
const static int shift18V = 1;
const static int shift33V = 2;
const static int shift50V = 4;
public: public:
Config(); Config();
void setDefaults(); void setDefaults();
void setMode(serialmode mode); void setMode(serialmode mode);
void setLineSpeed(linespeed speed); void setLineSpeed(linespeed speed);
void setVoltage(ttlvoltage voltage); void setVoltage(ttlvoltage voltage);
void setTimeout(timeout aTimeout); void setLCDTimeout(timeout aTimeout);
serialmode getSerialMode(); serialmode getSerialMode();
linespeed getLineSpeed(); linespeed getLineSpeed();
int getLineSpeedBaud(); float getLineSpeedBaud(); // MUST be an unsigned int for >= 38400 and float for >=115200
ttlvoltage getVoltage(); ttlvoltage getVoltage();
timeout getTimeout(); timeout getTimeout();
int getTimeoutMilis(); int getTimeoutMilis();

View file

@ -28,10 +28,10 @@
#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)
// 74HC595 Bit Shifter Pinout // Voltage Pinouts
#define shifterLatchPin 2 //Pin connected to ST_CP of 74HC595 #define voltagePinOnePointEight 40 // Pin controlling 1.8V TTL logic
#define shifterClockPin 5 //Pin connected to SH_CP of 74HC595 #define voltagePinThreePointThree 41 // Pin controlling 3.3V TTL logic
#define shifterDataPin 4 //Pin connected to DS of 74HC595 #define voltagePinFivePointZero 42 // Pin controlling 5V TTL logic
// Colors / theme of UI // Colors / theme of UI
#define SPLASH_BACKGROUND ST7735_WHITE #define SPLASH_BACKGROUND ST7735_WHITE
@ -66,7 +66,7 @@ enum linespeed {
nineteenTwoK, nineteenTwoK,
thirtyeightFourK, thirtyeightFourK,
fiftysevenFiveK, fiftysevenFiveK,
oneNineteenTwoK, oneFifteenTwoK,
maxlinespeed, maxlinespeed,
zero=-1 zero=-1
}; };

View file

@ -14,6 +14,9 @@
#include "UI.h" #include "UI.h"
UI::UI(Config* aConfig) { UI::UI(Config* aConfig) {
if (DEBUG) {
Serial.println("Config::UI()");
}
config = aConfig; config = aConfig;
okButton = new UIButton(okButtonPin, okButtonLed); okButton = new UIButton(okButtonPin, okButtonLed);
@ -28,11 +31,17 @@ UI::UI(Config* aConfig) {
} }
void UI::startUI() { void UI::startUI() {
if (DEBUG) {
Serial.println("Config::startUI()");
}
enableUI(); enableUI();
lcd->start(); lcd->start();
} }
void UI::disableUI() { void UI::disableUI() {
if (DEBUG) {
Serial.println("Config::disableUI()");
}
config->disableUI(); config->disableUI();
lcd->turnOff(); lcd->turnOff();
okButton->turnOffLed(); okButton->turnOffLed();
@ -40,6 +49,9 @@ void UI::disableUI() {
} }
void UI::enableUI() { void UI::enableUI() {
if (DEBUG) {
Serial.println("Config::enableUI()");
}
config->enableUI(); config->enableUI();
lcd->turnOn(); lcd->turnOn();
okButton->turnOnLed(); okButton->turnOnLed();

View file

@ -13,18 +13,25 @@
#include "Project.h" #include "Project.h"
UIButton::UIButton(int buttonPin, int ledPin) { UIButton::UIButton(int buttonPin, int ledPin) {
if (DEBUG) {
Serial.println("UIButton::UIButton()");
}
this->buttonPin = buttonPin; this->buttonPin = buttonPin;
this->ledPin = ledPin; this->ledPin = ledPin;
setup(); setup();
} }
void UIButton::setup() { void UIButton::setup() {
if (DEBUG) {
Serial.println("UIButton::setup()");
}
pinMode(buttonPin, INPUT); pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
} }
void UIButton::turnOnLed() { void UIButton::turnOnLed() {
if (DEBUG) { if (DEBUG) {
Serial.println("UIButton::turnOnLed()");
Serial.print("Turning on pin: "); Serial.print("Turning on pin: ");
Serial.println(ledPin); Serial.println(ledPin);
} }
@ -33,6 +40,7 @@ void UIButton::turnOnLed() {
void UIButton::turnOffLed() { void UIButton::turnOffLed() {
if (DEBUG) { if (DEBUG) {
Serial.println("UIButton::turnOffLed()");
Serial.print("Turning off pin: "); Serial.print("Turning off pin: ");
Serial.println(ledPin); Serial.println(ledPin);
} }
@ -40,6 +48,9 @@ void UIButton::turnOffLed() {
} }
bool UIButton::isPressed() { bool UIButton::isPressed() {
// if (DEBUG) {
//Serial.println("UIButton::isPressed()");
// }
bool pressed = digitalRead(buttonPin); bool pressed = digitalRead(buttonPin);
while (digitalRead(buttonPin)); // Wait for release while (digitalRead(buttonPin)); // Wait for release
return pressed; return pressed;

View file

@ -13,6 +13,9 @@ Serial Adapter Project: Dynamic serial TTY passthroughs
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
UIJoystickPSP::UIJoystickPSP(int xAxisPin, int yAxisPin) { UIJoystickPSP::UIJoystickPSP(int xAxisPin, int yAxisPin) {
if (DEBUG) {
Serial.println("UIJoystickPSP::UIJoystickPSP()");
}
this->xAxisPin = xAxisPin; this->xAxisPin = xAxisPin;
this->yAxisPin = yAxisPin; this->yAxisPin = yAxisPin;
@ -25,6 +28,9 @@ UIJoystickPSP::UIJoystickPSP(int xAxisPin, int yAxisPin) {
} }
joyDirection UIJoystickPSP::direction() { joyDirection UIJoystickPSP::direction() {
// if (DEBUG) {
//Serial.println("UIJoystickPSP::direction()");
// }
// Read the x/y values from the joystick // Read the x/y values from the joystick
xAxisValue = map(analogRead(xAxisPin), 0, 1023, 0, 10); xAxisValue = map(analogRead(xAxisPin), 0, 1023, 0, 10);
yAxisValue = map(analogRead(yAxisPin), 0, 1023, 0, 10); yAxisValue = map(analogRead(yAxisPin), 0, 1023, 0, 10);

View file

@ -20,6 +20,9 @@
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
UILCD::UILCD(Config* config) { UILCD::UILCD(Config* config) {
if (DEBUG) {
Serial.println("UILCD::UILCD()");
}
pinMode(LCD_LITE, OUTPUT); pinMode(LCD_LITE, OUTPUT);
this->config = config; this->config = config;
@ -28,26 +31,36 @@ UILCD::UILCD(Config* config) {
tft->initR(INITR_BLACKTAB); tft->initR(INITR_BLACKTAB);
tft->setRotation(3); tft->setRotation(3);
if (!SD.begin(SD_CS)) { if (!SD.begin(SD_CS) && DEBUG) {
Serial.println("SD.begin(SD_CS) -- failed!"); Serial.println("SD.begin(SD_CS) -- failed!");
} }
} }
void UILCD::start() { void UILCD::start() {
if (DEBUG) {
Serial.println("UILCD::start()");
}
drawSplashScreen(); drawSplashScreen();
drawMainScreen(); drawMainScreen();
} }
void UILCD::turnOn() { void UILCD::turnOn() {
if (DEBUG) {
Serial.println("UILCD::turnOn()");
}
digitalWrite(LCD_LITE, HIGH); digitalWrite(LCD_LITE, HIGH);
} }
void UILCD::turnOff() { void UILCD::turnOff() {
if (DEBUG) {
Serial.println("UILCD::turnOff()");
}
digitalWrite(LCD_LITE, LOW); digitalWrite(LCD_LITE, LOW);
} }
void UILCD::handleJoystickEvent(joyDirection direction) { void UILCD::handleJoystickEvent(joyDirection direction) {
if (DEBUG) { if (DEBUG) {
Serial.println("UILCD::handleJoystickEvent()");
Serial.println("begin UILCD::handleJoystickEvent"); Serial.println("begin UILCD::handleJoystickEvent");
Serial.print("Current Screen: "); Serial.print("Current Screen: ");
Serial.println(currentScreen); Serial.println(currentScreen);
@ -64,7 +77,8 @@ void UILCD::handleJoystickEvent(joyDirection direction) {
} }
void UILCD::handleOkButtonEvent() { void UILCD::handleOkButtonEvent() {
if (DEBUG) { if (DEBUG) {
Serial.println("UILCD::handleOkButtonEvent()");
Serial.println("begin UILCD::handleOkButtonEvent"); Serial.println("begin UILCD::handleOkButtonEvent");
Serial.print("Current Screen: "); Serial.print("Current Screen: ");
Serial.println(currentScreen); Serial.println(currentScreen);
@ -87,14 +101,15 @@ void UILCD::handleOkButtonEvent() {
drawVoltageScreen(true); drawVoltageScreen(true);
break; break;
case 5: // timeoutScreen case 5: // timeoutScreen
config->setTimeout((timeout)(currentLine - 3)); config->setLCDTimeout((timeout)(currentLine - 3));
drawTimeoutScreen(true); drawTimeoutScreen(true);
break; break;
} }
} }
void UILCD::handleCancelButtonEvent() { void UILCD::handleCancelButtonEvent() {
if (DEBUG) { if (DEBUG) {
Serial.println("UILCD::handleCancelButtonEvent");
Serial.println("begin UILCD::handleCancelButtonEvent"); Serial.println("begin UILCD::handleCancelButtonEvent");
Serial.print("Current Screen: "); Serial.print("Current Screen: ");
Serial.println(currentScreen); Serial.println(currentScreen);
@ -111,6 +126,9 @@ void UILCD::handleCancelButtonEvent() {
} }
void UILCD::mainScreenOkButton() { void UILCD::mainScreenOkButton() {
if (DEBUG) {
Serial.println("UILCD::mainScreenOkButton");
}
switch(currentLine) { switch(currentLine) {
case 0: // Connection Type case 0: // Connection Type
drawConnectionScreen(false); drawConnectionScreen(false);
@ -134,21 +152,33 @@ void UILCD::mainScreenOkButton() {
} }
void UILCD::mainScreenCancelButton() { void UILCD::mainScreenCancelButton() {
if (DEBUG) {
Serial.println("UILCD::mainScreenCancelButton()");
}
// Do nothing for now // Do nothing for now
} }
void UILCD::unHilightLine(int line) { void UILCD::unHilightLine(int line) {
if (DEBUG) {
Serial.println("UILCD::unHilightLine()");
}
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);
} }
void UILCD::hilightLine(int line) { void UILCD::hilightLine(int line) {
if (DEBUG) {
Serial.println("UILCD::hilightLine()");
}
tft->setCursor(0, line * FONT_HEIGHT); tft->setCursor(0, line * FONT_HEIGHT);
tft->setTextColor(HILIGHT); tft->setTextColor(HILIGHT);
tft->print("*"); tft->print("*");
} }
void UILCD::mainScreenHilight(joyDirection direction) { void UILCD::mainScreenHilight(joyDirection direction) {
if (DEBUG) {
Serial.println("UILCD::mainScreenHilight()");
}
if (direction == joyUp) { if (direction == joyUp) {
// Don't go up past the 1st line // Don't go up past the 1st line
if (currentLine == 0) { if (currentLine == 0) {
@ -160,13 +190,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) { if (config->getSerialMode() == ttl) {
Serial.println("Serial ttl blank line skip"); if (DEBUG) {
Serial.println("Serial ttl blank line skip");
}
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine -= 1; currentLine -= 1;
} }
} }
else { else {
Serial.println("Non-serial ttl blank line skip"); if (DEBUG) {
Serial.println("Non-serial ttl blank line skip");
}
if (currentLine == 2 || currentLine == 5) { if (currentLine == 2 || currentLine == 5) {
currentLine -= 1; currentLine -= 1;
} }
@ -193,13 +227,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) { if (config->getSerialMode() == ttl) {
Serial.println("Serial ttl blank line skip"); if (DEBUG) {
Serial.println("Serial ttl blank line skip");
}
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine += 1; currentLine += 1;
} }
} }
else { else {
Serial.println("Non-serial ttl blank line skip"); if (DEBUG) {
Serial.println("Non-serial ttl blank line skip");
}
if (currentLine == 2 || currentLine == 5) { if (currentLine == 2 || currentLine == 5) {
currentLine += 1; currentLine += 1;
} }
@ -210,6 +248,9 @@ void UILCD::mainScreenHilight(joyDirection direction) {
} }
void UILCD::configScreenHighlight(joyDirection direction) { void UILCD::configScreenHighlight(joyDirection direction) {
if (DEBUG) {
Serial.println("UILCD::configScreenhilight()");
}
if (direction == joyUp) { if (direction == joyUp) {
// Don't go up past the 1st line // Don't go up past the 1st line
if (currentLine == 3) { if (currentLine == 3) {
@ -256,6 +297,9 @@ void UILCD::configScreenHighlight(joyDirection direction) {
} }
void UILCD::drawTimeoutScreen(bool keepCurrentLine) { void UILCD::drawTimeoutScreen(bool keepCurrentLine) {
if (DEBUG) {
Serial.println("UILCD::drawTimeoutScreen()");
}
currentScreen = timeoutscreen; currentScreen = timeoutscreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -288,6 +332,9 @@ void UILCD::drawTimeoutScreen(bool keepCurrentLine) {
} }
void UILCD::drawConnectionScreen(bool keepCurrentLine) { void UILCD::drawConnectionScreen(bool keepCurrentLine) {
if (DEBUG) {
Serial.println("UILCD::drawConnectionScreen()");
}
currentScreen = connectionScreen; currentScreen = connectionScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -320,6 +367,9 @@ void UILCD::drawConnectionScreen(bool keepCurrentLine) {
} }
void UILCD::drawLineSpeedScreen(bool keepCurrentLine) { void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
if (DEBUG) {
Serial.println("UILCD::drawLineSpeedScreen()");
}
currentScreen = lineSpeedScreen; currentScreen = lineSpeedScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -352,6 +402,9 @@ void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
} }
void UILCD::drawVoltageScreen(bool keepCurrentLine) { void UILCD::drawVoltageScreen(bool keepCurrentLine) {
if (DEBUG) {
Serial.println("UILCD::drawVoltageScreen()");
}
currentScreen = voltageScreen; currentScreen = voltageScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -384,6 +437,9 @@ void UILCD::drawVoltageScreen(bool keepCurrentLine) {
} }
void UILCD::drawMainScreen() { void UILCD::drawMainScreen() {
if (DEBUG) {
Serial.println("UILCD::drawMainScreen()");
}
currentScreen = mainScreen; currentScreen = mainScreen;
currentLine = 0; currentLine = 0;
@ -413,6 +469,9 @@ void UILCD::drawMainScreen() {
} }
void UILCD::drawSplashScreen() { void UILCD::drawSplashScreen() {
if (DEBUG) {
Serial.println("UILCD::drawSplashScreen()");
}
tft->setCursor(0,0); tft->setCursor(0,0);
tft->fillScreen(SPLASH_BACKGROUND); tft->fillScreen(SPLASH_BACKGROUND);
bmpDraw("splash.bmp", 13, 0); bmpDraw("splash.bmp", 13, 0);
@ -424,6 +483,9 @@ void UILCD::drawSplashScreen() {
} }
void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) { void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
if (DEBUG) {
Serial.println("UILCD::bmpDraw()");
}
File bmpFile; File bmpFile;
int bmpWidth, bmpHeight; // W+H in pixels int bmpWidth, bmpHeight; // W+H in pixels
uint8_t bmpDepth; // Bit depth (currently must be 24) uint8_t bmpDepth; // Bit depth (currently must be 24)
@ -439,41 +501,55 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
if((x >= tft->width()) || (y >= tft->height())) return; if((x >= tft->width()) || (y >= tft->height())) return;
Serial.println(); if (DEBUG) {
Serial.print("Loading image '"); Serial.println();
Serial.print(filename); Serial.print("Loading image '");
Serial.println('\''); Serial.print(filename);
Serial.println('\'');
}
// Open requested file on SD card // Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) { if ((bmpFile = SD.open(filename)) == NULL) {
Serial.print("File not found"); if (DEBUG) {
Serial.print("File not found");
}
return; return;
} }
// Parse BMP header // Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature if(read16(bmpFile) == 0x4D42) { // BMP signature
Serial.print("File size: "); if (DEBUG) {
Serial.println(read32(bmpFile)); Serial.print("File size: ");
Serial.println(read32(bmpFile));
}
(void)read32(bmpFile); // Read & ignore creator bytes (void)read32(bmpFile); // Read & ignore creator bytes
bmpImageoffset = read32(bmpFile); // Start of image data bmpImageoffset = read32(bmpFile); // Start of image data
Serial.print("Image Offset: "); if (DEBUG) {
Serial.println(bmpImageoffset, DEC); Serial.print("Image Offset: ");
Serial.println(bmpImageoffset, DEC);
}
// Read DIB header // Read DIB header
Serial.print("Header size: "); if (DEBUG) {
Serial.println(read32(bmpFile)); Serial.print("Header size: ");
Serial.println(read32(bmpFile));
}
bmpWidth = read32(bmpFile); bmpWidth = read32(bmpFile);
bmpHeight = read32(bmpFile); bmpHeight = read32(bmpFile);
if(read16(bmpFile) == 1) { // # planes -- must be '1' if(read16(bmpFile) == 1) { // # planes -- must be '1'
bmpDepth = read16(bmpFile); // bits per pixel bmpDepth = read16(bmpFile); // bits per pixel
Serial.print("Bit Depth: "); if (DEBUG) {
Serial.println(bmpDepth); Serial.print("Bit Depth: ");
Serial.println(bmpDepth);
}
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
goodBmp = true; // Supported BMP format -- proceed! goodBmp = true; // Supported BMP format -- proceed!
Serial.print("Image size: "); if (DEBUG) {
Serial.print(bmpWidth); Serial.print("Image size: ");
Serial.print('x'); Serial.print(bmpWidth);
Serial.println(bmpHeight); Serial.print('x');
Serial.println(bmpHeight);
}
// BMP rows are padded (if needed) to 4-byte boundary // BMP rows are padded (if needed) to 4-byte boundary
rowSize = (bmpWidth * 3 + 3) & ~3; rowSize = (bmpWidth * 3 + 3) & ~3;
@ -526,15 +602,17 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
} // end pixel } // end pixel
delay(5); delay(5);
} // end scanline } // end scanline
Serial.print("Loaded in "); if (DEBUG) {
Serial.print(millis() - startTime); Serial.print("Loaded in ");
Serial.println(" ms"); Serial.print(millis() - startTime);
Serial.println(" ms");
}
} // end goodBmp } // end goodBmp
} }
} }
bmpFile.close(); bmpFile.close();
if(!goodBmp) Serial.println("BMP format not recognized."); if(!goodBmp && DEBUG) Serial.println("BMP format not recognized.");
} }
// These read 16- and 32-bit types from the SD card file. // These read 16- and 32-bit types from the SD card file.
@ -542,6 +620,9 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
// May need to reverse subscript order if porting elsewhere. // May need to reverse subscript order if porting elsewhere.
uint16_t UILCD::read16(File f) { uint16_t UILCD::read16(File f) {
if (DEBUG) {
Serial.println("UILCD::read16()");
}
uint16_t result; uint16_t result;
((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); // MSB ((uint8_t *)&result)[1] = f.read(); // MSB
@ -549,6 +630,9 @@ uint16_t UILCD::read16(File f) {
} }
uint32_t UILCD::read32(File f) { uint32_t UILCD::read32(File f) {
if (DEBUG) {
Serial.println("UILCD::read32()");
}
uint32_t result; uint32_t result;
((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[0] = f.read(); // LSB
((uint8_t *)&result)[1] = f.read(); ((uint8_t *)&result)[1] = f.read();

View file

@ -26,6 +26,8 @@ UI* ui;
Config* config; Config* config;
void setup() { void setup() {
Serial.begin(115200);
config = new Config(); config = new Config();
config->setDefaults(); config->setDefaults();