From ecb163227ff519b1b85985b2ee518963fb6aeed6 Mon Sep 17 00:00:00 2001 From: tianjialong Date: Mon, 20 Mar 2023 10:42:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BC=96=E7=A0=81=E5=99=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9B=B4=E6=96=B0=EF=BC=8C=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=81=AF=E9=97=AA=E7=83=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/LWIP.uvguix.29643 | 4 ++-- usersrc/encoder.c | 39 ++++++++++++++++++++++++++++++++++++++- usersrc/encoder.h | 2 +- usersrc/usermain.c | 10 +++++++++- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/MDK-ARM/LWIP.uvguix.29643 b/MDK-ARM/LWIP.uvguix.29643 index e80f77b..60723ee 100644 --- a/MDK-ARM/LWIP.uvguix.29643 +++ b/MDK-ARM/LWIP.uvguix.29643 @@ -1806,7 +1806,7 @@ File 2537 - 00200000010000002800FFFF01001100434D4643546F6F6C426172427574746F6E00E100000000000000000000000000000000000000000000000100000001000000018001E100000000000001000000000000000000000000000000000100000001000000018003E1000000000000020000000000000000000000000000000001000000010000000180CD7F0000000000000300000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018023E100000000040004000000000000000000000000000000000100000001000000018022E100000000040005000000000000000000000000000000000100000001000000018025E10000000000000600000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001802BE10000000000000700000000000000000000000000000000010000000100000001802CE10000000004000800000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001807A8A0000000000000900000000000000000000000000000000010000000100000001807B8A0000000004000A00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180D3B00000000000000B000000000000000000000000000000000100000001000000018015B10000000004000C0000000000000000000000000000000001000000010000000180F4B00000000004000D000000000000000000000000000000000100000001000000018036B10000000004000E00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FF88000000000400460000000000000000000000000000000001000000010000000180FE880000000004004500000000000000000000000000000000010000000100000001800B810000000004001300000000000000000000000000000000010000000100000001800C810000000004001400000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180F0880000020000000F000000000000000000000000000000000100000001000000FFFF0100120043555646696E64436F6D626F427574746F6EE803000000000000000000000000000000000000000000000001000000010000009600000002002050FFFFFFFF0096000000000000000000018024E10000000000001100000000000000000000000000000000010000000100000001800A810000000000001200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E2280000002000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B46350000000000000000000000000100000001000000000000000000000001000000020021802280000000000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B4635000000000000000000000000010000000100000000000000000000000100000000002180E0010000000000007500000021456E65726779204D6561737572656D656E742026776974686F75742044656275670000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C488000000000000160000000000000000000000000000000001000000010000000180C988000000000400180000000000000000000000000000000001000000010000000180C788000000000000190000000000000000000000000000000001000000010000002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000003002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000000002180E50100000000000078000000264B696C6C20416C6C20427265616B706F696E747320696E204163746976652050726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180E601000000000000790000002F4B696C6C20416C6C20427265616B706F696E747320696E204D756C74692D50726F6A65637420576F726B73706163650000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000021804C010000020001001A0000000F2650726F6A6563742057696E646F77000000000000000000000000010000000100000000000000000000000100000008002180DD880000000000001A0000000750726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180DC8B0000000000003A00000005426F6F6B73000000000000000000000000010000000100000000000000000000000100000000002180E18B0000000000003B0000000946756E6374696F6E73000000000000000000000000010000000100000000000000000000000100000000002180E28B000000000000400000000954656D706C6174657300000000000000000000000001000000010000000000000000000000010000000000218018890000000000003D0000000E536F757263652042726F777365720000000000000000000000000100000001000000000000000000000001000000000021800000000000000400FFFFFFFF00000000000000000001000000000000000100000000000000000000000100000000002180D988000000000000390000000C4275696C64204F7574707574000000000000000000000000010000000100000000000000000000000100000000002180E38B000000000000410000000B46696E64204F75747075740000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FB7F0000000000001B000000000000000000000000000000000100000001000000000000000446696C65C6030000 + 00200000010000002800FFFF01001100434D4643546F6F6C426172427574746F6E00E100000000000000000000000000000000000000000000000100000001000000018001E100000000000001000000000000000000000000000000000100000001000000018003E1000000000000020000000000000000000000000000000001000000010000000180CD7F0000000000000300000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000018023E100000000040004000000000000000000000000000000000100000001000000018022E100000000040005000000000000000000000000000000000100000001000000018025E10000000000000600000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001802BE10000000004000700000000000000000000000000000000010000000100000001802CE10000000004000800000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001807A8A0000000000000900000000000000000000000000000000010000000100000001807B8A0000000004000A00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180D3B00000000000000B000000000000000000000000000000000100000001000000018015B10000000004000C0000000000000000000000000000000001000000010000000180F4B00000000004000D000000000000000000000000000000000100000001000000018036B10000000004000E00000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FF88000000000400460000000000000000000000000000000001000000010000000180FE880000000004004500000000000000000000000000000000010000000100000001800B810000000004001300000000000000000000000000000000010000000100000001800C810000000004001400000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180F0880000020000000F000000000000000000000000000000000100000001000000FFFF0100120043555646696E64436F6D626F427574746F6EE803000000000000000000000000000000000000000000000001000000010000009600000002002050FFFFFFFF0096000000000000000000018024E10000000000001100000000000000000000000000000000010000000100000001800A810000000000001200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6E2280000002000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B46350000000000000000000000000100000001000000000000000000000001000000020021802280000000000000150000002153746172742F53746F70202644656275672053657373696F6E094374726C2B4635000000000000000000000000010000000100000000000000000000000100000000002180E0010000000000007500000021456E65726779204D6561737572656D656E742026776974686F75742044656275670000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C488000000000000160000000000000000000000000000000001000000010000000180C988000000000400180000000000000000000000000000000001000000010000000180C788000000000000190000000000000000000000000000000001000000010000002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000003002180C8880000000000001700000027264B696C6C20416C6C20427265616B706F696E747320696E2043757272656E7420546172676574000000000000000000000000010000000100000000000000000000000100000000002180E50100000000000078000000264B696C6C20416C6C20427265616B706F696E747320696E204163746976652050726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180E601000000000000790000002F4B696C6C20416C6C20427265616B706F696E747320696E204D756C74692D50726F6A65637420576F726B73706163650000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000021804C010000020001001A0000000F2650726F6A6563742057696E646F77000000000000000000000000010000000100000000000000000000000100000008002180DD880000000000001A0000000750726F6A656374000000000000000000000000010000000100000000000000000000000100000000002180DC8B0000000000003A00000005426F6F6B73000000000000000000000000010000000100000000000000000000000100000000002180E18B0000000000003B0000000946756E6374696F6E73000000000000000000000000010000000100000000000000000000000100000000002180E28B000000000000400000000954656D706C6174657300000000000000000000000001000000010000000000000000000000010000000000218018890000000000003D0000000E536F757263652042726F777365720000000000000000000000000100000001000000000000000000000001000000000021800000000000000400FFFFFFFF00000000000000000001000000000000000100000000000000000000000100000000002180D988000000000000390000000C4275696C64204F7574707574000000000000000000000000010000000100000000000000000000000100000000002180E38B000000000000410000000B46696E64204F75747075740000000000000000000000000100000001000000000000000000000001000000000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180FB7F0000000000001B000000000000000000000000000000000100000001000000000000000446696C65C6030000 1423 @@ -3634,7 +3634,7 @@ ..\usersrc\encoder.c 0 - 6 + 1 7 1 diff --git a/usersrc/encoder.c b/usersrc/encoder.c index 70ff5a0..5888409 100644 --- a/usersrc/encoder.c +++ b/usersrc/encoder.c @@ -38,6 +38,7 @@ void encoder_all_clear_counter(void) void encoder_switch_clear_counter(encoder_usage_t encoder) { + /* 需要注意别传入ENCODER_NUMBER,否则数组越界 */ m_encoders[encoder].count = 0; } @@ -57,8 +58,44 @@ void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value) } } -void encoder_light_schedule(void) +void encoder_light_schedule(bool netif_link_status, bool *camera_encoder_flag, bool *driven_encoder_gear_flag) { + static uint8_t camera_encoder_light_flicker_count = 0; + static uint8_t driven_encoder_gear_light_flicker_count = 0; + if (netif_link_status) + { + if (*camera_encoder_flag) + { + if (sys_haspassedms(camera_encoder_lastprocess) > 100) + { + camera_encoder_lastprocess = HAL_GetTick(); + HAL_GPIO_TogglePin(DIS_G1_GPIO_Port, DIS_G1_Pin); + camera_encoder_light_flicker_count += 1; + } + if (camera_encoder_light_flicker_count > 6) + { + encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN); + camera_encoder_light_flicker_count = 0; + *camera_encoder_flag = false; + } + } + + if (*driven_encoder_gear_flag) + { + if (sys_haspassedms(driven_encoder_gear_lastprocess) > 100) + { + driven_encoder_gear_lastprocess = HAL_GetTick(); + HAL_GPIO_TogglePin(DIS_G2_GPIO_Port, DIS_G2_Pin); + driven_encoder_gear_light_flicker_count += 1; + } + if (driven_encoder_gear_light_flicker_count > 6) + { + encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN); + driven_encoder_gear_light_flicker_count = 0; + *driven_encoder_gear_flag = false; + } + } + } } /* diff --git a/usersrc/encoder.h b/usersrc/encoder.h index 92a93c1..7ba0ece 100644 --- a/usersrc/encoder.h +++ b/usersrc/encoder.h @@ -29,7 +29,7 @@ void encoder_all_stop(void); void encoder_all_clear_counter(void); void encoder_switch_clear_counter(encoder_usage_t encoder); void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value); -void encoder_light_schedule(void); +void encoder_light_schedule(bool netif_link_status, bool *camera_encoder_flag, bool *driven_encoder_gear_flag); void encoder_light_switch_set_color(encoder_usage_t encoder, encoder_light_color_table_t color); void encoder_switch_close_light(encoder_usage_t encoder); encoder_t *encoder_get_camera_encoder_structer(void); diff --git a/usersrc/usermain.c b/usersrc/usermain.c index f8fc2a2..09bc263 100644 --- a/usersrc/usermain.c +++ b/usersrc/usermain.c @@ -35,6 +35,10 @@ static zkey_module_t s_key_module = ZMODULE_INIT(s_keys, onkey); static uint16_t encoder_get_temp; +static bool netif_link_status; +static bool camera_encoder_raw_count_update_flag; +static bool driven_encoder_gear_raw_count_update_flag; + static void zkey_schedule() { static uint32_t lastprocess_key_ticket; @@ -118,12 +122,14 @@ void netif_link_up_user_func(void) { encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN); encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN); + netif_link_status = true; } void netif_link_down_user_func(void) { encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED); encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_RED); + netif_link_status = false; } static void encoder_get_and_calculation(void) @@ -133,6 +139,7 @@ static void encoder_get_and_calculation(void) { encoder_get_camera_encoder_structer()->count += compute_uint16_t_minus_the_numbers(encoder_get_temp, encoder_get_camera_encoder_structer()->last_count); encoder_get_camera_encoder_structer()->last_count = encoder_get_temp; + camera_encoder_raw_count_update_flag = true; } encoder_get_temp = __HAL_TIM_GET_COUNTER(encoder_get_driven_encoder_gear_structer()->tim_handler); @@ -140,6 +147,7 @@ static void encoder_get_and_calculation(void) { encoder_get_driven_encoder_gear_structer()->count += compute_uint16_t_minus_the_numbers(encoder_get_temp, encoder_get_driven_encoder_gear_structer()->last_count); encoder_get_driven_encoder_gear_structer()->last_count = encoder_get_temp; + driven_encoder_gear_raw_count_update_flag = true; } } @@ -167,7 +175,7 @@ void user_main() zkey_schedule(); udp_client_recv(); at_cmd_processer_try_process_data(); - encoder_light_schedule(); + encoder_light_schedule(netif_link_status, &camera_encoder_raw_count_update_flag, &driven_encoder_gear_raw_count_update_flag); port_do_debug_light_state(); osDelay(1); }