|
| 1 | +/*-----------------------------------------*\ |
| 2 | +| RGBController_SRGBmodsLEDControllerV1.cpp| |
| 3 | +| | |
| 4 | +| Generic RGB Interface for SRGBmods | |
| 5 | +| LED Controller V1 | |
| 6 | +| | |
| 7 | +| Adam Honse (CalcProgrammer1) 6/30/2023 | |
| 8 | +\*-----------------------------------------*/ |
| 9 | + |
| 10 | +#include "RGBController_SRGBmodsLEDControllerV1.h" |
| 11 | + |
| 12 | +/**------------------------------------------------------------------*\ |
| 13 | + @name SRGBmods LED Controller V1 |
| 14 | + @category LEDStrip |
| 15 | + @type USB |
| 16 | + @save :x: |
| 17 | + @direct :white_check_mark: |
| 18 | + @effects :white_check_mark: |
| 19 | + @detectors DetectSRGBmodsControllers |
| 20 | + @comment |
| 21 | +\*-------------------------------------------------------------------*/ |
| 22 | + |
| 23 | +RGBController_SRGBmodsLEDControllerV1::RGBController_SRGBmodsLEDControllerV1(SRGBmodsLEDControllerV1* controller_ptr) |
| 24 | +{ |
| 25 | + controller = controller_ptr; |
| 26 | + |
| 27 | + name = "SRGBmods Device"; |
| 28 | + vendor = "SRGBmods.net"; |
| 29 | + description = "SRGBmods LED Controller V1 Device"; |
| 30 | + type = DEVICE_TYPE_LEDSTRIP; |
| 31 | + location = controller->GetLocationString(); |
| 32 | + serial = controller->GetSerialString(); |
| 33 | + |
| 34 | + mode Direct; |
| 35 | + Direct.name = "Direct"; |
| 36 | + Direct.value = SRGBMODS_LED_CONTROLLER_V1_MODE_DIRECT; |
| 37 | + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; |
| 38 | + Direct.color_mode = MODE_COLORS_PER_LED; |
| 39 | + modes.push_back(Direct); |
| 40 | + |
| 41 | + mode Rainbow; |
| 42 | + Rainbow.name = "Rainbow Wave"; |
| 43 | + Rainbow.value = SRGBMODS_LED_CONTROLLER_V1_MODE_RAINBOW; |
| 44 | + Rainbow.flags = MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE; |
| 45 | + Rainbow.color_mode = MODE_COLORS_RANDOM; |
| 46 | + Rainbow.brightness_min = 0x00; |
| 47 | + Rainbow.brightness_max = 0xFF; |
| 48 | + Rainbow.brightness = 0xFF; |
| 49 | + Rainbow.speed_min = 0x0A; |
| 50 | + Rainbow.speed_max = 0xFF; |
| 51 | + Rainbow.speed = 0x7F; |
| 52 | + modes.push_back(Rainbow); |
| 53 | + |
| 54 | + mode Breathing; |
| 55 | + Breathing.name = "Breathing"; |
| 56 | + Breathing.value = SRGBMODS_LED_CONTROLLER_V1_MODE_BREATHING_MODE_SPECIFIC; |
| 57 | + Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE; |
| 58 | + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; |
| 59 | + Breathing.brightness_min = 0x00; |
| 60 | + Breathing.brightness_max = 0xFF; |
| 61 | + Breathing.brightness = 0xFF; |
| 62 | + Breathing.speed_min = 0x0A; |
| 63 | + Breathing.speed_max = 0xFF; |
| 64 | + Breathing.speed = 0x7F; |
| 65 | + Breathing.colors_min = 1; |
| 66 | + Breathing.colors_max = 1; |
| 67 | + Breathing.colors.resize(1); |
| 68 | + modes.push_back(Breathing); |
| 69 | + |
| 70 | + mode Static; |
| 71 | + Static.name = "Static"; |
| 72 | + Static.value = SRGBMODS_LED_CONTROLLER_V1_MODE_STATIC; |
| 73 | + Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_AUTOMATIC_SAVE; |
| 74 | + Static.color_mode = MODE_COLORS_MODE_SPECIFIC; |
| 75 | + Static.brightness_min = 0x00; |
| 76 | + Static.brightness_max = 0xFF; |
| 77 | + Static.brightness = 0xFF; |
| 78 | + Static.colors_min = 1; |
| 79 | + Static.colors_max = 1; |
| 80 | + Static.colors.resize(1); |
| 81 | + modes.push_back(Static); |
| 82 | + |
| 83 | + SetupZones(); |
| 84 | +} |
| 85 | + |
| 86 | +RGBController_SRGBmodsLEDControllerV1::~RGBController_SRGBmodsLEDControllerV1() |
| 87 | +{ |
| 88 | + delete controller; |
| 89 | +} |
| 90 | + |
| 91 | +void RGBController_SRGBmodsLEDControllerV1::SetupZones() |
| 92 | +{ |
| 93 | + /*-------------------------------------------------*\ |
| 94 | + | Only set LED count on the first run | |
| 95 | + \*-------------------------------------------------*/ |
| 96 | + bool first_run = false; |
| 97 | + |
| 98 | + if(zones.size() == 0) |
| 99 | + { |
| 100 | + first_run = true; |
| 101 | + } |
| 102 | + |
| 103 | + /*-------------------------------------------------*\ |
| 104 | + | Clear any existing color/LED configuration | |
| 105 | + \*-------------------------------------------------*/ |
| 106 | + leds.clear(); |
| 107 | + colors.clear(); |
| 108 | + zones.resize(SRGBMODS_LED_CONTROLLER_V1_NUM_CHANNELS); |
| 109 | + |
| 110 | + /*-------------------------------------------------*\ |
| 111 | + | Set zones and leds | |
| 112 | + \*-------------------------------------------------*/ |
| 113 | + for(unsigned int channel_idx = 0; channel_idx < SRGBMODS_LED_CONTROLLER_V1_NUM_CHANNELS; channel_idx++) |
| 114 | + { |
| 115 | + char ch_idx_string[2]; |
| 116 | + snprintf(ch_idx_string, 2, "%d", channel_idx + 1); |
| 117 | + |
| 118 | + zones[channel_idx].name = "Channel "; |
| 119 | + zones[channel_idx].name.append(ch_idx_string); |
| 120 | + zones[channel_idx].type = ZONE_TYPE_LINEAR; |
| 121 | + |
| 122 | + /*-------------------------------------------------*\ |
| 123 | + | The maximum number of LEDs per channel is 800 | |
| 124 | + | according to https://srgbmods.net/lcv1/ | |
| 125 | + \*-------------------------------------------------*/ |
| 126 | + zones[channel_idx].leds_min = 0; |
| 127 | + zones[channel_idx].leds_max = 800; |
| 128 | + |
| 129 | + if(first_run) |
| 130 | + { |
| 131 | + zones[channel_idx].leds_count = 0; |
| 132 | + } |
| 133 | + |
| 134 | + zones[channel_idx].matrix_map = NULL; |
| 135 | + |
| 136 | + for(unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++) |
| 137 | + { |
| 138 | + char led_idx_string[4]; |
| 139 | + snprintf(led_idx_string, 4, "%d", led_ch_idx + 1); |
| 140 | + |
| 141 | + led new_led; |
| 142 | + new_led.name = "LED "; |
| 143 | + new_led.name.append(led_idx_string); |
| 144 | + |
| 145 | + leds.push_back(new_led); |
| 146 | + leds_channel.push_back(channel_idx); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + SetupColors(); |
| 151 | +} |
| 152 | + |
| 153 | +void RGBController_SRGBmodsLEDControllerV1::ResizeZone(int zone, int new_size) |
| 154 | +{ |
| 155 | + if((size_t) zone >= zones.size()) |
| 156 | + { |
| 157 | + return; |
| 158 | + } |
| 159 | + |
| 160 | + if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max)) |
| 161 | + { |
| 162 | + zones[zone].leds_count = new_size; |
| 163 | + |
| 164 | + SetupZones(); |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | +void RGBController_SRGBmodsLEDControllerV1::DeviceUpdateLEDs() |
| 169 | +{ |
| 170 | + if(modes[active_mode].value == SRGBMODS_LED_CONTROLLER_V1_MODE_DIRECT) |
| 171 | + { |
| 172 | + for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++) |
| 173 | + { |
| 174 | + if(zones[zone_idx].leds_count > 0) |
| 175 | + { |
| 176 | + controller->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count); |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + else |
| 181 | + { |
| 182 | + DeviceUpdateMode(); |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +void RGBController_SRGBmodsLEDControllerV1::UpdateZoneLEDs(int /*zone*/) |
| 187 | +{ |
| 188 | + DeviceUpdateLEDs(); |
| 189 | +} |
| 190 | + |
| 191 | +void RGBController_SRGBmodsLEDControllerV1::UpdateSingleLED(int /*led*/) |
| 192 | +{ |
| 193 | + DeviceUpdateLEDs(); |
| 194 | +} |
| 195 | + |
| 196 | +void RGBController_SRGBmodsLEDControllerV1::DeviceUpdateMode() |
| 197 | +{ |
| 198 | + if(modes[active_mode].value == SRGBMODS_LED_CONTROLLER_V1_MODE_DIRECT) |
| 199 | + { |
| 200 | + controller->SetDirect(); |
| 201 | + |
| 202 | + DeviceUpdateLEDs(); |
| 203 | + } |
| 204 | + else |
| 205 | + { |
| 206 | + unsigned int value = modes[active_mode].value; |
| 207 | + RGBColor color = 0; |
| 208 | + |
| 209 | + if(modes[active_mode].value == SRGBMODS_LED_CONTROLLER_V1_MODE_BREATHING_MODE_SPECIFIC && modes[active_mode].color_mode == MODE_COLORS_RANDOM) |
| 210 | + { |
| 211 | + value = SRGBMODS_LED_CONTROLLER_V1_MODE_BREATHING_RANDOM; |
| 212 | + } |
| 213 | + |
| 214 | + if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC) |
| 215 | + { |
| 216 | + color = modes[active_mode].colors[0]; |
| 217 | + } |
| 218 | + |
| 219 | + controller->SetConfiguration(value, modes[active_mode].speed, modes[active_mode].brightness, color); |
| 220 | + } |
| 221 | +} |
0 commit comments