Formatting and arrays#74
Conversation
| std::array<int16_t, 4> quaternion_packet; | ||
| //this struct is for mpu9250 support | ||
| #pragma pack(push, 1) | ||
| struct pak { |
There was a problem hiding this comment.
this struct corresponds to the packet send by hardware, it needs to have this structure
struct pak {
uint8_t id;
float quat[4];
uint8_t rest[47];
};changing float[4] to std::array<float, 4> may be fine(can't tell until i test it), but putting it at the end of this struct is definitely not
There was a problem hiding this comment.
Thank you for the review. I've reverted the float[4]. Concerning the removal rest: if the struct was used in the hid_read call, it would indeed not be fine. But on line 167 it is only used as an overlay on the contents of packet_buffer, so the trailing data won't matter.
There was a problem hiding this comment.
fine by me, except the fact that float[4] quat; won't compile, it needs to be float quit[4];
There was a problem hiding this comment.
Oops. I was on my work laptop, so I used the web editor and clicked save a little too fast.
There was a problem hiding this comment.
happens to the best of us
|
apart from that struct change, everything else looks ok at first glance, didn't check it with actual hardware yet i recommend you compile it, and at least test is with real hardware for while before merging this |
|
just dropping by, did anyone try this with actual hardware? |
|
I haven't had the time to source the components for a unit for me, so I wasn't able to test it. I figured the changes weren't radical enough and the reviewer would still need to test it themselves over trusting me on my (proverbial) blue eyes. |
Notable fixes
Fixed array out-of-range in
NormalizeIn
Normalizean attempt is made te read index 3 of a c-array of length 3Replaced the c-arrays of
std::atomic<float>withstd::array<float>guarded by locksWith how the quaternions were copied, race conditions were still possible. Especially in
Relativty::HMDDriver::calibrate_quaternion.Relativty::HMDDriver::qconjwas only written to inRelativty::HMDDriver::calibrate_quaternion, so locking that is a waste.Replaced assignments to quaternion arrays with
std::copys and astd::transformThe compiler can optionally optimise
std::copys tomemcpys or vector operations.Replaced calls to
Relativty::HmdQuaternion_Initwith braced initializationRename
Relativty::ServerDriver::HMDDrivertom_HMDDriverThe distinction between the class and the instance couldn't be made otherwise. No idea how MSVC handled that...
Replaced
NULLs with eithernullptrs or0sSome
NULLs imply the arguments are pointers when they areintsVarious formatting changes and renamed
Relativty::HMDDriver::new_vector_avaiabletoRelativty::HMDDriver::new_vector_available