Converted debug code to use ifdef's for conditional compilation

This commit is contained in:
Mike C 2013-04-25 19:29:14 -04:00
parent dd981aa44d
commit 73782533d4
6 changed files with 121 additions and 121 deletions

View file

@ -15,9 +15,9 @@
#include "UI.h" #include "UI.h"
Config::Config() { Config::Config() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::Config()"); Serial.println("Config::Config()");
} #endif
currentMode = none; currentMode = none;
currentLineSpeed = zero; currentLineSpeed = zero;
@ -28,50 +28,50 @@ Config::Config() {
pinMode(voltagePinThreePointThree, OUTPUT); pinMode(voltagePinThreePointThree, OUTPUT);
pinMode(voltagePinFivePointZero, OUTPUT); pinMode(voltagePinFivePointZero, OUTPUT);
if (DEBUG) { #if DEBUG == 2
Serial.begin(115200); Serial.begin(115200);
} #endif
} }
bool Config::isUIEnabled() { bool Config::isUIEnabled() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::isUIEnabled()"); Serial.println("Config::isUIEnabled()");
} #endif
return uiEnabled; return uiEnabled;
} }
void Config::enableUI() { void Config::enableUI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::enableUI()"); Serial.println("Config::enableUI()");
} #endif
uiEnabled = true; uiEnabled = true;
} }
void Config::disableUI() { void Config::disableUI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::disableUI()"); Serial.println("Config::disableUI()");
} #endif
uiEnabled = false; uiEnabled = false;
} }
serialmode Config::getSerialMode() { serialmode Config::getSerialMode() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getSerialMode()"); Serial.println("Config::getSerialMode()");
} #endif
return currentMode; return currentMode;
} }
linespeed Config::getLineSpeed() { linespeed Config::getLineSpeed() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getLineSpeed()"); Serial.println("Config::getLineSpeed()");
} #endif
return currentLineSpeed; return currentLineSpeed;
} }
float Config::getLineSpeedBaud() { float Config::getLineSpeedBaud() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getLineSpeedBaud()"); Serial.println("Config::getLineSpeedBaud()");
} #endif
switch (currentLineSpeed) { switch (currentLineSpeed) {
case 0: // twentyFourHundredBaud case 0: // twentyFourHundredBaud
@ -96,23 +96,23 @@ float Config::getLineSpeedBaud() {
} }
ttlvoltage Config::getVoltage() { ttlvoltage Config::getVoltage() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getVoltage()"); Serial.println("Config::getVoltage()");
} #endif
return currentVoltage; return currentVoltage;
} }
timeout Config::getTimeout() { timeout Config::getTimeout() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getTimeout()"); Serial.println("Config::getTimeout()");
} #endif
return currentTimeout; return currentTimeout;
} }
int Config::getTimeoutMilis() { int Config::getTimeoutMilis() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::getTimeoutMilis()"); Serial.println("Config::getTimeoutMilis()");
} #endif
switch (currentTimeout) { switch (currentTimeout) {
case 0: // tenseconds case 0: // tenseconds
return 10000; return 10000;
@ -127,12 +127,12 @@ int Config::getTimeoutMilis() {
} }
void Config::setMode(serialmode mode) { void Config::setMode(serialmode mode) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::setMode()"); Serial.println("Config::setMode()");
Serial.print(" Setting ttl line speed to:"); Serial.print(" Setting ttl line speed to:");
float baudrate = this->getLineSpeedBaud(); float baudrate = this->getLineSpeedBaud();
Serial.println(baudrate); Serial.println(baudrate);
} #endif
switch (currentMode) { switch (currentMode) {
case 1: // ttl case 1: // ttl
@ -162,9 +162,9 @@ void Config::setMode(serialmode mode) {
} }
void Config::setLineSpeed(linespeed aLineSpeed) { void Config::setLineSpeed(linespeed aLineSpeed) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::setLineSpeed()"); Serial.println("Config::setLineSpeed()");
} #endif
currentLineSpeed = aLineSpeed; currentLineSpeed = aLineSpeed;
Serial.end(); Serial.end();
Serial.begin(getLineSpeedBaud()); Serial.begin(getLineSpeedBaud());
@ -172,9 +172,9 @@ void Config::setLineSpeed(linespeed aLineSpeed) {
} }
void Config::setVoltage(ttlvoltage voltage) { void Config::setVoltage(ttlvoltage voltage) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::setVoltage()"); Serial.println("Config::setVoltage()");
} #endif
currentVoltage = voltage; currentVoltage = voltage;
digitalWrite(voltagePinOnePointEight, LOW); digitalWrite(voltagePinOnePointEight, LOW);
@ -196,17 +196,17 @@ void Config::setVoltage(ttlvoltage voltage) {
} }
void Config::setLCDTimeout(timeout aTimeout) { void Config::setLCDTimeout(timeout aTimeout) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::setTimeout()"); Serial.println("Config::setTimeout()");
} #endif
currentTimeout = aTimeout; currentTimeout = aTimeout;
ui->setLCDTimeout(); ui->setLCDTimeout();
} }
void Config::setDefaults() { void Config::setDefaults() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::setDefaults()"); Serial.println("Config::setDefaults()");
} #endif
setVoltage(onePointEight); setVoltage(onePointEight);
setLineSpeed(oneFifteenTwoK); setLineSpeed(oneFifteenTwoK);
setMode(ttl); setMode(ttl);

