Skip to content

Commit 296f62f

Browse files
committed
�Enhance full parameter change message box
1 parent 5cc57b0 commit 296f62f

File tree

1 file changed

+88
-53
lines changed

1 file changed

+88
-53
lines changed

GCSViews/ConfigurationView/ConfigRawParams.cs

Lines changed: 88 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -266,86 +266,121 @@ private void BUT_writePIDS_Click(object sender, EventArgs e)
266266
int error = 0;
267267
bool reboot = false;
268268

269-
// List to track successfully saved parameters
270-
List<string> savedParams = new List<string>();
271-
272-
foreach (string value in temp)
269+
if (temp.Count > 0 && temp.Count <= 20)
273270
{
274-
try
275-
{
276-
if (MainV2.comPort.BaseStream == null || !MainV2.comPort.BaseStream.IsOpen)
277-
{
278-
CustomMessageBox.Show("Your are not connected", Strings.ERROR);
279-
return;
280-
}
281-
282-
// Get the previous value of the param to display in 'param change info'
283-
// (a better way would be to get the value somewhere from inside the code, insted of demanding it from mavlink)
284-
string previousValue = MainV2.comPort.MAV.param[value].ToString();
285-
// new value of param
286-
double newValue = (double)_changes[value];
271+
// List to track successfully saved parameters
272+
List<string> savedParams = new List<string>();
287273

288-
MainV2.comPort.setParam(value, newValue);
289-
290-
// Add the parameter, previous and new values to the list for 'param change info'
291-
// remember, the 'value' here is key of param, while prev and new are actual values of param
292-
savedParams.Add($"{savedParams.Count + 1}) {value} : {previousValue} -> {newValue}");
293-
294-
//check if reboot required
295-
if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString()))
296-
{
297-
reboot = true;
298-
}
274+
foreach (string value in temp)
275+
{
299276
try
300277
{
301-
// set control as well
302-
var textControls = Controls.Find(value, true);
303-
if (textControls.Length > 0)
278+
if (MainV2.comPort.BaseStream == null || !MainV2.comPort.BaseStream.IsOpen)
304279
{
305-
ThemeManager.ApplyThemeTo(textControls[0]);
280+
CustomMessageBox.Show("You are not connected", Strings.ERROR);
281+
return;
306282
}
283+
284+
// Get the previous value of the param to display in 'param change info'
285+
// (a better way would be to get the value somewhere from inside the code, insted of recieving it over mavlink)
286+
string previousValue = MainV2.comPort.MAV.param[value].ToString();
287+
// new value of param
288+
double newValue = (double)_changes[value];
289+
290+
// Add the parameter, previous and new values to the list for 'param change info'
291+
// remember, the 'value' here is key of param, while prev and new are actual values of param
292+
savedParams.Add($"{savedParams.Count + 1}) {value} : {previousValue} -> {newValue}");
307293
}
308294
catch
309295
{
296+
error++;
297+
CustomMessageBox.Show("Read " + value + " Failed");
310298
}
299+
}
300+
301+
if (error == 0)
302+
{
303+
// Join the saved parameters list to a string
304+
string savedParamsMessage = string.Join(Environment.NewLine, savedParams);
305+
306+
// Ask the user for confirmation showing detailed changes
307+
if (CustomMessageBox.Show($"You are about to change {savedParams.Count} parameters. Please review the changes below:\n\n{savedParamsMessage}\n\nDo you want to proceed?", "Confirm Parameter Changes",
308+
CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) !=
309+
CustomMessageBox.DialogResult.Yes)
310+
return;
311+
}
312+
}
313+
else
314+
{
315+
// Ask the user for confirmation without listing individual changes
316+
if (CustomMessageBox.Show($"You are about to change {temp.Count} parameters. Are you sure you want to proceed?", "Confirm Parameter Changes",
317+
CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) !=
318+
CustomMessageBox.DialogResult.Yes)
319+
return;
320+
}
311321

322+
if (error == 0)
323+
{
324+
foreach (string value in temp)
325+
{
312326
try
313327
{
314-
// set param table as well
315-
foreach (DataGridViewRow row in Params.Rows)
328+
if (MainV2.comPort.BaseStream == null || !MainV2.comPort.BaseStream.IsOpen)
316329
{
317-
if (row.Cells[Command.Index].Value.ToString() == value)
330+
CustomMessageBox.Show("Your are not connected", Strings.ERROR);
331+
return;
332+
}
333+
334+
MainV2.comPort.setParam(value, (double)_changes[value]);
335+
336+
//check if reboot required
337+
if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString()))
338+
{
339+
reboot = true;
340+
}
341+
try
342+
{
343+
// set control as well
344+
var textControls = Controls.Find(value, true);
345+
if (textControls.Length > 0)
318346
{
319-
row.Cells[Value.Index].Style.BackColor = ThemeManager.ControlBGColor;
320-
_changes.Remove(value);
321-
break;
347+
ThemeManager.ApplyThemeTo(textControls[0]);
322348
}
323349
}
350+
catch
351+
{
352+
}
353+
354+
try
355+
{
356+
// set param table as well
357+
foreach (DataGridViewRow row in Params.Rows)
358+
{
359+
if (row.Cells[Command.Index].Value.ToString() == value)
360+
{
361+
row.Cells[Value.Index].Style.BackColor = ThemeManager.ControlBGColor;
362+
_changes.Remove(value);
363+
break;
364+
}
365+
}
366+
}
367+
catch
368+
{
369+
}
324370
}
325371
catch
326372
{
373+
error++;
374+
CustomMessageBox.Show("Set " + value + " Failed");
327375
}
328376
}
329-
catch
330-
{
331-
error++;
332-
CustomMessageBox.Show("Set " + value + " Failed");
333-
}
334377
}
335378

336379
if (error > 0)
337380
CustomMessageBox.Show("Not all parameters successfully saved.", "Saved");
338381
else
339-
{
340-
// Join the saved parameters list to a string
341-
string savedParamsMessage = string.Join(Environment.NewLine, savedParams);
342-
343-
if (savedParams.Count > 0)
344-
CustomMessageBox.Show($"{savedParams.Count} parameters successfully saved : \n\n{savedParamsMessage}", "Saved");
345-
else
346-
CustomMessageBox.Show($"No parameter saved.", "Saved");
347-
}
348-
382+
CustomMessageBox.Show($"{temp.Count} parameters successfully saved.", "Saved");
383+
349384
//Check if reboot is required
350385
if (reboot)
351386
{

0 commit comments

Comments
 (0)