目录

一、智能家居项目框架设计草图

二、框架代码文件工程建立

三、添加声音识别模块的串口读取功能


一、智能家居项目框架设计草图

代码思路讲解:

1、一个指令工厂,一个控制工厂,实际上就是通过链表链起来的数据。具体怎么链接起来,就是基于简单工厂模式的类与对象的概念,上一篇文章有学习记录。
2、主函数语音指令程序和tcp指令程序各起一个线程,然后通过指令名字找到对应的控制程序,实现对应的模块的功能。

二、框架代码文件工程建立

1、在桌面新建一个项目文件夹smartHose,然后在文件夹中创建如下文件:

2、把上述的所有文件,都加载到Source lnsight工具中,如下图代表加载完毕

3、创建inputCommand.h头文件

//面向指令工厂的头文件
#include <wiringPi.h>
#include <stdlib.h>struct InputCommander{char commandName[128];             //名字char command[32];                  //指令int (*Init)(char *name,char *ipAdress,char *port);  //操作函数 int (*getCommand)(char *cmd);      //获取数据函数char log[1024];                    //log日志获取struct InputCommander *next;
};

4、创建contrlDevices.h头文件

//设备头文件
#include <wiringPi.h>struct Devices{char deviceName[128]; //名字int status;           //状态int pinNum;           //引脚int (*open)(int pinNum);        //打开int (*close)(int pinNum);       //关闭int (*deviceInit)(int pinNum);  //设备初始化int (*readStatus)();  //火灾int (*changeStatus)(int status);struct Devices *next;
};struct Devices* addBathroomLightToDeviceLink(struct Devices *phead);
struct Devices* addUpstairLightToDeviceLink(struct Devices *phead);
struct Devices* addLivingRoomLightToDeviceLink(struct Devices *phead);
struct Devices* addRestaurantLightToDeviceLink(struct Devices *phead);
struct Devices* addFireToDeviceLink(struct Devices *phead);

5、创建bathroomLight.c文件

//浴室的灯
#include "contrlDevices.h"
#include<stdlib.h>int bathroomLightOpen(int pinNum){digitalWrite(pinNum,LOW);
}
int bathroomLightClose(int pinNum){digitalWrite(pinNum,HIGH);
}
int bathroomLightCloseInit(int pinNum){pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);
}
int bathroomLightCloseStatus(int status){}
struct Devices bathroomLight={.deviceName = "bathroomLight",.pinNum = 26,.open = bathroomLightOpen,.close = bathroomLightClose,.deviceInit = bathroomLightCloseInit,.changeStatus = bathroomLightCloseStatus};
struct Devices* addBathroomLightToDeviceLink(struct Devices *phead){if(phead == NULL){    return &bathroomLight;}else{bathroomLight.next = phead;phead = &bathroomLight;}
};

6、创建livingroomLight.c文件

#include "contrlDevices.h"
#include<stdlib.h>int livingroomLightOpen(int pinNum){digitalWrite(pinNum,LOW);
}
int livingroomLightClose(int pinNum){digitalWrite(pinNum,HIGH);
}
int livingroomLightCloseInit(int pinNum){pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);
}
int livingroomLightCloseStatus(int status){}
struct Devices livingroomLight={.deviceName = "livingroomLight",.pinNum = 27,.open = livingroomLightOpen,.close = livingroomLightClose,.deviceInit = livingroomLightCloseInit,.changeStatus = livingroomLightCloseStatus};
struct Devices* addLivingRoomLightToDeviceLink(struct Devices *phead){if(phead == NULL){  return &livingroomLight;}else{livingroomLight.next = phead;phead = &livingroomLight;}
};

7、创建restaurantLight.c文件

#include "contrlDevices.h"
#include<stdlib.h>int restaurantLightOpen(int pinNum){digitalWrite(pinNum,LOW);
}
int restaurantLightClose(int pinNum){digitalWrite(pinNum,HIGH);
}
int restaurantLightCloseInit(int pinNum){pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);
}
int restaurantLightCloseStatus(int status){}
struct Devices restaurantLight={.deviceName = "restaurantLight",.pinNum = 28,.open = restaurantLightOpen,.close = restaurantLightClose,.deviceInit = restaurantLightCloseInit,.changeStatus = restaurantLightCloseStatus
};
struct Devices* addRestaurantLightToDeviceLink(struct Devices *phead){if(phead == NULL){  return &restaurantLight;}else{restaurantLight.next = phead;phead = &restaurantLight;}
};

