-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow_varcontrols.cpp
More file actions
203 lines (173 loc) · 9.97 KB
/
mainwindow_varcontrols.cpp
File metadata and controls
203 lines (173 loc) · 9.97 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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
// Here we have two routines for setting all controls to the current value of our named variables, or
// setting all named variables to the values specified in the controls.
//------------------------------------------------------------------------------------------------------------------------>>
// VARIABLES TO CONTROLS & CONTROLS TO VARIABLES
//------------------------------------------------------------------------------------------------------------------------>>
void MainWindow::Variables_to_Controls(void)
{
// Radio tab
// ---------------------------------------------------------------------------------------------------------->>
// CHANNELS
for (int i=0; i<CHANNELS; i++)
{
// Number of channel switch positions (if switch)
switchPosCombo[i]->setCurrentText(QString::number(DeviceData.RCChannel[i].numPositions));
// Channel type (switch or some other)
channelTypeCombo[i]->setCurrentIndex(channelTypeCombo[i]->findData(DeviceData.RCChannel[i].chType));
// Channel reversed settings
reversedCheck[i]->setChecked(DeviceData.RCChannel[i].reversed);
SaveChannelType(channelTypeCombo[i],i);
SaveChannelPositions(switchPosCombo[i],i);
int start_interval = (MAX_SWITCH_POSITIONS * i);
for (int j=0; j<MAX_SWITCH_POSITIONS; j++)
{
// If switch, set function
if (DeviceData.RCChannel[i].Digital)
{
switchFunctionCombo[start_interval + j]->setCurrentIndex(switchFunctionCombo[start_interval + j]->findData(DeviceData.RCChannel[i].swFunction[j]));
}
// Some functions requires numbers and actions
SaveChannelSwitchAction(switchFunctionCombo[i + j], i, j); // First make sure all options are shown/hidden correctly
if (DeviceData.RCChannel[i].swFunction[j] == SF_USER ||
DeviceData.RCChannel[i].swFunction[j] == SF_SOUNDBANK ||
DeviceData.RCChannel[i].swFunction[j] == SF_MG ||
DeviceData.RCChannel[i].swFunction[j] == SF_LIGHT||
DeviceData.RCChannel[i].swFunction[j] == SF_CANNON_FIRE)
{
actionNumCombo[start_interval + j]->setCurrentIndex(actionNumCombo[start_interval + j]->findData(DeviceData.RCChannel[i].actionNum[j]));
switchActionCombo[start_interval + j]->setCurrentIndex(switchActionCombo[start_interval + j]->findData(DeviceData.RCChannel[i].switchAction[j]));
}
}
}
// Settings tab
// ---------------------------------------------------------------------------------------------------------->>
// Squeaks
for (uint8_t i=0; i<NUM_SQUEAKS; i++)
{
chkSqueakEnabled[i]->setChecked(DeviceData.Squeak[i].Enabled);
squeakMinInterval[i]->setValue(DeviceData.Squeak[i].MinInterval_mS);
squeakMaxInterval[i]->setValue(DeviceData.Squeak[i].MaxInterval_mS);
}
ui->spinMinSqueakSpeed->setValue(DeviceData.MinSqueakSpeedPct);
ShowHideOtherSqueakSettings();
ShowHideSqueak1Settings(ui->chkEnableSqueak1->isChecked());
ShowHideSqueak2Settings(ui->chkEnableSqueak2->isChecked());
ShowHideSqueak3Settings(ui->chkEnableSqueak3->isChecked());
ShowHideSqueak4Settings(ui->chkEnableSqueak4->isChecked());
ShowHideSqueak5Settings(ui->chkEnableSqueak5->isChecked());
ShowHideSqueak6Settings(ui->chkEnableSqueak6->isChecked());
// Volumes
ui->sliderEngineVolume->setValue(DeviceData.VolumeEngine);
ui->sliderOverlayVolume->setValue(DeviceData.VolumeTrackOverlay);
ui->sliderEffectsVolume->setValue(DeviceData.VolumeEffects);
// Throttle position
ui->radioCenterIdle->setChecked(DeviceData.centerThrottle);
ui->radioLowIdle->setChecked(!DeviceData.centerThrottle);
ui->spinIdleDeadband->setValue(DeviceData.idleDeadband);
// Lights
ui->spinLight1Flash_mS->setValue(DeviceData.Light1FlashTime_mS);
ui->spinLight1BlinkOn_mS->setValue(DeviceData.Light1BlinkOnTime_mS);
ui->spinLight1BlinkOff_mS->setValue(DeviceData.Light1BlinkOffTime_mS);
ui->spinLight2Flash_mS->setValue(DeviceData.Light2FlashTime_mS);
ui->spinLight2BlinkOn_mS->setValue(DeviceData.Light2BlinkOnTime_mS);
ui->spinLight2BlinkOff_mS->setValue(DeviceData.Light2BlinkOffTime_mS);
ui->spinLight3Flash_mS->setValue(DeviceData.Light3FlashTime_mS);
ui->spinLight3BlinkOn_mS->setValue(DeviceData.Light3BlinkOnTime_mS);
ui->spinLight3BlinkOff_mS->setValue(DeviceData.Light3BlinkOffTime_mS);
// Sound bank
ui->chkSBALoop->setChecked(DeviceData.SoundBankA_Loop);
ui->chkSBBLoop->setChecked(DeviceData.SoundBankB_Loop);
// Servo
ui->spinRecoilTimeToRecoil->setValue(DeviceData.ServoTimeToRecoil);
ui->spinRecoilTimeToReturn->setValue(DeviceData.ServoTimeToReturn);
ui->chkRecoilServoReversed->setChecked(DeviceData.ServoReversed);
ui->spinEndPointRecoil->setValue(DeviceData.ServoEndPointRecoiled);
ui->spinEndPointBattery->setValue(DeviceData.ServoEndPointBattery);
// Engine
ui->chkEngineAutoStart->setChecked(DeviceData.EngineAutoStart);
double autostop = DeviceData.EngineAutoStopTime_mS; // We need to convert mS to Minutes with 1-decimal precision
autostop /= 60000;
ui->dspinEngineAutoStop->setValue(autostop);
}
void MainWindow::Controls_to_Variables(void)
{
// Radio tab
// ---------------------------------------------------------------------------------------------------------->>
// CHANNELS
for (int i=0; i<CHANNELS; i++)
{
// Channel type (switch or some other)
DeviceData.RCChannel[i].chType = channelTypeCombo[i]->getCurrentChannelType();
if (static_cast<channel_type>(channelTypeCombo[i]->itemData(channelTypeCombo[i]->currentIndex()).toUInt()) == CT_SWITCH)
{
DeviceData.RCChannel[i].Digital = true;
}
else DeviceData.RCChannel[i].Digital = false;
// Number of channel switch positions (if switch)
DeviceData.RCChannel[i].numPositions = switchPosCombo[i]->currentText().toUInt();
// Channel reversed settings
DeviceData.RCChannel[i].reversed = reversedCheck[i]->isChecked();
int start_interval = (MAX_SWITCH_POSITIONS * i);
for (int j=0; j<MAX_SWITCH_POSITIONS; j++)
{
// If switch, set function, action, and action number
if (DeviceData.RCChannel[i].Digital && switchFunctionCombo[start_interval + j]->getCurrentSwitchFunction() != SF_NULL)
{
DeviceData.RCChannel[i].swFunction[j] = switchFunctionCombo[start_interval + j]->getCurrentSwitchFunction();
DeviceData.RCChannel[i].switchAction[j] = switchActionCombo[start_interval + j]->getCurrentSwitchAction();
DeviceData.RCChannel[i].actionNum[j] = actionNumCombo[start_interval + j]->currentData().toInt();
DeviceData.RCChannel[i].swFunctionID[j] = switchSettingsToID(DeviceData.RCChannel[i].swFunction[j], DeviceData.RCChannel[i].switchAction[j], DeviceData.RCChannel[i].actionNum[j]);
// qDebug() << "Channel " << i + 1 << " Position " << j + 1 << "Function " << DeviceData.RCChannel[i].swFunction[j] << " Action " << DeviceData.RCChannel[i].switchAction[j] << " Num " << DeviceData.RCChannel[i].actionNum[j] << " ID " << DeviceData.RCChannel[i].swFunctionID[j];
}
else // Default these to something benign
{
DeviceData.RCChannel[i].swFunctionID[j] = 0;
DeviceData.RCChannel[i].swFunction[j] = SF_NULL;
DeviceData.RCChannel[i].switchAction[j] = ACTION_NULL;
DeviceData.RCChannel[i].actionNum[j] = 1;
}
}
}
// Settings tab
// ---------------------------------------------------------------------------------------------------------->>
// Squeaks
for (uint8_t i=0; i<NUM_SQUEAKS; i++)
{
DeviceData.Squeak[i].Enabled = chkSqueakEnabled[i]->isChecked();
DeviceData.Squeak[i].MinInterval_mS = squeakMinInterval[i]->value();
DeviceData.Squeak[i].MaxInterval_mS = squeakMaxInterval[i]->value();
}
DeviceData.MinSqueakSpeedPct = ui->spinMinSqueakSpeed->value();
// Volumes
DeviceData.VolumeEngine = ui->sliderEngineVolume->value();
DeviceData.VolumeTrackOverlay = ui->sliderOverlayVolume->value();
DeviceData.VolumeEffects = ui->sliderEffectsVolume->value();
// Throttle position
if (ui->radioCenterIdle->isChecked()) DeviceData.centerThrottle = true;
else if (ui->radioLowIdle->isChecked()) DeviceData.centerThrottle = false;
DeviceData.idleDeadband = ui->spinIdleDeadband->value();
// Lights
DeviceData.Light1FlashTime_mS = ui->spinLight1Flash_mS->value();
DeviceData.Light1BlinkOnTime_mS = ui->spinLight1BlinkOn_mS->value();
DeviceData.Light1BlinkOffTime_mS = ui->spinLight1BlinkOff_mS->value();
DeviceData.Light2FlashTime_mS = ui->spinLight2Flash_mS->value();
DeviceData.Light2BlinkOnTime_mS = ui->spinLight2BlinkOn_mS->value();
DeviceData.Light2BlinkOffTime_mS = ui->spinLight2BlinkOff_mS->value();
DeviceData.Light3FlashTime_mS = ui->spinLight3Flash_mS->value();
DeviceData.Light3BlinkOnTime_mS = ui->spinLight3BlinkOn_mS->value();
DeviceData.Light3BlinkOffTime_mS = ui->spinLight3BlinkOff_mS->value();
// Sound bank
DeviceData.SoundBankA_Loop = ui->chkSBALoop->isChecked();
DeviceData.SoundBankB_Loop = ui->chkSBBLoop->isChecked();
// Servo
DeviceData.ServoReversed = ui->chkRecoilServoReversed->isChecked();
DeviceData.ServoTimeToRecoil = ui->spinRecoilTimeToRecoil->value();
DeviceData.ServoTimeToReturn = ui->spinRecoilTimeToReturn->value();
DeviceData.ServoEndPointRecoiled = ui->spinEndPointRecoil->value();
DeviceData.ServoEndPointBattery = ui->spinEndPointBattery->value();
// Engine
DeviceData.EngineAutoStart = ui->chkEngineAutoStart->isChecked();
DeviceData.EngineAutoStopTime_mS = static_cast<int32_t>(ui->dspinEngineAutoStop->value() * 60000.0); // We need to convert minutes to milli-seconds
}