Exemplo n.º 1
0
        private void testTrigger(string buttonName, SetTrigger setTrigger, GetTrigger getTrigger, PictureBox pictureBox)
        {
            if (stopButton.Enabled == false)
            {
                return;
            }

            try
            {
                float minValue = float.MaxValue;
                float maxValue = float.MinValue;
                for (float f = 0.0F; f <= 1.0 && stopButton.Enabled; f += 1.0F / 256.0F)
                {
                    setTrigger(f);
                    Application.DoEvents();
                    Thread.Sleep(16);
                    minValue = Math.Min(minValue, getTrigger());
                    maxValue = Math.Max(maxValue, getTrigger());
                    string entryLog = String.Format("{0:G} : {1} Trigger : Target = {2:F4}, Value = {3:F4}{4}", DateTime.Now, buttonName, f, getTrigger(), Environment.NewLine);
                    diagnosticsTextBox.AppendText(entryLog);
                }
                setTrigger(0.0F);
                string summaryLog = String.Format("{0:G} : {1} Trigger : Min = {2:F4}, Max = {3:F4}{4}", DateTime.Now, buttonName, minValue, maxValue, Environment.NewLine);
                diagnosticsTextBox.AppendText(summaryLog);
                SetPictureBoxStatus(pictureBox, (minValue == expectedLowTrigger && maxValue == expectedHighTrigger) ? PictureBoxStatus.Good : PictureBoxStatus.Bad);
            }
            catch
            {
                SetPictureBoxStatus(pictureBox, PictureBoxStatus.Bad);
            }
        }
Exemplo n.º 2
0
        static void MenuDoSetTrigger()
        {
            SetTrigger instance = EditorToolbarLoader.GetInstance <SetTrigger>();

            if (instance != null)
            {
                UnityEditor.ProBuilder.EditorUtility.ShowNotification(instance.DoAction().notification);
            }
        }
        private void OnPacketSetTrigger(ref SetTrigger p)
        {
            ushort triggerID = p.TriggerID;
            bool   newState  = p.NewState;

            Await.NextAfterUpdate().OnCompleted(() => {
                if (TileMap != null)
                {
                    TileMap.SetTrigger(triggerID, newState);
                }
            });
        }
Exemplo n.º 4
0
        private void graphTrigger(string titleText, SetTrigger setTrigger, GetTrigger getTrigger, byte[] calibrationTable)
        {
            zedGraphControl.GraphPane.CurveList.Clear();
            GraphPane graphPane = zedGraphControl.GraphPane;

            graphPane.Title.Text       = titleText;
            graphPane.XAxis.Title.Text = "Wiper Value";
            graphPane.XAxis.Scale.Min  = 0;
            graphPane.XAxis.Scale.Max  = 255;
            graphPane.YAxis.Title.Text = "Trigger Value";
            graphPane.YAxis.Scale.Min  = 0.0;
            graphPane.YAxis.Scale.Max  = 1.0;

            PointPairList targetValues = new PointPairList();
            PointPairList actualValues = new PointPairList();
            LineItem      targetCurve  = graphPane.AddCurve("Target", targetValues, Color.Red, SymbolType.None);
            LineItem      actualCurve  = graphPane.AddCurve("Actual", actualValues, Color.Blue, SymbolType.None);

            for (int wiper = 0; wiper <= byte.MaxValue && stopButton.Enabled; wiper++)
            {
                float deflection           = (float)wiper / (float)byte.MaxValue;
                float calibratedDeflection = calibrationTable == null? deflection : (float)calibrationTable[wiper] / (float)byte.MaxValue;
                setTrigger(calibratedDeflection);
                Application.DoEvents();
                Thread.Sleep(16);

                IPointListEdit targetList = targetCurve.Points as IPointListEdit;
                targetList.Add(wiper, deflection);

                IPointListEdit actualList    = actualCurve.Points as IPointListEdit;
                float          actualTrigger = getTrigger();
                actualList.Add(wiper, actualTrigger);

                zedGraphControl.AxisChange();
                zedGraphControl.Invalidate();
            }
            setTrigger(0.0F);
        }
