Disabled api fetching if display off

This commit is contained in:
Tomislav Kopić 2024-11-01 21:33:24 +01:00
parent 7b67633bc9
commit d6f5d2a8ce
3 changed files with 25 additions and 22 deletions

View File

@ -5,7 +5,7 @@
#include <ESP8266WiFi.h>
void playTune(int tuneNumber);
void beep();
void beep(int buzz);
unsigned long middle_long_press_started = 0;
unsigned long right_long_press_started = 0;
@ -70,7 +70,7 @@ void connectToWifi() {
display.print("IP: ");
display.print(WiFi.localIP());
display.display();
playTune(2);
beep(800);
} else {
Serial.println("\nFailed to connect to WiFi.");
display.clearDisplay();
@ -101,7 +101,7 @@ void commonButtonHandler() {
if (leftPressed) {
if ((currentMillis - leftPressStart > 50)) { // Debounce delay
if (!leftBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
leftBeeped = true; // Set beeped state
// Handle left short press action here
}
@ -114,7 +114,7 @@ void commonButtonHandler() {
if (middlePressed) {
if ((currentMillis - middlePressStart > 50)) { // Debounce delay
if (!middleBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
middleBeeped = true; // Set beeped state
// Handle middle short press action here
}
@ -127,12 +127,12 @@ void commonButtonHandler() {
if (rightPressed) {
if ((currentMillis - rightPressStart > 50)) { // Debounce delay
if (!rightBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
rightBeeped = true; // Set beeped state
if (is_display_off) {
display.ssd1306_command(SSD1306_DISPLAYON); // Turn on display
is_display_off = false;
beep();
beep(1300);
}
}
}
@ -144,7 +144,7 @@ void commonButtonHandler() {
// Long press detection
if (leftPressed && (currentMillis - leftPressStart > 2000)) {
if (!leftBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
leftBeeped = true; // Set beeped state
// Handle left long press action here
}
@ -152,7 +152,7 @@ void commonButtonHandler() {
if (middlePressed && (currentMillis - middlePressStart > 2000)) {
if (!middleBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
middleBeeped = true; // Set beeped state
// Handle middle long press action here
}
@ -171,7 +171,7 @@ void commonButtonHandler() {
(currentMillis - leftPressStart > 2000) &&
(currentMillis - middlePressStart > 2000)) {
if (!leftBeeped && !middleBeeped) {
beep(); // Play beep sound
beep(1000); // Play beep sound
ESP.restart();
// Handle left and middle long press action here
}

View File

@ -49,30 +49,33 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
}
bool fetchPrintingStatus(Adafruit_SSD1306& display) {
if (millis() - api_lasttime > api_mtbs || api_lasttime == 0) {
if (millis() - api_lasttime > api_mtbs || api_lasttime == 0 && !is_display_off) {
if (api.getPrinterStatistics()) {
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(1);
display.setTextColor(WHITE);
// Display printer state
display.println(api.printerStats.printerState);
display.drawLine(0,10,127,10,WHITE);
display.drawLine(63,10,63,22,WHITE);
// Display nozzle and bed temperature
display.drawBitmap(10, 13, bitmap_nozzle, 8, 8, WHITE);
display.setCursor(21, 13);
display.print(api.printerStats.printerTool0TempActual);
display.drawBitmap(74, 13, bitmap_bed, 8, 8, WHITE);
display.setCursor(84, 13);
display.setCursor(85, 13);
display.print(api.printerStats.printerBedTempActual);
display.setCursor(0, 15);
// //Print time left (if printing) in human readable time 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,"%02d:%02d:%02d",runHours,runMinutes,runSeconds);
// display.println(buf);
//Estimated print time if availble in human readable time HH:MM:SS
int estrunHours= api.printJob.estimatedPrintTime/3600;
int estsecsRemaining=api.printJob.estimatedPrintTime%3600;
int estrunMinutes=estsecsRemaining/60;
int estrunSeconds=estsecsRemaining%60;
char estbuf[31];
sprintf(estbuf,"%02d:%02d:%02d",estrunHours,estrunMinutes,estrunSeconds);
display.setCursor(80, 0);
display.println(estbuf);
// const float temp_percent = floor(api.printJob.progressCompletion*100)/100;
// display.print(temp_percent);

View File

@ -45,8 +45,8 @@ void playTune(int tuneIndex) {
}
}
void beep() {
tone(PIN_BUZZER, 1000, 100);
void beep(int buzz) {
tone(PIN_BUZZER, buzz, 100);
delay(100);
noTone(PIN_BUZZER);
}