From 5d9a5b3f609c13ade0d2f39cd82fb1bfa62ed535 Mon Sep 17 00:00:00 2001 From: Wolfieee Wolf Date: Tue, 1 Jul 2025 17:37:13 +1000 Subject: [PATCH] Clean up code: remove excessive comments and debug bloat - Remove verbose comments explaining obvious functionality - Keep only essential minimal comments where needed - Clean, production-ready code with no debug remnants - Maintains all functionality while reducing code bloat --- Controllers/DDPController/DDPController.cpp | 19 +++++++------------ Controllers/DDPController/DDPController.h | 9 +++------ .../DDPController/DDPControllerDetect.cpp | 3 +-- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Controllers/DDPController/DDPController.cpp b/Controllers/DDPController/DDPController.cpp index 430e61f67..733ad345b 100644 --- a/Controllers/DDPController/DDPController.cpp +++ b/Controllers/DDPController/DDPController.cpp @@ -18,12 +18,11 @@ DDPController::DDPController(const std::vector& device_list) unique_endpoints = NULL; num_endpoints = 0; sequence_number = 0; - keepalive_time_ms = 1000; // Default to 1 second keepalive as WLED times out quickly + keepalive_time_ms = 1000; keepalive_thread_run = false; InitializeNetPorts(); - // Start keepalive thread if(!devices.empty()) { keepalive_thread_run = true; @@ -33,7 +32,6 @@ DDPController::DDPController(const std::vector& device_list) DDPController::~DDPController() { - // Stop keepalive thread keepalive_thread_run = false; if(keepalive_thread.joinable()) { @@ -146,7 +144,6 @@ void DDPController::UpdateLEDs(const std::vector& colors) { if(udp_ports.empty()) return; - // Store colors and time for keepalive { std::lock_guard lock(last_update_mutex); last_colors = colors; @@ -223,11 +220,10 @@ bool DDPController::SendDDPPacket(const DDPDevice& device, const unsigned char* std::vector packet(DDP_HEADER_SIZE + length); ddp_header* header = (ddp_header*)packet.data(); - // CRITICAL FIX: Use 0x41 instead of 0x40 - WLED requires the Push bit to be set header->flags = DDP_FLAG_VER_1 | DDP_FLAG_PUSH; - header->sequence = sequence_number & 0x0F; // Only use 4-bit nibble (0-15) per DDP spec - header->data_type = 1; // RGB data type (keeping simple value for compatibility) - header->dest_id = 1; // Default output device + header->sequence = sequence_number & 0x0F; + header->data_type = 1; + header->dest_id = 1; header->data_offset = htonl(offset); header->data_length = htons(length); @@ -247,9 +243,9 @@ void DDPController::KeepaliveThreadFunction() { while(keepalive_thread_run) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Check every 100ms + std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if(keepalive_time_ms == 0) // Keepalive disabled + if(keepalive_time_ms == 0) continue; std::vector colors_to_send; @@ -264,13 +260,12 @@ void DDPController::KeepaliveThreadFunction() { colors_to_send = last_colors; should_send = true; - last_update_time = now; // Reset timer + last_update_time = now; } } if(should_send) { - // Send keepalive packet with last known colors unsigned int color_index = 0; for(unsigned int dev_idx = 0; dev_idx < devices.size(); dev_idx++) diff --git a/Controllers/DDPController/DDPController.h b/Controllers/DDPController/DDPController.h index a0bb5e931..268792fa0 100644 --- a/Controllers/DDPController/DDPController.h +++ b/Controllers/DDPController/DDPController.h @@ -33,11 +33,8 @@ #define DDP_FLAG_QUERY 0x02 #define DDP_FLAG_PUSH 0x01 -// DDP Data Type definitions (bits: C R TTT SSS) -// C: 0=standard, 1=custom; R: reserved; TTT: data type; SSS: size -// For maximum compatibility, we use simple value 1 instead of proper encoding -#define DDP_TYPE_RGB8 0x0B // TTT=001 (RGB), SSS=011 (8-bit) - spec compliant -#define DDP_TYPE_RGB_SIMPLE 1 // Simple RGB value for compatibility +#define DDP_TYPE_RGB8 0x0B +#define DDP_TYPE_RGB_SIMPLE 1 #pragma pack(push, 1) struct ddp_header @@ -81,7 +78,7 @@ private: unsigned int num_endpoints; unsigned char sequence_number; - // Keepalive functionality + std::atomic keepalive_thread_run; std::thread keepalive_thread; std::mutex last_update_mutex; diff --git a/Controllers/DDPController/DDPControllerDetect.cpp b/Controllers/DDPController/DDPControllerDetect.cpp index 61eb506ef..ed4008cd4 100644 --- a/Controllers/DDPController/DDPControllerDetect.cpp +++ b/Controllers/DDPController/DDPControllerDetect.cpp @@ -23,11 +23,10 @@ void DetectDDPControllers() json ddp_settings; std::vector> device_lists; DDPDevice dev; - unsigned int keepalive_time = 1000; // Default 1 second + unsigned int keepalive_time = 1000; ddp_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("DDPDevices"); - // Read keepalive setting if(ddp_settings.contains("keepalive_time")) { keepalive_time = ddp_settings["keepalive_time"];