Skip to content

Commit

Permalink
Longer watchdog timeout, refactor, use duty cycle for backlight
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jan 19, 2024
1 parent 9136f4c commit 082d66c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../conf/global_config.h"
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <esp_task_wdt.h>
#include "macros_query.h"

const char *printer_state_messages[] = {
Expand Down Expand Up @@ -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);
Expand All @@ -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"))
Expand Down Expand Up @@ -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()
Expand All @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion CYD-Klipper/src/core/screen_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 082d66c

Please sign in to comment.