setLedColor method
Commands the LED lightbar via 48-byte Output Reports (0x02).
r, g and b must be in the 0-255 range; out-of-range values are
clamped automatically. Does nothing if no controller is connected.
Implementation
void setLedColor(int r, int g, int b) {
if (_device == ffi.nullptr) return;
final ffi.Pointer<ffi.Uint8> outBuffer = pkg_ffi.calloc<ffi.Uint8>(48);
outBuffer[0] = 0x02; // Output report ID
outBuffer[1] = 0xFF; // Enable Sony's global refresh flags
outBuffer[45] = r.clamp(0, 255); // Red channel
outBuffer[46] = g.clamp(0, 255); // Green channel
outBuffer[47] = b.clamp(0, 255); // Blue channel
_bindings.hidWrite(_device, outBuffer, 48);
pkg_ffi.calloc.free(outBuffer);
}