mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Add feature to clear events
This commit is contained in:
parent
1a4d5a73f3
commit
a2efc21642
4 changed files with 38 additions and 6 deletions
|
@ -236,6 +236,18 @@ void clear_event(EVENTS_ENUM_TYPE event) {
|
|||
}
|
||||
}
|
||||
|
||||
void reset_all_events() {
|
||||
events.nof_logged_events = 0;
|
||||
for (uint16_t i = 0; i < EVENT_NOF_EVENTS; i++) {
|
||||
events.entries[i].data = 0;
|
||||
events.entries[i].timestamp = 0;
|
||||
events.entries[i].millisrolloverCount = 0;
|
||||
events.entries[i].occurences = 0;
|
||||
events.entries[i].log = true;
|
||||
events.entries[i].MQTTpublished = false; // Not published by default
|
||||
}
|
||||
}
|
||||
|
||||
void set_event_MQTTpublished(EVENTS_ENUM_TYPE event) {
|
||||
events.entries[event].MQTTpublished = true;
|
||||
}
|
||||
|
|
|
@ -152,6 +152,7 @@ void init_events(void);
|
|||
void set_event_latched(EVENTS_ENUM_TYPE event, uint8_t data);
|
||||
void set_event(EVENTS_ENUM_TYPE event, uint8_t data);
|
||||
void clear_event(EVENTS_ENUM_TYPE event);
|
||||
void reset_all_events();
|
||||
void set_event_MQTTpublished(EVENTS_ENUM_TYPE event);
|
||||
|
||||
const EVENTS_STRUCT_TYPE* get_event_pointer(EVENTS_ENUM_TYPE event);
|
||||
|
|
|
@ -5,10 +5,9 @@ const char EVENTS_HTML_START[] = R"=====(
|
|||
)=====";
|
||||
const char EVENTS_HTML_END[] = R"=====(
|
||||
</div></div>
|
||||
<button onclick='clear()'>Clear all events</button>
|
||||
<button onclick='home()'>Back to main page</button>
|
||||
<style>.event:nth-child(even){background-color:#455a64}.event:nth-child(odd){background-color:#394b52}</style>
|
||||
<script>function showEvent(){document.querySelectorAll(".event").forEach(function(e){var n=e.querySelector(".sec-ago");n&&(n.innerText=new Date(Date.now()-((+n.innerText.split(';')[0])*4294967296+ +n.innerText.split(';')[1])).toLocaleString());})}function home(){window.location.href="/"}window.onload=function(){showEvent()}</script>
|
||||
<button onclick="askClear()">Clear all events</button>
|
||||
<button onclick="home()">Back to main page</button>
|
||||
<style>.event:nth-child(even){background-color:#455a64}.event:nth-child(odd){background-color:#394b52}</style><script>function showEvent(){document.querySelectorAll(".event").forEach(function(e){var n=e.querySelector(".sec-ago");n&&(n.innerText=new Date(Date.now()-(4294967296*+n.innerText.split(";")[0]+ +n.innerText.split(";")[1])).toLocaleString())})}function askClear(){window.confirm("Are you sure you want to clear all events?")&&(window.location.href="/clearevents")}function home(){window.location.href="/"}window.onload=function(){showEvent()}</script>
|
||||
)=====";
|
||||
|
||||
static std::vector<EventData> order_events;
|
||||
|
@ -64,7 +63,7 @@ String events_processor(const String& var) {
|
|||
}
|
||||
|
||||
/* Script for displaying event log before it gets minified
|
||||
<button onclick="clear()">Clear all events</button>
|
||||
<button onclick="askClear()">Clear all events</button>
|
||||
<button onclick="home()">Back to main page</button>
|
||||
<style>
|
||||
.event:nth-child(even) {
|
||||
|
@ -81,6 +80,11 @@ String events_processor(const String& var) {
|
|||
n && (n.innerText = new Date(Date.now() - (+n.innerText.split(";")[0] * 4294967296 + +n.innerText.split(";")[1])).toLocaleString());
|
||||
});
|
||||
}
|
||||
function askClear() {
|
||||
if (window.confirm('Are you sure you want to clear all events?')) {
|
||||
window.location.href = '/clearevents';
|
||||
}
|
||||
}
|
||||
function home() {
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
|
|
@ -63,6 +63,18 @@ void init_webserver() {
|
|||
request->send_P(200, "text/html", index_html, events_processor);
|
||||
});
|
||||
|
||||
// Route for clearing all events
|
||||
server.on("/clearevents", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password))
|
||||
return request->requestAuthentication();
|
||||
reset_all_events();
|
||||
// Send back a response that includes an instant redirect to /events
|
||||
String response = "<html><body>";
|
||||
response += "<script>window.location.href = '/events';</script>"; // Instant redirect
|
||||
response += "</body></html>";
|
||||
request->send(200, "text/html", response);
|
||||
});
|
||||
|
||||
// Route for editing SSID
|
||||
server.on("/updateSSID", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password))
|
||||
|
@ -499,6 +511,9 @@ String processor(const String& var) {
|
|||
#ifdef NISSAN_LEAF_BATTERY
|
||||
content += "Nissan LEAF";
|
||||
#endif // NISSAN_LEAF_BATTERY
|
||||
#ifdef PYLON_BATTERY
|
||||
content += "Pylon compatible battery";
|
||||
#endif // PYLON_BATTERY
|
||||
#ifdef RJXZS_BMS
|
||||
content += "RJXZS BMS, DIY battery";
|
||||
#endif // RJXZS_BMS
|
||||
|
@ -810,7 +825,7 @@ String processor(const String& var) {
|
|||
content += "<button onclick='PauseBattery(false)'>Resume Battery</button>";
|
||||
else
|
||||
content += "<button onclick='PauseBattery(true)'>Pause Battery</button>";
|
||||
|
||||
content += " ";
|
||||
content += "<button onclick='OTA()'>Perform OTA update</button>";
|
||||
content += " ";
|
||||
content += "<button onclick='Settings()'>Change Settings</button>";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue