iOS simple controller works

This commit is contained in:
Piv
2020-05-06 21:44:42 +09:30
parent 9376bd70ed
commit 4b3b960d22
7 changed files with 90 additions and 97 deletions

View File

@@ -10,27 +10,33 @@ import SwiftUI
struct SimpleControllerView: View {
@EnvironmentObject var server: ServerData
// Need lazy so that we can initialise with local properties.
@ObservedObject var grpcController: PiLoader = PiLoader()
var body: some View {
HStack{
Slider(value: $grpcController.throttle, in: 0...1){_ in
self.grpcController.throttle = 0.5
VStack (alignment: .trailing, spacing: 0){
Spacer()
HStack{
// Move this up a bit, due to being rotated.
Slider(value: self.$grpcController.throttle, in: 0...1){_ in
self.grpcController.throttle = 0.5
}
.offset(x: 200)
.frame(width: 300)
.rotationEffect(.degrees(270))
Spacer()
Slider(value: self.$grpcController.steering, in: 0...1){_ in
self.grpcController.steering = 0.5
}
.frame(width:300)
.offset(x: -50, y: -200)
.padding()
}
.rotationEffect(.degrees(270))
Slider(value: $grpcController.steering, in: 0...1){_ in
self.grpcController.steering = 0.5
.onAppear(){
self.grpcController.startUpdating(forPort: self.server.grpcPort, atHost: self.server.host)
}
.onDisappear(){
self.grpcController.stop()
}
}
.onAppear(){
self.grpcController.startUpdating()
}
.onDisappear(){
// Stop the gRPC updater.
self.grpcController.stop()
}
}
}