智能家居(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;
}
相关推荐
Evand J1 天前
物联网智能设备:未来生活的变革者
人工智能·物联网·智能手机·智能家居·智能手表
嵌入式详谈3 天前
基于STM32的智能家居灯光控制系统设计
stm32·单片机·智能家居
沐欣工作室_lvyiyi4 天前
基于物联网的智能环境监测系统(论文+源码)
单片机·嵌入式硬件·物联网·stm32单片机·毕业设计·智能家居
zjytldz4 天前
无线物联网通信与智能家居
大数据·运维·网络·人工智能·物联网·5g·智能家居
唯创知音5 天前
AI芯片WT2605C赋能厨房家电,在线对话操控,引领智能烹饪新体验:尽享高效便捷生活
人工智能·单片机·物联网·生活·智能家居·语音识别
V: yingjun10056 天前
LP3718BSL封装SOP8/12W隔离开关电源芯片
科技·智能家居·集成学习
极客小张7 天前
基于STM32的智能家居交互终端:使用FreeRTOS与MQTT协议的流程设计
c语言·stm32·物联网·算法·毕业设计·智能家居·交互
成都纵横智控科技官方账号7 天前
智能家居技术的前景和现状
智能家居
V: yingjun10058 天前
FT8440A高速风筒电源芯片12V300mA,18V250mA
科技·单片机·嵌入式硬件·智能家居·集成学习
eSIM物联工厂8 天前
物联网系统中声音拾取音频方案_咪头
驱动开发·嵌入式硬件·物联网·音视频·智能家居