/// <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(System.DateTime.Now.ToLongTimeString() + ": OmniController(ReadOmniData) - During this frame, failed to read the Omni data packet."); } if (motionData != null) { debugCounterForDataMessages++; if (debugCounterForDataMessages > 450) { 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; } }
/// <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; } }