智能家居(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;
}
相关推荐
钱工的门窗技术笔记11 小时前
智能门窗的边界与前提:为什么“智能”不能替代本体性能
网络·物联网·智能家居
吴建旭 智宅焕14 小时前
智能家居全国交付的成本结构重构:从执行端计价到交付确定性基础设施
重构·智能家居
yuehuaxin0117 小时前
LS8011C 快充协议芯片|SOT‑23‑6L 内置 431,PD3.2 SPR/PPS 适配器物料备选评估调试笔记
笔记·智能家居·适配器模式·智能硬件
吴建旭 智宅焕18 小时前
智能家居全国交付中异地高并发管理带宽的系统架构与AI半自动化实现
人工智能·系统架构·智能家居
Yiran_G19 小时前
ZigBee单播、广播与组播详解:从寻址机制到批量控制设计
嵌入式硬件·物联网·智能家居
吴建旭 智宅焕21 小时前
智能家居全国交付基础设施的架构设计与实现:线上获客下的交付确定性体系
智能家居
Yiran_G1 天前
智能家居自动化为什么会失效?从一次开灯失败看无线通信链路
嵌入式硬件·物联网·智能家居
回眸&啤酒鸭2 天前
【回眸】Apple HomeView 智能家居场景化应用指南
智能家居
Gongsion2 天前
30V输入耐压|1.5μA超低静态电流|200mA输出,CSM52系列:线性稳压器LDO,12V母线转3.3V/5V传感器、MCU弱电支路可靠稳压方案
单片机·嵌入式硬件·车载系统·无人机·智能家居
Chery11403 天前
BLE + Wi-Fi双模智能家居方案:ESP32-C3FH4&ESP32-C5HF4芯片选型指南
物联网·ai·智能家居