setMode method

void setMode(
  1. int deviceId,
  2. int modeID,
  3. Color color
)

Sets a mode with given modeID on deviceId. color parameter does not always apply to all modes.

Implementation

void setMode(int deviceId, int modeID, Color color) {
  RGBController targetController = getControllerData(deviceId);
  if (deviceId >= _controllerCount) {
    throw Exception('Device index out of range!');
  }
  var targetMode = targetController.modes[modeID];
  List<Color> colors = [];
  for (int i = 0; i < targetMode.modeNumColors; i++) {
    colors.add(color);
  }
  targetMode = targetMode.copyWith(colors: colors);

  final bb = BytesBuilder();
  final dataSize = Uint8List(4)
    ..buffer
        .asByteData()
        .setUint8(0, targetMode.toBytes().lengthInBytes + 84);
  bb.add(dataSize.toBytes());
  bb.add(modeID.toBytes());
  bb.add(targetMode.toBytes());
  _send(
    CommandId.updateMode,
    bb.toBytes(),
    deviceId: deviceId,
  );
}