mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Add Cellmonitor to webserver
This commit is contained in:
parent
4cd5289929
commit
a56ceb50dd
7 changed files with 90 additions and 3 deletions
|
@ -60,6 +60,10 @@ void init_webserver() {
|
|||
server.on("/settings", HTTP_GET,
|
||||
[](AsyncWebServerRequest* request) { request->send_P(200, "text/html", index_html, settings_processor); });
|
||||
|
||||
// Route for going to cellmonitor web page
|
||||
server.on("/cellmonitor", HTTP_GET,
|
||||
[](AsyncWebServerRequest* request) { request->send_P(200, "text/html", index_html, cellmonitor_processor); });
|
||||
|
||||
// Route for editing Wh
|
||||
server.on("/updateBatterySize", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (request->hasParam("value")) {
|
||||
|
@ -547,11 +551,14 @@ String processor(const String& var) {
|
|||
|
||||
content += "<button onclick='goToUpdatePage()'>Perform OTA update</button>";
|
||||
content += " ";
|
||||
content += "<button onclick='goToSettingsPage()'>Change Battery Settings</button>";
|
||||
content += "<button onclick='goToSettingsPage()'>Change Settings</button>";
|
||||
content += " ";
|
||||
content += "<button onclick='goToCellmonitorPage()'>Cellmonitor</button>";
|
||||
content += " ";
|
||||
content += "<button onclick='promptToReboot()'>Reboot Emulator</button>";
|
||||
content += "<script>";
|
||||
content += "function goToUpdatePage() { window.location.href = '/update'; }";
|
||||
content += "function goToCellmonitorPage() { window.location.href = '/cellmonitor'; }";
|
||||
content += "function goToSettingsPage() { window.location.href = '/settings'; }";
|
||||
content +=
|
||||
"function promptToReboot() { if (window.confirm('Are you sure you want to reboot the emulator? NOTE: If "
|
||||
|
@ -810,6 +817,64 @@ String settings_processor(const String& var) {
|
|||
return String();
|
||||
}
|
||||
|
||||
String cellmonitor_processor(const String& var) {
|
||||
if (var == "PLACEHOLDER") {
|
||||
String content = "";
|
||||
// Page format
|
||||
content += "<style>";
|
||||
content += "body { background-color: black; color: white; }";
|
||||
content += ".container { display: flex; flex-wrap: wrap; justify-content: space-around; }";
|
||||
content += ".cell { width: 48%; margin: 1%; padding: 10px; border: 1px solid white; text-align: center; }";
|
||||
content += ".low-voltage { color: red; }"; // Style for low voltage text
|
||||
content += ".voltage-values { margin-bottom: 10px; }"; // Style for voltage values section
|
||||
content += "</style>";
|
||||
|
||||
// Start a new block with a specific background color
|
||||
content += "<div style='background-color: #303E47; padding: 10px; margin-bottom: 10px; border-radius: 50px'>";
|
||||
|
||||
// Display max, min, and deviation voltage values
|
||||
content += "<div class='voltage-values'>";
|
||||
content += "Max Voltage: " + String(cell_max_voltage) + " mV<br>";
|
||||
content += "Min Voltage: " + String(cell_min_voltage) + " mV<br>";
|
||||
int deviation = cell_max_voltage - cell_min_voltage;
|
||||
content += "Voltage Deviation: " + String(deviation) + " mV";
|
||||
content += "</div>";
|
||||
|
||||
// Visualize the populated cells in forward order using flexbox with conditional text color
|
||||
content += "<div class='container'>";
|
||||
for (int i = 0; i < 120; ++i) {
|
||||
// Skip empty values
|
||||
if (cellvoltages[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String cellContent = "Cell " + String(i + 1) + "<br>" + String(cellvoltages[i]) + " mV";
|
||||
|
||||
// Check if the cell voltage is below 3000, apply red color
|
||||
if (cellvoltages[i] < 3000) {
|
||||
cellContent = "<span class='low-voltage'>" + cellContent + "</span>";
|
||||
}
|
||||
|
||||
content += "<div class='cell'>" + cellContent + "</div>";
|
||||
}
|
||||
content += "</div>";
|
||||
|
||||
// Close the block
|
||||
content += "</div>";
|
||||
|
||||
content += "<button onclick='goToMainPage()'>Back to main page</button>";
|
||||
content += "<script>";
|
||||
content += "function goToMainPage() { window.location.href = '/'; }";
|
||||
content += "</script>";
|
||||
return content;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void onOTAStart() {
|
||||
// Log when OTA has started
|
||||
Serial.println("OTA update started!");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue