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

空间站建设谷歌关键词搜索

空间站建设,谷歌关键词搜索,一手网推项目平台,通化网站建设用户手册对应的I/O 工厂模式实现继电器灯控制 代码段 controlDevice.h(设备设备)main.c(主函数)bathroomLight.c(浴室灯)bedroomLight.c(卧室灯)restaurantLight.c(餐厅…

用户手册对应的I/O
工厂模式实现继电器灯控制
代码段

  • controlDevice.h(设备设备)
  • main.c(主函数)
  • bathroomLight.c(浴室灯)
  • bedroomLight.c(卧室灯)
  • restaurantLight.c(餐厅灯)
  • livingroomLight.c(客厅灯)
  • 编译
  • 运行结果

用户手册对应的I/O在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

工厂模式实现继电器灯控制

在这里插入图片描述

在这里插入图片描述

代码段

controlDevice.h(设备类)

#include <wiringPi.h>					//wiringPi库
#include <stdio.h>
#include <stdlib.h>struct Devices                          //设备类
{char deviceName[128];               //设备名int status;                         //状态int pinNum;							//引脚号int (*Init)(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);		//“浴室灯”加入设备链表函数声明 2
struct Devices* addBedroomLightToDeviceLink(struct Devices *phead);	        //“卧室灯”加入设备链表函数声明 8
struct Devices* addRestaurantLightToDeviceLink(struct Devices *phead);		//“餐厅灯”加入设备链表函数声明 13
struct Devices* addLivingroomLightToDeviceLink(struct Devices *phead);		//“客厅灯”加入设备链表函数声明 16

main.c(主函数)

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "controlDevice.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;}return NULL;}
}int main()
{char name[128];struct Devices *tmp = NULL;// 初始化wiringPi库if (wiringPiSetup() == -1) {fprintf(stdout, "Unable to start wiringPi: %s\n", strerror(errno));return 1;}// 定义初始设备链表头struct Devices *pdeviceHead = NULL;// “浴室灯”加入设备链表pdeviceHead = addBathroomLightToDeviceLink(pdeviceHead);// “卧室灯”加入设备链表pdeviceHead = addBedroomLightToDeviceLink(pdeviceHead);// “餐厅灯”加入设备链表pdeviceHead = addRestaurantLightToDeviceLink(pdeviceHead);// “客厅灯”加入设备链表pdeviceHead = addLivingroomLightToDeviceLink(pdeviceHead);// 无限循环,接受用户输入while (1){printf("Input:\n");scanf("%s", name);tmp = findDeviceByName(name, pdeviceHead);// 如果找到设备if (tmp != NULL) {tmp->Init(tmp->pinNum); // 先初始化tmp->open(tmp->pinNum); // 打开设备}}return 0;
}

bathroomLight.c(浴室灯)

#include "controlDevice.h"			//自定义设备类的文件int bathroomLightInit(int pinNum)           //C语言必须要传参,JAVA不用,可直接访问变量的值
{pinMode(pinNum,OUTPUT);					//配置引脚为输出模式digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int bathroomLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);				//引脚置低电平,闭合继电器
}int bathroomLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int bathroomLightStatus(int status)
{}struct Devices bathroomLight = {			//定义浴室灯(对象).deviceName = "bathroomLight",			//名字.pinNum = 2,							//香橙派 2号(wPi)引脚.Init = bathroomLightInit,				//指定初始化函数.open = bathroomLightOpen,				//指定“打开灯”函数.close = bathroomLightClose,			//指定“关闭灯”函数.changeStatus = bathroomLightStatus
};struct Devices* addBathroomLightToDeviceLink(struct Devices *phead)		//浴室灯(对象)加入设备链表函数
{if (phead == NULL) {return &bathroomLight;}else {bathroomLight.next = phead;  //以前的头变成.nextphead = &bathroomLight;      //更新头return phead;}
}

bedroomLight.c(卧室灯)

#include "controlDevice.h"int bedroomLightInit(int pinNum)            //C语言必须要传参,JAVA不用,可直接访问变量的值
{pinMode(pinNum,OUTPUT);					//配置引脚为输出模式digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int bedroomLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);				//引脚置低电平,闭合继电器
}int bedroomLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int bedroomLightStatus(int status)
{}struct Devices bedroomLight = {			//定义卧室灯(对象).deviceName = "bedroomLight",		//名字.pinNum = 8,						//香橙派 8号(wPi)引脚.Init = bedroomLightInit,			//指定初始化函数.open = bedroomLightOpen,			//指定“打开灯”函数.close = bedroomLightClose,			//指定“关闭灯”函数.changeStatus = bedroomLightStatus
};struct Devices* addBedroomLightToDeviceLink(struct Devices *phead)		//卧室灯(对象)加入设备链表函数
{if (phead == NULL) {return &bedroomLight;}else {bedroomLight.next = phead;  //以前的头变成.nextphead = &bedroomLight;      //更新头return phead;}
}

restaurantLight.c(餐厅灯)

#include "controlDevice.h"			//自定义设备类的文件int restaurantLightInit(int pinNum)         //C语言必须要传参,JAVA不用,可直接访问变量的值
{pinMode(pinNum,OUTPUT);					//配置引脚为输出模式digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int restaurantLightOpen(int pinNum)
{digitalWrite(pinNum,LOW);				//引脚置低电平,闭合继电器
}int restaurantLightClose(int pinNum)
{digitalWrite(pinNum,HIGH);				//引脚置高电平,断开继电器
}int restaurantLightStatus(int status)
{}struct Devices restaurantLight = {			//定义餐厅灯(对象).deviceName = "restaurantLight",		//名字.pinNum = 13,							//香橙派 13号(wPi)引脚.Init = restaurantLightInit,			//指定初始化函数.open = restaurantLightOpen,			//指定“打开灯”函数.close = restaurantLightClose,			//指定“关闭灯”函数.changeStatus = restaurantLightStatus
};struct Devices* addRestaurantLightToDeviceLink(struct Devices *phead)		//餐厅灯(对象)加入设备链表函数
{if (phead == NULL) {return &restaurantLight;}else {restaurantLight.next = phead;  //以前的头变成.nextphead = &restaurantLight;      //更新头return phead;}
}

livingroomLight.c(客厅灯)

#include "controlDevice.h" //自定义设备类的文件int livingroomLightInit(int pinNum) // C语言必须要传参,JAVA不用,可直接访问变量的值
{pinMode(pinNum, OUTPUT);	// 配置引脚为输出模式digitalWrite(pinNum, HIGH); // 引脚置高电平,断开继电器
}int livingroomLightOpen(int pinNum)
{digitalWrite(pinNum, LOW); // 引脚置低电平,闭合继电器
}int livingroomLightClose(int pinNum)
{digitalWrite(pinNum, HIGH); // 引脚置高电平,断开继电器
}int livingroomLightStatus(int status)
{
}struct Devices livingroomLight = {	 // 定义客厅灯(对象).deviceName = "livingroomLight", // 名字.pinNum = 16,					 // 香橙派 16号(wPi)引脚.Init = livingroomLightInit,	 // 指定初始化函数.open = livingroomLightOpen,	 // 指定“打开灯”函数.close = livingroomLightClose,	 // 指定“关闭灯”函数.changeStatus = livingroomLightStatus};struct Devices *addLivingroomLightToDeviceLink(struct Devices *phead) // 客厅灯(对象)加入设备链表函数
{if (phead == NULL) {return &livingroomLight;}else {livingroomLight.next = phead; // 以前的头变成.nextphead = &livingroomLight;	  // 更新头return phead;}
}

编译

gcc *.c -lwiringPi -lwiringPiDev -lpthread -lm -lcrypt -lrt

在这里插入图片描述

运行结果

在这里插入图片描述
在这里插入图片描述

http://www.hkea.cn/news/267882/

相关文章:

  • 一般做网站用什么字体比较合适搜索引擎营销是什么
  • 去什么网站发贴做推广seo及网络推广招聘
  • 如何批量建站什么是互联网营销
  • 哈尔滨网站建设如何搭建一个网站平台
  • 哪些网站可以做任务网络营销推广的基本手段
  • 互联网舆情报告什么是seo营销
  • 餐饮商家做网站的好处沈阳关键词优化费用
  • 如何把网站的文字编辑网站页面优化内容包括哪些
  • 安徽做公司网站哪家好销售策略和营销策略
  • 做游戏都需要什么网站吗域名注册腾讯云
  • 北京建设厅网站谷歌关键词搜索
  • 如何识别一个网站是否做的好谷歌关键词挖掘工具
  • 网站建设专家网店营销推广
  • 做试玩网站搜索引擎优化答案
  • 外贸家具网站百度引擎搜索网址
  • 公司网站的栏目设置肇庆seo优化
  • 如何制作一个论坛网站网络服务器配置与管理
  • 北京中国建设部网站有什么平台可以推广
  • flash网站优缺点厦门百度seo
  • 贵阳利于优化的网站百度搜索引擎推广步骤
  • 金色 网站 模板外链是什么
  • 网站有多难做如何做推广引流赚钱
  • 建设企业网站怎么样百度首页 百度
  • 热烈祝贺网站上线泉州seo代理计费
  • 网站平台建设意见长沙有实力seo优化
  • 深圳网站如何制作西安seo网站推广优化
  • 网站建设业务文案网站seo检测工具
  • 石家庄做外贸网站建设现在最好的营销方式
  • 兰州做网站公司有哪些html+css网页制作成品
  • 福州做网站的公司多少钱信息流优化