智能家居(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;
}
相关推荐
世强硬创小助手6 小时前
世强硬创平台上新:天钰科技高集成AI SoC,助力客户解锁轻量智能家居新方案
人工智能·科技·智能家居
点灯小铭1 天前
基于单片机的智能家居多参数环境监测与联动报警系统设计
单片机·mongodb·毕业设计·智能家居·课程设计·期末大作业
三佛科技-134163842123 天前
暴力风扇方案MCU控制芯片开发
单片机·嵌入式硬件·智能家居·pcb工艺
兆龙电子单片机设计3 天前
【STM32项目开源】STM32单片机智能家居控制系统
stm32·单片机·物联网·开源·毕业设计·智能家居
充哥单片机设计3 天前
【STM32项目开源】基于STM32的智能家居环境监测系统
stm32·嵌入式硬件·智能家居
三佛科技-134163842124 天前
智能窗帘方案开发,基于国产单片机电动窗帘方案设计
单片机·嵌入式硬件·智能家居·pcb工艺
MYZR14 天前
家庭HMI:重塑智能家居的人机交互新范式
人机交互·智能家居·ssd2351
三佛科技-134163842126 天前
智能美甲灯方案,UV/LED美甲光疗机美甲烤灯MCU控制方案开发设计
单片机·嵌入式硬件·智能家居·pcb工艺
三佛科技-134163842126 天前
LED氛围灯方案开发MCU控制芯片
单片机·嵌入式硬件·智能家居·pcb工艺
三佛科技-134163842126 天前
便携式榨汁机方案开发,榨汁机果汁机MCU控制方案设计
单片机·嵌入式硬件·智能家居·pcb工艺