Skip to content

Commit

Permalink
Simplify channels info structure
Browse files Browse the repository at this point in the history
  • Loading branch information
intrueder committed May 1, 2021
1 parent 24f0ac7 commit 14849c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
8 changes: 1 addition & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,17 @@ export interface CorsairChannelDeviceInfo {

export interface CorsairChannelInfo {
totalLedsCount: number;
devicesCount: number;
devices: Array<CorsairChannelDeviceInfo>;
}

export interface CorsairChannelsInfo {
channelsCount: number;
channels?: Array<CorsairChannelInfo>;
}

export interface CorsairDeviceInfo {
type: number;
model: string;
physicalLayout: CorsairPhysicalLayout;
logicalLayout: CorsairLogicalLayout;
capsMask: number;
ledsCount: number;
channels: CorsairChannelsInfo;
channels: Array<CorsairChannelInfo>;
deviceId: string;
}

Expand Down
8 changes: 2 additions & 6 deletions src/CorsairSdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Napi::Value corsairGetDeviceInfo(const Napi::CallbackInfo &info)
}

auto result = Napi::Object::New(env);
auto channels = Napi::Object::New(env);
auto channels = Napi::Array::New(env);

result["type"] = (int)deviceInfo->type;
result["model"] = std::string(deviceInfo->model);
Expand All @@ -60,15 +60,11 @@ Napi::Value corsairGetDeviceInfo(const Napi::CallbackInfo &info)
result["channels"] = channels;
result["deviceId"] = std::string(deviceInfo->deviceId);

channels["channelsCount"] = deviceInfo->channels.channelsCount;
if (deviceInfo->channels.channelsCount > 0) {
auto channelInfos = Napi::Array::New(env);
channels["channels"] = channelInfos;
for (int i = 0; i < deviceInfo->channels.channelsCount; i++) {
auto ci = deviceInfo->channels.channels[i];
auto channelInfo = Napi::Object::New(env);
channelInfo["totalLedsCount"] = ci.totalLedsCount;
channelInfo["devicesCount"] = ci.devicesCount;
auto channelDeviceInfos = Napi::Array::New(env);
channelInfo["devices"] = channelDeviceInfos;
for (int di = 0; di < ci.devicesCount; di++) {
Expand All @@ -78,7 +74,7 @@ Napi::Value corsairGetDeviceInfo(const Napi::CallbackInfo &info)
channelDeviceInfos[(uint32_t)di] = cdi;
}

channelInfos[(uint32_t)i] = channelInfo;
channels[(uint32_t)i] = channelInfo;
}
}

Expand Down

0 comments on commit 14849c6

Please sign in to comment.