Exemplo n.º 5
0
        private void graphTrigger(string titleText, SetTrigger setTrigger, GetTrigger getTrigger, byte[] calibrationTable)
        {
            zedGraphControl.GraphPane.CurveList.Clear();
            GraphPane graphPane = zedGraphControl.GraphPane;
            graphPane.Title.Text = titleText;
            graphPane.XAxis.Title.Text = "Wiper Value";
            graphPane.XAxis.Scale.Min = 0;
            graphPane.XAxis.Scale.Max = 255;
            graphPane.YAxis.Title.Text = "Trigger Value";
            graphPane.YAxis.Scale.Min = 0.0;
            graphPane.YAxis.Scale.Max = 1.0;

            PointPairList targetValues = new PointPairList();
            PointPairList actualValues = new PointPairList();
            LineItem targetCurve = graphPane.AddCurve("Target", targetValues, Color.Red, SymbolType.None);
            LineItem actualCurve = graphPane.AddCurve("Actual", actualValues, Color.Blue, SymbolType.None);

            for (int wiper = 0; wiper <= byte.MaxValue && stopButton.Enabled; wiper++)
            {
                float deflection = (float)wiper / (float)byte.MaxValue;
                float calibratedDeflection = calibrationTable == null? deflection : (float)calibrationTable[wiper] / (float)byte.MaxValue;
                setTrigger(calibratedDeflection);
                Application.DoEvents();
                Thread.Sleep(16);

                IPointListEdit targetList = targetCurve.Points as IPointListEdit;
                targetList.Add(wiper, deflection);

                IPointListEdit actualList = actualCurve.Points as IPointListEdit;
                float actualTrigger = getTrigger();
                actualList.Add(wiper, actualTrigger);

                zedGraphControl.AxisChange();
                zedGraphControl.Invalidate();
            }
            setTrigger(0.0F);
        }
Exemplo n.º 6
0
        private void calibrateTrigger(string controlName, SetTrigger setTrigger, GetTrigger getTrigger, SetCalibration setCalibration, bool isInverted)
        {
            float[] actualValues = new float[byte.MaxValue + 1];
            byte[] calibrationTable = new byte[byte.MaxValue + 1];

            // Read the GamePad Trigger deflection for each wiper value
            for (int wiper = 0; wiper <= byte.MaxValue && stopButton.Enabled; wiper++)
            {
                float deflection = (float)wiper / (float)byte.MaxValue;
                setTrigger(deflection);
                Application.DoEvents();
                Thread.Sleep(16);
                switch (calibrationEnabledComboBox.Text)
                {
                    case "All High":
                        actualValues[wiper] = 1.0F;
                        break;
                    case "All Centered":
                        actualValues[wiper] = 0.0F;
                        break;
                    case "All Low":
                        actualValues[wiper] = 0.0F;
                        break;
                    default:
                        actualValues[wiper] = getTrigger();
                        break;
                }
            }

            // Find value array entry whose value is closest to zero
            float zero = float.PositiveInfinity;
            Array.ForEach<float>(actualValues, (f) => { zero = (Math.Abs(f) < Math.Abs(zero)) ? f : zero; });

            // Find the last entry whose value is closest to zero
            int lastZero = Array.FindLastIndex<float>(actualValues, (f) => (f == zero));
            if (lastZero == -1) lastZero = byte.MinValue;

            // Find *any* array entry whose value is closest to 1.0F
            float plusOne = float.PositiveInfinity;
            Array.ForEach<float>(actualValues, (f) => { plusOne = (Math.Abs(f - 1.0F) < Math.Abs(plusOne - 1.0F)) ? f : plusOne; });

            // Find the first array entry whose value is closest to 1.0F
            int firstPlusOne = Array.FindIndex<float>(actualValues, (f) => (f == plusOne));
            if (firstPlusOne == -1) firstPlusOne = byte.MaxValue;

            for (int wiper = 0; wiper <= byte.MaxValue; wiper++)
            {
                float deflection = (float)wiper / (float)byte.MaxValue;
                int match = firstPlusOne;
                for (int index = lastZero; index <= firstPlusOne; index++)
                {
                    if (Math.Abs(actualValues[index] - deflection) < Math.Abs(actualValues[match] - deflection))
                        match = index;
                }
                calibrationTable[wiper] = (byte)match;
            }

            setTrigger(0.0F);

            graphTrigger(controlName + " Calibrated (Simulation)", setTrigger, getTrigger, calibrationTable);
            writeCalibrationTable(controlName, calibrationTable, isInverted);
            setCalibration(calibrationTable);
        }
Exemplo n.º 7
0
        static bool MenuVerifySetTrigger()
        {
            SetTrigger instance = EditorToolbarLoader.GetInstance <SetTrigger>();

            return(instance != null && instance.enabled);
        }
