diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp index 30894d0..b35d46d 100644 --- a/Universal_Serial_Adapter/Config.cpp +++ b/Universal_Serial_Adapter/Config.cpp @@ -15,9 +15,9 @@ #include "UI.h" Config::Config() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::Config()"); - } +#endif currentMode = none; currentLineSpeed = zero; @@ -28,50 +28,50 @@ Config::Config() { pinMode(voltagePinThreePointThree, OUTPUT); pinMode(voltagePinFivePointZero, OUTPUT); - if (DEBUG) { +#if DEBUG == 2 Serial.begin(115200); - } +#endif } bool Config::isUIEnabled() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::isUIEnabled()"); - } +#endif return uiEnabled; } void Config::enableUI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::enableUI()"); - } +#endif uiEnabled = true; } void Config::disableUI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::disableUI()"); - } +#endif uiEnabled = false; } serialmode Config::getSerialMode() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getSerialMode()"); - } +#endif return currentMode; } linespeed Config::getLineSpeed() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getLineSpeed()"); - } +#endif return currentLineSpeed; } float Config::getLineSpeedBaud() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getLineSpeedBaud()"); - } +#endif switch (currentLineSpeed) { case 0: // twentyFourHundredBaud @@ -96,23 +96,23 @@ float Config::getLineSpeedBaud() { } ttlvoltage Config::getVoltage() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getVoltage()"); - } +#endif return currentVoltage; } timeout Config::getTimeout() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getTimeout()"); - } +#endif return currentTimeout; } int Config::getTimeoutMilis() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::getTimeoutMilis()"); - } +#endif switch (currentTimeout) { case 0: // tenseconds return 10000; @@ -127,12 +127,12 @@ int Config::getTimeoutMilis() { } void Config::setMode(serialmode mode) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::setMode()"); Serial.print(" Setting ttl line speed to:"); float baudrate = this->getLineSpeedBaud(); Serial.println(baudrate); - } +#endif switch (currentMode) { case 1: // ttl @@ -162,9 +162,9 @@ void Config::setMode(serialmode mode) { } void Config::setLineSpeed(linespeed aLineSpeed) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::setLineSpeed()"); - } +#endif currentLineSpeed = aLineSpeed; Serial.end(); Serial.begin(getLineSpeedBaud()); @@ -172,9 +172,9 @@ void Config::setLineSpeed(linespeed aLineSpeed) { } void Config::setVoltage(ttlvoltage voltage) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::setVoltage()"); - } +#endif currentVoltage = voltage; digitalWrite(voltagePinOnePointEight, LOW); @@ -196,17 +196,17 @@ void Config::setVoltage(ttlvoltage voltage) { } void Config::setLCDTimeout(timeout aTimeout) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::setTimeout()"); - } +#endif currentTimeout = aTimeout; ui->setLCDTimeout(); } void Config::setDefaults() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::setDefaults()"); - } +#endif setVoltage(onePointEight); setLineSpeed(oneFifteenTwoK); setMode(ttl); diff --git a/Universal_Serial_Adapter/Project.h b/Universal_Serial_Adapter/Project.h index 3c68be8..d457752 100644 --- a/Universal_Serial_Adapter/Project.h +++ b/Universal_Serial_Adapter/Project.h @@ -11,7 +11,7 @@ #ifndef 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 #define okButtonPin 22 diff --git a/Universal_Serial_Adapter/UI.cpp b/Universal_Serial_Adapter/UI.cpp index 3b25abb..3ac1bf7 100644 --- a/Universal_Serial_Adapter/UI.cpp +++ b/Universal_Serial_Adapter/UI.cpp @@ -14,9 +14,9 @@ #include "UI.h" UI::UI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::UI()"); - } +#endif okButton = new UIButton(okButtonPin, okButtonLed); cancelButton = new UIButton(cancelButtonPin, cancelButtonLed); @@ -38,17 +38,17 @@ void UI::resetTimeout() { } void UI::startUI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::startUI()"); - } +#endif enableUI(); lcd->start(); } void UI::disableUI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::disableUI()"); - } +#endif config->disableUI(); lcd->turnOff(); okButton->turnOffLed(); @@ -56,9 +56,9 @@ void UI::disableUI() { } void UI::enableUI() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("Config::enableUI()"); - } +#endif config->enableUI(); lcd->turnOn(); okButton->turnOnLed(); @@ -80,10 +80,10 @@ void UI::processInputEvents() { return; } - if (DEBUG) { +#if DEBUG == 2 Serial.print("Joystick Event: "); Serial.println(joyStickEvent); - } +#endif resetTimeout(); lcd->handleJoystickEvent(joyStickEvent); } diff --git a/Universal_Serial_Adapter/UIButton.cpp b/Universal_Serial_Adapter/UIButton.cpp index 0ad3e0a..38fcead 100644 --- a/Universal_Serial_Adapter/UIButton.cpp +++ b/Universal_Serial_Adapter/UIButton.cpp @@ -13,37 +13,37 @@ #include "Project.h" UIButton::UIButton(int buttonPin, int ledPin) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UIButton::UIButton()"); - } +#endif this->buttonPin = buttonPin; this->ledPin = ledPin; setup(); } void UIButton::setup() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UIButton::setup()"); - } +#endif pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); } void UIButton::turnOnLed() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UIButton::turnOnLed()"); Serial.print("Turning on pin: "); Serial.println(ledPin); - } +#endif digitalWrite(ledPin, HIGH); } void UIButton::turnOffLed() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UIButton::turnOffLed()"); Serial.print("Turning off pin: "); Serial.println(ledPin); - } +#endif digitalWrite(ledPin, LOW); } diff --git a/Universal_Serial_Adapter/UIJoystickPSP.cpp b/Universal_Serial_Adapter/UIJoystickPSP.cpp index fc055b8..446369f 100644 --- a/Universal_Serial_Adapter/UIJoystickPSP.cpp +++ b/Universal_Serial_Adapter/UIJoystickPSP.cpp @@ -13,9 +13,9 @@ Serial Adapter Project: Dynamic serial TTY passthroughs #include "UIJoystickPSP.h" UIJoystickPSP::UIJoystickPSP(int xAxisPin, int yAxisPin) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UIJoystickPSP::UIJoystickPSP()"); - } +#endif this->xAxisPin = xAxisPin; this->yAxisPin = yAxisPin; diff --git a/Universal_Serial_Adapter/UILCD.cpp b/Universal_Serial_Adapter/UILCD.cpp index 1fe54b3..f60835a 100644 --- a/Universal_Serial_Adapter/UILCD.cpp +++ b/Universal_Serial_Adapter/UILCD.cpp @@ -20,9 +20,9 @@ #include "UIJoystickPSP.h" UILCD::UILCD() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::UILCD()"); - } +#endif pinMode(LCD_LITE, OUTPUT); tft = new Adafruit_ST7735(LCD_CS, LCD_DC, LCD_RST); @@ -35,34 +35,34 @@ UILCD::UILCD() { } void UILCD::start() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::start()"); - } +#endif drawSplashScreen(); drawMainScreen(); } void UILCD::turnOn() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::turnOn()"); - } +#endif digitalWrite(LCD_LITE, HIGH); } void UILCD::turnOff() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::turnOff()"); - } +#endif digitalWrite(LCD_LITE, LOW); } void UILCD::handleJoystickEvent(joyDirection direction) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::handleJoystickEvent()"); Serial.println("begin UILCD::handleJoystickEvent"); Serial.print("Current Screen: "); Serial.println(currentScreen); - } +#endif switch (currentScreen) { case 1: // enum screen -> mainScreen @@ -75,12 +75,12 @@ void UILCD::handleJoystickEvent(joyDirection direction) { } void UILCD::handleOkButtonEvent() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::handleOkButtonEvent()"); Serial.println("begin UILCD::handleOkButtonEvent"); Serial.print("Current Screen: "); Serial.println(currentScreen); - } +#endif switch (currentScreen) { case 1: // enum screen -> mainScreen @@ -106,12 +106,12 @@ void UILCD::handleOkButtonEvent() { } void UILCD::handleCancelButtonEvent() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::handleCancelButtonEvent"); Serial.println("begin UILCD::handleCancelButtonEvent"); Serial.print("Current Screen: "); Serial.println(currentScreen); - } +#endif switch (currentScreen) { case 1: // enum screen -> mainScreen @@ -124,9 +124,9 @@ void UILCD::handleCancelButtonEvent() { } void UILCD::mainScreenOkButton() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::mainScreenOkButton"); - } +#endif switch(currentLine) { case 0: // Connection Type drawConnectionScreen(false); @@ -150,33 +150,33 @@ void UILCD::mainScreenOkButton() { } void UILCD::mainScreenCancelButton() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::mainScreenCancelButton()"); - } +#endif // Do nothing for now } void UILCD::unHilightLine(int line) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::unHilightLine()"); - } +#endif tft->setCursor(0, line * FONT_HEIGHT); tft->fillRect(0, line * FONT_HEIGHT, FONT_WIDTH, FONT_HEIGHT, BACKGROUND); } void UILCD::hilightLine(int line) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::hilightLine()"); - } +#endif tft->setCursor(0, line * FONT_HEIGHT); tft->setTextColor(HILIGHT); tft->print("*"); } void UILCD::mainScreenHilight(joyDirection direction) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::mainScreenHilight()"); - } +#endif if (direction == joyUp) { // Don't go up past the 1st line if (currentLine == 0) { @@ -188,17 +188,17 @@ void UILCD::mainScreenHilight(joyDirection direction) { // Skip blank lines if (config->getSerialMode() == ttl) { - if (DEBUG) { + #if DEBUG == 2 Serial.println("Serial ttl blank line skip"); - } + #endif if (currentLine == 3 || currentLine == 6) { currentLine -= 1; } } else { - if (DEBUG) { + #if DEBUG == 2 Serial.println("Non-serial ttl blank line skip"); - } + #endif if (currentLine == 2 || currentLine == 5) { currentLine -= 1; } @@ -225,17 +225,17 @@ void UILCD::mainScreenHilight(joyDirection direction) { // Skip blank lines if (config->getSerialMode() == ttl) { - if (DEBUG) { + #if DEBUG == 2 Serial.println("Serial ttl blank line skip"); - } + #endif if (currentLine == 3 || currentLine == 6) { currentLine += 1; } } else { - if (DEBUG) { + #if DEBUG == 2 Serial.println("Non-serial ttl blank line skip"); - } + #endif if (currentLine == 2 || currentLine == 5) { currentLine += 1; } @@ -246,9 +246,9 @@ void UILCD::mainScreenHilight(joyDirection direction) { } void UILCD::configScreenHighlight(joyDirection direction) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::configScreenhilight()"); - } +#endif if (direction == joyUp) { // Don't go up past the 1st line if (currentLine == 3) { @@ -295,9 +295,9 @@ void UILCD::configScreenHighlight(joyDirection direction) { } void UILCD::drawTimeoutScreen(bool keepCurrentLine) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawTimeoutScreen()"); - } +#endif currentScreen = timeoutscreen; if (!keepCurrentLine) { currentLine = 3; @@ -330,9 +330,9 @@ void UILCD::drawTimeoutScreen(bool keepCurrentLine) { } void UILCD::drawConnectionScreen(bool keepCurrentLine) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawConnectionScreen()"); - } +#endif currentScreen = connectionScreen; if (!keepCurrentLine) { currentLine = 3; @@ -365,9 +365,9 @@ void UILCD::drawConnectionScreen(bool keepCurrentLine) { } void UILCD::drawLineSpeedScreen(bool keepCurrentLine) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawLineSpeedScreen()"); - } +#endif currentScreen = lineSpeedScreen; if (!keepCurrentLine) { currentLine = 3; @@ -400,9 +400,9 @@ void UILCD::drawLineSpeedScreen(bool keepCurrentLine) { } void UILCD::drawVoltageScreen(bool keepCurrentLine) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawVoltageScreen()"); - } +#endif currentScreen = voltageScreen; if (!keepCurrentLine) { currentLine = 3; @@ -435,9 +435,9 @@ void UILCD::drawVoltageScreen(bool keepCurrentLine) { } void UILCD::drawMainScreen() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawMainScreen()"); - } +#endif currentScreen = mainScreen; currentLine = 0; @@ -467,9 +467,9 @@ void UILCD::drawMainScreen() { } void UILCD::drawSplashScreen() { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::drawSplashScreen()"); - } +#endif tft->setCursor(0,0); tft->fillScreen(SPLASH_BACKGROUND); bmpDraw("splash.bmp", 13, 0); @@ -481,9 +481,9 @@ void UILCD::drawSplashScreen() { } void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::bmpDraw()"); - } +#endif File bmpFile; int bmpWidth, bmpHeight; // W+H in pixels 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 (DEBUG) { +#if DEBUG == 2 Serial.println(); Serial.print("Loading image '"); Serial.print(filename); Serial.println('\''); - } +#endif // Open requested file on SD card if ((bmpFile = SD.open(filename)) == NULL) { - if (DEBUG) { + #if DEBUG == 2 Serial.print("File not found"); - } + #endif return; } // Parse BMP header if(read16(bmpFile) == 0x4D42) { // BMP signature - if (DEBUG) { + #if DEBUG == 2 Serial.print("File size: "); Serial.println(read32(bmpFile)); - } + #endif (void)read32(bmpFile); // Read & ignore creator bytes bmpImageoffset = read32(bmpFile); // Start of image data - if (DEBUG) { + #if DEBUG == 2 Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC); - } + #endif // Read DIB header - if (DEBUG) { + #if DEBUG == 2 Serial.print("Header size: "); Serial.println(read32(bmpFile)); - } + #endif bmpWidth = read32(bmpFile); bmpHeight = read32(bmpFile); if(read16(bmpFile) == 1) { // # planes -- must be '1' bmpDepth = read16(bmpFile); // bits per pixel - if (DEBUG) { + #if DEBUG == 2 Serial.print("Bit Depth: "); Serial.println(bmpDepth); - } + #endif if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed goodBmp = true; // Supported BMP format -- proceed! - if (DEBUG) { + #if DEBUG == 2 Serial.print("Image size: "); Serial.print(bmpWidth); Serial.print('x'); Serial.println(bmpHeight); - } + #endif // BMP rows are padded (if needed) to 4-byte boundary rowSize = (bmpWidth * 3 + 3) & ~3; @@ -600,11 +600,11 @@ void UILCD::bmpDraw(char *filename, uint8_t x, uint8_t y) { } // end pixel delay(5); } // end scanline - if (DEBUG) { + #if DEBUG == 2 Serial.print("Loaded in "); Serial.print(millis() - startTime); Serial.println(" ms"); - } + #endif } // 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. uint16_t UILCD::read16(File f) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::read16()"); - } +#endif uint16_t result; ((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[1] = f.read(); // MSB @@ -628,9 +628,9 @@ uint16_t UILCD::read16(File f) { } uint32_t UILCD::read32(File f) { - if (DEBUG) { +#if DEBUG == 2 Serial.println("UILCD::read32()"); - } +#endif uint32_t result; ((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[1] = f.read();