Browse Source

编码器灯管调度函数完成

tags/修改需求前并且硬件测试除rs485都通过的版本
tianjialong 2 years ago
parent
commit
5439b30366
  1. 6
      MDK-ARM/LWIP.uvguix.29643
  2. 50
      usersrc/encoder.c
  3. 1
      usersrc/encoder.h
  4. 5
      usersrc/usermain.c

6
MDK-ARM/LWIP.uvguix.29643

@ -3633,9 +3633,9 @@
</Doc>
<Doc>
<Name>..\usersrc\encoder.c</Name>
<ColumnNumber>0</ColumnNumber>
<TopLine>172</TopLine>
<CurrentLine>173</CurrentLine>
<ColumnNumber>13</ColumnNumber>
<TopLine>9</TopLine>
<CurrentLine>12</CurrentLine>
<Folding>1</Folding>
<ContractedFolders></ContractedFolders>
<PaneID>0</PaneID>

50
usersrc/encoder.c

@ -7,7 +7,7 @@
static encoder_light_state_t camera_encoder_state = STANDBY;
static encoder_light_state_t driven_encoder_gear_state = STANDBY;
static uint32_t camera_encoder_lastprocess = 0;
// static uint32_t driven_encoder_gear_lastprocess = 0;
static uint32_t driven_encoder_gear_lastprocess = 0;
static encoder_t m_uarts[] = {
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2}, //
@ -76,21 +76,39 @@ bool encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value)
void encoder_light_schedule(void)
{
static bool camera_encoder_light_state;
static bool driven_encoder_light_state;
if (camera_encoder_state == STANDBY)
{
if (sys_haspassedms(camera_encoder_lastprocess) > 500)
{
camera_encoder_lastprocess = HAL_GetTick();
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin);
if (camera_encoder_light_state)
{
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness);
}
else
{
encoder_switch_close_light(CAMERA_ENCODER);
}
camera_encoder_light_state = !camera_encoder_light_state;
}
}
if (driven_encoder_gear_state == STANDBY)
{
if (sys_haspassedms(camera_encoder_lastprocess) > 500)
if (sys_haspassedms(driven_encoder_gear_lastprocess) > 500)
{
// driven_encoder_gear_lastprocess = HAL_GetTick();
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin);
driven_encoder_gear_lastprocess = HAL_GetTick();
if (driven_encoder_light_state)
{
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness);
}
else
{
encoder_switch_close_light(DRIVEN_ENCODER_GEAR);
}
driven_encoder_light_state = !driven_encoder_light_state;
}
}
}
@ -117,7 +135,7 @@ void encoder_set_state(encoder_usage_t encoder, encoder_light_state_t state)
driven_encoder_gear_state = state;
if (state == STANDBY)
{
// driven_encoder_gear_lastprocess = HAL_GetTick();
driven_encoder_gear_lastprocess = HAL_GetTick();
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin);
}
else if (state == WORKING)
@ -245,3 +263,23 @@ void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, enco
// error
}
}
void encoder_switch_close_light(encoder_usage_t encoder)
{
if (encoder == CAMERA_ENCODER)
{
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
}
else if (encoder == DRIVEN_ENCODER_GEAR)
{
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4);
}
else
{
// error
}
}

1
usersrc/encoder.h

@ -42,3 +42,4 @@ encoder_light_state_t encoder_get_state(encoder_usage_t encoder);
void encoder_all_encoder_clear_counter_and_structer_count(void);
void encoder_switch_encoder_clear_count_and_structer_count(encoder_usage_t encoder);
void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, encoder_light_color_table_t color, uint16_t brightness);
void encoder_switch_close_light(encoder_usage_t encoder);

5
usersrc/usermain.c

@ -108,9 +108,6 @@ void user_main()
zkey_init(&s_key_module);
port_uart_start_all_uart_receive();
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED, encoder_light_max_brightness);
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN, encoder_light_max_brightness);
while (1)
{
udp_client_genlock_and_esync_active();
@ -118,7 +115,7 @@ void user_main()
zkey_schedule();
udp_client_recv();
at_cmd_processer_try_process_data();
// encoder_light_schedule();
encoder_light_schedule();
port_do_debug_light_state();
osDelay(1);

Loading…
Cancel
Save