|
|
@ -4,12 +4,8 @@ |
|
|
|
#include "zport.h" |
|
|
|
#include "udpclient.h" |
|
|
|
|
|
|
|
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 bool camera_encoder_light_state; |
|
|
|
static bool driven_encoder_light_state; |
|
|
|
|
|
|
|
static encoder_t m_encoders[] = { |
|
|
|
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2, 0, 0}, // 相机编码器 |
|
|
@ -40,9 +36,13 @@ void encoder_all_clear_counter(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void encoder_switch_clear_counter(encoder_usage_t encoder) |
|
|
|
{ |
|
|
|
m_encoders[encoder].count = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value) |
|
|
|
{ |
|
|
|
bool get_encoder_value_flag = false; |
|
|
|
switch (encoder) |
|
|
|
{ |
|
|
|
case CAMERA_ENCODER: |
|
|
@ -70,33 +70,29 @@ void encoder_light_schedule(void) |
|
|
|
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) |
|
|
|
void encoder_light_switch_set_color(encoder_usage_t encoder, encoder_light_color_table_t color) |
|
|
|
{ |
|
|
|
uint16_t count; |
|
|
|
if (encoder == CAMERA_ENCODER) |
|
|
|
{ |
|
|
|
switch (color) |
|
|
|
{ |
|
|
|
case ENCODER_LIGHT_COLOR_RED: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 红色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_RESET); |
|
|
|
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET); |
|
|
|
break; |
|
|
|
case ENCODER_LIGHT_COLOR_GREEN: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 绿色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_RESET); |
|
|
|
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET); |
|
|
|
break; |
|
|
|
case ENCODER_LIGHT_COLOR_BLUE: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 蓝色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_RESET); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
@ -109,25 +105,22 @@ void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, enco |
|
|
|
switch (color) |
|
|
|
{ |
|
|
|
case ENCODER_LIGHT_COLOR_RED: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 红色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_RESET); |
|
|
|
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET); |
|
|
|
break; |
|
|
|
case ENCODER_LIGHT_COLOR_GREEN: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 绿色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_RESET); |
|
|
|
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET); |
|
|
|
break; |
|
|
|
case ENCODER_LIGHT_COLOR_BLUE: |
|
|
|
count = (1 - brightness / 65535.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); |
|
|
|
/* 蓝色 */ |
|
|
|
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_RESET); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
@ -145,47 +138,15 @@ 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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void encoder_switch_toggle_on_off_state(encoder_usage_t encoder) |
|
|
|
{ |
|
|
|
if (encoder == CAMERA_ENCODER) |
|
|
|
{ |
|
|
|
if (camera_encoder_light_state) |
|
|
|
{ |
|
|
|
encoder_switch_close_light(CAMERA_ENCODER); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness); |
|
|
|
} |
|
|
|
camera_encoder_light_state = !camera_encoder_light_state; |
|
|
|
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET); |
|
|
|
} |
|
|
|
else if (encoder == DRIVEN_ENCODER_GEAR) |
|
|
|
{ |
|
|
|
if (driven_encoder_light_state) |
|
|
|
{ |
|
|
|
encoder_switch_close_light(DRIVEN_ENCODER_GEAR); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness); |
|
|
|
} |
|
|
|
driven_encoder_light_state = !driven_encoder_light_state; |
|
|
|
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET); |
|
|
|
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|