BrrrBayBay.PwmGUIControl.PwmChannelControl.recalculateDutyCycle C# (CSharp) Метод

recalculateDutyCycle() приватный Метод

Recalculates and checks the dutycycle value
private recalculateDutyCycle ( ) : System.Boolean
Результат System.Boolean
        private Boolean recalculateDutyCycle()
        {
            Boolean retVal = false;
            double? rawVal = Utils.getDoubleFromString(dutyCycleBox.Text);
            double maxDc = 0;
            double tmpVal = 0 ;

            if (rawVal != null)
            {
                if (rawVal.Value >= 0)
                {

                    switch (dcUnitsBox.Text)
                    {
                        case "%":
                            if (rawVal.Value <= 100)
                            {
                                tmpVal = ((1f / tmpFrequency) / 100f) * rawVal.Value;
                                dutyCycleBox.BackColor = Color.Empty;
                                retVal = true;
                            }
                            else
                            {
                                dutyCycleBox.BackColor = Color.Salmon;
                            }
                            break;

                        case "us":
                            tmpVal = rawVal.Value / 1000000;
                            dutyCycleBox.BackColor = Color.Empty;
                            break;

                        case "ms":
                            tmpVal = rawVal.Value / 1000;
                            dutyCycleBox.BackColor = Color.Empty;

                            break;
                        default:
                            throw new Exception("Unknown unit selected for dutycycle");
                    }

                    //Check if the dutycycle doesn't exeed the frequency period time
                    maxDc = 1f / tmpFrequency;
                    if (tmpVal > maxDc)
                    {
                        dutyCycleBox.BackColor = Color.Salmon;
                        retVal = false;
                    }
                    else
                    {
                        retVal = true;
                        setTmpDc(tmpVal);
                        updateSliderPosition();
                    }

                }
                else
                {
                    dutyCycleBox.BackColor = Color.Salmon;
                }
            }
            else
            {
                dutyCycleBox.BackColor = Color.Salmon;
            }

            return retVal;
        }