From 2d0badde9aa9a48480e24a289569de1046c6acba Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 12 Jul 2023 01:05:23 -0500 Subject: [PATCH] Send zero state gyro events as reliable traffic --- src/InputStream.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/InputStream.c b/src/InputStream.c index 6cdf196..b45aa73 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -1424,8 +1424,16 @@ int LiSendControllerMotionEvent(uint8_t controllerNumber, uint8_t motionType, fl // Send each controller on a separate channel specific to motion sensors holder->channelId = CTRL_CHANNEL_SENSOR_BASE + controllerNumber; - // Motion events are so rapid that we can just drop any events that are lost in transit - holder->enetPacketFlags = 0; + // Motion events are so rapid that we can just drop any events that are lost in transit, + // but we will treat (0, 0, 0) as a special value for gyro events to allow clients to + // reliably set the gyro to a null state when sensor events are halted due to focus loss + // or similar client-side constraints. + if (motionType == LI_MOTION_TYPE_GYRO && x == 0.0f && y == 0.0f && z == 0.0f) { + holder->enetPacketFlags = ENET_PACKET_FLAG_RELIABLE; + } + else { + holder->enetPacketFlags = 0; + } holder->packet.controllerMotion.header.size = BE32(sizeof(SS_CONTROLLER_MOTION_PACKET) - sizeof(uint32_t)); holder->packet.controllerMotion.header.magic = LE32(SS_CONTROLLER_MOTION_MAGIC);