组件函数
这些函数用于将设备设置为与组件系统兼容。
device.SetLedLimit()
Section titled “device.SetLedLimit()”此函数接受一个整数值并设置设备上所有组件通道的 LED 上限。它用于后端的安全检查,并防止用户为设备添加超过其功率承受能力的 LED。应将其设置为制造商限制设备的最大值。
| 参数 | 描述 | 类型 | 示例 |
|---|---|---|---|
| LedLimit | 设备所有通道所需的 LED 限制 | Int | 80 |
const DeviceMaxLedLimit = 233; device.SetLedLimit(DeviceMaxLedLimit);device.getLedCount()
Section titled “device.getLedCount()”此函数将返回设备所有通道上所有组件的当前合计 LED 数量。其主要用途是检查是否有任何已选择的组件,因为 0 个 LED 等于 0 个组件。
| 返回值 | 描述 | 类型 | 示例 |
|---|---|---|---|
| LedCount | 所有通道的当前 LED 数量 | Int | 64 |
let ColorData = [] if(LightingMode == "Forced"){ // do stuff }else if(device.getLedCount() == 0){ // do stuff }else{ // do stuff }device.addChannel()
Section titled “device.addChannel()”此函数将向设备添加一个新的组件通道。添加第一个通道后,组件配置 UI 将出现在设备页面上。此函数接受一个可选但建议的 LedLimit,以警告用户不要超过设备的安全 LED 限制。此限制在多处使用,因此强烈建议设置它。
| 参数 | 描述 | 类型 | 示例 |
|---|---|---|---|
| ChannelName | 用于引用此通道的通道名称 | String | ”Channel 1” |
| LedLimit | 通道安全运行的 LED 限制。 | Int | 204 |
//Channel Name, Led Limitvar ChannelArray = [ ["Channel 1", 204], ["Channel 2", 204],]
function SetupChannels(){ device.SetLedLimit(DeviceMaxLedLimit); for(let i = 0; i < ChannelArray.length; i++){ device.addChannel(ChannelArray[i][0],ChannelArray[i][1]); }}device.removeChannel()
Section titled “device.removeChannel()”此函数将从设备中删除一个通道。在正常情况下,不需要此函数,因为通道在 SignalRGB 关闭时会被清理。但由于通道在插件文件热重载之间持续存在,如果您在开发插件时遇到问题,可能需要在初始化函数中清除它们。
| 参数 | 描述 | 类型 | 示例 |
|---|---|---|---|
| ChannelName | 要删除的通道名称 | String | ”Channel 1” |
device.createChannel("Channel1") // Do stuff device.removeChannel("Channel1")device.getChannelNames()
Section titled “device.getChannelNames()”此函数将返回设备上所有当前通道的名称。其主要用途是用于调试,因为通道名称应与设备数据包的通道索引一起存储在插件的逻辑中。但是,如果需要以轻微的性能损失为代价,它也可以用于迭代设备上的所有通道。
| 返回值 | 描述 | 类型 | 示例 |
|---|---|---|---|
| Channel Names | 设备上所有通道名称的列表 | 1D Array | [“Channel 1”,“Channel 2”] |
let channels = device.getChannelNames();device.channel()
Section titled “device.channel()”这是与 ComponentChannel 交互的入口。如果存在与给定 ChannelName 匹配的 ComponentChannel,它将返回对该 ComponentChannel 本身的引用;如果不存在,则返回 null。
| 参数 | 描述 | 类型 | 示例 |
|---|---|---|---|
| ChannelName | 要获取引用的通道名称 | String | ”Channel 1” |
| 返回值 | 描述 | 类型 |
|---|---|---|
| ComponentChannel | ComponentChannel 对象 | ComponentChannel | Null |
let components = device.channel("Channel 1").getComponentNames();ComponentChannel
Section titled “ComponentChannel”这些函数用于控制和与特定 ComponentChannel 引用交互。
channel.SetLedLimit()
Section titled “channel.SetLedLimit()”与类似的 device.ledLimit() 函数一样,此函数将为此 ComponentChannel 设置最大安全 LED 限制。
| 参数 | 描述 | 类型 | 示例 |
|---|---|---|---|
| LedLimit | 通道所需的 LED 限制 | Int | 16 |
device.channel("Channel 1").SetLedLimit(204);channel.LedCount()
Section titled “channel.LedCount()”这将返回用户在此 ComponentChannel 上配置的 LED 数量。
| 返回值 | 描述 | 类型 | 示例 |
|---|---|---|---|
| LedCount | 通道的当前 LED 数量 | Int | 16 |
let ChannelLedCount = device.channel("Channel 1").LedCount();channel.getColors()
Section titled “channel.getColors()”此函数将根据设备的 LED 映射和坐标返回 RGB 颜色数据数组。此函数的返回值在很大程度上取决于正确设置参数。
| 参数 | 描述 | 类型 | 示例 | 默认值 |
|---|---|---|---|---|
| ArrayOrder | 所需的数组格式 | String | ”Inline" | "Seperate” |
| ColorOrder | 所需的颜色顺序 | String | ”RGB" | "RGB” |
| 数组顺序 | 描述 | 类型 | 示例 |
|---|---|---|---|
| Inline | 将颜色数据格式化为按顺序的平面数组 | 1D Array | [R,G,B,R,G,B] |
| Seperate | 将颜色数据格式化为 3 个独立通道 | 2D Array | [[R,R], [G,G], [B,B]] |
ColorOrder 是”RGB”的 3 字母组合,即”BGR”、“GBR”、“RBG”,确定使用 Inline ArrayOrder 时颜色的顺序。无效值将默认回”RGB”。
| 返回值 | 描述 | 类型 | 示例 |
|---|---|---|---|
| RGB Data | 以所需格式返回的 RGB 颜色数据 | Array | 见数组顺序表 |
RGBData = device.channel("Channel 1").getColors("Inline", "GRB");channel.shouldPulseColors()
Section titled “channel.shouldPulseColors()”此函数返回一个布尔值,表示此设备通道是否应该”脉冲”。这可能是由于没有选择组件,或者正在显示新手引导组件设置 UI 时请求的。
可以使用 device.getChannelPulseColor() 获取预期的脉冲颜色。
| 返回值 | 类型 | 描述 |
|---|---|---|
| ShouldPulse | boolean | 此通道是否应该脉冲 |