Skip to content

Commit ddef980

Browse files
Initial commit for SRGBmods LED Controller V1
1 parent 36e8ab4 commit ddef980

8 files changed

+514
-7
lines changed
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*-----------------------------------------*\
2+
| RGBController_SRGBmodsLEDControllerV1.h |
3+
| |
4+
| Generic RGB Interface for SRGBmods |
5+
| LED Controller V1 |
6+
| |
7+
| Adam Honse (CalcProgrammer1) 6/30/2023 |
8+
\*-----------------------------------------*/
9+
10+
#pragma once
11+
12+
#include "RGBController.h"
13+
#include "SRGBmodsLEDControllerV1.h"
14+
15+
#define SRGBMODS_LED_CONTROLLER_V1_NUM_CHANNELS 1
16+
17+
class RGBController_SRGBmodsLEDControllerV1 : public RGBController
18+
{
19+
public:
20+
RGBController_SRGBmodsLEDControllerV1(SRGBmodsLEDControllerV1* controller_ptr);
21+
~RGBController_SRGBmodsLEDControllerV1();
22+
23+
void SetupZones();
24+
void ResizeZone(int zone, int new_size);
25+
26+
void DeviceUpdateLEDs();
27+
void UpdateZoneLEDs(int zone);
28+
void UpdateSingleLED(int led);
29+
30+
void DeviceUpdateMode();
31+
32+
private:
33+
SRGBmodsLEDControllerV1* controller;
34+
std::vector<unsigned int> leds_channel;
35+
std::vector<unsigned int> zones_channel;
36+
};

Controllers/SRGBmodsController/SRGBmodsControllerDetect.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#include "Detector.h"
2+
#include "SRGBmodsLEDControllerV1.h"
23
#include "SRGBmodsPicoController.h"
34
#include "RGBController.h"
5+
#include "RGBController_SRGBmodsLEDControllerV1.h"
46
#include "RGBController_SRGBmodsPico.h"
57
#include <vector>
68
#include <hidapi/hidapi.h>
79

8-
#define SRGBMODS_PICO_VID 0x16D0
9-
#define SRGBMODS_PICO_PID 0x1123
10+
#define SRGBMODS_VID 0x16D0
11+
12+
#define SRGBMODS_PICO_PID 0x1123
13+
#define SRGBMODS_LED_CONTROLLER_V1_PID 0x1205
1014

1115
/******************************************************************************************\
1216
* *
@@ -37,9 +41,18 @@ void DetectSRGBmodsControllers(hid_device_info* info, const std::string& name)
3741
RGBController_SRGBmodsPico* rgb_controller = new RGBController_SRGBmodsPico(controller);
3842
rgb_controller->name = name;
3943

44+
ResourceManager::get()->RegisterRGBController(rgb_controller);
45+
}
46+
else if(product_str == L"LED Controller v1")
47+
{
48+
SRGBmodsLEDControllerV1* controller = new SRGBmodsLEDControllerV1(dev, info->path);
49+
RGBController_SRGBmodsLEDControllerV1* rgb_controller = new RGBController_SRGBmodsLEDControllerV1(controller);
50+
rgb_controller->name = name;
51+
4052
ResourceManager::get()->RegisterRGBController(rgb_controller);
4153
}
4254
}
4355
} /* DetectSRGBmodsControllers() */
4456

45-
REGISTER_HID_DETECTOR("SRGBmods Pico LED Controller", DetectSRGBmodsControllers, SRGBMODS_PICO_VID, SRGBMODS_PICO_PID);
57+
REGISTER_HID_DETECTOR("SRGBmods Pico LED Controller", DetectSRGBmodsControllers, SRGBMODS_VID, SRGBMODS_PICO_PID );
58+
REGISTER_HID_DETECTOR("SRGBMods LED Controller v1", DetectSRGBmodsControllers, SRGBMODS_VID, SRGBMODS_LED_CONTROLLER_V1_PID);

0 commit comments

Comments
 (0)