mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Fix Klipper params being non-blocking
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "data_setup.h"
|
||||
#include "current_printer.h"
|
||||
#include "semaphore.h"
|
||||
|
||||
bool current_printer_move_printer(const char* axis, float amount, bool relative)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#include "data_setup.h"
|
||||
#include "semaphore.h"
|
||||
#include <esp_task_wdt.h>
|
||||
#include <UrlEncode.h>
|
||||
#include "printer_integration.hpp"
|
||||
@@ -8,32 +9,8 @@
|
||||
#include "bambu/bambu_printer_integration.hpp"
|
||||
#include "octoprint/octoprint_printer_integration.hpp"
|
||||
|
||||
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
|
||||
const long data_update_interval = 780;
|
||||
|
||||
void semaphore_init(){
|
||||
freezeRenderThreadSemaphore = xSemaphoreCreateMutex();
|
||||
freezeRequestThreadSemaphore = xSemaphoreCreateMutex();
|
||||
xSemaphoreGive(freezeRenderThreadSemaphore);
|
||||
xSemaphoreGive(freezeRequestThreadSemaphore);
|
||||
}
|
||||
|
||||
void freeze_request_thread(){
|
||||
xSemaphoreTake(freezeRequestThreadSemaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void unfreeze_request_thread(){
|
||||
xSemaphoreGive(freezeRequestThreadSemaphore);
|
||||
}
|
||||
|
||||
void freeze_render_thread(){
|
||||
xSemaphoreTake(freezeRenderThreadSemaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void unfreeze_render_thread(){
|
||||
xSemaphoreGive(freezeRenderThreadSemaphore);
|
||||
}
|
||||
|
||||
void fetch_printer_data()
|
||||
{
|
||||
freeze_request_thread();
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void data_loop();
|
||||
void data_setup();
|
||||
|
||||
void freeze_request_thread();
|
||||
void unfreeze_request_thread();
|
||||
void data_setup();
|
||||
@@ -3,6 +3,27 @@
|
||||
#include "../../ui/ui_utils.h"
|
||||
#include "../common/constants.h"
|
||||
#include <stdio.h>
|
||||
#include "../semaphore.h"
|
||||
|
||||
bool send_gcode_blocking(const char *gcode, bool wait = true)
|
||||
{
|
||||
freeze_request_thread();
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
bool result = printer->send_gcode(gcode);
|
||||
unfreeze_request_thread();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool move_printer_blocking(const char* axis, float amount, bool relative)
|
||||
{
|
||||
freeze_request_thread();
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
bool result = printer->move_printer(axis, amount, relative);
|
||||
unfreeze_request_thread();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void set_fan_speed_text(lv_event_t * e) {
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
@@ -14,10 +35,9 @@ static void set_fan_speed_text(lv_event_t * e) {
|
||||
static void set_fan_speed(lv_event_t * e){
|
||||
int speed = (int)lv_event_get_user_data(e);
|
||||
int actual_speed = fan_percent_to_byte(speed);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
char gcode[16];
|
||||
sprintf(gcode, "M106 S%d", actual_speed);
|
||||
printer->send_gcode(gcode);
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
FAN_SPEED_COLUMN(set_fan_speed, klipper_fan_speed_columns)
|
||||
@@ -40,24 +60,21 @@ static void set_zoffset_text_ex(lv_event_t * e) {
|
||||
|
||||
static void set_zoffset(lv_event_t * e){
|
||||
char* offset = (char*)lv_event_get_user_data(e);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
|
||||
char gcode[48];
|
||||
sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s MOVE=1", offset);
|
||||
printer->send_gcode(gcode);
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
static void set_z(lv_event_t * e){
|
||||
void* ptr = lv_event_get_user_data(e);
|
||||
float value = *(float *)(&ptr);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
|
||||
if (value < 0) {
|
||||
printer->send_gcode("SET_GCODE_OFFSET Z=0 MOVE=1");
|
||||
send_gcode_blocking("SET_GCODE_OFFSET Z=0 MOVE=1");
|
||||
return;
|
||||
}
|
||||
|
||||
printer->move_printer("Z", value, false);
|
||||
move_printer_blocking("Z", value, false);
|
||||
}
|
||||
|
||||
const char* zoffsets[] = { "-0.01", "-0.025", "-0.05", "-0.2" };
|
||||
@@ -80,20 +97,18 @@ static void set_speed_mult_text(lv_event_t * e){
|
||||
|
||||
static void set_speed_mult(lv_event_t * e){
|
||||
int speed = (int)lv_event_get_user_data(e);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
char gcode[16];
|
||||
sprintf(gcode, "M220 S%d", speed);
|
||||
printer->send_gcode(gcode);
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
static void set_speed_mult_offset(lv_event_t * e){
|
||||
int speed = (int)lv_event_get_user_data(e);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
float result = get_current_printer_data()->speed_mult * 100 + speed;
|
||||
get_current_printer_data()->speed_mult = result / 100;
|
||||
char gcode[16];
|
||||
sprintf(gcode, "M220 S%.0f", result);
|
||||
printer->send_gcode(gcode);
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
const char* speed_presets[] = { "50%", "100%", "150%", "200%" };
|
||||
@@ -118,20 +133,19 @@ static void set_extrude_mult_text(lv_event_t * e){
|
||||
|
||||
static void set_extrude_mult(lv_event_t * e){
|
||||
int speed = (int)lv_event_get_user_data(e);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
char gcode[16];
|
||||
sprintf(gcode, "M221 S%d", speed);
|
||||
printer->send_gcode(gcode);
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
static void set_extrude_mult_offset(lv_event_t * e){
|
||||
int speed = (int)lv_event_get_user_data(e);
|
||||
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
|
||||
float result = get_current_printer_data()->extrude_mult * 100 + speed;
|
||||
get_current_printer_data()->extrude_mult = result / 100;
|
||||
char gcode[16];
|
||||
sprintf(gcode, "M221 S%.0f", result);
|
||||
printer->send_gcode(gcode);
|
||||
|
||||
send_gcode_blocking(gcode);
|
||||
}
|
||||
|
||||
const char* extrude_presets[] = { "95%", "100%", "105%", "110%" };
|
||||
@@ -145,7 +159,7 @@ lv_button_column_t extrude_mult_columns[] = {
|
||||
};
|
||||
|
||||
static void open_fan_speed_panel(lv_event_t * e){
|
||||
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, klipper_fan_speed_columns, 2);
|
||||
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, klipper_fan_speed_columns, 3);
|
||||
}
|
||||
|
||||
static void open_zoffset_panel(lv_event_t * e){
|
||||
|
||||
28
CYD-Klipper/src/core/semaphore.cpp
Normal file
28
CYD-Klipper/src/core/semaphore.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "semaphore.h"
|
||||
#include <UrlEncode.h>
|
||||
#include <esp_task_wdt.h>
|
||||
|
||||
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
|
||||
|
||||
void semaphore_init(){
|
||||
freezeRenderThreadSemaphore = xSemaphoreCreateMutex();
|
||||
freezeRequestThreadSemaphore = xSemaphoreCreateMutex();
|
||||
xSemaphoreGive(freezeRenderThreadSemaphore);
|
||||
xSemaphoreGive(freezeRequestThreadSemaphore);
|
||||
}
|
||||
|
||||
void freeze_request_thread(){
|
||||
xSemaphoreTake(freezeRequestThreadSemaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void unfreeze_request_thread(){
|
||||
xSemaphoreGive(freezeRequestThreadSemaphore);
|
||||
}
|
||||
|
||||
void freeze_render_thread(){
|
||||
xSemaphoreTake(freezeRenderThreadSemaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void unfreeze_render_thread(){
|
||||
xSemaphoreGive(freezeRenderThreadSemaphore);
|
||||
}
|
||||
11
CYD-Klipper/src/core/semaphore.h
Normal file
11
CYD-Klipper/src/core/semaphore.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
void semaphore_init();
|
||||
|
||||
void freeze_request_thread();
|
||||
void unfreeze_request_thread();
|
||||
|
||||
// Don't use unless you want trouble
|
||||
void freeze_render_thread();
|
||||
// Don't use unless you want trouble
|
||||
void unfreeze_render_thread();
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <Esp.h>
|
||||
#include "../core/current_printer.h"
|
||||
#include "../core/data_setup.h"
|
||||
#include "../core/semaphore.h"
|
||||
|
||||
typedef struct {
|
||||
const char* power_device_name;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../core/data_setup.h"
|
||||
#include "../conf/global_config.h"
|
||||
#include "ota_setup.h"
|
||||
#include "../core/semaphore.h"
|
||||
|
||||
//const char *ota_url = "https://gist.githubusercontent.com/suchmememanyskill/ece418fe199e155340de6c224a0badf2/raw/0d6762d68bc807cbecc71e40d55b76692397a7b3/update.json"; // Test url
|
||||
const char *ota_url = "https://suchmememanyskill.github.io/CYD-Klipper/OTA.json"; // Prod url
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../core/lv_setup.h"
|
||||
#include "serial/serial_console.h"
|
||||
#include "panels/panel.h"
|
||||
#include "../core/semaphore.h"
|
||||
|
||||
void wifi_init_inner();
|
||||
void wifi_pass_entry(const char* ssid);
|
||||
|
||||
Reference in New Issue
Block a user