diff --git a/src/octoprint.h b/src/octoprint.h index 0c7338f..45c97dc 100644 --- a/src/octoprint.h +++ b/src/octoprint.h @@ -9,9 +9,9 @@ void playTune(int tuneNumber); WiFiClient client; -OctoprintApi api(client, OCTOPRINT_HOST, OCTOPRINT_PORT, OCTOPRINT_API_KEY); -unsigned long api_mtbs = OCTOPRINT_API_REFRESH_INTERVAL; -unsigned long api_lasttime = 0; +OctoprintApi octoprint(client, (const char*)OCTOPRINT_HOST, OCTOPRINT_PORT, OCTOPRINT_API_KEY); +unsigned long octoprint_mtbs = OCTOPRINT_API_REFRESH_INTERVAL; +unsigned long octoprint_lasttime = 0; bool displayOctoPrintVersion(Adafruit_SSD1306& display) { const int maxRetries = 3; // Maximum number of attempts @@ -37,7 +37,7 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) { // Attempt to connect up to maxRetries times while (attempts < maxRetries) { - if (api.getOctoprintVersion()) { + if (octoprint.getOctoprintVersion()) { // Connection successful; display version information display.clearDisplay(); display.setCursor(0, 0); @@ -46,7 +46,7 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) { display.print("OctoPrint Version:"); display.setCursor(0, 10); display.setTextSize(2); - display.print(api.octoprintVer.octoprintServer); + display.print(octoprint.octoprintVer.octoprintServer); display.display(); playTune(2); // Success tune return true; // Exit function, indicating success @@ -66,7 +66,7 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) { display.setCursor(0, 10); display.print("Failed to connect."); display.display(); - delay(1000); // Wait before retrying + delay(5000); // Wait before retrying } // If all attempts fail, display final failure message @@ -88,11 +88,11 @@ unsigned long lastScrollTime = 0; // To control the scroll speed const int scrollDelay = 100; // Delay in milliseconds between scroll updates bool fetchPrintingStatus(Adafruit_SSD1306& display) { - // Fetch printer statistics and update the display every api_mtbs milliseconds - if ((millis() - api_lasttime > api_mtbs || api_lasttime == 0) && !is_display_off) { - if (api.getPrinterStatistics() && api.getPrintJob()) { + // Fetch printer statistics and update the display every octoprint_mtbs milliseconds + if ((millis() - octoprint_lasttime > octoprint_mtbs || octoprint_lasttime == 0) && !is_display_off) { + if (octoprint.getPrinterStatistics() && octoprint.getPrintJob()) { // Update last fetch time - api_lasttime = millis(); + octoprint_lasttime = millis(); } else { Serial.println("Failed to fetch printer statistics."); return false; @@ -106,7 +106,7 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { display.setTextColor(WHITE); // Display lines - display.println(api.printerStats.printerState); + display.println(octoprint.printerStats.printerState); display.drawLine(0, 10, 127, 10, WHITE); display.drawLine(63, 10, 63, 22, WHITE); display.drawLine(0, 22, 127, 22, WHITE); @@ -114,14 +114,14 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { // Display nozzle and bed temperature display.drawBitmap(10, 13, bitmap_nozzle, 8, 8, WHITE); display.setCursor(21, 13); - display.print(api.printerStats.printerTool0TempActual); + display.print(octoprint.printerStats.printerTool0TempActual); display.drawBitmap(74, 13, bitmap_bed, 8, 8, WHITE); display.setCursor(85, 13); - display.print(api.printerStats.printerBedTempActual); + display.print(octoprint.printerStats.printerBedTempActual); // Estimated print time in HH:MM:SS format - int estrunHours = api.printJob.estimatedPrintTime / 3600; - int estsecsRemaining = api.printJob.estimatedPrintTime % 3600; + int estrunHours = octoprint.printJob.estimatedPrintTime / 3600; + int estsecsRemaining = octoprint.printJob.estimatedPrintTime % 3600; int estrunMinutes = estsecsRemaining / 60; int estrunSeconds = estsecsRemaining % 60; char estbuf[31]; @@ -130,7 +130,7 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { display.println(estbuf); // Display and scroll the file name - const char* fileName = api.printJob.jobFileName.c_str(); // Convert to const char* + const char* fileName = octoprint.printJob.jobFileName.c_str(); // Convert to const char* int fileNameWidth = strlen(fileName) * 6; // Approximate width of the file name in pixels int displayWidth = 127; @@ -158,8 +158,8 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { // Clear the area for "Time left" display before printing display.fillRect(0, 35, displayWidth, 9, BLACK); // Clear area for "Time left" // Print time left in HH:MM:SS - int runHours = api.printJob.progressPrintTimeLeft / 3600; - int secsRemaining = api.printJob.progressPrintTimeLeft % 3600; + int runHours = octoprint.printJob.progressPrintTimeLeft / 3600; + int secsRemaining = octoprint.printJob.progressPrintTimeLeft % 3600; int runMinutes = secsRemaining / 60; int runSeconds = secsRemaining % 60; char buf[31]; @@ -168,7 +168,7 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { display.println(buf); // Progress bar and percentage - const float temp_percent = floor(api.printJob.progressCompletion * 100) / 100; + const float temp_percent = floor(octoprint.printJob.progressCompletion * 100) / 100; int barY = 52; // Position just above the bottom of a 64-pixel-high display int barWidth = 127; // Full width of the display int barHeight = 12; // Set the height of the progress bar to 12 pixels @@ -194,4 +194,4 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { display.display(); return true; // Return true to indicate the display was updated -} \ No newline at end of file +}