|
@ -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,20 +76,20 @@ bool encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value) |
|
|
|
|
|
|
|
|
void encoder_light_schedule(void) |
|
|
void encoder_light_schedule(void) |
|
|
{ |
|
|
{ |
|
|
// if (camera_encoder_state == STANDBY) |
|
|
|
|
|
// { |
|
|
|
|
|
// if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
|
|
|
// { |
|
|
|
|
|
// camera_encoder_lastprocess = HAL_GetTick(); |
|
|
|
|
|
|
|
|
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); |
|
|
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (driven_encoder_gear_state == STANDBY) |
|
|
if (driven_encoder_gear_state == STANDBY) |
|
|
{ |
|
|
{ |
|
|
if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
{ |
|
|
{ |
|
|
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); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -117,7 +117,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) |
|
@ -165,3 +165,83 @@ void encoder_switch_encoder_clear_count_and_structer_count(encoder_usage_t encod |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
R1:tim2-->TIM_CHANNEL_4 |
|
|
|
|
|
G1:tim2-->TIM_CHANNEL_1 |
|
|
|
|
|
B1:tim3-->TIM_CHANNEL_1 |
|
|
|
|
|
|
|
|
|
|
|
R2:tim2-->TIM_CHANNEL_3 |
|
|
|
|
|
G2:tim4-->TIM_CHANNEL_3 |
|
|
|
|
|
B2:tim4-->TIM_CHANNEL_4 |
|
|
|
|
|
*/ |
|
|
|
|
|
void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, encoder_light_color_table_t color, uint16_t brightness) |
|
|
|
|
|
{ |
|
|
|
|
|
uint16_t count; |
|
|
|
|
|
if (encoder == CAMERA_ENCODER) |
|
|
|
|
|
{ |
|
|
|
|
|
switch (color) |
|
|
|
|
|
{ |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_RED: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim2); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, count); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); |
|
|
|
|
|
break; |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_GREEN: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim2); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, count); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); |
|
|
|
|
|
break; |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_BLUE: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim3); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, count); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
/* not find color */ |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (encoder == DRIVEN_ENCODER_GEAR) |
|
|
|
|
|
{ |
|
|
|
|
|
switch (color) |
|
|
|
|
|
{ |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_RED: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim2); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, count); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4); |
|
|
|
|
|
break; |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_GREEN: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim4); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, count); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4); |
|
|
|
|
|
break; |
|
|
|
|
|
case ENCODER_LIGHT_COLOR_BLUE: |
|
|
|
|
|
count = (1 - brightness / 1000.0) * __HAL_TIM_GET_AUTORELOAD(&htim4); |
|
|
|
|
|
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, count); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); |
|
|
|
|
|
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
/* not find color */ |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
// error |
|
|
|
|
|
} |
|
|
|
|
|
} |