mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Change back to klipper connect screen when connection to klipper gets severed
This commit is contained in:
@@ -12,6 +12,7 @@ const char *printer_state_messages[] = {
|
|||||||
"Printing"};
|
"Printing"};
|
||||||
|
|
||||||
Printer printer = {0};
|
Printer printer = {0};
|
||||||
|
int klipper_request_consecutive_fail_count = 0;
|
||||||
|
|
||||||
void send_gcode(bool wait, const char *gcode)
|
void send_gcode(bool wait, const char *gcode)
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,7 @@ void fetch_printer_data()
|
|||||||
int httpCode = client.GET();
|
int httpCode = client.GET();
|
||||||
if (httpCode == 200)
|
if (httpCode == 200)
|
||||||
{
|
{
|
||||||
|
klipper_request_consecutive_fail_count = 0;
|
||||||
String payload = client.getString();
|
String payload = client.getString();
|
||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
deserializeJson(doc, payload);
|
deserializeJson(doc, payload);
|
||||||
@@ -159,6 +161,7 @@ void fetch_printer_data()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
klipper_request_consecutive_fail_count++;
|
||||||
Serial.printf("Failed to fetch printer data: %d\n", httpCode);
|
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)
|
if (millis() - last_data_update < data_update_interval)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
last_data_update = millis();
|
|
||||||
|
|
||||||
fetch_printer_data();
|
fetch_printer_data();
|
||||||
|
last_data_update = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void data_setup()
|
void data_setup()
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ typedef struct _Printer {
|
|||||||
} Printer;
|
} Printer;
|
||||||
|
|
||||||
extern Printer printer;
|
extern Printer printer;
|
||||||
|
extern int klipper_request_consecutive_fail_count;
|
||||||
|
|
||||||
#define DATA_PRINTER_STATE 1
|
#define DATA_PRINTER_STATE 1
|
||||||
#define DATA_PRINTER_DATA 2
|
#define DATA_PRINTER_DATA 2
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
wifi_ok();
|
wifi_ok();
|
||||||
|
ip_ok();
|
||||||
data_loop();
|
data_loop();
|
||||||
lv_timer_handler();
|
lv_timer_handler();
|
||||||
lv_task_handler();
|
lv_task_handler();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
#include "core/data_setup.h"
|
||||||
|
|
||||||
bool connect_ok = false;
|
bool connect_ok = false;
|
||||||
lv_obj_t * ipEntry;
|
lv_obj_t * ipEntry;
|
||||||
@@ -117,6 +118,7 @@ int retry_count = 0;
|
|||||||
|
|
||||||
void ip_init(){
|
void ip_init(){
|
||||||
connect_ok = false;
|
connect_ok = false;
|
||||||
|
retry_count = 0;
|
||||||
|
|
||||||
ip_init_inner();
|
ip_init_inner();
|
||||||
|
|
||||||
@@ -133,4 +135,12 @@ void ip_init(){
|
|||||||
lv_label_set_text(label, retry_count_text.c_str());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
void ip_init();
|
void ip_init();
|
||||||
|
void ip_ok();
|
||||||
Reference in New Issue
Block a user