From 52d3ef0d0c426b90c5e81615d897e14767044d34 Mon Sep 17 00:00:00 2001
From: 95384 <664090429@qq.com>
Date: Wed, 15 Jan 2025 11:06:29 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=B8=85?=
=?UTF-8?q?=E9=99=A4=E9=9B=A8=E9=87=8F=E6=8C=87=E4=BB=A4=EF=BC=8C=E8=8E=B7?=
=?UTF-8?q?=E5=8F=96=E5=85=89=E7=85=A7=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
App/Src/uart_dev.c | 5 +++--
Core/Src/freertos.c | 1 +
Core/Src/main.c | 2 +-
Drivers/RainLight/rain.c | 41 ++++++++++++++++++++++++++++++++++++++++
Drivers/RainLight/rain.h | 18 ++++++++++++++++++
EWARM/micro_climate.ewp | 10 ++++++++++
EWARM/micro_climate.ewt | 9 +++++++++
7 files changed, 83 insertions(+), 3 deletions(-)
create mode 100644 Drivers/RainLight/rain.c
create mode 100644 Drivers/RainLight/rain.h
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