From f44d57d878eaf9088dad912fcd0fa2863bf8f416 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Wed, 24 May 2017 21:06:45 +1000 Subject: Working on ESPRIT (ESP32) --- esplogger/esplogger.ino | 122 ++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 67 deletions(-) (limited to 'esplogger/esplogger.ino') diff --git a/esplogger/esplogger.ino b/esplogger/esplogger.ino index 5cc1e7b..6d9fb05 100644 --- a/esplogger/esplogger.ino +++ b/esplogger/esplogger.ino @@ -6,6 +6,9 @@ #include #include +#include +#include +#include #include #include "SH1106.h" #include "images.h" @@ -39,12 +42,19 @@ static byte pidTier3[] = {PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, P byte pidValue[TIER_NUM1]; +#ifdef ESP32 +HardwareSerial Serial1(1); +#endif + class COBDLogger : public COBD, public CDataLogger { public: COBDLogger():state(0) {} void setup() { + pinMode(8, OUTPUT); + digitalWrite(8, LOW); + showStates(); #if USE_MPU6050 @@ -63,22 +73,6 @@ public: showStates(); -#if ENABLE_DATA_LOG - uint16_t index = openFile(); - lcd.setFontSize(FONT_SIZE_SMALL); - lcd.setCursor(86, 0); - if (index) { - lcd.write('['); - lcd.setFlags(FLAG_PAD_ZERO); - lcd.printInt(index, 5); - lcd.setFlags(0); - lcd.write(']'); - } else { - lcd.print("NO LOG"); - } - delay(100); -#endif - #if ENABLE_DATA_LOG // open file for logging if (!(state & STATE_SD_READY)) { @@ -87,9 +81,25 @@ public: showStates(); } } + + if (state & STATE_SD_READY) { + uint16_t index = openFile(); + lcd.setFontSize(FONT_SIZE_SMALL); + lcd.setCursor(86, 0); + if (index) { + lcd.write('['); + lcd.setFlags(FLAG_PAD_ZERO); + lcd.printInt(index, 5); + lcd.setFlags(0); + lcd.write(']'); + } else { + lcd.print("NO LOG"); + } + delay(100); + } #endif - initScreen(); + initLoggerScreen(); } void loop() { @@ -144,61 +154,37 @@ public: #if ENABLE_DATA_LOG bool checkSD() { - Sd2Card card; - SdVolume volume; state &= ~STATE_SD_READY; - pinMode(SS, OUTPUT); - if (card.init(SPI_FULL_SPEED, SD_CS_PIN)) { - const char* type; - - lcd.print("SD"); - switch(card.type()) { - case SD_CARD_TYPE_SD1: - type = "1"; - break; - case SD_CARD_TYPE_SD2: - type = "2"; - break; - case SD_CARD_TYPE_SDHC: - type = "HC"; - break; - default: - type = "x"; - } - - lcd.print(type); - lcd.write(' '); - if (!volume.init(card)) { - lcd.print("No FAT"); - return false; - } - - uint32_t volumesize = volume.blocksPerCluster(); - volumesize >>= 1; // 512 bytes per block - volumesize *= volume.clusterCount(); - volumesize >>= 10; + if (!SD.begin()) { + lcd.print("SD "); + lcd.draw(cross, 16, 16); + lcd.println(); + return false; + } - lcd.print((int)((volumesize + 511) / 1000)); - lcd.print("GB"); - } else { - lcd.print("SD "); - lcd.draw(cross, 16, 16); - return false; + uint8_t cardType = SD.cardType(); + if(cardType == CARD_NONE){ + lcd.println("No SD card"); + return false; } - if (!SD.begin(SD_CS_PIN)) { - lcd.print("Bad"); - return false; + if(cardType == CARD_MMC){ + Serial.print("MMC "); + } else if(cardType == CARD_SD){ + Serial.print("SDSC "); + } else if(cardType == CARD_SDHC){ + Serial.print("SDHC "); + } else { + Serial.print("SD "); } + unsigned int cardSize = (unsigned int)SD.cardSize() >> 30; + lcd.print(cardSize); + lcd.println("G"); state |= STATE_SD_READY; return true; } #endif - void initScreen() - { - initLoggerScreen(); - } private: void dataIdleLoop() { @@ -298,13 +284,13 @@ private: case PID_THROTTLE: lcd.setCursor(24, 5); lcd.setFontSize(FONT_SIZE_SMALL); - lcd.printInt(value % 100, 3); + lcd.print(value % 100); break; case PID_INTAKE_TEMP: if (value < 1000) { lcd.setCursor(102, 5); lcd.setFontSize(FONT_SIZE_SMALL); - lcd.printInt(value, 3); + lcd.print(value); } break; } @@ -348,9 +334,9 @@ private: lcd.setCursor(110, 3); lcd.print("rpm"); lcd.setCursor(0, 5); - lcd.print("THR: %"); + lcd.print("THR:"); lcd.setCursor(80, 5); - lcd.print("AIR: C"); + lcd.print("AIR:"); } }; @@ -366,14 +352,16 @@ void setup() delay(1000); logger.begin(); - logger.initSender(); #if ENABLE_DATA_LOG lcd.setFontSize(FONT_SIZE_MEDIUM); lcd.setCursor(0, 2); logger.checkSD(); #endif + logger.setup(); + + } void loop() -- cgit v1.2.3