setMode method

void setMode(
  1. OperatingMode? mode
)

Changes the current mode this gamepad is controlling, and chooses a new RoverControls.

Implementation

void setMode(OperatingMode? mode) {
  if (mode == null) return;
  if (mode != OperatingMode.none && otherControllerIs(mode)) {
    models.home.setMessage(severity: Severity.error, text: "Another controller is set to that mode");
    return;
  } else if (mode == OperatingMode.drive && otherControllerIs(OperatingMode.modernDrive)) {
    models.home.setMessage(severity: Severity.error, text: "Cannot use both tank and drive controls");
    return;
  } else if (mode == OperatingMode.modernDrive && otherControllerIs(OperatingMode.drive)) {
    models.home.setMessage(severity: Severity.error, text: "Cannot use both tank and drive controls");
    return;
  } else if (mode == OperatingMode.cameras && !models.settings.dashboard.splitCameras) {
    models.home.setMessage(severity: Severity.error, text: "Enable split camera controls in the settings");
    return;
  }
  controls.onDispose.forEach(models.messages.sendMessage);
  controls = RoverControls.forMode(mode);
  gamepad.pulse();
  notifyListeners();
}