Skip to content

Commit 2baab11

Browse files
author
Jerry Fan
committed
Customize device name for RtkArgbController
- Adopt manufacturer + uuid as device name when the specified bit is ON.
1 parent 31bfa1a commit 2baab11

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

Controllers/RtkArgbController/RGBController_RtkArgb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RGBController_RtkArgb::RGBController_RtkArgb(RtkArgbWrapper *_wrapper)
2626
{
2727
this->wrapper = _wrapper;
2828

29-
name = wrapper->get_product_name();
29+
name = wrapper->get_dev_name();
3030
vendor = wrapper->get_manu_name();
3131
location = wrapper->get_dev_loc();
3232
serial = wrapper->get_sn();

Controllers/RtkArgbController/RtkArgbControllerDetect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
void DetectRtkArgbControllers(hid_device_info *info, const std::string &name)
1818
{
1919
RGBController_RtkArgb *controller = NULL;
20+
RtkArgbWrapper *wrapper = NULL;
2021
static struct argb_device *dev = NULL;
2122
argbCtl *argb_ctl = NULL;
2223
int ret = -1;
@@ -46,7 +47,7 @@ void DetectRtkArgbControllers(hid_device_info *info, const std::string &name)
4647
}
4748
argb_ctl->sync_method = SYNC_METHOD_OPENRGB;
4849

49-
RtkArgbWrapper *wrapper = new RtkArgbWrapper(dev, argb_ctl, info);
50+
wrapper = new RtkArgbWrapper(dev, argb_ctl, info);
5051
controller = new RGBController_RtkArgb(wrapper);
5152
if(controller->type != DEVICE_TYPE_UNKNOWN)
5253
{

Controllers/RtkArgbController/RtkArgbWrapper.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ void RtkArgbWrapper::argb_reinit()
102102
return;
103103
}
104104

105+
static std::string int_to_hex_str(uint32_t value)
106+
{
107+
char hex_str[20] = {0};
108+
snprintf(hex_str, sizeof(hex_str), "%X", value);
109+
return std::string(hex_str);
110+
}
111+
105112
std::string RtkArgbWrapper::get_manu_name()
106113
{
107114
return wcharToString(hidinfo->manufacturer_string);
@@ -134,6 +141,34 @@ std::string RtkArgbWrapper::get_fw_ver()
134141
return ver;
135142
}
136143

144+
std::string RtkArgbWrapper::get_ic_uuid()
145+
{
146+
uint32_t uuid = 0;
147+
std::string uuid_str = "";
148+
149+
if (bridge_get_uuid(adev, (uint8_t *)&uuid))
150+
goto exit;
151+
152+
uuid_str = int_to_hex_str(uuid);
153+
exit:
154+
return uuid_str;
155+
}
156+
157+
std::string RtkArgbWrapper::get_dev_name()
158+
{
159+
PGINFO info = { 0 };
160+
std::string devname = get_product_name();
161+
162+
if (!pg_read(adev, &info))
163+
{
164+
if (info.customized_led[5] == CUST_DEVNAME_MANU_UUID)
165+
{
166+
devname = get_manu_name() + get_ic_uuid();
167+
}
168+
}
169+
return devname;
170+
}
171+
137172
int RtkArgbWrapper::get_fix_grps()
138173
{
139174
int fix_grps = 0;
@@ -219,7 +254,7 @@ int RtkArgbWrapper::set_argb_num(int grp_num, int new_num)
219254
if (led_argb_set_pos(adev, argb_ctl, group, poses, true))
220255
continue;
221256
}
222-
exit:
257+
223258
if (poses)
224259
{
225260
free(poses);
@@ -232,13 +267,13 @@ int RtkArgbWrapper::set_argb_num(int grp_num, int new_num)
232267
int RtkArgbWrapper::set_argb_direct(int grp_num, std::vector<RGBColor> color_buf, unsigned short brightness)
233268
{
234269
int ret = -1;
235-
int color_num = color_buf.size();
270+
size_t color_num = color_buf.size();
236271
int buf_len = color_num * ARGB_COLOR_DEPTH;
237272
static unsigned short prev_bright = 0xFFFF;
238273
uint8_t *buf;
239274
std::lock_guard<std::mutex> lock(my_mutex);
240275

241-
if (color_num <= 0)
276+
if (color_num == 0)
242277
goto exit;
243278

244279
if (appctl[grp_num] != LED_CTL_APP)
@@ -259,7 +294,7 @@ int RtkArgbWrapper::set_argb_direct(int grp_num, std::vector<RGBColor> color_buf
259294

260295
buf = (uint8_t*)malloc(buf_len);
261296
memset(buf, 0, buf_len);
262-
for (int i = 0; i < color_num; i++)
297+
for (size_t i = 0; i < color_num; i++)
263298
{
264299
buf[i * ARGB_COLOR_DEPTH + 0] = RGBGetRValue(color_buf[i]);
265300
buf[i * ARGB_COLOR_DEPTH + 1] = RGBGetGValue(color_buf[i]);

Controllers/RtkArgbController/RtkArgbWrapper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ enum RTK_ARGB_CYCLE_MS
3737
RTK_ARGB_CYCLE_MAX = 10000,
3838
};
3939

40+
enum RTK_ARGB_CUST_DEVNAME
41+
{
42+
CUST_DEVNAME_NULL = 0x0,
43+
CUST_DEVNAME_MANU_UUID = 0x1,
44+
};
45+
4046
class RtkArgbWrapper
4147
{
4248
public:
@@ -49,6 +55,8 @@ class RtkArgbWrapper
4955
std::string get_sn();
5056
std::string get_dev_loc();
5157
std::string get_fw_ver();
58+
std::string get_ic_uuid();
59+
std::string get_dev_name();
5260
int get_fix_grps();
5361
int get_argb_num(int grp_num);
5462
int get_argb_brightness(int grp_num);

0 commit comments

Comments
 (0)