diff --git a/src/octoprint.h b/src/octoprint.h index 873c671..8a3d962 100644 --- a/src/octoprint.h +++ b/src/octoprint.h @@ -18,7 +18,15 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) { display.setCursor(0, 0); display.setTextSize(1); display.setTextColor(WHITE); - display.print("Fetching OctoPrint Version..."); + display.print("Connecting to"); + display.setCursor(0, 10); + display.print("OctoPrint"); + display.setCursor(0, 20); + display.print("Host: "); + display.print(OCTOPRINT_HOST); + display.setCursor(0, 30); + display.print("Port: "); + display.print(OCTOPRINT_PORT); display.display(); if (api.getOctoprintVersion()) { @@ -49,7 +57,7 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) { } int scrollPos = 0; // Global variable to keep track of the scroll position -int scrollDirection = 1; // 1 for left, -1 for right +int scrollDirection = 1; // 1 for left, -1 for right unsigned long lastScrollTime = 0; // To control the scroll speed const int scrollDelay = 100; // Delay in milliseconds between scroll updates @@ -99,23 +107,26 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { const char* fileName = api.printJob.jobFileName.c_str(); // Convert to const char* int fileNameWidth = strlen(fileName) * 6; // Approximate width of the file name in pixels int displayWidth = 127; - + + // Clear the area for the file name to avoid overlap + display.fillRect(0, 26, displayWidth, 11, BLACK); + // Check if it’s time to scroll based on the delay if (millis() - lastScrollTime > scrollDelay) { - scrollPos += scrollDirection; // Move the scroll position by the direction + // Update scroll position based on the current direction + scrollPos += scrollDirection; + lastScrollTime = millis(); - // Check bounds to reverse direction - if (scrollPos < -fileNameWidth) { // If it scrolled past left - scrollDirection = 1; // Change direction to right - } else if (scrollPos > displayWidth) { // If it scrolled past right - scrollDirection = -1; // Change direction to left + // Reverse direction if the text reaches either edge + if (scrollPos > 0) { // Reached the left edge + scrollDirection = -1; // Start moving left + } else if (scrollPos < -fileNameWidth + displayWidth) { // Reached the right edge + scrollDirection = 1; // Start moving right } - - lastScrollTime = millis(); // Reset scroll timing } // Draw the file name with current scroll position - display.setCursor(scrollPos, 27); // Use scrollPos directly + display.setCursor(scrollPos, 27); display.print(fileName); // Clear the area for "Time left" display before printing @@ -149,7 +160,7 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) { int textY = barY + (barHeight - 8) / 2; // Center the text vertically within the bar // Clear the area for text and print centered percentage - display.fillRect(textX - 1, textY, textWidth + 2, 8, BLACK); + display.fillRect(textX - 1, textY -1, textWidth + 2, 10, BLACK); display.setCursor(textX, textY); display.print(percentText); display.drawLine(0, 38, 127, 38, WHITE);