智能家居(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;
}
相关推荐
华普微HOPERF10 分钟前
Matter如何终结智能家居生态割据,重构你的居住体验?
重构·智能家居
TSINGSEE8 小时前
跨平台嵌入式音视频开发指南:EasyRTC音视频通话的多场景适配与AI扩展能力
人工智能·音视频·webrtc·智能家居
zskj_zhyl1 天前
智能家居适老化改造:让科技回归“无感服务”
科技·智能家居
moton20176 天前
Matter协议深度解析:智能家居通信标准的技术架构、开发指南与生态挑战
物联网·智能家居·matter
心之所想,行之将至6 天前
零基础开始学习鸿蒙开发-智能家居APP离线版介绍
学习·智能家居·harmonyos
myzr1236 天前
明远智睿SSD2351核心板在物联网领域的应用实践
人工智能·嵌入式硬件·物联网·智能家居·边缘计算
远翔调光芯片^138287988726 天前
实测解析:FP7208 在汽车照明、摄影照明、教育照明以及太阳能照明等不同市场领域的典型应用参数解析和案例分析
科技·物联网·汽车·智能家居·能源
YHPsophie8 天前
智能家居设备
物联网·智能家居·设备
niuTaylor9 天前
瑞芯微RK3568嵌入式AI项目实战:智能家居项目(二)
人工智能·智能家居
云山工作室9 天前
基于STM32的智能家居门禁开锁控制系统(论文+源码)
stm32·嵌入式硬件·智能家居