-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.qml.in
3656 lines (3003 loc) · 136 KB
/
ui.qml.in
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2022 Benjamin Vedder <[email protected]>
// Copyright 2024 Lukas Hrazky
//
// This file is part of the Stig VESC package.
//
// Stig VESC package is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// Stig VESC package is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
import Qt.labs.settings 1.0
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Dialogs 1.3 as Dl
import QtGraphicalEffects 1.15
import Vedder.vesc.vescinterface 1.0
import Vedder.vesc.commands 1.0
import Vedder.vesc.configparams 1.0
import Vedder.vesc.utility 1.0
import QtQuick.Controls.Material 2.2
Item {
id: mainItem
property Commands vescCommands: VescIf.commands()
// Used to fix the float negative zero problem where applicable
function toFixed1Zero(num) {
return num.toFixed(1).replace("-0.0", "0.0");
}
function clamp(val, min, max) {
if (val > max) {
return max;
}
if (val < min) {
return min;
}
return val;
}
// 5s timeout for connection to package
Timer {
id: packageConnectionWatchdog
interval: 5000
running: true
onTriggered: {
state.pkgState = state.s_Disconnected;
}
}
// 10hz for realtime data
Timer {
running: true
repeat: true
interval: 100
onTriggered: {
vescCommands.getValuesSetup();
if (!commands.infoReceived) {
commands.sendGetInfo();
} else {
commands.sendGetRtData();
}
if (moveSlider.value != 0) {
commands.sendRcMove(moveSlider.value);
}
if (tiltEnabled.checked) {
vescCommands.lispSendReplCmd("(set-remote-state " + tiltSlider.value + " 0 0 0 0)");
}
}
}
// 4Hz timer to poll for lights status if enabled
Timer {
running: lights.enabled
repeat: true
interval: 250
triggeredOnStart: true
onTriggered: {
commands.sendLightsControl();
}
}
// 100hz for for UI updates
Timer {
running: true
repeat: true
interval: 10
onTriggered: {
if (!moveSlider.pressed) {
var stepSize = 0.05;
if (moveSlider.value > 0) {
if (moveSlider.value < stepSize) {
moveSlider.value = 0;
} else {
moveSlider.value -= stepSize;
}
} else if (moveSlider.value < 0) {
if (moveSlider.value > -stepSize) {
moveSlider.value = 0;
} else {
moveSlider.value += stepSize;
}
}
}
if (!tiltSlider.pressed) {
var stepSize = 0.05;
if (tiltSlider.value > 0) {
if (tiltSlider.value < stepSize) {
tiltSlider.value = 0;
} else {
tiltSlider.value -= stepSize;
}
} else if (tiltSlider.value < 0) {
if (tiltSlider.value > -stepSize) {
tiltSlider.value = 0;
} else {
tiltSlider.value += stepSize;
}
}
}
}
}
Connections {
id: vescConfig
target: VescIf
property bool useImperial: VescIf.useImperialUnits()
property string distanceUnit: useImperial ? "mi" : "km"
property string speedUnit: useImperial ? "mph" : "km/h"
property real imperialFactor: useImperial ? 0.621371192 : 1.0;
function onUseImperialUnitsChanged(useImperialUnits) {
useImperial = useImperialUnits;
}
}
Connections {
id: motorConfig
property ConfigParams mcConfig: VescIf.mcConfig()
target: mcConfig
property int batteryCells: mcConfig.getParamInt("si_battery_cells")
property real tempMotorStart: mcConfig.getParamDouble("l_temp_motor_start")
property real tempFetStart: mcConfig.getParamDouble("l_temp_fet_start")
property real currentMin: mcConfig.getParamDouble("l_current_min")
property real currentMax: mcConfig.getParamDouble("l_current_max")
property real inCurrentMin: mcConfig.getParamDouble("l_in_current_min")
property real inCurrentMax: mcConfig.getParamDouble("l_in_current_max")
function onParamChangedDouble(src, name, newParam) {
if (name === "l_temp_motor_start") {
tempMotorStart = newParam;
} else if (name === "l_temp_fet_start") {
tempFetStart = newParam;
} else if (name === "l_current_min") {
currentMin = newParam;
} else if (name === "l_current_max") {
currentMax = newParam;
} else if (name === "l_in_current_min") {
inCurrentMin = newParam;
} else if (name === "l_in_current_max") {
inCurrentMax = newParam;
}
}
function onParamChangedInt(src, name, newParam) {
if (name === "si_battery_cells") {
batteryCells = newParam;
}
}
}
Connections {
id: packageConfig
target: VescIf
property ConfigParams pkgConfig: VescIf.customConfig(0);
function onCustomConfigLoadDone() {
pkgConfig = VescIf.customConfig(0);
}
function checkConfig() {
state.configLoadingError = !pkgConfig;
return !!pkgConfig;
}
function setDisabled(disabled) {
if (!checkConfig()) return;
pkgConfig.updateParamBool("disabled", disabled);
vescCommands.customConfigSet(0, pkgConfig);
}
function fetchConfig(tuneOnly) {
if (!checkConfig()) return;
var tuneBlacklist = [
"disabled",
"hardware.mass",
"hardware.remote.type",
"hardware.remote.deadband",
"hardware.esc.frequency",
"hardware.motor.torque_constant",
"hardware.motor.rolling_resistance",
"hardware.motor.acceleration_resistance",
"rider.mass",
"rider.drag_coefficient",
"warnings.battery_cells",
"warnings.hv_threshold",
"warnings.lv_threshold",
"faults.adc1_threshold",
"faults.adc2_threshold",
];
var settings = [];
for (let subGroup of pkgConfig.getParamSubgroups("General")) {
for (let param of pkgConfig.getParamsFromSubgroup("General", subGroup)) {
if (tuneOnly && tuneBlacklist.includes(param)) {
continue;
}
var item = {"name": param};
if (pkgConfig.isParamDouble(param)) {
item.type = "Double";
item.value = pkgConfig.getParamDouble(param);
} else if (pkgConfig.isParamInt(param)) {
item.type = "Int";
item.value = pkgConfig.getParamInt(param);
} else if (pkgConfig.isParamEnum(param)) {
item.type = "Enum";
item.value = pkgConfig.getParamEnum(param);
} else if (pkgConfig.isParamBool(param)) {
item.type = "Bool";
item.value = pkgConfig.getParamBool(param);
} else if (pkgConfig.isParamQString(param)) {
item.type = "String";
item.value = pkgConfig.getParamQString(param);
} else if (pkgConfig.isParamBitfield(param)) {
item.type = "Bitfield";
item.value = pkgConfig.getParamInt(param);
} else {
// e.g. a separator
continue;
}
settings.push(item);
}
}
return settings;
}
function applyConfig(config) {
if (!checkConfig()) return;
if (config.version !== "1.0") {
VescIf.emitStatusMessage("Error: Unexpected version: %1".arg(config.version), false);
return;
}
for (let item of config.settings) {
if (item.type === "Double") {
pkgConfig.updateParamDouble(item.name, item.value);
} else if (item.type === "Int") {
pkgConfig.updateParamInt(item.name, item.value);
} else if (item.type === "Bool") {
pkgConfig.updateParamBool(item.name, item.value);
} else if (item.type === "Enum") {
pkgConfig.updateParamEnum(item.name, item.value);
} else if (item.type === "String") {
pkgConfig.updateParamString(item.name, item.value);
} else if (item.type === "Bitfield") {
pkgConfig.updateParamInt(item.name, item.value);
}
}
vescCommands.customConfigSet(0, pkgConfig);
}
// TODO don't do this...
function setInputTiltRemoteType(type) {
if (!checkConfig()) return;
if (pkgConfig.getParamEnum("hardware.remote.type", 0) != 1) {
pkgConfig.updateParamEnum("hardware.remote.type", 1);
vescCommands.customConfigSet(0, pkgConfig);
}
}
}
Connections {
id: commands
target: vescCommands
readonly property int c_GET_INFO: 0
readonly property int c_RC_MOVE: 7
readonly property int c_HANDTEST: 13
readonly property int c_GET_RT_DATA_2: 201
readonly property int c_LIGHTS_CONTROL: 202
property bool infoReceived: false
function createData(size, command) {
var data = new DataView(new ArrayBuffer(size));
var ind = 0;
data.setUint8(ind++, 101);
data.setUint8(ind++, command);
return data;
}
function sendGetInfo() {
vescCommands.sendCustomAppData(createData(2, c_GET_INFO).buffer);
}
function sendGetRtData() {
vescCommands.sendCustomAppData(createData(2, c_GET_RT_DATA_2).buffer);
}
function sendLightsControl(on, headlightsOn) {
var data = createData(4, c_LIGHTS_CONTROL);
var mask = 0;
var value = 0;
if (on !== undefined) {
mask |= 0b01;
if (on) {
value |= 0b01;
}
}
if (headlightsOn !== undefined) {
mask |= 0b10;
if (headlightsOn) {
value |= 0b10;
}
}
data.setUint8(2, mask);
data.setUint8(3, value);
vescCommands.sendCustomAppData(data.buffer);
}
function sendRcMove(value) {
var data = createData(6, c_RC_MOVE);
var current = Math.abs(Math.round(value * 70)) + 10;
data.setUint8(2, value > 0 ? 1 : 0); // direction
data.setUint8(3, current); // current
data.setUint8(4, 1); // time
data.setUint8(5, current + 1); // sum = time + current
vescCommands.sendCustomAppData(data.buffer);
}
function sendHandtest(on) {
var data = createData(3, c_HANDTEST);
data.setUint8(2, on); // on (1) / off (0)
vescCommands.sendCustomAppData(data.buffer);
}
function onValuesSetupReceived(values, mask) {
var fault = values.fault_str;
fault = fault.replace("FAULT_CODE_", "");
state.vescFault = fault != "NONE" ? fault : "";
batteryBar.voltage = values.v_in;
batteryBar.value = values.battery_level * 100;
var speed = Math.abs(values.speed * 3.6 * vescConfig.imperialFactor);
speedDial.value = speed;
speedDial.erpm = Math.abs(values.rpm);
currentDial.value = values.current_motor;
dutyDial.value = Math.abs(values.duty_now * 100);
batteryCurrent.value = values.current_in;
motorTemp.value = values.temp_motor;
controllerTemp.value = values.temp_mos;
odometer.value = Math.round(values.odometer * 0.001 * vescConfig.imperialFactor);
tachometer.value = values.tachometer_abs * 0.001 * vescConfig.imperialFactor;
consumption.add(Math.max(Math.min(values.current_in * values.v_in / Math.max(speed, 1e-6), 60) , -60));
}
function onCustomAppDataReceived(data) {
var dv = new DataView(data, 0);
var ind = 0;
var packageId = dv.getUint8(ind++);
if (packageId !== 101) {
return;
}
var msgtype = dv.getUint8(ind++);
if (msgtype == c_GET_INFO) {
ind += 2;
var led_type = dv.getUint8(ind++);
if (led_type > 0) {
lights.enabled = true;
if (led_type == 3) {
lights.lcm = true;
}
}
commands.infoReceived = true;
} else if (msgtype == c_LIGHTS_CONTROL) {
var values = dv.getUint8(ind++);
lights.on = values & 0b01;
lights.headlightsOn = values & 0b10;
} else if (msgtype === c_GET_RT_DATA_2) {
var mask = dv.getUint8(ind++);
var hasRuntime = !!(mask & 0x1);
var hasCharging = !!(mask & 0x2);
var modeAndState = dv.getUint8(ind++);
state.pkgMode = modeAndState >> 4;
state.pkgState = modeAndState & 0xF;
var sensorAndFlags = dv.getUint8(ind++);
state.fsState = sensorAndFlags >> 6;
state.wheelslip = sensorAndFlags & 0b00000001;
state.charging = sensorAndFlags & 0b00100000;
var setpointAndStop = dv.getUint8(ind++);
state.setpointAdjustmentType = setpointAndStop >> 4;
state.stopCondition = setpointAndStop & 0xF;
state.beepReason = dv.getUint8(ind++);
pitch.pitchValue = dv.getFloat32(ind); ind += 4;
pitch.balancePitchValue = dv.getFloat32(ind); ind += 4;
roll.value = dv.getFloat32(ind); ind += 4;
state.adc1Voltage = dv.getFloat32(ind); ind += 4;
state.adc2Voltage = dv.getFloat32(ind); ind += 4;
debugTest.rValue = dv.getFloat32(ind); ind += 4;
if (hasRuntime) {
pitch.setpointValue = dv.getFloat32(ind); ind += 4;
debugModifiersTarget.rValue = dv.getFloat32(ind); ind += 4;
debugModifiersValue.rValue = dv.getFloat32(ind); ind += 4;
debugModifiersSpeed.rValue = dv.getFloat32(ind); ind += 4;
debugPidProportional.rValue = dv.getFloat32(ind); ind += 4;
debugPidIntegral.rValue = dv.getFloat32(ind); ind += 4;
debugPidDerivative.rValue = dv.getFloat32(ind); ind += 4;
debugTractionConfidence.rValue = dv.getFloat32(ind); ind += 4;
debugTractionMultiplier.rValue = dv.getFloat32(ind); ind += 4;
debugAtrSlope.rValue = dv.getFloat32(ind); ind += 4;
debugWheelSpeed.rValue = dv.getFloat32(ind); ind += 4;
debugBoardSpeed.rValue = dv.getFloat32(ind); ind += 4;
debugWheelAccel.rValue = dv.getFloat32(ind); ind += 4;
debugBoardAccel.rValue = dv.getFloat32(ind); ind += 4;
}
if (hasCharging) {
chargingInfo.current = dv.getFloat32(ind); ind += 4;
chargingInfo.voltage = dv.getFloat32(ind); ind += 4;
}
}
packageConnectionWatchdog.restart();
}
}
// Old Float package settings, used to retrieve quicksaves
Settings {
id: floatSettings
}
Settings {
id: preferences
category: "preferences"
property int speedDialMax: vescConfig.useImperial ? 30 : 40
property alias swapAdcs: prefSwapAdcs.checked
property alias showBattVoltage: prefShowBattVoltage.checked
property alias showBattVoltagePerCell: prefShowBattVoltagePerCell.checked
property alias battCurrentLog: prefBattCurrentLog.checked
property int tempWarningOffset: 10
property alias tuneSlotCount: prefTuneSlotCount.value
property alias showWelcomeDialog: prefShowWelcomeDialog.checked
}
QtObject {
id: tuneManager
readonly property string formatVersion: "1.0"
readonly property string packageName: "Stig"
readonly property string packageVersion: "{{VERSION}}"
readonly property int maxTunes: 6
// Storage for tunes as well as full package configs
property var tuneStorage: Settings {
id: tuneStorage
category: "configs"
property var tuneArchive
property var tuneArchiveDownloadDate
// An array storing Float tune names that have been converted for
// each slot. Prevents converting tunes over and over again, until
// the name changes for the Float tune.
property var floatTunesConverted: Array(6)
property var fullBackup
}
property var tuneNames: {
var names = {}
for (var slot = 1; slot <= maxTunes; slot++) {
var tune = loadTune(slot);
if (tune) {
names[slot] = tune.name;
}
}
return names;
}
property alias fullBackup: tuneStorage.fullBackup
function tuneId(slot) {
return "tune_slot_" + slot;
}
function createTune(name, description, settings) {
var tune = {
"version": formatVersion,
"name": name,
"date": new Date(),
"package": {
"name": packageName,
"version": packageVersion
},
"settings": settings
};
if (description) {
tune.description = description;
}
return tune;
}
function updateTune(tune, name, description, settings) {
tune.name = name;
if (description) {
tune.description = description;
}
if (settings) {
tune.settings = settings;
tune.date = new Date();
}
}
function createBackup() {
return createTune("Full Backup", "", packageConfig.fetchConfig(false));
}
function saveTune(slot, tune) {
var id = tuneId(slot);
tuneStorage.setValue(id, JSON.stringify(tune));
tuneNames[slot] = tune.name;
// workaround needed so that the change is written through to the storage
tuneNames = tuneNames;
}
function loadTune(slot) {
var tuneJson = tuneStorage.value(tuneId(slot), "");
if (tuneJson) {
return JSON.parse(tuneJson);
}
return null;
}
function eraseTune(slot) {
tuneStorage.setValue(tuneId(slot), "");
tuneNames[slot] = null;
// workaround needed so that the change is written through to the storage
tuneNames = tuneNames;
}
function slotEmpty(slot) {
return !tuneStorage.value(tuneId(slot), null);
}
function saveTuneArchive(tuneArchive) {
tuneStorage.tuneArchive = JSON.stringify(tuneArchive);
tuneStorage.tuneArchiveDownloadDate = new Date();
}
function loadTuneArchive() {
if (tuneStorage.tuneArchive) {
return JSON.parse(tuneStorage.tuneArchive);
}
return null;
}
function getTuneArchiveDate() {
return Qt.formatDateTime(tuneStorage.tuneArchiveDownloadDate);
}
function convertFloatQuicksaves() {
var namesJson = floatSettings.value("quicksave_names", null);
if (namesJson) {
var names = JSON.parse(namesJson);
for (var slotName in names) {
if (!slotName.startsWith("Float Quicksave ")) {
continue;
}
var tuneSettingsJson = floatSettings.value(slotName, null);
if (!tuneSettingsJson) {
continue;
}
var slot = Number(slotName.replace("Float Quicksave ", ""));
// skipping if the tune has been converted before
if (tuneStorage.floatTunesConverted[slot - 1] === names[slotName]) {
continue;
}
// at this stage mark slot as converted, if target slot is not empty,
// we don't want it converted at the moment it gets emptied
tuneStorage.floatTunesConverted[slot - 1] = names[slotName];
// workaround needed so that the change is written through to the storage
tuneStorage.floatTunesConverted = tuneStorage.floatTunesConverted;
if (slotEmpty(slot)) {
var tuneSettings = JSON.parse(tuneSettingsJson);
tuneManager.saveTune(slot, tuneManager.createTune(names[slotName], "", tuneSettings));
}
}
}
}
function parseCsv(csv) {
var lines = csv.split("\r\n");
var tuneCount = lines[0].split(",").length - 1;
var result = [];
for (var i = 0; i < tuneCount; i++) {
// set the version to the current one to always pass the version check
result.push({"version": formatVersion, "settings": []});
}
for (var i in lines) {
var currentLine = lines[i].split(",");
for (var j = 0; j < tuneCount; j++) {
var value = currentLine[j + 1];
if (value) {
var key = currentLine[0];
var name;
var type;
if (key === "_name") {
result[j].name = value;
continue;
} else if (key.startsWith("double_")) {
name = key.substring(7);
type = "Double";
} else if (key.startsWith("int_")) {
name = key.substring(4);
type = "Int";
} else if (key.startsWith("bool_")) {
name = key.substring(5);
type = "Bool";
} else if (key.startsWith("enum_")) {
name = key.substring(5);
type = "Enum";
}
result[j].settings.push({
"name": name,
"type": type,
"value": value
});
}
}
}
return result;
}
Component.onCompleted: {
convertFloatQuicksaves();
}
}
QtObject {
id: state
// package state
readonly property int s_Disabled: 0
readonly property int s_Startup: 1
readonly property int s_Ready: 2
readonly property int s_Running: 3
readonly property int s_Connecting: 254
readonly property int s_Disconnected: 255
readonly property var pkgStateToString: new Map([
[s_Disabled, "DISABLED"],
[s_Startup, "STARTUP"],
[s_Ready, "READY"],
[s_Running, "RUNNING"],
[s_Connecting, "CONNECTING"],
[s_Disconnected, "DISCONNECTED"],
])
property int pkgState: s_Connecting
property string pkgStateString: pkgStateToString.get(pkgState) ?? "UNKNOWN (%1)".arg(pkgState)
onPkgStateChanged: {
updateErrorStrings();
}
// package mode
readonly property int m_Normal: 0
readonly property int m_Handtest: 1
property int pkgMode: m_Normal
property string pkgModeString: {
if (pkgState != s_Disconnected) {
if (pkgMode == m_Handtest) {
return "HANDTEST";
}
}
return "";
}
// footpad sensor state
readonly property int fs_None: 0
readonly property int fs_Left: 1
readonly property int fs_Right: 2
readonly property int fs_Both: 3
property int fsState: fs_None
property real adc1Voltage: 0
property real adc2Voltage: 0
onFsStateChanged: {
leftSensor.on = false;
rightSensor.on = false;
if (fsState & fs_Left) {
leftSensor.on = true;
}
if (fsState & fs_Right) {
rightSensor.on = true;
}
if (preferences.swapAdcs && leftSensor.on !== rightSensor.on) {
leftSensor.on = !leftSensor.on;
rightSensor.on = !rightSensor.on;
}
}
// setpoint adjustment type
readonly property int sat_None: 0
readonly property int sat_Centering: 1
readonly property int sat_ReverseStop: 2
// setpoint adjustment class
readonly property int sac_Normal: 0
readonly property int sac_Warning: 1
readonly property int sac_Error: 2
readonly property var setpointAdjustmentTypeToString: new Map([
[sat_None, ""],
[sat_Centering, "centering"],
[sat_ReverseStop, "reverse stop"],
])
property int setpointAdjustmentType: sat_None
property string setpointAdjustmentTypeString
property int setpointAdjustmentClass
onSetpointAdjustmentTypeChanged: {
// do these in one function to keep them consistent, order is important to display and fade correctly in pitchPushbackText
// setpointAdjustmentClass = setpointAdjustmentType >= sat_HighVoltage ? sac_Error : setpointAdjustmentType >= sat_Duty ? sac_Warning : sac_Normal;
setpointAdjustmentClass = sac_Normal;
setpointAdjustmentTypeString = setpointAdjustmentTypeToString.get(setpointAdjustmentType) ?? "unknown (%1)".arg(setpointAdjustmentType);
}
// stop condition
readonly property int sc_None: 0
readonly property int sc_Pitch: 1
readonly property int sc_Roll: 2
readonly property int sc_SensorHalf: 3
readonly property int sc_SensorFull: 4
readonly property int sc_ReverseStop: 5
readonly property int sc_Quickstop: 6
readonly property int sc_Ghost: 7
readonly property var stopConditionToString: new Map([
[sc_None, ""],
[sc_Pitch, "Pitch"],
[sc_Roll, "Roll"],
[sc_SensorHalf, "Sensor Half"],
[sc_SensorFull, "Sensor Full"],
[sc_ReverseStop, "Reverse Stop"],
[sc_Quickstop, "Quickstop"],
[sc_Ghost, "Ghost"],
])
property int stopCondition: sc_None
property string stopConditionString: stopConditionToString.get(stopCondition) ?? "unknown (%1)".arg(stopCondition)
property bool wheelslip: false
property bool charging: false
// readonly property int wt_None: 0
// readonly property int wt_LowVoltage: 1
readonly property var beepReasonToString: new Map([
[0, ""],
[1, "Low Voltage"],
[2, "High Voltage"],
[3, "Controller Temp"],
[4, "Motor Temp"],
[5, "Overcurrent"],
[6, "Duty Cycle"],
[7, "Foot Sensors"],
[8, "Low Battery"],
[9, "Board Idle"],
[10, "Debug"],
[11, "Other"],
[12, "Ghost"],
])
property int beepReason: 0
property string beepReasonString: beepReasonToString.get(beepReason) ?? "unknown (%1)".arg(beepReason)
property bool pkgStateIsError: ![s_Startup, s_Ready, s_Running, s_Connecting].includes(pkgState)
property string vescFault: ""
property bool configLoadingError: false
property bool isError: pkgStateIsError || !!vescFault || configLoadingError
onVescFaultChanged: updateErrorStrings()
onConfigLoadingErrorChanged: updateErrorStrings()
property string errorText: ""
property string errorDescription: ""
function updateErrorStrings() {
if (!!vescFault) {
errorText = "VESC fault: %1".arg(vescFault);
errorDescription = "VESC reported a fault. Be very careful. You should not continue riding before you fix the root cause."
} else if (configLoadingError) {
errorText = "Error: Stig Cfg failed to load.";
errorDescription = "Reconnecting to the board usually fixes this. If problem persists, try reinstalling the package.";
} else if (pkgState == s_Disconnected) {
errorText = "";
errorDescription = "Package is not responding. May occur temporarily with spotty connection. If board doesn't engage, the package is dead. Restart the board, if problem persists, try reinstalling the package.";
} else if (pkgState == s_Disabled) {
errorText = "";
errorDescription = "Stig package is disabled. After you're done with board setup, You can re-enable it in Settings > Setup."
} else if (![s_Startup, s_Ready, s_Running, s_Connecting].includes(pkgState)) {
errorText = "";
errorDescription = "Your Stig package state is unknown. This should never happen.";
} else {
errorText = "";
errorDescription = "";
}
}
}
QtObject {
id: lights
property bool enabled: false
property bool lcm: false
property bool on: false
property bool headlightsOn: false
}
// A distance unit used for most dimensions throughout the layouts.
// Basing on width ensures uniform scaling of the whole UI, height is a
// factor of width and we rely on vertical aspect ratio to have some space
// at the bottom for a StackLayout of Tunes / Control / ...
property real unit: width * 0.1
property real fontSizeBig: 0.4 * unit
property real fontSizeNormal: 0.35 * unit
property real fontSizeSmall: 0.3 * unit
property real fontSizeSuperSmall: 0.25 * unit
anchors.fill: parent
component NText : Text {
color: Utility.getAppHexColor("normalText")
}
component LText : Text {
color: Utility.getAppHexColor("lightText")
}
component DText : Text {
color: Utility.getAppHexColor("disabledText")
}
component FloatingToolButton : RoundButton {
id: button
anchors.margins: 4
width: unit
height: unit
padding: 0
leftInset: 0
rightInset: 0
topInset: 0
bottomInset: 0
property Path iconPath
property real iconSize: width * 0.7
property color strokeColor: Utility.getAppHexColor("normalText")
property color bgColor: Utility.getAppHexColor("darkBackground")
contentItem: Item {
Canvas {
id: downloadTuneArchiveCanvas
anchors.centerIn: parent
implicitWidth: iconSize
implicitHeight: iconSize
contextType: "2d"
onPaint: {
var context = getContext("2d");
context.reset();
context.strokeStyle = button.strokeColor
context.lineCap = "round";
iconPath.scale = Qt.size(iconSize / 50, iconSize / 50)
context.path = iconPath
context.lineWidth = 2
context.stroke()
}
}
}
background: Rectangle {
id: buttonBg
radius: parent.width / 2
opacity: 0.9
color: button.bgColor
states: [
State {
name: "change"
when: button.pressed
PropertyChanges {target: buttonBg; color: Utility.getAppHexColor("lightestBackground");}
}
]
transitions: Transition {
ColorAnimation {property: "color"; duration: 200; easing.type: Easing.InOutCirc;}
}
}
}
component ToolButton : FloatingToolButton {
anchors.margins: 0
bgColor: Utility.getAppHexColor("normalBackground")
}
component Dial : Item {
id: dial