77#include < esp_task_wdt.h>
88#include " config.h"
99
10- // Der Trick: Nur includen, wenn die Datei wirklich physisch da ist
10+ /* *
11+ * @brief Include secrets only if the file physically exists.
12+ */
1113#if __has_include("secret.h")
1214 #include " secret.h"
1315 #define HAS_SECRET_FILE
1416#endif
1517
16- // 2. WiFi Logik: Fallback auf CI-Flags, falls Makros nicht durch secret.h definiert wurden
18+ /* *
19+ * @brief WiFi logic: Fallback to CI flags if macros are not defined via secret.h.
20+ */
1721#ifndef SECRET_SSID
1822 #define SECRET_SSID WIFI_SSID_ENV
1923#endif
2024#ifndef SECRET_PASS
2125 #define SECRET_PASS WIFI_PASS_ENV
2226#endif
2327
24- // 3. API Key Logik
28+ /* *
29+ * @brief API Key logic: Fallback to CI flags.
30+ */
2531#ifndef SECRET_API
2632 #define SECRET_API PRINTER_API_KEY
2733#endif
2834
29- // Zuweisung der finalen Variablen (NUR EINMAL definieren !)
35+ // Assignment of final variables (define ONLY ONCE !)
3036const char * ssid = SECRET_SSID;
3137const char * password = SECRET_PASS;
3238const char * octoprint_apikey = SECRET_API;
33- const char * ip_address = PRINTER_IP; // Kommt direkt aus der platformio.ini
39+ const char * ip_address = PRINTER_IP; // Sourced directly from platformio.ini
3440const int octoprint_httpPort = 5000 ;
3541
36- // --- Konfiguration ---
42+ // --- Configuration ---
3743#define HEIGHT 32
3844#define WIDTH 64
3945#define MAX_FPS 45
@@ -44,7 +50,7 @@ uint8_t clockPin = 2;
4450uint8_t latchPin = 47 ;
4551uint8_t oePin = 14 ;
4652
47- // --- Funktionsprototypen (Vollständig) ---
53+ // --- Function Prototypes ---
4854void connectToWiFi ();
4955void reconnectWiFi ();
5056void displayWiFiOffline ();
@@ -66,15 +72,18 @@ Adafruit_Protomatter matrix(
6672unsigned long lastRequestTime = 0 ;
6773const unsigned long requestInterval = 5000 ;
6874
75+ /* *
76+ * @brief Initializes serial communication, WiFi, LED matrix, and the OctoPrint API client.
77+ */
6978void setup () {
7079 Serial.begin (115200 );
71- // wait for USB debug
80+ // Wait for USB debug connection
7281 delay (3000 );
7382
7483 ip.fromString (ip_address);
7584 api = new OctoprintApi (client, ip, octoprint_httpPort, octoprint_apikey);
7685
77- // Watchdog Setup für ESP32
86+ // Watchdog setup for ESP32
7887 esp_task_wdt_init (5 , true );
7988 esp_task_wdt_add (NULL );
8089
@@ -84,6 +93,9 @@ void setup() {
8493 connectToWiFi ();
8594}
8695
96+ /* *
97+ * @brief Main loop handling Watchdog reset, WiFi reconnection, and periodic API polling.
98+ */
8799void loop () {
88100 esp_task_wdt_reset ();
89101
@@ -96,13 +108,13 @@ void loop() {
96108 if (currentMillis - lastRequestTime >= requestInterval) {
97109 lastRequestTime = currentMillis;
98110
99- // 1. Drucker-Status abrufen
111+ // 1. Retrieve printer status
100112 if (api->getPrinterStatistics ()) {
101113 int temp_T0 = scaleFloatToInteger (api->printerStats .printerTool0TempActual );
102114 int temp_T1 = scaleFloatToInteger (api->printerStats .printerBedTempActual );
103115
104116 if (api->printerStats .printerStatePrinting ) {
105- // 2. Job-Daten abrufen (Name bei chunkysteveo: getPrintJob)
117+ // 2. Retrieve job data (endpoint in chunkysteveo library : getPrintJob)
106118 if (api->getPrintJob ()) {
107119 displayPrinterPrinting (
108120 api->printJob .estimatedPrintTime ,
@@ -116,38 +128,52 @@ void loop() {
116128 printOctoprintDebug ();
117129 } else {
118130 displayOctoprintOffline ();
119- Serial.println (" OctoPrint API nicht erreichbar ." );
131+ Serial.println (" OctoPrint API unreachable ." );
120132 }
121133 }
122134}
123135
124- // --- Hilfsfunktionen ---
136+ // --- Helper Functions ---
125137
138+ /* *
139+ * @brief Connects to the configured WiFi network and blocks until connected.
140+ */
126141void connectToWiFi () {
127- Serial.print (" Verbinde mit WiFi: " );
142+ Serial.print (" Connecting to WiFi: " );
128143 Serial.println (SECRET_SSID);
129144 WiFi.begin (SECRET_SSID, SECRET_PASS);
130145
131146 while (WiFi.status () != WL_CONNECTED) {
132147 delay (500 );
133148 Serial.print (" ." );
134149 }
135- Serial.println (" \n WiFi verbunden !" );
150+ Serial.println (" \n WiFi connected !" );
136151}
137152
153+ /* *
154+ * @brief Disconnects and attempts to reconnect to the WiFi network.
155+ */
138156void reconnectWiFi () {
139157 displayWiFiOffline ();
140158 WiFi.disconnect ();
141159 WiFi.begin (SECRET_SSID, SECRET_PASS);
142160 delay (2000 );
143161}
144162
163+ /* *
164+ * @brief Scales and rounds a float value to the nearest integer.
165+ * @param value The float value to be scaled.
166+ * @return The rounded integer value.
167+ */
145168int scaleFloatToInteger (float value) {
146169 return (int )(value + 0 .5f );
147170}
148171
149- // --- Grafik-Funktionen ---
172+ // --- Graphic Functions ---
150173
174+ /* *
175+ * @brief Displays a "NO WIFI" error message on the LED matrix.
176+ */
151177void displayWiFiOffline () {
152178 matrix.fillScreen (0 );
153179 matrix.setCursor (2 , 10 );
@@ -156,6 +182,9 @@ void displayWiFiOffline() {
156182 matrix.show ();
157183}
158184
185+ /* *
186+ * @brief Displays a "NO API" error message on the LED matrix.
187+ */
159188void displayOctoprintOffline () {
160189 matrix.fillScreen (0 );
161190 matrix.setCursor (2 , 10 );
@@ -164,6 +193,11 @@ void displayOctoprintOffline() {
164193 matrix.show ();
165194}
166195
196+ /* *
197+ * @brief Displays the "READY" state along with tool and bed temperatures.
198+ * @param temp_T0 Current temperature of Tool 0.
199+ * @param temp_T1 Current temperature of the Bed.
200+ */
167201void displayPrinterReady (int temp_T0, int temp_T1) {
168202 matrix.fillScreen (0 );
169203 matrix.setCursor (2 , 2 );
@@ -176,32 +210,41 @@ void displayPrinterReady(int temp_T0, int temp_T1) {
176210 matrix.show ();
177211}
178212
213+ /* *
214+ * @brief Displays the current printing progress, estimated time left, and temperatures.
215+ * @param seconds Estimated print time remaining in seconds.
216+ * @param progress Print progress percentage.
217+ * @param temp_T0 Current temperature of Tool 0.
218+ * @param temp_T1 Current temperature of the Bed.
219+ */
179220void displayPrinterPrinting (int seconds, float progress, int temp_T0, int temp_T1) {
180221 matrix.fillScreen (0 );
181222
182- // Progress in Blau
223+ // Progress in blue
183224 matrix.setCursor (2 , 2 );
184225 matrix.setTextColor (matrix.color565 (0 , 0 , 255 ));
185226 matrix.printf (" %.1f%%" , progress);
186227
187- // Zeit in Weiß
228+ // Time in white
188229 int h = seconds / 3600 ;
189230 int m = (seconds % 3600 ) / 60 ;
190231 matrix.setCursor (2 , 12 );
191232 matrix.setTextColor (0xFFFF );
192233 matrix.printf (" %02dh %02dm" , h, m);
193234
194- // Temperaturen unten
235+ // Temperatures at the bottom
195236 matrix.setCursor (2 , 22 );
196237 matrix.setTextColor (matrix.color565 (150 , 150 , 150 ));
197238 matrix.printf (" T:%d B:%d" , temp_T0, temp_T1);
198239
199240 matrix.show ();
200241}
201242
202- // --- Vollständige Debug-Ausgabe aus deinem Original ---
243+ /* *
244+ * @brief Prints detailed OctoPrint status and job information to the serial monitor.
245+ */
203246void printOctoprintDebug () {
204- // Hier nutzen wir die Namen der chunkysteveo Library
247+ // Using the variable names from the chunkysteveo library
205248 Serial.println (" \n ---------States---------" );
206249 Serial.print (" State: " ); Serial.println (api->printerStats .printerState );
207250 Serial.print (" Printing: " ); Serial.println (api->printerStats .printerStatePrinting );
0 commit comments