学怎么做建筑标书哪个网站,潍坊网站建设公司,注册教育培训机构需要什么条件,南京网站建设招标目录 一、主流程设计 
1、工厂模式结构体定义 #xff08;1#xff09;指令工厂 inputCmd.h 
#xff08;2#xff09;外设工厂 controlDevices.h 
二、外设框架编写 
1、创建外设工厂对象bathroomLight 
2、编写相关函数框架 
3、将浴室灯相关操作插入外设工厂链表等待被调…目录 一、主流程设计 
1、工厂模式结构体定义 1指令工厂 inputCmd.h 
2外设工厂 controlDevices.h 
二、外设框架编写 
1、创建外设工厂对象bathroomLight 
2、编写相关函数框架 
3、将浴室灯相关操作插入外设工厂链表等待被调用 
三、外设框架测试 
1、配置IO口输出状态 
2、将函数加入到controlDevices.h 
3、main函数编写 
四、编写完成后拷贝到树莓派运行 
1、创建一个文件夹用于保存上面所编写的三个代码 
2、查看使用的GPIO口位于第几个引脚 
3、编译运行 一、主流程设计 
#include stdio.hint main(){//指令工厂初始化//控制外设工厂初始化//线程池return 0;
} 
1、工厂模式结构体定义 1指令工厂 inputCmd.h 
struct InputCmd{char cmdName[128];//指令名称char cmd[32];//指令int (*Init)(char *name,char *ipAdresschar *port);//初始化函数int (*getCmd)(char *cmd);//获取指令函数char *log[1024];//日志struct InputCmd *next;
}; 
定义一个名为 InputCmd 的结构体包含以下成员 
char cmdName[128]一个长度为128的字符数组用于存储指令名称。char cmd[32]一个长度为32的字符数组用于存储指令。int (*Init)(char *name, char *ipAdress, char *port)一个初始化相关指令操作的函数指针它指向一个返回值为整型接受三个字符指针类型的参数名称、IP地址、端口号的函数。int (*getCmd)(char *cmd)一个用于获取指令的函数指针它指向一个返回值为整型接受一个字符指针类型的参数指令的函数。char *log[1024]一个长度为1024的字符指针数组用于存储日志信息。struct InputCmd *next一个指向 struct InputCmd 类型的指针用于链表的连接。 2外设工厂 controlDevices.h 
struct Devices{char devicesName[128];//设备名称int status;//状态开关int pinNum;//引脚号int (*open)(int pinNum);//打开设备int (*close)(int pinNum);//关闭设备int (*devicesInit)(int pinNum);//设备初始化int (*readStatus)();//读取设备状态int (*changeStatus)(int status);//改变设备状态struct Devices *next;
}; 
定义一个名为 Devices 的结构体包含以下成员 
char devicesName[128]一个长度为128的字符数组用于存储设备名称。int status一个整型变量用于存储设备的状态如开/关等。int pinNum一个整型变量用于存储设备的引脚号。int (*open)(int pinNum)一个用于打开相关设备的函数指针它指向一个返回值为整型、接受一个整型的参数引脚号的函数。int (*close)(int pinNum)一个用于关闭相关设备的函数指针它指向一个返回值为整型、接受一个整型的参数引脚号的函数。int (*devicesInit)(int pinNum)一个用于初始化相关设备的函数指针它指向一个返回值为整型、接受一个整型的参数引脚号的函数。int (*readStatus)()一个用于读取设备当前状态的函数指针它指向一个返回值为整型、无参数的函数。int (*changeStatus)(int status)一个用于更改设备状态的函数指针它指向一个返回值为整型接受一个字符指针类型的参数设备状态的函数。struct Devices *next一个指向 struct Devices 类型的指针通常链表的连接。 二、外设框架编写 
以浴室灯模块为例 
bathroomLight.c 
1、创建外设工厂对象bathroomLight 
struct Devices bathroomLight{.namebathroomLight,.pinNum你选择的引脚号,.openbathroomLight_open,.closebathroomLight_close,.devicesInitbathroomLight_init,.changeStatusbathroomLight_status
}; 
2、编写相关函数框架 int bathroomLight_open(int pinNum){}int bathroomLight_close(int pinNum){}int bathroomLight_init(int pinNum){}int bathroomLight_status(int status){}3、将浴室灯相关操作插入外设工厂链表等待被调用 
sturct  Devices *addbathroomLightToDevicesLink(struct Devices *phead){if(pheadNULL){ruturn bathroomLight;}else{bathroomLight.nextphead;pheadbathroomLight;}
} 
三、外设框架测试 
1、配置IO口输出状态 
pinMode()和digitalWrite()都是WiringPi库的函数要包含wiringPi.h头文件(我在controlDevices.h里面包含了 bathroomLight.c 
#include controlDevices.hint bathroomLight_open(int pinNum){digitalWrite(pinNum,LOW);
}int bathroomLight_close(int pinNum){digitalWrite(pinNum,HIGH);
}int bathroomLight_init(int pinNum){pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);
}int bathroomLight_status(int status){}struct Devices bathroomLight{.devicesNamebathroomLight,.pinNum1,.openbathroomLight_open,.closebathroomLight_close,.devicesInitbathroomLight_init,.changeStatusbathroomLight_status
};struct  Devices* addbathroomLightToDevicesLink(struct Devices *phead){if(phead NULL){return bathroomLight;}else{bathroomLight.nextphead;pheadbathroomLight;}
} 
2、将函数加入到controlDevices.h 
controlDevices.h 
#include wiringPi.h
#include stdio.hstruct Devices{char devicesName[128];int status;int pinNum;int (*open)(int pinNum);int (*close)(int pinNum);int (*devicesInit)(int pinNum);int (*readStatus)();int (*changeStatus)(int status);struct Devices *next;
};struct Devices *addbathroomLightToDevicesLink(struct Devices *phead);3、main函数编写 
1判断树莓派接口是否初始化成功 2将浴室灯模块加入到工厂模式的链表中等待被调用 3判断实现 mainPro.c 
#include stdio.h
#include string.h#include controlDevices.hstruct Devices *findDevicesName(char *name,struct Devices *phead){struct Devices *tmpphead;if(pheadNULL){return NULL;}else{while(tmp!NULL){if(strcmp(tmp-devicesName,name)0){return tmp;}tmptmp-next;}return NULL;}
}int main(){if(wiringPiSetup()-1){return -1;}struct Devices *pdevicesHeadNULL;pdevicesHeadaddbathroomLightToDevicesLink(pdevicesHead);char *namebathroomLight;struct Devices *tmpfindDevicesName(name,pdevicesHead);if(tmp!NULL){tmp-devicesInit(tmp-pinNum);tmp-open(tmp-pinNum);	}return 0;
} 
四、编写完成后拷贝到树莓派运行 
1、创建一个文件夹用于保存上面所编写的三个代码 2、查看使用的GPIO口位于第几个引脚 
我是用继电器进行测试 3、编译运行 
小插曲 编译 运行后可以听见继电器“哒” 的一声 输入gpio readall后查看发现GPIO1已经变为OUT 
 文章转载自: http://www.morning.bwqr.cn.gov.cn.bwqr.cn http://www.morning.zdmrf.cn.gov.cn.zdmrf.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.kybyf.cn.gov.cn.kybyf.cn http://www.morning.kpzbf.cn.gov.cn.kpzbf.cn http://www.morning.qsmmq.cn.gov.cn.qsmmq.cn http://www.morning.jmbgl.cn.gov.cn.jmbgl.cn http://www.morning.hhqjf.cn.gov.cn.hhqjf.cn http://www.morning.mrfgy.cn.gov.cn.mrfgy.cn http://www.morning.rfyff.cn.gov.cn.rfyff.cn http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn http://www.morning.ggnkt.cn.gov.cn.ggnkt.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.fnjrh.cn.gov.cn.fnjrh.cn http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn http://www.morning.nndbz.cn.gov.cn.nndbz.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.xqknl.cn.gov.cn.xqknl.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.lkmks.cn.gov.cn.lkmks.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.syqtt.cn.gov.cn.syqtt.cn http://www.morning.lgmty.cn.gov.cn.lgmty.cn http://www.morning.hrpjx.cn.gov.cn.hrpjx.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.kpgms.cn.gov.cn.kpgms.cn http://www.morning.saastob.com.gov.cn.saastob.com http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.yjdql.cn.gov.cn.yjdql.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.rfqk.cn.gov.cn.rfqk.cn http://www.morning.kdnrp.cn.gov.cn.kdnrp.cn http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.xflwq.cn.gov.cn.xflwq.cn http://www.morning.rdng.cn.gov.cn.rdng.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.gkmwk.cn.gov.cn.gkmwk.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.jgnst.cn.gov.cn.jgnst.cn http://www.morning.wjxtq.cn.gov.cn.wjxtq.cn http://www.morning.qjxxc.cn.gov.cn.qjxxc.cn http://www.morning.hrtct.cn.gov.cn.hrtct.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.mfsjn.cn.gov.cn.mfsjn.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.ljygq.cn.gov.cn.ljygq.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.qbtj.cn.gov.cn.qbtj.cn http://www.morning.bncrx.cn.gov.cn.bncrx.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.zdxss.cn.gov.cn.zdxss.cn http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn http://www.morning.lnmby.cn.gov.cn.lnmby.cn http://www.morning.fkffr.cn.gov.cn.fkffr.cn http://www.morning.blxlf.cn.gov.cn.blxlf.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.qhrlb.cn.gov.cn.qhrlb.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.kbqws.cn.gov.cn.kbqws.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.ctswj.cn.gov.cn.ctswj.cn http://www.morning.jcwrb.cn.gov.cn.jcwrb.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.sdktr.com.gov.cn.sdktr.com http://www.morning.fwqgy.cn.gov.cn.fwqgy.cn http://www.morning.rzsxb.cn.gov.cn.rzsxb.cn http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn http://www.morning.zmqb.cn.gov.cn.zmqb.cn http://www.morning.rrgm.cn.gov.cn.rrgm.cn