元件函式
這些函式用於設定裝置以與元件系統相容。
device.SetLedLimit()
Section titled “device.SetLedLimit()”此函式接受一個整數值,並為裝置上所有元件通道設定 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 陣列 | [“Channel 1”,“Channel 2”] |
let channels = device.getChannelNames();device.channel()
Section titled “device.channel()”這是與 ComponentChannel 互動的入口。如果找到與給定通道名稱匹配的 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 陣列 | [R,G,B,R,G,B] |
| Seperate | 將顏色資料格式化為 3 個不同的通道 | 2D 陣列 | [[R,R], [G,G], [B,B]] |
ColorOrder 是 “RGB” 的 3 個字母組合,例如 “BGR”、“GBR”、“RBG”,決定使用 Inline ArrayOrder 時的顏色順序。無效值將回退到 “RGB”。
| 返回值 | 說明 | 類型 | 範例 |
|---|---|---|---|
| RGB Data | 以所需格式返回的 RGB 顏色資料 | 陣列 | 請參閱陣列順序表 |
RGBData = device.channel("Channel 1").getColors("Inline", "GRB");channel.shouldPulseColors()
Section titled “channel.shouldPulseColors()”此函式返回一個布林值,表示此裝置通道是否應「脈衝」。這可能是因為沒有選擇任何元件,或者正在顯示引導元件設定 UI 而被要求的。
可以使用 device.getChannelPulseColor() 來獲取預期的脈衝顏色。
| 返回值 | 類型 | 說明 |
|---|---|---|
| ShouldPulse | boolean | 此通道是否應脈衝 |