智能家居(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;
}
相关推荐
三佛科技-1341638421217 小时前
BP85958D输出12V400MA智能家居电源芯片(典型应用电路、替代型号HN32512)
单片机·嵌入式硬件·物联网·智能家居·pcb工艺
九河云21 小时前
华为云 IoT 边缘 IoTEdge 实战:工业设备数采与云边协同部署全指南
服务器·物联网·华为云·智能家居
三佛科技-134163842122 天前
BP85928D贴片SOP8 5V500MA智能家居开关电源芯片 (典型应用电路、替代方案FT8451B/FT8451H)
单片机·嵌入式硬件·物联网·智能家居·pcb工艺
飞睿科技2 天前
开发者指南:乐鑫Matter SDK在智能家居中的实战应用与优势解析
物联网·esp32·智能家居·sdk·乐鑫科技
l3538o675732 天前
智能家居设备供电芯片:220v降压5v 12v-600ma电源芯片AH8966/AH8665
人工智能·科技·单片机·智能家居
清风6666663 天前
基于单片机的智能家居多参数环境监测与联动报警系统设计
数据库·单片机·毕业设计·智能家居·课程设计·期末大作业
LCG米4 天前
从零搭建智能家居网关:基于瑞萨RA4L1 MCU与Home Assistant
单片机·嵌入式硬件·智能家居
三佛科技-134163842125 天前
SM7015 输出12V/18V 电流150MA非隔离LED电源驱动IC典型应用电路
单片机·嵌入式硬件·智能家居·pcb工艺
三佛科技-134163842125 天前
PL3367C 离线反激式PWM控制芯片兼容DP2525JD 典型应用电路
单片机·嵌入式硬件·智能家居·pcb工艺
九河云6 天前
智能家居生态数字化:设备联动场景化编程与用户习惯学习系统建设
人工智能·学习·智能家居