tentative de réparer le fuck-up
This commit is contained in:
parent
2c22dda0f4
commit
e98c415226
BIN
Ico/switch-off-icon.png
Normal file
BIN
Ico/switch-off-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
Ico/switch-on-icon.png
Normal file
BIN
Ico/switch-on-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
62
Sources/Sprinkler/Sprinkler.cpp
Normal file
62
Sources/Sprinkler/Sprinkler.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "Sprinkler.h"
|
||||||
|
|
||||||
|
|
||||||
|
CSprinkler::CSprinkler(CSprinklerGui *GUI)
|
||||||
|
{
|
||||||
|
mNetworkInterface = new CSprinklerMasterCtrlInterface(this);
|
||||||
|
mGui = GUI;
|
||||||
|
|
||||||
|
CSprinklerDevice *Sprinkler = new CSprinklerDevice();
|
||||||
|
mSprinklers.append(Sprinkler);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSprinkler::~CSprinkler()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mSprinklers.size(); i++)
|
||||||
|
{
|
||||||
|
delete mSprinklers[i];
|
||||||
|
}
|
||||||
|
mSprinklers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSprinklerDevice* CSprinkler::FindSprinkler(int DeviceAddress)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mSprinklers.size(); i++)
|
||||||
|
{
|
||||||
|
if(mSprinklers.at(i)->mDeviceAddress == DeviceAddress)
|
||||||
|
{
|
||||||
|
return mSprinklers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSprinkler::SetSprinklerState(int DeviceAddress, unsigned char State)
|
||||||
|
{
|
||||||
|
CSprinklerDevice *Dev = FindSprinkler(DeviceAddress);
|
||||||
|
if(Dev != 0)
|
||||||
|
{
|
||||||
|
Dev->SetSprinklerState((SprinklerState)State);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSprinkler::SetSprinklerFlow(int DeviceAddress, unsigned short Flow)
|
||||||
|
{
|
||||||
|
CSprinklerDevice *Dev = FindSprinkler(DeviceAddress);
|
||||||
|
if(Dev != 0)
|
||||||
|
{
|
||||||
|
Dev->SetFlow(Flow);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
34
Sources/Sprinkler/Sprinkler.h
Normal file
34
Sources/Sprinkler/Sprinkler.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef SPRINKLER_H
|
||||||
|
#define SPRINKLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QList>
|
||||||
|
#include "SprinklerMasterCtrlInterface.h"
|
||||||
|
#include "SprinklerGui.h"
|
||||||
|
#include "SprinklerDevice.h"
|
||||||
|
|
||||||
|
|
||||||
|
class CSprinkler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CSprinkler(CSprinklerGui *GUI);
|
||||||
|
~CSprinkler();
|
||||||
|
|
||||||
|
int SetSprinklerState(int DeviceAddress, unsigned char State);
|
||||||
|
int SetSprinklerFlow(int DeviceAddress, unsigned short Flow);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CSprinklerDevice *FindSprinkler(int DeviceAddress);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CSprinklerMasterCtrlInterface *mNetworkInterface;
|
||||||
|
CSprinklerGui *mGui;
|
||||||
|
QList<CSprinklerDevice*> mSprinklers;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SPRINKLER_H
|
||||||
111
Sources/Sprinkler/SprinklerMasterCtrlInterface.cpp
Normal file
111
Sources/Sprinkler/SprinklerMasterCtrlInterface.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#include "SprinklerMasterCtrlInterface.h"
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QDataStream>
|
||||||
|
#include <QBuffer>
|
||||||
|
#include "SystemGui.h"
|
||||||
|
#include "Sprinkler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CSprinklerMasterCtrlInterface::CSprinklerMasterCtrlInterface(CSprinkler *ProgramHandle)
|
||||||
|
{
|
||||||
|
mDeviceAddress = 1;
|
||||||
|
mNetworkPort = 2182;
|
||||||
|
mMasterCtrlAddress = "127.0.0.1";
|
||||||
|
// mNetworkPort = 6463;
|
||||||
|
// mMasterCtrlAddress = "192.168.0.112";
|
||||||
|
mNetworkCommSocket = 0;
|
||||||
|
mMyDeviceID = ID_SPRINKLER_INTERFACE;
|
||||||
|
|
||||||
|
mProgramHandle = ProgramHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSprinklerMasterCtrlInterface::~CSprinklerMasterCtrlInterface()
|
||||||
|
{
|
||||||
|
// if(mNetworkCommSocket !=0)
|
||||||
|
// {
|
||||||
|
//// mNetworkCommSocket->disconnectFromHost();
|
||||||
|
// // delete mNetworkCommSocket;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSprinklerMasterCtrlInterface::DeviceConnectedToMaster(bool Connected)
|
||||||
|
{
|
||||||
|
if(Connected)
|
||||||
|
{
|
||||||
|
mNetworkCommSocket->write(GetTxPacket(SPRINKLER_INTERFACE_GET_SPRINKLERS_REQUEST,0,0,0,1,ID_MASTER,mMyDeviceID,mDeviceAddress));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//???
|
||||||
|
}
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSprinklerMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderDeviceID, int SenderAddress, int MessageID, int DataSize, QByteArray Data)
|
||||||
|
{
|
||||||
|
Q_UNUSED(DataSize)
|
||||||
|
|
||||||
|
|
||||||
|
if(TargetDeviceID == mMyDeviceID && (TargetDeviceAddress == BROADCAST_VALUE || TargetDeviceAddress == mDeviceAddress))
|
||||||
|
{
|
||||||
|
switch(MessageID)
|
||||||
|
{
|
||||||
|
case SPRINKLER_INTERFACE_ACK:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_STATUS_REQUEST:
|
||||||
|
{
|
||||||
|
QByteArray Frame,ResponseData;
|
||||||
|
ResponseData.append(ACK);
|
||||||
|
ResponseData.append((char)SPRINKLER_INTERFACE_STATUS_RESPONSE);
|
||||||
|
Frame = GetTxPacket(SPRINKLER_INTERFACE_STATUS_RESPONSE,0,ResponseData.data(),ResponseData.size(),1,ID_MASTER,ID_SPRINKLER_INTERFACE,mDeviceAddress);
|
||||||
|
mNetworkCommSocket->write(Frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLERS_RESPONSE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLER_DATA_RESPONSE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_SET_SPRINKLER_DATA_ACK:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLER_STATE_RESPONSE:
|
||||||
|
{
|
||||||
|
for(int i = 0; i < Data.at(0); i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_SET_SPRINKLER_STATE_ACK:
|
||||||
|
{
|
||||||
|
QByteArray Frame,RequestData;
|
||||||
|
RequestData.append(1); //device address
|
||||||
|
Frame = GetTxPacket(SPRINKLER_INTERFACE_GET_SPRINKLER_STATE_REQUEST,0,RequestData.data(),RequestData.size(),1,ID_MASTER,ID_SPRINKLER_INTERFACE,mDeviceAddress);
|
||||||
|
mNetworkCommSocket->write(Frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SPRINKLER_INTERFACE_STATUS_RESPONSE:
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLERS_REQUEST:
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLER_DATA_REQUEST:
|
||||||
|
case SPRINKLER_INTERFACE_SET_SPRINKLER_DATA_REQUEST:
|
||||||
|
case SPRINKLER_INTERFACE_GET_SPRINKLER_STATE_REQUEST:
|
||||||
|
case SPRINKLER_INTERFACE_SET_SPRINKLER_STATE_REQUEST:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
qDebug("Sprinkler: Invalid Ethernet MSg received: %d",MessageID);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
28
Sources/Sprinkler/SprinklerMasterCtrlInterface.h
Normal file
28
Sources/Sprinkler/SprinklerMasterCtrlInterface.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef CSPRINKLERMASTERCTRLINTERFACE_H
|
||||||
|
#define CSPRINKLERMASTERCTRLINTERFACE_H
|
||||||
|
|
||||||
|
#include "MasterCtrlInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
//class CSystemGui;
|
||||||
|
class CSprinkler;
|
||||||
|
|
||||||
|
|
||||||
|
class CSprinklerMasterCtrlInterface: public CMasterCtrlInterface
|
||||||
|
{
|
||||||
|
//Q_OBJECT
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
CSprinkler *mProgramHandle;
|
||||||
|
|
||||||
|
CSprinklerMasterCtrlInterface(CSprinkler *ProgramHandle);
|
||||||
|
~CSprinklerMasterCtrlInterface();
|
||||||
|
|
||||||
|
virtual int DeviceFrameReceived(int TargetDeviceID, int TargetDeviceAddress, int SenderID, int SenderAddress, int MessageID, int DataSize, QByteArray Data);
|
||||||
|
virtual int DeviceConnectedToMaster(bool Connected);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CSPRINKLERMASTERCTRLINTERFACE_H
|
||||||
25
Sources/ToggleSwitch.cpp
Normal file
25
Sources/ToggleSwitch.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "ToggleSwitch.h"
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
CToggleSwitch::CToggleSwitch(QWidget *parent) :
|
||||||
|
QAbstractButton(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CToggleSwitch::paintEvent(QPaintEvent *e)
|
||||||
|
{
|
||||||
|
mOnPixmap = QPixmap("./Ico/switch-off-icon.png").scaled(size());
|
||||||
|
mOffPixmap = QPixmap("./Ico/switch-on-icon.png").scaled(size());
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
if(isChecked())
|
||||||
|
{
|
||||||
|
painter.drawPixmap(0,0,mOnPixmap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
painter.drawPixmap(0,0,mOffPixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
20
Sources/ToggleSwitch.h
Normal file
20
Sources/ToggleSwitch.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef TOGGLESWITCH_H
|
||||||
|
#define TOGGLESWITCH_H
|
||||||
|
|
||||||
|
#include <QAbstractButton>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
class CToggleSwitch : public QAbstractButton
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CToggleSwitch(QWidget *parent = 0);
|
||||||
|
QPixmap mOnPixmap, mOffPixmap;
|
||||||
|
|
||||||
|
void paintEvent(QPaintEvent *e);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TOGGLESWITCH_H
|
||||||
72
ui_SprinklerDeviceGuiItem.h
Normal file
72
ui_SprinklerDeviceGuiItem.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/********************************************************************************
|
||||||
|
** Form generated from reading UI file 'SprinklerDeviceGuiItem.ui'
|
||||||
|
**
|
||||||
|
** Created by: Qt User Interface Compiler version 5.5.0
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef UI_SPRINKLERDEVICEGUIITEM_H
|
||||||
|
#define UI_SPRINKLERDEVICEGUIITEM_H
|
||||||
|
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtWidgets/QAction>
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <QtWidgets/QButtonGroup>
|
||||||
|
#include <QtWidgets/QHeaderView>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QtWidgets/QPushButton>
|
||||||
|
#include <QtWidgets/QWidget>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class Ui_CSprinklerDeviceGuiItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QLabel *SprinklerAddress;
|
||||||
|
QLabel *SprinklerFlowSpeed;
|
||||||
|
QLabel *label;
|
||||||
|
QPushButton *pushButton;
|
||||||
|
|
||||||
|
void setupUi(QWidget *CSprinklerDeviceGuiItem)
|
||||||
|
{
|
||||||
|
if (CSprinklerDeviceGuiItem->objectName().isEmpty())
|
||||||
|
CSprinklerDeviceGuiItem->setObjectName(QStringLiteral("CSprinklerDeviceGuiItem"));
|
||||||
|
CSprinklerDeviceGuiItem->resize(540, 399);
|
||||||
|
SprinklerAddress = new QLabel(CSprinklerDeviceGuiItem);
|
||||||
|
SprinklerAddress->setObjectName(QStringLiteral("SprinklerAddress"));
|
||||||
|
SprinklerAddress->setGeometry(QRect(20, 10, 101, 41));
|
||||||
|
SprinklerFlowSpeed = new QLabel(CSprinklerDeviceGuiItem);
|
||||||
|
SprinklerFlowSpeed->setObjectName(QStringLiteral("SprinklerFlowSpeed"));
|
||||||
|
SprinklerFlowSpeed->setGeometry(QRect(20, 50, 131, 41));
|
||||||
|
label = new QLabel(CSprinklerDeviceGuiItem);
|
||||||
|
label->setObjectName(QStringLiteral("label"));
|
||||||
|
label->setGeometry(QRect(30, 100, 54, 17));
|
||||||
|
pushButton = new QPushButton(CSprinklerDeviceGuiItem);
|
||||||
|
pushButton->setObjectName(QStringLiteral("pushButton"));
|
||||||
|
pushButton->setGeometry(QRect(220, 20, 80, 25));
|
||||||
|
pushButton->setCheckable(true);
|
||||||
|
|
||||||
|
retranslateUi(CSprinklerDeviceGuiItem);
|
||||||
|
|
||||||
|
QMetaObject::connectSlotsByName(CSprinklerDeviceGuiItem);
|
||||||
|
} // setupUi
|
||||||
|
|
||||||
|
void retranslateUi(QWidget *CSprinklerDeviceGuiItem)
|
||||||
|
{
|
||||||
|
CSprinklerDeviceGuiItem->setWindowTitle(QApplication::translate("CSprinklerDeviceGuiItem", "Form", 0));
|
||||||
|
SprinklerAddress->setText(QApplication::translate("CSprinklerDeviceGuiItem", "Address : ", 0));
|
||||||
|
SprinklerFlowSpeed->setText(QApplication::translate("CSprinklerDeviceGuiItem", "Flow speed :", 0));
|
||||||
|
label->setText(QApplication::translate("CSprinklerDeviceGuiItem", "State : ", 0));
|
||||||
|
pushButton->setText(QApplication::translate("CSprinklerDeviceGuiItem", "PushButton", 0));
|
||||||
|
} // retranslateUi
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class CSprinklerDeviceGuiItem: public Ui_CSprinklerDeviceGuiItem {};
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // UI_SPRINKLERDEVICEGUIITEM_H
|
||||||
60
ui_SprinklerGui.h
Normal file
60
ui_SprinklerGui.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/********************************************************************************
|
||||||
|
** Form generated from reading UI file 'SprinklerGui.ui'
|
||||||
|
**
|
||||||
|
** Created by: Qt User Interface Compiler version 5.5.0
|
||||||
|
**
|
||||||
|
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
|
#ifndef UI_SPRINKLERGUI_H
|
||||||
|
#define UI_SPRINKLERGUI_H
|
||||||
|
|
||||||
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtWidgets/QAction>
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <QtWidgets/QButtonGroup>
|
||||||
|
#include <QtWidgets/QHeaderView>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QtWidgets/QWidget>
|
||||||
|
#include "ToggleSwitch.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class Ui_CSprinklerGui
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QLabel *label;
|
||||||
|
CToggleSwitch *mValveSwitch;
|
||||||
|
|
||||||
|
void setupUi(QWidget *CSprinklerGui)
|
||||||
|
{
|
||||||
|
if (CSprinklerGui->objectName().isEmpty())
|
||||||
|
CSprinklerGui->setObjectName(QStringLiteral("CSprinklerGui"));
|
||||||
|
CSprinklerGui->resize(1047, 560);
|
||||||
|
label = new QLabel(CSprinklerGui);
|
||||||
|
label->setObjectName(QStringLiteral("label"));
|
||||||
|
label->setGeometry(QRect(20, 10, 201, 51));
|
||||||
|
mValveSwitch = new CToggleSwitch(CSprinklerGui);
|
||||||
|
mValveSwitch->setObjectName(QStringLiteral("mValveSwitch"));
|
||||||
|
mValveSwitch->setGeometry(QRect(220, 90, 91, 81));
|
||||||
|
|
||||||
|
retranslateUi(CSprinklerGui);
|
||||||
|
|
||||||
|
QMetaObject::connectSlotsByName(CSprinklerGui);
|
||||||
|
} // setupUi
|
||||||
|
|
||||||
|
void retranslateUi(QWidget *CSprinklerGui)
|
||||||
|
{
|
||||||
|
CSprinklerGui->setWindowTitle(QApplication::translate("CSprinklerGui", "Form", 0));
|
||||||
|
label->setText(QApplication::translate("CSprinklerGui", "Sprinklers", 0));
|
||||||
|
} // retranslateUi
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class CSprinklerGui: public Ui_CSprinklerGui {};
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // UI_SPRINKLERGUI_H
|
||||||
Loading…
x
Reference in New Issue
Block a user