From ba2ce98a3ee3ac52fbc91345d8926b917d6a8112 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 15 Apr 2020 20:39:58 -0500 Subject: [PATCH] Add support for multiple addressable channels in Aura addressable controller. Direct mode only for now --- .../AuraAddressableController.cpp | 32 +++++++++++++------ .../AuraAddressableController.h | 21 +++++++++--- .../RGBController_AuraAddressable.cpp | 16 ++++++---- RGBController/RGBController_AuraAddressable.h | 3 +- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Controllers/AuraAddressableController/AuraAddressableController.cpp b/Controllers/AuraAddressableController/AuraAddressableController.cpp index 14fc1d646..895302616 100644 --- a/Controllers/AuraAddressableController/AuraAddressableController.cpp +++ b/Controllers/AuraAddressableController/AuraAddressableController.cpp @@ -34,25 +34,30 @@ AuraAddressableController::~AuraAddressableController() } +unsigned int AuraAddressableController::GetChannelCount() +{ + return( 1 ); +} + std::string AuraAddressableController::GetDeviceName() { return(device_name); } -void AuraAddressableController::SetLEDsDirect(std::vector colors) +void AuraAddressableController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors) { unsigned char led_data[60]; unsigned int leds_sent = 0; - SendDirectBegin(); + SendDirectBegin(channel); - while(leds_sent < colors.size()) + while(leds_sent < num_colors) { unsigned int leds_to_send = 20; - if((colors.size() - leds_sent) < leds_to_send) + if((num_colors - leds_sent) < leds_to_send) { - leds_to_send = colors.size() - leds_sent; + leds_to_send = num_colors - leds_sent; } for(int led_idx = 0; led_idx < leds_to_send; led_idx++) @@ -64,7 +69,7 @@ void AuraAddressableController::SetLEDsDirect(std::vector colors) SendDirect ( - 0, + channel, leds_sent, leds_to_send, led_data @@ -73,7 +78,7 @@ void AuraAddressableController::SetLEDsDirect(std::vector colors) leds_sent += leds_to_send; } - SendDirectApply(); + SendDirectApply(channel); } void AuraAddressableController::SetMode @@ -235,7 +240,10 @@ void AuraAddressableController::SendDirect hid_write(dev, usb_buf, 65); } -void AuraAddressableController::SendDirectBegin() +void AuraAddressableController::SendDirectBegin + ( + unsigned char channel + ) { unsigned char usb_buf[65]; @@ -249,6 +257,7 @@ void AuraAddressableController::SendDirectBegin() \*-----------------------------------------------------*/ usb_buf[0x00] = 0xEC; usb_buf[0x01] = AURA_CONTROL_MODE_EFFECT; + usb_buf[0x02] = channel; usb_buf[0x04] = 0xFF; /*-----------------------------------------------------*\ @@ -257,7 +266,10 @@ void AuraAddressableController::SendDirectBegin() hid_write(dev, usb_buf, 65); } -void AuraAddressableController::SendDirectApply() +void AuraAddressableController::SendDirectApply + ( + unsigned char channel + ) { unsigned char usb_buf[65]; @@ -271,7 +283,7 @@ void AuraAddressableController::SendDirectApply() \*-----------------------------------------------------*/ usb_buf[0x00] = 0xEC; usb_buf[0x01] = AURA_CONTROL_MODE_DIRECT; - usb_buf[0x02] = 0x80; + usb_buf[0x02] = 0x80 | channel; /*-----------------------------------------------------*\ | Send packet | diff --git a/Controllers/AuraAddressableController/AuraAddressableController.h b/Controllers/AuraAddressableController/AuraAddressableController.h index 99f373df6..e81080017 100644 --- a/Controllers/AuraAddressableController/AuraAddressableController.h +++ b/Controllers/AuraAddressableController/AuraAddressableController.h @@ -47,11 +47,16 @@ public: AuraAddressableController(hid_device* dev_handle); ~AuraAddressableController(); + unsigned int GetChannelCount(); + std::string GetDeviceName(); - int GetChannelCount(); - - void SetLEDsDirect(std::vector colors); + void SetChannelLEDs + ( + unsigned char channel, + RGBColor * colors, + unsigned int num_colors + ); void SetMode ( @@ -87,7 +92,13 @@ private: unsigned char* led_data ); - void SendDirectBegin(); + void SendDirectBegin + ( + unsigned char channel + ); - void SendDirectApply(); + void SendDirectApply + ( + unsigned char channel + ); }; diff --git a/RGBController/RGBController_AuraAddressable.cpp b/RGBController/RGBController_AuraAddressable.cpp index 7725af00e..b14a54174 100644 --- a/RGBController/RGBController_AuraAddressable.cpp +++ b/RGBController/RGBController_AuraAddressable.cpp @@ -121,12 +121,12 @@ void RGBController_AuraAddressable::SetupZones() \*-------------------------------------------------*/ leds.clear(); colors.clear(); - zones.resize(AURA_ADDRESSABLE_NUM_CHANNELS); + zones.resize(aura->GetChannelCount()); /*-------------------------------------------------*\ | Set zones and leds | \*-------------------------------------------------*/ - for (unsigned int channel_idx = 0; channel_idx < AURA_ADDRESSABLE_NUM_CHANNELS; channel_idx++) + for (unsigned int channel_idx = 0; channel_idx < zones.size(); channel_idx++) { char ch_idx_string[2]; sprintf(ch_idx_string, "%d", channel_idx + 1); @@ -153,9 +153,9 @@ void RGBController_AuraAddressable::SetupZones() new_led.name.append(ch_idx_string); new_led.name.append(", LED "); new_led.name.append(led_idx_string); + new_led.value = channel_idx; leds.push_back(new_led); - leds_channel.push_back(channel_idx); } } @@ -174,20 +174,22 @@ void RGBController_AuraAddressable::ResizeZone(int zone, int new_size) void RGBController_AuraAddressable::UpdateLEDs() { - if(modes[active_mode].value == 0xFFFF) + for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++) { - aura->SetLEDsDirect(colors); + aura->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count); } } void RGBController_AuraAddressable::UpdateZoneLEDs(int zone) { - UpdateLEDs(); + aura->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count); } void RGBController_AuraAddressable::UpdateSingleLED(int led) { - UpdateLEDs(); + unsigned int channel = leds[led].value; + + aura->SetChannelLEDs(channel, zones[channel].colors, zones[channel].leds_count); } void RGBController_AuraAddressable::SetCustomMode() diff --git a/RGBController/RGBController_AuraAddressable.h b/RGBController/RGBController_AuraAddressable.h index fa428701c..89239365a 100644 --- a/RGBController/RGBController_AuraAddressable.h +++ b/RGBController/RGBController_AuraAddressable.h @@ -12,7 +12,6 @@ #include "AuraAddressableController.h" #define AURA_ADDRESSABLE_MAX_LEDS 120 -#define AURA_ADDRESSABLE_NUM_CHANNELS 1 class RGBController_AuraAddressable : public RGBController { @@ -35,4 +34,4 @@ private: AuraAddressableController* aura; std::vector leds_channel; std::vector zones_channel; -}; \ No newline at end of file +};