getDataAsRgb static method

List<int> getDataAsRgb(
  1. String entertainmentConfigurationId,
  2. List<EntertainmentStreamCommand> commands
)

Creates a packet to send to the bridge, using RGB color space encoding.

The entertainmentConfigurationId parameter is the ID of the entertainment configuration to send the data to. Note, any channel that is using XY instead of RGB will be ignored.

The commands are the commands that are being sent to the bridge.

Returns a list of bytes representing the packet.

Implementation

static List<int> getDataAsRgb(
  String entertainmentConfigurationId,
  List<EntertainmentStreamCommand> commands,
) {
  final List<int> packet =
      // ignore: deprecated_member_use_from_same_package
      _getPacketBase(ColorMode.rgb, entertainmentConfigurationId);

  // Add every command to the packet.
  int counter = 0;
  for (final EntertainmentStreamCommand command in commands) {
    // Skip any commands that are not using RGB color space.
    // ignore: deprecated_member_use_from_same_package
    if (command.color is! ColorRgb || command.color is! ColorRgbNormalized) {
      continue;
    }

    // Only allow 20 commands per packet.
    if (counter >= 20) break;

    packet.add(command.channel);

    // ignore: deprecated_member_use_from_same_package
    if (command.color is ColorRgb) {
      packet.addAll(
        _formatRgb(
          // ignore: deprecated_member_use_from_same_package
          (command.color as ColorRgb).r,
          // ignore: deprecated_member_use_from_same_package
          (command.color as ColorRgb).g,
          // ignore: deprecated_member_use_from_same_package
          (command.color as ColorRgb).b,
        ),
      );
    } else {
      packet.addAll(
        _formatRgbNormalized(
          (command.color as ColorRgbNormalized).r,
          (command.color as ColorRgbNormalized).g,
          (command.color as ColorRgbNormalized).b,
        ),
      );
    }

    counter++;
  }

  return packet;
}