|
@ -7,7 +7,7 @@ |
|
|
static encoder_light_state_t camera_encoder_state = STANDBY; |
|
|
static encoder_light_state_t camera_encoder_state = STANDBY; |
|
|
static encoder_light_state_t driven_encoder_gear_state = STANDBY; |
|
|
static encoder_light_state_t driven_encoder_gear_state = STANDBY; |
|
|
static uint32_t camera_encoder_lastprocess = 0; |
|
|
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[] = { |
|
|
static encoder_t m_uarts[] = { |
|
|
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2}, // 相机编码器 |
|
|
{&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) |
|
|
void encoder_light_schedule(void) |
|
|
{ |
|
|
{ |
|
|
|
|
|
static bool camera_encoder_light_state; |
|
|
|
|
|
static bool driven_encoder_light_state; |
|
|
if (camera_encoder_state == STANDBY) |
|
|
if (camera_encoder_state == STANDBY) |
|
|
{ |
|
|
{ |
|
|
if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
{ |
|
|
{ |
|
|
camera_encoder_lastprocess = HAL_GetTick(); |
|
|
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 (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; |
|
|
driven_encoder_gear_state = state; |
|
|
if (state == STANDBY) |
|
|
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); |
|
|
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
} |
|
|
} |
|
|
else if (state == WORKING) |
|
|
else if (state == WORKING) |
|
@ -245,3 +263,23 @@ void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, enco |
|
|
// error |
|
|
// 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 |
|
|
|
|
|
} |
|
|
|
|
|
} |