Browse Source

新增编码器数据更新,状态灯闪烁功能

new_pcb
tianjialong 2 years ago
parent
commit
ecb163227f
  1. 4
      MDK-ARM/LWIP.uvguix.29643
  2. 39
      usersrc/encoder.c
  3. 2
      usersrc/encoder.h
  4. 10
      usersrc/usermain.c

4
MDK-ARM/LWIP.uvguix.29643
File diff suppressed because it is too large
View File

39
usersrc/encoder.c

@ -38,6 +38,7 @@ void encoder_all_clear_counter(void)
void encoder_switch_clear_counter(encoder_usage_t encoder) void encoder_switch_clear_counter(encoder_usage_t encoder)
{ {
/* 需要注意别传入ENCODER_NUMBER,否则数组越界 */
m_encoders[encoder].count = 0; 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;
}
}
}
} }
/* /*

2
usersrc/encoder.h

@ -29,7 +29,7 @@ void encoder_all_stop(void);
void encoder_all_clear_counter(void); void encoder_all_clear_counter(void);
void encoder_switch_clear_counter(encoder_usage_t encoder); void encoder_switch_clear_counter(encoder_usage_t encoder);
void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value); 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_light_switch_set_color(encoder_usage_t encoder, encoder_light_color_table_t color);
void encoder_switch_close_light(encoder_usage_t encoder); void encoder_switch_close_light(encoder_usage_t encoder);
encoder_t *encoder_get_camera_encoder_structer(void); encoder_t *encoder_get_camera_encoder_structer(void);

10
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 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 void zkey_schedule()
{ {
static uint32_t lastprocess_key_ticket; 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(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN);
encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, 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) void netif_link_down_user_func(void)
{ {
encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED); encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED);
encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, 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) 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()->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; 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); 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()->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; 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(); zkey_schedule();
udp_client_recv(); udp_client_recv();
at_cmd_processer_try_process_data(); 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(); port_do_debug_light_state();
osDelay(1); osDelay(1);
} }

Loading…
Cancel
Save