增加编码器移动距离读取
This commit is contained in:
parent
dd006921d7
commit
8241229bb8
|
@ -44,6 +44,7 @@
|
|||
"user_lib.h": "c",
|
||||
"init.h": "c",
|
||||
"user_flash.h": "c",
|
||||
"uart_lcd.h": "c"
|
||||
"uart_lcd.h": "c",
|
||||
"linear_encoder.h": "c"
|
||||
}
|
||||
}
|
|
@ -34,6 +34,8 @@
|
|||
#include "tcpserverc.h"
|
||||
#include "lwip.h"
|
||||
#include "uart_lcd.h"
|
||||
#include "user_gpio.h"
|
||||
#include "linear_encoder.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -43,7 +45,7 @@
|
|||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
// extern UART_HandleTypeDef huart5;
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
@ -65,13 +67,6 @@ osThreadId ec11_taskHandle;
|
|||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
extern float current_buff[2];
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
extern uint8_t send_data_flag_cmd;
|
||||
ec11_t ec11_data = {0};
|
||||
uint8_t di_state_last[DI_MAX] = {0};
|
||||
uint8_t di_state_now[DI_MAX] = {0};
|
||||
int encode_direction = 0;
|
||||
int encode_num = 0;
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void start_tcp_task(void const *argument);
|
||||
|
@ -194,61 +189,8 @@ void start_led_toggle_task(void const *argument)
|
|||
for (;;)
|
||||
{
|
||||
HAL_GPIO_TogglePin(LED3_G_GPIO_Port, LED3_G_Pin);
|
||||
// 旋转编码器确认按键状态,并切换<E58887>?<3F>道和确认电流<E794B5>?<3F>输<EFBFBD>?????
|
||||
// if (uart_lcd_state.page_num == 0)
|
||||
{
|
||||
if (ec11_data.confirm_key_flag == 0)
|
||||
{
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 1) // 确认按键确认电流输出
|
||||
{
|
||||
ec11_data.confirm_key_flag_last++;
|
||||
if (ec11_data.confirm_key_flag_last > 2)
|
||||
{
|
||||
current_buff[0] = (float)uart_lcd_state.current_value[0];
|
||||
current_buff[1] = (float)uart_lcd_state.current_value[1];
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
}
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 2) // 切换通道按键确认状<E8AEA4>??
|
||||
{
|
||||
ec11_data.confirm_key_flag_last++;
|
||||
if (ec11_data.confirm_key_flag_last > 2)
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
uart_lcd_state.key_state[0] = 0;
|
||||
uart_lcd_state.key_state[1] = 1;
|
||||
uart_lcd_state.key_state[2] = 0;
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
uart_lcd_state.key_state[0] = 1;
|
||||
uart_lcd_state.key_state[1] = 0;
|
||||
uart_lcd_state.key_state[2] = 1;
|
||||
}
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
uart_lcd_channel_switch(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 3) // 切换界面
|
||||
{
|
||||
|
||||
if (uart_lcd_state.page_num == 0)
|
||||
{
|
||||
uart_lcd_state.page_num = 1;
|
||||
}
|
||||
else if (uart_lcd_state.page_num == 1)
|
||||
{
|
||||
uart_lcd_state.page_num = 0;
|
||||
}
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
uart_lcd_page_switch(uart_lcd_state.page_num);
|
||||
}
|
||||
}
|
||||
uart_lcd_ecll_control_current_out();
|
||||
vTaskDelay(500);
|
||||
}
|
||||
/* USER CODE END start_led_toggle_task */
|
||||
|
@ -297,17 +239,7 @@ void start_adc_task(void const *argument)
|
|||
{
|
||||
ad7124_get_analog(ch);
|
||||
}
|
||||
// HAL_GPIO_TogglePin(LED2_Y_GPIO_Port, LED2_Y_Pin);
|
||||
|
||||
/*姝ら儴鍒嗘槸鍥犱负閫氳杩囩▼涓細浜х敓閫氳涓柇骞舵棤娉曟仮澶嶇殑鎯呭喌*/
|
||||
if (huart5.RxState == HAL_UART_STATE_READY)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
|
||||
}
|
||||
if (huart2.RxState == HAL_UART_STATE_READY)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
|
||||
}
|
||||
communication_reset_hart();
|
||||
osThreadResume(dac_taskHandle);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
|
@ -327,36 +259,7 @@ void start_gpio_di_do_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
|
||||
uint8_t di_ch = 0;
|
||||
uint8_t tx_data_len = 7 + DI_MAX;
|
||||
uint8_t tx_data[32] = {0};
|
||||
tx_data[0] = FRAME_HEAD;
|
||||
tx_data[1] = COM_OK;
|
||||
tx_data[2] = DEVICE_NUM;
|
||||
tx_data[3] = SEND_STATE_CMD;
|
||||
tx_data[4] = DI_MAX;
|
||||
for (di_ch = 0; di_ch < DI_MAX; di_ch++)
|
||||
{
|
||||
di_state_now[di_ch] = gpio_di_test(di_ch);
|
||||
if (di_state_last[di_ch] != di_state_now[di_ch])
|
||||
{
|
||||
di_state_last[di_ch] = di_state_now[di_ch];
|
||||
send_data_flag_cmd = 1;
|
||||
}
|
||||
tx_data[5 + di_ch] = di_state_now[di_ch];
|
||||
}
|
||||
if ((send_data_flag_cmd != 0) && (1 == tcp_echo_flags_control))
|
||||
{
|
||||
tx_data[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 寮傛垨鏍¢獙
|
||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 甯у熬
|
||||
user_send_data_control(tx_data, tx_data_len);
|
||||
send_data_flag_cmd++;
|
||||
if (send_data_flag_cmd > 3) // 杩炵画涓夋涓婁綅鏈烘病鏈夊洖搴旓紝鍒欏仠姝㈠彂閫佹暟鎹寘
|
||||
{
|
||||
send_data_flag_cmd = 0;
|
||||
}
|
||||
}
|
||||
user_gpio_trigger();
|
||||
vTaskDelay(100);
|
||||
}
|
||||
/* USER CODE END start_gpio_di_do_task */
|
||||
|
@ -375,63 +278,8 @@ void start_ec11_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
encode_direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim8);
|
||||
encode_num = (short)__HAL_TIM_GET_COUNTER(&htim8);
|
||||
// 旋转编码器调节电流<E794B5>?<3F>画面显<E99DA2>?????
|
||||
if (uart_lcd_state.page_num == 0)
|
||||
{
|
||||
ec11_data.direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim1);
|
||||
ec11_data.encode_num = (short)__HAL_TIM_GET_COUNTER(&htim1);
|
||||
|
||||
if ((ec11_data.direction == 0) && (ec11_data.encode_num > ec11_data.encode_num_last))
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
uart_lcd_state.current_value[0] += 1;
|
||||
if (uart_lcd_state.current_value[0] > 20)
|
||||
{
|
||||
uart_lcd_state.current_value[0] = 20;
|
||||
}
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
uart_lcd_state.current_value[1] += 1;
|
||||
if (uart_lcd_state.current_value[1] > 20)
|
||||
{
|
||||
uart_lcd_state.current_value[1] = 20;
|
||||
}
|
||||
}
|
||||
uart_lcd_current_out(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
if ((ec11_data.direction == 1) && (ec11_data.encode_num < ec11_data.encode_num_last))
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
if (uart_lcd_state.current_value[0] < 2)
|
||||
{
|
||||
uart_lcd_state.current_value[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uart_lcd_state.current_value[0] -= 1;
|
||||
}
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
if (uart_lcd_state.current_value[1] < 2)
|
||||
{
|
||||
uart_lcd_state.current_value[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uart_lcd_state.current_value[1] -= 1;
|
||||
}
|
||||
}
|
||||
uart_lcd_current_out(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
|
||||
ec11_data.encode_num_last = ec11_data.encode_num;
|
||||
}
|
||||
linear_encoder_get_data();
|
||||
uart_lcd_ec11_control_current();
|
||||
vTaskDelay(100);
|
||||
}
|
||||
/* USER CODE END start_ec11_task */
|
||||
|
|
Binary file not shown.
|
@ -320,6 +320,11 @@
|
|||
<WinNumber>1</WinNumber>
|
||||
<ItemText>encode_num,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>34</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>linear_enc</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
|
@ -1943,7 +1948,7 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>User/board</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -1959,6 +1964,18 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>126</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\board\src\linear_encoder.c</PathWithFileName>
|
||||
<FilenameWithoutPath>linear_encoder.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -1969,7 +1986,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>126</FileNumber>
|
||||
<FileNumber>127</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1981,9 +1998,9 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>127</FileNumber>
|
||||
<FileNumber>128</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\application\src\communication_protocol.c</PathWithFileName>
|
||||
|
@ -1993,7 +2010,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>128</FileNumber>
|
||||
<FileNumber>129</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2005,7 +2022,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>129</FileNumber>
|
||||
<FileNumber>130</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2017,7 +2034,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>130</FileNumber>
|
||||
<FileNumber>131</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2037,7 +2054,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>131</FileNumber>
|
||||
<FileNumber>132</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2049,7 +2066,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>132</FileNumber>
|
||||
<FileNumber>133</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2061,7 +2078,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>133</FileNumber>
|
||||
<FileNumber>134</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2073,7 +2090,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>134</FileNumber>
|
||||
<FileNumber>135</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2093,7 +2110,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>135</FileNumber>
|
||||
<FileNumber>136</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2105,7 +2122,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>136</FileNumber>
|
||||
<FileNumber>137</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -2117,7 +2134,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>137</FileNumber>
|
||||
<FileNumber>138</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -1053,6 +1053,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\User\board\src\leds.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>linear_encoder.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\User\board\src\linear_encoder.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,16 +3,28 @@
|
|||
|
||||
#include "user_lib.h"
|
||||
|
||||
#define COM_ERROR_CODE_SIZE 7 // 通信错误返回帧长度
|
||||
#define COM_AI_DATA_SIZE 11 // 模拟量数据返回帧长度
|
||||
#define FRAME_HEAD 0xAA // 帧头
|
||||
#define FRAME_TAIL 0x3C // 帧尾
|
||||
#define DEVICE_NUM 0x00 // 设备号
|
||||
#define READ_ANALOG_CMD 0x00 // 读模拟量命令
|
||||
#define WRITE_ANALOG_CMD 0x01 // 写模拟量命令
|
||||
#define READ_DIGITAL_CMD 0x02 // 读数字量命令
|
||||
#define WRITE_DIGITAL_CMD 0x03 // 写数字量命令
|
||||
#define SEND_STATE_CMD 0x04 // 主动上发状态命令
|
||||
#define COM_ERROR_CODE_SIZE 7 // 通信错误返回帧长度
|
||||
#define COM_AI_DATA_SIZE 11 // 模拟量数据返回帧长度
|
||||
#define COM_ENCODER_DATA_SIZE 12 // 模拟量数据返回帧长度
|
||||
#define FRAME_HEAD 0xAA // 帧头
|
||||
#define FRAME_TAIL 0x3C // 帧尾
|
||||
#define DEVICE_NUM 0x00 // 设备号
|
||||
|
||||
typedef enum
|
||||
{
|
||||
READ_ANALOG_CMD = 0x00, // 读模拟量命令
|
||||
WRITE_ANALOG_CMD, // 写模拟量命令
|
||||
READ_DIGITAL_CMD, // 读数字量命令
|
||||
WRITE_DIGITAL_CMD, // 写数字量命令
|
||||
SEND_STATE_CMD, // 主动上发状态命令
|
||||
READ_ENCODER_CMD, // 读编码器命令
|
||||
} communication_cmd_e;
|
||||
// #define READ_ANALOG_CMD 0x00 // 读模拟量命令
|
||||
// #define WRITE_ANALOG_CMD 0x01 // 写模拟量命令
|
||||
// #define READ_DIGITAL_CMD 0x02 // 读数字量命令
|
||||
// #define WRITE_DIGITAL_CMD 0x03 // 写数字量命令
|
||||
// #define SEND_STATE_CMD 0x04 // 主动上发状态命令
|
||||
// #define READ_ENCODER_CMD 0x05 // 读编码器命令
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -47,6 +59,11 @@ typedef struct
|
|||
uint8_t channel;
|
||||
} communication_ai_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t channel;
|
||||
} comnmunication_encoder_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint8_t data[50];
|
||||
|
@ -54,10 +71,13 @@ typedef union
|
|||
communication_di_t di_data;
|
||||
communication_ao_t ao_data;
|
||||
communication_ai_t ai_data;
|
||||
comnmunication_encoder_t encoder_data;
|
||||
} communication_data_u;
|
||||
#pragma pack()
|
||||
|
||||
void communication_exception(uint8_t *tx_data, const uint8_t *const rx_data, communication_error_e error_code);
|
||||
void communication_get_ai(communication_ai_t *ai_data, uint8_t *tx_data, const uint8_t *const rx_data);
|
||||
void communication_set_ao(communication_ao_t *ao_data);
|
||||
void communication_get_encoder(comnmunication_encoder_t *encoder_data, uint8_t *tx_data, const uint8_t *const rx_data);
|
||||
void communication_reset_hart(void);
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "communication_protocol.h"
|
||||
#include "user_lib.h"
|
||||
#include "ad7124.h"
|
||||
|
||||
#include "usart.h"
|
||||
#include "linear_encoder.h"
|
||||
extern float current_buff[2];
|
||||
extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX];
|
||||
/**
|
||||
|
@ -57,4 +58,32 @@ void communication_set_ao(communication_ao_t *ao_data)
|
|||
current_buff[ao_data->channel] = B2S_FLOAT32(ao_data->data.f);
|
||||
}
|
||||
|
||||
|
||||
void communication_get_encoder(comnmunication_encoder_t *encoder_data, uint8_t *tx_data, const uint8_t *const rx_data)
|
||||
{
|
||||
float32_u enc_data;
|
||||
uint8_t tx_data_len = COM_ENCODER_DATA_SIZE;
|
||||
enc_data.f = S2B_FLOAT32(linear_enc.length);
|
||||
tx_data[0] = FRAME_HEAD; // 帧头
|
||||
tx_data[1] = COM_OK; // 状态
|
||||
tx_data[2] = rx_data[2]; // 设备号
|
||||
tx_data[3] = rx_data[3]; // 命令号
|
||||
tx_data[4] = 5; // 数据长度
|
||||
tx_data[5] = linear_enc.direction; // 运动方向
|
||||
tx_data[6] = enc_data.c; // 数据
|
||||
tx_data[7] = enc_data.c >> 8; // 数据
|
||||
tx_data[8] = enc_data.c >> 16; // 数据
|
||||
tx_data[9] = enc_data.c >> 24; // 数据
|
||||
tx_data[10] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[11] = FRAME_TAIL; // 帧尾
|
||||
}
|
||||
void communication_reset_hart(void)
|
||||
{
|
||||
if (huart5.RxState == HAL_UART_STATE_READY)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
|
||||
}
|
||||
if (huart2.RxState == HAL_UART_STATE_READY)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ communication_di_t *user_communication_di = NULL;
|
|||
communication_do_t *user_communication_do = NULL;
|
||||
communication_ai_t *user_communication_ai = NULL;
|
||||
communication_ao_t *user_communication_ao = NULL;
|
||||
comnmunication_encoder_t *user_communication_encoder = NULL;
|
||||
|
||||
extern uint8_t tcp_echo_flags_hart1;
|
||||
extern uint8_t tcp_echo_flags_hart2;
|
||||
|
@ -198,6 +199,15 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
{
|
||||
send_data_flag_cmd = 0; // 上位机返回数据,发送状态标志位清零
|
||||
}
|
||||
else if (tcp_rx_data[3] == READ_ENCODER_CMD)
|
||||
{
|
||||
/*读操作,从寄存器读取数据,组包返回*/
|
||||
tx_data_len = COM_ENCODER_DATA_SIZE;
|
||||
user_communication_encoder = &communication_data.encoder_data;
|
||||
communication_get_encoder(user_communication_encoder, tcp_tx_data, tcp_rx_data);
|
||||
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// 返回命令号错误
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef __LINEAR_ENCODER_H__
|
||||
#define __LINEAR_ENCODER_H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
typedef struct linear_encoder
|
||||
{
|
||||
uint8_t channel;
|
||||
uint8_t direction;
|
||||
int data;
|
||||
float length;
|
||||
} linear_encoder_t;
|
||||
|
||||
extern linear_encoder_t linear_enc;
|
||||
|
||||
void linear_encoder_get_data(void);
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#include "linear_encoder.h"
|
||||
#include "tim.h"
|
||||
|
||||
linear_encoder_t linear_enc = {0};
|
||||
|
||||
void linear_encoder_get_data(void)
|
||||
{
|
||||
linear_enc.channel = 0;
|
||||
linear_enc.direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim8);
|
||||
linear_enc.data = (short)__HAL_TIM_GET_COUNTER(&htim8);
|
||||
linear_enc.length = (float)(linear_enc.data * 0.005);
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
#include "uart_lcd.h"
|
||||
#include "usart.h"
|
||||
#include "lwip.h"
|
||||
|
||||
#include "tim.h"
|
||||
extern ip4_addr_t ipaddr;
|
||||
extern float current_buff[2];
|
||||
uart_lcd_t uart_lcd_state = {0};
|
||||
ec11_t ec11_data = {0};
|
||||
|
||||
static void uart_lcd_current_channel1(void);
|
||||
static void uart_lcd_current_channel2(void);
|
||||
|
@ -141,3 +143,116 @@ void uart_lcd_page_switch(uint8_t page)
|
|||
}
|
||||
// HAL_Delay(100);
|
||||
}
|
||||
|
||||
void uart_lcd_ec11_control_current(void)
|
||||
{
|
||||
if (uart_lcd_state.page_num == 0) // 当前页面为电流调节页面时,才对EC11编码器进行计数处理
|
||||
{
|
||||
ec11_data.direction = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim1);
|
||||
ec11_data.encode_num = (short)__HAL_TIM_GET_COUNTER(&htim1);
|
||||
|
||||
if ((ec11_data.direction == 0) && (ec11_data.encode_num > ec11_data.encode_num_last))
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
uart_lcd_state.current_value[0] += 1;
|
||||
if (uart_lcd_state.current_value[0] > 20)
|
||||
{
|
||||
uart_lcd_state.current_value[0] = 20;
|
||||
}
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
uart_lcd_state.current_value[1] += 1;
|
||||
if (uart_lcd_state.current_value[1] > 20)
|
||||
{
|
||||
uart_lcd_state.current_value[1] = 20;
|
||||
}
|
||||
}
|
||||
uart_lcd_current_out(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
if ((ec11_data.direction == 1) && (ec11_data.encode_num < ec11_data.encode_num_last))
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
if (uart_lcd_state.current_value[0] < 2)
|
||||
{
|
||||
uart_lcd_state.current_value[0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uart_lcd_state.current_value[0] -= 1;
|
||||
}
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
if (uart_lcd_state.current_value[1] < 2)
|
||||
{
|
||||
uart_lcd_state.current_value[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uart_lcd_state.current_value[1] -= 1;
|
||||
}
|
||||
}
|
||||
uart_lcd_current_out(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
|
||||
ec11_data.encode_num_last = ec11_data.encode_num;
|
||||
}
|
||||
}
|
||||
|
||||
void uart_lcd_ecll_control_current_out(void)
|
||||
{
|
||||
if (ec11_data.confirm_key_flag == 0)
|
||||
{
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 1) // 确认按键确认电流输出
|
||||
{
|
||||
ec11_data.confirm_key_flag_last++;
|
||||
if (ec11_data.confirm_key_flag_last > 2)
|
||||
{
|
||||
current_buff[0] = (float)uart_lcd_state.current_value[0];
|
||||
current_buff[1] = (float)uart_lcd_state.current_value[1];
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
}
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 2) // 切换通道按键确认状<E8AEA4>??
|
||||
{
|
||||
ec11_data.confirm_key_flag_last++;
|
||||
if (ec11_data.confirm_key_flag_last > 2)
|
||||
{
|
||||
if (uart_lcd_state.key_state[0] == 1)
|
||||
{
|
||||
uart_lcd_state.key_state[0] = 0;
|
||||
uart_lcd_state.key_state[1] = 1;
|
||||
uart_lcd_state.key_state[2] = 0;
|
||||
}
|
||||
else if (uart_lcd_state.key_state[0] == 0)
|
||||
{
|
||||
uart_lcd_state.key_state[0] = 1;
|
||||
uart_lcd_state.key_state[1] = 0;
|
||||
uart_lcd_state.key_state[2] = 1;
|
||||
}
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
uart_lcd_channel_switch(uart_lcd_state.key_state[0]);
|
||||
}
|
||||
}
|
||||
else if (ec11_data.confirm_key_flag == 3) // 切换界面
|
||||
{
|
||||
|
||||
if (uart_lcd_state.page_num == 0)
|
||||
{
|
||||
uart_lcd_state.page_num = 1;
|
||||
}
|
||||
else if (uart_lcd_state.page_num == 1)
|
||||
{
|
||||
uart_lcd_state.page_num = 0;
|
||||
}
|
||||
ec11_data.confirm_key_flag_last = 0;
|
||||
ec11_data.confirm_key_flag = 0;
|
||||
uart_lcd_page_switch(uart_lcd_state.page_num);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,4 +26,7 @@ void uart_lcd_init(void);
|
|||
void uart_lcd_current_out(uint8_t channel);
|
||||
void uart_lcd_channel_switch(uint8_t channel);
|
||||
void uart_lcd_page_switch(uint8_t page);
|
||||
|
||||
void uart_lcd_ec11_control_current(void);
|
||||
void uart_lcd_ecll_control_current_out(void);
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include "user_gpio.h"
|
||||
|
||||
extern uint8_t send_data_flag_cmd;
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
uint8_t di_state_last[DI_MAX] = {0};
|
||||
uint8_t di_state_now[DI_MAX] = {0};
|
||||
void user_write_gpio(communication_do_t *do_data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
@ -35,3 +39,36 @@ void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t
|
|||
tx_data[5 + length] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[6 + length] = FRAME_TAIL; // 帧尾
|
||||
}
|
||||
|
||||
void user_gpio_trigger(void)
|
||||
{
|
||||
uint8_t di_ch = 0;
|
||||
uint8_t tx_data_len = 7 + DI_MAX;
|
||||
uint8_t tx_data[32] = {0};
|
||||
tx_data[0] = FRAME_HEAD;
|
||||
tx_data[1] = COM_OK;
|
||||
tx_data[2] = DEVICE_NUM;
|
||||
tx_data[3] = SEND_STATE_CMD;
|
||||
tx_data[4] = DI_MAX;
|
||||
for (di_ch = 0; di_ch < DI_MAX; di_ch++)
|
||||
{
|
||||
di_state_now[di_ch] = gpio_di_test(di_ch);
|
||||
if (di_state_last[di_ch] != di_state_now[di_ch])
|
||||
{
|
||||
di_state_last[di_ch] = di_state_now[di_ch];
|
||||
send_data_flag_cmd = 1;
|
||||
}
|
||||
tx_data[5 + di_ch] = di_state_now[di_ch];
|
||||
}
|
||||
if ((send_data_flag_cmd != 0) && (1 == tcp_echo_flags_control))
|
||||
{
|
||||
tx_data[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 寮傛垨鏍¢獙
|
||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 甯у熬
|
||||
user_send_data_control(tx_data, tx_data_len);
|
||||
send_data_flag_cmd++;
|
||||
if (send_data_flag_cmd > 3) // 杩炵画涓夋涓婁綅鏈烘病鏈夊洖搴旓紝鍒欏仠姝㈠彂閫佹暟鎹寘
|
||||
{
|
||||
send_data_flag_cmd = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
void user_write_gpio(communication_do_t *do_data);
|
||||
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data);
|
||||
void user_gpio_trigger(void);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue