-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentView.swift
68 lines (58 loc) · 2.91 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// ContentView.swift
// RaspberryPiConnection WatchKit Extension
//
// Created by Jessica Saroufim on 08.09.21.
//
import SwiftUI
struct ContentView: View {
@EnvironmentObject var stateManager: StateManager
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect()
var body: some View {
ScrollView {
#if os(watchOS)
if #available(watchOSApplicationExtension 8.0, *) {
TimelineView(.periodic(from: Date.now, by: 1)) { context in
VStack {
Text("Drone2Buoy App \(stateManager.tick(date: context.date))")
Text("State: \(stateManager.state.state.rawValue)")
Text("WiFi status \(stateManager.wifiConnectivity.isConnected)")
if stateManager.wifiConnectivity.isConnected == "connected" {
Text("Connected to \(stateManager.wifiConnectivity.connectedNetwork)")
} else {
Text("Last connected to \(stateManager.wifiConnectivity.connectedNetwork)")
}
Text("Connected to Pi: \(stateManager.bluetoothConnectivity.connected)")
Text("Pi turned \(stateManager.bluetoothConnectivity.status.rawValue)")
Text("Data received: \(stateManager.receivedData.toString(data: stateManager.receivedData.data))")
NavigationLink("Configuration") {
Setup().environmentObject(stateManager)
}
}
}
} else {
// Fallback on earlier versions
Text("please update to watchos 8 or later")
}
#else
VStack {
Text("Drone2Buoy App")
Text("State: \(stateManager.state.state.rawValue)")
Text("WiFi status \(stateManager.wifiConnectivity.isConnected)")
if stateManager.wifiConnectivity.isConnected == "connected" {
Text("Connected to \(stateManager.wifiConnectivity.connectedNetwork)")
} else {
Text("Last connected to \(stateManager.wifiConnectivity.connectedNetwork)")
}
Text("Connected to Pi: \(stateManager.bluetoothConnectivity.connected)")
Text("Pi turned \(stateManager.bluetoothConnectivity.status.rawValue)")
Text("Data received: \(stateManager.receivedData.toString(data: stateManager.receivedData.data))")
NavigationLink("Configuration") {
Setup().environmentObject(stateManager)
}
}.onReceive(timer) { input in stateManager.tick(date: Date())
}
#endif
}
}
}