定义一个数组arr[15]
其中,数组中1-9字节分别代表XYZ轴的角速度,高字节在前,低字节在后,在数据处理的时候,需要将数据转换为int型
int32_t convert3BytesToSignedInt1(uint8_t arr[15]) {
//½«Èý×Ö½Úת»»ÎªÓзûºÅÕûÐÍ
int32_t result = 0;
// ????,??????
result = (arr[1] << 16) | (arr[2] << 8) | arr[3];
// ????????????(arr[0]????)
if (arr[1] & 0x80) {
// ??????1,???????,??9????1
result |= 0xFF000000;
}
return result;
}
int32_t convert3BytesToSignedInt2(uint8_t arr[15]) {
//½«Èý×Ö½Úת»»ÎªÓзûºÅÕûÐÍ
int32_t result = 0;
// ????,??????
result = (arr[4] << 16) | (arr[5] << 8) | arr[6];
// ????????????(arr[0]????)
if (arr[4] & 0x80) {
// ??????1,???????,??9????1
result |= 0xFF000000;
}
return result;
}
int32_t convert3BytesToSignedInt3(uint8_t arr[15]) {
//½«Èý×Ö½Úת»»ÎªÓзûºÅÕûÐÍ
int32_t result = 0;
// ????,??????
result = (arr[7] << 16) | (arr[8] << 8) | arr[9];
// ????????????(arr[0]????)
if (arr[7] & 0x80) {
// ??????1,???????,??9????1
result |= 0xFF000000;
}
return result;
}