Change back to klipper connect screen when connection to klipper gets severed

This commit is contained in:
suchmememanyskill
2023-12-11 22:23:18 +01:00
parent f2d232d9eb
commit 7a430f81c5
5 changed files with 18 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ const char *printer_state_messages[] = {
"Printing"};
Printer printer = {0};
int klipper_request_consecutive_fail_count = 0;
void send_gcode(bool wait, const char *gcode)
{
@@ -46,6 +47,7 @@ void fetch_printer_data()
int httpCode = client.GET();
if (httpCode == 200)
{
klipper_request_consecutive_fail_count = 0;
String payload = client.getString();
DynamicJsonDocument doc(4096);
deserializeJson(doc, payload);
@@ -159,6 +161,7 @@ void fetch_printer_data()
}
else
{
klipper_request_consecutive_fail_count++;
Serial.printf("Failed to fetch printer data: %d\n", httpCode);
}
}
@@ -171,9 +174,8 @@ void data_loop()
if (millis() - last_data_update < data_update_interval)
return;
last_data_update = millis();
fetch_printer_data();
last_data_update = millis();
}
void data_setup()

View File

@@ -28,6 +28,7 @@ typedef struct _Printer {
} Printer;
extern Printer printer;
extern int klipper_request_consecutive_fail_count;
#define DATA_PRINTER_STATE 1
#define DATA_PRINTER_DATA 2

View File

@@ -34,6 +34,7 @@ void setup() {
void loop(){
wifi_ok();
ip_ok();
data_loop();
lv_timer_handler();
lv_task_handler();

View File

@@ -3,6 +3,7 @@
#include "lvgl.h"
#include <TFT_eSPI.h>
#include <HTTPClient.h>
#include "core/data_setup.h"
bool connect_ok = false;
lv_obj_t * ipEntry;
@@ -117,6 +118,7 @@ int retry_count = 0;
void ip_init(){
connect_ok = false;
retry_count = 0;
ip_init_inner();
@@ -133,4 +135,12 @@ void ip_init(){
lv_label_set_text(label, retry_count_text.c_str());
}
}
}
void ip_ok(){
if (klipper_request_consecutive_fail_count > 5){
ip_init();
klipper_request_consecutive_fail_count = 0;
lv_msg_send(DATA_PRINTER_STATE, &printer);
}
}

View File

@@ -1 +1,2 @@
void ip_init();
void ip_init();
void ip_ok();