Longer watchdog timeout, refactor, use duty cycle for backlight

This commit is contained in:
suchmememanyskill
2024-01-19 21:05:57 +01:00
parent 9136f4c94b
commit 082d66ca10
2 changed files with 12 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
#include "../conf/global_config.h" #include "../conf/global_config.h"
#include <HTTPClient.h> #include <HTTPClient.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <esp_task_wdt.h>
#include "macros_query.h" #include "macros_query.h"
const char *printer_state_messages[] = { const char *printer_state_messages[] = {
@@ -64,7 +65,6 @@ void send_gcode(bool wait, const char *gcode)
void fetch_printer_data() void fetch_printer_data()
{ {
bool frozen = true;
freeze_request_thread(); freeze_request_thread();
char buff[256] = {}; 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); 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; int printer_state = printer.state;
delay(10); delay(10);
unfreeze_request_thread(); unfreeze_request_thread();
frozen = false;
freeze_render_thread(); freeze_render_thread();
if (status.containsKey("webhooks")) if (status.containsKey("webhooks"))
@@ -196,11 +195,9 @@ void fetch_printer_data()
{ {
klipper_request_consecutive_fail_count++; klipper_request_consecutive_fail_count++;
Serial.printf("Failed to fetch printer data: %d\n", httpCode); Serial.printf("Failed to fetch printer data: %d\n", httpCode);
}
if (frozen)
unfreeze_request_thread(); unfreeze_request_thread();
} }
}
void data_loop() void data_loop()
{ {
@@ -211,6 +208,7 @@ void data_loop()
} }
void data_loop_background(void * param){ void data_loop_background(void * param){
esp_task_wdt_init(10, true);
while (true){ while (true){
delay(data_update_interval); delay(data_update_interval);
fetch_printer_data(); fetch_printer_data();

View File

@@ -84,7 +84,11 @@ void touchscreen_calibrate(bool force)
void screen_setBrightness(byte brightness) 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() void set_screen_brightness()
@@ -213,6 +217,10 @@ void screen_setup()
lv_init(); lv_init();
tft.init(); tft.init();
ledcSetup(0, 5000, 12);
ledcAttachPin(21, 0);
tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.setRotation(global_config.rotateScreen ? 3 : 1);
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
set_screen_brightness(); set_screen_brightness();