1.修复绝对值按键映射不保存的问题 pc和app同时设置
authord15521469561 <1731678236@qq.com>
Fri, 5 Jun 2026 03:02:12 +0000 (11:02 +0800)
committerd15521469561 <1731678236@qq.com>
Fri, 5 Jun 2026 03:02:12 +0000 (11:02 +0800)
App/inc/flash.h
App/inc/io.h
App/src/flash.c
App/src/iap.c
App/src/io.c
App/src/iot.c
App/src/system.c

index 74f4ecb..c23384b 100644 (file)
@@ -49,7 +49,7 @@
 
 // °´¼üÓ³Éä
 #define FLASH_INPUT_REMAP_ADDR                                         (0x08075000)
-#define FLASH_INPUT_REMAP_FLAG                                         (0x09000001)
+#define FLASH_INPUT_REMAP_FLAG                                         (0x09000002)
 
 // Óû§ÊäÈëÊä³öÉèÖÃ
 #define FLASH_USER_IO_SETTING_ADDR                                     (0x08075800)
index dc72fa5..af72331 100644 (file)
@@ -5,6 +5,10 @@
 #include "led.h"
 
 #pragma pack(push, 1)
+
+// ½á¹¹Ìå³ÉÔ±Æ«ÒÆÁ¿
+#define offsetofstruct(type,member)   ((int) &((type *)0)->member)
+       
 typedef enum
 {
        GPIOP_A = 0,
@@ -869,7 +873,59 @@ typedef union
        };
        uint8_t remap_dst[34];
 #endif
-}IO_REMAPABLE_KEY_T;
+}IO_REMAPABLE_KEY_0_T;
+
+typedef union
+{
+#if (W_GTL)
+       struct
+       {
+               uint8_t abs_enc1_cnt1;
+               uint8_t abs_enc1_cnt2;
+               uint8_t abs_enc1_cnt3;
+               uint8_t abs_enc1_cnt4;
+               uint8_t abs_enc1_cnt5;
+               uint8_t abs_enc1_cnt6;
+               uint8_t abs_enc1_cnt7;
+               uint8_t abs_enc1_cnt8;
+               
+               uint8_t abs_enc1_cnt9;
+               uint8_t abs_enc1_cnt10;
+               uint8_t abs_enc1_cnt11;
+               uint8_t abs_enc1_cnt12;
+               uint8_t abs_enc2_cnt1;
+               uint8_t abs_enc2_cnt2;
+               uint8_t abs_enc2_cnt3;
+               uint8_t abs_enc2_cnt4;
+               
+               uint8_t abs_enc2_cnt5;
+               uint8_t abs_enc2_cnt6;
+               uint8_t abs_enc2_cnt7;
+               uint8_t abs_enc2_cnt8;
+               uint8_t abs_enc2_cnt9;
+               uint8_t abs_enc2_cnt10;
+               uint8_t abs_enc2_cnt11;
+               uint8_t abs_enc2_cnt12;
+               
+               uint8_t abs_enc3_cnt1;
+               uint8_t abs_enc3_cnt2;
+               uint8_t abs_enc3_cnt3;
+               uint8_t abs_enc3_cnt4;
+               uint8_t abs_enc3_cnt5;
+               uint8_t abs_enc3_cnt6;
+               uint8_t abs_enc3_cnt7;
+               uint8_t abs_enc3_cnt8;
+               
+               uint8_t abs_enc3_cnt9;
+               uint8_t abs_enc3_cnt10;
+               uint8_t abs_enc3_cnt11;
+               uint8_t abs_enc3_cnt12;
+       };
+       uint8_t remap_dst[36];
+#elif (W_TS)
+
+#endif
+}IO_REMAPABLE_KEY_1_T;
 
 typedef union
 {
@@ -985,7 +1041,8 @@ typedef union
                                uint8_t sub_packet;
                                union
                                {
-                                       IO_REMAPABLE_KEY_T remapable_key;
+                                       IO_REMAPABLE_KEY_0_T remapable_key_0;
+                                       IO_REMAPABLE_KEY_1_T remapable_key_1;
                                };
                        }mode1;
                        
