44 lines
1.1 KiB
Swift
44 lines
1.1 KiB
Swift
//
|
|
// SimpleControllerView.swift
|
|
// CarController
|
|
//
|
|
// Created by Michael Pivato on 13/4/20.
|
|
// Copyright © 2020 Michael Pivato. All rights reserved.
|
|
//
|
|
|
|
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
|
|
}
|
|
.rotationEffect(.degrees(270))
|
|
|
|
Slider(value: $grpcController.steering, in: 0...1){_ in
|
|
self.grpcController.steering = 0.5
|
|
}
|
|
}
|
|
.onAppear(){
|
|
self.grpcController.startUpdating()
|
|
}
|
|
.onDisappear(){
|
|
// Stop the gRPC updater.
|
|
self.grpcController.stop()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SimpleControllerView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SimpleControllerView()
|
|
.environmentObject(ServerData())
|
|
}
|
|
}
|