8、创建upstairLight.c文件

//二楼灯
#include "contrlDevices.h"
#include<stdlib.h>int upstairLightOpen(int pinNum){digitalWrite(pinNum,LOW);
}
int upstairLightClose(int pinNum){digitalWrite(pinNum,HIGH);
}
int upstairLightCloseInit(int pinNum){pinMode(pinNum,OUTPUT);digitalWrite(pinNum,HIGH);
}
int upstairLightCloseStatus(int status){}
struct Devices upstairLight={.deviceName = "upstairLight",.pinNum = 29,.open = upstairLightOpen,.close = upstairLightClose,.deviceInit = upstairLightCloseInit,.changeStatus = upstairLightCloseStatus
};
struct Devices* addUpstairLightToDeviceLink(struct Devices *phead){if(phead == NULL){ return &upstairLight;}else{upstairLight.next = phead;phead = &upstairLight;}
};

9、创建fire.c文件

//火灾报警
#include "contrlDevices.h"
#include<stdlib.h>int fireIfOrNotInit(int pinNum){pinMode(pinNum,INPUT);digitalWrite(pinNum,HIGH);
}
int fireStatusRead(int pinNum){return digitalRead(pinNum);
}
struct Devices fireIfOrNot={.deviceName = "fireIfOrNot",.pinNum = 25,.deviceInit = fireIfOrNotInit,.readStatus = fireStatusRead};
struct Devices* addFireToDeviceLink(struct Devices *phead){if(phead == NULL){ return &fireIfOrNot;}else{fireIfOrNot.next = phead;phead = &fireIfOrNot;}
};

10、创建mainPro.c主函数文件

#include <stdio.h>
#include "contrlDevices.h"
#include <string.h>
#include "inputCommand.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;if(-1 == wiringPiSetup()){return -1;}struct Devices *pdeviceHead = NULL;pdeviceHead = addBathroomLightToDeviceLink(pdeviceHead);pdeviceHead = addUpstairLightToDeviceLink(pdeviceHead);pdeviceHead = addLivingRoomLightToDeviceLink(pdeviceHead);pdeviceHead = addRestaurantLightToDeviceLink(pdeviceHead);pdeviceHead = addFireToDeviceLink(pdeviceHead);while(1){printf("Input:\n");scanf("%s",name);tmp = findDeviceByName(name,pdeviceHead);if(tmp != NULL){tmp->deviceInit(tmp->pinNum);tmp->open(tmp->pinNum);}}//1、指令工厂初始化//2、设备控制工厂初始化//3、线程池建立//3.1、语音线程//3.2、socket线程//3.3、摄像头线程//3.4、火灾线程
}

把上述的代码传到树莓派的终端,用FileZilla传即可,然后执行结果:

gcc mainPro.c upstairLight.c bathroomLight.c livingroomLight.c restaurantLight.c -lwiringPi -o test1

