智能家居(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;
}
相关推荐
欢乐熊嵌入式编程18 小时前
WIFI协议全解析01:WiFi协议的前世今生:从802.11到智能家居
esp32·智能家居·wifi协议·wifi通信
技术支持者python,php13 天前
MQTT通讯:物联网
物联网·智能家居
深圳市尚想信息技术有限公司14 天前
UL/CE双认证!光宝MOC3052-A双向可控硅输出光耦 智能家居/工业控制必备!
智能家居·工业控制·光宝·驱动光耦·输出光耦
根号三加载成功15 天前
物联网控制器:一台顶N台!路由器、PLC控制器、网关、工控机……
物联网·云计算·智能家居·工业自动化
Smartlabs16 天前
Matter协议开发者指南:使用Matter SDK构建智能家居应用
智能家居·matter·matter方案·matter协议
华普微HOPERF17 天前
让温度“说话”,数字温度传感器如何智能感知温度?
科技·单片机·嵌入式硬件·物联网·智能家居
花开月满西楼20 天前
Android实例项目【智能家居系统】实现数据库登录注册+动画效果+网页跳转+短信发送!!!
android·数据库·智能家居
华一精品Adreamer20 天前
定制平板在智能家居中能做些什么?全面解析其核心功能
智能家居·平板
13631676419侯24 天前
ESP32-C3FH4X—低功耗、高集成度的 MCU 系统级芯片 (SoC)
嵌入式硬件·智能家居·芯片
riveting25 天前
明远智睿SD2351核心板:边缘计算时代的工业级核心引擎深度解析
人工智能·功能测试·音频·智能家居·边缘计算·智能硬件