- added icons in the top left corner which indicate connection status to the bas estation and off extentions connected to the base station

- minor changes
This commit is contained in:
Dorian Zedler 2019-03-24 21:16:16 +01:00
parent 1f8fdab69f
commit ef60a4065a
13 changed files with 117 additions and 71 deletions

BIN
graphics/BaseStation.xcf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -24,7 +24,7 @@ signals:
public slots:
QVariant getStyle();
Q_INVOKABLE bool changeTheme();
Q_INVOKABLE void changeTheme();
};
#endif // APPTHEME_H

View file

@ -26,7 +26,7 @@ public:
// values for the socket connection
int connection_progress;
QString ip;
qint16 port = 3563;
ushort port = 3563;
int errors;
int errors_until_disconnect = 4;

View file

@ -14,6 +14,7 @@ class ClimbingRace : public QObject
Q_OBJECT
Q_PROPERTY(int state READ getState NOTIFY stateChanged)
Q_PROPERTY(int mode READ getMode NOTIFY modeChanged)
Q_PROPERTY(QVariant timers READ getTimerTextList NOTIFY timerTextChanged)
Q_PROPERTY(QString baseStationState READ getBaseStationState NOTIFY baseStationStateChanged)
Q_PROPERTY(QVariant baseStationConnections READ getBaseStationConnections NOTIFY baseStationConnectionsChanged)
@ -38,6 +39,8 @@ private:
QTimer * timerTextRefreshTimer;
QTimer * nextStartActionTimer;
QDateTime *date;
QList<SpeedTimer *> speedTimers;
int nextStartAction;
@ -63,6 +66,7 @@ signals:
void nextStartActionDelayProgressChanged();
void stateChanged(int state);
void modeChanged();
void timerTextChanged();
void baseStationStateChanged();
void baseStationConnectionsChanged();
@ -76,6 +80,7 @@ public slots:
// functions for qml
Q_INVOKABLE int getState();
Q_INVOKABLE int getMode();
Q_INVOKABLE QVariant getTimerTextList();
Q_INVOKABLE double getNextStartActionDelayProgress();

View file

