这是大三所做的项目,距离完成项目的时间已经过去快十个月之久了,至于为什么今天想发出来是因为马上面临找工作了,想把所做的项目再复习复习,,希望能温故而知新吧O(∩_∩)O。
项目名称叫“智慧停车场”通过arduino等硬件设施来模拟停车场的场景,用QT写软件来实时监控停车场的周边环境以及车辆停放信息,通过WIFI实现软硬件的通信
这个小项目由window软件(SmartPark)+udp上行传输(用来实现硬件向软件发送数据)+udp下行传输(用来实现软件向硬件发送消息)+TCP登陆注册(登陆注册)+APP等等组成。 后面再陆续详细的说可能有点麻烦
刚完成时候录的视频
http://player.youku.com/player.php/sid/XMzgwNzIyNDgzMg==/v.swf
先从window软件说起吧:`
window主要由主页面类+消息接收类+消息事件处理类+数据库类+udp通信类。。。等等组成
主页面头文件
#ifndef SHOWPAGE_H
#define SHOWPAGE_H
#include<QPaintEvent>
#include<QMouseEvent>
#include <QWidget>
#include<QLabel>
#include<QPushButton>
#include<QTimer>
#include "firepage.h" //触发火焰传感器的效果界面
#include "camera.h"
#include "widget.h" //一些硬件的控制界面
#include "areaclicked.h" //重写鼠标点击事件,用来找主界面的坐标
#include"handle.h" //事件处理类
class showpage : public QWidget
{
Q_OBJECT
public:
// explicit showpage(QWidget *parent = nullptr);
showpage(QWidget *parent=0);
~showpage();
void carNUM();
protected:
void paintEvent(QPaintEvent *);
void mouseReleaseEvent(QMouseEvent *);
signals:
public slots:
void fristClickedSlot(); //鼠标点击触发的槽函数
void secondClickedSlot();
void thridClickedSlot();
void fristChangSlot(bool);//收到单片机按钮按下信号所触发的槽函数
void secondChangSlot(bool);
void thridChangSlot(bool);
void getCarNumSlot();// 获取当前车位数量信息
private:
areaclicked *frist;
areaclicked *second;
areaclicked *thrid;
bool friststat; //定义的三个车位的状态
bool secondstat;
bool thridstat;
//QPixmap car[3];
QLabel *label;
QLabel *label1;
QPushButton *pushButton;
int carNum;
QTimer *timer;
QPushButton *controlFrame;
Widget *w;
FirePage *fire;
Camera myCameraFrame;
QPushButton *cameraButton;
};
#endif // SHOWPAGE_H
源文件
#include "showpage.h"
#include <QPainter>
#include<QMouseEvent>
#include <QDebug>
#include<QIcon>
#include"handle.h"
showpage::showpage(QWidget *parent) : QWidget(parent)
{
//设置主窗口的大小图标名称
this->setFixedSize(1600,900);
this->setWindowIcon(QIcon(":/images/park.ico"));
this->setWindowTitle("SmartPark");
//初始化车位
friststat=false;
secondstat=false;
thridstat=false;
timer=new QTimer(this);
label=new QLabel(this);
label->setText("当前车位共148个");
label->move(1394,818);
label->setFont(QFont("Times",12,QFont::Bold));
label1=new QLabel(this);
label1->move(1394,840);
// label1->setText("当前已用车位:148");
label1->setFont(QFont("Times",12,QFont::Bold));
connect(timer,SIGNAL(timeout()),
this,SLOT(getCarNumSlot()));
timer->start(100);
timer->setInterval(500);
// 给定义的Areaclick对象划定范围,即定义的范围收到点击即触发信号;
// frist =new areaclicked(this);
// frist->setGeometry(378,267,30,45);
// connect(frist,SIGNAL(clicked()),
// this,SLOT(fristClickedSlot()));
// second =new areaclicked(this);
// second->setGeometry(339,0,360,768);
// connect(second,SIGNAL(clicked()),
// this,SLOT(secondClickedSlot()));
// thrid =new areaclicked(this);
// thrid->setGeometry(712,0,312,768);
// connect(thrid,SIGNAL(clicked()),
// this,SLOT(thridClickedSlot()));
connect(Handle::getobject(),SIGNAL(firstStatChange(bool)),
this,SLOT(fristChangSlot(bool)));
connect(Handle::getobject(),SIGNAL(secondStatChange(bool)),
this,SLOT(secondChangSlot(bool)));
connect(Handle::getobject(),SIGNAL(thridStatChange(bool)),
this,SLOT(thridChangSlot(bool)));
w=new Widget();
controlFrame=new QPushButton(this);
controlFrame->setText("控制页面");
controlFrame->move(1231,9);
connect(controlFrame,&QPushButton::clicked,
[=]()
{
w->show();
}
);
//监控
cameraButton=new QPushButton(this);
cameraButton->setText("监控");
cameraButton->move(1231,50);
connect(cameraButton,&QPushButton::clicked,
[=]()
{
myCameraFrame.show();
}
);
bool isShow;
isShow=false;
connect(Handle::getobject(),&Handle::fireStatChange,
[=]()
{
if(!isShow)
{
fire=new FirePage();
fire->show();
}
}
);
}
showpage::~showpage()
{
}
void showpage::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(0,0,this->width(),this->height(),QPixmap(":/images/parkground.jpg"));
if(friststat){
painter.drawPixmap(378,267,30,45,QPixmap(":/images/littlecar.jpg"));
}
if(secondstat){
painter.drawPixmap(414,267,30,45,QPixmap(":/images/littlecar.jpg"));
}
if(thridstat){
painter.drawPixmap(450,267,30,45,QPixmap(":/images/littlecar.jpg"));
}
}
//窗口坐标
void showpage::mouseReleaseEvent(QMouseEvent *e)
{
qDebug()<<e->x()<<" "<<e->y()<<" ";
}
//鼠标点击会改变信号
void showpage::fristClickedSlot()
{
if(friststat)
friststat=false;
else
friststat=true;
this->update();
}
void showpage::secondClickedSlot()
{
if(secondstat)
secondstat=false;
else
secondstat=true;
this->update();
}
void showpage::thridClickedSlot()
{
if(thridstat)
thridstat=false;
else
thridstat=true;
this->update();
}
//在handle中根据收到的数据触发信号,改变车位状态
void showpage::fristChangSlot(bool stat)
{
friststat=stat;
this->update();
}
void showpage::secondChangSlot(bool stat)
{
secondstat=stat;
this->update();
}
void showpage::thridChangSlot(bool stat)
{
thridstat=stat;
this->update();
}
//获取
void showpage::getCarNumSlot()
{
carNum=0;
if(friststat)
carNum++;
if(secondstat)
carNum++;
if(thridstat)
carNum++;
QString a=QString::number(carNum);
label1->setText(a.prepend("当前已用车位:"));
}
这是用三个按钮模拟车辆停放(背景是一张图片)按钮按下代表车辆停放,本来是准备用红外或者什么的但是测试起来比较麻烦,就简单点用了三个按钮,当然还有许多其他的传感器。
后面将会陆续介绍其他的部分