Testing
This commit is contained in:
parent
2da3ff1019
commit
6ff3352c57
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"string": "cpp"
|
||||||
|
}
|
||||||
|
}
|
66
src/main.cpp
66
src/main.cpp
@ -17,6 +17,7 @@ const unsigned long displayInterval = 100; // 100 ms
|
|||||||
|
|
||||||
String lastEventId = "";
|
String lastEventId = "";
|
||||||
String problems[10];
|
String problems[10];
|
||||||
|
String problemDescriptions;
|
||||||
int problemCount = 0;
|
int problemCount = 0;
|
||||||
int severityCounts[5] = {0};
|
int severityCounts[5] = {0};
|
||||||
bool newProblemsDetected = false;
|
bool newProblemsDetected = false;
|
||||||
@ -48,6 +49,8 @@ void initSystems() {
|
|||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int totalProblems = 0; // Variable to store the total number of active problems
|
||||||
|
|
||||||
void fetchActiveProblems() {
|
void fetchActiveProblems() {
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
@ -55,7 +58,7 @@ void fetchActiveProblems() {
|
|||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
// JSON payload
|
// JSON payload
|
||||||
DynamicJsonDocument doc(512);
|
DynamicJsonDocument doc(1024);
|
||||||
doc["jsonrpc"] = "2.0";
|
doc["jsonrpc"] = "2.0";
|
||||||
doc["method"] = "problem.get";
|
doc["method"] = "problem.get";
|
||||||
doc["id"] = 1;
|
doc["id"] = 1;
|
||||||
@ -83,6 +86,8 @@ void fetchActiveProblems() {
|
|||||||
int newProblemCount = 0;
|
int newProblemCount = 0;
|
||||||
memset(severityCounts, 0, sizeof(severityCounts)); // Reset severities
|
memset(severityCounts, 0, sizeof(severityCounts)); // Reset severities
|
||||||
|
|
||||||
|
totalProblems = result.size(); // Set total problems count
|
||||||
|
|
||||||
for (JsonObject problem : result) {
|
for (JsonObject problem : result) {
|
||||||
String eventId = problem["eventid"].as<String>();
|
String eventId = problem["eventid"].as<String>();
|
||||||
int severity = problem["severity"].as<int>();
|
int severity = problem["severity"].as<int>();
|
||||||
@ -104,6 +109,7 @@ void fetchActiveProblems() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newProblemCount++;
|
newProblemCount++;
|
||||||
|
problemDescriptions += description;
|
||||||
}
|
}
|
||||||
|
|
||||||
problemCount = newProblemCount;
|
problemCount = newProblemCount;
|
||||||
@ -119,49 +125,39 @@ void fetchActiveProblems() {
|
|||||||
http.end();
|
http.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int scrollPos = SCREEN_WIDTH; // Global variable to keep track of the scroll position
|
||||||
|
unsigned long lastScrollTime = 0; // To control the scroll speed
|
||||||
|
const int scrollDelay = 150; // Delay in milliseconds between scroll updates
|
||||||
|
|
||||||
void displayProblems() {
|
void displayProblems() {
|
||||||
static int scrollPos = SCREEN_WIDTH;
|
|
||||||
static unsigned long lastScrollTime = 0;
|
|
||||||
|
|
||||||
if (millis() - lastDisplayUpdate < displayInterval) {
|
|
||||||
return; // Skip rendering if the display interval hasn't elapsed
|
|
||||||
}
|
|
||||||
lastDisplayUpdate = millis();
|
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
||||||
// Header
|
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0,0);
|
||||||
display.print("Problems: ");
|
display.print("Total Problems: ");
|
||||||
display.print(problemCount);
|
display.print(totalProblems); // Display total problems
|
||||||
|
|
||||||
// Display severity counts (S0 to S4)
|
int stateWidth = strlen(problemDescriptions.c_str()) * 12; // Approximate width of the status text in pixels
|
||||||
for (int i = 0; i < 5; i++) {
|
// Scroll the text to the left
|
||||||
display.setCursor(0, 10 + (i * 10));
|
if (!is_display_off) {
|
||||||
display.printf("S%d: %d", i, severityCounts[i]);
|
if (millis() - lastScrollTime > scrollDelay) {
|
||||||
}
|
// Update scroll position
|
||||||
|
scrollPos -= 11; // Move left by 1 pixel each time
|
||||||
|
|
||||||
// Scrolling description of the first problem
|
lastScrollTime = millis();
|
||||||
if (problemCount > 0) {
|
|
||||||
String problemText = problems[0];
|
|
||||||
int16_t x1, y1;
|
|
||||||
uint16_t textWidth, textHeight;
|
|
||||||
display.getTextBounds(problemText, 0, 55, &x1, &y1, &textWidth, &textHeight);
|
|
||||||
|
|
||||||
if (millis() - lastScrollTime > 100) {
|
// If the text has completely scrolled off, reset scroll position to start from the right
|
||||||
scrollPos -= 2;
|
if (scrollPos < -stateWidth) {
|
||||||
if (scrollPos < -textWidth) {
|
|
||||||
scrollPos = SCREEN_WIDTH;
|
scrollPos = SCREEN_WIDTH;
|
||||||
}
|
}
|
||||||
lastScrollTime = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display.setTextSize(1);
|
|
||||||
display.setCursor(scrollPos, 55);
|
|
||||||
display.print(problemText);
|
|
||||||
}
|
}
|
||||||
|
// Draw the file name with current scroll position
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setCursor(scrollPos, 54);
|
||||||
|
display.print(problemDescriptions);
|
||||||
|
display.setCursor(0, 44);
|
||||||
|
display.setTextSize(1);
|
||||||
|
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +171,7 @@ void loop() {
|
|||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
cubeButtonHandler();
|
cubeButtonHandler();
|
||||||
|
|
||||||
if (currentMillis - lastRefresh >= refreshInterval) {
|
if (!is_display_off && currentMillis - lastRefresh >= refreshInterval) {
|
||||||
lastRefresh = currentMillis;
|
lastRefresh = currentMillis;
|
||||||
fetchActiveProblems();
|
fetchActiveProblems();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user