示例#1
0
        internal RDButtonInputControl(byte userButton, byte defaultButton, RailDriverBase railDriver)
        {
            InitializeComponent();
            if (RDButtonInputControl.railDriver == null)
            {
                RDButtonInputControl.railDriver = railDriver;
            }
            if (null == readBuffer)
            {
                readBuffer = railDriver.GetReadBuffer();
            }
            UserButton    = userButton;
            DefaultButton = defaultButton;

            UpdateText();
        }
        private void RunCalibration()
        {
            byte[] readData = instance.GetReadBuffer();
            instance.SetLeds(RailDriverDisplaySign.C, RailDriverDisplaySign.A, RailDriverDisplaySign.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)
            {
                calibrationSet = (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);
        }