View file

@ -11,7 +11,7 @@
#ifndef Project_h #ifndef Project_h
#define Project_h #define Project_h
#define DEBUG false // For controlling debug output via serial #define DEBUG 1 // NONE = 0; MINIMAL = 1; FULL = 2;
// Buttons / Joystick / Input Hardware Pinouts // Buttons / Joystick / Input Hardware Pinouts
#define okButtonPin 22 #define okButtonPin 22

View file

@ -14,9 +14,9 @@
#include "UI.h" #include "UI.h"
UI::UI() { UI::UI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::UI()"); Serial.println("Config::UI()");
} #endif
okButton = new UIButton(okButtonPin, okButtonLed); okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
@ -38,17 +38,17 @@ void UI::resetTimeout() {
} }
void UI::startUI() { void UI::startUI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::startUI()"); Serial.println("Config::startUI()");
} #endif
enableUI(); enableUI();
lcd->start(); lcd->start();
} }
void UI::disableUI() { void UI::disableUI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::disableUI()"); Serial.println("Config::disableUI()");
} #endif
config->disableUI(); config->disableUI();
lcd->turnOff(); lcd->turnOff();
okButton->turnOffLed(); okButton->turnOffLed();
@ -56,9 +56,9 @@ void UI::disableUI() {
} }
void UI::enableUI() { void UI::enableUI() {
if (DEBUG) { #if DEBUG == 2
Serial.println("Config::enableUI()"); Serial.println("Config::enableUI()");
} #endif
config->enableUI(); config->enableUI();
lcd->turnOn(); lcd->turnOn();
okButton->turnOnLed(); okButton->turnOnLed();
@ -80,10 +80,10 @@ void UI::processInputEvents() {
return; return;
} }
if (DEBUG) { #if DEBUG == 2
Serial.print("Joystick Event: "); Serial.print("Joystick Event: ");
Serial.println(joyStickEvent); Serial.println(joyStickEvent);
} #endif
resetTimeout(); resetTimeout();
lcd->handleJoystickEvent(joyStickEvent); lcd->handleJoystickEvent(joyStickEvent);
} }

View file

