本文主要是介绍【智能家居】7、主程序编写+实现语音、网络和串口功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
需要毕业论文私信有偿获取
截止目前mainPro.c代码
#include <stdio.h>
#include <string.h>#include "controlDevices.h"
#include "inputCmd.h"struct Devices *findDevicesName(char *name,struct Devices *phead){struct Devices *tmp=phead;if(phead==NULL){return NULL;}else{while(tmp!=NULL){if(strcmp(tmp->devicesName,name)==0){return tmp;}tmp=tmp->next;}return NULL;}
}int main(){if(wiringPiSetup()==-1){return -1;}struct Devices *pdevicesHead=NULL;struct InputCmd *pinputCmdHead=NULL;pdevicesHead=addbathroomLightToDevicesLink(pdevicesHead);pdevicesHead=addupstairLightToDevicesLink(pdevicesHead);pdevicesHead=addlivingroomLightToDevicesLink(pdevicesHead);pdevicesHead=addrestaurantLightToDevicesLink(pdevicesHead);pdevicesHead=addFireToDevicesLink(pdevicesHead);pinputCmdHead=addVoiceToInputCmdLink(pinputCmdHead);pinputCmdHead=addSocketToInputCmdLink(pinputCmdHead);char name[128]={'\0'};struct Devices *tmp=NULL;while(1){printf("INPUT:\n");scanf("%s",name);tmp=findDevicesName(name,pdevicesHead);if(tmp!=NULL){tmp->devicesInit(tmp->pinNum);tmp->open(tmp->pinNum); tmp->readStatus(tmp->pinNum);}}return 0;
}
一、编写流程
1、工厂初始化
将指令和设备结构体指针定义为全局变量
(1)指令工厂初始化
/*指令工厂初始化*/pinputCmdHead=addVoiceToInputCmdLink(pinputCmdHead);pinputCmdHead=addSocketToInputCmdLink(pinputCmdHead);
(2)设备控制工厂初始化
/*设备工厂初始化*/
pdevicesHead=addbathroomLightToDevicesLink(pdevicesHead);
pdevicesHead=addupstairLightToDevicesLink(pdevicesHead);
pdevicesHead=addlivingroomLightToDevicesLink(pdevicesHead);
pdevicesHead=addrestaurantLightToDevicesLink(pdevicesHead);
pdevicesHead=addFireToDevicesLink(pdevicesHead);
2、查找指令名称函数
struct InputCmd *findCmdName(char *name,struct InputCmd *phead){struct InputCmd *tmp=phead;if(phead==NULL){re
这篇关于【智能家居】7、主程序编写+实现语音、网络和串口功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!