-
Notifications
You must be signed in to change notification settings - Fork 7
/
mainwindow_tab_lightsio.cpp
191 lines (176 loc) · 9.89 KB
/
mainwindow_tab_lightsio.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
//------------------------------------------------------------------------------------------------------------------------>>
// FORM CONTROLS - LIGHTS & IO TAB
//------------------------------------------------------------------------------------------------------------------------>>
void MainWindow::SetupControls_LightsIOTab(void)
{
// Setup external I/O data direction combo boxes
ui->cboPortADataDirection->insertItem(0, "Input", DD_INPUT); // Arduino data-direction flag is 0 for input
ui->cboPortADataDirection->insertItem(1, "Output",DD_OUTPUT); // Arduino data-direction flag is 1 for output
ui->cboPortBDataDirection->insertItem(0, "Input", DD_INPUT); // Arduino data-direction flag is 0 for input
ui->cboPortBDataDirection->insertItem(1, "Output",DD_OUTPUT); // Arduino data-direction flag is 1 for output
ui->cboPortA_DataType->insertItem(0, "Analog (variable)", 0); // Initialize to types under Analog direction
ui->cboPortA_DataType->insertItem(1, "Digital (on/off)",1); // but they can be changed later if direction
ui->cboPortB_DataType->insertItem(0, "Analog (variable)", 0); // is changed
ui->cboPortB_DataType->insertItem(1, "Digital (on/off)",1);
// Signals and slots
// This handles validation of Aux output usage if the user checks the option to auto-flash Aux output with cannon fire
connect(ui->chkAuxFlashWithCannon, SIGNAL(clicked(bool)), this, SLOT(ValidateAuxFlash(bool)));
// This adds/removes the manual High Intensity flash function from the list depending on if the user wants to trigger
// it manually or automatically with cannon fire.
connect(ui->chkHiFlashWithCannon, SIGNAL(clicked(bool)), this, SLOT(SetHiFlashAuto(bool)));
// If external I/O is set to output, hide the input type combo, or show it if set to input
// Also save the current setting to our variable
connect(ui->cboPortADataDirection, SIGNAL(currentIndexChanged(int)), this, SLOT(SetupInputAType(int)));
connect(ui->cboPortBDataDirection, SIGNAL(currentIndexChanged(int)), this, SLOT(SetupInputBType(int)));
// On any input type change, save setting to variable
connect(ui->cboPortA_DataType, SIGNAL(currentIndexChanged(int)), this, SLOT(SavePortA_InputType(int)));
connect(ui->cboPortB_DataType, SIGNAL(currentIndexChanged(int)), this, SLOT(SavePortB_InputType(int)));
// Additionally, depending on whether the external I/O is set to input or output, determines whether that port
// get assigned as a trigger (input) or a function (output). We have extra slots for that
connect(ui->cboPortADataDirection, SIGNAL(currentIndexChanged(int)), this, SLOT(SetupPortAFunctionTrigger(int)));
connect(ui->cboPortBDataDirection, SIGNAL(currentIndexChanged(int)), this, SLOT(SetupPortBFunctionTrigger(int)));
// Now we make sure the setup runs once at startup
SetupPortAFunctionTrigger(ui->cboPortADataDirection->findData(ui->cboPortADataDirection->currentIndex()));
SetupPortBFunctionTrigger(ui->cboPortBDataDirection->findData(ui->cboPortBDataDirection->currentIndex()));
}
void MainWindow::SetHiFlashAuto(bool isChecked)
{
if (isChecked)
{ // User wants the high intensity flash unit to flash automatically with cannon fire
// We remove the manual flash function from the function list
ui->cboSelectFunction->RemoveSF(SF_HI_FLASH);
// Make sure we didn't already have a function trigger defined for it too
if (FT_TableModel->removeFunctionFromList(SF_HI_FLASH)) { RemovedFunctionTriggersMsgBox(); }
}
else
{ // User does not want the high-intensity flash unit to flash automatically with cannon fire.
// Add a manual control option to the function list instead.
// The add function will only add it if it isn't there already
ui->cboSelectFunction->AddSF(SF_HI_FLASH);
}
}
void MainWindow::ValidateAuxFlash(bool isChecked)
{
if (isChecked)
{
// In this case we are using the Aux Output for a cannon flash so we disable the Flicker Lights during Engine Start option
// which would conflict with the use of the Aux output
if (ui->chkFlickerHeadlights->isChecked() == true)
{
ui->chkFlickerHeadlights->setChecked(false);
// msgBox("The Flicker Lights during Engine Start option will not be available under Separate Heat & Fan "
// "because it would create a conflict with the use of the Aux output. That option has been disabled on the Lights tab.",vbOkOnly,"Flicker Lights Option Disabled",vbExclamation);
}
DeviceData.FlickerLightsOnEngineStart = false;
ui->chkFlickerHeadlights->setEnabled(false);
ui->lblFlickerLights->setEnabled(false);
}
else
{
// Here we can permit the "Flicker Lights during Engine Start" setting to become active since the Aux output will
// not be used for the cannon flash, BUT we also need to make sure that it isn't being reserved for the smoker fan
if (ui->cboSmokerType->currentData() != SMOKERTYPE_ONBOARD_SEPARATE)
{
ui->chkFlickerHeadlights->setEnabled(true);
ui->lblFlickerLights->setEnabled(true);
}
}
}
void MainWindow::SetupInputAType(int indexnum)
{
// Any change, save to our variable
DeviceData.PortA.Settings.dataDirection = ui->cboPortADataDirection->itemData(indexnum).toUInt();
// Now take some action depending on what it is
if (DeviceData.PortA.Settings.dataDirection == 1) // 1 means output
{
// Port A data direction is set to output:
ui->cboPortA_DataType->setItemText(0, "Default Low");
ui->cboPortA_DataType->setItemText(1, "Default High");
}
else
{
// Port A data direction is set to input:
ui->cboPortA_DataType->setItemText(0, "Analog (variable)");
ui->cboPortA_DataType->setItemText(1, "Digital (on/off)");
}
// Set the type to the actual number in variable
ui->cboPortA_DataType->setCurrentIndex(ui->cboPortA_DataType->findData(DeviceData.PortA.Settings.dataType));
// Either way, we must check this change against our existing function-triggers!
if (FT_TableModel->checkExternalPortDirectionAgainstFunctionTriggers(1, DeviceData.PortA.Settings.dataDirection))
RemovedFunctionTriggersMsgBox();
}
void MainWindow::SavePortA_InputType(int indexnum)
{
// Any change, save to our variable
DeviceData.PortA.Settings.dataType = ui->cboPortA_DataType->itemData(indexnum).toUInt();
// We also need to check this change against our function triggers in case any are no longer valid
if (FT_TableModel->checkExternalPortInputTypeAgainstFunctionTriggers(1, DeviceData.PortA.Settings.dataType))
RemovedFunctionTriggersMsgBox();
}
void MainWindow::SetupInputBType(int indexnum)
{
// Any change, save to our variable
DeviceData.PortB.Settings.dataDirection = ui->cboPortBDataDirection->itemData(indexnum).toUInt();
// Now take some action depending on what it is
if (DeviceData.PortB.Settings.dataDirection == 1) // 1 means output
{
// Port B data direction is set to output:
ui->cboPortB_DataType->setItemText(0, "Default Low");
ui->cboPortB_DataType->setItemText(1, "Default High");
}
else
{
// Port B data direction is set to input:
ui->cboPortB_DataType->setItemText(0, "Analog (variable)");
ui->cboPortB_DataType->setItemText(1, "Digital (on/off)");
}
// Set the type to the actual number in variable
ui->cboPortB_DataType->setCurrentIndex(ui->cboPortB_DataType->findData(DeviceData.PortB.Settings.dataType));
// Either way, we must check this change against our existing function-triggers!
if (FT_TableModel->checkExternalPortDirectionAgainstFunctionTriggers(2, DeviceData.PortB.Settings.dataDirection))
RemovedFunctionTriggersMsgBox();
}
void MainWindow::SavePortB_InputType(int indexnum)
{
// Any change, save to our variable
DeviceData.PortB.Settings.dataType = ui->cboPortB_DataType->itemData(indexnum).toUInt();
// We also need to check this change against our function triggers in case any are no longer valid
if (FT_TableModel->checkExternalPortInputTypeAgainstFunctionTriggers(2, DeviceData.PortA.Settings.dataType))
RemovedFunctionTriggersMsgBox();
}
void MainWindow::SetupPortAFunctionTrigger(int indexnum)
{
if (ui->cboPortADataDirection->itemData(indexnum) == 1) // 1 means output
{
// If Port A data direction is set to output, we need to add the PortA output functions to our list of special functions,
// while also making sure Port A is no longer in the list of triggers
ui->cboSelectFunction->addExternalOutputsA();
ui->cboTriggerSource->removeExternalInputA();
}
else
{
// But if Port A data direction is set to input, we need to remove the Port A output function from the function list.
// We don't need to worry about adding Port A input to the trigger source list, because the trigger source list will
// fill it in automatically as required.
ui->cboSelectFunction->removeExternalOutputsA();
}
}
void MainWindow::SetupPortBFunctionTrigger(int indexnum)
{
if (ui->cboPortBDataDirection->itemData(indexnum) == 1) // 1 means output
{
// If Port B data direction is set to output, we need to add the PortB output functions to our list of special functions,
// while also making sure Port B is no longer in the list of triggers
ui->cboSelectFunction->addExternalOutputsB();
ui->cboTriggerSource->removeExternalInputB();
}
else
{
// But if Port B data direction is set to input, we need to remove the Port B output function from the function list.
// We don't need to worry about adding Port B input to the trigger source list, because the trigger source list will
// fill it in automatically as required.
ui->cboSelectFunction->removeExternalOutputsB();
}
}