mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
A
This commit is contained in:
@@ -163,18 +163,7 @@ bool KlipperPrinter::execute_feature(PrinterFeatures feature)
|
|||||||
|
|
||||||
bool KlipperPrinter::connect()
|
bool KlipperPrinter::connect()
|
||||||
{
|
{
|
||||||
HTTPClient client;
|
return connection_test_klipper(printer_config) == ConnectionStatus::ConnectOk;
|
||||||
configure_http_client(client, "/printer/info", false, 1000);
|
|
||||||
|
|
||||||
int http_code;
|
|
||||||
try {
|
|
||||||
http_code = client.GET();
|
|
||||||
return http_code == 200;
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
LOG_LN("Failed to connect");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KlipperPrinter::fetch()
|
bool KlipperPrinter::fetch()
|
||||||
@@ -778,7 +767,7 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena
|
|||||||
|
|
||||||
configure_http_client(client, "/server/files/gcodes/" + urlEncode(img_filename_path), false, 2000);
|
configure_http_client(client, "/server/files/gcodes/" + urlEncode(img_filename_path), false, 2000);
|
||||||
|
|
||||||
int http_code = 0;
|
http_code = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
http_code = client.GET();
|
http_code = client.GET();
|
||||||
@@ -819,3 +808,32 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena
|
|||||||
free(img_filename_path);
|
free(img_filename_path);
|
||||||
return thumbnail;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectionStatus connection_test_klipper(PrinterConfiguration* config)
|
||||||
|
{
|
||||||
|
HTTPClient client;
|
||||||
|
|
||||||
|
client.setTimeout(1000);
|
||||||
|
client.setConnectTimeout(1000);
|
||||||
|
client.begin("http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + "/printer/info");
|
||||||
|
|
||||||
|
if (config->auth_configured) {
|
||||||
|
client.addHeader("X-Api-Key", config->klipper_auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
int http_code;
|
||||||
|
try {
|
||||||
|
http_code = client.GET();
|
||||||
|
|
||||||
|
if (http_code == 403)
|
||||||
|
{
|
||||||
|
return ConnectionStatus::ConnectAuthRequired;
|
||||||
|
}
|
||||||
|
|
||||||
|
return http_code == 200 ? ConnectionStatus::ConnectOk : ConnectionStatus::ConnectFail;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
LOG_LN("Failed to connect");
|
||||||
|
return ConnectionStatus::ConnectFail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,3 +55,11 @@ class KlipperPrinter : public BasePrinter
|
|||||||
void configure_http_client(HTTPClient &client, String url_part, bool stream, int timeout);
|
void configure_http_client(HTTPClient &client, String url_part, bool stream, int timeout);
|
||||||
void init_ui_panels();
|
void init_ui_panels();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ConnectionStatus {
|
||||||
|
ConnectFail = 0,
|
||||||
|
ConnectOk = 1,
|
||||||
|
ConnectAuthRequired = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
ConnectionStatus connection_test_klipper(PrinterConfiguration* config);
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "../core/lv_setup.h"
|
#include "../core/lv_setup.h"
|
||||||
#include "serial/serial_console.h"
|
#include "serial/serial_console.h"
|
||||||
|
#include "../core/klipper/klipper_printer_integration.hpp"
|
||||||
|
|
||||||
lv_obj_t * hostEntry;
|
lv_obj_t * hostEntry;
|
||||||
lv_obj_t * portEntry;
|
lv_obj_t * portEntry;
|
||||||
@@ -46,30 +47,6 @@ static const lv_btnmatrix_ctrl_t hex_numpad_ctrl[] = {
|
|||||||
1, 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 1,
|
1, 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum connection_status_t {
|
|
||||||
CONNECT_FAIL = 0,
|
|
||||||
CONNECT_OK = 1,
|
|
||||||
CONNECT_AUTH_REQUIRED = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
connection_status_t verify_ip(){
|
|
||||||
SETUP_HTTP_CLIENT_FULL("/printer/info", true, 1000);
|
|
||||||
|
|
||||||
int httpCode;
|
|
||||||
try {
|
|
||||||
httpCode = client.GET();
|
|
||||||
|
|
||||||
if (httpCode == 401)
|
|
||||||
return CONNECT_AUTH_REQUIRED;
|
|
||||||
|
|
||||||
return httpCode == 200 ? CONNECT_OK : CONNECT_FAIL;
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
LOG_LN("Failed to connect");
|
|
||||||
return CONNECT_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void keyboard_event_ip_entry(lv_event_t * e) {
|
static void keyboard_event_ip_entry(lv_event_t * e) {
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
lv_obj_t * ta = lv_event_get_target(e);
|
lv_obj_t * ta = lv_event_get_target(e);
|
||||||
@@ -102,13 +79,13 @@ static void keyboard_event_ip_entry(lv_event_t * e) {
|
|||||||
strcpy(global_config.printer_config[global_config.printer_index].klipper_host, lv_textarea_get_text(hostEntry));
|
strcpy(global_config.printer_config[global_config.printer_index].klipper_host, lv_textarea_get_text(hostEntry));
|
||||||
global_config.printer_config[global_config.printer_index].klipper_port = atoi(lv_textarea_get_text(portEntry));
|
global_config.printer_config[global_config.printer_index].klipper_port = atoi(lv_textarea_get_text(portEntry));
|
||||||
|
|
||||||
connection_status_t status = verify_ip();
|
ConnectionStatus status = connection_test_klipper(&global_config.printer_config[global_config.printer_index]);
|
||||||
if (status == CONNECT_OK)
|
if (status == ConnectionStatus::ConnectOk)
|
||||||
{
|
{
|
||||||
global_config.printer_config[global_config.printer_index].ip_configured = true;
|
global_config.printer_config[global_config.printer_index].ip_configured = true;
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
else if (status == CONNECT_AUTH_REQUIRED)
|
else if (status == ConnectionStatus::ConnectAuthRequired)
|
||||||
{
|
{
|
||||||
show_auth_entry();
|
show_auth_entry();
|
||||||
}
|
}
|
||||||
@@ -137,7 +114,7 @@ static void keyboard_event_auth_entry(lv_event_t * e) {
|
|||||||
global_config.printer_config[global_config.printer_index].auth_configured = true;
|
global_config.printer_config[global_config.printer_index].auth_configured = true;
|
||||||
strcpy(global_config.printer_config[global_config.printer_index].klipper_auth, txt);
|
strcpy(global_config.printer_config[global_config.printer_index].klipper_auth, txt);
|
||||||
|
|
||||||
if (verify_ip() == CONNECT_OK)
|
if (connection_test_klipper(&global_config.printer_config[global_config.printer_index]) == ConnectionStatus::ConnectOk)
|
||||||
{
|
{
|
||||||
global_config.printer_config[global_config.printer_index].ip_configured = true;
|
global_config.printer_config[global_config.printer_index].ip_configured = true;
|
||||||
global_config.printer_config[global_config.printer_index].setup_complete = true;
|
global_config.printer_config[global_config.printer_index].setup_complete = true;
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ static void btn_printer_secondary(lv_event_t * e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
global_config_delete_printer(config_index);
|
global_config_delete_printer(config_index);
|
||||||
nav_buttons_setup(PANEL_PRINTER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btn_printer_rename(lv_event_t * e)
|
static void btn_printer_rename(lv_event_t * e)
|
||||||
|
|||||||
Reference in New Issue
Block a user