/// <summary>
    /// Pulls packets from the Omni and decodes them to populate the class variables and motiondata.
    /// </summary>
    void ReadOmniData()
    {
        byte[] packet = null;

        if (omniManager.ReadData(ref packet) > 0)
        {
            OmniCommon.Messages.OmniBaseMessage obm = OmniCommon.OmniPacketBuilder.decodePacket(packet);

            if (obm != null)
            {
                switch (obm.MsgType)
                {
                case OmniCommon.Messages.MessageType.OmniMotionAndRawDataMessage:
                    OmniCommon.Messages.OmniMotionAndRawDataMessage OmniMotionAndRawData = new OmniCommon.Messages.OmniMotionAndRawDataMessage(obm);
                    motionData = OmniMotionAndRawData.GetMotionData();
                    Debug.Log(motionData.ToString());
                    break;

                default:
                    break;
                }
            }
        }
        else
        {
            motionData = null;
            Debug.LogError(System.DateTime.Now.ToLongTimeString() + ": OmniMovementComponent(ReadOmniData) - During this frame, failed to read the Omni data packet.");
        }

        if (motionData != null)
        {
            /*
             * debugCounterForDataMessages++;
             * if (debugCounterForDataMessages > 30)
             * {
             *  Debug.Log(System.DateTime.Now.ToLongTimeString() +
             *      ": Timestamp = " + motionData.Timestamp +
             *      "; Step count = " + motionData.StepCount +
             *      "; Ring Angle = " + motionData.RingAngle +
             *      "; Ring Delta = " + motionData.RingDelta +
             *      "; joy x = " + motionData.GamePad_X +
             *      "; joy y = " + motionData.GamePad_Y);
             *  debugCounterForDataMessages = 0;
             * }*/

            currentOmniYaw = motionData.RingAngle;

            rawX  = motionData.GamePad_X;
            rawY  = motionData.GamePad_Y;
            omniX = motionData.GamePad_X;
            omniY = motionData.GamePad_Y;

            if (omniX > 0)
            {
                omniX = (omniX / 255.0f) * 2f - 1f;
            }
            else
            {
                omniX = -1f;
            }

            if (omniY > 0)
            {
                omniY = (omniY / 255.0f) * 2f - 1f;
            }
            else
            {
                omniY = -1;
            }

            //clamp '0'
            if (rawX == 127)
            {
                omniX = 0f;
            }
            if (rawY == 127)
            {
                omniY = 0f;
            }
            //@TODO - may need to change this for fully coupled mode...
            omniY   *= -1f;
            hidInput = new Vector2(omniX, omniY);


            if (hasFullyInitialized)
            {
                UpdateStepCountFromMotionData();
            }
        }
        else
        {
            hidInput = Vector2.zero;
        }
    }
Example #2
0
        /// <summary>
        /// Pulls packets from the Omni and decodes them to populate the class variables and motiondata.
        /// </summary>
        void ReadOmniData()
        {
            byte[] packet = null;

            if (omniManager.ReadData(ref packet) > 0)
            {
                obm = OmniCommon.OmniPacketBuilder.decodePacket(packet);

                if (obm != null)
                {
                    switch (obm.MsgType)
                    {
                    case OmniCommon.Messages.MessageType.OmniRawDataMessage:

                        ordm    = new OmniCommon.Messages.OmniRawDataMessage(obm);
                        rawData = ordm.GetRawData();
                        break;

                    case OmniCommon.Messages.MessageType.OmniMotionDataMessage:
                        omdm       = new OmniCommon.Messages.OmniMotionDataMessage(obm);
                        motionData = omdm.GetMotionData();
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                motionData = null;
                Debug.LogError("Omni data reading failed.");
            }

            if (motionData != null)
            {
                currentOmniYaw = motionData.RingAngle;

                rawX  = motionData.GamePad_X;
                rawY  = motionData.GamePad_Y;
                omniX = motionData.GamePad_X;
                omniY = motionData.GamePad_Y;

                if (omniX > 0)
                {
                    omniX = (omniX / 255.0f) * 2f - 1f;
                }
                else
                {
                    omniX = -1f;
                }

                if (omniY > 0)
                {
                    omniY = (omniY / 255.0f) * 2f - 1f;
                }
                else
                {
                    omniY = -1;
                }

                //clamp '0'
                if (rawX == 127)
                {
                    omniX = 0f;
                }
                if (rawY == 127)
                {
                    omniY = 0f;
                }
                //@TODO - may need to change this for fully coupled mode...
                omniY   *= -1f;
                hidInput = new Vector2(omniX, omniY);

                if (hasFullyInitialized)
                {
                    UpdateStepCountFromMotionData();
                }
            }
            else
            {
                hidInput = Vector2.zero;
            }
        }