-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_settings_menu.go
165 lines (148 loc) · 4.05 KB
/
gui_settings_menu.go
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
157
158
159
160
161
162
163
164
165
package main
import (
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
serialv "go.bug.st/serial"
"github.com/duncanvanzyl/xplane-serial-gps-connector/nmea"
"github.com/duncanvanzyl/xplane-serial-gps-connector/serial"
)
// SettingsMenu returns the settings menu
func (ui *AppUI) SettingsMenu(w fyne.Window) *fyne.Menu {
prMenu := fyne.NewMenuItem("Precision", func() {
prGrp := widget.NewRadioGroup([]string{"Standard", "Enhanced"}, func(value string) {
switch value {
case "Standard":
nmea.Formats = nmea.DEFAULTS
case "Enhanced":
nmea.Formats = nmea.ENHANCED
}
ui.Logger.Debug("Precision Changed", "precision", value)
})
if nmea.Formats == nmea.ENHANCED {
prGrp.SetSelected("Enhanced")
} else {
prGrp.SetSelected("Standard")
}
info := widget.NewLabel(
"Sets the number of decimal places in the NMEA\n" +
"Sentences.\n" +
"• Standard follows the NMEA standard.\n" +
"• Enhanced adds more decimal places to the NMEA\n" +
" Sentences, but may not be supported by all devices.")
// info.Alignment = fyne.TextAlignLeading
c := container.NewVBox(
info,
widget.NewSeparator(),
prGrp,
)
dialog.ShowCustom("Precision", "Done", c, w)
})
spMenu := fyne.NewMenuItem("Serial Port", func() {
ser, ok := ui.app.Serial.(*serial.Serial)
if !ok {
return
}
mode := ser.Mode()
dataBits := widget.NewSelect([]string{"8", "7", "6", "5"}, func(value string) {
v, err := strconv.Atoi(value)
if err != nil {
ui.Logger.Error("Failed to convert DataBits", "err", err)
return
}
if v < 5 || v > 8 {
ui.Logger.Error("Invalid DataBits", "databits", v)
return
}
ser.SetDataBits(v)
ui.Logger.Debug("Set DataBits", "databits", value)
})
parity := widget.NewSelect([]string{"None", "Odd", "Even", "Mark", "Space"}, func(value string) {
switch value {
case "Odd":
ser.SetParity(serialv.OddParity)
case "Even":
ser.SetParity(serialv.EvenParity)
case "Mark":
ser.SetParity(serialv.MarkParity)
case "Space":
ser.SetParity(serialv.SpaceParity)
default:
ser.SetParity(serialv.NoParity)
}
ui.Logger.Debug("Set Parity", "parity", value)
})
stopBits := widget.NewSelect([]string{"1", "1.5", "2"}, func(value string) {
switch value {
case "1.5":
ser.SetStopBits(serialv.OnePointFiveStopBits)
case "2":
ser.SetStopBits(serialv.TwoStopBits)
default:
ser.SetStopBits(serialv.OneStopBit)
ui.Logger.Debug("Set StopBits", "stopbits", value)
}
})
info := widget.NewLabel("These are the advanced settings for the serial port.")
info.Alignment = fyne.TextAlignCenter
// info.Wrapping = fyne.TextWrapWord
warning := widget.NewLabel(
"You probably don't want to change these settings\n" +
"unless you know what you are doing.",
)
warning.Alignment = fyne.TextAlignCenter
// warning.Wrapping = fyne.TextWrapWord
warning.Importance = widget.HighImportance
dialog.ShowCustom("Serial Port", "Done",
container.NewVBox(
info,
warning,
widget.NewSeparator(),
container.New(layout.NewFormLayout(),
widget.NewLabel("Baude Rate"), ui.baudRate,
widget.NewLabel("Data Bits"), dataBits,
widget.NewLabel("Parity"), parity,
widget.NewLabel("Stop Bits"), stopBits,
),
),
w,
)
switch mode.DataBits {
case 7:
dataBits.SetSelected("7")
case 6:
dataBits.SetSelected("6")
case 5:
dataBits.SetSelected("5")
default:
dataBits.SetSelected("8")
}
switch mode.Parity {
case serialv.OddParity:
parity.SetSelected("Odd")
case serialv.EvenParity:
parity.SetSelected("Even")
case serialv.MarkParity:
parity.SetSelected("Mark")
case serialv.SpaceParity:
parity.SetSelected("Space")
default:
parity.SetSelected("None")
}
switch mode.StopBits {
case serialv.OnePointFiveStopBits:
stopBits.SetSelected("1.5")
case serialv.TwoStopBits:
stopBits.SetSelected("2")
default:
stopBits.SetSelected("1")
}
})
return fyne.NewMenu("Settings",
prMenu,
spMenu,
)
}