diff --git a/icbm.ino b/icbm.ino index 4b1580e5f3de40d1586a04229b7900ef9ee8cf0e..c43b3cf30726d99a9c137b62a6b96d70b63a1de3 100644 --- a/icbm.ino +++ b/icbm.ino @@ -18,6 +18,8 @@ void setup() { start = millis(); poll_port_expander(); + PINS.stage = ""; + PINS.ramping = false; } enum { diff --git a/mpod.cpp b/mpod.cpp index ff68d800014a299bcabc7be7f7862232ba6ca827..04c602f609adf029fe8b1458b82ec24e5505f117 100644 --- a/mpod.cpp +++ b/mpod.cpp @@ -34,7 +34,7 @@ SNMP::Message *MPOD::read(uint16_t channel) { return message; } -// Create an SNMP SETREQUEST message to switch on or off the MPOD +// Create an SNMP SETREQUEST message to switch on or off the specified channel SNMP::Message *MPOD::output(const uint16_t channel, const bool on) { SNMP::Message *message = new SNMP::Message(SNMP::Version::V2C, "guru", SNMP::Type::SetRequest); // In SETREQUEST, use node type and set the value. diff --git a/panel.hpp b/panel.hpp index 1d62bda2e6977738d0995dba0b0b9bdf9fd26d9e..884ba68866b83048f1974c05b4d4f180a06b4507 100644 --- a/panel.hpp +++ b/panel.hpp @@ -1,4 +1,4 @@ -String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) { +String buildPanel(const bool sib, const bool plc, const bool ups, const unsigned long elapsed_secs, const String& status, const bool ramping) { // Shows OK if not triggered (ie bool == false) String page = "<!DOCTYPE html><html lang=\"en\">\n"; page += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"; @@ -38,8 +38,19 @@ String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) { page += "<h3>Last Interrupt: "; page += elapsed_secs; - page += " secs. ago"; - page += "</h3></div></body></html>"; + page += " secs. ago<h3>"; + + page += "<h3>Status: "; + page += status; + page += "</h3>"; + + page += "<div class=\"status-item\">\n"; + page += "<span class=\"status-label\">Ramping:</span>\n"; + if (ramping) { page += "<span class=\"status-value status-error\">Powering Down</span>\n"; } + else { page += "<span class=\"status-value status-ok\">Idle</span>\n"; } + page += "</div>\n"; + + page += "</div></body></html>"; return page; } diff --git a/pins.hpp b/pins.hpp index e07afbf9985fb92c71915765d66f94c4c97388b1..0cd10be8355680ed00f69e82155f5bf4df5fe46f 100644 --- a/pins.hpp +++ b/pins.hpp @@ -21,6 +21,8 @@ struct pins { bool plc; bool ups; int last_triggered; + String stage; + bool ramping; }; extern struct pins PINS; diff --git a/powerproc.hpp b/powerproc.hpp index 859f00bef38b9ede84ddee0d097b84834aa9a817..5f0236ffb95f495a4362a9fdcbffff6785fd664f 100644 --- a/powerproc.hpp +++ b/powerproc.hpp @@ -1,6 +1,8 @@ #pragma once #include <Arduino.h> +#include "pins.hpp" + #define STAGESCOUNT 4 class PowerProcedure { diff --git a/rest.cpp b/rest.cpp index 49cdf4115987cd1a668f90f3cd43e7091e4b5d50..8a5a577febedac0ea4e75109c8366a9c343f7a17 100644 --- a/rest.cpp +++ b/rest.cpp @@ -76,12 +76,20 @@ void identify() { unsigned long elapsed_seconds = (millis() - PINS.last_triggered) / 1000; message += "\"sec_since_interrupt\":"; message += elapsed_seconds; - message += "\n}"; + message += "\n},"; // TODO: Add here power sequence status // is_ramping_down // current step // percentage + message += "\"status\":{\n"; + message += "\"ramping\":"; + message += PINS.ramping; + message += ",\n"; + message += "\"stage\":"; + message += PINS.stage; + message += ",\n"; + message += "\n}"; message += "\n}"; @@ -90,7 +98,8 @@ void identify() { void panel() { unsigned long elapsed_seconds = (millis() - PINS.last_triggered) / 1000; - String content = buildPanel(PINS.sib, PINS.plc, PINS.ups, elapsed_seconds); + String content = + buildPanel(PINS.sib, PINS.plc, PINS.ups, elapsed_seconds, PINS.stage, PINS.ramping); restServer.send(200, "text/html", content); } @@ -231,15 +240,18 @@ void powerAllOff() { } if (success) { + PINS.ramping = true; for (uint8_t groupIdx = pproc.stagesCount - 1; groupIdx >= 0; groupIdx--) { group = pproc.stages[groupIdx].name; groups += group; groups += ","; + PINS.stage = group; success = pproc.powerOff(group); if (!success) { break; } } + PINS.ramping = false; } String http_msg = "{\n";