@ -13,37 +13,37 @@
#include "Project.h" #include "Project.h"
UIButton::UIButton(int buttonPin, int ledPin) { UIButton::UIButton(int buttonPin, int ledPin) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UIButton::UIButton()"); Serial.println("UIButton::UIButton()");
} #endif
this->buttonPin = buttonPin; this->buttonPin = buttonPin;
this->ledPin = ledPin; this->ledPin = ledPin;
setup(); setup();
} }
void UIButton::setup() { void UIButton::setup() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UIButton::setup()"); Serial.println("UIButton::setup()");
} #endif
pinMode(buttonPin, INPUT); pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
} }
void UIButton::turnOnLed() { void UIButton::turnOnLed() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UIButton::turnOnLed()"); Serial.println("UIButton::turnOnLed()");
Serial.print("Turning on pin: "); Serial.print("Turning on pin: ");
Serial.println(ledPin); Serial.println(ledPin);
} #endif
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
} }
void UIButton::turnOffLed() { void UIButton::turnOffLed() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UIButton::turnOffLed()"); Serial.println("UIButton::turnOffLed()");
Serial.print("Turning off pin: "); Serial.print("Turning off pin: ");
Serial.println(ledPin); Serial.println(ledPin);
} #endif
digitalWrite(ledPin, LOW); digitalWrite(ledPin, LOW);
} }

View file

@ -13,9 +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) { #if DEBUG == 2
Serial.println("UIJoystickPSP::UIJoystickPSP()"); Serial.println("UIJoystickPSP::UIJoystickPSP()");
} #endif
this->xAxisPin = xAxisPin; this->xAxisPin = xAxisPin;
this->yAxisPin = yAxisPin; this->yAxisPin = yAxisPin;

View file

