readInput method

Future<Map<InputType, InputDataType>> readInput(
  1. InputType inputType
)

Implementation

Future<Map<InputType, InputDataType>> readInput(InputType inputType) async {
  _ensureValid();
  final input = feature.input;
  if (input == null) {
    throw ButtplugClientDeviceFeatureCapabilityException(
      '${feature.featureDescription} does not have a readable input',
    );
  }
  final inputInfo = input[inputType];
  if (inputInfo == null) {
    throw ButtplugClientDeviceFeatureCapabilityException(
      '${feature.featureDescription} does not have input type $inputType',
    );
  }
  final supportsRead = inputInfo.command.any((command) => command.toLowerCase() == InputCommand.read.name.toLowerCase());
  if (!supportsRead) {
    throw ButtplugClientDeviceFeatureCapabilityException(
      '${feature.featureDescription} does not support Read for $inputType',
    );
  }

  final sensorReadMsg = InputCmd()
    ..deviceIndex = deviceIndex
    ..featureIndex = feature.featureIndex
    ..type = inputType
    ..command = InputCommand.read;
  final returnMsg = await _communicator.sendMessageExpectReply(sensorReadMsg);
  if (returnMsg.inputReading == null) {
    throw ButtplugClientDeviceFeatureCapabilityException(
      'Did not receive InputReading back from InputCmd transaction',
    );
  }
  return returnMsg.inputReading!.reading;
}