feat: before tring to fix cmdHandler
This commit is contained in:
111
Core/Src/main.c
111
Core/Src/main.c
@ -44,10 +44,7 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define K1 HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin)
|
||||
#define K2 HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin)
|
||||
#define K3 HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin)
|
||||
#define K4 HAL_GPIO_ReadPin(KEY4_GPIO_Port, KEY4_Pin)
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@ -60,8 +57,6 @@
|
||||
/* USER CODE BEGIN PV */
|
||||
extern unsigned short esp8266_cnt;
|
||||
extern unsigned char esp8266_buf[128];
|
||||
char ONENET_CONNECTED = 0;
|
||||
uint8_t* dataPtr;
|
||||
uint8_t* UART1_RxData[40];
|
||||
uint8_t UART2_RxData;
|
||||
|
||||
@ -86,72 +81,7 @@ void MX_FREERTOS_Init(void);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
void KeyScan(void)
|
||||
{
|
||||
if (K1 == GPIO_PIN_RESET)
|
||||
{
|
||||
// HAL_Delay(5);
|
||||
osDelay(5);
|
||||
if (K1 == GPIO_PIN_RESET)
|
||||
{
|
||||
HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
|
||||
}
|
||||
while (K1 == GPIO_PIN_RESET);
|
||||
}
|
||||
if (K2 == GPIO_PIN_RESET)
|
||||
{
|
||||
// HAL_Delay(5);
|
||||
osDelay(5);
|
||||
if (K2 == GPIO_PIN_RESET)
|
||||
{
|
||||
HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
|
||||
}
|
||||
while (K2 == GPIO_PIN_RESET);
|
||||
}
|
||||
if (K3 == GPIO_PIN_RESET)
|
||||
{
|
||||
// HAL_Delay(5);
|
||||
osDelay(5);
|
||||
if (K3 == GPIO_PIN_RESET)
|
||||
{
|
||||
HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
|
||||
}
|
||||
while (K3 == GPIO_PIN_RESET);
|
||||
}
|
||||
if (K4 == GPIO_PIN_RESET)
|
||||
{
|
||||
// HAL_Delay(5);
|
||||
osDelay(5);
|
||||
if (K4 == GPIO_PIN_RESET)
|
||||
{
|
||||
HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
|
||||
}
|
||||
while (K4 == GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
void Display_IM1281B(void)
|
||||
{
|
||||
OLED_ShowString(0, 0, "Volt:", 12);
|
||||
OLED_ShowString(0, 2, "Curr:", 12);
|
||||
OLED_ShowString(0, 4, "Pwr: ", 12);
|
||||
OLED_ShowString(0, 6, "Eng: ", 12);
|
||||
|
||||
char buffer[16];
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%.2fV", IM_Volt * 0.0001);
|
||||
OLED_ShowString(40, 0, buffer, 12);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%.2fA", IM_Curr * 0.0001);
|
||||
OLED_ShowString(40, 2, buffer, 12);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%.2fW", IM_Power * 0.0001);
|
||||
OLED_ShowString(40, 4, buffer, 12);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "%.3fKWh", IM_Energy * 0.0001);
|
||||
OLED_ShowString(40, 6, buffer, 12);
|
||||
|
||||
}
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -192,31 +122,22 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
// Retarget uart
|
||||
RetargetInit(&huart1);
|
||||
// RetargetInit(&huart1);
|
||||
|
||||
// Init OLED
|
||||
OLED_Init();
|
||||
OLED_Clear();
|
||||
|
||||
OLED_ShowString(0,0,"initializing...",12);
|
||||
|
||||
// HAL_TIM_Base_Start_IT(&htim1);
|
||||
// HAL_TIM_Base_Start_IT(&htim3);
|
||||
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t*)UART1_RxData, 40);
|
||||
HAL_UART_Receive_IT(&huart2, &UART2_RxData, 1);
|
||||
|
||||
ESP8266_Init();
|
||||
while (OneNet_DevLink()) {}
|
||||
OneNET_Subscribe();
|
||||
ONENET_CONNECTED = 1;
|
||||
|
||||
// Init RC522
|
||||
MFRC_Init();
|
||||
PCD_Reset();
|
||||
|
||||
OLED_ShowString(0,0,"OneNet online ",12);
|
||||
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t*)UART1_RxData, 40);
|
||||
HAL_UART_Receive_IT(&huart2, &UART2_RxData, 1);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Init scheduler */
|
||||
@ -404,17 +325,17 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
// if(htim->Instance == TIM1){
|
||||
// KeyScan();
|
||||
// }
|
||||
if (htim->Instance == TIM3)
|
||||
{
|
||||
if (ONENET_CONNECTED)
|
||||
{
|
||||
dataPtr = ESP8266_GetIPD(0);
|
||||
if (dataPtr != NULL)
|
||||
{
|
||||
OneNet_RevPro(dataPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (htim->Instance == TIM3)
|
||||
// {
|
||||
// if (ONENET_CONNECTED)
|
||||
// {
|
||||
// dataPtr = ESP8266_GetIPD(0);
|
||||
// if (dataPtr != NULL)
|
||||
// {
|
||||
// OneNet_RevPro(dataPtr);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM4)
|
||||
{
|
||||
|
Reference in New Issue
Block a user