Text scroll ping-pong effect
This commit is contained in:
parent
ef6327e2eb
commit
5e78e8e369
@ -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()) {
|
||||
@ -100,22 +108,25 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user