#include "key.h" #include "usart.h" #include "interface.h" //结构体 LockInfo lockinfo; extern Menu_table menu; extern TipsFlag tipsflag; struct keys key[1]={0}; //布尔 bool sent1_key = false; bool sent2_key = false; bool sent3_key = false; bool sent4_key = false; uint32_t enterInterface_time =0; bool Allopen = false; uint8_t KEY_1_Scan_PDA(void) { static uint8_t key_state = 0; static uint8_t last_key_state = 0; static uint32_t debounce_time = 0; key_state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_3); if (key_state != last_key_state) // 检测按键状态变化 { last_key_state = key_state; debounce_time = HAL_GetTick(); // 记录当前时间 } else { if (HAL_GetTick() - debounce_time > 30) // 去抖时间 { if (key_state == GPIO_PIN_RESET) // 按键按下 { if(!sent1_key) { enterInterface_time = HAL_GetTick(); switch(menu.current) { case 0: { SET_MENU_STATUS(1,2,0,1); break; } case 1: { SWITCH_MENU_UP3(); break; } case 4: { SWITCH_MENU_UPmore(); break; } } #if debugkeyinfo == 1 PRINT_MENU_STATUS("K1"); #endif sent1_key = true; } return 1; } else // 按键释放 { sent1_key = false; return 0; } } } return 0; } uint8_t KEY_2_Scan_PDA(void) { static uint8_t key_state = 0; static uint8_t last_key_state = 0; static uint32_t debounce_time = 0; key_state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4); if (key_state != last_key_state) // 检测按键状态变化 { last_key_state = key_state; debounce_time = HAL_GetTick(); // 记录当前时间 } else { if (HAL_GetTick() - debounce_time > 30) // 去抖时间 { if (key_state == GPIO_PIN_RESET) // 按键按下 { if (!sent2_key) { enterInterface_time = HAL_GetTick(); switch (menu.current) { case 0: { SET_MENU_STATUS(1,2,0,1); break; } case 1: { SWITCH_MENU_DOWN3(); break; } case 4: { SWITCH_MENU_DOWNmore(); break; } } #if debugkeyinfo == 1 PRINT_MENU_STATUS("K2"); #endif sent2_key = true; } return 1; } else // 按键释放 { sent2_key = false; return 0; } } } return 0; } char macStr[20][13]; // 长度为13的字符串加上字符串结束符'\0' uint8_t KEY_3_Scan_PDA(void) { static uint8_t key_state = 0; static uint8_t last_key_state = 0; static uint32_t debounce_time = 0; key_state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5); if (key_state != last_key_state) // 检测按键状态变化 { last_key_state = key_state; debounce_time = HAL_GetTick(); // 记录当前时间 } else { if (HAL_GetTick() - debounce_time > 30) // 去抖时间 { if (key_state == GPIO_PIN_RESET) // 按键按下 { if (!sent3_key) { enterInterface_time = HAL_GetTick(); switch (menu.current) { case 0: { SET_MENU_STATUS(1,2,0,1); break; } case 1: { if(menu.down==0) { printf("$$操作集合:%d%d%d%d%d%d%d%d\r\n",devices[0],devices[1],devices[2],devices[3],devices[4],devices[5],devices[6],devices[7]); //printf("一键解封\r\n"); SET_MENU_STATUS(2,2,0,0); Allopen=true; break; } else if(menu.down==1) { printf("$$操作集合:%d%d%d%d%d%d%d%d\r\n",devices[0],devices[1],devices[2],devices[3],devices[4],devices[5],devices[6],devices[7]); //printf("一键施封\r\n"); SET_MENU_STATUS(2,1,1,1); Allopen=true; break; } else if(menu.down==2)//查看绑定信息 { //printf("查看绑定信息\r\n"); SET_MENU_STATUS(4,macsetptr->macCount,0,0); break; } } } #if debugkeyinfo == 1 PRINT_MENU_STATUS("K3"); #endif sent3_key = true; } return 1; } else // 按键释放 { sent3_key = false; return 0; } } } return 0; } uint8_t KEY_4_Scan_PDA(void) { static uint8_t key_state = 0; static uint8_t last_key_state = 0; static uint32_t debounce_time = 0; key_state = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6); if (key_state != last_key_state) // 检测按键状态变化 { last_key_state = key_state; debounce_time = HAL_GetTick(); // 记录当前时间 } else { if (HAL_GetTick() - debounce_time > 30) // 去抖时间 { if (key_state == GPIO_PIN_RESET) // 按键按下 { enterInterface_time = HAL_GetTick(); if (!sent4_key) {//返回 switch (menu.current) { case 0: { SET_MENU_STATUS(1,2,0,1); break; } case 1: { SET_MENU_STATUS(0,0,0,0); break; } case 2: { reAuth = false; menu.current=1; menu.enter=0; refresh=true; break; } case 3: { reAuth = false; menu.enter=0; menu.current=1; refresh=true; break; } case 4: { SET_MENU_STATUS(1,0,2,1); break; } case 5: { menu.current=1; menu.enter=0; //SET_MENU_STATUS(1,2,0,1); refresh=true; break; } } #if debugkeyinfo == 1 PRINT_MENU_STATUS("K4"); #endif sent4_key = true; } return 1; } else // 按键释放 { sent4_key = false; return 0; } } } return 0; } void updatekeystate(void) { #if ManualWork == 1 KEY_1_Scan_PDA(); KEY_2_Scan_PDA(); KEY_3_Scan_PDA(); KEY_4_Scan_PDA(); #else #endif }