Fix warnings

This commit is contained in:
Tomislav Kopić 2024-11-03 16:15:08 +01:00
parent ee2581b3ef
commit 982321141b

View File

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