-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
408 lines (400 loc) · 14 KB
/
Main.qml
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
import QtQuick
import QtQuick.Controls
import QtQuick.Shapes
import QtQuick.Effects
import QtQuick.Controls.Material
ApplicationWindow {
visible: true
width: 1280
height: 720
title: "DashBeam"
Material.theme: Material.Dark
Component.onCompleted: {
console.log("Main Window: Starting udpListener...")
udpListener.setPort(ogPort)
udpListener.start()
}
onClosing: close => {
udpListener.stop()
console.log("Main Window: Stopped udpListener. Bye...")
}
FontLoader {
id: uiFont
source: "assets/Aldrich-Regular.ttf"
}
FontLoader {
id: circleFont
source: "assets/JetBrainsMono-Bold.ttf"
}
Rectangle {
width: parent.width
height: parent.height
color: "#151515"
anchors.centerIn: parent
// Central display
Rectangle {
id: centerBox
width: parent.width * 0.3
height: parent.height * 0.4
color: "#060607"
radius: 4
anchors.centerIn: parent
border.color: "#292929"
border.width: 1
clip: true
Image {
id: brandingIcon
source: "assets/screen_topleft.svg"
layer.enabled: true
width: parent.height
height: parent.height
anchors.left: parent.left
anchors.top: parent.top
anchors.margins: 5
layer.effect: MultiEffect {
saturation: vThrottle == 1 ? 1.0 : -1.0
opacity: vThrottle == 1 ? 1.0 : 0.5
}
}
Text {
id: gearText
anchors.centerIn: parent
text: (vGear - 1).toString()
color: "white"
font.pixelSize: parent.height / 2
font.family: uiFont.name
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
Text {
id: fuelText
anchors.left: parent.left
anchors.bottom: fuelBar.top
text: "Fuel"
anchors.leftMargin: 10
color: "white"
font.pixelSize: parent.height / 18
font.family: uiFont.name
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
ColorBar {
id: fuelBar
horizontal: true
width: parent.width * 0.95
radius: 5
height: parent.height * 0.02
anchors.bottom: coolantText.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 5
value: vFuel
fillColor: "#32389f"
}
Text {
id: coolantText
anchors.left: parent.left
anchors.bottom: coolantBar.top
text: "Coolant Temp"
anchors.leftMargin: 10
color: "white"
font.pixelSize: parent.height / 18
font.family: uiFont.name
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
ColorBar {
id: coolantBar
horizontal: true
width: parent.width * 0.95
radius: 5
height: parent.height * 0.02
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 5
value: vEngTemp/180
fillColor: "#9f3244"
}
}
// RPM Gauge (Left)
CircleMeter {
id: tacho
radius: Math.min(parent.width / 6, parent.height / 2) - 10
width: parent.width / 3
height: parent.height
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
tickStep: 0.5 / 5
tickCount: 91
tickDivide: 120
longTickEvery: 5
labelSkipEvery: 10
needleValue: vRpm / 1000
labelFontSize: radius / 10
tickFontName: uiFont.name
tickColor: "#FE8000"
strokeColor: "#FE8000"
labelFontColor: "#FE8000"
backgroundColorInner: vShowLights.includes(
"DL_SHIFT") ? "#392424" : "#242424"
redline: clShiftPoint > 0 ? clShiftPoint / 1000 : 99999.9
middleText: "<h1><b>" + vRpm.toFixed() + "</b></h1>RPM"
middleFontSize: radius / 8
middleFontName: circleFont.name
}
// Speed Gauge (Right)
CircleMeter {
id: speedo
radius: Math.min(parent.width / 6, parent.height / 2) - 10
width: parent.width / 3
height: parent.height
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
needleValue: vSpeed
tickStep: 2
tickCount: 151 // 75% + 1 for 3/4 quarters
tickDivide: 200
startAngle: 270
tickColor: "#FE8000"
strokeColor: "#FE8000"
labelFontColor: "#FE8000"
labelSkipEvery: 10
longTickEvery: 5
tickFontName: uiFont.name
redline: 280
middleText: "<h1><b>" + vSpeed.toFixed() + "</b></h1>km/h"
middleFontSize: radius / 8
middleFontName: circleFont.name
}
// Turbo
CircleMeter {
id: boostGauge
visible: vFlags.includes("OG_TURBO")
tickStart: -1.5
radius: Math.min(parent.width / 8, parent.height / 8) - 10
width: parent.width / 4
height: parent.height / 4
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: parent.height * 0.01
needleValue: vTurbo
tickStep: 0.1
tickCount: 41
tickDivide: 50
startAngle: 270
tickColor: "#FE8000"
strokeColor: "#FE8000"
labelFontColor: "#FE8000"
longTickLength: radius / 8
shortTickLength: radius / 12
labelSkipEvery: 5
longTickEvery: 5
tickFontName: uiFont.name
needleWidth: radius / 20
labelFontSize: radius / 8
middleText: "<h1><b>" + vTurbo.toFixed(2) + "</b></h1>bar"
middleFontSize: radius / 8
middleFontName: circleFont.name
}
Rectangle {
id: indicators
width: 0.4 * parent.width
height: 0.08 * parent.height
color: "#1F1F1F"
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.margins: parent.height * 0.1
radius: height / 5
border.color: "#292929"
border.width: 1
Image {
id: sourceItemL
source: "assets/signal_l.svg"
layer.enabled: true
width: parent.height - 15
height: parent.height - 15
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
layer.effect: MultiEffect {
saturation: vShowLights.includes("DL_SIGNAL_L") ? 1.0 : -1.0
opacity: vShowLights.includes("DL_SIGNAL_L") ? 1.0 : 0.5
}
}
Image {
id: highbeamImg
source: "assets/highbeam.svg"
layer.enabled: true
width: parent.height - 15
height: parent.height - 15
anchors.left: sourceItemL.right
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
layer.effect: MultiEffect {
saturation: vShowLights.includes("DL_FULLBEAM") ? 1.0 : -1.0
opacity: vShowLights.includes("DL_FULLBEAM") ? 1.0 : 0.5
}
}
Image {
id: handbrakeWarn
source: "assets/handbrake.svg"
layer.enabled: true
width: parent.height - 15
height: parent.height - 15
anchors.right: sourceItemR.left
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
layer.effect: MultiEffect {
saturation: vShowLights.includes(
"DL_HANDBRAKE") ? 1.0 : -1.0
opacity: vShowLights.includes("DL_HANDBRAKE") ? 1.0 : 0.5
}
}
Image {
id: sourceItemR
source: "assets/signal_r.svg"
layer.enabled: true
width: parent.height - 15
height: parent.height - 15
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.margins: 10
// For the layered items, you can assign a MultiEffect directly
// to layer.effect.
layer.effect: MultiEffect {
saturation: vShowLights.includes("DL_SIGNAL_R") ? 1.0 : -1.0
opacity: vShowLights.includes("DL_SIGNAL_R") ? 1.0 : 0.5
}
}
}
ShiftLights {
id: shiftLights
visible: showMultiLights ? (clShiftPoint > 0) : vDashLights.includes(
"DL_SHIFT")
maxShiftPoint: clShiftPoint
vehicleRpm: vRpm
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.margins: parent.height * 0.025
shiftSingleOn: !showMultiLights
numLeds: numShiftLeds
shiftSingleNow: vShowLights.includes("DL_SHIFT")
}
// Pedal inputs
Rectangle {
color: "#1F1F1F"
width: 0.075 * parent.width
height: 0.15 * parent.height
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color: "#292929"
border.width: 1
radius: 5
anchors.margins: 10
ColorBar {
id: clutchBar
width: parent.width / 4
radius: 5
height: parent.height * 0.9
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.margins: 5
value: vClutch
fillColor: "#23319f"
}
ColorBar {
id: brakeBar
width: parent.width / 4
radius: 5
height: parent.height * 0.9
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.margins: 5
value: vBrake
fillColor: "#9f2831"
}
ColorBar {
id: throttleBar
width: parent.width / 4
radius: 5
height: parent.height * 0.9
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.margins: 5
value: vThrottle
fillColor: "#239f21"
}
}
RoundButton {
text: "Settings"
width: 100
height: 40
radius: 5
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: 10
onClicked: settingsLoader.source = "SettingsPage.qml"
}
}
// Settings Page Loader
Loader {
id: settingsLoader
anchors.fill: parent
}
property var vFlags: []
property int vGear: 0
property real vSpeed: 0.0
property real vRpm: 0.0
property real vTurbo: 0.0
property real vEngTemp: 0.0
property real vFuel: 0.0
property real vOilTemp: 0.0
property var vDashLights: []
property var vShowLights: []
property real vThrottle: 0.0
property real vBrake: 0.0
property real vClutch: 0.0
property int vId: 0
// Client side options
property real clShiftPoint: settingsManager.loadSetting("shiftPoint", -1.0)
property int numShiftLeds: settingsManager.loadSetting("numLeds", 9)
property int ogPort: settingsManager.loadSetting("ogPort", 4444)
property bool showMultiLights: settingsManager.loadSetting("isShift", false)
// Connect to C++ signal for a packet
Connections {
target: udpListener
function onOutGaugeUpdated(data) {
vFlags = data.flags
vGear = data.gear
vSpeed = data.speed * 3.6 // Convert speed from m/s to km/h
vRpm = data.rpm
vTurbo = data.turbo
vEngTemp = data.engTemp
vFuel = data.fuel
vOilTemp = data.oilTemp
vDashLights = data.dashLights
vShowLights = data.showLights
vThrottle = data.throttle
vBrake = data.brake
vClutch = data.clutch
vId = data.id
}
}
Connections {
target: settingsManager
function onSettingChanged(key, value) {
if (key === "ogPort") {
ogPort = value
udpListener.setPort(ogPort)
udpListener.start()
} else if (key === "shiftPoint") {
clShiftPoint = value
} else if (key === "isShift") {
showMultiLights = value
} else if (key === "numLeds") {
numShiftLeds = value
}
}
}
}