Initialise serial port in factory
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// File.swift
|
// VehicleFactory.swift
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Created by Michael Pivato on 20/5/20.
|
// 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.
|
// 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.
|
// 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")
|
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 {
|
guard let throttlePin = Esp32ServoOutput(forChannel: 1, forPin: 14, onPort: serialPort) else {
|
||||||
print("Failed to create throttle pin.")
|
print("Failed to create throttle pin.")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user