diff --git a/Controllers/ENESMBusController/ENESMBusController.cpp b/Controllers/ENESMBusController/ENESMBusController.cpp index a1e48fe9c..e103d3d9a 100644 --- a/Controllers/ENESMBusController/ENESMBusController.cpp +++ b/Controllers/ENESMBusController/ENESMBusController.cpp @@ -174,14 +174,9 @@ std::string ENESMBusController::GetDeviceLocation() return(return_string); } -unsigned char ENESMBusController::GetChannel(unsigned int led) +const char * ENESMBusController::GetChannelName(unsigned int cfg_zone) { - return(config_table[channel_cfg + led]); -} - -const char * ENESMBusController::GetChannelName(unsigned int led) -{ - switch (config_table[channel_cfg + led]) + switch(config_table[channel_cfg + cfg_zone]) { case (unsigned char)ENE_LED_CHANNEL_AUDIO: return(ene_channels[0]); @@ -230,9 +225,9 @@ const char * ENESMBusController::GetChannelName(unsigned int led) } } -unsigned int ENESMBusController::GetLEDCount() +unsigned int ENESMBusController::GetLEDCount(unsigned int cfg_zone) { - return(led_count); + return(config_table[0x03 + cfg_zone]); } unsigned char ENESMBusController::GetLEDRed(unsigned int led) diff --git a/Controllers/ENESMBusController/ENESMBusController.h b/Controllers/ENESMBusController/ENESMBusController.h index 1891a2ace..d216c349c 100644 --- a/Controllers/ENESMBusController/ENESMBusController.h +++ b/Controllers/ENESMBusController/ENESMBusController.h @@ -18,7 +18,7 @@ #define ENE_APPLY_VAL 0x01 /* Value for Apply Changes Register */ #define ENE_SAVE_VAL 0xAA /* Value for Save Changes */ - +#define ENE_NUM_ZONES 8 /* Number of ENE config table zones */ enum { ENE_REG_DEVICE_NAME = 0x1000, /* Device String 16 bytes */ @@ -103,9 +103,8 @@ public: std::string GetDeviceName(); std::string GetDeviceLocation(); - unsigned char GetChannel(unsigned int led); - const char* GetChannelName(unsigned int led); - unsigned int GetLEDCount(); + const char* GetChannelName(unsigned int cfg_zone); + unsigned int GetLEDCount(unsigned int cfg_zone); unsigned char GetLEDRed(unsigned int led); unsigned char GetLEDGreen(unsigned int led); unsigned char GetLEDBlue(unsigned int led); diff --git a/Controllers/ENESMBusController/RGBController_ENESMBus.cpp b/Controllers/ENESMBusController/RGBController_ENESMBus.cpp index d1f582cb6..468d7cbcc 100644 --- a/Controllers/ENESMBusController/RGBController_ENESMBus.cpp +++ b/Controllers/ENESMBusController/RGBController_ENESMBus.cpp @@ -295,81 +295,88 @@ void RGBController_ENESMBus::UpdateSingleLED(int led) void RGBController_ENESMBus::SetupZones() { - std::vector led_map; - /*---------------------------------------------------------*\ | Search through all LEDs and create zones for each channel | | type | \*---------------------------------------------------------*/ - for(std::size_t led_idx = 0; led_idx < controller->GetLEDCount(); led_idx++) + for(std::size_t cfg_zone_idx = 0; cfg_zone_idx < ENE_NUM_ZONES; cfg_zone_idx++) { - bool matched = false; - /*---------------------------------------------------------*\ - | Search through existing zones to make sure we don't | - | create a duplicate zone | + | Get the number of LEDs in the zone | \*---------------------------------------------------------*/ - for(std::size_t existing_zone_idx = 0; existing_zone_idx < zones.size(); existing_zone_idx++) + unsigned int leds_in_zone = controller->GetLEDCount(cfg_zone_idx); + + if(leds_in_zone > 0) { - if(controller->GetChannelName(led_idx) == zones[existing_zone_idx].name) - { - matched = true; - } - } - - /*---------------------------------------------------------*\ - | If zone does not already exist, create it | - \*---------------------------------------------------------*/ - if(matched == false) - { - zone* new_zone = new zone(); - /*---------------------------------------------------------*\ - | Set zone name to channel name | + | Search through existing zones to make sure we don't | + | create a duplicate zone | \*---------------------------------------------------------*/ - new_zone->name = controller->GetChannelName(led_idx); + bool matched = false; + std::size_t existing_zone_idx = 0; - new_zone->leds_count = 0; - - /*---------------------------------------------------------*\ - | Find all LEDs with this channel type and add them to zone | - \*---------------------------------------------------------*/ - for(std::size_t zone_led_idx = 0; zone_led_idx < controller->GetLEDCount(); zone_led_idx++) + for(existing_zone_idx = 0; existing_zone_idx < zones.size(); existing_zone_idx++) { - if(controller->GetChannelName(zone_led_idx) == new_zone->name) + if(controller->GetChannelName(cfg_zone_idx) == zones[existing_zone_idx].name) { - new_zone->leds_count++; - led_map.push_back(zone_led_idx); + matched = true; + break; } } /*---------------------------------------------------------*\ - | Zones have fixed size, so set min and max to count | + | If zone does not already exist, create it | \*---------------------------------------------------------*/ - new_zone->leds_min = new_zone->leds_count; - new_zone->leds_max = new_zone->leds_count; - - /*---------------------------------------------------------*\ - | If this zone has more than one LED, mark it as linear type| - \*---------------------------------------------------------*/ - if(new_zone->leds_count > 1) + if(matched == false) { - new_zone->type = ZONE_TYPE_LINEAR; + zone* new_zone = new zone(); + + /*---------------------------------------------------------*\ + | Set zone name to channel name | + \*---------------------------------------------------------*/ + new_zone->name = controller->GetChannelName(cfg_zone_idx); + + /*---------------------------------------------------------*\ + | Set zone LED count to LEDs in zone | + \*---------------------------------------------------------*/ + new_zone->leds_count = leds_in_zone; + + /*---------------------------------------------------------*\ + | Push new zone to zones vector | + \*---------------------------------------------------------*/ + zones.push_back(*new_zone); } + /*---------------------------------------------------------*\ + | Otherwise, add the number of LEDs from this zone to the | + | existing one. | + \*---------------------------------------------------------*/ else { - new_zone->type = ZONE_TYPE_SINGLE; + zones[existing_zone_idx].leds_count += leds_in_zone; } - - new_zone->matrix_map = NULL; - - /*---------------------------------------------------------*\ - | Push new zone to zones vector | - \*---------------------------------------------------------*/ - zones.push_back(*new_zone); } } + /*---------------------------------------------------------*\ + | Finish setting up the zones | + \*---------------------------------------------------------*/ + for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++) + { + zones[zone_idx].leds_min = zones[zone_idx].leds_count; + zones[zone_idx].leds_max = zones[zone_idx].leds_count; + + if(zones[zone_idx].leds_count > 1) + { + zones[zone_idx].type = ZONE_TYPE_LINEAR; + } + else + { + zones[zone_idx].type = ZONE_TYPE_SINGLE; + } + + zones[zone_idx].matrix_map = NULL; + } + /*---------------------------------------------------------*\ | Create LED entries for each zone | \*---------------------------------------------------------*/ @@ -383,7 +390,8 @@ void RGBController_ENESMBus::SetupZones() new_led->name = zones[zone_idx].name + " LED "; new_led->name.append(std::to_string(zone_led_idx + 1)); - new_led->value = led_map[led_idx++]; + new_led->value = led_idx; + led_idx++; leds.push_back(*new_led); }