diff --git a/SwiftyCar/Sources/SwiftyCar/VehicleFactory.swift b/SwiftyCar/Sources/SwiftyCar/VehicleFactory.swift index e0f78a8..df83c86 100644 --- a/SwiftyCar/Sources/SwiftyCar/VehicleFactory.swift +++ b/SwiftyCar/Sources/SwiftyCar/VehicleFactory.swift @@ -1,5 +1,5 @@ // -// File.swift +// VehicleFactory.swift // // // Created by Michael Pivato on 20/5/20. @@ -22,6 +22,10 @@ func getVehicle2D() throws -> Vehicle2D? { // TODO: Get from environment variable. tty won't work in macos anyway. // We share the serialport object, as cu will block on macOS (required by SwiftSerial), so can't open 2 of the same port. let serialPort = SerialPort(path: "/dev/ttyUSB0") + + // The port does not open/initialise inside of the ESP32ServoOutputs, as on macOS /dev/cu.* blocks. + try initPort.openPort() + initPort.setSettings(receiveRate: .baud115200, transmitRate: .baud115200, minimumBytesToRead: 1)x guard let throttlePin = Esp32ServoOutput(forChannel: 1, forPin: 14, onPort: serialPort) else { print("Failed to create throttle pin.") return nil