|
|
@ -3,6 +3,11 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include "zport.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 encoder_t m_uarts[] = { |
|
|
|
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2}, // 相机编码器 |
|
|
|
{&driven_encoder_gear, TIM_CHANNEL_1 | TIM_CHANNEL_2} // 从动编码器 |
|
|
@ -68,10 +73,66 @@ bool encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value) |
|
|
|
|
|
|
|
void encoder_light_schedule(void) |
|
|
|
{ |
|
|
|
static uint32_t lastprocess = 0; |
|
|
|
if (sys_haspassedms(lastprocess) > 500) |
|
|
|
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 (driven_encoder_gear_state == STANDBY) |
|
|
|
{ |
|
|
|
if (sys_haspassedms(camera_encoder_lastprocess) > 500) |
|
|
|
{ |
|
|
|
driven_encoder_gear_lastprocess = HAL_GetTick(); |
|
|
|
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void encoder_set_state(encoder_usage_t encoder, encoder_light_state_t state) |
|
|
|
{ |
|
|
|
/* 主动上报的时候常亮,接收到触发指令直接翻转led,待机中0.5s周期闪烁 */ |
|
|
|
if (encoder == CAMERA_ENCODER) |
|
|
|
{ |
|
|
|
camera_encoder_state = state; |
|
|
|
if (state == STANDBY) |
|
|
|
{ |
|
|
|
camera_encoder_lastprocess = HAL_GetTick(); |
|
|
|
HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
|
} |
|
|
|
else if (state == WORKING) |
|
|
|
{ |
|
|
|
/* 如果工作状态的时候触发了genlock等,灯的状态不应该变成待机状态,只有同为待机的时候闪烁,上层写的时候需要加判断 */ |
|
|
|
HAL_GPIO_WritePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin, GPIO_PIN_RESET); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (encoder == DRIVEN_ENCODER_GEAR) |
|
|
|
{ |
|
|
|
driven_encoder_gear_state = state; |
|
|
|
if (state == STANDBY) |
|
|
|
{ |
|
|
|
driven_encoder_gear_lastprocess = HAL_GetTick(); |
|
|
|
// HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
|
} |
|
|
|
else if (state == WORKING) |
|
|
|
{ |
|
|
|
// HAL_GPIO_WritePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin, GPIO_PIN_SET); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
encoder_light_state_t encoder_get_state(encoder_usage_t encoder) |
|
|
|
{ |
|
|
|
if (encoder == CAMERA_ENCODER) |
|
|
|
{ |
|
|
|
return camera_encoder_state; |
|
|
|
} |
|
|
|
else if (encoder == DRIVEN_ENCODER_GEAR) |
|
|
|
{ |
|
|
|
lastprocess = HAL_GetTick(); |
|
|
|
HAL_GPIO_TogglePin(ENCODER_LIGHT_GPIO_Port, ENCODER_LIGHT_Pin); |
|
|
|
return driven_encoder_gear_state; |
|
|
|
} |
|
|
|
return ENCODER_STATE_NUMBER_AND_ERR_STATE; |
|
|
|
} |