Skip to content

Commit 2d4351a

Browse files
committed
Display messages
1 parent f2c760d commit 2d4351a

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

firmware/foamer-display/src/main.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
const char *ERROR_COLOR = "D70000";
1010
const int HEADSIGN_WIDTH = 6;
1111
const char *TRANSIT_COLOR = "3ac364";
12+
const char *MESSAGE_COLOR = "FF7B9C"; // Coral pink between peach and hot pink
1213
const int DISPLAY_INTERVAL_MS = 10000; // 10 seconds per page
1314

1415
// Global variables for rotation
1516
int currentRouteIndex = 0;
1617
int totalRoutes = 0;
18+
bool hasMessage = false;
19+
bool messageShown = false;
20+
String currentMessage = "";
1721
JsonDocument globalDoc; // Global to store fetched data
1822
MatrixPanel_I2S_DMA *display; // Pointer to display object
1923

@@ -133,6 +137,17 @@ void displayDirection(MatrixPanel_I2S_DMA *display, JsonObject direction,
133137
display->print("\n");
134138
}
135139

140+
/* Function to display a message on the LED matrix */
141+
void displayMessage(MatrixPanel_I2S_DMA *display, const char *message) {
142+
display->fillScreen(0);
143+
display->setCursor(0, 0);
144+
display->setTextColor(hexToColor565(MESSAGE_COLOR));
145+
display->setTextWrap(true);
146+
display->println(message);
147+
display->setTextWrap(false);
148+
delay(10000);
149+
}
150+
136151
/* Function to display a route on the LED matrix */
137152
void displayRoute(MatrixPanel_I2S_DMA *display, JsonObject route) {
138153
const char *name = route["name"];
@@ -228,29 +243,37 @@ void loop() {
228243
totalRoutes = routes.size();
229244
Serial.print("Total routes: ");
230245
Serial.println(totalRoutes);
231-
}
232246

233-
JsonArray routes = globalDoc["routes"];
247+
// Check if there's a message to display
248+
const char *message = globalDoc["message"];
249+
if (message != nullptr) {
250+
currentMessage = String(message);
251+
Serial.print("Message to display: ");
252+
Serial.println(currentMessage);
253+
displayMessage(display, currentMessage.c_str());
254+
}
255+
}
234256

235257
// Clear screen and reset cursor
236258
display->fillScreen(0);
237259
display->setCursor(0, 0);
238260
display->setTextColor(display->color565(255, 255, 255));
239261

240262
// Display two routes starting from currentRouteIndex
263+
JsonArray routes = globalDoc["routes"];
241264
for (int i = 0; i < 2 && (currentRouteIndex + i) < totalRoutes; i++) {
242265
JsonObject route = routes[currentRouteIndex + i];
243266
displayRoute(display, route);
244267
}
245268

246-
// Wait for display interval
247-
delay(DISPLAY_INTERVAL_MS);
248-
249269
// Move to next pair of routes
250270
currentRouteIndex += 2;
251271

252272
// Loop back to start when we reach the end
253273
if (currentRouteIndex >= totalRoutes) {
254274
currentRouteIndex = 0;
255275
}
276+
277+
// Wait for display interval
278+
delay(DISPLAY_INTERVAL_MS);
256279
}

0 commit comments

Comments
 (0)