iOS simple controller works
This commit is contained in:
@@ -15,42 +15,32 @@ class PiLoader: ObservableObject {
|
||||
// Find a cleaner way to handle these properties
|
||||
@Published var throttle: Float = 0.5
|
||||
@Published var steering: Float = 0.5
|
||||
let port: Int = 50051
|
||||
var stopped = false
|
||||
|
||||
func makeClient(port: Int, group: EventLoopGroup) -> MotorControl_CarControlClient {
|
||||
let channel = ClientConnection.insecure(group: group)
|
||||
// TODO: Pass the host in based on the settings.
|
||||
.connect(host: "10.0.0.55", port: port)
|
||||
|
||||
return MotorControl_CarControlClient(channel: channel)
|
||||
}
|
||||
|
||||
func startUpdating() {
|
||||
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||
defer {
|
||||
try? group.syncShutdownGracefully()
|
||||
}
|
||||
let client = makeClient(port: self.port, group: group)
|
||||
let options = CallOptions(timeout: .seconds(rounding: 10))
|
||||
let call = client.stream_vehicle_2d(callOptions: options)
|
||||
|
||||
call.response.whenFailure { error in
|
||||
print("RecordRoute Failed: \(error)")
|
||||
self.stop()
|
||||
}
|
||||
|
||||
call.status.whenComplete { _ in
|
||||
print("Finished RecordRoute")
|
||||
self.stop()
|
||||
}
|
||||
|
||||
call.response.whenSuccess { summary in
|
||||
print("Finished")
|
||||
self.stop()
|
||||
}
|
||||
|
||||
DispatchQueue.global(qos: .userInteractive).async{
|
||||
func startUpdating(forPort port: Int, atHost host: String) {
|
||||
DispatchQueue.global(qos: .background).async{
|
||||
let group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
|
||||
defer {
|
||||
try? group.syncShutdownGracefully()
|
||||
}
|
||||
let client = makeClient(port: port, host: host, group: group)
|
||||
let options = CallOptions(timeout: .seconds(rounding: 10))
|
||||
let call = client.stream_vehicle_2d(callOptions: options)
|
||||
|
||||
call.response.whenFailure { error in
|
||||
print("Failed: \(error)")
|
||||
self.stop()
|
||||
}
|
||||
|
||||
call.status.whenComplete { _ in
|
||||
print("Finished")
|
||||
self.stop()
|
||||
}
|
||||
|
||||
call.response.whenSuccess { summary in
|
||||
print("Finished")
|
||||
self.stop()
|
||||
}
|
||||
// Running in background. Do the update thread stuff.
|
||||
while (!self.stopped){
|
||||
call.sendMessage(self.createProto(), promise: nil)
|
||||
@@ -74,3 +64,12 @@ class PiLoader: ObservableObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeClient(port: Int, host: String, group: EventLoopGroup) -> MotorControl_CarControlClient {
|
||||
let channel = ClientConnection.insecure(group: group)
|
||||
// TODO: Pass the host in based on the settings.
|
||||
.connect(host: host, port: port)
|
||||
|
||||
|
||||
return MotorControl_CarControlClient(channel: channel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user