diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 49713aa..b02b986 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -4,6 +4,7 @@ #include "../conf/global_config.h" #include #include +#include #include "macros_query.h" const char *printer_state_messages[] = { @@ -64,7 +65,6 @@ void send_gcode(bool wait, const char *gcode) void fetch_printer_data() { - bool frozen = true; freeze_request_thread(); char buff[256] = {}; sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks", global_config.klipperHost, global_config.klipperPort); @@ -83,7 +83,6 @@ void fetch_printer_data() int printer_state = printer.state; delay(10); unfreeze_request_thread(); - frozen = false; freeze_render_thread(); if (status.containsKey("webhooks")) @@ -196,10 +195,8 @@ void fetch_printer_data() { klipper_request_consecutive_fail_count++; Serial.printf("Failed to fetch printer data: %d\n", httpCode); - } - - if (frozen) unfreeze_request_thread(); + } } void data_loop() @@ -211,6 +208,7 @@ void data_loop() } void data_loop_background(void * param){ + esp_task_wdt_init(10, true); while (true){ delay(data_update_interval); fetch_printer_data(); diff --git a/CYD-Klipper/src/core/screen_driver.cpp b/CYD-Klipper/src/core/screen_driver.cpp index e419ab5..ae06f78 100644 --- a/CYD-Klipper/src/core/screen_driver.cpp +++ b/CYD-Klipper/src/core/screen_driver.cpp @@ -84,7 +84,11 @@ void touchscreen_calibrate(bool force) void screen_setBrightness(byte brightness) { - analogWrite(TFT_BL, brightness); + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / 255) * brightness; + + // write duty to LEDC + ledcWrite(0, duty); } void set_screen_brightness() @@ -213,6 +217,10 @@ void screen_setup() lv_init(); tft.init(); + + ledcSetup(0, 5000, 12); + ledcAttachPin(21, 0); + tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_screen_brightness();