From 4c21aa13532216cb3cc00170d6ecfd0323f27f6c Mon Sep 17 00:00:00 2001 From: Drath Date: Thu, 19 Mar 2026 22:04:07 +0100 Subject: [PATCH] UX tweaks --- main/light_driver.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/main/light_driver.c b/main/light_driver.c index 1f5c86b..e3f6a8b 100644 --- a/main/light_driver.c +++ b/main/light_driver.c @@ -1,22 +1,21 @@ #include "light_driver.h" -#include - #include "driver/ledc.h" #include "esp_log.h" #include "esp_err.h" #include #include +#include #include static const char* TAG = "light_driver"; /* tweakable stuff */ -static const uint8_t light_gpio = 15; +static const uint8_t light_gpio = 2; static const uint16_t light_pwm_freq = 65000; static const ledc_timer_bit_t light_pwm_resolution = LEDC_TIMER_10_BIT; -static const double light_lowest_duty_pct = 0.05; // lowest duty percentage where the LEDs still light up nice -static const uint8_t light_identify_level_delta = 60; +static const double light_lowest_duty_pct = 0.001; // lowest duty percentage where the LEDs still light up nice +static const uint8_t light_identify_level_delta = 80; /* no need to tweak this stuff */ static const ledc_channel_t light_ledc_channel = LEDC_CHANNEL_0; @@ -47,10 +46,11 @@ void light_driver_set_power(const bool power) { void light_driver_identify(void) { const uint8_t level = light_driver_get_level(); - light_driver_set_level(MIN(level + light_identify_level_delta, 254)); - vTaskDelay(pdMS_TO_TICKS(350)); - light_driver_set_level(MAX(level - light_identify_level_delta, 0)); - vTaskDelay(pdMS_TO_TICKS(350)); + if (level > 128) + light_driver_set_level(level - light_identify_level_delta); + else + light_driver_set_level(level + light_identify_level_delta); + vTaskDelay(pdMS_TO_TICKS(500)); light_driver_set_level(level); } @@ -58,7 +58,7 @@ void light_driver_task(void *pvParameter) { const ledc_timer_config_t ledc_timer = { .speed_mode = light_ledc_speed_mode, .duty_resolution = light_pwm_resolution, - .timer_num = LEDC_TIMER_2, + .timer_num = LEDC_TIMER_0, .freq_hz = light_pwm_freq, .clk_cfg = LEDC_AUTO_CLK }; @@ -69,12 +69,12 @@ void light_driver_task(void *pvParameter) { .intr_type = LEDC_INTR_DISABLE, .gpio_num = light_gpio, .duty = 0, // Set duty to 0% - .hpoint = (int)light_brightness_steps + .hpoint = 0 }; ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer)); ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel)); - ESP_ERROR_CHECK(ledc_fade_func_install(0)); + // ESP_ERROR_CHECK(ledc_fade_func_install(0)); static uint8_t prev_level = 0; // pre-compute gamma table @@ -100,7 +100,8 @@ void light_driver_task(void *pvParameter) { if (tgt != prev_level) { const int diff = tgt - prev_level; const int abs_diff = abs(diff); - const int step = MIN(abs_diff / 8 + 1, 20); + int step = abs_diff / 16; + if (step == 0) step = 1; if (diff > 0) prev_level += step; @@ -108,8 +109,9 @@ void light_driver_task(void *pvParameter) { prev_level -= step; ESP_LOGI(TAG, "setting light level to %d, tgt is %d, step of %d", prev_level, tgt, step); - ledc_set_duty_and_update(light_ledc_speed_mode, light_ledc_channel, gamma_lut[prev_level], light_brightness_steps); + ledc_set_duty(light_ledc_speed_mode, light_ledc_channel, gamma_lut[prev_level]); + ledc_update_duty(light_ledc_speed_mode, light_ledc_channel); } - vTaskDelay(pdMS_TO_TICKS(20)); + vTaskDelay(pdMS_TO_TICKS(10)); } } \ No newline at end of file