需要毕业论文私信有偿获取
截止目前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