Exemple #1
0
    /// <summary>
    /// Data transformation, encapsulating key values as apis
    /// </summary>
    private void TransformData(ControllerHand hand, int handId, int[] data)
    {
        var offset = handId == 1 ? 67 : 0;

        hand.TouchPadPosition.x = data[0 + offset];
        hand.TouchPadPosition.y = data[5 + offset];

        TransSingleKey(hand.Home, 10 + offset, data);
        TransSingleKey(hand.App, 15 + offset, data);
        TransSingleKey(hand.Touch, 20 + offset, data);
        TransSingleKey(hand.VolumeUp, 25 + offset, data);
        TransSingleKey(hand.VolumeDown, 30 + offset, data);
        TransSingleKey(hand.Trigger, 35 + offset, data);

        if (controllerlink.goblinserviceStarted && !controllerlink.neoserviceStarted)
        {
            hand.TriggerNum = controllerlink.GetHBKeyValue();
        }

        if (!controllerlink.goblinserviceStarted && controllerlink.neoserviceStarted)
        {
            hand.TriggerNum = controllerlink.GetCVTriggerValue(handId);
        }

        hand.Battery = data[40 + offset];

        if (data.Length == 47)
        {
            hand.SwipeDirection = (SwipeDirection)data[45];
            hand.TouchPadClick  = (TouchPadClick)data[46];
        }
        else
        {
            switch (handId)
            {
            case 0:
                TransSingleKey(hand.X, 45 + offset, data);
                TransSingleKey(hand.Y, 50 + offset, data);
                TransSingleKey(hand.Left, 60 + offset, data);
                break;

            case 1:
                TransSingleKey(hand.A, 45 + offset, data);
                TransSingleKey(hand.B, 50 + offset, data);
                TransSingleKey(hand.Right, 55 + offset, data);
                break;
            }

            hand.SwipeDirection = (SwipeDirection)data[65 + offset];
            hand.TouchPadClick  = (TouchPadClick)data[66 + offset];
        }

        hand.GripValue = controllerlink.GetNeo3GripValue(handId);

        var touchData = controllerlink.GetNeo3TouchData(handId);

        TransformTouchData(hand, handId, touchData);
    }
    /// <summary>
    /// Data transformation, encapsulating key values as apis
    /// </summary>
    private void TransformData(ControllerHand hand, int handid, int[] data)
    {
        hand.TouchPadPosition.x = data[0];
        hand.TouchPadPosition.y = data[5];

        hand.Home.State       = Convert.ToBoolean(data[10]);
        hand.Home.PressedDown = Convert.ToBoolean(data[11]);
        hand.Home.PressedUp   = Convert.ToBoolean(data[12]);
        hand.Home.LongPressed = Convert.ToBoolean(data[13]);
        hand.Home.Click       = Convert.ToBoolean(data[14]);

        hand.App.State       = Convert.ToBoolean(data[15]);
        hand.App.PressedDown = Convert.ToBoolean(data[16]);
        hand.App.PressedUp   = Convert.ToBoolean(data[17]);
        hand.App.LongPressed = Convert.ToBoolean(data[18]);
        hand.App.Click       = Convert.ToBoolean(data[19]);

        hand.Touch.State       = Convert.ToBoolean(data[20]);
        hand.Touch.PressedDown = Convert.ToBoolean(data[21]);
        hand.Touch.PressedUp   = Convert.ToBoolean(data[22]);
        hand.Touch.LongPressed = Convert.ToBoolean(data[23]);
        hand.Touch.Click       = Convert.ToBoolean(data[24]);

        hand.VolumeUp.State       = Convert.ToBoolean(data[25]);
        hand.VolumeUp.PressedDown = Convert.ToBoolean(data[26]);
        hand.VolumeUp.PressedUp   = Convert.ToBoolean(data[27]);
        hand.VolumeUp.LongPressed = Convert.ToBoolean(data[28]);
        hand.VolumeUp.Click       = Convert.ToBoolean(data[29]);

        hand.VolumeDown.State       = Convert.ToBoolean(data[30]);
        hand.VolumeDown.PressedDown = Convert.ToBoolean(data[31]);
        hand.VolumeDown.PressedUp   = Convert.ToBoolean(data[32]);
        hand.VolumeDown.LongPressed = Convert.ToBoolean(data[33]);
        hand.VolumeDown.Click       = Convert.ToBoolean(data[34]);

        if (controllerlink.goblinserviceStarted && !controllerlink.neoserviceStarted)
        {
            hand.TriggerNum = controllerlink.GetHBKeyValue();
        }

        if (!controllerlink.goblinserviceStarted && controllerlink.neoserviceStarted)
        {
            hand.TriggerNum = controllerlink.GetCVTriggerValue(handid);
        }

        hand.Trigger.State       = Convert.ToBoolean(data[35]);
        hand.Trigger.PressedDown = Convert.ToBoolean(data[36]);
        hand.Trigger.PressedUp   = Convert.ToBoolean(data[37]);
        hand.Trigger.LongPressed = Convert.ToBoolean(data[38]);
        hand.Trigger.Click       = Convert.ToBoolean(data[39]);

        hand.Battery = data[40];

        if (data.Length == 47)
        {
            hand.SwipeDirection = (SwipeDirection)data[45];
            hand.TouchPadClick  = (TouchPadClick)data[46];
        }
        else
        {
            if (handid == 0)
            {
                hand.X.State       = Convert.ToBoolean(data[45]);
                hand.X.PressedDown = Convert.ToBoolean(data[46]);
                hand.X.PressedUp   = Convert.ToBoolean(data[47]);
                hand.X.LongPressed = Convert.ToBoolean(data[48]);
                hand.X.Click       = Convert.ToBoolean(data[49]);

                hand.Y.State       = Convert.ToBoolean(data[50]);
                hand.Y.PressedDown = Convert.ToBoolean(data[51]);
                hand.Y.PressedUp   = Convert.ToBoolean(data[52]);
                hand.Y.LongPressed = Convert.ToBoolean(data[53]);
                hand.Y.Click       = Convert.ToBoolean(data[54]);

                hand.Left.State       = Convert.ToBoolean(data[60]);
                hand.Left.PressedDown = Convert.ToBoolean(data[61]);
                hand.Left.PressedUp   = Convert.ToBoolean(data[62]);
                hand.Left.LongPressed = Convert.ToBoolean(data[63]);
                hand.Left.Click       = Convert.ToBoolean(data[64]);
            }

            if (handid == 1)
            {
                hand.A.State       = Convert.ToBoolean(data[45]);
                hand.A.PressedDown = Convert.ToBoolean(data[46]);
                hand.A.PressedUp   = Convert.ToBoolean(data[47]);
                hand.A.LongPressed = Convert.ToBoolean(data[48]);
                hand.A.Click       = Convert.ToBoolean(data[49]);

                hand.B.State       = Convert.ToBoolean(data[50]);
                hand.B.PressedDown = Convert.ToBoolean(data[51]);
                hand.B.PressedUp   = Convert.ToBoolean(data[52]);
                hand.B.LongPressed = Convert.ToBoolean(data[53]);
                hand.B.Click       = Convert.ToBoolean(data[54]);

                hand.Right.State       = Convert.ToBoolean(data[55]);
                hand.Right.PressedDown = Convert.ToBoolean(data[56]);
                hand.Right.PressedUp   = Convert.ToBoolean(data[57]);
                hand.Right.LongPressed = Convert.ToBoolean(data[58]);
                hand.Right.Click       = Convert.ToBoolean(data[59]);
            }

            hand.SwipeDirection = (SwipeDirection)data[65];
            hand.TouchPadClick  = (TouchPadClick)data[66];
        }
    }