From ec5610c91903e7d9070512780d47463941fe7a2c Mon Sep 17 00:00:00 2001 From: Stefan Ostermann Date: Fri, 28 Mar 2025 23:46:11 +0100 Subject: [PATCH] delete, move files --- .gitignore | 2 ++ README.md | 4 ++++ src/main.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index c0b392f..2d52016 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ schema/hannabox/hannabox-backups/ schema/hannabox/*.lck .copilot + +.codegpt \ No newline at end of file diff --git a/README.md b/README.md index 192a252..7123a28 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,9 @@ Chip to use: MCP73837? ### Amplifier +The Chip is a MAX98357 Class D Amp. +Pin 1 is on the lower left side, seen from the letters in correct orientation. + #### SD / MODE This pin is used for shutdown mode but is also used for setting which channel is output. It's a little confusing but essentially: @@ -133,6 +136,7 @@ This is compounded by an internal 100K pulldown resistor on SD so you need to us For the breakout board, there's a 1Mohm resistor from SD to Vin which, when powering from 5V will give you the 'stereo average' output. If you want left or right channel only, or if you are powering from non-5V power, you may need to experiment with different resistors to get the desired voltage on SD + ![](images/amp.png) ## Links diff --git a/src/main.cpp b/src/main.cpp index 432dd0f..ce7076f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,6 +174,33 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, } } +void handleMoveFile(AsyncWebServerRequest *request) { + String from = request->arg("from"); + String to = request->arg("to"); + + if (SD.exists(from)) { + SD.rename(from.c_str(), to.c_str()); + Serial.println("Moved file: " + from + " to " + to); + request->send(200, "text/plain", "File moved successfully."); + } else { + Serial.println("File not found: " + from); + request->send(404, "text/plain", "File not found."); + } +} + +void handleDeleteFile(AsyncWebServerRequest *request) { + String filename = request->arg("filename"); + + if (SD.exists(filename)) { + SD.remove(filename.c_str()); + Serial.println("Deleted file: " + filename); + request->send(200, "text/plain", "File deleted successfully."); + } else { + Serial.println("File not found: " + filename); + request->send(404, "text/plain", "File not found."); + } +} + uint32_t getBatteryVoltageMv() { uint32_t voltage = analogReadMilliVolts(BAT_VOLTAGE_PIN); voltage *= 2;//*2 because of the voltage divider. @@ -680,6 +707,9 @@ void setup() request->send(200); }, handleUpload); + server.on("/move_file", HTTP_GET, handleMoveFile); + server.on("/delete_file", HTTP_GET, handleDeleteFile); + server.begin(); Serial.println("Wifi initialized."); } else {