Compare commits
No commits in common. "dea19d89d88985b6db0e589140b748f7374498d2" and "d3d74938d30bda923553f71f2516d0fa441e2545" have entirely different histories.
dea19d89d8
...
d3d74938d3
102
src/functions.h
102
src/functions.h
@ -4,9 +4,6 @@
|
|||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
void playTune(int tuneNumber);
|
|
||||||
void beep();
|
|
||||||
|
|
||||||
unsigned long middle_long_press_started = 0;
|
unsigned long middle_long_press_started = 0;
|
||||||
unsigned long right_long_press_started = 0;
|
unsigned long right_long_press_started = 0;
|
||||||
bool is_display_off = false;
|
bool is_display_off = false;
|
||||||
@ -41,9 +38,10 @@ void initSystems() {
|
|||||||
// Connect to WiFi
|
// Connect to WiFi
|
||||||
void connectToWifi() {
|
void connectToWifi() {
|
||||||
|
|
||||||
|
Serial.println("Connecting to WiFi...");
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println("Connecting to WiFi");
|
display.print("Connecting to WiFi...");
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
@ -51,6 +49,7 @@ void connectToWifi() {
|
|||||||
int attemptCount = 0;
|
int attemptCount = 0;
|
||||||
while (WiFi.status() != WL_CONNECTED && attemptCount < 20) { // Timeout after 20 attempts
|
while (WiFi.status() != WL_CONNECTED && attemptCount < 20) { // Timeout after 20 attempts
|
||||||
delay(500);
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
display.print(".");
|
display.print(".");
|
||||||
display.display();
|
display.display();
|
||||||
attemptCount++;
|
attemptCount++;
|
||||||
@ -70,7 +69,6 @@ void connectToWifi() {
|
|||||||
display.print("IP: ");
|
display.print("IP: ");
|
||||||
display.print(WiFi.localIP());
|
display.print(WiFi.localIP());
|
||||||
display.display();
|
display.display();
|
||||||
playTune(2);
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("\nFailed to connect to WiFi.");
|
Serial.println("\nFailed to connect to WiFi.");
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
@ -84,96 +82,32 @@ void connectToWifi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void commonButtonHandler() {
|
void commonButtonHandler() {
|
||||||
|
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
static unsigned long leftPressStart = 0;
|
bool middleLeftPressed = (digitalRead(PIN_BTN_M) == HIGH) && (digitalRead(PIN_BTN_L) == HIGH);
|
||||||
static unsigned long middlePressStart = 0;
|
|
||||||
static unsigned long rightPressStart = 0;
|
|
||||||
|
|
||||||
static bool leftBeeped = false;
|
|
||||||
static bool middleBeeped = false;
|
|
||||||
static bool rightBeeped = false;
|
|
||||||
|
|
||||||
bool leftPressed = (digitalRead(PIN_BTN_L) == HIGH);
|
|
||||||
bool middlePressed = (digitalRead(PIN_BTN_M) == HIGH);
|
|
||||||
bool rightPressed = (digitalRead(PIN_BTN_R) == HIGH);
|
bool rightPressed = (digitalRead(PIN_BTN_R) == HIGH);
|
||||||
|
|
||||||
// Short press detection
|
// Handle middle + left button long press for reset
|
||||||
if (leftPressed) {
|
if (middleLeftPressed) {
|
||||||
if ((currentMillis - leftPressStart > 50)) { // Debounce delay
|
if ((currentMillis - middle_long_press_started) > 2000) {
|
||||||
if (!leftBeeped) {
|
ESP.restart(); // Restart if the buttons are pressed for more than 2 seconds
|
||||||
beep(); // Play beep sound
|
|
||||||
leftBeeped = true; // Set beeped state
|
|
||||||
// Handle left short press action here
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
leftPressStart = currentMillis; // Reset the timer if button is not pressed
|
middle_long_press_started = currentMillis; // Reset timer if the buttons are not pressed
|
||||||
leftBeeped = false; // Reset beeped state
|
|
||||||
}
|
|
||||||
|
|
||||||
if (middlePressed) {
|
|
||||||
if ((currentMillis - middlePressStart > 50)) { // Debounce delay
|
|
||||||
if (!middleBeeped) {
|
|
||||||
beep(); // Play beep sound
|
|
||||||
middleBeeped = true; // Set beeped state
|
|
||||||
// Handle middle short press action here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
middlePressStart = currentMillis; // Reset the timer if button is not pressed
|
|
||||||
middleBeeped = false; // Reset beeped state
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rightPressed) {
|
if (rightPressed) {
|
||||||
if ((currentMillis - rightPressStart > 50)) { // Debounce delay
|
if ((currentMillis - right_long_press_started) > 2000) {
|
||||||
if (!rightBeeped) {
|
|
||||||
beep(); // 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rightPressStart = currentMillis; // Reset the timer if button is not pressed
|
|
||||||
rightBeeped = false; // Reset beeped state
|
|
||||||
}
|
|
||||||
|
|
||||||
// Long press detection
|
|
||||||
if (leftPressed && (currentMillis - leftPressStart > 2000)) {
|
|
||||||
if (!leftBeeped) {
|
|
||||||
beep(); // Play beep sound
|
|
||||||
leftBeeped = true; // Set beeped state
|
|
||||||
// Handle left long press action here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (middlePressed && (currentMillis - middlePressStart > 2000)) {
|
|
||||||
if (!middleBeeped) {
|
|
||||||
beep(); // Play beep sound
|
|
||||||
middleBeeped = true; // Set beeped state
|
|
||||||
// Handle middle long press action here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rightPressed && (currentMillis - rightPressStart > 2000)) {
|
|
||||||
if (!is_display_off) {
|
if (!is_display_off) {
|
||||||
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display
|
display.ssd1306_command(SSD1306_DISPLAYOFF); // Turn off display
|
||||||
is_display_off = true;
|
is_display_off = true;
|
||||||
playTune(3); // Play beep sound
|
}
|
||||||
|
} else if (is_display_off) {
|
||||||
|
display.ssd1306_command(SSD1306_DISPLAYON); // Turn on display
|
||||||
|
is_display_off = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
right_long_press_started = currentMillis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combination of Left and Middle long press
|
|
||||||
if (leftPressed && middlePressed &&
|
|
||||||
(currentMillis - leftPressStart > 2000) &&
|
|
||||||
(currentMillis - middlePressStart > 2000)) {
|
|
||||||
if (!leftBeeped && !middleBeeped) {
|
|
||||||
beep(); // Play beep sound
|
|
||||||
ESP.restart();
|
|
||||||
// Handle left and middle long press action here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,5 +17,4 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
commonButtonHandler();
|
commonButtonHandler();
|
||||||
fetchPrintingStatus(display);
|
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,19 @@
|
|||||||
#include "tunes.h"
|
#include "tunes.h"
|
||||||
|
|
||||||
void playTune(int tuneNumber);
|
void playTune(int tuneNumber);
|
||||||
|
|
||||||
WiFiClient client;
|
WiFiClient client;
|
||||||
|
|
||||||
|
String printerOperational;
|
||||||
|
String printerPaused;
|
||||||
|
String printerPrinting;
|
||||||
|
String printerReady;
|
||||||
|
String printerText;
|
||||||
|
String printerHotend;
|
||||||
|
String printerTarget;
|
||||||
|
String payload;
|
||||||
|
|
||||||
OctoprintApi api(client, OCTOPRINT_HOST, OCTOPRINT_PORT, OCTOPRINT_API_KEY);
|
OctoprintApi api(client, OCTOPRINT_HOST, OCTOPRINT_PORT, OCTOPRINT_API_KEY);
|
||||||
unsigned long api_mtbs = OCTOPRINT_API_REFRESH_INTERVAL;
|
|
||||||
unsigned long api_lasttime = 0;
|
|
||||||
|
|
||||||
bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
@ -19,20 +27,23 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
|||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
display.print("Fetching OctoPrint Version...");
|
display.print("Fetching OctoPrint Version...");
|
||||||
display.display();
|
display.display(); // Show loading message
|
||||||
|
|
||||||
|
// Attempt to fetch the OctoPrint version
|
||||||
if (api.getOctoprintVersion()) {
|
if (api.getOctoprintVersion()) {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
|
|
||||||
display.print("OctoPrint Version:");
|
display.print("OctoPrint Version:");
|
||||||
display.setCursor(0, 10);
|
display.setCursor(0, 10);
|
||||||
display.setTextSize(2);
|
display.setTextSize(2); // Larger text for version
|
||||||
display.print(api.octoprintVer.octoprintServer);
|
display.print(api.octoprintVer.octoprintServer);
|
||||||
display.display();
|
|
||||||
|
display.display(); // Update the display
|
||||||
playTune(2);
|
playTune(2);
|
||||||
return true;
|
return true; // Indicate success
|
||||||
} else {
|
} else {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
@ -42,44 +53,10 @@ bool displayOctoPrintVersion(Adafruit_SSD1306& display) {
|
|||||||
display.setCursor(0, 10);
|
display.setCursor(0, 10);
|
||||||
display.print("OctoPrint version.");
|
display.print("OctoPrint version.");
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
|
// Optionally, add a short delay to show the error
|
||||||
playTune(3);
|
playTune(3);
|
||||||
return false;
|
return false; // Indicate failure
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fetchPrintingStatus(Adafruit_SSD1306& display) {
|
|
||||||
if (millis() - api_lasttime > api_mtbs || api_lasttime == 0) {
|
|
||||||
if (api.getPrinterStatistics()) {
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setCursor(0, 0);
|
|
||||||
display.setTextSize(1);
|
|
||||||
display.setTextColor(WHITE);
|
|
||||||
display.println(api.printerStats.printerState);
|
|
||||||
display.print("Nozzle: ");
|
|
||||||
display.println(api.printerStats.printerTool0TempActual);
|
|
||||||
display.print("Bed: ");
|
|
||||||
display.println(api.printerStats.printerBedTempActual);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
|
|
||||||
const float temp_percent = floor(api.printJob.progressCompletion*100)/100;
|
|
||||||
display.print(temp_percent);
|
|
||||||
display.println("%");
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
@ -44,9 +44,3 @@ void playTune(int tuneIndex) {
|
|||||||
noTone(PIN_BUZZER); // Stop the tone
|
noTone(PIN_BUZZER); // Stop the tone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void beep() {
|
|
||||||
tone(PIN_BUZZER, 1000, 100);
|
|
||||||
delay(100);
|
|
||||||
noTone(PIN_BUZZER);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user