index 26f692c..1eee383 100644 (file)
@@ -811,7 +811,7 @@ void Flash_Io_Input_Remap_Set_Default(void *remap_table)
        
        for(uint8_t i=0;i<=((int)&((IO_INPUT_REMAP_T *)0)->abs_enc3_cnt12)-((int)&((IO_INPUT_REMAP_T *)0)->abs_enc1_cnt1);i++)
        {
-               ((IO_INPUT_REMAP_T*)remap_table)->data[i+((int)&((IO_INPUT_REMAP_T *)0)->abs_enc1_cnt1)] = i+(128-36)+1;
+               ((IO_INPUT_REMAP_T*)remap_table)->data[i+((int)&((IO_INPUT_REMAP_T *)0)->abs_enc1_cnt1)] = i+55;
        }
        
        ((IO_INPUT_REMAP_T*)remap_table)->paddle_ld = KV_AXIS_Z;
index 31c2bd8..fe052b2 100644 (file)
@@ -59,7 +59,7 @@ uint8_t Iap_Write(uint32_t addr, uint8_t packet_size, uint8_t* data)
                wdata |= data[j+1]<<8;
                wdata |= data[j+2]<<16;
                wdata |= data[j+3]<<24;
-               DUG_PRINTF("addr:%08x\n",waddr+4*i);
+               
                FLASH_ProgramWord(waddr+4*i, wdata);
                j+=4;
        }
index 73ae933..8ec95f7 100644 (file)
@@ -487,7 +487,7 @@ void Io_Init(void)
 //     Led_Key_Switch_Profile(0);
 //     Led_Tele_Switch_Profile(0);
 //     Led_Enc_Switch_Profile(0);
-       Led_Key_Ble_Connected_Blink();
+//     Led_Key_Ble_Connected_Blink();
        
        Base_Uart_Init();
 #if (IOT_ENABLE)
@@ -610,7 +610,6 @@ ENCODER_DIR_T encoder_dir[DIR_ENC_NUM] = {{.data = 0}, {.data = 0}};
 uint16_t encoder_bcd_cooldown[ABS_ENC_NUM] = {0};
 ENCODER_BCD_T encoder_bcd[ABS_ENC_NUM] = {{.data = 0}, {.data = 0}, {.data = 0}};
 ENCODER_BCD_T encoder_bcd_last[ABS_ENC_NUM] = {{.data = 0xFF}, {.data = 0xFF}, {.data = 0xFF}};
-uint8_t abs_enc_mode[ABS_ENC_NUM] = {0, 0, 0};
 uint16_t abs_enc_pos_bit[ABS_ENC_NUM] = {0};
 #endif
 #endif
