Compare commits
2 Commits
5cbe653063
...
ae97de4ef0
| Author | SHA1 | Date |
|---|---|---|
|
|
ae97de4ef0 | |
|
|
6ffd4a5a05 |
|
|
@ -6,3 +6,4 @@
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
schema/hannabox/hannabox-backups/
|
schema/hannabox/hannabox-backups/
|
||||||
schema/hannabox/*.lck
|
schema/hannabox/*.lck
|
||||||
|
.copilot
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,15 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
|
|
||||||
<form method="POST" action="/upload" enctype="multipart/form-data"><input type="file" name="data"/><input type="submit" name="upload" value="Upload" title="Upload File"></form>
|
<form method="POST" action="/upload" enctype="multipart/form-data"><input type="file" name="data"/><input type="submit" name="upload" value="Upload" title="Upload File"></form>
|
||||||
|
|
||||||
|
<h2>Edit RFID Mapping</h2>
|
||||||
|
<form id="editMappingForm">
|
||||||
|
<label for="rfid">RFID:</label>
|
||||||
|
<input type="text" id="rfid" name="rfid" required><br>
|
||||||
|
<label for="song">Song:</label>
|
||||||
|
<input type="text" id="song" name="song" required><br>
|
||||||
|
<button type="button" onclick="editMapping()">Update Mapping</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
setInterval(getState, 4000);
|
setInterval(getState, 4000);
|
||||||
setInterval(updateProgress, 500); // Update progress every second
|
setInterval(updateProgress, 500); // Update progress every second
|
||||||
|
|
@ -180,6 +189,20 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function editMapping() {
|
||||||
|
var rfid = document.getElementById('rfid').value;
|
||||||
|
var song = document.getElementById('song').value;
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/edit_mapping", true);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
|
xhr.send("rfid=" + encodeURIComponent(rfid) + "&song=" + encodeURIComponent(song));
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
alert("Mapping updated successfully!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>)rawliteral";
|
</html>)rawliteral";
|
||||||
36
src/main.cpp
36
src/main.cpp
|
|
@ -144,7 +144,7 @@ void deactivateRFID()
|
||||||
String humanReadableSize(const size_t bytes) {
|
String humanReadableSize(const size_t bytes) {
|
||||||
if (bytes < 1024) return String(bytes) + " B";
|
if (bytes < 1024) return String(bytes) + " B";
|
||||||
else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + " KB";
|
else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + " KB";
|
||||||
else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + " MB";
|
else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + " MB";
|
||||||
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB";
|
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,10 +176,11 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
|
||||||
|
|
||||||
uint32_t getBatteryVoltageMv() {
|
uint32_t getBatteryVoltageMv() {
|
||||||
uint32_t voltage = analogReadMilliVolts(BAT_VOLTAGE_PIN);
|
uint32_t voltage = analogReadMilliVolts(BAT_VOLTAGE_PIN);
|
||||||
|
voltage *= 2;//*2 because of the voltage divider.
|
||||||
Serial.print("Battery Voltage: ");
|
Serial.print("Battery Voltage: ");
|
||||||
Serial.println(voltage*2);
|
Serial.println(voltage);
|
||||||
Serial.println(" mV");
|
Serial.println(" mV");
|
||||||
return voltage*2;//*2 because of the voltage divider.
|
return voltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -365,6 +366,33 @@ String getState()
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to save the rfid_map to the mapping file
|
||||||
|
void saveMappingToFile(const char *filename) {
|
||||||
|
File file = SD.open(filename, FILE_WRITE);
|
||||||
|
if (file) {
|
||||||
|
for (const auto &pair : rfid_map) {
|
||||||
|
file.println(pair.first + "=" + pair.second);
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
Serial.println("Mapping saved to file.");
|
||||||
|
} else {
|
||||||
|
Serial.println("Error opening file for writing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to handle edit requests
|
||||||
|
void editMapping(AsyncWebServerRequest *request) {
|
||||||
|
if (request->hasParam("rfid", true) && request->hasParam("song", true)) {
|
||||||
|
String rfid = request->getParam("rfid", true)->value();
|
||||||
|
String song = request->getParam("song", true)->value();
|
||||||
|
rfid_map[rfid] = song;
|
||||||
|
saveMappingToFile(mapping_file.c_str());
|
||||||
|
request->send(200, "text/plain", "Mapping updated");
|
||||||
|
} else {
|
||||||
|
request->send(400, "text/plain", "Invalid parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::map<String, String> readDataFromFile(const char *filename) {
|
std::map<String, String> readDataFromFile(const char *filename) {
|
||||||
|
|
||||||
File file = SD.open(filename);
|
File file = SD.open(filename);
|
||||||
|
|
@ -645,6 +673,8 @@ void setup()
|
||||||
|
|
||||||
server.on("/volume", HTTP_POST, volume_action);
|
server.on("/volume", HTTP_POST, volume_action);
|
||||||
|
|
||||||
|
server.on("/edit_mapping", HTTP_POST, editMapping);
|
||||||
|
|
||||||
// run handleUpload function when any file is uploaded
|
// run handleUpload function when any file is uploaded
|
||||||
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
|
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
request->send(200);
|
request->send(200);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue