Configure scrolling text
This commit is contained in:
parent
d6f5d2a8ce
commit
ef6327e2eb
@ -168,12 +168,8 @@ void commonButtonHandler() {
|
||||
|
||||
// Combination of Left and Middle long press
|
||||
if (leftPressed && middlePressed &&
|
||||
(currentMillis - leftPressStart > 2000) &&
|
||||
(currentMillis - middlePressStart > 2000)) {
|
||||
if (!leftBeeped && !middleBeeped) {
|
||||
(currentMillis - leftPressStart > 2000) && (currentMillis - middlePressStart > 2000)) {
|
||||
beep(1000); // Play beep sound
|
||||
ESP.restart();
|
||||
// Handle left and middle long press action here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,17 +48,35 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
int scrollPos = 0; // Global variable to keep track of the scroll position
|
||||
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
|
||||
|
||||
bool fetchPrintingStatus(Adafruit_SSD1306& display) {
|
||||
if (millis() - api_lasttime > api_mtbs || api_lasttime == 0 && !is_display_off) {
|
||||
if (api.getPrinterStatistics()) {
|
||||
// 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()) {
|
||||
// Update last fetch time
|
||||
api_lasttime = millis();
|
||||
} else {
|
||||
Serial.println("Failed to fetch printer statistics.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Regardless of whether the fetch was successful, continue with the display updates
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 0);
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
// Display printer state
|
||||
|
||||
// Display lines
|
||||
display.println(api.printerStats.printerState);
|
||||
display.drawLine(0, 10, 127, 10, WHITE);
|
||||
display.drawLine(63, 10, 63, 22, WHITE);
|
||||
display.drawLine(0, 22, 127, 22, WHITE);
|
||||
|
||||
// Display nozzle and bed temperature
|
||||
display.drawBitmap(10, 13, bitmap_nozzle, 8, 8, WHITE);
|
||||
display.setCursor(21, 13);
|
||||
@ -67,7 +85,7 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) {
|
||||
display.setCursor(85, 13);
|
||||
display.print(api.printerStats.printerBedTempActual);
|
||||
|
||||
//Estimated print time if availble in human readable time HH:MM:SS
|
||||
// Estimated print time in HH:MM:SS format
|
||||
int estrunHours = api.printJob.estimatedPrintTime / 3600;
|
||||
int estsecsRemaining = api.printJob.estimatedPrintTime % 3600;
|
||||
int estrunMinutes = estsecsRemaining / 60;
|
||||
@ -77,16 +95,66 @@ bool fetchPrintingStatus(Adafruit_SSD1306& display) {
|
||||
display.setCursor(80, 0);
|
||||
display.println(estbuf);
|
||||
|
||||
// const float temp_percent = floor(api.printJob.progressCompletion*100)/100;
|
||||
// display.print(temp_percent);
|
||||
// display.println("%");
|
||||
// Display and scroll the file name
|
||||
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;
|
||||
|
||||
// Check if it’s time to scroll based on the delay
|
||||
if (millis() - lastScrollTime > scrollDelay) {
|
||||
scrollPos += scrollDirection; // Move the scroll position by the direction
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
lastScrollTime = millis(); // Reset scroll timing
|
||||
}
|
||||
|
||||
// Draw the file name with current scroll position
|
||||
display.setCursor(scrollPos, 27); // Use scrollPos directly
|
||||
display.print(fileName);
|
||||
|
||||
// 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 runMinutes = secsRemaining / 60;
|
||||
int runSeconds = secsRemaining % 60;
|
||||
char buf[31];
|
||||
sprintf(buf, "Time left: %02d:%02d:%02d", runHours, runMinutes, runSeconds);
|
||||
display.setCursor(0, 42);
|
||||
display.println(buf);
|
||||
|
||||
// Progress bar and percentage
|
||||
const float temp_percent = floor(api.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
|
||||
int filledWidth = (temp_percent / 100.0) * barWidth;
|
||||
|
||||
// Draw the progress bar
|
||||
display.drawRect(0, barY, barWidth, barHeight, WHITE); // Outline of the bar
|
||||
display.fillRect(0, barY, filledWidth, barHeight, WHITE); // Filled portion
|
||||
|
||||
// Display centered percentage text in the progress bar
|
||||
char percentText[6];
|
||||
sprintf(percentText, "%.0f%%", temp_percent);
|
||||
int textWidth = strlen(percentText) * 6; // Approximate text width
|
||||
int textX = (barWidth - textWidth) / 2; // Center the text horizontally
|
||||
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.setCursor(textX, textY);
|
||||
display.print(percentText);
|
||||
display.drawLine(0, 38, 127, 38, WHITE);
|
||||
|
||||
display.display();
|
||||
api_lasttime = millis(); // Update the last fetch time
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("Failed to fetch printer statistics.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false; // No fetch was done (within the time interval)
|
||||
|
||||
return true; // Return true to indicate the display was updated
|
||||
}
|
Loading…
Reference in New Issue
Block a user