Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Controllers/ENESMBusController/ENESMBusController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ void ENESMBusController::SaveMode()

void ENESMBusController::SetAllColorsDirect(RGBColor* colors)
{
auto now = std::chrono::steady_clock::now();

// Throttle updates
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update_time).count() < MIN_UPDATE_MS)
return;

// Skip if colors haven't changed
std::vector<RGBColor> current(colors, colors + led_count);
if(current == last_colors)
return;

last_colors = current;
last_update_time = now;


unsigned char* color_buf = new unsigned char[led_count * 3];
unsigned int bytes_sent = 0;

Expand Down Expand Up @@ -454,6 +469,20 @@ void ENESMBusController::SetAllColorsDirect(RGBColor* colors)

void ENESMBusController::SetAllColorsEffect(RGBColor* colors)
{
auto now = std::chrono::steady_clock::now();

// Throttle updates
if(std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update_time).count() < MIN_UPDATE_MS)
return;

// Skip if colors haven't changed
std::vector<RGBColor> current(colors, colors + led_count);
if(current == last_colors)
return;

last_colors = current;
last_update_time = now;

unsigned char* color_buf = new unsigned char[led_count * 3];
unsigned int bytes_sent = 0;

Expand Down
4 changes: 4 additions & 0 deletions Controllers/ENESMBusController/ENESMBusController.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,8 @@ class ENESMBusController
bool supports_mode_14;
std::string name;
device_type type;

std::vector<RGBColor> LAST_COLOURS; // log of the previous colors
std::chrono::steady_clock::time_point last_update_time; // previous timestamp
static constexpr int MIN_UPDATE_MS = 50; // capped interval between updates
};