settings method

MraaReturnCode settings(
  1. int index,
  2. MraaUartSettings settings
)

Settings - mraa_uart_settings

Get the current settings of a UART. This is an unintrusive function. Meaning it intends not to change anything, only read the values. All but the first index parameter are settable, i.e. they can contain values on return. If any parameter is not set it will be set to null. The device path parameter can be either an in or out parameter. If a negative index is supplied, the UART is identified using the supplied device path instead. This functionality is intended for and needed by for instance USB serial adapters. In case of a non-success return value, the out parameters are undefined and will be set as passed in, see MraaUartSettings.

Implementation

MraaReturnCode settings(int index, MraaUartSettings settings) {
  // Check for either a valid index or a device path
  if (index < 0 && settings.devicePath.isNotEmpty) {
    return MraaReturnCode.errorInvalidParameter;
  }

  // Construct the parameter list
  final ptrDevicePath = ffi.calloc.allocate<Pointer<Char>>(255);
  if (index < 0) {
    ptrDevicePath.value = settings.devicePath.toNativeUtf8().cast<Char>();
  }
  final ptrName = ffi.calloc.allocate<Pointer<Char>>(255);
  final ptrBaudrate = ffi.calloc.allocate<Int>(1);
  final ptrDataBits = ffi.calloc.allocate<Int>(1);
  final ptrStopBits = ffi.calloc.allocate<Int>(1);
  final ptrParity = ffi.calloc.allocate<Int32>(1);
  final ptrRtsCts = ffi.calloc.allocate<UnsignedInt>(1);
  final ptrXonXoff = ffi.calloc.allocate<UnsignedInt>(1);

  // Get the settings
  final ret = _impl.mraa_uart_settings(
      index,
      ptrDevicePath,
      ptrName,
      ptrBaudrate,
      ptrDataBits,
      ptrStopBits,
      ptrParity,
      ptrRtsCts,
      ptrXonXoff);

  // If not success just return the status
  if (MraaReturnCode.returnCode(ret) != MraaReturnCode.success) {
    return MraaReturnCode.returnCode(ret);
  }

  // Set the output parameters
  settings.devicePath = ptrDevicePath.value.cast<ffi.Utf8>().toDartString();
  settings.name = ptrName.value.cast<ffi.Utf8>().toDartString();
  settings.baudRate = ptrBaudrate.value;
  settings.dataBits = ptrDataBits.value;
  settings.stopBits = ptrStopBits.value;
  settings.parity = MraaUartParity.uartParity(ptrParity.value);
  settings.rtsCts = ptrRtsCts.value != 0;
  settings.xonXoff = ptrXonXoff.value != 0;

  // End
  return MraaReturnCode.success;
}