赞
踩
主控芯片——树莓派
控制端支持语音设备的输入uart,也可以是安卓app(tcp客户端)
外设——灯:客厅灯、餐厅灯、二楼灯、卫生间灯;
火灾报警器
摄像头:监控、人脸锁
433M:泳池灯、实景智能窗帘
红外——电风扇、电视、空调、小夜灯
如下图,一边是指令工厂、一边是控制工厂,main函数负责组织架构
1、树莓派控制灯的实现
接线:灯的接线,orangepi2、5、7、8接4联继电器1,2,3,4,
客厅——2
餐厅——5脚
卫生间灯——7脚,
二楼灯——8脚,
代码:
mainPro.c
#include <stdio.h> #include <string.h> #include "controlDevices.h" struct Devices *findDeviceByName(char *name,struct Devices *phead) { struct Devices *tmp =phead; if(phead==NULL){ return NULL; }else{ while(tmp!=NULL){ if(strcmp(tmp->deviceName,name)==0){ return tmp; } tmp=tmp->next; } } } int main() { char name[32]; struct Devices *tmp=NULL; if(wiringPiSetup()==-1) return -1; struct Devices *pdeviceHead=NULL; pdeviceHead=addBathroomLightToDeviceLink(pdeviceHead); pdeviceHead=addupstairLightToDeviceLink(pdeviceHead); pdeviceHead=addresturantLightToDeviceLink(pdeviceHead); pdeviceHead=addlivingroomLightToDeviceLink(pdeviceHead); while(1){ printf("你想要点亮哪盏灯\n"); scanf("%s",name); tmp= findDeviceByName(name,pdeviceHead); if(tmp!=NULL){ tmp->deviceInit(tmp->pinNum); tmp->close(tmp->pinNum);//这里控制打开和关闭,关闭是close,打开是open } } //1.指令工厂初始化 //2.设备工厂初始化 //3.线程池建立 //3.1语音线程 //3.2socket线程 //3.3摄像头线程 //3.4火灾线程 return 0; }controlDevices.h
#include <wiringPi.h> struct Devices { char deviceName[128];//名字 int status;//状态 int pinNum; int (*open)(int pinNum);//打开 int (*close)(int pinNum);//关闭 int (*deviceInit)(int pinNum);//初始化 int (*readStatus)();//火灾传感器状态 int (*changeStatus)(int status); struct Devices *next; }; struct Devices *addBathroomLightToDeviceLink(struct Devices *phead); struct Devices *addupstairLightToDeviceLink(struct Devices *phead); struct Devices *addlivingroomLightToDeviceLink(struct Devices *phead); struct Devices *addresturantLightToDeviceLink(struct Devices *phead);livingroomLight.c
#include "controlDevices.h" #include <stddef.h> int livingroomLightOpen(int pinNum) { digitalWrite(pinNum,LOW); } int livingroomLightClose(int pinNum) { digitalWrite(pinNum,HIGH); } int livingroomLightInit(int pinNum) { pinMode(pinNum,OUTPUT); digitalWrite(pinNum,HIGH); } int livingroomLightStatus(int status) { } struct Devices livingroomLight={ .deviceName="livingroomLight", .pinNum=2, .open=livingroomLightOpen, .close=livingroomLightClose, .deviceInit=livingroomLightInit, .changeStatus=livingroomLightStatus }; struct Devices *addlivingroomLightToDeviceLink(struct Devices *phead) { if(phead==NULL){ phead=&livingroomLight; return phead; }else{ livingroomLight.next=phead; phead=&livingroomLight; return phead; } };resturantLight.c
#include "controlDevices.h" #include <stddef.h> int resturantLightOpen(
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。