Example #1
0
        private void SaveRailDriverSettings()
        {
            foreach (Control control in panelRDButtons.Controls)
            {
                if (control is Panel)
                {
                    foreach (Control child in control.Controls)
                    {
                        if (child is RDButtonInputControl)
                        {
                            Settings.RailDriver.UserCommands[(int)child.Tag] = (child as RDButtonInputControl).UserButton;
                        }
                    }
                    break;
                }
            }

            if (isCalibrationSet)
            {
                currentCalibrationStep = RailDriverCalibrationSetting.ReverserNeutral;
                while (currentCalibrationStep < RailDriverCalibrationSetting.ReverseReverser)
                {
                    Settings.RailDriver.CalibrationSettings[(int)currentCalibrationStep] = calibrationSettings[(int)currentCalibrationStep];
                    currentCalibrationStep++;
                }
            }

            Settings.RailDriver.CalibrationSettings[(int)RailDriverCalibrationSetting.ReverseReverser]         = Convert.ToByte(checkReverseReverser.Checked);
            Settings.RailDriver.CalibrationSettings[(int)RailDriverCalibrationSetting.ReverseThrottle]         = Convert.ToByte(checkReverseThrottle.Checked);
            Settings.RailDriver.CalibrationSettings[(int)RailDriverCalibrationSetting.ReverseAutoBrake]        = Convert.ToByte(checkReverseAutoBrake.Checked);
            Settings.RailDriver.CalibrationSettings[(int)RailDriverCalibrationSetting.ReverseIndependentBrake] = Convert.ToByte(checkReverseIndependentBrake.Checked);
            Settings.RailDriver.CalibrationSettings[(int)RailDriverCalibrationSetting.FullRangeThrottle]       = Convert.ToByte(checkFullRangeThrottle.Checked);

            currentCalibrationStep = RailDriverCalibrationSetting.CutOffDelta;
        }
Example #2
0
        private void RunCalibration()
        {
            byte[] readData = instance.NewReadBuffer;
            instance.SetLeds(RailDriverDisplaySign.Char_C, RailDriverDisplaySign.Char_A, RailDriverDisplaySign.Char_L);
            RailDriverCalibrationSetting nextStep = RailDriverCalibrationSetting.ReverserNeutral;
            DialogResult result = DialogResult.OK;

            while (result == DialogResult.OK && nextStep < RailDriverCalibrationSetting.ReverseReverser)
            {
                currentCalibrationStep = nextStep;
                railDriverLegend.Invalidate(true);  //enforce redraw legend to show guidance
                result = MessageBox.Show(railDriverLegend, $"Now calibrating \"{currentCalibrationStep.GetDescription()}\". Move the Lever as indicated through guidance. \r\n\r\nClick OK to read the position and continue. Click Cancel anytime to abort the calibration process.", "RailDriver Calibration", MessageBoxButtons.OKCancel);
                // Read Setting
                if (result == DialogResult.OK)
                {
                    if (0 == instance.ReadCurrentData(ref readData))
                    {
                        int index = 0;
                        if ((int)currentCalibrationStep < 3)        //Reverser
                        {
                            index = 1;
                        }
                        else if ((int)currentCalibrationStep < 7)   //Throttle/Dynamic Brake
                        {
                            index = 2;
                        }
                        else if ((int)currentCalibrationStep < 10)  //Auto Brake
                        {
                            index = 3;
                        }
                        else if ((int)currentCalibrationStep < 12)  //Independent Brake
                        {
                            index = 4;
                        }
                        else if ((int)currentCalibrationStep < 16)  //Independent Brake
                        {
                            index = 5;
                        }
                        else if ((int)currentCalibrationStep < 19)  //Rotary 1
                        {
                            index = 6;
                        }
                        else if ((int)currentCalibrationStep < 22)  //Rotary 2
                        {
                            index = 7;
                        }

                        calibrationSettings[(int)currentCalibrationStep] = readData[index];
                        instance.SetLedsNumeric(readData[index]);
                    }
                }
                nextStep++;
            }
            currentCalibrationStep = RailDriverCalibrationSetting.CutOffDelta;
            railDriverLegend.Invalidate(true);
            if (nextStep == RailDriverCalibrationSetting.ReverseReverser)
            {
                isCalibrationSet = (MessageBox.Show(railDriverLegend, "Calibration Completed. Do you want to keep the results?", "Calibration Done", MessageBoxButtons.YesNo) == DialogResult.Yes);
            }
            instance.SetLeds(RailDriverDisplaySign.Blank, RailDriverDisplaySign.Blank, RailDriverDisplaySign.Blank);
        }