@@ -2516,31 +2515,45 @@ void App_Comm_Handle(uint8_t* data, uint8_t size)
                                        if(app_command->key_remap.mode == 0)
                                        {
                                                app_reply.key_remap.mode1.sub_packet = app_command->key_remap.mode1.sub_packet;
+                                               app_reply.cmd.status = REPLY_STATUS_OK;
+#if (W_GTL)
                                                if(app_command->key_remap.mode1.sub_packet == 0)
                                                {
-#if (W_GTL)
-                                                       memcpy(&app_reply.key_remap.mode1.remapable_key.key1, &io_input_remap[DINPUT_MODE].key1, 40);
-                                                       memcpy(&app_reply.key_remap.mode1.remapable_key.paddle_ld, &io_input_remap[DINPUT_MODE].paddle_ld, 2);
+                                                       memcpy(&app_reply.key_remap.mode1.remapable_key_0.key1, &io_input_remap[DINPUT_MODE].key1, 40);
+                                                       memcpy(&app_reply.key_remap.mode1.remapable_key_0.paddle_ld, &io_input_remap[DINPUT_MODE].paddle_ld, 2);
+                                               }
+                                               else if(app_command->key_remap.mode1.sub_packet == 1)
+                                               {
+                                                       memcpy(&app_reply.key_remap.mode1.remapable_key_1.abs_enc1_cnt1, &io_input_remap[DINPUT_MODE].abs_enc1_cnt1, sizeof(IO_REMAPABLE_KEY_1_T));
+                                               }
 #elif (W_TS)
-                                                       memcpy(&app_reply.key_remap.mode1.remapable_key.key1, &io_input_remap[DINPUT_MODE].key1, sizeof(IO_REMAPABLE_KEY_T));
+                                               if(app_command->key_remap.mode1.sub_packet == 0)
+                                               {
+                                                       memcpy(&app_reply.key_remap.mode1.remapable_key_0.key1, &io_input_remap[DINPUT_MODE].key1, sizeof(IO_REMAPABLE_KEY_0_T));
+                                               }
 #endif
+                                               else
+                                               {
+                                                       app_reply.cmd.status = REPLY_STATUS_NO_CMD;
                                                }
-                                               app_reply.cmd.status = REPLY_STATUS_OK;
+                                               
                                        }
                                        else if(app_command->key_remap.mode == 1)
                                        {
                                                app_reply.key_remap.mode2.remap_src = app_command->key_remap.mode2.remap_src;
                                                
-                                               if(app_command->key_remap.mode2.remap_src >= 40 && app_command->key_remap.mode2.remap_src <= 75)
-                                               {
-                                                       app_reply.key_remap.mode2.remap_dst = 0;
-                                                       app_reply.cmd.status = REPLY_STATUS_FAIL;
-                                               }
-                                               else
-                                               {
-                                                       app_reply.key_remap.mode2.remap_dst = io_input_remap[DINPUT_MODE].data[app_command->key_remap.mode2.remap_src];
-                                                       app_reply.cmd.status = REPLY_STATUS_OK;
-                                               }
+//                                             if(app_command->key_remap.mode2.remap_src >= 40 && app_command->key_remap.mode2.remap_src <= 75)
+//                                             {
+//                                                     app_reply.key_remap.mode2.remap_dst = 0;
+//                                                     app_reply.cmd.status = REPLY_STATUS_FAIL;
+//                                             }
+//                                             else
+//                                             {
+//                                                     app_reply.key_remap.mode2.remap_dst = io_input_remap[DINPUT_MODE].data[app_command->key_remap.mode2.remap_src];
+//                                                     app_reply.cmd.status = REPLY_STATUS_OK;
+//                                             }
+                                               app_reply.key_remap.mode2.remap_dst = io_input_remap[DINPUT_MODE].data[app_command->key_remap.mode2.remap_src];
+                                               app_reply.cmd.status = REPLY_STATUS_OK;
                                        }
                                }
                                else if(app_command->key_remap.read_write == USB_COMM_WRITE)