@ -20,9 +20,9 @@
#include "UIJoystickPSP.h" #include "UIJoystickPSP.h"
UILCD::UILCD() { UILCD::UILCD() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::UILCD()"); Serial.println("UILCD::UILCD()");
} #endif
pinMode(LCD_LITE, OUTPUT); pinMode(LCD_LITE, OUTPUT);
tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST); tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST);
@ -35,34 +35,34 @@ UILCD::UILCD() {
} }
void UILCD::start() { void UILCD::start() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::start()"); Serial.println("UILCD::start()");
} #endif
drawSplashScreen(); drawSplashScreen();
drawMainScreen(); drawMainScreen();
} }
void UILCD::turnOn() { void UILCD::turnOn() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::turnOn()"); Serial.println("UILCD::turnOn()");
} #endif
digitalWrite(LCD_LITE, HIGH); digitalWrite(LCD_LITE, HIGH);
} }
void UILCD::turnOff() { void UILCD::turnOff() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::turnOff()"); Serial.println("UILCD::turnOff()");
} #endif
digitalWrite(LCD_LITE, LOW); digitalWrite(LCD_LITE, LOW);
} }
void UILCD::handleJoystickEvent(joyDirection direction) { void UILCD::handleJoystickEvent(joyDirection direction) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::handleJoystickEvent()"); 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);
} #endif
switch (currentScreen) { switch (currentScreen) {
case 1: // enum screen -> mainScreen case 1: // enum screen -> mainScreen
@ -75,12 +75,12 @@ void UILCD::handleJoystickEvent(joyDirection direction) {
} }
void UILCD::handleOkButtonEvent() { void UILCD::handleOkButtonEvent() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::handleOkButtonEvent()"); 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);
} #endif
switch (currentScreen) { switch (currentScreen) {
case 1: // enum screen -> mainScreen case 1: // enum screen -> mainScreen
@ -106,12 +106,12 @@ void UILCD::handleOkButtonEvent() {
} }
void UILCD::handleCancelButtonEvent() { void UILCD::handleCancelButtonEvent() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::handleCancelButtonEvent"); 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);
} #endif
switch (currentScreen) { switch (currentScreen) {
case 1: // enum screen -> mainScreen case 1: // enum screen -> mainScreen
@ -124,9 +124,9 @@ void UILCD::handleCancelButtonEvent() {
} }
void UILCD::mainScreenOkButton() { void UILCD::mainScreenOkButton() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::mainScreenOkButton"); Serial.println("UILCD::mainScreenOkButton");
} #endif
switch(currentLine) { switch(currentLine) {
case 0: // Connection Type case 0: // Connection Type
drawConnectionScreen(false); drawConnectionScreen(false);
@ -150,33 +150,33 @@ void UILCD::mainScreenOkButton() {
} }
void UILCD::mainScreenCancelButton() { void UILCD::mainScreenCancelButton() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::mainScreenCancelButton()"); Serial.println("UILCD::mainScreenCancelButton()");
} #endif
// Do nothing for now // Do nothing for now
} }
void UILCD::unHilightLine(int line) { void UILCD::unHilightLine(int line) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::unHilightLine()"); Serial.println("UILCD::unHilightLine()");
} #endif
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) { #if DEBUG == 2
Serial.println("UILCD::hilightLine()"); Serial.println("UILCD::hilightLine()");
} #endif
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) { #if DEBUG == 2
Serial.println("UILCD::mainScreenHilight()"); Serial.println("UILCD::mainScreenHilight()");
} #endif
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) {
@ -188,17 +188,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) { if (config->getSerialMode() == ttl) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Serial ttl blank line skip"); Serial.println("Serial ttl blank line skip");
} #endif
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine -= 1; currentLine -= 1;
} }
} }
else { else {
if (DEBUG) { #if DEBUG == 2
Serial.println("Non-serial ttl blank line skip"); Serial.println("Non-serial ttl blank line skip");
} #endif
if (currentLine == 2 || currentLine == 5) { if (currentLine == 2 || currentLine == 5) {
currentLine -= 1; currentLine -= 1;
} }
@ -225,17 +225,17 @@ void UILCD::mainScreenHilight(joyDirection direction) {
// Skip blank lines // Skip blank lines
if (config->getSerialMode() == ttl) { if (config->getSerialMode() == ttl) {
if (DEBUG) { #if DEBUG == 2
Serial.println("Serial ttl blank line skip"); Serial.println("Serial ttl blank line skip");
} #endif
if (currentLine == 3 || currentLine == 6) { if (currentLine == 3 || currentLine == 6) {
currentLine += 1; currentLine += 1;
} }
} }
else { else {
if (DEBUG) { #if DEBUG == 2
Serial.println("Non-serial ttl blank line skip"); Serial.println("Non-serial ttl blank line skip");
} #endif
if (currentLine == 2 || currentLine == 5) { if (currentLine == 2 || currentLine == 5) {
currentLine += 1; currentLine += 1;
} }
@ -246,9 +246,9 @@ void UILCD::mainScreenHilight(joyDirection direction) {
} }
void UILCD::configScreenHighlight(joyDirection direction) { void UILCD::configScreenHighlight(joyDirection direction) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::configScreenhilight()"); Serial.println("UILCD::configScreenhilight()");
} #endif
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) {
@ -295,9 +295,9 @@ void UILCD::configScreenHighlight(joyDirection direction) {
} }
void UILCD::drawTimeoutScreen(bool keepCurrentLine) { void UILCD::drawTimeoutScreen(bool keepCurrentLine) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawTimeoutScreen()"); Serial.println("UILCD::drawTimeoutScreen()");
} #endif
currentScreen = timeoutscreen; currentScreen = timeoutscreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -330,9 +330,9 @@ void UILCD::drawTimeoutScreen(bool keepCurrentLine) {
} }
void UILCD::drawConnectionScreen(bool keepCurrentLine) { void UILCD::drawConnectionScreen(bool keepCurrentLine) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawConnectionScreen()"); Serial.println("UILCD::drawConnectionScreen()");
} #endif
currentScreen = connectionScreen; currentScreen = connectionScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -365,9 +365,9 @@ void UILCD::drawConnectionScreen(bool keepCurrentLine) {
} }
void UILCD::drawLineSpeedScreen(bool keepCurrentLine) { void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawLineSpeedScreen()"); Serial.println("UILCD::drawLineSpeedScreen()");
} #endif
currentScreen = lineSpeedScreen; currentScreen = lineSpeedScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -400,9 +400,9 @@ void UILCD::drawLineSpeedScreen(bool keepCurrentLine) {
} }
void UILCD::drawVoltageScreen(bool keepCurrentLine) { void UILCD::drawVoltageScreen(bool keepCurrentLine) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawVoltageScreen()"); Serial.println("UILCD::drawVoltageScreen()");
} #endif
currentScreen = voltageScreen; currentScreen = voltageScreen;
if (!keepCurrentLine) { if (!keepCurrentLine) {
currentLine = 3; currentLine = 3;
@ -435,9 +435,9 @@ void UILCD::drawVoltageScreen(bool keepCurrentLine) {
} }
void UILCD::drawMainScreen() { void UILCD::drawMainScreen() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawMainScreen()"); Serial.println("UILCD::drawMainScreen()");
} #endif
currentScreen = mainScreen; currentScreen = mainScreen;
currentLine = 0; currentLine = 0;
@ -467,9 +467,9 @@ void UILCD::drawMainScreen() {
} }
void UILCD::drawSplashScreen() { void UILCD::drawSplashScreen() {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::drawSplashScreen()"); Serial.println("UILCD::drawSplashScreen()");
} #endif
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);
@ -481,9 +481,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) { #if DEBUG == 2
Serial.println("UILCD::bmpDraw()"); Serial.println("UILCD::bmpDraw()");
} #endif
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)
@ -499,55 +499,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;
if (DEBUG) { #if DEBUG == 2
Serial.println(); Serial.println();
Serial.print("Loading image '"); Serial.print("Loading image '");
Serial.print(filename); Serial.print(filename);
Serial.println('\''); Serial.println('\'');
} #endif
// Open requested file on SD card // Open requested file on SD card
if ((bmpFile = SD.open(filename)) == NULL) { if ((bmpFile = SD.open(filename)) == NULL) {
if (DEBUG) { #if DEBUG == 2
Serial.print("File not found"); Serial.print("File not found");
} #endif
return; return;
} }
// Parse BMP header // Parse BMP header
if(read16(bmpFile) == 0x4D42) { // BMP signature if(read16(bmpFile) == 0x4D42) { // BMP signature
if (DEBUG) { #if DEBUG == 2
Serial.print("File size: "); Serial.print("File size: ");
Serial.println(read32(bmpFile)); Serial.println(read32(bmpFile));
} #endif
(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
if (DEBUG) { #if DEBUG == 2
Serial.print("Image Offset: "); Serial.print("Image Offset: ");
Serial.println(bmpImageoffset, DEC); Serial.println(bmpImageoffset, DEC);
} #endif
// Read DIB header // Read DIB header
if (DEBUG) { #if DEBUG == 2
Serial.print("Header size: "); Serial.print("Header size: ");
Serial.println(read32(bmpFile)); Serial.println(read32(bmpFile));
} #endif
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
if (DEBUG) { #if DEBUG == 2
Serial.print("Bit Depth: "); Serial.print("Bit Depth: ");
Serial.println(bmpDepth); Serial.println(bmpDepth);
} #endif
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!
if (DEBUG) { #if DEBUG == 2
Serial.print("Image size: "); Serial.print("Image size: ");
Serial.print(bmpWidth); Serial.print(bmpWidth);
Serial.print('x'); Serial.print('x');
Serial.println(bmpHeight); Serial.println(bmpHeight);
} #endif
// 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;
@ -600,11 +600,11 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) {
} // end pixel } // end pixel
delay(5); delay(5);
} // end scanline } // end scanline
if (DEBUG) { #if DEBUG == 2
Serial.print("Loaded in "); Serial.print("Loaded in ");
Serial.print(millis() - startTime); Serial.print(millis() - startTime);
Serial.println(" ms"); Serial.println(" ms");
} #endif
} // end goodBmp } // end goodBmp
} }
} }
@ -618,9 +618,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) { #if DEBUG == 2
Serial.println("UILCD::read16()"); Serial.println("UILCD::read16()");
} #endif
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
@ -628,9 +628,9 @@ uint16_t UILCD::read16(File f) {
} }
uint32_t UILCD::read32(File f) { uint32_t UILCD::read32(File f) {
if (DEBUG) { #if DEBUG == 2
Serial.println("UILCD::read32()"); Serial.println("UILCD::read32()");
} #endif
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();