智能家居(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;
}
相关推荐
2601_968502061 天前
无主灯灯具怎么选?
智能家居·武汉装修·武汉无主灯·武汉灯光设计
远翔调光芯片^138287988722 天前
ECP5702能芯科技PD取电芯片在市场上的优势有哪些?
开发语言·人工智能·单片机·嵌入式硬件·智能家居
Zentceh2 天前
海洋牧场夜间监测:AI全彩夜视+水下成像集成方案
图像处理·人工智能·科技·计算机视觉·车载系统·无人机·智能家居
远翔调光芯片^138287988724 天前
Type-C接口统一了,但充电协议没统一,终端设备如何解决取电难题?
人工智能·科技·物联网·智能家居·能源
senyushejiaz4 天前
海珠局部改造怎么做?不用全屋重装,这些居住问题可以针对性解决
智能家居·装修
AiNightVision5 天前
AI-ISP微光全彩夜视技术深度解析:如何在0.001Lux下实现全彩成像
人工智能·计算机视觉·车载系统·自动驾驶·无人机·智能家居·智能硬件
蒲公英内测分发6 天前
App 更新一次就换一个二维码?智能硬件配套 App 的版本和下载入口怎么管理
人工智能·测试工具·智能家居·智能硬件
3C速讯6 天前
掌静脉识别 vs 指纹 vs 3D人脸:2026智能门锁生物识别方案技术原理与实测数据对比
智能家居·智能门锁
TOP品牌榜中榜8 天前
2026智能门锁密码安全评测:20位虚位密码、5次试错锁定、室内独立反锁谁更强?
智能家居·智能门锁
阿钱真强道9 天前
55 极物科技 | KNX协议 - 读/写/响应机制与状态同步
智能家居·状态同步·极物·极物智能·极物科技·knx协议