@@ -2549,41 +2562,68 @@ void App_Comm_Handle(uint8_t* data, uint8_t size)
                                        if(app_command->key_remap.mode == 0)
                                        {
                                                app_reply.key_remap.mode1.sub_packet = app_command->key_remap.mode1.sub_packet;
+                                               app_reply.cmd.status = REPLY_STATUS_OK;
                                                if(app_command->key_remap.mode1.sub_packet == 0)
                                                {
                                                        for(uint8_t i=0;i<40;i++)
                                                        {
-                                                               if(app_command->key_remap.mode1.remapable_key.remap_dst[i] != 0)
+                                                               if(app_command->key_remap.mode1.remapable_key_0.remap_dst[i] != 0)
                                                                {
-                                                                       io_input_remap[DINPUT_MODE].data[i] = app_command->key_remap.mode1.remapable_key.remap_dst[i];
+                                                                       io_input_remap[DINPUT_MODE].data[i] = app_command->key_remap.mode1.remapable_key_0.remap_dst[i];
                                                                }
-                                                               app_reply.key_remap.mode1.remapable_key.remap_dst[i] = io_input_remap[DINPUT_MODE].data[i];
+                                                               app_reply.key_remap.mode1.remapable_key_0.remap_dst[i] = io_input_remap[DINPUT_MODE].data[i];
                                                        }
                                                        
                                                        for(uint8_t i=40;i<42;i++)
                                                        {
-                                                               if(app_command->key_remap.mode1.remapable_key.remap_dst[i] != 0)
+                                                               if(app_command->key_remap.mode1.remapable_key_0.remap_dst[i] != 0)
                                                                {
-                                                                       io_input_remap[DINPUT_MODE].data[i+36] = app_command->key_remap.mode1.remapable_key.remap_dst[i];
+                                                                       io_input_remap[DINPUT_MODE].data[i+36] = app_command->key_remap.mode1.remapable_key_0.remap_dst[i];
                                                                }
-                                                               app_reply.key_remap.mode1.remapable_key.remap_dst[i] = io_input_remap[DINPUT_MODE].data[i+36];
+                                                               app_reply.key_remap.mode1.remapable_key_0.remap_dst[i] = io_input_remap[DINPUT_MODE].data[i+36];
                                                        }
-                                                       app_reply.cmd.status = REPLY_STATUS_OK;
+                                                       Flash_Write_Query_Add(FLASH_INPUT_REMAP_ADDR, FLASH_INPUT_REMAP_FLAG, (uint8_t*)&io_input_remap, sizeof(IO_INPUT_REMAP_T)*3, 1);
+                                                       
+                                               }
+                                               else if(app_command->key_remap.mode1.sub_packet == 1)
+                                               {
+                                                       for(uint8_t i=0;i<sizeof(IO_REMAPABLE_KEY_1_T);i++)
+                                                       {
+                                                               if(app_command->key_remap.mode1.remapable_key_1.remap_dst[i] != 0)
+                                                               {
+                                                                       io_input_remap[DINPUT_MODE].data[offsetofstruct(IO_INPUT_REMAP_T, abs_enc1_cnt1) + i] = app_command->key_remap.mode1.remapable_key_1.remap_dst[i];
+                                                               }
+                                                               app_reply.key_remap.mode1.remapable_key_1.remap_dst[i] = io_input_remap[DINPUT_MODE].data[offsetofstruct(IO_INPUT_REMAP_T, abs_enc1_cnt1) + i];
+                                                       }
+                                                       Flash_Write_Query_Add(FLASH_INPUT_REMAP_ADDR, FLASH_INPUT_REMAP_FLAG, (uint8_t*)&io_input_remap, sizeof(IO_INPUT_REMAP_T)*3, 1);
+                                               }
+                                               else
+                                               {
+                                                       app_reply.cmd.status = REPLY_STATUS_NO_CMD;
                                                }
+                                               
                                        }
                                        else if(app_command->key_remap.mode == 1)
                                        {
-                                               if(app_command->key_remap.mode2.remap_src >= 40 && app_command->key_remap.mode2.remap_src <= 75)
-                                               {
-                                                       app_reply.cmd.status = REPLY_STATUS_FAIL;
-                                               }
-                                               else if(app_command->key_remap.mode2.remap_src && app_command->key_remap.mode2.remap_dst != 0)
+//                                             if(app_command->key_remap.mode2.remap_src >= 40 && app_command->key_remap.mode2.remap_src <= 75)
+//                                             {
+//                                                     app_reply.cmd.status = REPLY_STATUS_FAIL;
+//                                             }
+//                                             else 
+                                               if(app_command->key_remap.mode2.remap_src < sizeof(IO_INPUT_REMAP_T) && app_command->key_remap.mode2.remap_dst != 0)
                                                {
                                                        io_input_remap[DINPUT_MODE].data[app_command->key_remap.mode2.remap_src] = app_command->key_remap.mode2.remap_dst;
                                                        app_reply.cmd.status = REPLY_STATUS_OK;
+                                                       Flash_Write_Query_Add(FLASH_INPUT_REMAP_ADDR, FLASH_INPUT_REMAP_FLAG, (uint8_t*)&io_input_remap, sizeof(IO_INPUT_REMAP_T)*3, 1);
+                                               }
+                                               else
+                                               {
+                                                       app_reply.cmd.status = REPLY_STATUS_FAIL;
                                                }
                                                app_reply.key_remap.mode2.remap_src = app_command->key_remap.mode2.remap_src;
                                                app_reply.key_remap.mode2.remap_dst = app_command->key_remap.mode2.remap_dst;
+                                               
+                                               
                                        }
                                        else
                                        {
index 72dd086..17e4a64 100644 (file)
@@ -166,7 +166,7 @@ uint8_t got_heartbeat_flag = 0;
 
 void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
 {
-       if(data[1] != 0xE0)
+       if(data[1] != 0xE0 && data[1] != 0xB7)
        {
                DUG_PRINTF("IOT: ");
                for(uint8_t i=0;i<10;i++)
@@ -182,7 +182,7 @@ void Iot_Uart_Rx_Handle(uint8_t *data ,uint8_t len)
        }
     if(len >= 4 && len <= IOT_UART_BUFFER_MAX && data[0] == FRAMEHEAD_IOT_TO_PANEL && Crc8_ROHC_Cal(&data[1], len-2) == data[len-1])
     {
-               DUG_PRINTF("recv:%02x\n", data[1]);
+//             DUG_PRINTF("recv:%02x\n", data[1]);
         switch (data[1])
         {
             case 0x00:
@@ -393,11 +393,11 @@ void Iot_OneTimerSecond(void)
        if(systicks - timerSecond >= ONE_TIMER_SECOND)
        {
                timerSecond= systicks;
-               if(powerOn_count <= 10)
+               if(powerOn_count <= 15)
                {
                        powerOn_count++;
 //                     DUG_PRINTF("iot got_heartbeat_flag:%d",got_heartbeat_flag);
-                       if(powerOn_count == 10 && got_heartbeat_flag >= 3) //¿ª»ú10¼ì²éÒ»´ÎÊÇ·ñÐèÒª·¢ËÍmcuÐÅÏ¢
+                       if(powerOn_count % 5 == 0 && got_heartbeat_flag >= 3) //¿ª»ú10¼ì²éÒ»´ÎÊÇ·ñÐèÒª·¢ËÍmcuÐÅÏ¢
                        {
                          Iot_Send_Mcu_Info();
                          Iot_Uart_Tx_Query_Add(0x0A, NULL, 0);
@@ -467,7 +467,7 @@ void Iot_Uart_Tx_Query_Process(void)
 //                     DUG_PRINTF("iot_uart_tx_query[0].size %d\n",iot_uart_tx_query[0].size);
 #if (1)
 //                             DUG_PRINTF("iot iot_uart_tx_query[0].size£º%d\n",iot_uart_tx_query[0].size);
-                               if(iot_uart_tx_query[0].buffer[0] != 0xb7 || iot_uart_tx_query[0].buffer[0] != 0xe0  ){
+                               if(iot_uart_tx_query[0].buffer[0] != 0xb7 && iot_uart_tx_query[0].buffer[0] != 0xe0  ){
                                        DUG_PRINTF("iot send:\n");
 //                                     for(uint8_t i=0;i<iot_uart_tx_query[0].size;i++)
 //                                     {
@@ -2795,7 +2795,7 @@ uint8_t Iot_Write_Object(uint16_t dp_id, void* buf, uint8_t len)
 //                                             user_io_setting.race_telemetry_config.unit[i].key,user_io_setting.race_telemetry_config.unit[i].enc);
 //                                     
 //                                     }
-                                       DUG_PRINTF("data %d dp_id:%d\n",*((uint8_t*)dp_object[dp_id].object),dp_id);
+                                       DUG_PRINTF("dp_id %d abs_enc1_cnt1:%d %d %d %d\n",*((uint8_t*)dp_object[dp_id].object),dp_id,io_input_remap[0].abs_enc1_cnt1,io_input_remap[0].abs_enc1_cnt2,io_input_remap[0].abs_enc1_cnt3,io_input_remap[0].abs_enc1_cnt4);
                                        if(dp_id == 746)
                                        {
                                                *(uint8_t *)dp_object[747].object = (uint8_t)input;
index 40013bd..220fa64 100644 (file)
@@ -137,7 +137,7 @@ void SysTick_Handler(void)
 void Systick_Delay_Ms(uint32_t ms)
 {
        volatile uint32_t tick = systicks;
-       while(systicks - tick < ms);
+       while(systicks - tick < (ms*10));
 }