mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Make octoprint work after testing
This commit is contained in:
@@ -84,8 +84,8 @@ void global_config_add_new_printer()
|
|||||||
new_config->printer_type = PrinterType::PrinterTypeNone;
|
new_config->printer_type = PrinterType::PrinterTypeNone;
|
||||||
|
|
||||||
new_config->printer_name[0] = 0;
|
new_config->printer_name[0] = 0;
|
||||||
new_config->klipper_host[0] = 0;
|
new_config->printer_host[0] = 0;
|
||||||
new_config->klipper_auth[0] = 0;
|
new_config->printer_auth[0] = 0;
|
||||||
new_config->klipper_port = 0;
|
new_config->klipper_port = 0;
|
||||||
|
|
||||||
new_config->color_scheme = old_config->color_scheme;
|
new_config->color_scheme = old_config->color_scheme;
|
||||||
@@ -144,8 +144,8 @@ void set_printer_config_index(int index)
|
|||||||
new_config->auth_configured = false;
|
new_config->auth_configured = false;
|
||||||
|
|
||||||
new_config->printer_name[0] = 0;
|
new_config->printer_name[0] = 0;
|
||||||
new_config->klipper_host[0] = 0;
|
new_config->printer_host[0] = 0;
|
||||||
new_config->klipper_auth[0] = 0;
|
new_config->printer_auth[0] = 0;
|
||||||
new_config->klipper_port = 0;
|
new_config->klipper_port = 0;
|
||||||
|
|
||||||
new_config->color_scheme = old_config->color_scheme;
|
new_config->color_scheme = old_config->color_scheme;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
#define CONFIG_VERSION 7
|
#define CONFIG_VERSION 7
|
||||||
#define PRINTER_CONFIG_COUNT 8
|
#define PRINTER_CONFIG_COUNT 6
|
||||||
#define DISPLAY_SECRETS 0
|
#define DISPLAY_SECRETS 0
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -49,8 +49,8 @@ typedef struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
char printer_name[25];
|
char printer_name[25];
|
||||||
char klipper_host[65];
|
char printer_host[65];
|
||||||
char klipper_auth[33];
|
char printer_auth[65];
|
||||||
unsigned int klipper_port;
|
unsigned int klipper_port;
|
||||||
|
|
||||||
unsigned char color_scheme;
|
unsigned char color_scheme;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ bool BambuPrinter::publish_mqtt_command(const char* command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char auth[48] = {0};
|
char auth[48] = {0};
|
||||||
sprintf(auth, "device/%s/request", printer_config->klipper_auth);
|
sprintf(auth, "device/%s/request", printer_config->printer_auth);
|
||||||
|
|
||||||
return client.publish(auth, command);
|
return client.publish(auth, command);
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ bool BambuPrinter::connect()
|
|||||||
{
|
{
|
||||||
wifi_client.setInsecure();
|
wifi_client.setInsecure();
|
||||||
client.setBufferSize(4096);
|
client.setBufferSize(4096);
|
||||||
client.setServer(printer_config->klipper_host, 8883);
|
client.setServer(printer_config->printer_host, 8883);
|
||||||
current_printer = this;
|
current_printer = this;
|
||||||
client.setCallback(NULL);
|
client.setCallback(NULL);
|
||||||
char buff[10] = {0};
|
char buff[10] = {0};
|
||||||
@@ -129,7 +129,7 @@ bool BambuPrinter::connect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
char auth[48] = {0};
|
char auth[48] = {0};
|
||||||
sprintf(auth, "device/%s/report", printer_config->klipper_auth);
|
sprintf(auth, "device/%s/report", printer_config->printer_auth);
|
||||||
|
|
||||||
if (!client.subscribe(auth))
|
if (!client.subscribe(auth))
|
||||||
{
|
{
|
||||||
@@ -341,7 +341,7 @@ BambuConnectionStatus connection_test_bambu(PrinterConfiguration* config)
|
|||||||
WiFiClientSecure connection_test_wifi_client;
|
WiFiClientSecure connection_test_wifi_client;
|
||||||
PubSubClient connection_test_client(connection_test_wifi_client);
|
PubSubClient connection_test_client(connection_test_wifi_client);
|
||||||
connection_test_wifi_client.setInsecure();
|
connection_test_wifi_client.setInsecure();
|
||||||
connection_test_client.setServer(config->klipper_host, 8883);
|
connection_test_client.setServer(config->printer_host, 8883);
|
||||||
char buff[10] = {0};
|
char buff[10] = {0};
|
||||||
sprintf(buff, "%d", config->klipper_port);
|
sprintf(buff, "%d", config->klipper_port);
|
||||||
if (!connection_test_client.connect("id", "bblp", buff))
|
if (!connection_test_client.connect("id", "bblp", buff))
|
||||||
@@ -351,7 +351,7 @@ BambuConnectionStatus connection_test_bambu(PrinterConfiguration* config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char auth[48] = {0};
|
char auth[48] = {0};
|
||||||
sprintf(auth, "device/%s/report", config->klipper_auth);
|
sprintf(auth, "device/%s/report", config->printer_auth);
|
||||||
|
|
||||||
if (!connection_test_client.subscribe(auth))
|
if (!connection_test_client.subscribe(auth))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ Files BambuPrinter::parse_files(WiFiClientSecure& wifi_client, int max_files)
|
|||||||
unsigned long timer_request = millis();
|
unsigned long timer_request = millis();
|
||||||
Files result = {0};
|
Files result = {0};
|
||||||
|
|
||||||
if (!wifi_client.connect(printer_config->klipper_host, 990))
|
if (!wifi_client.connect(printer_config->printer_host, 990))
|
||||||
{
|
{
|
||||||
LOG_LN("Failed to fetch files: connection failed");
|
LOG_LN("Failed to fetch files: connection failed");
|
||||||
}
|
}
|
||||||
@@ -325,7 +325,7 @@ Files BambuPrinter::parse_files(WiFiClientSecure& wifi_client, int max_files)
|
|||||||
send_command_without_response(wifi_client, "NLST");
|
send_command_without_response(wifi_client, "NLST");
|
||||||
wifi_client.stop();
|
wifi_client.stop();
|
||||||
|
|
||||||
if (wifi_client.connect(printer_config->klipper_host, 2024))
|
if (wifi_client.connect(printer_config->printer_host, 2024))
|
||||||
{
|
{
|
||||||
unsigned long timer_parse = millis();
|
unsigned long timer_parse = millis();
|
||||||
std::list<char*> files;
|
std::list<char*> files;
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ void KlipperPrinter::configure_http_client(HTTPClient &client, String url_part,
|
|||||||
client.setConnectTimeout(timeout);
|
client.setConnectTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.begin("http://" + String(printer_config->klipper_host) + ":" + String(printer_config->klipper_port) + url_part);
|
client.begin("http://" + String(printer_config->printer_host) + ":" + String(printer_config->klipper_port) + url_part);
|
||||||
|
|
||||||
if (printer_config->auth_configured) {
|
if (printer_config->auth_configured) {
|
||||||
client.addHeader("X-Api-Key", printer_config->klipper_auth);
|
client.addHeader("X-Api-Key", printer_config->printer_auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,10 +495,10 @@ KlipperConnectionStatus connection_test_klipper(PrinterConfiguration* config)
|
|||||||
|
|
||||||
client.setTimeout(1000);
|
client.setTimeout(1000);
|
||||||
client.setConnectTimeout(1000);
|
client.setConnectTimeout(1000);
|
||||||
client.begin("http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + "/printer/info");
|
client.begin("http://" + String(config->printer_host) + ":" + String(config->klipper_port) + "/printer/info");
|
||||||
|
|
||||||
if (config->auth_configured) {
|
if (config->auth_configured) {
|
||||||
client.addHeader("X-Api-Key", config->klipper_auth);
|
client.addHeader("X-Api-Key", config->printer_auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
int http_code;
|
int http_code;
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ void configure_http_client(HTTPClient &client, String url_part, bool stream, int
|
|||||||
client.setConnectTimeout(timeout);
|
client.setConnectTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.begin("http://" + String(printer_config->klipper_host) + ":" + String(printer_config->klipper_port) + url_part);
|
client.begin("http://" + String(printer_config->printer_host) + ":" + String(printer_config->klipper_port) + url_part);
|
||||||
|
|
||||||
if (printer_config->auth_configured) {
|
if (printer_config->auth_configured) {
|
||||||
client.addHeader("X-Api-Key", printer_config->klipper_auth);
|
client.addHeader("X-Api-Key", printer_config->printer_auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ bool OctoPrinter::post_request(const char* endpoint, const char* body, int timeo
|
|||||||
timeout_ms = 500;
|
timeout_ms = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_F(("POST >>> %s %s\n", endpoint, body));
|
||||||
configure_http_client(client, endpoint, false, timeout_ms, printer_config);
|
configure_http_client(client, endpoint, false, timeout_ms, printer_config);
|
||||||
|
|
||||||
if (body[0] == '{' || body[0] == '[')
|
if (body[0] == '{' || body[0] == '[')
|
||||||
@@ -61,8 +62,10 @@ bool OctoPrinter::post_request(const char* endpoint, const char* body, int timeo
|
|||||||
client.addHeader("Content-Type", "application/json");
|
client.addHeader("Content-Type", "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = client.POST(body);
|
int http_code = client.POST(body);
|
||||||
return result >= 200 && result < 300;
|
bool result = http_code >= 200 && http_code < 300;
|
||||||
|
LOG_F(("<<< %d\n", http_code));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OctoPrinter::send_gcode(const char* gcode, bool wait)
|
bool OctoPrinter::send_gcode(const char* gcode, bool wait)
|
||||||
@@ -77,7 +80,8 @@ bool OctoPrinter::send_gcode(const char* gcode, bool wait)
|
|||||||
|
|
||||||
for (char* iter = gcode_copy;; iter++)
|
for (char* iter = gcode_copy;; iter++)
|
||||||
{
|
{
|
||||||
if (*iter == '\n' || *iter == '\0')
|
char cur_iter = *iter;
|
||||||
|
if (cur_iter == '\n' || cur_iter == '\0')
|
||||||
{
|
{
|
||||||
if (iter != last_line_start)
|
if (iter != last_line_start)
|
||||||
{
|
{
|
||||||
@@ -88,7 +92,7 @@ bool OctoPrinter::send_gcode(const char* gcode, bool wait)
|
|||||||
last_line_start = iter + 1;
|
last_line_start = iter + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*iter == '\0')
|
if (cur_iter == '\0')
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -100,7 +104,7 @@ bool OctoPrinter::send_gcode(const char* gcode, bool wait)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(gcode_copy);
|
free(gcode_copy);
|
||||||
bool result = post_request("/api/printer/command/custom", out_buff);
|
bool result = post_request("/api/printer/command", out_buff);
|
||||||
free(out_buff);
|
free(out_buff);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -109,9 +113,11 @@ bool OctoPrinter::move_printer(const char* axis, float amount, bool relative)
|
|||||||
{
|
{
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
char out_buff[512];
|
char out_buff[512];
|
||||||
|
out_buff[0] = tolower(axis[0]);
|
||||||
|
out_buff[1] = '\0';
|
||||||
|
|
||||||
doc["command"] = "jog";
|
doc["command"] = "jog";
|
||||||
doc[axis] = amount;
|
doc[out_buff] = amount;
|
||||||
doc["absolute"] = !relative;
|
doc["absolute"] = !relative;
|
||||||
|
|
||||||
if (serializeJson(doc, out_buff, 512) >= 512)
|
if (serializeJson(doc, out_buff, 512) >= 512)
|
||||||
@@ -390,7 +396,7 @@ Files OctoPrinter::get_files()
|
|||||||
bool OctoPrinter::start_file(const char* filename)
|
bool OctoPrinter::start_file(const char* filename)
|
||||||
{
|
{
|
||||||
char buff[512];
|
char buff[512];
|
||||||
sprintf("/api/files/local/%s", filename);
|
sprintf(buff, "/api/files/local/%s", filename);
|
||||||
return post_request(buff, COMMAND_PRINT);
|
return post_request(buff, COMMAND_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,13 +120,15 @@ void OctoPrinter::parse_file_list(JsonDocument &in, std::list<OctoFileSystemFile
|
|||||||
|
|
||||||
for (auto file : result)
|
for (auto file : result)
|
||||||
{
|
{
|
||||||
if (!strcmp("local", file["origin"]))
|
const char *path = file["path"];
|
||||||
|
if (strcmp("local", file["origin"]))
|
||||||
{
|
{
|
||||||
|
LOG_F(("Skipping non-local file %s\n", path))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctoFileSystemFile f = {0};
|
OctoFileSystemFile f = {0};
|
||||||
const char *path = file["path"];
|
|
||||||
float modified = file["date"];
|
float modified = file["date"];
|
||||||
auto file_iter = files.begin();
|
auto file_iter = files.begin();
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void serial_check_connection()
|
|||||||
if (result == KlipperConnectionStatus::ConnectOk)
|
if (result == KlipperConnectionStatus::ConnectOk)
|
||||||
{
|
{
|
||||||
global_config.printer_config[global_config.printer_index].setup_complete = true;
|
global_config.printer_config[global_config.printer_index].setup_complete = true;
|
||||||
strcpy(global_config.printer_config[global_config.printer_index].klipper_host, "Serial");
|
strcpy(global_config.printer_config[global_config.printer_index].printer_host, "Serial");
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ void switch_printer_init() {
|
|||||||
|
|
||||||
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){
|
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){
|
||||||
PrinterConfiguration * config = &global_config.printer_config[i];
|
PrinterConfiguration * config = &global_config.printer_config[i];
|
||||||
const char* printer_name = (config->printer_name[0] == 0) ? config->klipper_host : config->printer_name;
|
const char* printer_name = (config->printer_name[0] == 0) ? config->printer_host : config->printer_name;
|
||||||
|
|
||||||
if (i == global_config.printer_index && config->setup_complete)
|
if (i == global_config.printer_index && config->setup_complete)
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ static void host_update(lv_event_t * e)
|
|||||||
{
|
{
|
||||||
lv_obj_t * ta = lv_event_get_target(e);
|
lv_obj_t * ta = lv_event_get_target(e);
|
||||||
const char* text = lv_textarea_get_text(ta);
|
const char* text = lv_textarea_get_text(ta);
|
||||||
strcpy(global_config.printer_config[global_config.printer_index].klipper_host, text);
|
strcpy(global_config.printer_config[global_config.printer_index].printer_host, text);
|
||||||
global_config.printer_config[global_config.printer_index].ip_configured = text[0] != '\0';
|
global_config.printer_config[global_config.printer_index].ip_configured = text[0] != '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ static void auth_update(lv_event_t * e)
|
|||||||
{
|
{
|
||||||
lv_obj_t * ta = lv_event_get_target(e);
|
lv_obj_t * ta = lv_event_get_target(e);
|
||||||
const char* text = lv_textarea_get_text(ta);
|
const char* text = lv_textarea_get_text(ta);
|
||||||
strcpy(global_config.printer_config[global_config.printer_index].klipper_auth, text);
|
strcpy(global_config.printer_config[global_config.printer_index].printer_auth, text);
|
||||||
global_config.printer_config[global_config.printer_index].auth_configured = text[0] != '\0';
|
global_config.printer_config[global_config.printer_index].auth_configured = text[0] != '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +166,10 @@ static void keyboard_event_ip_entry(lv_event_t * e) {
|
|||||||
{
|
{
|
||||||
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_2);
|
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_2);
|
||||||
}
|
}
|
||||||
|
else if (lv_obj_has_flag(ta, LV_OBJ_FLAG_USER_3))
|
||||||
|
{
|
||||||
|
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_TEXT_LOWER);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
|
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
|
||||||
@@ -309,7 +313,7 @@ void show_ip_entry()
|
|||||||
{
|
{
|
||||||
char buff[10] = {0};
|
char buff[10] = {0};
|
||||||
sprintf(buff, "%d", global_config.printer_config[global_config.printer_index].klipper_port);
|
sprintf(buff, "%d", global_config.printer_config[global_config.printer_index].klipper_port);
|
||||||
lv_textarea_set_text(host_entry, global_config.printer_config[global_config.printer_index].klipper_host);
|
lv_textarea_set_text(host_entry, global_config.printer_config[global_config.printer_index].printer_host);
|
||||||
lv_textarea_set_text(port_entry, buff);
|
lv_textarea_set_text(port_entry, buff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -327,18 +331,18 @@ void show_ip_entry()
|
|||||||
global_config.printer_config[global_config.printer_index].klipper_port = 80;
|
global_config.printer_config[global_config.printer_index].klipper_port = 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
global_config.printer_config[global_config.printer_index].klipper_host[0] = '\0';
|
global_config.printer_config[global_config.printer_index].printer_host[0] = '\0';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global_config.printer_config[global_config.printer_index].auth_configured)
|
if (global_config.printer_config[global_config.printer_index].auth_configured)
|
||||||
{
|
{
|
||||||
lv_textarea_set_text(auth_entry, global_config.printer_config[global_config.printer_index].klipper_auth);
|
lv_textarea_set_text(auth_entry, global_config.printer_config[global_config.printer_index].printer_auth);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lv_textarea_set_text(auth_entry, "");
|
lv_textarea_set_text(auth_entry, "");
|
||||||
global_config.printer_config[global_config.printer_index].klipper_auth[0] = '\0';
|
global_config.printer_config[global_config.printer_index].printer_auth[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_add_event_cb(host_entry, host_update, LV_EVENT_VALUE_CHANGED, NULL);
|
lv_obj_add_event_cb(host_entry, host_update, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
@@ -373,6 +377,9 @@ void show_ip_entry()
|
|||||||
lv_textarea_set_placeholder_text(auth_entry, "Printer serial number");
|
lv_textarea_set_placeholder_text(auth_entry, "Printer serial number");
|
||||||
break;
|
break;
|
||||||
case PrinterType::PrinterTypeOctoprint:
|
case PrinterType::PrinterTypeOctoprint:
|
||||||
|
lv_obj_clear_flag(auth_entry, LV_OBJ_FLAG_USER_2);
|
||||||
|
lv_obj_add_flag(auth_entry, LV_OBJ_FLAG_USER_3);
|
||||||
|
lv_textarea_set_max_length(auth_entry, 48);
|
||||||
lv_label_set_text(main_label, "Octoprint Setup");
|
lv_label_set_text(main_label, "Octoprint Setup");
|
||||||
lv_textarea_set_max_length(port_entry, 5);
|
lv_textarea_set_max_length(port_entry, 5);
|
||||||
lv_textarea_set_placeholder_text(host_entry, "Octoprint Host");
|
lv_textarea_set_placeholder_text(host_entry, "Octoprint Host");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ void connecting_panel_init(lv_obj_t* panel)
|
|||||||
{
|
{
|
||||||
lv_obj_t* label = lv_label_create(panel);
|
lv_obj_t* label = lv_label_create(panel);
|
||||||
lv_label_set_text_fmt(label, "Connecting to %s...", (get_current_printer()->printer_config->printer_name[0] == 0)
|
lv_label_set_text_fmt(label, "Connecting to %s...", (get_current_printer()->printer_config->printer_name[0] == 0)
|
||||||
? get_current_printer()->printer_config->klipper_host
|
? get_current_printer()->printer_config->printer_host
|
||||||
: get_current_printer()->printer_config->printer_name);
|
: get_current_printer()->printer_config->printer_name);
|
||||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ void macros_panel_init(lv_obj_t* panel) {
|
|||||||
if (macros_count <= 0){
|
if (macros_count <= 0){
|
||||||
label = lv_label_create(root_panel);
|
label = lv_label_create(root_panel);
|
||||||
if (get_current_printer()->printer_config->printer_type == PrinterType::PrinterTypeKlipper
|
if (get_current_printer()->printer_config->printer_type == PrinterType::PrinterTypeKlipper
|
||||||
|| get_current_printer()->printer_config->printer_type == PrinterType::PrinterTypeKlipper)
|
|| get_current_printer()->printer_config->printer_type == PrinterType::PrinterTypeKlipperSerial)
|
||||||
{
|
{
|
||||||
lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here.");
|
lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ static void update_printer_name_text(lv_event_t * e)
|
|||||||
lv_obj_t * label = lv_event_get_target(e);
|
lv_obj_t * label = lv_event_get_target(e);
|
||||||
int config_index = (int)lv_event_get_user_data(e);
|
int config_index = (int)lv_event_get_user_data(e);
|
||||||
BasePrinter* printer = get_printer(config_index);
|
BasePrinter* printer = get_printer(config_index);
|
||||||
lv_label_set_text(label, printer->printer_config->printer_name[0] == 0 ? printer->printer_config->klipper_host : printer->printer_config->printer_name);
|
lv_label_set_text(label, printer->printer_config->printer_name[0] == 0 ? printer->printer_config->printer_host : printer->printer_config->printer_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_printer_status_text(lv_event_t * e)
|
static void update_printer_status_text(lv_event_t * e)
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ namespace serial_console {
|
|||||||
- optionally add handling the new preference to sets() and settings() if it modifies global_config
|
- optionally add handling the new preference to sets() and settings() if it modifies global_config
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
PrinterConfiguration* get_current_printer_config()
|
||||||
|
{
|
||||||
|
return &global_config.printer_config[global_config.printer_index];
|
||||||
|
}
|
||||||
|
|
||||||
HANDLER commandHandlers[] = {
|
HANDLER commandHandlers[] = {
|
||||||
{"help", &help, 1},
|
{"help", &help, 1},
|
||||||
{"reset", &reset, 1},
|
{"reset", &reset, 1},
|
||||||
@@ -94,20 +99,20 @@ void sets(String argv[])
|
|||||||
Serial.printf("erase ssid\n");
|
Serial.printf("erase ssid\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_current_printer()->printer_config->ip_configured)
|
if(get_current_printer_config()->ip_configured)
|
||||||
{
|
{
|
||||||
Serial.printf("ip %s %d\n",get_current_printer()->printer_config->klipper_host, get_current_printer()->printer_config->klipper_port);
|
Serial.printf("ip %s %d\n",get_current_printer_config()->printer_host, get_current_printer_config()->klipper_port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.printf("erase ip\n");
|
Serial.printf("erase ip\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_current_printer()->printer_config->auth_configured)
|
if(get_current_printer_config()->auth_configured)
|
||||||
{
|
{
|
||||||
Serial.printf("key %s\n",
|
Serial.printf("key %s\n",
|
||||||
#if DISPLAY_SECRETS
|
#if DISPLAY_SECRETS
|
||||||
get_current_printer()->printer_config->klipper_auth
|
get_current_printer_config()->printer_auth
|
||||||
#else
|
#else
|
||||||
"[redacted]"
|
"[redacted]"
|
||||||
#endif
|
#endif
|
||||||
@@ -135,9 +140,9 @@ void sets(String argv[])
|
|||||||
void settings(String argv[])
|
void settings(String argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
if(get_current_printer()->printer_config->printer_name[0] != 0)
|
if(get_current_printer_config()->printer_name[0] != 0)
|
||||||
{
|
{
|
||||||
Serial.printf("Current printer# %d name: %s",global_config.printer_index, get_current_printer()->printer_config->printer_name);
|
Serial.printf("Current printer# %d name: %s",global_config.printer_index, get_current_printer_config()->printer_name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -162,20 +167,20 @@ void settings(String argv[])
|
|||||||
Serial.printf("Wifi not configured\n");
|
Serial.printf("Wifi not configured\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_current_printer()->printer_config->ip_configured)
|
if(get_current_printer_config()->ip_configured)
|
||||||
{
|
{
|
||||||
Serial.printf("Moonraker address: %s:%d\n",get_current_printer()->printer_config->klipper_host, get_current_printer()->printer_config->klipper_port);
|
Serial.printf("Moonraker address: %s:%d\n",get_current_printer_config()->printer_host, get_current_printer_config()->klipper_port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.printf("Moonraker address not configured\n");
|
Serial.printf("Moonraker address not configured\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_current_printer()->printer_config->auth_configured)
|
if(get_current_printer_config()->auth_configured)
|
||||||
{
|
{
|
||||||
Serial.printf("Moonraker API key: %s\n",
|
Serial.printf("Moonraker API key: %s\n",
|
||||||
#if DISPLAY_SECRETS
|
#if DISPLAY_SECRETS
|
||||||
get_current_printer()->printer_config->klipper_auth
|
get_current_printer_config()->printer_auth
|
||||||
#else
|
#else
|
||||||
"[redacted]"
|
"[redacted]"
|
||||||
#endif
|
#endif
|
||||||
@@ -205,15 +210,15 @@ void erase_one(const String arg)
|
|||||||
{
|
{
|
||||||
if(arg == "key")
|
if(arg == "key")
|
||||||
{
|
{
|
||||||
get_current_printer()->printer_config->auth_configured = false;
|
get_current_printer_config()->auth_configured = false;
|
||||||
// overwrite the key to make it unrecoverable for 3rd parties
|
// overwrite the key to make it unrecoverable for 3rd parties
|
||||||
memset(get_current_printer()->printer_config->klipper_auth,0,32);
|
memset(get_current_printer_config()->printer_auth,0,64);
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
else if(arg == "ip")
|
else if(arg == "ip")
|
||||||
{
|
{
|
||||||
get_current_printer()->printer_config->setup_complete = false;
|
get_current_printer_config()->setup_complete = false;
|
||||||
get_current_printer()->printer_config->ip_configured = false;
|
get_current_printer_config()->ip_configured = false;
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
else if(arg == "touch")
|
else if(arg == "touch")
|
||||||
@@ -252,14 +257,8 @@ void erase(String argv[])
|
|||||||
|
|
||||||
void key(String argv[])
|
void key(String argv[])
|
||||||
{
|
{
|
||||||
if (argv[1].length() != 32)
|
get_current_printer_config()->auth_configured = true;
|
||||||
{
|
strncpy(get_current_printer_config()->printer_auth, argv[1].c_str(), sizeof(global_config.printer_config[0].printer_auth));
|
||||||
Serial.println("Key must be 32 characters");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_current_printer()->printer_config->auth_configured = true;
|
|
||||||
strncpy(get_current_printer()->printer_config->klipper_auth, argv[1].c_str(), sizeof(global_config.printer_config[0].klipper_auth));
|
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,10 +282,10 @@ void ssid(String argv[])
|
|||||||
|
|
||||||
void ip(String argv[])
|
void ip(String argv[])
|
||||||
{
|
{
|
||||||
strncpy(get_current_printer()->printer_config->klipper_host, argv[1].c_str(), sizeof(global_config.printer_config[0].klipper_host)-1);
|
strncpy(get_current_printer_config()->printer_host, argv[1].c_str(), sizeof(global_config.printer_config[0].printer_host)-1);
|
||||||
get_current_printer()->printer_config->klipper_port = argv[2].toInt();
|
get_current_printer_config()->klipper_port = argv[2].toInt();
|
||||||
get_current_printer()->printer_config->ip_configured = true;
|
get_current_printer_config()->ip_configured = true;
|
||||||
get_current_printer()->printer_config->setup_complete = true;
|
get_current_printer_config()->setup_complete = true;
|
||||||
write_global_config();
|
write_global_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user