mirror of
https://github.com/pmarchini/Esp32Dimmer.git
synced 2026-02-07 03:08:07 +03:00
Remove dead code and fix pulse width timing precision
Co-authored-by: pmarchini <49943249+pmarchini@users.noreply.github.com>
This commit is contained in:
@@ -81,27 +81,6 @@ static void init_event_queue(void)
|
|||||||
event_queue_size = 0;
|
event_queue_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Find the next event in queue (earliest timestamp)
|
|
||||||
* @return Index of next event, or -1 if queue is empty
|
|
||||||
*/
|
|
||||||
static int find_next_event_index(void)
|
|
||||||
{
|
|
||||||
int next_idx = -1;
|
|
||||||
uint64_t earliest_time = UINT64_MAX;
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TIMER_EVENTS; i++)
|
|
||||||
{
|
|
||||||
if (event_queue[i].active && event_queue[i].timestamp < earliest_time)
|
|
||||||
{
|
|
||||||
earliest_time = event_queue[i].timestamp;
|
|
||||||
next_idx = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return next_idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Schedule a timer event
|
* @brief Schedule a timer event
|
||||||
* @param timestamp Absolute timestamp when event should occur
|
* @param timestamp Absolute timestamp when event should occur
|
||||||
@@ -479,8 +458,9 @@ static void IRAM_ATTR onTimerISR(void *para)
|
|||||||
// Fire the triac
|
// Fire the triac
|
||||||
gpio_set_level(dimOutPin[event->dimmer_id], 1);
|
gpio_set_level(dimOutPin[event->dimmer_id], 1);
|
||||||
|
|
||||||
// Schedule pulse end event using pre-calculated pulse width
|
// Schedule pulse end event based on the event's original fire time
|
||||||
uint64_t pulse_end_time = current_time + pulse_width_ticks;
|
// to maintain precise pulse width
|
||||||
|
uint64_t pulse_end_time = event->timestamp + pulse_width_ticks;
|
||||||
bool scheduled = schedule_timer_event(pulse_end_time, event->dimmer_id, EVENT_END_PULSE);
|
bool scheduled = schedule_timer_event(pulse_end_time, event->dimmer_id, EVENT_END_PULSE);
|
||||||
|
|
||||||
// If scheduling failed, turn off triac immediately to prevent it staying on
|
// If scheduling failed, turn off triac immediately to prevent it staying on
|
||||||
|
|||||||
Reference in New Issue
Block a user