智能家居(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;
}
相关推荐
阿钱真强道2 天前
06 极物科技 | 创明RS485窗帘 - UDP 通讯协议规范
udp·智能家居·通讯协议·极物·极物智能·极物科技·创明窗帘
3C速讯2 天前
智能门锁生物识别方案技术对比:3D双目人脸 vs 3D结构光 vs 掌静脉的实测数据分析
智能家居·智能门锁
明天会出太阳3 天前
酒店照明设计:大堂、客房、餐厅的照度与色温工程化要点
智能家居·武汉·酒店灯光设计·灯具定制
zhonyu鱼3 天前
Home Assistant:开源的智能家居自动化平台,统一控制全屋设备
开源·自动化·智能家居
欧阳天羲3 天前
全屋智能家居一体化方案‑配套资料文档合集
云原生·eureka·智能家居
阿钱真强道3 天前
04 极物科技 | 创明RS485窗帘 - 快速接入指南
智能家居·rs485·极物·极物智能·极物科技·创明窗帘·窗帘控制
国产化创客3 天前
ESP32-S3+INMP441+MAX98357 本地 WAV 录音播放方案详解
物联网·开源·音视频·智能家居·智能硬件
lf13210275 天前
用 JSON Schema 管装修节点记录:从照片台账到可校验工程数据
网络·数据库·人工智能·经验分享·物联网·json·智能家居
Yiran_G5 天前
低功耗 Zigbee 模组怎么选?基于 CC2340R53 的 WS8823 设计实践
人工智能·物联网·智能家居
SKYLAB018 天前
打破智能家居生态壁垒|微喇智能 WKV553‑A 模组原生支持 Matter,解锁跨平台互联新体验
网络·智能家居