UX tweaks

This commit is contained in:
2026-03-19 22:04:07 +01:00
parent a5f4b71163
commit 4c21aa1353

View File

@@ -1,22 +1,21 @@
#include "light_driver.h"
#include <esp_zigbee_core.h>
#include "driver/ledc.h"
#include "esp_log.h"
#include "esp_err.h"
#include <stdbool.h>
#include <math.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
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));
}
}