Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance full parameter change message box #3412

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
58 changes: 51 additions & 7 deletions GCSViews/ConfigurationView/ConfigRawParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ private void BUT_save_Click(object sender, EventArgs e)

private void BUT_writePIDS_Click(object sender, EventArgs e)
{
if (Common.MessageShowAgain("Write Raw Params", "Are you Sure?") != DialogResult.OK)
return;

// sort with enable at the bottom - this ensures params are set before the function is disabled
var temp = _changes.Keys.Cast<string>().ToList();

Expand All @@ -266,6 +263,49 @@ private void BUT_writePIDS_Click(object sender, EventArgs e)
int error = 0;
bool reboot = false;

if (temp.Count > 0 && temp.Count <= 20)
prathamEndu marked this conversation as resolved.
Show resolved Hide resolved
{
// List to track successfully saved parameters
List<string> savedParams = new List<string>();

foreach (string value in temp)
{
if (MainV2.comPort.BaseStream == null || !MainV2.comPort.BaseStream.IsOpen)
{
CustomMessageBox.Show("You are not connected", Strings.ERROR);
return;
}

// Get the previous value of the param to display in 'param change info'
// (a better way would be to get the value somewhere from inside the code, insted of recieving it over mavlink)
string previousValue = MainV2.comPort.MAV.param[value].ToString();
// new value of param
double newValue = (double)_changes[value];

// Add the parameter, previous and new values to the list for 'param change info'
// remember, the 'value' here is key of param, while prev and new are actual values of param
savedParams.Add($"{savedParams.Count + 1}) {value} : {previousValue} -> {newValue}");
prathamEndu marked this conversation as resolved.
Show resolved Hide resolved
}

// Join the saved parameters list to a string
string savedParamsMessage = string.Join(Environment.NewLine, savedParams);

// Ask the user for confirmation showing detailed changes
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",
CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) !=
CustomMessageBox.DialogResult.Yes)
return;
}
else if (temp.Count > 20)
{
// Ask the user for confirmation without listing individual changes
if (CustomMessageBox.Show($"You are about to change {temp.Count} parameters. Are you sure you want to proceed?", "Confirm Parameter Changes",
CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) !=
CustomMessageBox.DialogResult.Yes)
return;
}


foreach (string value in temp)
{
try
Expand All @@ -277,10 +317,11 @@ private void BUT_writePIDS_Click(object sender, EventArgs e)
}

MainV2.comPort.setParam(value, (double)_changes[value]);

//check if reboot required
if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString()))
{
reboot = true;
if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString()))
{
reboot = true;
prathamEndu marked this conversation as resolved.
Show resolved Hide resolved
}
try
{
Expand Down Expand Up @@ -318,11 +359,14 @@ private void BUT_writePIDS_Click(object sender, EventArgs e)
CustomMessageBox.Show("Set " + value + " Failed");
}
}

prathamEndu marked this conversation as resolved.
Show resolved Hide resolved

if (error > 0)
CustomMessageBox.Show("Not all parameters successfully saved.", "Saved");
else if (temp.Count>0)
CustomMessageBox.Show($"{temp.Count} parameters successfully saved.", "Saved");
else
CustomMessageBox.Show("Parameters successfully saved.", "Saved");
CustomMessageBox.Show($"No parameters were changed.", "No changes");
prathamEndu marked this conversation as resolved.
Show resolved Hide resolved

//Check if reboot is required
if (reboot)
Expand Down