123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include "PM2_5.h"
- #include "iot_errno.h"
- #include "iot_gpio.h"
- #include "iot_gpio_ex.h"
- #include "iot_uart.h"
- #include "stdio.h"
- #define RESET_GPIO 7
- #define LED_SAFE_GPIO 8
- #define LED_WARN_GPIO 14
- #define SET_GPIO 13
- #define WIFI_IOT_UART_IDX_1 1
- uint8_t RxBuffer[3];
- void BoardInit(void)
- {
- IoTGpioInit(RESET_GPIO);
- IoTGpioSetFunc(RESET_GPIO, IOT_GPIO_FUNC_GPIO_7_GPIO);
- IoTGpioSetDir(RESET_GPIO, IOT_GPIO_DIR_OUT); // 设置为输出模式
- IoTGpioSetOutputVal(RESET_GPIO, 1);
- IoTGpioInit(LED_SAFE_GPIO);
- IoTGpioSetFunc(LED_SAFE_GPIO, IOT_GPIO_FUNC_GPIO_8_GPIO);
- IoTGpioSetDir(LED_SAFE_GPIO, IOT_GPIO_DIR_OUT); // 设置为输出模式
- IoTGpioInit(LED_WARN_GPIO);
- IoTGpioSetFunc(LED_WARN_GPIO, IOT_GPIO_FUNC_GPIO_14_GPIO);
- IoTGpioSetDir(LED_WARN_GPIO, IOT_GPIO_DIR_OUT); // 设置为输出模式
- IoTGpioInit(SET_GPIO);
- IoTGpioSetFunc(SET_GPIO, IOT_GPIO_FUNC_GPIO_13_GPIO);
- IoTGpioSetDir(SET_GPIO, IOT_GPIO_DIR_OUT); // 设置为输入模式
- IoTGpioSetOutputVal(SET_GPIO, 1);
- uint32_t ret;
- IotUartAttribute uart_attr = {
- // baud_rate: 9600
- .baudRate = 9600,
- // data_bits: 8bits
- .dataBits = 8,
- .stopBits = 1,
- .parity = 0,
- };
- // Initialize uart driver
- ret = IoTUartInit(WIFI_IOT_UART_IDX_1, &uart_attr);
- if (ret != IOT_SUCCESS) {
- printf("Failed to init uart! Err code = %d\n", ret);
- return;
- }
- }
- static unsigned char read_date[32];
- /***************************************************************
- * 函数名称: PM2DReadData
- * 说 明: 获取GPS经纬度信息
- * 参 数: 无
- * 返 回 值: 无
- ***************************************************************/
- void PM2DReadData(PM2D5Data* ReadData)
- {
- //通过串口1接收数据
- IoTUartRead(WIFI_IOT_UART_IDX_1, read_date, 32);
- // for(int i = 0; i<32; i++)
- // {
- // printf("%d------%x\r\n",i,read_date[i]);
- // }
- if(read_date[0]== 0x42 && read_date[1]== 0x4d)
- {
- ReadData->pm1_0=read_date[2]<<8|read_date[3];
- ReadData->pm2_5=read_date[4]<<8|read_date[5];
- ReadData->pm10=read_date[6]<<8|read_date[7];
- }
- }
- /***************************************************************
- * 函数名称: LedWarnStatusSet
- * 说 明: LED_Warn状态设置
- * 参 数: status,ENUM枚举的数据
- * OFF,关
- * ON,开
- * 返 回 值: 无
- ***************************************************************/
- void LedWarnStatusSet(SwitchStatus status)
- {
- if (status == ON) {
- IoTGpioSetOutputVal(LED_WARN_GPIO, 1); // 设置输出高电平点亮灯
- }
- if (status == OFF) {
- IoTGpioSetOutputVal(LED_WARN_GPIO, 0); // 设置输出低电平关闭灯
- }
- }
- /***************************************************************
- * 函数名称: LedSafeStatusSet
- * 说 明: LED_Safe状态设置
- * 参 数: status,ENUM枚举的数据
- * OFF,关
- * ON,开
- * 返 回 值: 无
- ***************************************************************/
- void LedSafeStatusSet(SwitchStatus status)
- {
- if (status == ON) {
- IoTGpioSetOutputVal(LED_SAFE_GPIO, 1); // 设置输出高电平点亮灯
- }
- if (status == OFF) {
- IoTGpioSetOutputVal(LED_SAFE_GPIO, 0); // 设置输出低电平关闭灯
- }
- }
|