- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "time.h"
- #include "adc_dma.h"
- #include "mq2.h"
- #include "mq7.h"
- #include "dht11.h"
- #include "esp8266.h"
- #include "gizwits_product.h"
- #include "Lcd_Driver.h"
- #include "GUI.h"
- #include "led.h"
- #include "sensor.h"
- u8 temperature = 20;
- u8 humidity = 20;
- float mq2 = 20;
- float mq7 = 10;
- char str[10] ={0};
- //硬件初始化
- void Hardware_Init(void)
- {
- delay_init();
- NVIC_Configuration(); //設置NVIC中斷分組2:2位搶占優先級,2位響應優先級
- uart_init(115200); //串口初始化為115200
- ADCx_Init(); //ADC初始化
- // TIM4_Init(6000,36000-1); //定時3s
- Led_Init();
- Sensor_Init();
- Lcd_Init();
- Lcd_Clear(BLUE);
-
- // while(DHT11_Init()) //DHT11初始化
- // {
- // Gui_DrawFont_GBK16(16,30,RED,BLUE,(u8 *)"DHT11_Init FAILED");
- // delay_ms(500);
- // }
- }
- //協議初始化
- void Gizwits_Init(void)
- {
- TIM3_Int_Init(9,7199); //1MS 系統定時
- usart3_init(9600); //WIFI 初始化 波特率必須為 9600
- memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));//設備狀態結構體初始化
- userInit();
- gizwitsInit();
- }
- void userHandle(void);
- void TFT_ShowTable(void);
- int main(void)
- {
- u8 t=0;
- Hardware_Init();
- Gizwits_Init();
- TFT_ShowTable();
- while(1)
- {
- gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-link模式接入
- if(t%10==0) //每100ms讀取一次
- {
- // DHT11_Read_Data(&temperature,&humidity); //讀取溫濕度值
- mq2 = MQ2_GetPPM();
- mq7 = MQ7_GetPPM();
- }
- delay_ms(10);
- t++;
- if(t==20)
- {
- t=0;
- }
- userHandle();//用戶采集
- gizwitsHandle((dataPoint_t *)¤tDataPoint);//協議處理
-
- if(SENSOR_LIGHT == 1)//手頭沒有獨立按鍵了,用光敏傳感器代替
- {
- printf("WIFI進入AirLink連接模式\r\n");
- gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-link模式接入
- }
- }
- }
- void userHandle(void)
- {
- currentDataPoint.valueValue_Tem = temperature; //Add Sensor Data Collection
- currentDataPoint.valueValue_Hum = humidity; //Add Sensor Data Collection
- currentDataPoint.valueValue_Mq7 = mq7; //Add Sensor Data Collection
- currentDataPoint.valueValue_Mq2 = mq2; //Add Sensor Data Collection
-
-
- Gui_DrawFont_GBK24(23,4,BLUE,YELLOW,(u8 *)"AIR MONITOR");
-
- sprintf(str, "MQ2: %.2fppm", mq2);
- Gui_DrawFont_GBK16(16,30,BLUE,YELLOW, (u8 *)str);
- sprintf(str, "MQ7: %.2fppm", mq7);
- Gui_DrawFont_GBK16(16,50,BLUE,YELLOW,(u8 *)str);
- sprintf(str, "TEM: %d℃", temperature);
- Gui_DrawFont_GBK16(16,70,BLUE,YELLOW,(u8 *)str);
- sprintf(str, "HUM: %d%c", humidity, '%');
- Gui_DrawFont_GBK16(16,90,BLUE,YELLOW,(u8 *)str);
-
-
- if(currentDataPoint.valueValue_Mq2 >= currentDataPoint.valueMq2_MAX)
- {
- currentDataPoint.valueWarning_Mq2 = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Mq2 = 0;//Add Sensor Data Collection
- }
-
- if(currentDataPoint.valueValue_Mq7 >= currentDataPoint.valueMq7_MAX)
- {
- currentDataPoint.valueWarning_Mq7 = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Mq7 = 0;//Add Sensor Data Collection
- }
-
-
- if((currentDataPoint.valueValue_Tem >= currentDataPoint.valueTem_MAX) | (currentDataPoint.valueValue_Tem <= currentDataPoint.valueTem_MIN))
- {
- currentDataPoint.valueWarning_Tem = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Tem = 0;//Add Sensor Data Collection
- }
-
- if((currentDataPoint.valueWarning_Hum >= currentDataPoint.valueHum_MAX) | (currentDataPoint.valueWarning_Hum <= currentDataPoint.valueHum_MIN))
- {
- currentDataPoint.valueWarning_Hum = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Hum = 0;//Add Sensor Data Collection
- }
- }
- void TFT_ShowTable(void)
- {
- Gui_DrawFont_GBK24(23,4,BLUE,YELLOW,(u8 *)"AIR MONITOR");
- DisplayButtonUp(15,28,113,46); //x1,y1,x2,y2
- DisplayButtonUp(15,48,113,66); //x1,y1,x2,y2
- DisplayButtonUp(15,68,113,86); //x1,y1,x2,y2
- DisplayButtonUp(15,88,113,106); //x1,y1,x2,y2
- }
復制代碼
原理圖: 無
仿真: 無
代碼:
環境監測.7z
(264.33 KB, 下載次數: 60)
2023-11-7 15:46 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|