mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Implement move ui
This commit is contained in:
@@ -19,7 +19,6 @@ lib_deps =
|
||||
https://github.com/Bodmer/TFT_eSPI.git
|
||||
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
|
||||
bblanchon/ArduinoJson@^6.21.3
|
||||
links2004/WebSockets@^2.4.1
|
||||
build_flags =
|
||||
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
|
||||
-DUSER_SETUP_LOADED=1
|
||||
|
||||
@@ -326,7 +326,7 @@
|
||||
/*Montserrat fonts with ASCII range and some symbols using bpp = 4
|
||||
*https://fonts.google.com/specimen/Montserrat*/
|
||||
#define LV_FONT_MONTSERRAT_8 0
|
||||
#define LV_FONT_MONTSERRAT_10 0
|
||||
#define LV_FONT_MONTSERRAT_10 1
|
||||
#define LV_FONT_MONTSERRAT_12 0
|
||||
#define LV_FONT_MONTSERRAT_14 1
|
||||
#define LV_FONT_MONTSERRAT_16 0
|
||||
|
||||
@@ -13,6 +13,24 @@ const char * printer_state_messages[] = {
|
||||
|
||||
Printer printer = {0};
|
||||
|
||||
void send_gcode(bool wait, const char* gcode){
|
||||
char buff[256] = {};
|
||||
sprintf(buff, "http://%s:%d/printer/gcode/script?script=%s", global_config.klipperHost, global_config.klipperPort, gcode);
|
||||
HTTPClient client;
|
||||
client.begin(buff);
|
||||
|
||||
if (!wait){
|
||||
client.setTimeout(1000);
|
||||
}
|
||||
|
||||
try {
|
||||
client.GET();
|
||||
}
|
||||
catch (...){
|
||||
Serial.println("Failed to send gcode");
|
||||
}
|
||||
}
|
||||
|
||||
void fetch_printer_state(){
|
||||
char buff[91] = {};
|
||||
sprintf(buff, "http://%s:%d/printer/info", global_config.klipperHost, global_config.klipperPort);
|
||||
@@ -21,7 +39,6 @@ void fetch_printer_state(){
|
||||
int httpCode = client.GET();
|
||||
if (httpCode == 200) {
|
||||
String payload = client.getString();
|
||||
Serial.println(payload);
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, payload);
|
||||
auto result = doc["result"];
|
||||
@@ -59,19 +76,20 @@ void fetch_printer_state(){
|
||||
|
||||
void fetch_printer_data(){
|
||||
char buff[256] = {};
|
||||
sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead", global_config.klipperHost, global_config.klipperPort);
|
||||
sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead&gcode_move", global_config.klipperHost, global_config.klipperPort);
|
||||
HTTPClient client;
|
||||
client.begin(buff);
|
||||
int httpCode = client.GET();
|
||||
if (httpCode == 200) {
|
||||
String payload = client.getString();
|
||||
Serial.println(payload);
|
||||
DynamicJsonDocument doc(2048);
|
||||
deserializeJson(doc, payload);
|
||||
auto status = doc["result"]["status"];
|
||||
if (status.containsKey("extruder")){
|
||||
printer.extruder_temp = status["extruder"]["temperature"];
|
||||
printer.extruder_target_temp = status["extruder"]["target"];
|
||||
bool can_extrude = status["extruder"]["can_extrude"];
|
||||
printer.can_extrude = can_extrude == true;
|
||||
}
|
||||
|
||||
if (status.containsKey("heater_bed")){
|
||||
@@ -83,6 +101,13 @@ void fetch_printer_data(){
|
||||
printer.position[0] = status["toolhead"]["position"][0];
|
||||
printer.position[1] = status["toolhead"]["position"][1];
|
||||
printer.position[2] = status["toolhead"]["position"][2];
|
||||
const char * homed_axis = status["toolhead"]["homed_axes"];
|
||||
printer.homed_axis = strcmp(homed_axis, "xyz") == 0;
|
||||
}
|
||||
|
||||
if (status.containsKey("gcode_move")){
|
||||
bool absolute_coords = status["gcode_move"]["absolute_coordinates"];
|
||||
printer.absolute_coords = absolute_coords == true;
|
||||
}
|
||||
|
||||
lv_msg_send(DATA_PRINTER_DATA, &printer);
|
||||
@@ -92,8 +117,15 @@ void fetch_printer_data(){
|
||||
}
|
||||
}
|
||||
|
||||
long last_data_update = 0;
|
||||
const long data_update_interval = 1500;
|
||||
|
||||
void data_loop(){
|
||||
// TODO: slow down requests
|
||||
if (millis() - last_data_update < data_update_interval)
|
||||
return;
|
||||
|
||||
last_data_update = millis();
|
||||
|
||||
fetch_printer_state();
|
||||
if (printer.state != PRINTER_STATE_ERROR)
|
||||
fetch_printer_data();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
enum {
|
||||
PRINTER_STATE_ERROR = 0,
|
||||
PRINTER_STATE_IDLE = 1,
|
||||
PRINTER_SATE_PRINTING = 2,
|
||||
PRINTER_STATE_PRINTING = 2,
|
||||
};
|
||||
|
||||
extern const char* printer_state_messages[];
|
||||
@@ -16,6 +16,9 @@ typedef struct Printer {
|
||||
float bed_temp;
|
||||
float bed_target_temp;
|
||||
float position[3];
|
||||
unsigned char can_extrude;
|
||||
unsigned char homed_axis;
|
||||
unsigned char absolute_coords;
|
||||
} _Printer;
|
||||
|
||||
extern Printer printer;
|
||||
@@ -24,4 +27,5 @@ extern Printer printer;
|
||||
#define DATA_PRINTER_DATA 2
|
||||
|
||||
void data_loop();
|
||||
void data_setup();
|
||||
void data_setup();
|
||||
void send_gcode(bool wait, const char* gcode);
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "screen_driver.h"
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include "global_config.h"
|
||||
#include "../conf/global_config.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
SPIClass touchscreen_spi = SPIClass(HSPI);
|
||||
@@ -1,41 +0,0 @@
|
||||
#include <WebSocketsClient.h>
|
||||
#include "../conf/global_config.h"
|
||||
|
||||
WebSocketsClient webSocket;
|
||||
|
||||
void websocket_event(WStype_t type, uint8_t * payload, size_t length) {
|
||||
switch(type) {
|
||||
case WStype_DISCONNECTED:
|
||||
Serial.printf("[WSc] Disconnected!\n");
|
||||
break;
|
||||
case WStype_CONNECTED:
|
||||
Serial.printf("[WSc] Connected to url: %s\n", payload);
|
||||
|
||||
// send message to server when Connected
|
||||
webSocket.sendTXT("Connected");
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
Serial.printf("[WSc] get text: %s\n", payload);
|
||||
|
||||
// send message to server
|
||||
// webSocket.sendTXT("message here");
|
||||
break;
|
||||
case WStype_BIN:
|
||||
case WStype_ERROR:
|
||||
case WStype_FRAGMENT_TEXT_START:
|
||||
case WStype_FRAGMENT_BIN_START:
|
||||
case WStype_FRAGMENT:
|
||||
case WStype_FRAGMENT_FIN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void websocket_process(){
|
||||
webSocket.loop();
|
||||
}
|
||||
|
||||
void websocket_setup(){
|
||||
webSocket.begin("192.168.0.122", global_config.klipperPort, "/websocket");
|
||||
webSocket.onEvent(websocket_event);
|
||||
webSocket.setReconnectInterval(5000);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
void websocket_process();
|
||||
void websocket_setup();
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "conf/global_config.h"
|
||||
#include "conf/screen_driver.h"
|
||||
#include "core/screen_driver.h"
|
||||
#include "ui/wifi_setup.h"
|
||||
#include "ui/ip_setup.h"
|
||||
#include "core/websocket_setup.h"
|
||||
#include "lvgl.h"
|
||||
#include "core/data_setup.h"
|
||||
#include "ui/main_ui.h"
|
||||
#include "ui/nav_buttons.h"
|
||||
|
||||
static void event_handler(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
@@ -27,8 +27,9 @@ void setup() {
|
||||
|
||||
wifi_init();
|
||||
ip_setup();
|
||||
websocket_setup();
|
||||
data_setup();
|
||||
|
||||
nav_style_setup();
|
||||
main_ui_setup();
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "main_ui.h"
|
||||
#include "../core/data_setup.h"
|
||||
#include "lvgl.h"
|
||||
#include "nav_buttons.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
char extruder_temp_buff[20];
|
||||
char bed_temp_buff[20];
|
||||
char position_buff[20];
|
||||
|
||||
/*
|
||||
static void update_printer_state(lv_event_t * e){
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
|
||||
@@ -19,7 +20,7 @@ static void update_printer_state_message(lv_event_t * e) {
|
||||
lv_label_set_text(label, printer.state_message);
|
||||
}
|
||||
|
||||
static void update_printer_data_extruder_temp(lv_event_t * e) {
|
||||
static void update_printer_data_temp(lv_event_t * e) {
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
|
||||
sprintf(extruder_temp_buff, "E: %.1f/%.1f", printer.extruder_temp, printer.extruder_target_temp);
|
||||
@@ -59,7 +60,7 @@ void main_ui(){
|
||||
label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "Waiting for update...");
|
||||
lv_obj_align(label, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
||||
lv_obj_add_event_cb(label, update_printer_data_extruder_temp, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_obj_add_event_cb(label, update_printer_data_temp, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
|
||||
label = lv_label_create(lv_scr_act());
|
||||
@@ -74,10 +75,35 @@ void main_ui(){
|
||||
lv_obj_add_event_cb(label, update_printer_data_position, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
}
|
||||
*/
|
||||
|
||||
void error_ui(){
|
||||
lv_obj_clean(lv_scr_act());
|
||||
|
||||
lv_obj_t * label;
|
||||
label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10);
|
||||
|
||||
label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, printer.state_message);
|
||||
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 30);
|
||||
lv_obj_set_size(label, TFT_HEIGHT - 20, TFT_WIDTH - 30);
|
||||
lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||
}
|
||||
|
||||
static void on_state_change(void * s, lv_msg_t * m){
|
||||
if (printer.state == PRINTER_STATE_ERROR){
|
||||
error_ui();
|
||||
}
|
||||
else {
|
||||
nav_buttons_setup(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main_ui_setup(){
|
||||
// TODO: Subscribe to events
|
||||
main_ui();
|
||||
lv_msg_send(DATA_PRINTER_STATE, &printer);
|
||||
lv_msg_send(DATA_PRINTER_DATA, &printer);
|
||||
lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL);
|
||||
on_state_change(NULL, NULL);
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
void main_ui();
|
||||
void main_ui_setup();
|
||||
151
CYD-Klipper-Display/src/ui/nav_buttons.cpp
Normal file
151
CYD-Klipper-Display/src/ui/nav_buttons.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
#include "lvgl.h"
|
||||
#include "panels/panel.h"
|
||||
#include "../core/data_setup.h"
|
||||
#include "nav_buttons.h"
|
||||
#include <HTTPClient.h>
|
||||
|
||||
static lv_style_t nav_button_style;
|
||||
|
||||
static char temp_buffer[10];
|
||||
static char z_pos_buffer[10];
|
||||
|
||||
static lv_style_t nav_button_text_style;
|
||||
|
||||
static void update_printer_data_z_pos(lv_event_t * e) {
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
|
||||
sprintf(z_pos_buffer, "Z%.2f", printer.position[2]);
|
||||
lv_label_set_text(label, z_pos_buffer);
|
||||
}
|
||||
|
||||
static void update_printer_data_temp(lv_event_t * e) {
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
|
||||
sprintf(temp_buffer, "%.0f/%.0f", printer.extruder_temp, printer.bed_temp);
|
||||
lv_label_set_text(label, temp_buffer);
|
||||
}
|
||||
|
||||
static void btn_click_files(lv_event_t * e){
|
||||
nav_buttons_setup(0);
|
||||
}
|
||||
|
||||
static void btn_click_move(lv_event_t * e){
|
||||
nav_buttons_setup(1);
|
||||
}
|
||||
|
||||
static void btn_click_extrude(lv_event_t * e){
|
||||
nav_buttons_setup(2);
|
||||
}
|
||||
|
||||
static void btn_click_settings(lv_event_t * e){
|
||||
nav_buttons_setup(3);
|
||||
}
|
||||
|
||||
void nav_buttons_setup(unsigned char active_panel){
|
||||
lv_obj_clean(lv_scr_act());
|
||||
lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
|
||||
sprintf(temp_buffer, "%.0f/%.0f", printer.extruder_temp, printer.bed_temp);
|
||||
sprintf(z_pos_buffer, "Z%.2f", printer.position[2]);
|
||||
|
||||
const int button_width = 40;
|
||||
const int button_height = 60;
|
||||
const int icon_text_spacing = 10;
|
||||
|
||||
// Files/Print
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, button_width, button_height);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
lv_obj_add_style(btn, &nav_button_style, 0);
|
||||
lv_obj_add_event_cb(btn, btn_click_files, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_COPY);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Idle");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
|
||||
lv_obj_add_style(label, &nav_button_text_style, 0);
|
||||
|
||||
// Move
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, button_width, button_height);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height);
|
||||
lv_obj_add_style(btn, &nav_button_style, 0);
|
||||
lv_obj_add_event_cb(btn, btn_click_move, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_CHARGE);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, z_pos_buffer);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
|
||||
lv_obj_add_event_cb(label, update_printer_data_z_pos, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
lv_obj_add_style(label, &nav_button_text_style, 0);
|
||||
|
||||
// Extrude/Temp
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, button_width, button_height);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 2);
|
||||
lv_obj_add_style(btn, &nav_button_style, 0);
|
||||
lv_obj_add_event_cb(btn, btn_click_extrude, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_WARNING);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, temp_buffer);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
|
||||
lv_obj_add_event_cb(label, update_printer_data_temp, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
lv_obj_add_style(label, &nav_button_text_style, 0);
|
||||
|
||||
// Settings
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, button_width, button_height);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 3);
|
||||
lv_obj_add_style(btn, &nav_button_style, 0);
|
||||
lv_obj_add_event_cb(btn, btn_click_settings, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_SETTINGS);
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Screen");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
|
||||
lv_obj_add_style(label, &nav_button_text_style, 0);
|
||||
|
||||
lv_obj_t * panel = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(panel, TFT_HEIGHT - button_width, TFT_WIDTH);
|
||||
lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_obj_set_style_border_width(panel, 0, 0);
|
||||
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_pad_all(panel, 0, 0);
|
||||
|
||||
switch (active_panel){
|
||||
case 0:
|
||||
print_panel_init(panel);
|
||||
break;
|
||||
case 1:
|
||||
move_panel_init(panel);
|
||||
break;
|
||||
case 2:
|
||||
temp_panel_init(panel);
|
||||
break;
|
||||
case 3:
|
||||
settings_panel_init(panel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void nav_style_setup(){
|
||||
lv_style_init(&nav_button_style);
|
||||
lv_style_set_radius(&nav_button_style, 0);
|
||||
|
||||
lv_style_init(&nav_button_text_style);
|
||||
lv_style_set_text_font(&nav_button_text_style, &lv_font_montserrat_10);
|
||||
}
|
||||
2
CYD-Klipper-Display/src/ui/nav_buttons.h
Normal file
2
CYD-Klipper-Display/src/ui/nav_buttons.h
Normal file
@@ -0,0 +1,2 @@
|
||||
void nav_buttons_setup(unsigned char active_panel);
|
||||
void nav_style_setup();
|
||||
215
CYD-Klipper-Display/src/ui/panels/move_panel.cpp
Normal file
215
CYD-Klipper-Display/src/ui/panels/move_panel.cpp
Normal file
@@ -0,0 +1,215 @@
|
||||
#include "lvgl.h"
|
||||
#include "panel.h"
|
||||
#include "../../core/data_setup.h"
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
static void move_printer(const char* axis, float amount) {
|
||||
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
|
||||
return;
|
||||
|
||||
char gcode[64];
|
||||
const char* extra = (amount > 0) ? "+" : "";
|
||||
|
||||
bool absolute_coords = printer.absolute_coords;
|
||||
|
||||
if (absolute_coords) {
|
||||
send_gcode(true, "G91");
|
||||
}
|
||||
|
||||
const char * space = "%20";
|
||||
|
||||
sprintf(gcode, "G1%s%s%s%.1f", space, axis, extra, amount);
|
||||
send_gcode(true, gcode);
|
||||
|
||||
if (absolute_coords) {
|
||||
send_gcode(true, "G90");
|
||||
}
|
||||
}
|
||||
|
||||
static void x_line_button_press(lv_event_t * e) {
|
||||
float* data_pointer = (float*)lv_event_get_user_data(e);
|
||||
float data = *data_pointer;
|
||||
move_printer("X", data);
|
||||
}
|
||||
|
||||
static void y_line_button_press(lv_event_t * e) {
|
||||
float* data_pointer = (float*)lv_event_get_user_data(e);
|
||||
float data = *data_pointer;
|
||||
move_printer("Y", data);
|
||||
}
|
||||
|
||||
static void z_line_button_press(lv_event_t * e) {
|
||||
float* data_pointer = (float*)lv_event_get_user_data(e);
|
||||
float data = *data_pointer;
|
||||
move_printer("Z", data);
|
||||
}
|
||||
|
||||
char x_pos_buff[12];
|
||||
|
||||
static void x_pos_update(lv_event_t * e){
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
sprintf(x_pos_buff, "X: %.1f", printer.position[0]);
|
||||
lv_label_set_text(label, x_pos_buff);
|
||||
}
|
||||
|
||||
char y_pos_buff[12];
|
||||
|
||||
static void y_pos_update(lv_event_t * e){
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
sprintf(y_pos_buff, "Y: %.1f", printer.position[1]);
|
||||
lv_label_set_text(label, y_pos_buff);
|
||||
}
|
||||
|
||||
char z_pos_buff[12];
|
||||
|
||||
static void z_pos_update(lv_event_t * e){
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
sprintf(z_pos_buff, "Z: %.2f", printer.position[2]);
|
||||
lv_label_set_text(label, z_pos_buff);
|
||||
}
|
||||
|
||||
lv_event_cb_t button_callbacks[] = {x_line_button_press, y_line_button_press, z_line_button_press};
|
||||
lv_event_cb_t position_callbacks[] = {x_pos_update, y_pos_update, z_pos_update};
|
||||
|
||||
const float xy_offsets[] = {-100, -10, -1, 1, 10, 100};
|
||||
const float z_offsets[] = {-25, -1, -0.1, 0.1, 1, 25};
|
||||
const float* offsets[] = {
|
||||
xy_offsets,
|
||||
xy_offsets,
|
||||
z_offsets
|
||||
};
|
||||
|
||||
const char* xy_offset_labels[] = {"-100", "-10", "-1", "+1", "+10", "+100"};
|
||||
const char* z_offset_labels[] = {"-25", "-1", "-0.1", "+0.1", "+1", "+25"};
|
||||
|
||||
const char** offset_labels[] = {
|
||||
xy_offset_labels,
|
||||
xy_offset_labels,
|
||||
z_offset_labels
|
||||
};
|
||||
|
||||
static void home_button_click(lv_event_t * e) {
|
||||
if (printer.state == PRINTER_STATE_PRINTING)
|
||||
return;
|
||||
|
||||
send_gcode(false, "G28");
|
||||
}
|
||||
|
||||
static void disable_steppers_click(lv_event_t * e) {
|
||||
if (printer.state == PRINTER_STATE_PRINTING)
|
||||
return;
|
||||
|
||||
send_gcode(true, "M18");
|
||||
}
|
||||
|
||||
static void stepper_state_update(lv_event_t * e){
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
lv_label_set_text(label, printer.homed_axis ? LV_SYMBOL_HOME " Steppers locked" : LV_SYMBOL_EYE_CLOSE " Steppers unlocked");
|
||||
}
|
||||
|
||||
void move_panel_data(lv_obj_t* panel){
|
||||
lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE);
|
||||
const int button_size = 40;
|
||||
const int button_size_vertical = 40;
|
||||
const int button_padding = 2;
|
||||
const int x_offset = 15;
|
||||
int y_pos = 75;
|
||||
|
||||
auto panel_width = TFT_HEIGHT - 40;
|
||||
|
||||
lv_obj_t * home_button = lv_btn_create(panel);
|
||||
lv_obj_align(home_button, LV_ALIGN_TOP_LEFT, 10, 5);
|
||||
lv_obj_add_event_cb(home_button, home_button_click, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_set_size(home_button, panel_width / 2 - 15, 30);
|
||||
|
||||
lv_obj_t * home_label = lv_label_create(home_button);
|
||||
lv_label_set_text(home_label, LV_SYMBOL_HOME "Home Axis");
|
||||
lv_obj_center(home_label);
|
||||
|
||||
lv_obj_t * disable_steppers_button = lv_btn_create(panel);
|
||||
lv_obj_align(disable_steppers_button, LV_ALIGN_TOP_RIGHT, -10, 5);
|
||||
lv_obj_add_event_cb(disable_steppers_button, disable_steppers_click, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_set_size(disable_steppers_button, panel_width / 2 - 15, 30);
|
||||
|
||||
lv_obj_t * disable_steppers_label = lv_label_create(disable_steppers_button);
|
||||
lv_label_set_text(disable_steppers_label, LV_SYMBOL_EYE_CLOSE "Disable Step");
|
||||
lv_obj_center(disable_steppers_label);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, "???");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 40);
|
||||
lv_obj_add_event_cb(label, stepper_state_update, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i]));
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][0]);
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 1, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 1));
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][1]);
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 2, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 2));
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][2]);
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 3, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 3));
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][3]);
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 4, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 4));
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][4]);
|
||||
lv_obj_center(label);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_size(btn, button_size, button_size_vertical);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 5, y_pos);
|
||||
lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 5));
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, offset_labels[i][5]);
|
||||
lv_obj_center(label);
|
||||
|
||||
label = lv_label_create(panel);
|
||||
lv_label_set_text(label, "???");
|
||||
lv_obj_align(label, LV_ALIGN_TOP_LEFT, x_offset, y_pos - 15);\
|
||||
lv_obj_add_event_cb(label, position_callbacks[i], LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
|
||||
|
||||
y_pos += 60;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void move_panel_init(lv_obj_t* panel){
|
||||
move_panel_data(panel);
|
||||
}
|
||||
6
CYD-Klipper-Display/src/ui/panels/panel.h
Normal file
6
CYD-Klipper-Display/src/ui/panels/panel.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "lvgl.h"
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel);
|
||||
void temp_panel_init(lv_obj_t* panel);
|
||||
void print_panel_init(lv_obj_t* panel);
|
||||
void move_panel_init(lv_obj_t* panel);
|
||||
6
CYD-Klipper-Display/src/ui/panels/print_panel.cpp
Normal file
6
CYD-Klipper-Display/src/ui/panels/print_panel.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "lvgl.h"
|
||||
#include "panel.h"
|
||||
|
||||
void print_panel_init(lv_obj_t* panel){
|
||||
|
||||
}
|
||||
6
CYD-Klipper-Display/src/ui/panels/settings_panel.cpp
Normal file
6
CYD-Klipper-Display/src/ui/panels/settings_panel.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "lvgl.h"
|
||||
#include "panel.h"
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel){
|
||||
|
||||
}
|
||||
6
CYD-Klipper-Display/src/ui/panels/temp_panel.cpp
Normal file
6
CYD-Klipper-Display/src/ui/panels/temp_panel.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "lvgl.h"
|
||||
#include "panel.h"
|
||||
|
||||
void temp_panel_init(lv_obj_t* panel){
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user