Added loop with timeout for version fetch
This commit is contained in:
parent
1107b563d4
commit
ee2581b3ef
@ -160,9 +160,10 @@ void commonButtonHandler() {
|
||||
|
||||
if (rightPressed && (currentMillis - rightPressStart > 2000)) {
|
||||
if (!is_display_off) {
|
||||
beep(1300);
|
||||
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display
|
||||
is_display_off = true;
|
||||
playTune(3); // Play beep sound
|
||||
beep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@ unsigned long api_mtbs = OCTOPRINT_API_REFRESH_INTERVAL;
|
||||
unsigned long api_lasttime = 0;
|
||||
|
||||
bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||
const int maxRetries = 3; // Maximum number of attempts
|
||||
int attempts = 0;
|
||||
|
||||
// Initial display of connecting message with host and port
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
@ -28,9 +32,13 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||
display.print("Port: ");
|
||||
display.print(OCTOPRINT_PORT);
|
||||
display.display();
|
||||
delay(500);
|
||||
|
||||
delay(500); // Delay to allow message display before attempting connection
|
||||
|
||||
// Attempt to connect up to maxRetries times
|
||||
while (attempts < maxRetries) {
|
||||
if (api.getOctoprintVersion()) {
|
||||
// Connection successful; display version information
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
@ -40,9 +48,28 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||
display.setTextSize(2);
|
||||
display.print(api.octoprintVer.octoprintServer);
|
||||
display.display();
|
||||
playTune(2);
|
||||
return true;
|
||||
} else {
|
||||
playTune(2); // Success tune
|
||||
return true; // Exit function, indicating success
|
||||
}
|
||||
|
||||
attempts++; // Increment attempt count
|
||||
|
||||
// If the connection attempt fails, clear the display and show retry status
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.print("Retry ");
|
||||
display.print(attempts);
|
||||
display.print(" of ");
|
||||
display.print(maxRetries);
|
||||
display.setCursor(0, 10);
|
||||
display.print("Failed to connect.");
|
||||
display.display();
|
||||
delay(1000); // Wait before retrying
|
||||
}
|
||||
|
||||
// If all attempts fail, display final failure message
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
@ -51,11 +78,9 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||
display.setCursor(0, 10);
|
||||
display.print("OctoPrint version.");
|
||||
display.display();
|
||||
playTune(3);
|
||||
playTune(3); // Failure tune
|
||||
return false;
|
||||
}
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
int scrollPos = 0; // Global variable to keep track of the scroll position
|
||||
int scrollDirection = 1; // 1 for left, -1 for right
|
||||
|
Loading…
Reference in New Issue
Block a user