Ben des affaires...

This commit is contained in:
2021-04-11 13:18:40 -04:00
parent 940287a97e
commit 50d091c68c
33 changed files with 38430 additions and 67 deletions
+35
View File
@@ -41,6 +41,16 @@ int CChalet::ChaletStatusReceived(CChaletMainStatus Status)
return RET_OK;
}
int CChalet::ChaletLogReceived(QByteArray *Log)
{
mChaletGui->UpdateChaletLogPlot(Log);
return RET_OK;
}
int CChalet::ChaletCommActivity()
{
return mChaletGui->ChaletCommActivity();
}
int CChalet::WiFiToggleButtonPressed(bool RequestedState)
{
@@ -89,3 +99,28 @@ int CChalet::RebootCPUButtonPressed()
{
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_REBOOT_CPU_REQUEST,QByteArray());
}
int CChalet::ConnectedToMaster(bool connected)
{
if(connected)
{
mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST,QByteArray());
}
return RET_OK;
}
int CChalet::RequestChaletLogs(QDate StartDate)
{
if(StartDate > QDate::currentDate())
{
return false;
}
QByteArray StartDateData;
QDataStream Strm(&StartDateData,QIODevice::WriteOnly);
Strm.device()->seek(0);
Strm << StartDate;
return mNetworkInterface->SendMasterCtrlCommand(CHALET_INTERFACE_GET_DATA_LOG_REQUEST,StartDateData);
}
+4
View File
@@ -23,11 +23,15 @@ public:
int Start();
int ChaletStatusReceived(CChaletMainStatus Status);
int ChaletLogReceived(QByteArray *Log);
int ConnectedToMaster(bool connected);
int ChaletCommActivity();
int WiFiToggleButtonPressed(bool RequestedState);
int InverterToggleButtonPressed(bool RequestedState);
int DoHarakiriButtonClicked(bool Verified);
int RebootCPUButtonPressed();
int RequestChaletLogs(QDate StartDate);
signals:
+24 -11
View File
@@ -7,8 +7,11 @@ CChaletMainStatus::CChaletMainStatus()
{
mInverterRelayStatus = CHALET_POWER_RELAY_UNKNOWN_STATE;
mWiFiModuleStatus = WIFI_UNKNOWN_STATE;
mCurrentSensorStatus = CHALET_CURRENT_SENSOR_UNKNOWN_STATE;
mBatteryCurrent = 0;
mBatteryVoltage = 0;
mIsOnline = false;
mLostRequestPercentage = 0;
}
@@ -17,26 +20,36 @@ int CChaletMainStatus::FromByteArray(QByteArray Data)
QDataStream Strm(Data);
Strm.device()->seek(0);
Strm >> *this;
/*
Strm >> mInverterRelayStatus;
Strm >> mWiFiModuleStatus;
Strm >> mBatteryVoltage;
Strm >> mBatteryCurrent;
Strm >> mBatterySOC;
// ChaletStatus[0] = GetChaletPowerRelayState(); //Inverter relay status
// ChaletStatus[1] = GetWiFiSate(); //Wifi Module state
// ChaletStatus[2] = 3; //Battery Voltage 1
// ChaletStatus[3] = 4; //Battery voltage 2
// ChaletStatus[4] = 5; //Battery current 1
// ChaletStatus[5] = 6; //Batgtery current 2
// ChaletStatus[6] = 7; //Battery SOC
// ChaletStatus[7] = 8; //Snatch
// ChaletStatus[8] = 9;
// ChaletStatus[9] = 10;
Strm >> mIsOnline;
Strm >> mCurrentSensorStatus;
Strm >> mLostRequestPercentage;*/
return RET_OK;
}
QDataStream &operator>>(QDataStream &in, CChaletMainStatus &dest)
{
in >> dest.mInverterRelayStatus
>> dest.mWiFiModuleStatus
>> dest.mBatteryVoltage
>> dest.mBatteryCurrent
>> dest.mBatterySOC
>> dest.mIsOnline
>> dest.mCurrentSensorStatus
>> dest.mLostRequestPercentage
>> dest.mThisStatusDateTime
>> dest.mLastLoraStatus
>> dest.mStatusToggleBit;
return in;
}
//QByteArray CChaletMainStatus::ToByteArray()
//{
// QByteArray Data;
+18 -3
View File
@@ -21,6 +21,13 @@ enum eChaletPowerRelayState
CHALET_POWER_RELAY_UNKNOWN_STATE
};
enum eChaletCurrentSensorState
{
CHALET_CURRENT_SENSOR_DEFECT_STATE = 0,
CHALET_CURRENT_SENSOR_OK_STATE,
CHALET_CURRENT_SENSOR_UNKNOWN_STATE
};
class CChaletMainStatus
{
@@ -33,17 +40,25 @@ public:
quint8 mInverterRelayStatus;
quint8 mWiFiModuleStatus;
qint8 mCurrentSensorStatus;
float mBatteryVoltage;
float mBatteryCurrent;
float mBatterySOC;
qint16 mBatteryCurrent;
qint16 mBatterySOC;
bool mHarakiriDone;
bool mIsOnline;
bool mStatusToggleBit;
QDateTime mLastLoraStatus;
QDateTime mThisStatusDateTime;
float mLostRequestPercentage;
};
QDataStream &operator>>(QDataStream &in, CChaletMainStatus &dest);
#endif // CHALETDATA_H
+180
View File
@@ -1,14 +1,19 @@
#include "ChaletGui.h"
#include "ui_ChaletGui.h"
#include "CChalet.h"
#include <QWidget>
#include <QDate>
CChaletGui::CChaletGui(QWidget *parent) :
QWidget(parent),
ui(new Ui::CChaletGui)
{
ui->setupUi(this);
ui->mDoHarakiriButton->setEnabled(false);
ui->mLogStartDateEdit->setDate(QDate::currentDate());
connect(ui->mWiFiModuleONBtn,SIGNAL(clicked()),this,SLOT(WiFiONButtonClicked()));
connect(ui->mWiFiModuleOFFBtn,SIGNAL(clicked(bool)),this,SLOT(WiFiOFFButtonClicked()));
@@ -17,16 +22,84 @@ CChaletGui::CChaletGui(QWidget *parent) :
connect(ui->mRebootCPUBtn,SIGNAL(clicked(bool)),this,SLOT(RebootCPUButtonClicked()));
connect(ui->mDoHarakiriButton,SIGNAL(clicked(bool)),this,SLOT(DoHarakiriButtonClicked()));
connect(ui->mEnableHarakiriChkBx,SIGNAL(clicked(bool)),this,SLOT(EnableHarakiriClicked(bool)));
connect(ui->mGetChaletLogButton,SIGNAL(clicked(bool)),this,SLOT(GetChaletLogsBtnClicked()));
mBatteryPlotWidget = new QCustomPlot(ui->mPlotWidget);
mBatteryPlotWidget->resize(ui->mPlotWidget->size());
// create graph and assign data to it:
mBatteryPlotWidget->addGraph();
// give the axes some labels:
mBatteryPlotWidget->xAxis->setLabel("time");
mBatteryPlotWidget->yAxis->setLabel("Volts");
double now = QDateTime::currentDateTime().toSecsSinceEpoch();
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
dateTicker->setDateTimeFormat("hh:mm:ss\ndd MMM");
mBatteryPlotWidget->xAxis->setTicker(dateTicker);
mBatteryPlotWidget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
QDateTime Now = QDateTime::currentDateTime().toLocalTime();
QDateTime midnight = Now;
midnight.setTime(QTime(0,0,0));
QDateTime eod = Now;
eod.setTime(QTime(23,59,0));
//mBatteryPlotWidget->xAxis->setRange(0/*QCPAxisTickerDateTime::dateTimeToKey(midnight)*/,QCPAxisTickerDateTime::dateTimeToKey(eod));
// mBatteryPlotWidget->xAxis->setRange(now, now+(2*3600));
mBatteryPlotWidget->xAxis->setRange(midnight.toSecsSinceEpoch(), eod.toSecsSinceEpoch());
mBatteryPlotWidget->yAxis->setRange(12,15);
mBatteryPlotWidget->graph(0)->addData(now,13.5);
mBatteryPlotWidget->replot();
}
CChaletGui::~CChaletGui()
{
delete ui;
delete mBatteryPlotWidget;
}
int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
{
static bool LastToggle = false;
QString text;
int Delta = QDateTime::currentDateTime().toSecsSinceEpoch() - Status.mLastLoraStatus.toSecsSinceEpoch();
ui->mLasCommRequestReceivedLbl->setText(QString("Last response: %1 | %2 seconds ago...").arg(Status.mLastLoraStatus.toString("yyyy-MM-dd-hh:mm:ss")).arg(Delta));
if(Status.mIsOnline == false)
{
ui->mChaletOnlineStatusLbl->setText("OFFLINE");
QPalette pal = QPalette(ui->mChaletOnlineStatusLbl->palette());
pal.setColor(QPalette::WindowText,QColor(Qt::red));
ui->mChaletOnlineStatusLbl->setPalette(pal);
ui->mWiFiModuleStatusLabel->setText("Unknown");
ui->mInverterRlyStatusLabel->setText("Unknown");
ui->mCurrentSensorStateLbl->setText("Current Sensor: Unknown state");
ui->mBatteryVoltageLabel->setText("Battery Voltage: Unknown");
ui->mBatterySOCLabel->setText("Battery SOC: Unknown");
ui->mSolarPanelCurrentLabel->setText("Solar Panel Current: Unknown");
ui->mLostReqPercentLbl->setText("N/A");
return RET_OK;
}
else if(ui->mChaletOnlineStatusLbl->text() == "OFFLINE")
{
ui->mChaletOnlineStatusLbl->setText("ONLINE");
QPalette pal = QPalette(ui->mChaletOnlineStatusLbl->palette());
pal.setColor(QPalette::WindowText,QColor(Qt::darkGreen));
ui->mChaletOnlineStatusLbl->setPalette(pal);
}
switch(Status.mWiFiModuleStatus)
{
case WIFI_CONNECTED_STATE:
@@ -82,8 +155,91 @@ int CChaletGui::UpdateChaletStatus(CChaletMainStatus Status)
}
ui->mInverterRlyStatusLabel->setText(text);
switch(Status.mCurrentSensorStatus)
{
case CHALET_CURRENT_SENSOR_DEFECT_STATE:
{
text = "Current Sensor: DEFECTIVE";
break;
}
case CHALET_CURRENT_SENSOR_OK_STATE:
{
text = "Current Sensor: OK";
break;
}
case CHALET_CURRENT_SENSOR_UNKNOWN_STATE:
default:
{
text = "Current Sensor: Unknown state";
break;
}
}
ui->mCurrentSensorStateLbl->setText(text);
QString Voltage = QString("Battery Voltage: %1").arg(Status.mBatteryVoltage);
ui->mBatteryVoltageLabel->setText(Voltage);
ui->mVoltageLCD->display(Voltage);
QString Current = QString("Solar Panel Current: %1").arg(Status.mBatteryCurrent);
ui->mSolarPanelCurrentLabel->setText(Current);
QString SOC = QString("Battery SOC: %1").arg(Status.mBatterySOC);
ui->mBatterySOCLabel->setText(SOC);
QString Percent = QString("Lost Requests: %1%").arg(Status.mLostRequestPercentage,0,'f',2);
ui->mLostReqPercentLbl->setText(Percent);
if(Status.mStatusToggleBit != LastToggle)
{
LastToggle = Status.mStatusToggleBit;
if(ui->mChaletCommActivityLbl->isEnabled())
{
ui->mChaletCommActivityLbl->setEnabled(false);
}
else
{
ui->mChaletCommActivityLbl->setEnabled(true);
}
double CurTime = QDateTime::currentDateTime().toSecsSinceEpoch();
mBatteryPlotWidget->graph(0)->addData(CurTime,Status.mBatteryVoltage);
mBatteryPlotWidget->replot();
}
return RET_OK;
}
int CChaletGui::UpdateChaletLogPlot(QByteArray *Log)
{
int NbRecords;
CChaletMainStatus CurData;
QVector<double> x,y;
QDataStream Strm(Log,QIODevice::ReadOnly);
Strm.device()->seek(0);
Strm >> NbRecords;
if(NbRecords > 0)
{
for(int i = 0; i < NbRecords; i++)
{
Strm >> CurData;
x.append(CurData.mThisStatusDateTime.toSecsSinceEpoch());
y.append(CurData.mBatteryVoltage);
}
}
mBatteryPlotWidget->graph(0)->data().clear();
mBatteryPlotWidget->graph(0)->setData(x,y);
mBatteryPlotWidget->xAxis->setRange(x.first(),x.last());
mBatteryPlotWidget->replot();
return RET_OK;
}
@@ -124,3 +280,27 @@ void CChaletGui::RebootCPUButtonClicked()
ui->mDoHarakiriButton->setEnabled(false);
}
}
int CChaletGui::ChaletCommActivity()
{
if(ui->mChaletCommActivityLbl->isEnabled())
{
ui->mChaletCommActivityLbl->setEnabled(false);
}
else
{
ui->mChaletCommActivityLbl->setEnabled(true);
}
return RET_OK;
}
void CChaletGui::GetChaletLogsBtnClicked()
{
QDate StartDate = ui->mLogStartDateEdit->date();
if(StartDate > QDate::currentDate())
{
QMessageBox::critical(this,"Error","Date is in the future!");
return;
}
mProgramHandle->RequestChaletLogs(StartDate);
}
+5
View File
@@ -3,6 +3,7 @@
#include <QWidget>
#include "ChaletData.h"
#include "QCustomPlot/qcustomplot.h"
class CChalet;
@@ -19,8 +20,11 @@ public:
~CChaletGui();
CChalet *mProgramHandle;
QCustomPlot *mBatteryPlotWidget;
int UpdateChaletStatus(CChaletMainStatus Status);
int UpdateChaletLogPlot(QByteArray* Log);
int ChaletCommActivity();
private:
Ui::CChaletGui *ui;
@@ -33,6 +37,7 @@ public slots:
void RebootCPUButtonClicked();
void DoHarakiriButtonClicked();
void EnableHarakiriClicked(bool);
void GetChaletLogsBtnClicked();
};
#endif // CHALETGUI_H
+184 -28
View File
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>849</width>
<width>1205</width>
<height>598</height>
</rect>
</property>
@@ -16,9 +16,9 @@
<widget class="QLabel" name="MainPageLabel">
<property name="geometry">
<rect>
<x>370</x>
<y>20</y>
<width>201</width>
<x>460</x>
<y>10</y>
<width>71</width>
<height>31</height>
</rect>
</property>
@@ -36,9 +36,9 @@
<widget class="QLabel" name="mInverterRlyStatusLabel">
<property name="geometry">
<rect>
<x>350</x>
<y>90</y>
<width>211</width>
<x>198</x>
<y>50</y>
<width>210</width>
<height>16</height>
</rect>
</property>
@@ -49,9 +49,9 @@
<widget class="QLabel" name="mWiFiModuleStatusLabel">
<property name="geometry">
<rect>
<x>360</x>
<y>130</y>
<width>131</width>
<x>198</x>
<y>90</y>
<width>130</width>
<height>16</height>
</rect>
</property>
@@ -62,8 +62,8 @@
<widget class="QLabel" name="mWiFiSectionLabel">
<property name="geometry">
<rect>
<x>180</x>
<y>130</y>
<x>26</x>
<y>90</y>
<width>31</width>
<height>16</height>
</rect>
@@ -75,8 +75,8 @@
<widget class="QPushButton" name="mInverterRelayOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>90</y>
<x>126</x>
<y>50</y>
<width>61</width>
<height>22</height>
</rect>
@@ -88,8 +88,8 @@
<widget class="QPushButton" name="mWiFiModuleOFFBtn">
<property name="geometry">
<rect>
<x>280</x>
<y>130</y>
<x>126</x>
<y>90</y>
<width>61</width>
<height>23</height>
</rect>
@@ -101,8 +101,8 @@
<widget class="QPushButton" name="mInverterRelayONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>90</y>
<x>70</x>
<y>50</y>
<width>51</width>
<height>23</height>
</rect>
@@ -114,8 +114,8 @@
<widget class="QPushButton" name="mWiFiModuleONBtn">
<property name="geometry">
<rect>
<x>224</x>
<y>130</y>
<x>70</x>
<y>90</y>
<width>51</width>
<height>23</height>
</rect>
@@ -127,8 +127,8 @@
<widget class="QLabel" name="mWiFiSectionLabel_2">
<property name="geometry">
<rect>
<x>170</x>
<y>90</y>
<x>16</x>
<y>50</y>
<width>51</width>
<height>20</height>
</rect>
@@ -140,8 +140,8 @@
<widget class="QPushButton" name="mRebootCPUBtn">
<property name="geometry">
<rect>
<x>220</x>
<y>170</y>
<x>66</x>
<y>130</y>
<width>75</width>
<height>23</height>
</rect>
@@ -151,9 +151,12 @@
</property>
</widget>
<widget class="QCheckBox" name="mEnableHarakiriChkBx">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>640</x>
<x>850</x>
<y>80</y>
<width>111</width>
<height>17</height>
@@ -166,7 +169,7 @@
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>620</x>
<x>830</x>
<y>50</y>
<width>151</width>
<height>81</height>
@@ -192,8 +195,8 @@
<widget class="QLabel" name="mBatteryVoltageLabel">
<property name="geometry">
<rect>
<x>170</x>
<y>210</y>
<x>147</x>
<y>170</y>
<width>241</width>
<height>16</height>
</rect>
@@ -202,6 +205,148 @@
<string>Battery Voltage</string>
</property>
</widget>
<widget class="QLabel" name="mChaletOnlineStatusLbl">
<property name="geometry">
<rect>
<x>450</x>
<y>50</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>Terminal</family>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mSolarPanelCurrentLabel">
<property name="geometry">
<rect>
<x>147</x>
<y>190</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Solar Panel Current: </string>
</property>
</widget>
<widget class="QLabel" name="mBatterySOCLabel">
<property name="geometry">
<rect>
<x>147</x>
<y>210</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Battery SOC: </string>
</property>
</widget>
<widget class="QLabel" name="mCurrentSensorStateLbl">
<property name="geometry">
<rect>
<x>147</x>
<y>230</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Current Sensor:</string>
</property>
</widget>
<widget class="QLabel" name="mLostReqPercentLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>200</y>
<width>241</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Lost requests: </string>
</property>
</widget>
<widget class="QWidget" name="mPlotWidget" native="true">
<property name="geometry">
<rect>
<x>590</x>
<y>250</y>
<width>571</width>
<height>321</height>
</rect>
</property>
</widget>
<widget class="QLCDNumber" name="mVoltageLCD">
<property name="geometry">
<rect>
<x>30</x>
<y>170</y>
<width>111</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="mChaletCommActivityLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>180</y>
<width>47</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Activity!!!</string>
</property>
</widget>
<widget class="QLabel" name="mLasCommRequestReceivedLbl">
<property name="geometry">
<rect>
<x>770</x>
<y>160</y>
<width>301</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Last Request: </string>
</property>
</widget>
<widget class="QDateEdit" name="mLogStartDateEdit">
<property name="geometry">
<rect>
<x>950</x>
<y>220</y>
<width>110</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="mGetChaletLogButton">
<property name="geometry">
<rect>
<x>1070</x>
<y>220</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<zorder>groupBox</zorder>
<zorder>MainPageLabel</zorder>
<zorder>mInverterRlyStatusLabel</zorder>
@@ -215,6 +360,17 @@
<zorder>mRebootCPUBtn</zorder>
<zorder>mEnableHarakiriChkBx</zorder>
<zorder>mBatteryVoltageLabel</zorder>
<zorder>mChaletOnlineStatusLbl</zorder>
<zorder>mSolarPanelCurrentLabel</zorder>
<zorder>mBatterySOCLabel</zorder>
<zorder>mCurrentSensorStateLbl</zorder>
<zorder>mLostReqPercentLbl</zorder>
<zorder>mPlotWidget</zorder>
<zorder>mVoltageLCD</zorder>
<zorder>mChaletCommActivityLbl</zorder>
<zorder>mLasCommRequestReceivedLbl</zorder>
<zorder>mLogStartDateEdit</zorder>
<zorder>mGetChaletLogButton</zorder>
</widget>
<resources/>
<connections/>
@@ -19,6 +19,8 @@ int CChaletMasterCtrlInterface::DeviceConnectedToMaster(bool Connected)
if(Connected)
{
qDebug("Chalet Interface connected to Master.");
mProgramHandle->ConnectedToMaster(Connected);
}
else
return RET_ERROR;
@@ -66,10 +68,27 @@ int CChaletMasterCtrlInterface::DeviceFrameReceived(int TargetDeviceID, int Targ
{
break;
}
case CHALET_INTERFACE_GET_TODAYS_DATA_LOG_RESPONSE:
{
mProgramHandle->ChaletLogReceived(&Data);
break;
}
case CHALET_INTERFACE_CHALET_ACTIVITY_RESPONSE:
{
mProgramHandle->ChaletCommActivity();
break;
}
case CHALET_INTERFACE_GET_DATA_LOG_RESPONSE:
{
mProgramHandle->ChaletLogReceived(&Data);
break;
}
case CHALET_INTERFACE_GENERAL_STATUS_REQUEST:
case CHALET_INTERFACE_AC_POWER_STATE_STATUS_REQUEST:
case CHALET_INTERFACE_AC_POWER_SET_STATE_REQUEST:
case CHALET_INTERFACE_BATTERY_VOLTAGE_REQUEST:
case CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST:
default:
{
qDebug("Chalet: Invalid Ethernet Msg received from MasterCtrl: %d",MessageID);
+3 -1
View File
@@ -9,13 +9,15 @@ CGuiMain::CGuiMain(QWidget *parent)
mAvReceiverGui = new CAvReceiverGui(this);
mMainTabWidget = new QTabWidget(this);
mChaletGui = new CChaletGui(this);
mTowerLightShowGui = new CTowerLightShowGui;
setCentralWidget(mMainTabWidget);
mMainTabWidget->addTab(mSMSGui,"SMS");
mMainTabWidget->addTab(mSprinklerGui,"Sprinkler");
mMainTabWidget->addTab(mAvReceiverGui,"AV Receiver");
mMainTabWidget->addTab(mChaletGui,"Chalet");
mMainTabWidget->addTab(mTowerLightShowGui,"Lightshow");
resize(1024,768);
resize(1500,768);
}
CGuiMain::~CGuiMain()
+2 -1
View File
@@ -8,7 +8,7 @@
#include "SprinklerGui.h"
#include "AvReceiverGui.h"
#include "ChaletGui.h"
#include "TowerLightShowGui.h"
class CGuiMain : public QMainWindow
{
@@ -23,6 +23,7 @@ public:
CAvReceiverGui *mAvReceiverGui;
CChaletGui *mChaletGui;
QTabWidget *mMainTabWidget;
CTowerLightShowGui *mTowerLightShowGui;
int RespawnMainWindow();
int HideMainWindow();
+24 -4
View File
@@ -3,6 +3,18 @@
CMasterCtrlInterface::CMasterCtrlInterface()
{
mNetworkCommSocket = 0;
mNetworkCommSocket = new QTcpSocket();
connect(mNetworkCommSocket,SIGNAL(connected()),this,SLOT(NetworkSocketConnected()));
connect(mNetworkCommSocket,SIGNAL(disconnected()),this,SLOT(NetworkSocketDisconnected()));
connect(mNetworkCommSocket,SIGNAL(readyRead()),this,SLOT(NetworkSocketDataAvailable()));
// mMasterReconnectTimer.setInterval(500);
// mMasterReconnectTimer.stop();
// mMasterReconnectTimer.setSingleShot(false);
// connect(&mMasterReconnectTimer,SIGNAL(timeout()),this,SLOT(NetworkReconnectTimerExpired()));
}
int CMasterCtrlInterface::ConnectToMasterCtrl()
@@ -10,11 +22,11 @@ int CMasterCtrlInterface::ConnectToMasterCtrl()
if(mNetworkCommSocket == 0)
{
mNetworkCommSocket = new QTcpSocket();
}
connect(mNetworkCommSocket,SIGNAL(connected()),this,SLOT(NetworkSocketConnected()));
connect(mNetworkCommSocket,SIGNAL(disconnected()),this,SLOT(NetworkSocketDisconnected()));
connect(mNetworkCommSocket,SIGNAL(readyRead()),this,SLOT(NetworkSocketDataAvailable()));
connect(mNetworkCommSocket,SIGNAL(connected()),this,SLOT(NetworkSocketConnected()));
connect(mNetworkCommSocket,SIGNAL(disconnected()),this,SLOT(NetworkSocketDisconnected()));
connect(mNetworkCommSocket,SIGNAL(readyRead()),this,SLOT(NetworkSocketDataAvailable()));
}
mNetworkCommSocket->connectToHost(mMasterCtrlIPAddress,mNetworkPort);
return RET_OK;
@@ -27,6 +39,7 @@ int CMasterCtrlInterface::DisconnectMasterCtrl()
mNetworkCommSocket->close();
// mNetworkCommSocket->deleteLater();
}
mMasterReconnectTimer.start();
return RET_OK;
}
@@ -81,6 +94,7 @@ int CMasterCtrlInterface::NewFrameReceived(int TargetDeviceID, int TargetDeviceA
void CMasterCtrlInterface::NetworkSocketConnected()
{
qDebug("Connected to MasterCtrl");
mMasterReconnectTimer.stop();
}
@@ -92,6 +106,7 @@ void CMasterCtrlInterface::NetworkSocketDataAvailable()
void CMasterCtrlInterface::NetworkSocketDisconnected()
{
qDebug("Disconnected from MasterCtrl");
mMasterReconnectTimer.start();
}
@@ -101,3 +116,8 @@ int CMasterCtrlInterface::SendMasterCtrlCommand(unsigned char MessageID, QByteAr
return RET_OK;
}
void CMasterCtrlInterface::NetworkReconnectTimerExpired()
{
ConnectToMasterCtrl();
}
+3
View File
@@ -6,6 +6,7 @@
#include "ProtocolDefs.h"
#include <QTcpSocket>
#include "SMSMessage.h"
#include <QTimer>
class CMasterCtrlInterface : public QObject, public CNetworkProtocol
{
@@ -20,6 +21,7 @@ public:
int mNetworkPort;
QString mMasterCtrlIPAddress;
int mMyDeviceID;
QTimer mMasterReconnectTimer;
int ConnectToMasterCtrl();
int DisconnectMasterCtrl();
@@ -36,6 +38,7 @@ public slots:
void NetworkSocketConnected();
void NetworkSocketDataAvailable();
void NetworkSocketDisconnected();
void NetworkReconnectTimerExpired();
};
+5
View File
@@ -264,6 +264,11 @@ enum CHALET_INTERFACE_CMDS
CHALET_INTERFACE_DO_HARAKIRI_RESPONSE,
CHALET_INTERFACE_REBOOT_CPU_REQUEST,
CHALET_INTERFACE_REBOOT_CPU_RESPONSE,
CHALET_INTERFACE_GET_TODAYS_DATA_LOG_REQUEST,
CHALET_INTERFACE_GET_TODAYS_DATA_LOG_RESPONSE,
CHALET_INTERFACE_CHALET_ACTIVITY_RESPONSE,
CHALET_INTERFACE_GET_DATA_LOG_REQUEST,
CHALET_INTERFACE_GET_DATA_LOG_RESPONSE,
MAX_CHALET_INTERFACE_CMD
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
#include "LEDAnimation.h"
CLEDAnimation::CLEDAnimation()
{
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef LEDANIMATION_H
#define LEDANIMATION_H
#include <QList>
class QColor;
class CLEDAnimation
{
public:
CLEDAnimation();
int LedStringSize;
virtual QList<QColor> *GetCurrentFrame() = 0;
};
#endif // LEDANIMATION_H
+16
View File
@@ -0,0 +1,16 @@
#include "LEDAnimator.h"
CLEDAnimator::CLEDAnimator(QObject *parent) : QObject(parent)
{
mAnimationRefreshTimer = new QTimer();
mAnimationRefreshTimer->setSingleShot(false);
mAnimationRefreshTimer->setInterval(ANIMATION_REFRESH_TIMEOUT);
connect(mAnimationRefreshTimer,SIGNAL(timeout()),this,SLOT(AnimationTimerExipired()));
}
void CLEDAnimator::AnimationTimerExipired()
{
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef LEDANIMATOR_H
#define LEDANIMATOR_H
#include <QObject>
#include <QTimer>
#define ANIMATION_REFRESH_TIMEOUT 33 //ms = 30 FPS
class CLEDAnimator : public QObject
{
Q_OBJECT
public:
explicit CLEDAnimator(QObject *parent = 0);
QTimer *mAnimationRefreshTimer;
signals:
public slots:
void AnimationTimerExipired();
};
#endif // LEDANIMATOR_H
+129
View File
@@ -0,0 +1,129 @@
#include "LedStringWidget.h"
#include <QPainter>
CLedStringWidget::CLedStringWidget(int NbLed, QGraphicsItem *parent)
{
mLEDSpacing = 5;
mNbLED = NbLed;
mBoundingRect.setTop(0);
mBoundingRect.setLeft(0);
int color = 0;
// for(int i = 0; i < NbLed; i++)
// {
// QColor LedColor;
// if(color == 0)
// {
// LedColor = QColor(Qt::red);
// color++;
// }
// else if(color == 1)
// {
// LedColor = QColor(Qt::green);
// color++;
// }
// else
// {
// LedColor = QColor(Qt::blue);
// color = 0;
// }
// CRGBLedWidget *NewLED = new CRGBLedWidget(LedColor,this);
// NewLED->setPos(i*(NewLED->boundingRect().width()+mLEDSpacing),0);
// mLEDList.append(NewLED);
// }
for(int i = 0; i < 30; i++)
{
// for(int led = 0; led < 10; led++)
{
QColor LedColor = QColor(50,0,0);
CRGBLedWidget *NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+1)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(100,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+2)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(150,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+3)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(200,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+4)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(255,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+5)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(200,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+6)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(150,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+7)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(100,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+8)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(50,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+9)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
LedColor = QColor(25,0,0);
NewLED = new CRGBLedWidget(LedColor,this);
NewLED->setPos(((i*10)+10)*(NewLED->boundingRect().width()+mLEDSpacing),0);
mLEDList.append(NewLED);
}
}
}
void CLedStringWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(Qt::darkGreen));
// painter->drawRect(boundingRect());
}
QRectF CLedStringWidget::boundingRect() const
{
if(mLEDList.size() == 0)
return QRectF();
//This assumes all leds are the same size...
return QRectF(0,
0,
mLEDList.size()*(mLEDSpacing + mLEDList.at(0)->boundingRect().width()),
mLEDList.at(0)->boundingRect().height());
}
int CLedStringWidget::SetLedStringColors(QList<QColor> *LEDColors)
{
if(LEDColors->size() != mLEDList.size())
{
return 0;
}
for(int i = 0; i < mLEDList.size(); i++)
{
mLEDList[i]->SetColor(LEDColors->at(i));
}
this->boundingRect();
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef LEDSTRINGWIDGET_H
#define LEDSTRINGWIDGET_H
#include <QGraphicsItem>
#include <QList>
#include "RGBLedWidget.h"
class CLedStringWidget : public QGraphicsItem
{
public:
CLedStringWidget(int NbLed, QGraphicsItem *parent = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
int SetLedStringColors(QList<QColor> *LEDColors);
int mNbLED;
int mLEDSpacing;
QRectF mBoundingRect;
QList<CRGBLedWidget*> mLEDList;
};
#endif // LEDSTRINGWIDGET_H
+145
View File
@@ -0,0 +1,145 @@
#include "LightShowWidget.h"
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <math.h>
#include <QScrollBar>
#define VIEW_CENTER viewport()->rect().center()
#define VIEW_WIDTH viewport()->rect().width()
#define VIEW_HEIGHT viewport()->rect().height()
CLightShowWidget::CLightShowWidget(QWidget *parent)
{
mScale = 1.0;
mDoMousePan = false;
setParent(parent);
mScene = new QGraphicsScene(this);
mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
mScene->setSceneRect(-5000, -5000, 10000, 10000);
// scene->setSceneRect(-100,-100,10000,10000);
setScene(mScene);
// setMinimumSize(500,500);
// setMaximumSize(parent->size());
setTransformationAnchor(AnchorUnderMouse);
// setTransformationAnchor(AnchorViewCenter);
setDragMode(QGraphicsView::NoDrag);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mViewportRect = new QGraphicsRectItem(0,0,50,50);
mViewportRect->setPen(QPen(Qt::darkBlue));
mSceneRect = new QGraphicsRectItem(sceneRect());
mSceneRect->setPen(QPen(Qt::red));
mLedStringRect = new QGraphicsRectItem();
mLedStringRect->setPen(QPen(Qt::darkGreen));
// test->setBrush(QBrush(Qt::darkBlue));
// mScene->addItem(mViewportRect);
// mScene->addItem(mSceneRect);
// mScene->addItem(mLedStringRect);
mLedStringWidget = new CLedStringWidget(300);
mScene->addItem(mLedStringWidget);
// mLedStringWidget->setTransform(QTransform::fromScale(10, 10), true);
mLedStringWidget->setPos(0,100);
setSceneRect(-100,-100,parentWidget()->geometry().width(),parentWidget()->geometry().height());
setMinimumSize(parentWidget()->geometry().width(),parentWidget()->geometry().height());
}
void CLightShowWidget::wheelEvent(QWheelEvent *event)
{
ScaleView(pow((double)2, event->delta() / 240.0));
}
void CLightShowWidget::ScaleView(qreal scaleFactor)
{
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
if (/*factor < 0.07 || */factor > 1)
return;
scale(scaleFactor, scaleFactor);
mScale *= scaleFactor;
qreal deltaW = factor * sceneRect().width();
qreal deltaH = factor * sceneRect().height();
}
void CLightShowWidget::ZoomIn()
{
ScaleView(qreal(1.2));
}
void CLightShowWidget::ZoomOut()
{
ScaleView(1 / qreal(1.2));
}
void CLightShowWidget::showEvent(QShowEvent *event)
{
mNominalTransform = transform();
mLedStringRect->setRect(mLedStringWidget->boundingRect());
}
void CLightShowWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
mLasMousePos = event->pos();
mDoMousePan = true;
}
QGraphicsView::mousePressEvent(event);
}
void CLightShowWidget::mouseMoveEvent(QMouseEvent *event)
{
if (mDoMousePan){
QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(mLasMousePos);
Pan(mouseDelta);
}
QGraphicsView::mouseMoveEvent(event);
mLasMousePos = event->pos();
}
void CLightShowWidget::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton){
mDoMousePan = false;
}
QGraphicsView::mouseReleaseEvent(event);
}
void CLightShowWidget::Pan(QPointF delta)
{
// Scale the pan amount by the current zoom.
// delta *= mScale;
delta *= PAN_SPEED;
// qDebug("Moving by x:%f, y:%f",delta.x(),delta.y());
delta.setX(-delta.rx());
delta.setY(-delta.ry());
QRectF NewViewRect = sceneRect();
NewViewRect.translate(delta.x(),delta.y());
mCurTransform = transform();
setSceneRect(NewViewRect);
mViewportRect->setRect(viewport()->geometry());
mSceneRect->setRect(sceneRect());
// qDebug("Scene Rect: left: %f, right:%f, top:%f, bottom:%f",sceneRect().left(),sceneRect().right(),sceneRect().top(),sceneRect().bottom());
// Have panning be anchored from the mouse.
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
}
+47
View File
@@ -0,0 +1,47 @@
#ifndef LIGHTSHOWWIDGET_H
#define LIGHTSHOWWIDGET_H
#include <QGraphicsView>
#include <QWheelEvent>
#include "LedStringWidget.h"
#include <QObject>
#define PAN_SPEED 1
class CLightShowWidget : public QGraphicsView
{
Q_OBJECT
public:
CLightShowWidget(QWidget *parent = 0);
void ScaleView(qreal scaleFactor);
void Pan(QPointF delta);
void showEvent(QShowEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
bool mDoMousePan;
qreal mScale;
QPoint mLasMousePos;
QGraphicsRectItem *mViewportRect, *mSceneRect, *mLedStringRect;
QGraphicsScene *mScene;
QTransform mCurTransform, mNominalTransform;
CLedStringWidget *mLedStringWidget;
public slots:
void ZoomIn();
void ZoomOut();
protected:
void wheelEvent(QWheelEvent *event);
};
#endif // LIGHTSHOWWIDGET_H
+62
View File
@@ -0,0 +1,62 @@
#include "RGBLedWidget.h"
#include <math.h>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
CRGBLedWidget::CRGBLedWidget(QColor Color, QGraphicsItem *parent)
{
setParentItem(parent);
mLEDColor = Color;
mIsSelected = false;
mLedDiameter = LED_DIAMETER;
}
void CRGBLedWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(mLEDColor));
painter->drawEllipse(0,0,mLedDiameter,mLedDiameter);
if(mIsSelected == true)
{
painter->setPen(Qt::black);
painter->setBrush(Qt::NoBrush);
painter->drawRect(0,0,mLedDiameter,mLedDiameter);
}
}
QRectF CRGBLedWidget::boundingRect() const
{
return QRectF(0,0,mLedDiameter,mLedDiameter);
}
void CRGBLedWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mIsSelected = !mIsSelected;
update(boundingRect());
qDebug("LedMouseRelease");
}
void CRGBLedWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug("LedMousePress");
}
int CRGBLedWidget::SetColor(QColor color)
{
mLEDColor = color;
return 1;
}
int CRGBLedWidget::SetColor(int r, int g, int b)
{
mLEDColor = QColor(r,g,b);
return 1;
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef RGBLEDWIDGET_H
#define RGBLEDWIDGET_H
#include <QGraphicsItem>
#define LED_DIAMETER 30.0
class CRGBLedWidget : public QGraphicsItem
{
public:
CRGBLedWidget(QColor Color = Qt::darkBlue, QGraphicsItem *parent = 0);
QColor mLEDColor;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
int SetColor(QColor color);
int SetColor(int r, int g, int b);
bool mIsSelected;
qreal mLedDiameter;
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
};
#endif // RGBLEDWIDGET_H
+18
View File
@@ -0,0 +1,18 @@
#include "TowerLightShowGui.h"
#include "ui_TowerLightShowGui.h"
CTowerLightShowGui::CTowerLightShowGui(QWidget *parent) :
QDialog(parent),
ui(new Ui::CTowerLightShowGui)
{
ui->setupUi(this);
mLightShowWidget = new CLightShowWidget(ui->mLightCtrlWidget);
//mLightShowWidget->resize(ui->mLightCtrlWidget->size());
}
CTowerLightShowGui::~CTowerLightShowGui()
{
delete ui;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef TOWERLIGHTSHOWGUI_H
#define TOWERLIGHTSHOWGUI_H
#include <QDialog>
#include "LightShowWidget.h"
namespace Ui {
class CTowerLightShowGui;
}
class CTowerLightShowGui : public QDialog
{
Q_OBJECT
public:
explicit CTowerLightShowGui(QWidget *parent = 0);
~CTowerLightShowGui();
CLightShowWidget *mLightShowWidget;
private:
Ui::CTowerLightShowGui *ui;
};
#endif // TOWERLIGHTSHOWGUI_H
+60
View File
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CTowerLightShowGui</class>
<widget class="QDialog" name="CTowerLightShowGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1694</width>
<height>658</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>470</x>
<y>20</y>
<width>171</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Tower Light Show</string>
</property>
</widget>
<widget class="QWidget" name="mLightCtrlWidget" native="true">
<property name="geometry">
<rect>
<x>39</x>
<y>119</y>
<width>1621</width>
<height>531</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>