智能家居(4)---火灾报警线程封装

封装火灾报警线程实现智能家居中的火灾报警功能
mainPro.c(主函数)

c 复制代码
#include <stdio.h>
#include "controlDevice.h"
#include "inputCommand.h"

#include <pthread.h>

struct Devices        *pdeviceHead  = NULL;         //设备工厂链表头

struct Devices* findDeviceByName(struct Devices *phead,char *name)          //在设备链表中查找设备(语音和socket均可使用)
{
    struct Devices *tmp = phead;
    if(tmp == NULL){
        printf("The devicesLink is NULL");
        return NULL;
    
    }else{
        while(tmp != NULL){
            if(strcmp(tmp->deviceName,name) == 0){
                return tmp;
            }
            tmp = tmp->next;
        }
   
     return NULL;   

    }

}

void* fire_pthread(void *data)					//火灾报警线程处理函数
{
    struct Devices *fire;
    struct Devices *beep;
    int status;

    fire = findDeviceByName(pdeviceHead,"fire");        //从设备链表找出火灾检测和蜂鸣器
    beep = findDeviceByName(pdeviceHead,"beep");

    fire->deviceInit(fire->pinNum);                     
    beep->deviceInit(beep->pinNum);

     while(1){                                           //检测到火灾通过蜂鸣器报警
        status = fire->readStatus(fire->pinNum);
        if(status == 0){
            beep->open(beep->pinNum);
            printf("fire warning\n");
            delay(20000);
        }else
            beep->close(beep->pinNum);
            
    } 

 
 int main()
{
    pthread_t fire_pth;

    if(wiringPiSetup()<0){//初始化wiringPi外设库

            printf("wiringPi Init failed\n");
            return -1;
        }


    //1.指令工厂初始化


    //2.设备控制工厂初始化
  
    pdeviceHead = addFireToDeviceLink(pdeviceHead);                 //将火灾检测加入设备链表
    pdeviceHead = addBeepToDeviceLink(pdeviceHead);                 //将蜂鸣器加入设备链表

   
    //3.线程池建立
   

    //3.3火灾线程
    ret = pthread_create(&fire_pth,NULL,fire_pthread,NULL);
     if (ret != 0) {
        printf("Failed to create firethread.\n");
        return -1;
    }


    //等待线程退出
    pthread_join(fire_pth,NULL);


    return 0;
}
相关推荐
艾格北峰1 天前
STM32 物联网智能家居 (六) OLED显示设备
arm开发·stm32·单片机·嵌入式硬件·物联网·智能家居
Anna_Tong5 天前
如何通过阿里云内容安全在数字时代获得“第一防线”?
安全·网络安全·阿里云·云计算·智能家居·内容安全·实时监控
沐欣工作室_lvyiyi6 天前
基于单片机控制的电动汽车双闭环调速系统(论文+源码)
单片机·嵌入式硬件·物联网·智能家居·电机
木燚垚10 天前
物联网水质监测系统设计与实现/基于STM32的水产养殖云监控系统设计
stm32·嵌入式硬件·物联网·智能家居
深圳启明云端科技11 天前
设备智能化无线交互,ESP32-C3芯片方案,物联网WiFi蓝牙控制通信
物联网·人机交互·智能家居·乐鑫·esp32-c3
深圳启明云端科技15 天前
旋钮屏设备物联网方案,ESP32-C3无线通信应用,助力设备智能化升级
物联网·人机交互·智能家居·乐鑫·旋钮屏
神一样的老师16 天前
【BQ3568HM开发板】智能家居中控屏连接华为云IoTDA物联网平台
物联网·华为云·智能家居
沐欣工作室_lvyiyi17 天前
基于单片机的智能家居设计(论文+源码)
stm32·单片机·嵌入式硬件·物联网·智能家居·指纹识别
Stark-C17 天前
春节娱乐大餐,智能家居互联互通,极空间虚拟机安装小米官方 HA 集成组件
智能家居·娱乐