Runtime
The runtime of a plugin is comprised of three parts. Initialize -> Render Loop -> Shutdown
The only exception to this pattern is the use of on*Change Callbacks which are processed at the start of a frame prior to the render function being called.
"Initialize"
Initialize runs once when a device is [re]connected to, and anytime the streaming toggle is enabled in the device's config page. You'll want to handle any initial start up tasks here.
- Note: if the device has any conflicting processes running initialization will wait until they are closed, or the user bypasses the check.
export function Initialize()
{
// Do Stuff ...
SendInitPacket1();
SendInitPacket2();
SetSoftwareControl();
}
Render Loop
The Render Loop is the core of the plugin and is where color changes and other runtime functions are handled.
The process of each frame is as follows:
- User Settings are updated for the frame
- Colors are grabbed for the device and sub devices pixel buffers
- on*Change Callbacks are called in order
- Render is called
- Note: The default time between frames is 30ms
export function Render()
{
// Do Stuff ...
SendColors()
}
"Shutdown"
Shutdown is called when SignalRGB exits gracefully, and whenever the streaming toggle is disabled in the device config page. You'll want to return the device to its hardware mode here if needed.
export function Shutdown()
{
// Do Stuff ...
SetHardwareControl();
}
on*Changed Callbacks
These functions get called whenever a User Control is changed. These trigger just before the Render() function is called in the order they occurred in.
- Note: Their naming must be as follows: "on[User Control property name]Changed()". This is case sensitive.
// User Control from ControllableParameters()
{"property":"dpi1", "label":"DPI","step":"50", "type":"number","min":"200", "max":"18000","default":"800"},
// DPI Functions
export function ondpi1Changed(){
setDpi(dpi1)
}
function setDpi(dpi){
// Guard clause to prevent changing dpi if the user doesn't have this boolean toggled on
if(!SettingControl){
return;
}
device.log(`Setting Dpi to ${dpi}`)
Corsair_Set(CORSAIR_DPI_X,dpi)
Corsair_Set(CORSAIR_DPI_Y,dpi)
device.log(`DPI x is now ${Corsair_Get(CORSAIR_DPI_X)}`)
device.log(`DPI y is now ${Corsair_Get(CORSAIR_DPI_Y)}`)
}
Built in Callbacks are as Follows:
Function Name | Description |
---|---|
onBrightnessChanged() | Triggers when the device's main brightness slider is moved. |