-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmainwindow_tab_driving.cpp
391 lines (369 loc) · 15.4 KB
/
mainwindow_tab_driving.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
//------------------------------------------------------------------------------------------------------------------------>>
// FORM CONTROLS - DRIVING TAB
//------------------------------------------------------------------------------------------------------------------------>>
void MainWindow::SetupControls_DrivingTab(void)
{
QString display;
QString level;
// Apply css to driving profiles QTabWidget and QTabBar
QFile file(":/css/drivingprofiletabs.qss");
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
ui->tabDrivingProfiles->setStyleSheet(file.readAll());
file.close();
}
// Setup accel/decel preset combos
ui->cboAccelPreset_1->setCategory(ptAccel);
ui->cboDecelPreset_1->setCategory(ptDecel);
ui->cboAccelPreset_2->setCategory(ptAccel);
ui->cboDecelPreset_2->setCategory(ptDecel);
// Setup accel/decel level combos
// We wil be using the index number to reference the level, so we don't need user data,
// and we can put whatever we want for the display text
for (int i = 0; i < MAX_SKIP_NUM; i )
{
display = QString::number(i 1);
display.append(" (~");
level.setNum(((i 1)*0.5),'f',1);
display.append(level);
display.append(" sec)");
ui->cboAccelLevel_1->insertItem(i, display);
ui->cboDecelLevel_1->insertItem(i, display);
ui->cboAccelLevel_2->insertItem(i, display);
ui->cboDecelLevel_2->insertItem(i, display);
}
// Initialize driving mode to Tab 1 (Profile 1 - default)
ui->tabDrivingProfiles->setCurrentIndex(0);
// Turn Modes
for (int i = 0; i < NUM_TURN_MODES; i )
{
ui->cboTurnMode->insertItem(i, QString::number(i 1));
}
// Connect Signals and Slots
// If we disable neutral turns, no need to allow a neutral turn percent speed
connect(ui->chkNeutralTurn, SIGNAL(clicked(bool)), this, SLOT(ShowHideNeutralTurnPct(bool)));
// If we disable accel/decel, disable some other options as well
connect(ui->chkAccelEnable_1, SIGNAL(clicked(bool)), this, SLOT(ShowHideAccelOptions_1(bool)));
connect(ui->chkDecelEnable_1, SIGNAL(clicked(bool)), this, SLOT(ShowHideDecelOptions_1(bool)));
connect(ui->chkAccelEnable_2, SIGNAL(clicked(bool)), this, SLOT(ShowHideAccelOptions_2(bool)));
connect(ui->chkDecelEnable_2, SIGNAL(clicked(bool)), this, SLOT(ShowHideDecelOptions_2(bool)));
// If we disable barrel stabilization or hill physics, disable the sensitivity options as well
connect(ui->chkEnableBarrel, SIGNAL(clicked(bool)), this, SLOT(ShowHideBarrelSensitivity(bool)));
connect(ui->chkEnableHills, SIGNAL(clicked(bool)), this, SLOT(ShowHideHillSensitivity(bool)));
// If we disable the nudge feature (by setting nudge percent to zero), disable the nudge time
connect(ui->spinNudgePercent, SIGNAL(valueChanged(int)), this, SLOT(ShowHideNudgeTime(int)));
// Track recoil enabled/disabled
connect(ui->chkEnableTrackRecoil, SIGNAL(clicked(bool)), this, SLOT(ShowHideTrackRecoil(bool)));
// FOR NOW WE ARE HIDING THE IMU SETTINGS BECAUSE THE FUNCTIONALITY IS NOT COMPLETE ON THE TCB
// However, the code here is done and the settings are saved/recorded to TCB if we just unhide
// this frame, and add back the IMU-specific functions that are commented out in getopqmaps.cpp
ui->frmIMU->hide();
}
void MainWindow::ShowHideNudgeTime(int nudgePct)
{
if (nudgePct > 0)
{
ui->lblNudgeTime1->setEnabled(true);
ui->lblNudgeTime2->setEnabled(true);
ui->spinNudgeTime->setEnabled(true);
DeviceData.NudgeTime_mS = ui->spinNudgeTime->value();
}
else
{
ui->lblNudgeTime1->setEnabled(false);
ui->lblNudgeTime2->setEnabled(false);
ui->spinNudgeTime->setEnabled(false);
}
}
void MainWindow::ShowHideNeutralTurnAllowed(int)
{
if (ui->cboDriveType->currentData() == DT_TANK || ui->cboDriveType->currentData() == DT_DKLM)
{
// Enable the option for enabling/disabling neutral turns
if (!ui->chkNeutralTurn->isEnabled())
{
ui->lblNeutralTurnAllowed->setEnabled(true);
ui->lblMaxNeutralTurn->setEnabled(true);
ui->chkNeutralTurn->setEnabled(true);
ui->chkNeutralTurn->setChecked(DeviceData.NeutralTurnAllowed);
ShowHideNeutralTurnPct(DeviceData.NeutralTurnAllowed);
}
}
else
{
// This is not a tank, so disable all the neutral turn options
ui->lblNeutralTurnAllowed->setEnabled(false);
ui->lblMaxNeutralTurn->setEnabled(false);
DeviceData.NeutralTurnAllowed = false;
ui->chkNeutralTurn->setChecked(false);
ui->chkNeutralTurn->setEnabled(false);
ShowHideNeutralTurnPct(DeviceData.NeutralTurnAllowed);
}
// Set also turn mode selection availability, and helpful messages
if (ui->cboDriveType->currentData() == DT_TANK)
{
// Enable turn mode options
ui->lblTurnMode->setEnabled(true);
ui->cboTurnMode->setEnabled(true);
// Hide these labels
ui->lblNoTurnMode->hide();
ui->lblNoTurnSettingsForCars->hide();
ui->lblNoNeutralTurns->hide();
}
else if (ui->cboDriveType->currentData() == DT_HALFTRACK)
{
// Enable turn mode options
ui->lblTurnMode->setEnabled(true);
ui->cboTurnMode->setEnabled(true);
ui->lblNoTurnMode->hide();
ui->lblNoTurnSettingsForCars->hide();
ui->lblNoNeutralTurns->setText("(Unavailable for Halftracks)");
ui->lblNoNeutralTurns->show(); // Show - no neutral turns for halftracks
}
else if (ui->cboDriveType->currentData() == DT_CAR)
{
// Disable turn mode options for cars
ui->lblTurnMode->setEnabled(false);
ui->cboTurnMode->setEnabled(false);
ui->lblNoTurnMode->hide();
ui->lblNoTurnSettingsForCars->show(); // Show - no turn settings at all for cars
ui->lblNoNeutralTurns->hide();
}
else if (ui->cboDriveType->currentData() == DT_DKLM)
{
// Disable turn modes for clutch-type gearboxes
ui->lblTurnMode->setEnabled(false);
ui->cboTurnMode->setEnabled(false);
ui->lblNoTurnMode->show(); // Show - no turn modes for DKLM
ui->lblNoTurnMode->setText("Unavailable for DKLM");
ui->lblNoTurnSettingsForCars->hide();
ui->lblNoNeutralTurns->hide();
}
else if (ui->cboDriveType->currentData() == DT_DMD)
{
// Disable turn modes for Tamiya DMD since it does the mixing itself
ui->lblTurnMode->setEnabled(false);
ui->cboTurnMode->setEnabled(false);
ui->lblNoTurnMode->show(); // Show - no turn modes for DKLM
ui->lblNoTurnMode->setText("Unavailable for DMD");
ui->lblNoTurnSettingsForCars->hide();
ui->lblNoNeutralTurns->setText("(Handled by DMD)");
ui->lblNoNeutralTurns->show(); // Show - neutral turns are allowed, but they are handled by DMD so we don't need settings here
}
}
void MainWindow::ShowHideNeutralTurnPct(bool checked)
{ // If neutral turns are allowed, enable the spin box to set the neutral turn max speed.
// Otherwise, disable the spin box.
if (checked)
{
ui->lblMaxNeutralTurn->setEnabled(true);
ui->spinNeutralTurnSpeed->setEnabled(true);
ui->spinNeutralTurnSpeed->setValue(DeviceData.NeutralTurnPct);
}
else
{
ui->lblMaxNeutralTurn->setEnabled(false);
DeviceData.NeutralTurnPct = 50; // Reset to default amount, though it won't matter
ui->spinNeutralTurnSpeed->setValue(DeviceData.NeutralTurnPct);
ui->spinNeutralTurnSpeed->setEnabled(false);
}
}
void MainWindow::ShowHideHalftrackTurn(int)
{
if (ui->cboDriveType->currentData() == DT_HALFTRACK)
{
ui->lblHalftrackTurnPercent->setEnabled(true);
ui->spinHalftrackTurnPct->setEnabled(true);
ui->spinHalftrackTurnPct->setValue(DeviceData.HalftrackTreadTurnPct);
}
else
{
ui->lblHalftrackTurnPercent->setEnabled(false);
DeviceData.HalftrackTreadTurnPct = 50; // Reset to default amount, though it won't matter
ui->spinHalftrackTurnPct->setValue(DeviceData.HalftrackTreadTurnPct);
ui->spinHalftrackTurnPct->setEnabled(false);
}
}
void MainWindow::ShowHideAccelOptions_1(bool isChecked)
{
if (isChecked)
{ // Show options
ui->lblAccelPreset_1->setEnabled(true);
ui->cboAccelPreset_1->setEnabled(true);
ui->lblAccelLevel_1->setEnabled(true);
ui->cboAccelLevel_1->setEnabled(true);
}
else
{ // Hide options
ui->lblAccelPreset_1->setEnabled(false);
ui->cboAccelPreset_1->setCurrentIndex(ui->cboAccelPreset_1->findData(ADP_NONE));
ui->cboAccelPreset_1->setEnabled(false);
ui->lblAccelLevel_1->setEnabled(false);
ui->cboAccelLevel_1->setCurrentIndex(3); // This will put it on item 4, which is default for Profile 1
ui->cboAccelLevel_1->setEnabled(false);
}
}
void MainWindow::ShowHideDecelOptions_1(bool isChecked)
{
if (isChecked)
{ // Show options
ui->lblDecelPreset_1->setEnabled(true);
ui->cboDecelPreset_1->setEnabled(true);
ui->lblDecelLevel_1->setEnabled(true);
ui->cboDecelLevel_1->setEnabled(true);
}
else
{ // Hide options
ui->lblDecelPreset_1->setEnabled(false);
ui->cboAccelPreset_1->setCurrentIndex(ui->cboDecelPreset_1->findData(DDP_NONE));
ui->cboDecelPreset_1->setEnabled(false);
ui->lblDecelLevel_1->setEnabled(false);
ui->cboDecelLevel_1->setCurrentIndex(3); // This will put it on item 4, which is default for Profile 1
ui->cboDecelLevel_1->setEnabled(false);
}
}
void MainWindow::ShowHideAccelOptions_2(bool isChecked)
{
if (isChecked)
{ // Show options
ui->lblAccelPreset_2->setEnabled(true);
ui->cboAccelPreset_2->setEnabled(true);
ui->lblAccelLevel_2->setEnabled(true);
ui->cboAccelLevel_2->setEnabled(true);
}
else
{ // Hide options
ui->lblAccelPreset_2->setEnabled(false);
ui->cboAccelPreset_2->setCurrentIndex(ui->cboAccelPreset_2->findData(ADP_NONE));
ui->cboAccelPreset_2->setEnabled(false);
ui->lblAccelLevel_2->setEnabled(false);
ui->cboAccelLevel_2->setCurrentIndex(0); // This will put it on item 1, which is default for Profile 2
ui->cboAccelLevel_2->setEnabled(false);
}
}
void MainWindow::ShowHideDecelOptions_2(bool isChecked)
{
if (isChecked)
{ // Show options
ui->lblDecelPreset_2->setEnabled(true);
ui->cboDecelPreset_2->setEnabled(true);
ui->lblDecelLevel_2->setEnabled(true);
ui->cboDecelLevel_2->setEnabled(true);
}
else
{ // Hide options
ui->lblDecelPreset_2->setEnabled(false);
ui->cboAccelPreset_2->setCurrentIndex(ui->cboDecelPreset_2->findData(DDP_NONE));
ui->cboDecelPreset_2->setEnabled(false);
ui->lblDecelLevel_2->setEnabled(false);
ui->cboDecelLevel_2->setCurrentIndex(0); // This will put it on item 1, which is default for Profile 2
ui->cboDecelLevel_2->setEnabled(false);
}
}
void MainWindow::ShowHideBarrelSensitivity(bool isChecked)
{
if (isChecked)
{
ui->lblBarrelSensitivity1->setEnabled(true);
ui->lblBarrelSensitivity2->setEnabled(true);
ui->spinBarrelSensitivity->setEnabled(true);
ui->spinBarrelSensitivity->setValue(DeviceData.BarrelSensitivity);
}
else
{
ui->lblBarrelSensitivity1->setEnabled(false);
ui->lblBarrelSensitivity2->setEnabled(false);
DeviceData.BarrelSensitivity = 50;
ui->spinBarrelSensitivity->setValue(DeviceData.BarrelSensitivity);
ui->spinBarrelSensitivity->setEnabled(false);
}
}
void MainWindow::ShowHideHillSensitivity(bool isChecked)
{
if (isChecked)
{
ui->lblHillSensitivity1->setEnabled(true);
ui->lblHillSensitivity2->setEnabled(true);
ui->spinHillSensitivity->setEnabled(true);
ui->spinHillSensitivity->setValue(DeviceData.HillSensitivity);
}
else
{
ui->lblHillSensitivity1->setEnabled(false);
ui->lblHillSensitivity2->setEnabled(false);
DeviceData.HillSensitivity = 50;
ui->spinHillSensitivity->setValue(DeviceData.HillSensitivity);
ui->spinHillSensitivity->setEnabled(false);
}
}
void MainWindow::ShowHideBarrelStabilization(bool isEnabled)
{
if (isEnabled)
{
ui->lblBarrelNote->hide();
ui->lblEnableBarrelStabilization->setEnabled(true);
ui->chkEnableBarrel->setEnabled(true);
ui->chkEnableBarrel->setChecked(DeviceData.EnableBarrelStabilize);
}
else
{
ui->lblBarrelNote->show();
ui->lblEnableBarrelStabilization->setEnabled(false);
ui->chkEnableBarrel->setChecked(false);
DeviceData.EnableBarrelStabilize = false;
ui->chkEnableBarrel->setEnabled(false);
}
}
void MainWindow::ShowHideTrackRecoil(bool isEnabled)
{
if (isEnabled)
{
ui->spinKickbackSpeed->setEnabled(true);
ui->spinDecelerateFactor->setEnabled(true);
}
else
{
ui->spinKickbackSpeed->setEnabled(false);
ui->spinDecelerateFactor->setEnabled(false);
}
}
void MainWindow::ValidateFreewheelingGearboxOptions(void)
{
// Certain gearboxes such as the notorious Taigen "V2" Steel 3:1 and 4:1 gearboxes don't have adequate internal friction to
// keep from free-wheeling when any kind of external force is applied to them. This is a big problem in a tank given that
// reducing the speed of one track relative to another is the only way to accomplish steering, but with one of these gearboxes,
// especially in a heavy model with wide tracks such as the Jagdpanther, Jadgtiger, King Tiger, Panther, etc, the outer track
// has more than enough power and contact with the ground to drive the tank completely straight even if power is reduced or
// turned off completely from the inner track. In other words, you can't steer.
// The Scout ESC has a mode that can compensate for this kind of defective gearbox, by "dragging" the inner track with pulsed
// brake commands. This option is only available on the Scout, and only if the vehicle type is set to Tank or Halftrack, and even
// then most users shouldn't need it unless they find themselves with the condition described above.
if (ui->cboDriveType->currentData() == DT_TANK || ui->cboDriveType->currentData() == DT_HALFTRACK)
{
if (ui->cboDriveMotors->currentData() == OP_SCOUT)
{
ui->chkFreewheelGearbox->setChecked(DeviceData.DragInnerTrack);
ui->chkFreewheelGearbox->setEnabled(true);
ui->lblFreewheel2->hide();
}
else
{ // It's a tank, but not driven by the Scout
DeviceData.DragInnerTrack = false;
ui->chkFreewheelGearbox->setChecked(DeviceData.DragInnerTrack);
ui->chkFreewheelGearbox->setEnabled(false);
ui->lblFreewheel2->setText("(Only available with Scout ESC)");
ui->lblFreewheel2->show();
}
}
else
{
// It might be driven by the Scout, but it's not a tank
DeviceData.DragInnerTrack = false;
ui->chkFreewheelGearbox->setChecked(DeviceData.DragInnerTrack);
ui->chkFreewheelGearbox->setEnabled(false);
ui->lblFreewheel2->setText("(Only available for tanks and halftracks)");
ui->lblFreewheel2->show();
}
}