generateOutputCmd method

OutputCmd generateOutputCmd(
  1. DeviceOutputCommand command
)

Implementation

OutputCmd generateOutputCmd(DeviceOutputCommand command) {
  _ensureValid();
  final info = _outputInfo(command.outputType);
  final newCommand = ClientDeviceFeatureOutput()..value = _outputValue(command, info);

  if (command.outputType == OutputType.hwPositionWithDuration) {
    final duration = command.duration;
    if (duration == null) {
      throw ButtplugClientDeviceFeatureCapabilityException(
        'hwPositionWithDuration requires a duration',
      );
    }
    final durationRange = _range(info.duration, 'duration');
    if (duration < durationRange[0] || duration > durationRange[1] || duration < 0) {
      throw ButtplugClientDeviceFeatureRangeException(
        '${feature.featureDescription} duration $duration is outside range [${durationRange[0]}, ${durationRange[1]}]',
      );
    }
    newCommand.duration = duration;
  }

  final msg = OutputCmd()
    ..command[command.outputType] = newCommand
    ..deviceIndex = deviceIndex
    ..featureIndex = feature.featureIndex;
  return msg;
}