diff --git a/project/paint_robot_new/include/paint_robot_new.h b/project/paint_robot_new/include/paint_robot_new.h index f22fd92..ece89d5 100644 --- a/project/paint_robot_new/include/paint_robot_new.h +++ b/project/paint_robot_new/include/paint_robot_new.h @@ -68,7 +68,6 @@ extern "C"{ *----------------------------------------------*/ typedef struct _MSP_MK32_Button { - int32_t RxIndex; int32_t CH0_RY_H; int32_t CH1_RY_V; int32_t CH2_LY_V; @@ -86,6 +85,7 @@ typedef struct _MSP_MK32_Button int32_t CH14_LT; int32_t CH15_RT; int32_t IsOnline; + int32_t RxIndex; } MSP_MK32_Button; /*==============================================* diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index e3c0f13..12e43a5 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -58,7 +58,7 @@ int check_MK32(char *_pBuffer, uint32_t _iSize) void decode_MK32(const char *buf, uint32_t _iSize) { - int16_t CH[16]; + int32_t CH[16]; int Start_byte = 0; CH[0] = ((buf[Start_byte + 1] | buf[Start_byte + 2] << 8) & 0x07FF); @@ -82,21 +82,15 @@ void decode_MK32(const char *buf, uint32_t _iSize) CH[14] = ((buf[Start_byte + 20] >> 2 | buf[Start_byte + 21] << 6) & 0x07FF); CH[15] = ((buf[Start_byte + 21] >> 5 | buf[Start_byte + 22] << 3) & 0x07FF); - int32_t* channel_ptrs[16] = - { - &RB_MK32.CH0_RY_H, &RB_MK32.CH1_RY_V, &RB_MK32.CH2_LY_V, &RB_MK32.CH3_LY_H, - &RB_MK32.CH4_SA, &RB_MK32.CH5_SB, &RB_MK32.CH6_SC, &RB_MK32.CH7_SD, - &RB_MK32.CH8_SE, &RB_MK32.CH9_SF, &RB_MK32.CH10_LD1, &RB_MK32.CH11_RD1, - &RB_MK32.CH12_S1, &RB_MK32.CH13_S2, &RB_MK32.CH14_LT, &RB_MK32.CH15_RT - }; - // 按键数值转换:1050为中间值,272-1712 for (int i = 0; i < 16; i++) { // 通过指针解引用赋值,完美替代原来的 RB_MK32[i + 1] - *channel_ptrs[i] = (int32_t)((CH[i] - 992) * 1.388889); + CH[i] = (int32_t)((CH[i] - 992) * 1.388889); } + RD_MEMCPY(&RB_MK32, CH, sizeof(CH)); + // buf[23] 才是在线标志字节,对应老工程 Sbus_Data_Count(&buffer[1]) 中的 buf[22]==buffer[23] if (buf[23] == 0) {