智能家居(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;
}
相关推荐
墨染倾城殇1 天前
蓝牙模块 + Wi-Fi 6 在家庭智能网关中如何分工
智能家居·蓝牙模块·智能网关·wifi6
佛漏米2 天前
全屋智能的理性决策:从真实体验拆解哪些功能值得投入
智能家居·别墅装修
2501_913981782 天前
智能家居无线数传技术深度解析:从Wi-Fi到Zigbee,探索高速稳定的通信解决方案
智能家居
Jack_02203 天前
基于51单片机的智能电动窗帘控制OLED显示设计
单片机·嵌入式硬件·51单片机·智能家居·oled显示·电动窗帘
2501_913981783 天前
2025年智能家居行业发展报告:无线数传技术助力家庭互联新体验
智能家居
墨染倾城殇3 天前
EFR32BG21 BLE 5.2 Mesh 模组:面向智能家居的长距离连接方案
智能家居·蓝牙模块·低功耗模块
振浩微433射频芯片3 天前
低功耗无线遥控新选择:深度解析VI520R ASK/OOK接收芯片与433MHz方案优势
网络·单片机·嵌入式硬件·物联网·智能家居
三佛科技-134163842123 天前
电动牙刷方案开发-基于FT61E131B-RB单片机
单片机·嵌入式硬件·智能家居·pcb工艺
三佛科技-134163842124 天前
PL3325CS/CD/CH/CE 与PL3325BE 之间的对比与联系(应用功率与典型应用电路)
单片机·嵌入式硬件·物联网·智能家居·pcb工艺
三佛科技-134163842124 天前
FT838NB1-RT_5W(5V1A)原边反馈(5级能效)典型应用电路分析
单片机·嵌入式硬件·物联网·智能家居·pcb工艺