-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.go
More file actions
156 lines (132 loc) · 4.34 KB
/
control.go
File metadata and controls
156 lines (132 loc) · 4.34 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"FlightControl/ThreeDView"
"FlightControl/ThreeDView/camera"
"FlightControl/ThreeDView/types"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"math"
)
var voltageLabel *widget.Label
var statusLabel *widget.Label
var heightLabel *widget.Label
var maxHeightLabel *widget.Label
func updateVoltage(voltage float64) {
voltageLabel.SetText("Voltage: " + fmt.Sprintf("%f", voltage) + " V")
}
func updateStatus(status string) {
statusLabel.SetText("Status: " + status)
}
func updateHeight(height float64) {
heightLabel.SetText("Height: " + fmt.Sprintf("%f", height) + " m")
}
func updateMaxHeight(maxHeight float64) {
maxHeightLabel.SetText("Max height: " + fmt.Sprintf("%f", maxHeight) + " m")
}
func controlTab(App fyne.App, MainWindow fyne.Window) fyne.CanvasObject {
ipLabel := widget.NewLabel("WaRa IP: " + App.Preferences().StringWithFallback("WaRaIP", "Not set"))
voltageLabel = widget.NewLabel("Voltage: N/A")
statusLabel = widget.NewLabel("Status: Not connected")
heightLabel = widget.NewLabel("Height: N/A")
maxHeightLabel = widget.NewLabel("Max height: N/A")
App.Preferences().AddChangeListener(func() {
ipLabel.SetText("WaRa IP: " + App.Preferences().StringWithFallback("WaRaIP", "Not set"))
})
threeDVisualisation, rocket := threeDVisualisation()
resetButton := widget.NewButton("Reset", func() { go reset(App) })
deployParachuteButton := widget.NewButton("Deploy parachute", func() { go deployParachute(App) })
deployStageButton := widget.NewButton("Deploy stage", func() { go deployStage(App) })
getLogButton := widget.NewButton("Get log", func() { go getLog(App) })
ipEditButton := widget.NewButtonWithIcon("", theme.DocumentCreateIcon(), func() {
ipEntry := widget.NewEntry()
ipEntry.SetPlaceHolder("Enter IP")
dialog.ShowForm("Set WaRa IP", "OK", "Cancel", []*widget.FormItem{
widget.NewFormItem("IP", ipEntry),
}, func(ok bool) {
if !ok {
return
}
App.Preferences().SetString("WaRaIP", ipEntry.Text)
updateWebsocket(App)
}, MainWindow)
})
infoLabelContainer := container.NewVBox(
container.NewHBox(ipLabel, ipEditButton), voltageLabel, statusLabel, heightLabel, maxHeightLabel,
)
infoContainer := container.NewGridWithColumns(3,
infoLabelContainer,
container.NewCenter(),
threeDVisualisation,
)
buttons := []fyne.CanvasObject{
resetButton,
deployParachuteButton,
deployStageButton,
getLogButton,
}
var buttonContainer *fyne.Container
if fyne.CurrentDevice().IsMobile() && fyne.CurrentDevice().Orientation() == 0 {
buttonContainer = container.NewVBox(
buttons...,
)
} else {
buttonContainer = container.NewGridWithColumns(3,
buttons...,
)
}
content := container.NewVBox(
infoContainer,
buttonContainer,
)
go func() {
selectedTabChannel := ps.Sub("selectedTab")
for selectedTab := range selectedTabChannel {
selectedTab := selectedTab.(*container.TabItem)
if selectedTab.Text == "Control" {
threeDVisualisation.Show()
} else {
threeDVisualisation.Hide()
}
}
}()
go func() {
newestDataChannel := ps.Sub("newData")
for newestData := range newestDataChannel {
newestData := newestData.(Data)
updateVoltage(newestData.voltage)
updateStatus(string(newestData.status))
updateHeight(newestData.altitude)
updateMaxHeight(newestData.maxAltitude)
rocket.DataChannel <- newestData
}
}()
return content
}
func threeDVisualisation() (fyne.CanvasObject, *Rocket) {
threeDEnv := ThreeDView.NewThreeDWidget()
if fyne.CurrentDevice().IsMobile() {
threeDEnv.SetFPSCap(30)
threeDEnv.SetResolutionFactor(0.3)
} else {
threeDEnv.SetFPSCap(60)
threeDEnv.SetResolutionFactor(0.5)
}
rocket := NewTwoStageRocket(types.Point3D{X: 0, Y: 0, Z: 0}, types.Rotation3D{Roll: 0, Pitch: 0, Yaw: 0}, threeDEnv)
envCamera := camera.NewCamera(types.Point3D{}, types.Rotation3D{})
orbitController := camera.NewOrbitController(rocket)
orbitController.SetControlsEnabled(false)
orbitController.SetRotation(types.Rotation3D{Roll: 0, Pitch: 0, Yaw: 0})
envCamera.SetController(orbitController)
threeDEnv.SetCamera(&envCamera)
updateDistance := func() {
orbitController.SetDistance(types.Unit(math.Max(float64(threeDEnv.Size().Width), float64(threeDEnv.Size().Height)) / 2))
}
threeDEnv.RegisterTickMethod(func() {
updateDistance()
})
return threeDEnv, rocket
}