mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 13:43:25 +00:00
Printer init
This commit is contained in:
@@ -46,11 +46,11 @@ PrinterConfiguration* get_current_printer_config()
|
|||||||
return &global_config.printer_config[global_config.printer_index];
|
return &global_config.printer_config[global_config.printer_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_printer_config_count()
|
int global_config_get_printer_config_count()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
|
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
|
||||||
if (global_config.printer_config[i].ip_configured)
|
if (global_config.printer_config[i].setup_complete)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
@@ -59,12 +59,72 @@ int get_printer_config_count()
|
|||||||
int get_printer_config_free_index()
|
int get_printer_config_free_index()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
|
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
|
||||||
if (!global_config.printer_config[i].ip_configured)
|
if (!global_config.printer_config[i].setup_complete)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void global_config_add_new_printer()
|
||||||
|
{
|
||||||
|
int free_index = get_printer_config_free_index();
|
||||||
|
if (free_index <= -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrinterConfiguration* old_config = &global_config.printer_config[global_config.printer_index];
|
||||||
|
PrinterConfiguration* new_config = &global_config.printer_config[free_index];
|
||||||
|
|
||||||
|
new_config->raw = old_config->raw;
|
||||||
|
new_config->ip_configured = false;
|
||||||
|
new_config->auth_configured = false;
|
||||||
|
|
||||||
|
new_config->printer_name[0] = 0;
|
||||||
|
new_config->klipper_host[0] = 0;
|
||||||
|
new_config->klipper_auth[0] = 0;
|
||||||
|
new_config->klipper_port = 0;
|
||||||
|
|
||||||
|
new_config->color_scheme = old_config->color_scheme;
|
||||||
|
|
||||||
|
// TODO: Replace with memcpy
|
||||||
|
for (int i = 0; i < 3; i++){
|
||||||
|
new_config->hotend_presets[i] = old_config->hotend_presets[i];
|
||||||
|
new_config->bed_presets[i] = old_config->bed_presets[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++){
|
||||||
|
new_config->printer_move_x_steps[i] = old_config->printer_move_x_steps[i];
|
||||||
|
new_config->printer_move_y_steps[i] = old_config->printer_move_y_steps[i];
|
||||||
|
new_config->printer_move_z_steps[i] = old_config->printer_move_z_steps[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
write_global_config();
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void global_config_set_printer(int idx)
|
||||||
|
{
|
||||||
|
if (idx < 0 || idx >= PRINTER_CONFIG_COUNT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
global_config.printer_index = idx;
|
||||||
|
write_global_config();
|
||||||
|
}
|
||||||
|
|
||||||
|
void global_config_delete_printer(int idx)
|
||||||
|
{
|
||||||
|
if (global_config.printer_index == idx)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrinterConfiguration* config = &global_config.printer_config[idx];
|
||||||
|
config->setup_complete = false;
|
||||||
|
write_global_config();
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
void set_printer_config_index(int index)
|
void set_printer_config_index(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= PRINTER_CONFIG_COUNT)
|
if (index < 0 || index >= PRINTER_CONFIG_COUNT)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
#define CONFIG_VERSION 6
|
#define CONFIG_VERSION 7
|
||||||
#define PRINTER_CONFIG_COUNT 8
|
#define PRINTER_CONFIG_COUNT 8
|
||||||
#define DISPLAY_SECRETS 0
|
#define DISPLAY_SECRETS 0
|
||||||
|
|
||||||
@@ -32,17 +32,17 @@ typedef struct {
|
|||||||
unsigned int raw;
|
unsigned int raw;
|
||||||
struct {
|
struct {
|
||||||
// Internal
|
// Internal
|
||||||
|
bool setup_complete : 1;
|
||||||
bool ip_configured : 1;
|
bool ip_configured : 1;
|
||||||
bool auth_configured : 1;
|
bool auth_configured : 1;
|
||||||
|
bool custom_filament_move_macros : 1;
|
||||||
|
PrinterType printer_type : 3;
|
||||||
|
|
||||||
// External
|
// External
|
||||||
bool light_mode : 1;
|
bool light_mode : 1;
|
||||||
bool invert_colors : 1;
|
bool invert_colors : 1;
|
||||||
unsigned char remaining_time_calc_mode : 2;
|
unsigned char remaining_time_calc_mode : 2;
|
||||||
unsigned char show_stats_on_progress_panel : 2;
|
unsigned char show_stats_on_progress_panel : 2;
|
||||||
|
|
||||||
bool custom_filament_move_macros : 1;
|
|
||||||
PrinterType printer_type : 3;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,8 +122,12 @@ void write_global_config();
|
|||||||
void verify_version();
|
void verify_version();
|
||||||
void load_global_config();
|
void load_global_config();
|
||||||
|
|
||||||
|
void global_config_add_new_printer();
|
||||||
|
void global_config_set_printer(int idx);
|
||||||
|
void global_config_delete_printer(int idx);
|
||||||
|
|
||||||
//PRINTER_CONFIG* get_current_printer_config();
|
//PRINTER_CONFIG* get_current_printer_config();
|
||||||
//int get_printer_config_count();
|
int global_config_get_printer_config_count();
|
||||||
//void set_printer_config_index(int index);
|
//void set_printer_config_index(int index);
|
||||||
//int get_printer_config_free_index();
|
//int get_printer_config_free_index();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
#include <UrlEncode.h>
|
#include <UrlEncode.h>
|
||||||
#include "printer_integration.hpp"
|
#include "printer_integration.hpp"
|
||||||
|
#include "klipper/klipper_printer_integration.hpp"
|
||||||
|
|
||||||
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
|
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
|
||||||
const long data_update_interval = 780;
|
const long data_update_interval = 780;
|
||||||
@@ -101,6 +102,22 @@ TaskHandle_t background_loop;
|
|||||||
|
|
||||||
void data_setup()
|
void data_setup()
|
||||||
{
|
{
|
||||||
|
BasePrinter** available_printers = (BasePrinter**)malloc(sizeof(BasePrinter*) * PRINTER_CONFIG_COUNT);
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++)
|
||||||
|
{
|
||||||
|
if (global_config.printer_config[i].setup_complete)
|
||||||
|
{
|
||||||
|
switch (global_config.printer_config[i].printer_type)
|
||||||
|
{
|
||||||
|
case PrinterType::PrinterTypeKlipper:
|
||||||
|
available_printers[count++] = new KlipperPrinter(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize_printers(available_printers, count);
|
||||||
semaphore_init();
|
semaphore_init();
|
||||||
fetch_printer_data();
|
fetch_printer_data();
|
||||||
freeze_render_thread();
|
freeze_render_thread();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include "../../ui/ui_utils.h"
|
#include "../../ui/ui_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
static void set_fan_speed_text(lv_event_t * e) {
|
static void set_fan_speed_text(lv_event_t * e) {
|
||||||
lv_obj_t * label = lv_event_get_target(e);
|
lv_obj_t * label = lv_event_get_target(e);
|
||||||
char data[16];
|
char data[16];
|
||||||
|
|||||||
@@ -4,13 +4,14 @@
|
|||||||
|
|
||||||
unsigned char current_printer_index = 0;
|
unsigned char current_printer_index = 0;
|
||||||
unsigned char total_printers;
|
unsigned char total_printers;
|
||||||
BasePrinter* registered_printers;
|
BasePrinter** registered_printers;
|
||||||
PrinterDataMinimal* minimal_data_copy;
|
PrinterDataMinimal* minimal_data_copy;
|
||||||
PrinterData* printer_data_copy;
|
PrinterData* printer_data_copy;
|
||||||
|
|
||||||
BasePrinter::BasePrinter(unsigned char index)
|
BasePrinter::BasePrinter(unsigned char index)
|
||||||
{
|
{
|
||||||
config_index = index;
|
config_index = index;
|
||||||
|
printer_config = &global_config.printer_config[index];
|
||||||
|
|
||||||
printer_data.state_message = (char*)malloc(1);
|
printer_data.state_message = (char*)malloc(1);
|
||||||
printer_data.print_filename = (char*)malloc(1);
|
printer_data.print_filename = (char*)malloc(1);
|
||||||
@@ -54,9 +55,13 @@ PrinterData* BasePrinter::AnnouncePrinterData()
|
|||||||
lv_msg_send(DATA_PRINTER_DATA, get_current_printer());
|
lv_msg_send(DATA_PRINTER_DATA, get_current_printer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_printers()
|
void initialize_printers(BasePrinter** printers, unsigned char total)
|
||||||
{
|
{
|
||||||
printer_data_copy = (PrinterData*)malloc(sizeof(PrinterData));
|
printer_data_copy = (PrinterData*)malloc(sizeof(PrinterData));
|
||||||
|
minimal_data_copy = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * total_printers);
|
||||||
|
memset(minimal_data_copy, 0, sizeof(PrinterDataMinimal) * total_printers);
|
||||||
|
registered_printers = printers;
|
||||||
|
total_printers = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePrinter* get_current_printer()
|
BasePrinter* get_current_printer()
|
||||||
@@ -66,7 +71,7 @@ BasePrinter* get_current_printer()
|
|||||||
|
|
||||||
BasePrinter* get_printer(int idx)
|
BasePrinter* get_printer(int idx)
|
||||||
{
|
{
|
||||||
return registered_printers + idx;
|
return registered_printers[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_current_printer_index()
|
int get_current_printer_index()
|
||||||
@@ -86,7 +91,7 @@ unsigned int get_printer_count()
|
|||||||
|
|
||||||
void announce_printer_data_minimal(PrinterDataMinimal* printer_data)
|
void announce_printer_data_minimal(PrinterDataMinimal* printer_data)
|
||||||
{
|
{
|
||||||
memcpy(printer_data_copy, printer_data, sizeof(PrinterDataMinimal) * total_printers);
|
memcpy(minimal_data_copy, printer_data, sizeof(PrinterDataMinimal) * total_printers);
|
||||||
lv_msg_send(DATA_PRINTER_MINIMAL, get_current_printer());
|
lv_msg_send(DATA_PRINTER_MINIMAL, get_current_printer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,20 +100,10 @@ PrinterDataMinimal* get_printer_data_minimal(int idx)
|
|||||||
return &(minimal_data_copy[idx]);
|
return &(minimal_data_copy[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePrinter::save_printer_config()
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void add_printer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_current_printer(int idx)
|
void set_current_printer(int idx)
|
||||||
{
|
{
|
||||||
//set_printer_config_index(index);
|
current_printer_index = idx;
|
||||||
|
global_config_set_printer(idx);
|
||||||
set_color_scheme();
|
set_color_scheme();
|
||||||
set_invert_display();
|
set_invert_display();
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,6 @@ class BasePrinter
|
|||||||
|
|
||||||
BasePrinter(unsigned char index);
|
BasePrinter(unsigned char index);
|
||||||
PrinterData* AnnouncePrinterData();
|
PrinterData* AnnouncePrinterData();
|
||||||
void save_printer_config();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DATA_PRINTER_STATE 1
|
#define DATA_PRINTER_STATE 1
|
||||||
@@ -174,11 +173,10 @@ class BasePrinter
|
|||||||
|
|
||||||
BasePrinter* get_current_printer();
|
BasePrinter* get_current_printer();
|
||||||
BasePrinter* get_printer(int idx);
|
BasePrinter* get_printer(int idx);
|
||||||
void initialize_printers();
|
void initialize_printers(BasePrinter** printers, unsigned char total);
|
||||||
PrinterData* get_current_printer_data();
|
PrinterData* get_current_printer_data();
|
||||||
unsigned int get_printer_count();
|
unsigned int get_printer_count();
|
||||||
void announce_printer_data_minimal(PrinterDataMinimal* printer_data);
|
void announce_printer_data_minimal(PrinterDataMinimal* printer_data);
|
||||||
PrinterDataMinimal* get_printer_data_minimal(int idx);
|
PrinterDataMinimal* get_printer_data_minimal(int idx);
|
||||||
int get_current_printer_index();
|
int get_current_printer_index();
|
||||||
void add_printer();
|
|
||||||
void set_current_printer(int idx);
|
void set_current_printer(int idx);
|
||||||
@@ -165,9 +165,7 @@ static void btn_printer_secondary(lv_event_t * e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printer->printer_config->ip_configured = false;
|
global_config_delete_printer(config_index);
|
||||||
write_global_config();
|
|
||||||
|
|
||||||
nav_buttons_setup(PANEL_PRINTER);
|
nav_buttons_setup(PANEL_PRINTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +194,7 @@ static void btn_printer_activate(lv_event_t * e)
|
|||||||
|
|
||||||
static void btn_printer_add(lv_event_t * e)
|
static void btn_printer_add(lv_event_t * e)
|
||||||
{
|
{
|
||||||
add_printer();
|
global_config_add_new_printer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_printer_ui(PrinterConfiguration * config, lv_obj_t * root)
|
void create_printer_ui(PrinterConfiguration * config, lv_obj_t * root)
|
||||||
|
|||||||
Reference in New Issue
Block a user