diff --git a/App/Src/uart_dev.c b/App/Src/uart_dev.c index e2f7f6b..8da0bb3 100644 --- a/App/Src/uart_dev.c +++ b/App/Src/uart_dev.c @@ -4,6 +4,7 @@ #include "timer.h" #include "gpio.h" #include "inflash.h" +#include "rain.h" extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart3; @@ -352,7 +353,7 @@ void init_ec801_uart() * @retval None */ void init_rain_uart() -{ - HAL_GPIO_WritePin(GPIO_RAIN_PWR_CTRL_GPIO_Port, GPIO_RAIN_PWR_CTRL_Pin, GPIO_PIN_SET); +{ + rainLightPowerOn(); g_rain_uart_handle = uart_dev_init(RAIN_RS485_UART_INDEX, rain_in_buff, sizeof(rain_in_buff)); } diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index b37fcd7..c8f55f6 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -33,6 +33,7 @@ void task_shell_term_main_loop(void const * argument); #include "inflash.h" #include "hp203b.h" #include "encrypt.h" +#include "rain.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ diff --git a/Core/Src/main.c b/Core/Src/main.c index 051265d..af5dab1 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -167,7 +167,7 @@ void Flash_EnableReadProtection(void) /* USER CODE BEGIN 2 */ init_term_uart(); init_rs485_uart(); - init_rain_uart();uart_dev_write(g_rain_uart_handle, "Hello", 5); + init_rain_uart(); // init_ec801_uart(); term_printf("Micro Climate Station Sensor.\r\n"); term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__); diff --git a/Drivers/RainLight/rain.c b/Drivers/RainLight/rain.c new file mode 100644 index 0000000..8515b7d --- /dev/null +++ b/Drivers/RainLight/rain.c @@ -0,0 +1,41 @@ +#include "rain.h" +#include "gpio.h" +#include "uart_dev.h" + +//开电 +void rainLightPowerOn(void) +{ + HAL_GPIO_WritePin(GPIO_RAIN_PWR_CTRL_GPIO_Port, GPIO_RAIN_PWR_CTRL_Pin, GPIO_PIN_SET); +} + +//关电 +void rainLightPowerOff(void) +{ + HAL_GPIO_WritePin(GPIO_RAIN_PWR_CTRL_GPIO_Port, GPIO_RAIN_PWR_CTRL_Pin, GPIO_PIN_RESET); +} + +//获取雨量指令,返回的雨量是十倍,两个字节 +void getRainData(void) +{ + uint8_t getRainDataCmd[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A}; + uart_dev_write(g_rain_uart_handle, getRainDataCmd, sizeof(getRainDataCmd)); +} + +//清空雨量指令 +void clearRainData(void) +{ + uint8_t getRainDataCmd[] = {0x01, 0x06, 0x00, 0x00, 0x00, 0x5A, 0x09, 0xF1}; + uart_dev_write(g_rain_uart_handle, getRainDataCmd, sizeof(getRainDataCmd)); +} + +//获取光照指令,返回一倍光照,四个字节 +void getLightData(void) +{ + uint8_t getRainDataCmd[] = {0x01, 0x03, 0x00, 0x02, 0x00, 0x02, 0x65, 0xCB}; + uart_dev_write(g_rain_uart_handle, getRainDataCmd, sizeof(getRainDataCmd)); +} + +void readProcessRainData(device_handle device) +{ + +} \ No newline at end of file diff --git a/Drivers/RainLight/rain.h b/Drivers/RainLight/rain.h new file mode 100644 index 0000000..2e3566f --- /dev/null +++ b/Drivers/RainLight/rain.h @@ -0,0 +1,18 @@ +#ifndef __RAIN_H__ +#define __RAIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void rainLightPowerOn(void); //开雨量光照电源 +void rainLightPowerOff(void); //关雨量光照电源 +void getRainData(void); //获取雨量指令 +void clearRainData(void); //清空雨量电源 +void getLightData(void); //获取光照数据 + +#ifdef __cplusplus +} +#endif +#endif /*___RAIN_H__ */ + diff --git a/EWARM/micro_climate.ewp b/EWARM/micro_climate.ewp index 4e95e6e..2339eeb 100644 --- a/EWARM/micro_climate.ewp +++ b/EWARM/micro_climate.ewp @@ -374,6 +374,7 @@ $PROJ_DIR$\..\tools $PROJ_DIR$\..\App\Inc $PROJ_DIR$\..\Drivers\HP203B + $PROJ_DIR$\..\Drivers\RainLight