mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Refactor + Power menu in printer menu
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <UrlEncode.h>
|
#include <UrlEncode.h>
|
||||||
#include "http_client.h"
|
#include "http_client.h"
|
||||||
#include "../ui/ui_utils.h"
|
#include "../ui/ui_utils.h"
|
||||||
|
#include "macros_query.h"
|
||||||
|
|
||||||
const char *printer_state_messages[] = {
|
const char *printer_state_messages[] = {
|
||||||
"Error",
|
"Error",
|
||||||
@@ -325,6 +326,7 @@ void fetch_printer_data_minimal()
|
|||||||
if (httpCode == 200)
|
if (httpCode == 200)
|
||||||
{
|
{
|
||||||
data[i].online = true;
|
data[i].online = true;
|
||||||
|
data[i].power_devices = 0;
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
deserializeJson(doc, client.getStream());
|
deserializeJson(doc, client.getStream());
|
||||||
auto status = doc["result"]["status"];
|
auto status = doc["result"]["status"];
|
||||||
@@ -377,7 +379,8 @@ void fetch_printer_data_minimal()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printer_minimal->online = false;
|
data[i].online = false;
|
||||||
|
data[i].power_devices = power_devices_count(config);
|
||||||
unfreeze_request_thread();
|
unfreeze_request_thread();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,7 +423,6 @@ void data_setup()
|
|||||||
printer.print_filename = filename_buff;
|
printer.print_filename = filename_buff;
|
||||||
fetch_printer_data();
|
fetch_printer_data();
|
||||||
|
|
||||||
macros_query_setup();
|
|
||||||
freeze_render_thread();
|
freeze_render_thread();
|
||||||
xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0);
|
xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ typedef struct _PrinterMinimal {
|
|||||||
bool online;
|
bool online;
|
||||||
unsigned char state;
|
unsigned char state;
|
||||||
float print_progress; // 0 -> 1
|
float print_progress; // 0 -> 1
|
||||||
|
unsigned int power_devices;
|
||||||
} PrinterMinimal;
|
} PrinterMinimal;
|
||||||
|
|
||||||
extern Printer printer;
|
extern Printer printer;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#include "macros_query.h"
|
#include "macros_query.h"
|
||||||
#include "./data_setup.h"
|
#include "./data_setup.h"
|
||||||
#include "../conf/global_config.h"
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <UrlEncode.h>
|
#include <UrlEncode.h>
|
||||||
#include "http_client.h"
|
#include "http_client.h"
|
||||||
@@ -11,12 +10,15 @@ static int macros_count = 0;
|
|||||||
|
|
||||||
static char* power_devices[16] = {0};
|
static char* power_devices[16] = {0};
|
||||||
static bool power_device_states[16] = {0};
|
static bool power_device_states[16] = {0};
|
||||||
static int power_devices_count = 0;
|
static unsigned int stored_power_devices_count = 0;
|
||||||
|
|
||||||
void _macros_query_internal(){
|
MACROSQUERY macros_query(PRINTER_CONFIG * config)
|
||||||
SETUP_HTTP_CLIENT("/printer/gcode/help")
|
{
|
||||||
|
HTTPClient client;
|
||||||
|
configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000);
|
||||||
|
|
||||||
int httpCode = client.GET();
|
int httpCode = client.GET();
|
||||||
|
|
||||||
if (httpCode == 200){
|
if (httpCode == 200){
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
deserializeJson(doc, client.getStream());
|
deserializeJson(doc, client.getStream());
|
||||||
@@ -37,76 +39,132 @@ void _macros_query_internal(){
|
|||||||
macros[macros_count++] = macro;
|
macros[macros_count++] = macro;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {(const char**)macros, (unsigned int)macros_count};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {NULL, 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void power_devices_clear(){
|
MACROSQUERY macros_query()
|
||||||
for (int i = 0; i < power_devices_count; i++){
|
{
|
||||||
free(power_devices[i]);
|
return macros_query(get_current_printer_config());
|
||||||
}
|
}
|
||||||
|
|
||||||
power_devices_count = 0;
|
unsigned int macro_count(PRINTER_CONFIG * config)
|
||||||
}
|
{
|
||||||
|
HTTPClient client;
|
||||||
void _power_devices_query_internal(){
|
configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000);
|
||||||
SETUP_HTTP_CLIENT("/machine/device_power/devices")
|
|
||||||
|
|
||||||
int httpCode = client.GET();
|
int httpCode = client.GET();
|
||||||
|
|
||||||
if (httpCode == 200 || httpCode == 404 || httpCode == 500){
|
if (httpCode == 200){
|
||||||
power_devices_clear();
|
JsonDocument doc;
|
||||||
|
deserializeJson(doc, client.getStream());
|
||||||
|
auto result = doc["result"].as<JsonObject>();
|
||||||
|
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
for (JsonPair i : result){
|
||||||
|
const char *value = i.value().as<String>().c_str();
|
||||||
|
if (strcmp(value, "CYD_SCREEN_MACRO") == 0) {
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int macro_count()
|
||||||
|
{
|
||||||
|
return macro_count(get_current_printer_config());
|
||||||
|
}
|
||||||
|
|
||||||
|
POWERQUERY power_devices_query(PRINTER_CONFIG * config)
|
||||||
|
{
|
||||||
|
HTTPClient client;
|
||||||
|
configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000);
|
||||||
|
|
||||||
|
int httpCode = client.GET();
|
||||||
|
|
||||||
if (httpCode == 200){
|
if (httpCode == 200){
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
deserializeJson(doc, client.getStream());
|
deserializeJson(doc, client.getStream());
|
||||||
auto result = doc["result"]["devices"].as<JsonArray>();
|
auto result = doc["result"]["devices"].as<JsonArray>();
|
||||||
|
|
||||||
|
for (int i = 0; i < stored_power_devices_count; i++){
|
||||||
|
free(power_devices[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
stored_power_devices_count = 0;
|
||||||
|
|
||||||
for (auto i : result){
|
for (auto i : result){
|
||||||
const char * device_name = i["device"];
|
const char * device_name = i["device"];
|
||||||
const char * device_state = i["status"];
|
const char * device_state = i["status"];
|
||||||
power_devices[power_devices_count] = (char*)malloc(strlen(device_name) + 1);
|
power_devices[stored_power_devices_count] = (char*)malloc(strlen(device_name) + 1);
|
||||||
strcpy(power_devices[power_devices_count], device_name);
|
strcpy(power_devices[stored_power_devices_count], device_name);
|
||||||
power_device_states[power_devices_count] = strcmp(device_state, "on") == 0;
|
power_device_states[stored_power_devices_count] = strcmp(device_state, "on") == 0;
|
||||||
power_devices_count++;
|
stored_power_devices_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)stored_power_devices_count};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {NULL, NULL, 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_state_change(void * s, lv_msg_t * m) {
|
POWERQUERY power_devices_query()
|
||||||
if (printer.state == PRINTER_STATE_ERROR || printer.state == PRINTER_STATE_PAUSED){
|
{
|
||||||
return;
|
return power_devices_query(get_current_printer_config());
|
||||||
}
|
}
|
||||||
|
|
||||||
_macros_query_internal();
|
unsigned int power_devices_count(PRINTER_CONFIG * config)
|
||||||
_power_devices_query_internal();
|
{
|
||||||
|
HTTPClient client;
|
||||||
|
configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000);
|
||||||
|
|
||||||
|
int httpCode = client.GET();
|
||||||
|
|
||||||
|
if (httpCode == 200){
|
||||||
|
JsonDocument doc;
|
||||||
|
deserializeJson(doc, client.getStream());
|
||||||
|
auto result = doc["result"]["devices"].as<JsonArray>();
|
||||||
|
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
for (auto i : result){
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_power_state(const char* device_name, bool state) {
|
return count;
|
||||||
SETUP_HTTP_CLIENT("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off"));
|
}
|
||||||
|
else {
|
||||||
if (client.POST("") != 200)
|
return 0;
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = 0; i < power_devices_count; i++){
|
|
||||||
if (strcmp(power_devices[i], device_name) == 0){
|
|
||||||
power_device_states[i] = state;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
unsigned int power_devices_count()
|
||||||
|
{
|
||||||
|
return power_devices_count(get_current_printer_config());
|
||||||
}
|
}
|
||||||
|
|
||||||
MACROSQUERY macros_query() {
|
|
||||||
return {(const char**)macros, (unsigned int)macros_count};
|
|
||||||
|
bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config)
|
||||||
|
{
|
||||||
|
HTTPClient client;
|
||||||
|
configure_http_client(client, get_full_url("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off"), config), true, 1000);
|
||||||
|
|
||||||
|
return client.POST("") == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
POWERQUERY power_devices_query() {
|
bool set_power_state(const char* device_name, bool state)
|
||||||
return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)power_devices_count};
|
{
|
||||||
}
|
return set_power_state(device_name, state, get_current_printer_config());
|
||||||
|
|
||||||
void macros_query_setup(){
|
|
||||||
lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL);
|
|
||||||
on_state_change(NULL, NULL);
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../conf/global_config.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char** macros;
|
const char** macros;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
@@ -11,10 +13,13 @@ typedef struct {
|
|||||||
uint32_t count;
|
uint32_t count;
|
||||||
} POWERQUERY;
|
} POWERQUERY;
|
||||||
|
|
||||||
|
MACROSQUERY macros_query(PRINTER_CONFIG * config);
|
||||||
MACROSQUERY macros_query();
|
MACROSQUERY macros_query();
|
||||||
|
unsigned int macro_count(PRINTER_CONFIG * config);
|
||||||
|
unsigned int macro_count();
|
||||||
|
POWERQUERY power_devices_query(PRINTER_CONFIG * config);
|
||||||
POWERQUERY power_devices_query();
|
POWERQUERY power_devices_query();
|
||||||
void macros_query_setup();
|
unsigned int power_devices_count(PRINTER_CONFIG * config);
|
||||||
|
unsigned int power_devices_count();
|
||||||
|
bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config);
|
||||||
bool set_power_state(const char* device_name, bool state);
|
bool set_power_state(const char* device_name, bool state);
|
||||||
void _power_devices_query_internal();
|
|
||||||
void _macros_query_internal();
|
|
||||||
void power_devices_clear();
|
|
||||||
@@ -8,8 +8,10 @@
|
|||||||
#include "panels/panel.h"
|
#include "panels/panel.h"
|
||||||
#include "../core/http_client.h"
|
#include "../core/http_client.h"
|
||||||
#include "switch_printer.h"
|
#include "switch_printer.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
bool connect_ok = false;
|
bool connect_ok = false;
|
||||||
|
int prev_power_device_count = 0;
|
||||||
lv_obj_t * hostEntry;
|
lv_obj_t * hostEntry;
|
||||||
lv_obj_t * portEntry;
|
lv_obj_t * portEntry;
|
||||||
lv_obj_t * label = NULL;
|
lv_obj_t * label = NULL;
|
||||||
@@ -116,21 +118,7 @@ static void reset_btn_event_handler(lv_event_t * e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void power_devices_button(lv_event_t * e) {
|
static void power_devices_button(lv_event_t * e) {
|
||||||
lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
|
macros_draw_power_fullscreen();
|
||||||
lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0);
|
|
||||||
lv_layout_flex_column(panel);
|
|
||||||
lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX);
|
|
||||||
lv_obj_align(panel, LV_ALIGN_TOP_LEFT, 0, CYD_SCREEN_GAP_PX);
|
|
||||||
|
|
||||||
lv_obj_t * button = lv_btn_create(panel);
|
|
||||||
lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
|
||||||
lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel);
|
|
||||||
|
|
||||||
lv_obj_t * label = lv_label_create(button);
|
|
||||||
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
|
|
||||||
lv_obj_center(label);
|
|
||||||
|
|
||||||
macros_panel_add_power_devices_to_panel(panel, power_devices_query());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void redraw_connect_screen(){
|
void redraw_connect_screen(){
|
||||||
@@ -153,7 +141,7 @@ void redraw_connect_screen(){
|
|||||||
lv_label_set_text(btn_label, "Reset");
|
lv_label_set_text(btn_label, "Reset");
|
||||||
lv_obj_center(btn_label);
|
lv_obj_center(btn_label);
|
||||||
|
|
||||||
if (power_devices_query().count >= 1){
|
if (prev_power_device_count >= 1){
|
||||||
lv_obj_t * power_devices_btn = lv_btn_create(button_row);
|
lv_obj_t * power_devices_btn = lv_btn_create(button_row);
|
||||||
lv_obj_add_event_cb(power_devices_btn, power_devices_button, LV_EVENT_CLICKED, NULL);
|
lv_obj_add_event_cb(power_devices_btn, power_devices_button, LV_EVENT_CLICKED, NULL);
|
||||||
lv_obj_set_height(power_devices_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
lv_obj_set_height(power_devices_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
@@ -292,7 +280,7 @@ int retry_count = 0;
|
|||||||
void ip_init(){
|
void ip_init(){
|
||||||
connect_ok = false;
|
connect_ok = false;
|
||||||
retry_count = 0;
|
retry_count = 0;
|
||||||
int prev_power_device_count = 0;
|
prev_power_device_count = 0;
|
||||||
|
|
||||||
ip_init_inner();
|
ip_init_inner();
|
||||||
|
|
||||||
@@ -312,13 +300,12 @@ void ip_init(){
|
|||||||
lv_label_set_text(label, retry_count_text.c_str());
|
lv_label_set_text(label, retry_count_text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != CONNECT_AUTH_REQUIRED)
|
if (status == CONNECT_AUTH_REQUIRED)
|
||||||
_power_devices_query_internal();
|
|
||||||
else
|
|
||||||
handle_auth_entry();
|
handle_auth_entry();
|
||||||
|
|
||||||
if (power_devices_query().count != prev_power_device_count) {
|
unsigned int power_device_count = power_devices_count();
|
||||||
prev_power_device_count = power_devices_query().count;
|
if (power_device_count != prev_power_device_count) {
|
||||||
|
prev_power_device_count = power_device_count;
|
||||||
redraw_connect_screen();
|
redraw_connect_screen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,7 +315,6 @@ void ip_init(){
|
|||||||
void ip_ok(){
|
void ip_ok(){
|
||||||
if (klipper_request_consecutive_fail_count > 5){
|
if (klipper_request_consecutive_fail_count > 5){
|
||||||
freeze_request_thread();
|
freeze_request_thread();
|
||||||
power_devices_clear();
|
|
||||||
ip_init();
|
ip_init();
|
||||||
unfreeze_request_thread();
|
unfreeze_request_thread();
|
||||||
klipper_request_consecutive_fail_count = 0;
|
klipper_request_consecutive_fail_count = 0;
|
||||||
|
|||||||
75
CYD-Klipper/src/ui/macros.cpp
Normal file
75
CYD-Klipper/src/ui/macros.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#include "macros.h"
|
||||||
|
#include "ui_utils.h"
|
||||||
|
#include <Esp.h>
|
||||||
|
#include "../core/data_setup.h"
|
||||||
|
|
||||||
|
PRINTER_CONFIG * curernt_config = NULL;
|
||||||
|
|
||||||
|
static void btn_press(lv_event_t * e){
|
||||||
|
lv_obj_t * btn = lv_event_get_target(e);
|
||||||
|
const char* macro = (const char*)lv_event_get_user_data(e);
|
||||||
|
Serial.printf("Macro: %s\n", macro);
|
||||||
|
send_gcode(false, macro);
|
||||||
|
}
|
||||||
|
|
||||||
|
void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < query.count; i++){
|
||||||
|
const char* macro = query.macros[i];
|
||||||
|
lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void power_device_toggle(lv_event_t * e)
|
||||||
|
{
|
||||||
|
auto state = lv_obj_get_state(lv_event_get_target(e));
|
||||||
|
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
|
||||||
|
const char* power_device_name = (const char*)lv_event_get_user_data(e);
|
||||||
|
Serial.printf("Power Device: %s, State: %d -> %d\n", power_device_name, !checked, checked);
|
||||||
|
|
||||||
|
if (curernt_config != NULL)
|
||||||
|
set_power_state(power_device_name, checked, curernt_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < query.count; i++){
|
||||||
|
const char* power_device_name = query.power_devices[i];
|
||||||
|
const bool power_device_state = query.power_states[i];
|
||||||
|
lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void macros_draw_power_fullscreen(PRINTER_CONFIG * config)
|
||||||
|
{
|
||||||
|
curernt_config = config;
|
||||||
|
|
||||||
|
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
|
||||||
|
lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0);
|
||||||
|
lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||||
|
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
|
||||||
|
lv_layout_flex_column(parent);
|
||||||
|
|
||||||
|
lv_obj_set_size(lv_create_empty_panel(parent), 0, 0);
|
||||||
|
|
||||||
|
auto width = CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;
|
||||||
|
|
||||||
|
lv_obj_t * btn = lv_btn_create(parent);
|
||||||
|
lv_obj_set_size(btn, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
|
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, parent);
|
||||||
|
|
||||||
|
lv_obj_t * label = lv_label_create(btn);
|
||||||
|
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
|
||||||
|
lv_obj_center(label);
|
||||||
|
|
||||||
|
MACROSQUERY query = macros_query(config);
|
||||||
|
POWERQUERY power = power_devices_query(config);
|
||||||
|
|
||||||
|
macros_add_macros_to_panel(parent, query);
|
||||||
|
macros_add_power_devices_to_panel(parent, power);
|
||||||
|
}
|
||||||
|
|
||||||
|
void macros_draw_power_fullscreen()
|
||||||
|
{
|
||||||
|
macros_draw_power_fullscreen(get_current_printer_config());
|
||||||
|
}
|
||||||
9
CYD-Klipper/src/ui/macros.h
Normal file
9
CYD-Klipper/src/ui/macros.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "lvgl.h"
|
||||||
|
#include "../core/macros_query.h"
|
||||||
|
|
||||||
|
void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query);
|
||||||
|
void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query);
|
||||||
|
void macros_draw_power_fullscreen(PRINTER_CONFIG * config);
|
||||||
|
void macros_draw_power_fullscreen();
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "../core/macros_query.h"
|
#include "../core/macros_query.h"
|
||||||
#include "../core/lv_setup.h"
|
#include "../core/lv_setup.h"
|
||||||
#include "switch_printer.h"
|
#include "switch_printer.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
char extruder_temp_buff[20];
|
char extruder_temp_buff[20];
|
||||||
char bed_temp_buff[20];
|
char bed_temp_buff[20];
|
||||||
@@ -37,7 +38,7 @@ void error_ui_macros_open(lv_event_t * e){
|
|||||||
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
|
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
|
||||||
lv_obj_center(label);
|
lv_obj_center(label);
|
||||||
|
|
||||||
macros_panel_add_power_devices_to_panel(panel, power_devices_query());
|
macros_add_power_devices_to_panel(panel, power_devices_query());
|
||||||
}
|
}
|
||||||
|
|
||||||
void error_ui(){
|
void error_ui(){
|
||||||
@@ -81,7 +82,7 @@ void error_ui(){
|
|||||||
lv_label_set_text(label, "FW Restart");
|
lv_label_set_text(label, "FW Restart");
|
||||||
lv_obj_center(label);
|
lv_obj_center(label);
|
||||||
|
|
||||||
if (power_devices_query().count >= 1){
|
if (power_devices_count() >= 1){
|
||||||
btn = lv_btn_create(button_row);
|
btn = lv_btn_create(button_row);
|
||||||
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL);
|
lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL);
|
||||||
|
|||||||
@@ -1,49 +1,15 @@
|
|||||||
#include "lvgl.h"
|
#include "../macros.h"
|
||||||
#include "panel.h"
|
#include "panel.h"
|
||||||
#include "../nav_buttons.h"
|
#include "../nav_buttons.h"
|
||||||
#include "../../core/data_setup.h"
|
#include "../../core/data_setup.h"
|
||||||
#include "../../core/macros_query.h"
|
|
||||||
#include "../../conf/global_config.h"
|
#include "../../conf/global_config.h"
|
||||||
#include "../ui_utils.h"
|
#include "../ui_utils.h"
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
|
|
||||||
|
|
||||||
static void btn_press(lv_event_t * e){
|
|
||||||
lv_obj_t * btn = lv_event_get_target(e);
|
|
||||||
const char* macro = (const char*)lv_event_get_user_data(e);
|
|
||||||
Serial.printf("Macro: %s\n", macro);
|
|
||||||
send_gcode(false, macro);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void btn_goto_settings(lv_event_t * e){
|
static void btn_goto_settings(lv_event_t * e){
|
||||||
nav_buttons_setup(3);
|
nav_buttons_setup(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){
|
|
||||||
for (int i = 0; i < query.count; i++){
|
|
||||||
const char* macro = query.macros[i];
|
|
||||||
lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void power_device_toggle(lv_event_t * e){
|
|
||||||
auto state = lv_obj_get_state(lv_event_get_target(e));
|
|
||||||
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
|
|
||||||
const char* power_device_name = (const char*)lv_event_get_user_data(e);
|
|
||||||
Serial.printf("Power Device: %s, State: %d -> %d\n", power_device_name, !checked, checked);
|
|
||||||
|
|
||||||
set_power_state(power_device_name, checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query){
|
|
||||||
for (int i = 0; i < query.count; i++){
|
|
||||||
const char* power_device_name = query.power_devices[i];
|
|
||||||
const bool power_device_state = query.power_states[i];
|
|
||||||
lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void macros_panel_init(lv_obj_t* panel) {
|
void macros_panel_init(lv_obj_t* panel) {
|
||||||
lv_obj_t * btn = lv_btn_create(panel);
|
lv_obj_t * btn = lv_btn_create(panel);
|
||||||
lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL);
|
lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL);
|
||||||
@@ -69,6 +35,6 @@ void macros_panel_init(lv_obj_t* panel) {
|
|||||||
lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2);
|
lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2);
|
||||||
lv_layout_flex_column(root_panel);
|
lv_layout_flex_column(root_panel);
|
||||||
|
|
||||||
macros_panel_add_power_devices_to_panel(root_panel, power);
|
macros_add_power_devices_to_panel(root_panel, power);
|
||||||
macros_panel_add_macros_to_panel(root_panel, query);
|
macros_add_macros_to_panel(root_panel, query);
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,3 @@ void progress_panel_init(lv_obj_t* panel);
|
|||||||
void macros_panel_init(lv_obj_t* panel);
|
void macros_panel_init(lv_obj_t* panel);
|
||||||
void stats_panel_init(lv_obj_t* panel);
|
void stats_panel_init(lv_obj_t* panel);
|
||||||
void printer_panel_init(lv_obj_t* panel);
|
void printer_panel_init(lv_obj_t* panel);
|
||||||
void macros_panel_add_power_devices_to_panel(lv_obj_t * panel, POWERQUERY query);
|
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "../nav_buttons.h"
|
#include "../nav_buttons.h"
|
||||||
#include "../../core/macros_query.h"
|
#include "../../core/macros_query.h"
|
||||||
#include "../switch_printer.h"
|
#include "../switch_printer.h"
|
||||||
|
#include "../macros.h"
|
||||||
|
|
||||||
const char * printer_status[] = {
|
const char * printer_status[] = {
|
||||||
"Error",
|
"Error",
|
||||||
@@ -83,34 +84,56 @@ static void update_printer_percentage_text(lv_event_t * e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btn_disable_if_controlled(lv_event_t * e)
|
static void update_printer_control_button_text(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_obj_t * label = lv_event_get_target(e);
|
||||||
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
|
int index = config - global_config.printer_config;
|
||||||
|
PrinterMinimal * printer = &printer_minimal[index];
|
||||||
|
|
||||||
|
if (!printer->online && printer->power_devices > 0)
|
||||||
|
{
|
||||||
|
lv_label_set_text(label, "Power");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lv_label_set_text(label, "Control");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btn_enable_delete(lv_event_t * e)
|
||||||
{
|
{
|
||||||
lv_obj_t * btn = lv_event_get_target(e);
|
lv_obj_t * btn = lv_event_get_target(e);
|
||||||
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
|
|
||||||
if (config == get_current_printer_config())
|
if (config == get_current_printer_config())
|
||||||
{
|
{
|
||||||
|
// Disable
|
||||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Enable
|
||||||
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btn_disable_if_controlled_or_offline(lv_event_t * e)
|
static void btn_enable_control(lv_event_t * e)
|
||||||
{
|
{
|
||||||
lv_obj_t * btn = lv_event_get_target(e);
|
lv_obj_t * btn = lv_event_get_target(e);
|
||||||
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
int index = config - global_config.printer_config;
|
int index = config - global_config.printer_config;
|
||||||
PrinterMinimal * printer = &printer_minimal[index];
|
PrinterMinimal * printer = &printer_minimal[index];
|
||||||
|
|
||||||
if (config == get_current_printer_config() || !printer->online)
|
if (config == get_current_printer_config() || (!printer->online && printer->power_devices < 0))
|
||||||
{
|
{
|
||||||
|
// Disable
|
||||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Enable
|
||||||
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,6 +178,13 @@ static void btn_printer_activate(lv_event_t * e)
|
|||||||
lv_obj_t * label = lv_event_get_target(e);
|
lv_obj_t * label = lv_event_get_target(e);
|
||||||
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||||
int index = config - global_config.printer_config;
|
int index = config - global_config.printer_config;
|
||||||
|
PrinterMinimal * printer = &printer_minimal[index];
|
||||||
|
|
||||||
|
if (!printer->online)
|
||||||
|
{
|
||||||
|
macros_draw_power_fullscreen(config);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch_printer(index);
|
switch_printer(index);
|
||||||
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
|
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
|
||||||
@@ -203,7 +233,7 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root)
|
|||||||
lv_obj_t * btn = lv_btn_create(button_row);
|
lv_obj_t * btn = lv_btn_create(button_row);
|
||||||
lv_obj_set_flex_grow(btn, 1);
|
lv_obj_set_flex_grow(btn, 1);
|
||||||
lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config);
|
lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config);
|
||||||
lv_obj_add_event_cb(btn, btn_disable_if_controlled, LV_EVENT_MSG_RECEIVED, config);
|
lv_obj_add_event_cb(btn, btn_enable_delete, LV_EVENT_MSG_RECEIVED, config);
|
||||||
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
||||||
|
|
||||||
label = lv_label_create(btn);
|
label = lv_label_create(btn);
|
||||||
@@ -221,12 +251,13 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root)
|
|||||||
btn = lv_btn_create(button_row);
|
btn = lv_btn_create(button_row);
|
||||||
lv_obj_set_flex_grow(btn, 2);
|
lv_obj_set_flex_grow(btn, 2);
|
||||||
lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config);
|
lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config);
|
||||||
lv_obj_add_event_cb(btn, btn_disable_if_controlled_or_offline, LV_EVENT_MSG_RECEIVED, config);
|
lv_obj_add_event_cb(btn, btn_enable_control, LV_EVENT_MSG_RECEIVED, config);
|
||||||
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
|
||||||
|
|
||||||
label = lv_label_create(btn);
|
label = lv_label_create(btn);
|
||||||
lv_label_set_text(label, "Control");
|
|
||||||
lv_obj_center(label);
|
lv_obj_center(label);
|
||||||
|
lv_obj_add_event_cb(label, update_printer_control_button_text, LV_EVENT_MSG_RECEIVED, config);
|
||||||
|
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config);
|
||||||
|
|
||||||
lv_obj_t * line = lv_line_create(root);
|
lv_obj_t * line = lv_line_create(root);
|
||||||
lv_line_set_points(line, line_points, 2);
|
lv_line_set_points(line, line_points, 2);
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ void switch_printer(int index)
|
|||||||
set_printer_config_index(index);
|
set_printer_config_index(index);
|
||||||
set_color_scheme();
|
set_color_scheme();
|
||||||
set_invert_display();
|
set_invert_display();
|
||||||
_macros_query_internal();
|
|
||||||
_power_devices_query_internal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btn_switch_printer(lv_event_t *e){
|
static void btn_switch_printer(lv_event_t *e){
|
||||||
|
|||||||
Reference in New Issue
Block a user