@ -7,8 +7,8 @@ Image {
source: "qrc:/graphics/icons/buzzer_black.png"
mipmap: true
opacity: status !== "disconnected" ? 1:0
visible: false
opacity: status === "connected" || status === "connecting" ? 1:0
visible: true
width: height
onOpacityChanged: visible = true

View file

@ -47,7 +47,7 @@ Item {
enabled: true
NumberAnimation {
duration: root.animationDuration
easing.type: Easing.InOutCubic
easing.type: Easing.Linear
}
}
@ -56,7 +56,7 @@ Item {
enabled: true
NumberAnimation {
duration: root.animationDuration
easing.type: Easing.InOutCubic
easing.type: Easing.Linear
}
}

View file

@ -141,6 +141,63 @@ Window {
}
}
Item {
id: connectionIconContainer
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: parent.bottom
bottomMargin: root.landscape() ? 0:parent.height * 0.8
rightMargin: root.landscape() ? parent.width * 0.8:0
}
ConnectionIcon {
id: baseConnConnIcon
status: speedBackend.baseStationState
source: "qrc:/graphics/icons/BaseStation_black.png"
anchors {
top: parent.top
topMargin: 10
left: parent.left
leftMargin: 10
}
scale: 1.3
height: !root.landscape()? parent.height*0.3:parent.width*0.3
}
ConnectionIcon {
id: buzzerConnIcon
status: speedBackend.baseStationConnections[1]["state"]
source: "qrc:/graphics/icons/buzzer_black.png"
anchors {
top: parent.top
topMargin: 10
left: baseConnConnIcon.right
leftMargin: 1
}
height: !root.landscape()? parent.height*0.17:parent.width*0.17
}
ConnectionIcon {
id: startpadConnIcon
status: speedBackend.baseStationConnections[0]["state"]
source: "qrc:/graphics/icons/startpad_black.png"
anchors {
top: parent.top
topMargin: 10
left: buzzerConnIcon.right
leftMargin: 0
}
height: !root.landscape() ? parent.height*0.17:parent.width*0.17
}
}
Rectangle {
id: upper_line
width: root.landscape() ? 1:parent.width
@ -226,7 +283,7 @@ Window {
}
}
animationDuration: 0
animationDuration: speedBackend.mode === 1 ? 150:0
}
/*----------------------

View file

@ -22,5 +22,7 @@
<file>graphics/icons/startpad_black.png</file>
<file>sounds/false.wav</file>
<file>graphics/icons/error.png</file>
<file>graphics/icons/BaseStation.png</file>
<file>graphics/icons/BaseStation_black.png</file>
</qresource>
</RCC>

View file

@ -82,7 +82,7 @@ QVariant AppTheme::getStyle() {
return *this->currentTheme;
}
bool AppTheme::changeTheme() {
void AppTheme::changeTheme() {
QString currentThemeString = pGlobalAppSettings->loadSetting("theme");
QString newThemeString = "Light";

View file

@ -122,14 +122,6 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
QString jsonRequest = QJsonDocument(requestObj).toJson();
QByteArray arrBlock;
QDataStream out(&arrBlock, QIODevice::WriteOnly);
//out.setVersion(QDataStream::Qt_5_10);
out << quint16(0) << jsonRequest;
out.device()->seek(0);
out << quint16(ulong(arrBlock.size()) - sizeof(quint16));
QTimer timer;
timer.setSingleShot(true);
@ -142,7 +134,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
//write data
socket->write(arrBlock);
socket->write(jsonRequest.toLatin1());
//wait for an answer to finish (programm gets stuck in here)
loop.exec();
@ -171,29 +163,8 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
}
void BaseConn::readyRead() {
QDataStream in(socket);
//in.setVersion(QDataStream::Qt_5_10);
qint16 nextBlockSize = 0;
for (;;)
{
if (!nextBlockSize)
{
if (ulong(socket->bytesAvailable()) < sizeof(quint16)) { break; }
in >> nextBlockSize;
}
if (socket->bytesAvailable() < nextBlockSize) { break; }
QString str; in >> str;
// if (str == "0")
// {
// str = "Connection closed";
// closeConnection();
// }
nextBlockSize = 0;
QString reply = str;
QString reply = socket->readAll();
int id = 0;
QJsonDocument jsonReply = QJsonDocument::fromJson(reply.toUtf8());
@ -211,10 +182,8 @@ void BaseConn::readyRead() {
}
}
latestReadReply = str;
emit gotUnexpectedReply(str);
}
latestReadReply = reply;
emit gotUnexpectedReply(reply);
}
int BaseConn::writeRemoteSetting(QString key, QString value) {

View file

@ -18,18 +18,19 @@ ClimbingRace::ClimbingRace(QObject *parent) : QObject(parent)
this->appSettings = new AppSettings;
this->baseConn = new BaseConn;
this->baseConn->setIP("192.168.4.1");
this->baseConn->setIP("ScStw");
connect(this->baseConn, &BaseConn::stateChanged, this, &ClimbingRace::baseStationStateChanged);
this->speedTimers.append( new SpeedTimer );
this->player = new QMediaPlayer;
this->date = new QDateTime;
this->nextStartActionTimer = new QTimer(this);
nextStartActionTimer->setSingleShot(true);
this->baseStationSyncTimer = new QTimer();
this->baseStationSyncTimer->setInterval(10);
this->baseStationSyncTimer->setInterval(100);
this->baseStationSyncTimer->setSingleShot(true);
this->baseStationSyncTimer->connect(this->baseStationSyncTimer, &QTimer::timeout, this, &ClimbingRace::syncWithBaseStation);
this->baseStationSyncTimer->start();
@ -228,19 +229,19 @@ void ClimbingRace::syncWithBaseStation() {
speedTimers[0]->setState(SpeedTimer::STARTING);
}
tmpReply = this->baseConn->sendCommand(2004);
if(tmpReply["status"] != 200){
//handle Error!!
qDebug() << "+ --- getting next start action from basestation failed: " << tmpReply["status"];
this->baseStationSyncTimer->start();
return;
}
else {
if(this->nextStartAction != tmpReply["data"].toInt()){
this->nextStartAction = tmpReply["data"].toInt();
this->nextStartActionChanged(this->nextStartAction);
}
}
// tmpReply = this->baseConn->sendCommand(2004);
// if(tmpReply["status"] != 200){
// //handle Error!!
// qDebug() << "+ --- getting next start action from basestation failed: " << tmpReply["status"];
// this->baseStationSyncTimer->start();
// return;
// }
// else {
// if(this->nextStartAction != tmpReply["data"].toInt()){
// this->nextStartAction = tmpReply["data"].toInt();
// this->nextStartActionChanged(this->nextStartAction);
// }
// }
tmpReply = this->baseConn->sendCommand(2005);
if(tmpReply["status"] != 200){
@ -270,6 +271,7 @@ void ClimbingRace::syncWithBaseStation() {
else {
QVariantList timers = tmpReply["data"].toList();
speedTimers[0]->startTime = this->date->currentMSecsSinceEpoch() - timers[0].toMap()["currTime"].toDouble();
speedTimers[0]->stoppedTime = timers[0].toMap()["currTime"].toDouble();
speedTimers[0]->reactionTime = timers[0].toMap()["reactTime"].toDouble();
@ -392,12 +394,19 @@ void ClimbingRace::setState(raceState newState) {
}
void ClimbingRace::refreshMode() {
raceMode newMode;
if(this->baseConn->state == "connected"){
this->mode = REMOTE;
newMode = REMOTE;
}
else {
this->mode = LOCAL;
newMode = LOCAL;
}
if(this->mode != newMode){
this->mode = newMode;
emit this->modeChanged();
}
}
void ClimbingRace::refreshTimerText() {
@ -456,6 +465,10 @@ int ClimbingRace::getState() {
return this->state;
}
int ClimbingRace::getMode() {
return this->mode;
}
QVariant ClimbingRace::getTimerTextList() {
return this->qmlTimers;
// QVariantList test;