Exemplo n.º 8
0
        private void calibrateTrigger(string controlName, SetTrigger setTrigger, GetTrigger getTrigger, SetCalibration setCalibration, bool isInverted)
        {
            float[] actualValues     = new float[byte.MaxValue + 1];
            byte[]  calibrationTable = new byte[byte.MaxValue + 1];

            // Read the GamePad Trigger deflection for each wiper value
            for (int wiper = 0; wiper <= byte.MaxValue && stopButton.Enabled; wiper++)
            {
                float deflection = (float)wiper / (float)byte.MaxValue;
                setTrigger(deflection);
                Application.DoEvents();
                Thread.Sleep(16);
                switch (calibrationEnabledComboBox.Text)
                {
                case "All High":
                    actualValues[wiper] = 1.0F;
                    break;

                case "All Centered":
                    actualValues[wiper] = 0.0F;
                    break;

                case "All Low":
                    actualValues[wiper] = 0.0F;
                    break;

                default:
                    actualValues[wiper] = getTrigger();
                    break;
                }
            }

            // Find value array entry whose value is closest to zero
            float zero = float.PositiveInfinity;

            Array.ForEach <float>(actualValues, (f) => { zero = (Math.Abs(f) < Math.Abs(zero)) ? f : zero; });

            // Find the last entry whose value is closest to zero
            int lastZero = Array.FindLastIndex <float>(actualValues, (f) => (f == zero));

            if (lastZero == -1)
            {
                lastZero = byte.MinValue;
            }

            // Find *any* array entry whose value is closest to 1.0F
            float plusOne = float.PositiveInfinity;

            Array.ForEach <float>(actualValues, (f) => { plusOne = (Math.Abs(f - 1.0F) < Math.Abs(plusOne - 1.0F)) ? f : plusOne; });

            // Find the first array entry whose value is closest to 1.0F
            int firstPlusOne = Array.FindIndex <float>(actualValues, (f) => (f == plusOne));

            if (firstPlusOne == -1)
            {
                firstPlusOne = byte.MaxValue;
            }

            for (int wiper = 0; wiper <= byte.MaxValue; wiper++)
            {
                float deflection = (float)wiper / (float)byte.MaxValue;
                int   match      = firstPlusOne;
                for (int index = lastZero; index <= firstPlusOne; index++)
                {
                    if (Math.Abs(actualValues[index] - deflection) < Math.Abs(actualValues[match] - deflection))
                    {
                        match = index;
                    }
                }
                calibrationTable[wiper] = (byte)match;
            }

            setTrigger(0.0F);

            graphTrigger(controlName + " Calibrated (Simulation)", setTrigger, getTrigger, calibrationTable);
            writeCalibrationTable(controlName, calibrationTable, isInverted);
            setCalibration(calibrationTable);
        }
Exemplo n.º 9
0
        private void testTrigger(string buttonName, SetTrigger setTrigger, GetTrigger getTrigger, PictureBox pictureBox)
        {
            if (stopButton.Enabled == false)
                return;

            try
            {
                float minValue = float.MaxValue;
                float maxValue = float.MinValue;
                for (float f = 0.0F; f <= 1.0 && stopButton.Enabled; f += 1.0F / 256.0F)
                {
                    setTrigger(f);
                    Application.DoEvents();
                    Thread.Sleep(16);
                    minValue = Math.Min(minValue, getTrigger());
                    maxValue = Math.Max(maxValue, getTrigger());
                    string entryLog = String.Format("{0:G} : {1} Trigger : Target = {2:F4}, Value = {3:F4}{4}", DateTime.Now, buttonName, f, getTrigger(), Environment.NewLine);
                    diagnosticsTextBox.AppendText(entryLog);
                }
                setTrigger(0.0F);
                string summaryLog = String.Format("{0:G} : {1} Trigger : Min = {2:F4}, Max = {3:F4}{4}", DateTime.Now, buttonName, minValue, maxValue, Environment.NewLine);
                diagnosticsTextBox.AppendText(summaryLog);
                SetPictureBoxStatus(pictureBox, (minValue == expectedLowTrigger && maxValue == expectedHighTrigger) ? PictureBoxStatus.Good : PictureBoxStatus.Bad);
            }
            catch
            {
                SetPictureBoxStatus(pictureBox, PictureBoxStatus.Bad);
            }
        }