智能家居(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;
}
相关推荐
深圳市青牛科技实业有限公司 小芋圆10 小时前
CS4334:一款高性能的立体声音频数模转换器
科技·嵌入式硬件·音视频·智能家居·新能源·工控主板
绿算技术4 天前
“强强联手,智启未来”凯创未来与绿算技术共筑高端智能家居及智能照明领域新生态
大数据·人工智能·智能家居
LetsonH4 天前
Home Assistant 米家集成:开启智能家居新体验
网络·智能家居
平凡灵感码头4 天前
基于智能家居项目 解析DHT11温湿度传感器
单片机·智能家居
码视野6 天前
基于物联网的智能家居监控系统设计和实现(源码+论文+部署讲解等)
物联网·智能家居
平凡灵感码头6 天前
基于智能家居项目 实现DHT11驱动源代码
stm32·单片机·智能家居
深圳市尚想信息技术有限公司6 天前
智能家居“心脏“升级战:GD25Q127CSIG国产芯片如何重构家庭物联生态
网关·智能家居·存储芯片·兆易创新·闪存芯片
平凡灵感码头11 天前
基于智能家居项目 RGB彩灯(P9813)
单片机·fpga开发·智能家居
学习日记hhh14 天前
智能家居的OneNet云平台
智能家居
奇墨 ITQM15 天前
【QinAgent应用案例】从开发到管理,QinAgent为某智能家居企业提效50%,降本20%
人工智能·ai·云原生·智能家居