Example #1
0
        // compares the current measured quantity to a given value
        // returns true if the measured quantity is less than / more than [comparator] the given value
        private bool valueComparer(double value, RampMode mode, Comparison comparator)
        {
            switch (mode)
            {
            case RampMode.Current:
            {
                return((comparator == Comparison.LessThan) == (Current < value));
            }

            case RampMode.Power_CC:
            case RampMode.Power_CV:
            {
                return((comparator == Comparison.LessThan) == (Power < value));
            }

            case RampMode.Resistance_CC:
            case RampMode.Resistance_CV:
            {
                return((comparator == Comparison.LessThan) == (Resistance < value));
            }

            case RampMode.Voltage:
            case RampMode.VoltageSoftware:
            {
                return((comparator == Comparison.LessThan) == (Voltage < value));
            }
            }

            throw new NotImplementedException();
        }
        public IEnumerator TempoRamp()
        {
            float progress = 0;

            while (tempoRampActive)
            {
                if (ModifierManager.stopAllModifiers)
                {
                    AudioDriver.I.SetSpeed(1f);
                    if (amount >= 1f)
                    {
                        ScoreKeeper.I.GetScoreValidity();
                    }
                    tempoRampActive = false;
                    base.Deactivate();
                    yield break;
                }
                if (rampmode == RampMode.Up)
                {
                    AudioDriver.I.SetSpeed(Mathf.Lerp(1f, amount, progress / 200f));
                    if ((amount > 1f && AudioDriver.I.mSpeed >= amount) || (amount < 1f && AudioDriver.I.mSpeed <= amount))
                    {
                        AudioDriver.I.SetSpeed(amount);
                        tempoRampActive = false;
                        rampmode        = RampMode.Down;
                        MelonCoroutines.Start(ActiveTimer());
                        yield break;
                    }
                }
                else
                {
                    AudioDriver.I.SetSpeed(Mathf.Lerp(amount, 1f, progress / 200f));
                    if ((amount < 1f && AudioDriver.I.mSpeed >= 1f) || (amount > 1f && AudioDriver.I.mSpeed <= 1f))
                    {
                        AudioDriver.I.SetSpeed(1f);
                        tempoRampActive = false;
                        base.Deactivate();
                        yield break;
                    }
                }
                if (amount >= 1f)
                {
                    ScoreKeeper.I.GetScoreValidity();
                }
                progress++;
                yield return(new WaitForSecondsRealtime(.002f));
            }
        }
Example #3
0
 public static RunMode ToRunMode(this RampMode mode)
 {
     return((RunMode)((int)mode));
 }
Example #4
0
 public static string Symbol(this RampMode mode)
 {
     return(RampModeSymbols[(int)mode]);
 }
Example #5
0
 public static string Name(this RampMode mode)
 {
     return(RampModeNames[(int)mode]);
 }
