Skip to content

Commit

Permalink
shrink UDPPacket23IMUFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 21, 2024
1 parent 24b8568 commit f870482
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,14 @@ data class UDPPacket23IMUFrame(
override var sensorId: Int = 0
override fun readData(buf: ByteBuffer) {
sensorId = buf.get().toInt() and 0xFF
rotation = UDPUtils.getSafeBufferQuaternion(buf)
acceleration = Vector3(UDPUtils.getSafeBufferFloat(buf), UDPUtils.getSafeBufferFloat(buf), UDPUtils.getSafeBufferFloat(buf))
val scaleR = (1 shl 15).toFloat() // Q15: 1 is represented as 0x7FFF and -1 as 0x8000
val x = buf.short / scaleR
val y = buf.short / scaleR
val z = buf.short / scaleR
val w = buf.short / scaleR
rotation = Quaternion(w, x, y, z).unit()
val scaleA = (1 shl 7).toFloat() // The same as the HID scale
acceleration = Vector3(buf.short / scaleA, buf.short / scaleA, buf.short / scaleA)
}
}

Expand Down

0 comments on commit f870482

Please sign in to comment.