效果演示:(虽然没有装到实际的智能家居里,但是小灯亮了,说明程序是可以正常用的

智能家居项目(三)之框架设计及框架代码文件工程建立相关推荐

  1. 视频教程-5G物联网云平台智能家居项目30天搞定-物联网技术

    5G物联网云平台智能家居项目30天搞定 我叫连志安,现任职广东长虹技术研究所(国企).之前在康佳集团(国企).CVTE(上市公司)等公司任职.负责过Android TV.智能网关.路由器.智能家居.安 ...

  2. 智能家居项目开发: 设计模式(工厂模式)+ 线程池 + Socket (持续更新中)

    智能家居项目开发 一.智能家居功能细节拆分 控制区: 外设区: 面向对象类和对象的概念 结构体新玩法 二.工厂模式 1. 工厂模式的概念 2. 工厂模式的实现 3. 工厂模式使用及功能验证 三.智能家 ...

  3. 树莓派智能家居项目整合(包含语音、socket、火灾、摄像头线程)

    树莓派智能家居项目一 1.百度网盘下载代码链接 2.main.c 3.段错误 4.C语言的函数声明 4.1没声明的报错内容 5.关于报错,调试程序 坎坎坷坷,墨墨迹迹了这么久也算是完成了四个线程的同时 ...

  4. 某智能家居项目框架学习总结

    这个月来第一篇博客,各种其他事情.. 之前负责过一个智能家居项目的二次开发,苏州一家公司做的,项目还是分了好几个系统,对业务流程的不同部分进行了划分,我是此项目的主要负责人,通过老师的指导,对这个项目 ...

  5. 智能家居 (8) ——智能家居项目整合(网络控制线程、语音控制线程,火灾报警线程)

    目录 mainPro.c(主函数) 指令工厂 inputCommand.h voiceControl.c(语音控制) socketControl.c(网络线程) 控制工厂 contrlEquipmen ...

  6. 智能家居项目开发准备工作

    智能家居功能细节拆分: 控制端支持语音设备的输入(用到之前所学习的LD3320语音识别模块)或者是socket客户端(这个客户端可以是ftp项目的客户端也可以是Android的app),主控芯片是树莓 ...

  7. 嵌入式智能家居项目视频监控_智能化您的视频嵌入

    嵌入式智能家居项目视频监控 Video content is taking over the Internet. The trend began long ago and the most recen ...

  8. 智能家居项目开发(一):简单工厂设计模式引入

    智能家居项目开发 一.智能家居功能细节拆分 二.设计模式概念的引入 三.类与对象 四.结构体新玩法 五.工厂模式 一.智能家居功能细节拆分 1.控制区 我们会用到之前学过的: 语音识别模块 socke ...

  9. android 智能家居 pdf,智能家居项目化教程.pdf

    作 者 :曾文波,伦硕波,黄日胜,钟建坤编著 出版发行 : 北京:中国水利水电出版社 , 2019.03 ISBN号 :978-7-5170-6858-7 页 数 : 151 原书定价 : 27.00 ...

最新文章

  1. IDEA 配置maven
  2. 举例分析Linux动态库和静态库
  3. poj1273 最大流
  4. 修改内核的启动logo
  5. [USACO 2012 Feb Gold] Cow Coupons【贪心 堆】
  6. Atitit mysql 数据类型 5.7.9 目录 1.1. 数值类型 1 2. 字符串 2 3. 时间日期 2 4. 地理位置 2 5. 几何数据的存储,生成,分析,优化。 空间数据类型(存储)
  7. linux lvm的管理
  8. Cesium加载GeoJson数据
  9. Adobe Flash Player32 离线安装包及菁苗软件打开白屏的解决方法
  10. word转PDF,导航窗格输出目录
  11. Activity生命周期
  12. Ubuntu无法调节屏幕亮度问题
  13. Eclipse Error - Error notifying a preference...
  14. 环境会计信息披露问题研究
  15. 中基鸿业家庭理财注意事项
  16. 防止前端重复提交表单
  17. AI 入行那些事儿(13)人工智能的三类技术岗位
  18. 【Android每周专题】触摸屏手势
  19. VBS带你领略脚本语言的快乐!(实战篇—死循环)
  20. ebs开发入门 oracle 知乎_知乎日报

热门文章

  1. Python基础教程读书笔记(第1章—第2章:基础知识、列表和元组)
  2. 平台多样化:Gavin Grover的Groovy之路
  3. Flink CEP 介绍及其使用场景
  4. mac连接mysql出现 Access denied for user ‘Lampard‘@‘localhost‘ (using password: NO)
  5. 【printf函数】vprintf使用参数列表(va_list)传递参数
  6. 【机器学习与深度学习理论要点】10.什么是置信概率、什么是交叉验证、解决类别不均衡问题?
  7. UOS安装腾讯视频客户端
  8. 自考总结 数据库系统原理
  9. 年轻人秃了,这家公司却赚翻了
  10. 最骚操作的二分查找,秀儿?