Skip to content

Commit

Permalink
Allow negative test values for stepper (#1144)
Browse files Browse the repository at this point in the history
* Allow negative test values for stepper
* Fixed validation check for numbers and negeative numbers
  • Loading branch information
DocMoebiuz authored Feb 12, 2023
1 parent 464c3eb commit cea6410
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions UI/Panels/Output/StepperPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,20 @@ private void inputRevTextBox_Validating(object sender, CancelEventArgs e)

try
{
e.Cancel = !(Int16.Parse(value) > 0);
// all boxes should only accept
// positive numbers,
// exception is the test value textbox
var v = Int16.Parse(value);
if (sender != stepperTestValueTextBox)
e.Cancel = !(v > 0);
}
catch (Exception ex)
{
e.Cancel = true;
displayError(sender as Control, i18n._tr("uiMessageValidationMustBeNumber"));
return;
}

if (e.Cancel)
{
displayError(sender as Control, i18n._tr("uiMessagePanelsStepperInputRevolutionsMustBeGreaterThan0"));
Expand Down Expand Up @@ -162,21 +170,16 @@ private void stepperAddressesComboBox_SelectedValueChanged(object sender, EventA

internal void SetStepperProfile(StepperProfilePreset profilePreset)
{
this.StepperProfile = profilePreset;
if (outputRevTextBox.Text == "")
{
outputRevTextBox.Text = this.StepperProfile.StepsPerRevolution.ToString();
}

if (AccelerationTextBox.Text == "")
// we assume that it is safe to update the values
// when we have a different id
if (StepperProfile?.id != profilePreset.id)
{
AccelerationTextBox.Text = this.StepperProfile.Acceleration.ToString();
outputRevTextBox.Text = profilePreset.StepsPerRevolution.ToString();
AccelerationTextBox.Text = profilePreset.Acceleration.ToString();
SpeedTextBox.Text = profilePreset.Speed.ToString();
}

if (SpeedTextBox.Text == "")
{
SpeedTextBox.Text = this.StepperProfile.Speed.ToString();
}
this.StepperProfile = profilePreset;
}

private void ResetButton_Click(object sender, EventArgs e)
Expand Down

0 comments on commit cea6410

Please sign in to comment.