Example #6
0
        // adds items from xml file to already existing list of program items; ignores loop settings
        public void AddItems(BindingList <ProgramItem> programItems)
        {
            XmlElement main;
            XmlNode    items;
            XmlNode    parameter;

            document.Load(this.path);
            main  = document.DocumentElement;
            items = main.SelectSingleNode("items");

            foreach (XmlNode item in items)
            {
                ProgramModes programMode;
                bool         result = (Enum.TryParse(item.Attributes.GetNamedItem("programMode").Value, out programMode));
                if (result)
                {
                    switch (programMode)
                    {
                    case ProgramModes.Constant:
                    {
                        // mode
                        RunMode mode = (RunMode)(Enum.Parse(typeof(RunMode), item.Attributes.GetNamedItem("mode").Value));

                        // value
                        parameter = item.Attributes.GetNamedItem("value");
                        double?value = null;
                        if (parameter.Value != "previous")
                        {
                            value = Double.Parse(parameter.Value);
                        }

                        // duration
                        string durationString = item.Attributes.GetNamedItem("duration").Value;

                        // timeunits
                        TimeUnits timeunit = (TimeUnits)(Enum.Parse(typeof(TimeUnits), item.Attributes.GetNamedItem("timeUnit").Value));

                        // skip
                        bool          skipEnabled = false;
                        WDandSkipMode skipMode;
                        Comparison    skipComparator;
                        double        skipValue;
                        foreach (XmlNode node in item.ChildNodes)
                        {
                            if (node.Name == "skip")
                            {
                                skipEnabled    = true;
                                skipMode       = (WDandSkipMode)(Enum.Parse(typeof(WDandSkipMode), node.Attributes.GetNamedItem("mode").Value));
                                skipComparator = (Comparison)(Enum.Parse(typeof(Comparison), node.Attributes.GetNamedItem("comparator").Value));
                                skipValue      = Double.Parse(node.Attributes.GetNamedItem("value").Value);
                                programItems.Add(new ProgramItem(mode, value, durationString, timeunit, skipMode, skipComparator, skipValue));
                                break;
                            }
                        }
                        if (!skipEnabled)
                        {
                            programItems.Add(new ProgramItem(mode, value, durationString, timeunit));
                        }
                        break;
                    }

                    case ProgramModes.Ramp:
                    {
                        // mode
                        RampMode mode = (RampMode)(Enum.Parse(typeof(RampMode), item.Attributes.GetNamedItem("mode").Value));

                        // starting value
                        parameter = item.Attributes.GetNamedItem("startingValue");
                        double?startingValue = null;
                        if (parameter.Value != "previous")
                        {
                            startingValue = Double.Parse(parameter.Value);
                        }

                        // final value
                        parameter = item.Attributes.GetNamedItem("finalValue");
                        double finalValue;
                        finalValue = Double.Parse(parameter.Value);

                        // duration
                        string durationString = item.Attributes.GetNamedItem("duration").Value;

                        // timeunits
                        TimeUnits timeunit = (TimeUnits)(Enum.Parse(typeof(TimeUnits), item.Attributes.GetNamedItem("timeUnit").Value));

                        // skip
                        bool          skipEnabled = false;
                        WDandSkipMode skipMode;
                        Comparison    skipComparator;
                        double        skipValue;
                        foreach (XmlNode node in item.ChildNodes)
                        {
                            if (node.Name == "skip")
                            {
                                skipEnabled    = true;
                                skipMode       = (WDandSkipMode)(Enum.Parse(typeof(WDandSkipMode), node.Attributes.GetNamedItem("mode").Value));
                                skipComparator = (Comparison)(Enum.Parse(typeof(Comparison), node.Attributes.GetNamedItem("comparator").Value));
                                skipValue      = Double.Parse(node.Attributes.GetNamedItem("value").Value);
                                programItems.Add(new ProgramItem(mode, startingValue, finalValue, durationString, timeunit, skipMode, skipComparator, skipValue));
                                break;
                            }
                        }
                        if (!skipEnabled)
                        {
                            programItems.Add(new ProgramItem(mode, startingValue, finalValue, durationString, timeunit));
                        }
                        break;
                    }

                    case ProgramModes.Pin:
                    {
                        // pin number
                        parameter = item.Attributes.GetNamedItem("pinLogicalNumber");
                        byte pinNumber;
                        if (parameter.Value != "all")
                        {
                            pinNumber = byte.Parse(parameter.Value);
                        }
                        else
                        {
                            pinNumber = Convert.ToByte(Load.Pins.Length);
                        }

                        // action
                        parameter = item.Attributes.GetNamedItem("action");
                        if (parameter.Value == "set")
                        {
                            programItems.Add(new ProgramItem(pinNumber, true));
                        }
                        else if (parameter.Value == "reset")
                        {
                            programItems.Add(new ProgramItem(pinNumber, false));
                        }
                        break;
                    }
                    }
                }
            }
        }
Example #7
0
 // constructor for ramp mode with skip
 public ProgramItem(RampMode mode, double?startingValue, double finalValue, string durationString, TimeUnits timeUnit, WDandSkipMode skipMode, Comparison skipComparator, double skipValue)
 {
     ramp(mode, startingValue, finalValue, durationString, timeUnit);
     skip(skipMode, skipComparator, skipValue);
 }
Example #8
0
 // constructor for ramp mode
 public ProgramItem(RampMode mode, double?startingValue, double finalValue, string durationString, TimeUnits timeUnit)
 {
     ramp(mode, startingValue, finalValue, durationString, timeUnit);
 }
Example #9
0
        // creates ramp mode program item
        private void ramp(RampMode mode, double?startingValue, double finalValue, string durationString, TimeUnits timeUnit)
        {
            this.programMode    = ProgramModes.Ramp;
            this.mode           = mode.ToRunMode();
            this.durationString = durationString;
            this.timeUnit       = timeUnit;
            this.startingValue  = startingValue;
            this.finalValue     = finalValue;

            // compute duration in seconds
            Converters.TimeConverter timeConverter = new Converters.TimeConverter();
            this.duration = (double)(timeConverter.ConvertBack(durationString, typeof(double), timeUnit, System.Globalization.CultureInfo.CurrentCulture));

            // string representation for GUI
            switch (mode)
            {
            case RampMode.Current:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp current " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp current (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.Power_CC:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp power (CC) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp power (CC, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.Power_CV:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp power (CV) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp power (CV, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.Resistance_CC:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp resistance (CC) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp resistance (CC, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.Resistance_CV:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp resistance (CV) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp resistance (CV, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.Voltage:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp voltage " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp voltage (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }

            case RampMode.VoltageSoftware:
            {
                if (startingValue != null)
                {
                    this.name = "Ramp SW controlled voltage " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString();
                }
                else
                {
                    this.name = "Ramp SW controlled voltage (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString();
                }
                break;
            }
            }
        }