From fb98d97acc0555fb557ed7b1ffa00f0f0d73adb8 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 18:23:43 +0200 Subject: [PATCH 1/9] Shorten log texts (save space) --- BoxAccelerometer.cpp | 6 +++--- BoxBattery.cpp | 12 ++++++------ BoxCLI.cpp | 30 +++++++++++++++--------------- BoxConfig.cpp | 6 +++--- BoxDAC.cpp | 24 ++++++++++++------------ BoxEvents.cpp | 24 ++++++++++++------------ BoxI2C.cpp | 4 ++-- BoxLEDs.cpp | 4 ++-- BoxPower.cpp | 2 +- BoxRFID.cpp | 26 +++++++++++++------------- BoxSD.cpp | 6 +++--- BoxTonies.cpp | 6 +++--- WrapperWebServer.cpp | 12 ++++++------ WrapperWiFi.cpp | 2 +- 14 files changed, 82 insertions(+), 82 deletions(-) diff --git a/BoxAccelerometer.cpp b/BoxAccelerometer.cpp index ccf29c6..b4a034f 100644 --- a/BoxAccelerometer.cpp +++ b/BoxAccelerometer.cpp @@ -6,10 +6,10 @@ void BoxAccelerometer::begin() { digitalWrite(62, HIGH); setInterval(250); - Log.info("Initialize Accelerometer..."); + Log.info("Init Accelerometer..."); if (!_accel.begin()) - Log.error("... not found!"); + Log.error("...not found!"); _accel.setupPL(); @@ -30,7 +30,7 @@ void BoxAccelerometer::begin() { _accel.writeRegister(CTRL_REG5, 0x40); //Original 0x40 _accel.writeRegister(CTRL_REG1, 0x03); //Original 0x03 - Log.info("... initialized"); + Log.info("...done"); } void BoxAccelerometer::loop() { diff --git a/BoxBattery.cpp b/BoxBattery.cpp index c64b0d4..d075cd9 100644 --- a/BoxBattery.cpp +++ b/BoxBattery.cpp @@ -75,7 +75,7 @@ void BoxBattery::logBatteryStatus() { int voltageNum = voltageDec / 100; voltageDec = voltageDec - voltageNum * 100; - Log.info("Battery Status:"); + Log.info("Battery Stats:"); Log.info(" Charging: %T", isChargerConnected()); Log.info(" ADC Raw: %c", getBatteryAdcRaw()); Log.info(" Estimated Voltage: %d.%s%dV", voltageNum, (voltageDec<10) ? "0": "", voltageDec); @@ -123,11 +123,11 @@ void BoxBattery::_doBatteryTestStep() { file.writeString("\r\n"); file.close(); } else { - Log.error("Could not write battery logfile %", _batteryTestFilename); + Log.error("Couldn't write log %", _batteryTestFilename); } } void BoxBattery::startBatteryTest() { - Log.info("Starting battery test..."); + Log.info("Start battery test..."); _batteryTestThread.enabled = true; _batteryTestStartMillis = millis(); @@ -152,14 +152,14 @@ void BoxBattery::startBatteryTest() { _batteryTestThread.run(); } else { - Log.error("Could not initialize battery logfile %s", _batteryTestFilename); + Log.error("Couldn't init battery log %s", _batteryTestFilename); _batteryTestThread.enabled = false; } } void BoxBattery::stopBatteryTest() { if (!_batteryTestThread.enabled) return; - Log.info("Stopping battery test..."); + Log.info("Stop battery test..."); _batteryTestThread.enabled = false; _doBatteryTestStep(); FileFs file; @@ -172,7 +172,7 @@ void BoxBattery::stopBatteryTest() { file.writeString("\r\n"); file.close(); } else { - Log.error("Could not write battery logfile %s", _batteryTestFilename); + Log.error("Couldn't write battery log %s", _batteryTestFilename); _batteryTestThread.enabled = false; } } diff --git a/BoxCLI.cpp b/BoxCLI.cpp index e5593bd..a1eecd3 100644 --- a/BoxCLI.cpp +++ b/BoxCLI.cpp @@ -39,7 +39,7 @@ void BoxCLI::begin() { cmdRFID.addFlagArg("o/verwrite"); cmdLoad = cli.addCmd("load"); - cmdLoad.setDescription(" Shows the current load of all threads"); + cmdLoad.setDescription(" Shows the load of all threads"); cmdLoad.addArg("n/ame", ""); cmdLoad.addArg("p/ointer", "0"); cmdLoad.addFlagArg("r/eset"); @@ -145,14 +145,14 @@ void BoxCLI::execI2C() { tmpNum = parseNumber(saddress); if (tmpNum > 127) { - Log.error("address must be lower than 128"); + Log.error("address must be <128"); return; } addr = (uint8_t)tmpNum; tmpNum = parseNumber(sregister); if (tmpNum > 255) { - Log.error("register must be lower than 256"); + Log.error("register must be <256"); return; } regi = (uint8_t)tmpNum; @@ -163,7 +163,7 @@ void BoxCLI::execI2C() { if (read) { String soutput = c.getArg("output").getValue(); if (!(soutput == "x" || soutput == "X" || soutput == "i" || soutput == "b" || soutput == "B")) { - Log.error("Allowed values for output are: x, X, i, b, B"); + Log.error("Allowed output values are: x, X, i, b, B"); return; } @@ -187,10 +187,10 @@ void BoxCLI::execI2C() { while(isspace((unsigned char)*value)) value++; tmpNum = parseNumber(value, &newVal); if (tmpNum > 255) { - Log.error("value must be lower than 256"); + Log.error("value must be <256"); return; } else if (value == newVal) { - Log.error("Could not parse part \"%s\" of \"%s\"", value, svalue.c_str()); + Log.error("Couldn't parse part \"%s\" of \"%s\"", value, svalue.c_str()); return; } uint8_t data = (uint8_t)tmpNum; @@ -212,7 +212,7 @@ void BoxCLI::execSpiRFID() { String sregister = c.getArg("register").getValue(); tmpNum = parseNumber(sregister); if (tmpNum > 255) { - Log.error("register must be lower than 256"); + Log.error("register must be <256"); return; } uint8_t regi = (uint8_t)tmpNum; @@ -220,7 +220,7 @@ void BoxCLI::execSpiRFID() { String svalue = c.getArg("value").getValue(); tmpNum = parseNumber(svalue); if (tmpNum > 255) { - Log.error("value/command must be lower than 256"); + Log.error("value/command must be <256"); return; } uint8_t value = (uint8_t)tmpNum; @@ -250,7 +250,7 @@ void BoxCLI::execBeep() { String sid = c.getArg("midi-id").getValue(); tmpNum = parseNumber(sid); if (tmpNum > 127) { - Log.error("midi-id must be lower than 128"); + Log.error("midi-id must be <128"); return; } uint8_t id = (uint8_t)tmpNum; @@ -258,7 +258,7 @@ void BoxCLI::execBeep() { String slength = c.getArg("length").getValue(); tmpNum = parseNumber(slength); if (tmpNum > 65535) { - Log.error("length must be lower than 65.536"); + Log.error("length must be <65.536"); return; } uint16_t length = (uint16_t)tmpNum; @@ -309,7 +309,7 @@ void BoxCLI::execLoad() { unsigned long pointer = parseNumber(pointerStr); if (name != "") { - Log.info("Thread statistics for Threads starting with \"%s\"", name.c_str()); + Log.info("Statistics for Threads starting with \"%s\"", name.c_str()); Log.println("---"); for (uint8_t i = 0; i < Box.threadController.size(); i++) { EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i); @@ -321,7 +321,7 @@ void BoxCLI::execLoad() { Box.delayTask(1); } } else if (pointer > 0) { - Log.info("Thread statistics for Threads with pointer=%i", pointer); + Log.info("Statistics for Threads with pointer=%i", pointer); Log.println("---"); for (uint8_t i = 0; i < Box.threadController.size(); i++) { EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i); @@ -333,7 +333,7 @@ void BoxCLI::execLoad() { } Box.delayTask(1); } else { - Log.info("Thread statistics for all %i Threads", Box.threadController.size(false)); //TODO ThreadController + Log.info("Statistics for all %i Threads", Box.threadController.size(false)); //TODO ThreadController Log.println("---"); for (uint8_t i = 0; i < Box.threadController.size(); i++) { EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i); @@ -344,7 +344,7 @@ void BoxCLI::execLoad() { } } - if (reset) Log.info("All stats of selected threads are reset."); + if (reset) Log.info("All stats of selected threads reset."); } void BoxCLI::execI2S() { @@ -427,7 +427,7 @@ void BoxCLI::execAudio() { Log.info("Max Samplerate is set to %ihz", Box.boxDAC.audioOutputResample->GetMaxRate()); } if (buffer == 0) { - Log.info("Additional buffering disabled."); + Log.info("Additional buffering off"); Box.boxDAC.audioOutput = Box.boxDAC.audioOutputResample; } else if (buffer > 0) { if (buffer <= freeHeapMemory() / 2) { diff --git a/BoxConfig.cpp b/BoxConfig.cpp index ef011e2..a323da9 100644 --- a/BoxConfig.cpp +++ b/BoxConfig.cpp @@ -23,11 +23,11 @@ void BoxConfig::read() { } file.close(); if (!setFromJson(json)) { - Log.error("Could not read config file %s, try to recreate it.", CONFIG_SD_PATH); + Log.error("Couldn't read cfg file %s, recreating it", CONFIG_SD_PATH); write(); } } else { - Log.error("Could not read config file %s, try to recreate it.", CONFIG_SD_PATH); + Log.error("Couldn't read cfg file %s, recreating it", CONFIG_SD_PATH); write(); } } @@ -38,7 +38,7 @@ void BoxConfig::write() { file.writeString((char*)json.c_str()); file.close(); } else { - Log.error("Could not write config file %", CONFIG_SD_PATH); + Log.error("Couldn't write cfg file %", CONFIG_SD_PATH); } } diff --git a/BoxDAC.cpp b/BoxDAC.cpp index f605dc1..4529592 100644 --- a/BoxDAC.cpp +++ b/BoxDAC.cpp @@ -13,24 +13,24 @@ void BoxDAC::logDmaIrqChanges() { if (lastDmaIRQcount != dmaIRQcount) { - Log.info("***dmaIRQcount=%i", dmaIRQcount); + Log.info("*dmaIRQcount=%i", dmaIRQcount); lastDmaIRQcount = dmaIRQcount; } if (lastPriIndexRx != priIndexRx) { - Log.info("***priIndexRx=%i", priIndexRx); + Log.info("*priIndexRx=%i", priIndexRx); lastPriIndexRx = priIndexRx; } if (lastAltIndexRx != altIndexRx) { - Log.info("***altIndexRx=%i", altIndexRx); + Log.info("*altIndexRx=%i", altIndexRx); lastAltIndexRx = altIndexRx; } if (lastDmaBufferFilled != dmaBufferFilled) { - Log.info("***dmaBufferFilled=%i", dmaBufferFilled); + Log.info("*dmaBufferFilled=%i", dmaBufferFilled); lastDmaBufferFilled = dmaBufferFilled; } if (lastDmaBufferEmpty != dmaBufferEmpty) { - Log.info("***dmaBufferEmpty=%i", dmaBufferEmpty); + Log.info("*dmaBufferEmpty=%i", dmaBufferEmpty); lastDmaBufferEmpty = dmaBufferEmpty; } } @@ -40,7 +40,7 @@ void dma_irq() { } void BoxDAC::begin() { - Log.info("Initialize DAC..."); + Log.info("Init DAC..."); audioBuffer.init(); audioBuffer.logState(); @@ -122,7 +122,7 @@ void BoxDAC::begin() { send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO); send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00); - Log.info("...initialized"); + Log.info("...done"); //samSay("Hackiebox by Team Revvox!"); } @@ -175,7 +175,7 @@ void BoxDAC::opusTest() { Log.info("Needed heap %ib", opus_decoder_get_size(channels)); decoder = opus_decoder_create(16000, channels, &error); if (error != OPUS_OK) { - Log.error("Could not create OPUS Decoder error=%i", error); + Log.error("Couldn't create OPUS Decoder error=%i", error); return; } Box.boxPower.feedSleepTimer(); @@ -272,7 +272,7 @@ bool BoxDAC::_playWAV(const char* path) { audioSource = new AudioFileSourceFatFs(path); if (!audioGenerator->begin(audioSource, audioOutput)) { - Log.error("Could not play wav?!"); + Log.error("Couldn't play wav?!"); return false; } Log.info("WAV file loaded..."); @@ -530,7 +530,7 @@ void BoxDAC::samSay(const char *text, enum ESP8266SAM::SAMVoice voice, uint8_t s audioOutput->SetRate(samplerate); #else - Log.error("Text-To-Speech is not active (FEATURE_FLAG_TEXT2SPEECH not set)"); + Log.error("Text-To-Speech off (FEATURE_FLAG_TEXT2SPEECH not set)"); #endif } @@ -581,7 +581,7 @@ bool BoxDAC::increaseVolume() { Box.delayTask(50); beepRaw(0x30F9, 0x763F, 0x000140); //16kHz //beepMidi(84,50,true); - Log.info("Maximum volume reached."); + Log.info("Max volume reached"); } logVolume(); return result; @@ -599,7 +599,7 @@ bool BoxDAC::decreaseVolume() { Box.delayTask(50); beepRaw(0x0F0A, 0x7F1A, 0x000140); //16kHz //beepMidi(62, 50, true); - Log.info("Minimal volume reached."); + Log.info("Min volume reached"); } logVolume(); return result; diff --git a/BoxEvents.cpp b/BoxEvents.cpp index 98c1bbd..0492d8b 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -128,7 +128,7 @@ void BoxEvents::handleEarEvent(BoxButtonEars::EarButton earId, BoxButtonEars::Pr void BoxEvents::handleBatteryEvent(BoxBattery::BatteryEvent state) { switch (state) { case BoxBattery::BatteryEvent::BAT_CRITICAL: - Log.info("Battery is critical, please connect the charger, hibernating!"); + Log.info("Battery is critical, connect the charger, hibernating!"); Box.boxBattery.stopBatteryTest(); Box.boxBattery.logBatteryStatus(); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Orange, 3); @@ -136,17 +136,17 @@ void BoxEvents::handleBatteryEvent(BoxBattery::BatteryEvent state) { Box.boxPower.hibernate(); break; case BoxBattery::BatteryEvent::BAT_LOW: - Log.info("Battery is low, please connect the charger!"); + Log.info("Battery is low, connect the charger!"); Box.boxBattery.logBatteryStatus(); Box.boxLEDs.setIdleAnimation(BoxLEDs::ANIMATION_TYPE::PULSE, BoxLEDs::CRGB::Orange); break; case BoxBattery::BatteryEvent::CHR_CONNECT: - Log.info("Charger was connected"); + Log.info("Charger connected"); Box.boxBattery.logBatteryStatus(); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::White, 3); break; case BoxBattery::BatteryEvent::CHR_DISCONNECT: - Log.info("Charger was disconnected"); + Log.info("Charger disconnected"); Box.boxBattery.logBatteryStatus(); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::DarkSlateGray, 3); break; @@ -158,16 +158,16 @@ void BoxEvents::handleWiFiEvent(WrapperWiFi::ConnectionState state) { case WrapperWiFi::ConnectionState::WAIT_CONNECT: break; case WrapperWiFi::ConnectionState::WAIT_IP: - Log.info("WiFi connected successfully, waiting for ip..."); + Log.info("WiFi connected, waiting for ip..."); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Cyan, 3); break; case WrapperWiFi::ConnectionState::CONNECTED: - Log.info("IP address: %s", WiFi.localIP().toString().c_str()); + Log.info("IP: %s", WiFi.localIP().toString().c_str()); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Blue, 3); break; case WrapperWiFi::ConnectionState::DISCONNECTED: //Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Cyan, 3); - Log.info("WiFi connection lost"); + Log.info("WiFi lost"); break; default: @@ -186,11 +186,11 @@ void BoxEvents::handlePowerEvent(BoxPower::PowerEvent event) { break; case BoxPower::PowerEvent::BOX_IDLE: if (Box.boxBattery.batteryTestActive()) { - Log.info("Box not used, but battery test is running, keep alive..."); + Log.info("Box unused, battery test running, keep alive..."); Box.boxPower.feedSleepTimer(); return; } - Log.info("Box not used, powering off."); + Log.info("Box unused, power off."); Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Green, 3); Box.boxLEDs.waitForAnimationToFinish(); Box.boxPower.hibernate(); @@ -271,20 +271,20 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { DirFs dir; char* rcontent = "/rCONTENT"; if (!dir.openDir(rcontent)) { - Log.info("Creating missing dir %s...", rcontent); + Log.info("Create dir %s...", rcontent); if (!FatFs.mkdir(rcontent)) { Log.info("...failed!"); } } char* rdump = "/rDUMP"; if (!dir.openDir(rdump)) { - Log.info("Creating missing dir %s...", rdump); + Log.info("Create dir %s...", rdump); if (!FatFs.mkdir(rdump)) { Log.info("...failed!"); } } if (!dir.openDir((char*)path)) { - Log.info("Creating missing dir %s...", path); + Log.info("Create dir %s...", path); if (!FatFs.mkdir((char*)path)) { Log.info("...failed!"); } diff --git a/BoxI2C.cpp b/BoxI2C.cpp index 634b163..aa992e9 100644 --- a/BoxI2C.cpp +++ b/BoxI2C.cpp @@ -6,7 +6,7 @@ void BoxI2C::begin() { bool BoxI2C::send_raw(uint8_t data) { if (!Wire.write(data)) { - Log.error("Could not write into I2C Buffer"); + Log.error("Couldn't write into I2C Buffer"); return false; } return true; @@ -18,7 +18,7 @@ bool BoxI2C::send(uint8_t address, uint8_t target_register, uint8_t data) { uint8_t result = Wire.endTransmission(false); if (!result) return true; - Log.error("Could not send I2C buffer, error=%i", result); + Log.error("Couldn't send I2C buffer, error=%i", result); } uint8_t BoxI2C::readByte(uint8_t address, uint8_t source_register) { diff --git a/BoxLEDs.cpp b/BoxLEDs.cpp index d0a14de..2f5f847 100644 --- a/BoxLEDs.cpp +++ b/BoxLEDs.cpp @@ -297,7 +297,7 @@ void BoxLEDs::testLEDs() { uint8_t ledG = getGreen(); uint8_t ledB = getBlue(); - Log.info("Testing LEDs..."); + Log.info("Test LEDs..."); Box.delayTask(250); Log.info(" Red"); @@ -327,7 +327,7 @@ void BoxLEDs::testLEDs() { Box.delayTask(500); Log.info(" Reset"); setAll(ledR, ledG, ledB); - Log.info(" Test finished."); + Log.info(" finished"); } BoxLEDs::CRGB BoxLEDs::_wheel(uint8_t wheelPos) { diff --git a/BoxPower.cpp b/BoxPower.cpp index 83227e9..8f7972e 100644 --- a/BoxPower.cpp +++ b/BoxPower.cpp @@ -13,7 +13,7 @@ void BoxPower::begin() { _lastFeed = millis(); setInterval(5000); - Log.info("Initialize BoxPower class, sleepMinutes=%i", _sleepMinutes); + Log.info("Init BoxPower class, sleepMinutes=%i", _sleepMinutes); } void BoxPower::loop() { diff --git a/BoxRFID.cpp b/BoxRFID.cpp index cd734d2..210d26a 100644 --- a/BoxRFID.cpp +++ b/BoxRFID.cpp @@ -6,7 +6,7 @@ void rfid_irq() { Box.boxRFID.receivedInterrupt(); } void BoxRFID::begin() { - Log.info("Initialize RFID..."); + Log.info("Init RFID..."); setInterval(250); pinMode(16, OUTPUT); @@ -17,7 +17,7 @@ void BoxRFID::begin() { resetRFID(); - Log.info("...initialized"); + Log.info("...done"); } void BoxRFID::loop() { @@ -43,10 +43,10 @@ void BoxRFID::loop() { for (uint8_t i = 0; i < 3; i++) { result = ISO15693_setPassSlixL(0x04, knownPasswords[i]); //reversed! if (result == ISO15693_RESULT::SET_PASSWORD_CORRECT) { - Log.info("Password %X (i=%i) was correct", knownPasswords[i], i); + Log.info("Password %X (i=%i) was ok", knownPasswords[i], i); break; } else if (result == ISO15693_RESULT::SET_PASSWORD_INCORRECT) { - Log.info("Password %X (i=%i) was incorrect", knownPasswords[i], i); + Log.info("Password %X (i=%i) was wrong", knownPasswords[i], i); writeRegister(REGISTER::CHIP_STATUS_CONTROL, 0b00000001); //turnRfOff(); Box.delayTask(20); reinitRFID(); @@ -119,7 +119,7 @@ void BoxRFID::processInterrupt(IRQ_STATUS irqStatus) { memmove(&trfBuffer[trfOffset], &trfBuffer[trfOffset+2], trfRxLength-2); trfRxLength -= 2; } else { - Log.print("No ghost bytes found @RX_COMPLETE|FIFO_HIGH_OR_LOW\r\n"); + Log.print("No ghost bytes @RX_COMPLETE|FIFO_HIGH_OR_LOW\r\n"); } trfOffset += trfRxLength; @@ -147,7 +147,7 @@ void BoxRFID::processInterrupt(IRQ_STATUS irqStatus) { memmove(&trfBuffer[trfOffset], &trfBuffer[trfOffset+2], trfRxLength-2); trfRxLength -= 2; } else { - Log.print("No ghost bytes found @RX_COMPLETE\r\n"); + Log.print("No ghost bytes @RX_COMPLETE\r\n"); } trfOffset += trfRxLength; @@ -385,7 +385,7 @@ BoxRFID::ISO15693_RESULT BoxRFID::ISO15693_readSingleBlock(uint8_t blockId, uint } return ISO15693_RESULT::READ_SINGLE_BLOCK_VALID_RESPONSE; } else { - Log.error("Received invalid answer. Length should be %i but is %i", 5, trfRxLength); + Log.error("Invalid answer. Length should be %i but is %i", 5, trfRxLength); for (uint8_t i=0; isendContent("]}"); } else { StaticJsonDocument<299> doc; //Maximum 256 chars path length //https://arduinojson.org/v6/assistant/ - doc["error"] = "Directory not found"; - Log.error("Directory %s not found", directory); + doc["error"] = "Dir not found"; + Log.error("Dir %s not found", directory); size_t len = measureJson(doc)+1; char json[len]; diff --git a/BoxTonies.cpp b/BoxTonies.cpp index b5371b6..e9f7e42 100644 --- a/BoxTonies.cpp +++ b/BoxTonies.cpp @@ -23,7 +23,7 @@ bool BoxTonies::loadTonieByPath(uint8_t* path) { bool ret = true; clearHeader(); - Log.info("Loading Tonie from path %s...", path); + Log.info("Load Tonie from path %s...", path); if (tonieFile.open((char*)path, FA_OPEN_EXISTING | FA_READ)) { uint8_t buffer[512]; //TODO: buffer >512 size may scramble the stream 4096 block needed @@ -102,12 +102,12 @@ bool BoxTonies::loadTonieByPath(uint8_t* path) { ret = false; } } else { - Log.error("... could not data from file."); + Log.error("... couldn't data from file"); ret = false; } tonieFile.close(); } else { - Log.error("... could not open Tonie."); + Log.error("... couldn't open Tonie"); ret = false; } if (!ret) { diff --git a/WrapperWebServer.cpp b/WrapperWebServer.cpp index 900ea0d..0000c81 100755 --- a/WrapperWebServer.cpp +++ b/WrapperWebServer.cpp @@ -179,7 +179,7 @@ void WrapperWebServer::handleAjax(void) { sendJsonSuccess(); return; } - Log.error("Could not del %s %s", filepath, SerFlash.lastErrorString()); + Log.error("Couldn't del %s %s", filepath, SerFlash.lastErrorString()); } else if (cmd.equals("create-dir")) { String dir_str = _server->arg("dir"); char* dir = (char*)dir_str.c_str(); @@ -377,7 +377,7 @@ bool WrapperWebServer::commandGetFile(String* path, long read_start, long read_l file.close(); return true; } else { - Log.error("Could not open %s", path->c_str()); + Log.error("Couldn't open %s", path->c_str()); } return false; } @@ -409,7 +409,7 @@ bool WrapperWebServer::commandGetFlashFile(String* path, long read_start, long r SerFlash.close(); return true; } else { - Log.error("Could not open %s %s", path->c_str(), SerFlash.lastErrorString()); + Log.error("Couldn't open %s %s", path->c_str(), SerFlash.lastErrorString()); SerFlash.close(); } return false; @@ -438,7 +438,7 @@ void WrapperWebServer::handleUploadFile() { _uploadFile.seekSet(write_start); return; } - Log.error("File could not be opened."); + Log.error("File Couldn't be opened."); } else if (upload.status == UPLOAD_FILE_WRITE) { //Log.verbose("handleUploadFile Data: %i", upload.currentSize); if (_uploadFileOpen) { @@ -483,10 +483,10 @@ void WrapperWebServer::handleUploadFlashFile() { SerFlash.seek(write_start); return; } - Log.error("Could not open %s %s", filename, SerFlash.lastErrorString()); + Log.error("Couldn't open %s %s", filename, SerFlash.lastErrorString()); SerFlash.close(); } else { - Log.error("Could not delete %s %s", filename, SerFlash.lastErrorString()); + Log.error("Couldn't delete %s %s", filename, SerFlash.lastErrorString()); } } else if (upload.status == UPLOAD_FILE_WRITE) { //Log.verbose("handleUploadFlashFile Data: %i", upload.currentSize); diff --git a/WrapperWiFi.cpp b/WrapperWiFi.cpp index 7b77b86..34caa37 100755 --- a/WrapperWiFi.cpp +++ b/WrapperWiFi.cpp @@ -71,7 +71,7 @@ void WrapperWiFi::reconnect() { //TODO: LED Stuff _state = ConnectionState::NONE; Log.debug("WrapperWiFi(ssid=\"%s\", password=\"%s\")", _ssid, _password); - Log.info("Connecting to WiFi %s", _ssid); + Log.info("Connect to WiFi %s", _ssid); //stationary mode if (_ip[0] != 0) { From 001708095930c9bdbab819c895b7572d0709e3fa Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 19:15:50 +0200 Subject: [PATCH 2/9] Shorten log messages --- BoxEvents.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BoxEvents.cpp b/BoxEvents.cpp index 0492d8b..45e31d1 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -273,20 +273,20 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { if (!dir.openDir(rcontent)) { Log.info("Create dir %s...", rcontent); if (!FatFs.mkdir(rcontent)) { - Log.info("...failed!"); + Log.info("...fail!"); } } char* rdump = "/rDUMP"; if (!dir.openDir(rdump)) { Log.info("Create dir %s...", rdump); if (!FatFs.mkdir(rdump)) { - Log.info("...failed!"); + Log.info("...fail!"); } } if (!dir.openDir((char*)path)) { Log.info("Create dir %s...", path); if (!FatFs.mkdir((char*)path)) { - Log.info("...failed!"); + Log.info("...fail!"); } } else { bool foundFile = false; @@ -297,7 +297,7 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { } } if (!foundFile) { - Log.info("No file found to play."); + Log.info("No file play."); } else { uint8_t* filepath; asprintf( From a1def3970c46571b973cfab2678cd2cd60997fcd Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 19:24:35 +0200 Subject: [PATCH 3/9] reduce watchdog timer to 5s --- Hackiebox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hackiebox.cpp b/Hackiebox.cpp index 35c2e74..f92fc14 100755 --- a/Hackiebox.cpp +++ b/Hackiebox.cpp @@ -165,7 +165,7 @@ bool Hackiebox::watchdog_start() { MAP_WatchdogUnlock(WDT_BASE); MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1); MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler); - MAP_WatchdogReloadSet(WDT_BASE, 80000000*15); //15s + MAP_WatchdogReloadSet(WDT_BASE, 80000000*5); //5s MAP_WatchdogEnable(WDT_BASE); return MAP_WatchdogRunning(WDT_BASE); From 25af9f8fd2a6d90997cad9c16ed016d6d9644770 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 19:30:56 +0200 Subject: [PATCH 4/9] Autodump config / sound --- BoxConfig.cpp | 10 +++------- BoxConfig.h | 4 ++-- BoxEvents.cpp | 15 +++++++++------ ConfigStructures.h | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/BoxConfig.cpp b/BoxConfig.cpp index a323da9..f5068a0 100644 --- a/BoxConfig.cpp +++ b/BoxConfig.cpp @@ -73,11 +73,11 @@ String BoxConfig::getAsJson() { JsonObject logDoc = doc.createNestedObject("log"); ConfigLog* logCfg = &_config.log; logDoc["sdLog"] = logCfg->sdLog; -/* + JsonObject miscDoc = doc.createNestedObject("misc"); ConfigMisc* miscCfg = &_config.misc; miscDoc["autodump"] = miscCfg->autodump; -*/ + serializeJson(doc, json); return json; } @@ -114,11 +114,9 @@ bool BoxConfig::setFromJson(String json) { ConfigLog* logCfg = &_config.log; logCfg->sdLog = logDoc["sdLog"].as(); - /* JsonObject miscDoc = doc["misc"]; ConfigMisc* miscCfg = &_config.misc; - miscCfg->autodump = logDoc["autodump"].as(); - */ + miscCfg->autodump = miscDoc["autodump"].as(); // Convert old config version to latest one. if (_config.version != CONFIG_ACTIVE_VERSION) { @@ -129,13 +127,11 @@ bool BoxConfig::setFromJson(String json) { _config.version = 3; write(); break; - /* case 3: miscCfg->autodump = false; _config.version = 4; write(); break; - */ default: _initializeConfig(); write(); diff --git a/BoxConfig.h b/BoxConfig.h index 72fdd25..faad2b3 100644 --- a/BoxConfig.h +++ b/BoxConfig.h @@ -6,8 +6,8 @@ #include "BoxSD.h" -#define BOXCONFIG_JSON_SIZE 489 -//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false}} +#define BOXCONFIG_JSON_SIZE 515 +//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false},"misc":{"autodump":false}} //Size from https://arduinojson.org/v6/assistant/ class BoxConfig { diff --git a/BoxEvents.cpp b/BoxEvents.cpp index 45e31d1..a67b351 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -259,14 +259,17 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7] ); - //Needs tooo much heap memory?! - //if(/*Config.get()->misc.autodump*/) { + if(Config.get()->misc.autodump) { + Log.info("Autodump..."); if (Box.boxRFID.dumpTagMemory(false)) { - //Box.boxDAC.beep(); - //Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Yellow, 5); - //Box.boxLEDs.waitForAnimationToFinish(); + Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Yellow, 2); + Box.boxDAC.beepMidi(84, 100, false); + Box.boxDAC.beepMidi(76, 100, false); + } else { } - //} + } else { + Log.info("No Autodump"); + } DirFs dir; char* rcontent = "/rCONTENT"; diff --git a/ConfigStructures.h b/ConfigStructures.h index 81bf7e1..d7a9ef4 100644 --- a/ConfigStructures.h +++ b/ConfigStructures.h @@ -1,7 +1,7 @@ #ifndef ConfigStructures_h #define ConfigStructures_h -#define CONFIG_ACTIVE_VERSION 3 +#define CONFIG_ACTIVE_VERSION 4 typedef struct { uint32_t voltageFactor; From 3387b75e43749bc0d874105515f3c9dd8bac7c01 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 19:40:43 +0200 Subject: [PATCH 5/9] Json temp var as private var --- BoxConfig.cpp | 10 ++++------ BoxConfig.h | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/BoxConfig.cpp b/BoxConfig.cpp index f5068a0..9c8b956 100644 --- a/BoxConfig.cpp +++ b/BoxConfig.cpp @@ -32,10 +32,10 @@ void BoxConfig::read() { } } void BoxConfig::write() { - String json = getAsJson(); + _json = getAsJson(); FileFs file; if (file.open(CONFIG_SD_PATH, FA_CREATE_ALWAYS | FA_WRITE)) { - file.writeString((char*)json.c_str()); + file.writeString((char*)_json.c_str()); file.close(); } else { Log.error("Couldn't write cfg file %", CONFIG_SD_PATH); @@ -48,8 +48,6 @@ ConfigStruct* BoxConfig::get() { String BoxConfig::getAsJson() { StaticJsonDocument doc; - String json; - doc["version"] = _config.version; JsonObject batteryDoc = doc.createNestedObject("battery"); @@ -78,8 +76,8 @@ String BoxConfig::getAsJson() { ConfigMisc* miscCfg = &_config.misc; miscDoc["autodump"] = miscCfg->autodump; - serializeJson(doc, json); - return json; + serializeJson(doc, _json); + return _json; } bool BoxConfig::setFromJson(String json) { StaticJsonDocument doc; diff --git a/BoxConfig.h b/BoxConfig.h index faad2b3..9d07b16 100644 --- a/BoxConfig.h +++ b/BoxConfig.h @@ -22,6 +22,7 @@ class BoxConfig { ConfigStruct* get(); private: + String _json; ConfigStruct _config; void _initializeConfig(); From 0dcf38467269898aa95f10f265fe81d3223349b0 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 19:44:21 +0200 Subject: [PATCH 6/9] Shorten log strings --- BoxRFID.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/BoxRFID.cpp b/BoxRFID.cpp index 210d26a..e4976f6 100644 --- a/BoxRFID.cpp +++ b/BoxRFID.cpp @@ -385,17 +385,17 @@ BoxRFID::ISO15693_RESULT BoxRFID::ISO15693_readSingleBlock(uint8_t blockId, uint } return ISO15693_RESULT::READ_SINGLE_BLOCK_VALID_RESPONSE; } else { - Log.error("Invalid answer. Length should be %i but is %i", 5, trfRxLength); + Log.error("Invalid length, should be %i but is %i", 5, trfRxLength); for (uint8_t i=0; i Date: Tue, 20 Jul 2021 20:21:42 +0200 Subject: [PATCH 7/9] Update multiple versions in cfg --- BoxConfig.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/BoxConfig.cpp b/BoxConfig.cpp index 9c8b956..29f9440 100644 --- a/BoxConfig.cpp +++ b/BoxConfig.cpp @@ -123,8 +123,6 @@ bool BoxConfig::setFromJson(String json) { batteryCfg->criticalAdc = batteryDoc["minimalAdc"].as(); batteryCfg->lowAdc = batteryCfg->criticalAdc + 100; _config.version = 3; - write(); - break; case 3: miscCfg->autodump = false; _config.version = 4; From b0cf4dbadd37d4e6231a61d61c6b0760f77c4d92 Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 20:22:49 +0200 Subject: [PATCH 8/9] Reoirder TagEvent (optimize) --- BoxEvents.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/BoxEvents.cpp b/BoxEvents.cpp index a67b351..04ddbd6 100644 --- a/BoxEvents.cpp +++ b/BoxEvents.cpp @@ -248,19 +248,16 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { Log.info("Continue playing last file"); Box.boxDAC.play(); } else { - Box.boxTonie.loadTonieByUid(Box.boxRFID.tagUid); - - uint8_t* path; - uint8_t* uid = Box.boxRFID.tagUid; - asprintf( - (char**)&path, - "%s%02X%02X%02X%02X%02X%02X%02X%02X", - Box.boxTonie.RCONTENT_BASE, - uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7] - ); - + DirFs dir; if(Config.get()->misc.autodump) { Log.info("Autodump..."); + char* rdump = "/rDUMP"; + if (!dir.openDir(rdump)) { + Log.info("Create dir %s...", rdump); + if (!FatFs.mkdir(rdump)) { + Log.info("...fail!"); + } + } if (Box.boxRFID.dumpTagMemory(false)) { Box.boxLEDs.setActiveAnimationByIteration(BoxLEDs::ANIMATION_TYPE::BLINK, BoxLEDs::CRGB::Yellow, 2); Box.boxDAC.beepMidi(84, 100, false); @@ -271,7 +268,6 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { Log.info("No Autodump"); } - DirFs dir; char* rcontent = "/rCONTENT"; if (!dir.openDir(rcontent)) { Log.info("Create dir %s...", rcontent); @@ -279,13 +275,16 @@ void BoxEvents::handleTagEvent(BoxRFID::TAG_EVENT event) { Log.info("...fail!"); } } - char* rdump = "/rDUMP"; - if (!dir.openDir(rdump)) { - Log.info("Create dir %s...", rdump); - if (!FatFs.mkdir(rdump)) { - Log.info("...fail!"); - } - } + + Box.boxTonie.loadTonieByUid(Box.boxRFID.tagUid); + uint8_t* path; + uint8_t* uid = Box.boxRFID.tagUid; + asprintf( + (char**)&path, + "%s%02X%02X%02X%02X%02X%02X%02X%02X", + Box.boxTonie.RCONTENT_BASE, + uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7] + ); if (!dir.openDir((char*)path)) { Log.info("Create dir %s...", path); if (!FatFs.mkdir((char*)path)) { From 74d37d1bd25623a45c6e2c5e40aa592f8d7b9fdd Mon Sep 17 00:00:00 2001 From: scilor Date: Tue, 20 Jul 2021 20:23:26 +0200 Subject: [PATCH 9/9] Use fixed memory for chapters (dynamic caused crashes) --- BoxTonies.cpp | 7 ++++--- BoxTonies.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/BoxTonies.cpp b/BoxTonies.cpp index e9f7e42..da17ee8 100644 --- a/BoxTonies.cpp +++ b/BoxTonies.cpp @@ -71,8 +71,6 @@ bool BoxTonies::loadTonieByPath(uint8_t* path) { cursor += readBytes; header.audioChapterCount++; } - free(header.audioChapters); - header.audioChapters = new uint32_t[header.audioChapterCount]; cursor = blockStart; //reread for (uint8_t i = 0; i < header.audioChapterCount; i++) { uint32_t chapter = (uint32_t)readVariant(&buffer[cursor], bufferLen-cursor, readBytes); @@ -120,8 +118,11 @@ void BoxTonies::clearHeader() { //header.hash = {0}; //TODO header.audioLength = 0; header.audioId = 0; - free(header.audioChapters); header.audioChapterCount = 0; + for (uint8_t i=0; i<99; i++) { + header.audioChapters[i] = 0; + } + } uint64_t BoxTonies::readVariant(uint8_t* buffer, uint16_t length, uint8_t& readBytes) { diff --git a/BoxTonies.h b/BoxTonies.h index 6af777e..f463565 100644 --- a/BoxTonies.h +++ b/BoxTonies.h @@ -16,7 +16,7 @@ class BoxTonies { uint8_t hash[20]; uint32_t audioLength; //length in bytes uint32_t audioId; //id, which is the unix time stamp of file creation - uint32_t* audioChapters; //Ogg page numbers for Chapters + uint32_t audioChapters[99]; //Ogg page numbers for Chapters uint8_t audioChapterCount; };