当前位置: 首页 > news >正文

网站开发最佳组合深网网络网站

网站开发最佳组合,深网网络网站,html教程下载,厦门手机建站采用工厂模式以面向对象的方式来封装各种设备模块&#xff0c;方便整合项目以及后期的维护和扩展 mainPro.c&#xff08;主函数&#xff09; #include <stdio.h> #include "controlDevice.h"struct Devices *pdeviceHead NULL; //设备工厂链…

采用工厂模式以面向对象的方式来封装各种设备模块,方便整合项目以及后期的维护和扩展

mainPro.c(主函数)

#include <stdio.h>
#include "controlDevice.h"struct Devices        *pdeviceHead  = NULL;         //设备工厂链表头struct Devices* findDeviceByName(struct Devices *phead,char *name)          //在设备链表中查找设备
{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;   }}int main()
{if(wiringPiSetup()<0){//初始化wiringPi外设库printf("wiringPi Init failed\n");return -1;}//设备控制工厂初始化pdeviceHead = addBathroomLightToDeviceLink(pdeviceHead);        //将卫生灯加入设备链表pdeviceHead = addbedroomLightToDeviceLink(pdeviceHead);         //将卧室灯加入设备链表pdeviceHead = addRestaurantLightToDeviceLink(pdeviceHead);      //将餐厅灯加入设备链表pdeviceHead = addLivingroomLightToDeviceLink(pdeviceHead);      //将客厅灯加入设备链表pdeviceHead = addFireToDeviceLink(pdeviceHead);                 //将火灾检测加入设备链表pdeviceHead = addBeepToDeviceLink(pdeviceHead);                 //将蜂鸣器加入设备链表

controlDevice.h( 设备类)

#include <wiringPi.h>
#include <stddef.h>struct Devices
{char deviceName[128];                       //设备名字int status;                                 //状态int pinNum;                                 //引脚int (*deviceInit)(int pinNum);              //设备初始化函数指针,后面类似int (*open)(int pinNum);                    //打开设备int (*close)(int pinNum);                   //关闭设备int (*readStatus)(int pinNum);              //读取引脚状态int (*changeStatus)(int status);struct Devices *next;                       //方便链表使用的结构体指针
};struct Devices *addBathroomLightToDeviceLink(struct Devices *phead);        //卫生间灯加入设备链表声明,以下类似
struct Devices *addbedroomLightToDeviceLink(struct Devices *phead);         //卧室灯
struct Devices *addRestaurantLightToDeviceLink(struct Devices *phead);      //餐厅灯
struct Devices *addLivingroomLightToDeviceLink(struct Devices *phead);      //客厅灯
struct Devices *addFireToDeviceLink(struct Devices *phead);                 //火灾检测器
struct Devices *addBeepToDeviceLink(struct Devices *phead);                 //蜂鸣器

bathroomLight.c(浴室灯)

#include "controlDevice.h"int bathroomLightInit(int pinNum)
{pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);}int bathroomLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);
}int bathroomLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);}int bathroomLightChangeStatus()
{//暂时不用,后面用着在完善}struct Devices bathroomLight = {.deviceName = "bathroomLight",.pinNum = 26,.deviceInit = bathroomLightInit,.open  = bathroomLightOpen,.close = bathroomLightClose,.changeStatus = bathroomLightChangeStatus,};struct Devices *addBathroomLightToDeviceLink(struct Devices *phead)		//将浴室灯加入设备链表的函数
{if(phead == NULL){return &bathroomLight;}else{bathroomLight.next=phead;phead = &bathroomLight;return phead;}}

livingroomLight.c(客厅灯)

#include "controlDevice.h"int livingroomLightInit(int pinNum)
{pinMode(pinNum,OUTPUT);//设置引脚为输出模式digitalWrite(pinNum,HIGH);}int livingroomLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);
}int livingroomLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);}int livingroomLightChangeStatus()
{//暂时不用,后面用着在完善}struct Devices livingroomLight = {.deviceName = "livingroomLight",.pinNum = 29,.deviceInit = livingroomLightInit,.open  = livingroomLightOpen,.close = livingroomLightClose,.changeStatus = livingroomLightChangeStatus,};struct Devices *addLivingroomLightToDeviceLink(struct Devices *phead)
{if(phead == NULL){return &livingroomLight;}else{livingroomLight.next=phead;phead = &livingroomLight;return phead;}}

restaurantLight.c(餐厅灯)

#include "controlDevice.h"int restaurantLightInit(int pinNum)
{pinMode(pinNum,OUTPUT);//设置引脚为输出模式digitalWrite(pinNum,HIGH);}int restaurantLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);
}int restaurantLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);}int restaurantLightChangeStatus()
{//暂时不用,后面用着在完善}struct Devices restaurantLight = {.deviceName = "restaurantLight",.pinNum = 28,.deviceInit = restaurantLightInit,.open  = restaurantLightOpen,.close = restaurantLightClose,.changeStatus = restaurantLightChangeStatus,};struct Devices *addRestaurantLightToDeviceLink(struct Devices *phead)
{if(phead == NULL){return &restaurantLight;}else{restaurantLight.next=phead;phead = &restaurantLight;return phead;}}

beedroomLight(卧室灯)

#include "controlDevice.h"int bedroomLightInit(int pinNum)
{pinMode(pinNum,OUTPUT);//设置引脚为输出模式digitalWrite(pinNum,HIGH);}int bedroomLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);
}int bedroomLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);}int bedroomLightChangeStatus()
{//暂时不用,后面用着在完善}struct Devices bedroomLight = {.deviceName = "bedroomLight",.pinNum = 27,.deviceInit = bedroomLightInit,.open  = bedroomLightOpen,.close = bedroomLightClose,.changeStatus = bedroomLightChangeStatus,};struct Devices *addbedroomLightToDeviceLink(struct Devices *phead)
{if(phead == NULL){return &bedroomLight;}else{bedroomLight.next=phead;phead = &bedroomLight;return phead;}}

fire.c(火灾检测)

#include "controlDevice.h"int fireInit(int pinNum)
{pinMode(pinNum,INPUT);//设置引脚为输出模式}int fireStatusRead(int pinNum)
{return digitalRead(pinNum);}int fireChangeStatus()
{//暂时不用,后面用着在完善}struct Devices fire = {.deviceName = "fire",.pinNum = 25,.deviceInit = fireInit,.readStatus = fireStatusRead,.changeStatus = fireChangeStatus,};struct Devices *addFireToDeviceLink(struct Devices *phead)
{if(phead == NULL){return &fire;}else{fire.next=phead;phead = &fire;return phead;}}

beep.c(和火灾检测配合实现火灾报警的蜂鸣器)

#include "controlDevice.h"int beepInit(int pinNum)
{pinMode(pinNum,OUTPUT);//设置引脚为输出模式digitalWrite(pinNum,HIGH);}int beepOpen(int pinNum)
{digitalWrite(pinNum,LOW);}int beepClose(int pinNum)
{digitalWrite(pinNum,HIGH);}int beepChangeStatus()
{//暂时不用,后面用着在完善}struct Devices beep = {.deviceName = "beep",.pinNum = 24,.deviceInit = beepInit,.open = beepOpen,.close = beepClose,.changeStatus = beepChangeStatus,};struct Devices *addBeepToDeviceLink(struct Devices *phead)
{if(phead == NULL){return &beep;}else{beep.next=phead;phead = &beep;return phead;}}
http://www.yayakq.cn/news/802024/

相关文章:

  • 专门做护理PDCA的网站网站定制 动易
  • 沈阳核工业建设工程总公司网站两个网站如何做端口映射
  • 最近军事新闻广州网站优化运营
  • 贵州省住房和城乡建设厅网站人事教育栏网站怎么提升流量
  • 本子网站建设wordpress外贸企业模板
  • 织梦网站教程做网站要运用到代码吗
  • 做网站建设公司网站设计临泉做网站
  • 导航网站网站提交怎么做平凉市崆峒区建设局网站
  • les做ml网站wordpress媒体库 不显示图片
  • 自助提交网站湖南seo优化报价
  • frontpage建设网站的图片wordpress数据库表管理
  • 山东网站备案时间重庆高端设计公司
  • 网站用什么做备份网上写作最好的网站
  • 解析到网站怎样做做网站配送地址怎么变换
  • 手机网站有什么不同做网站的流量怎么算钱
  • 做网站接单的网站网站策划网
  • 快速搭建网站后台免费给网站做seo
  • 有什么引流客源的软件公司网站优化推广
  • wordpress建站教程入门制作网页的工具主要有哪些
  • 盐城做网站网络公司电话?苗木网站建设
  • 网站开发项目视频wordpress 主题分享
  • 网站建设所属行业哪家微网站建设
  • 建设银行网站怎么看不见余额互联网网站怎么做
  • 关于美术馆网站建设的方案哪里网站建设
  • 青岛企业建站dw怎么新建网站
  • 谷歌seo网站推广怎么做优化免费搭建业务网站
  • 不花钱网站推广做网站运营需要学的东西
  • 会计公司网站模板下载做app网站的软件有哪些内容
  • 青岛城市建设局网站上海网上推广
  • 运城有做网站设计搜索引擎推广实训