From 0957a913f8958885a612dc12aed775df1ef179a3 Mon Sep 17 00:00:00 2001 From: dorian Date: Mon, 15 Apr 2019 13:33:31 +0200 Subject: [PATCH] - cleanup - implemented new state ('WAITING') - multiple timers are now supported at the frontend --- graphics/Buzzer.xcf | Bin 35938 -> 35938 bytes graphics/speedclimbing_stopwatch.xcf | Bin 505264 -> 505266 bytes headers/climbingrace.h | 4 +- headers/speedtimer.h | 2 +- qml/main.qml | 177 ++++++++++++++++++++++----- sources/climbingrace.cpp | 42 ++++--- sources/speedtimer.cpp | 3 + 7 files changed, 173 insertions(+), 55 deletions(-) diff --git a/graphics/Buzzer.xcf b/graphics/Buzzer.xcf index 840ecfb773688bc36a25f279649404c72b7fa08d..2cac802ec634855cac0788994da380c509558109 100644 GIT binary patch delta 907 zcmXxgu}cDB9LDiCIYBp}<#4DYt>hZI8sdaPAp?biyCD;5c!NN}3$Cs0?hj}$F8XaMyr)W4NEJ zTb?gU9Ox=;=-f~@+1yZXp$}qsxPV8Jy70IPPx!n!N1I$<&Y;UG&KGAY1{Je2vSMyu}^!bS@_hYMSy2E68%G+lJlrvV+nn<>0q z8?j?}2ZZE5AU%G$Ea8siL9)(n!3RlQ>eB$WC0+M~&4W7{x?{mE+v^$}ROxzwWV_U- x0UgjGozN+bXbc@7oE%$QSrCrFL6urmQa8NHevh7t_jM(ejC$$m==Je)>mM4=X9)lR delta 903 zcmXxgAxr{c7>Dss1{*du3p41=LuF?XgFA!cHgSW^06}EaaKVk+z|H10jASufazuiG zjY2RG3DaTFUzvHo{_eQ5Y}{t_F5X}rD}kIg4fiA?8V z`)#c-A8+nhk2=(B<1=>gb@A=iJnX(E_6Wc57pF2KOeRHJc!(aB(Z_qa>&m^6+@GIY z+;6fB9BWa=I4pF$Wg3Ttj;}tLNsgIZpw5Nzs3?y;=}zT|FefS6(*5St(jdQW6ujO4{+`TLEju&9#Og9?i(uKLoGRTfm+G>fV|_0^BO zUOAy>@+K*L{sF&bF*rmI%jnD707GnJBI7YA8&P?HV1)o>XUadjY|Lu_M& oJsjc({@?^>vYEs*W|!Kg=`tu{4Fe1ZUE3*j;)&0}%ia6dKO$gdq5uE@ diff --git a/graphics/speedclimbing_stopwatch.xcf b/graphics/speedclimbing_stopwatch.xcf index f92c2681e3332808cd2ebde451e1ca7f9cf2fc07..1ea0472c57ae92c4f099aff39f3c017773dc5b9e 100644 GIT binary patch delta 763 zcmXZYAxHyJ9LMpu)7=w;13`mfs6o)6B4{uyEG!IM*kEDcV3Q4;a>A5_3pO{BQkZZU-Zm%15 zO(omSNF-BQFRg5?ZdjvBh0QhZwkc2ND?%7E`pgO;Liz|HFB*aV4({U-HoU@Ec*v0| z76dAe2~1)N)0o8^=CO!n)TQ(zm4#KTq21NdAJhqGs&<+8kml-u`4HJe9W$RGo2xVC zb8O)yUTK|f!)t;Yyu*8Zz(;(-7ktGxe8&&`#4r5Dpa1)Hf!`qT4K%SI2XGLFaRj3{ zjuSYA(>R9>X{ckN1b+pceIx_6#DU8x8WS~8UoLRhARkQd!Rzl{gj!LDo1MkXDplR= 1 ? ( timerCol.height * 0.9 ) / timerRep.model:timerCol.height + + Label { + id: timerTextLa + + anchors.centerIn: parent + + width: ( parent.width * 0.8 ) + height: parent.height + + elide: "ElideRight" + color: appTheme.style.textColor + + text: speedBackend.timers[index]["text"] + + fontSizeMode: Text.Fit + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + font.pixelSize: root.landscape() ? parent.width * 0.15 : parent.height * 0.4 + + minimumPixelSize: 0 + + Behavior on text { + enabled: root.state !== "RUNNING" + FadeAnimation { + target: timerTextLa + } + } + } + + Label { + id: react_time + + property int rtime: speedBackend.timers[index]["reacttime"] + + anchors { + centerIn: parent + verticalCenterOffset: parent.height * 0.25 + } + + width: ( parent.width * 0.6 ) + height: parent.height + + fontSizeMode: Text.Fit + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + text: qsTr("reaction time (ms): ") + Math.round(rtime) + + opacity: (root.state === "RUNNING" || root.state === "STOPPED") && rtime !== 0 ? 1:0 + + color: appTheme.style.textColor + + font.pixelSize: timerTextLa.font.pixelSize * 0.5 + } + } + } + + Behavior on opacity { + NumberAnimation { + duration: 200 + } + } + } + + Behavior on opacity { + NumberAnimation { + duration: 200 } } } @@ -239,8 +334,8 @@ Window { width: root.landscape() ? 1:parent.width height: root.landscape() ? parent.height:1 color: appTheme.style.lineColor - anchors.left: root.landscape() ? time_container.right:parent.left - anchors.top: root.landscape() ? parent.top:time_container.bottom + anchors.left: root.landscape() ? topContainerItm.right:parent.left + anchors.top: root.landscape() ? parent.top:topContainerItm.bottom anchors.bottom: root.landscape() ? parent.bottom:undefined visible: false } @@ -524,9 +619,8 @@ Window { State { name: "IDLE" //state for the start page - PropertyChanges { target: timer_1; font.pixelSize: root.landscape() ? parent.width * 0.1:parent.height * 0.3; scale: 1 } PropertyChanges { - target: time_container; + target: topContainerItm; anchors.bottomMargin: root.landscape() ? undefined:parent.height * 0.1; anchors.rightMargin: root.landscape() ? parent.height * 0.05:0 } @@ -537,8 +631,27 @@ Window { anchors.bottomMargin: parent.height * 0.5 - startButt.height * 0.5 anchors.rightMargin: parent.width * 0.5 - startButt.width * 0.5 } + PropertyChanges { + target: topLa + text: qsTr("Click Start to start") + } }, + State { + name: "WAITING" + //state when a false start occured and waiting for time calculation + PropertyChanges { + target: startButt; enabled: false; text: qsTr("waiting..."); + anchors.rightMargin: root.landscape() ? parent.width * 0.05:parent.width * 0.5 - startButt.width * 0.5 //put the button more to the right to hide the menu (only in landscape mode) + anchors.bottomMargin: root.landscape() ? parent.height * 0.5 - startButt.height * 0.5:parent.height * 0.1 //put the button lower to hide the menu (only in portrait mode) + } + PropertyChanges { target: cancelButt; scale: 0; enabled: false} + PropertyChanges { target: menu_container; } + PropertyChanges { + target: topLa + text: qsTr("please wait...") + } + }, State { name: "STARTING" //state for the start sequence @@ -546,14 +659,17 @@ Window { anchors.rightMargin: root.landscape() ? parent.width * 0.05:parent.width * 0.5 - startButt.width * 0.5 //put the button more to the right to hide the menu (only in landscape mode) anchors.bottomMargin: root.landscape() ? parent.height * 0.5 - startButt.height * 0.5:parent.height * 0.1 //put the button lower to hide the menu (only in portrait mode) } - PropertyChanges { target: timer_1; font.pixelSize: root.landscape() ? parent.width * 0.2:parent.height * 0.3; scale: 1 } PropertyChanges { target: cancelButt; scale: 1} PropertyChanges { target: menu_container; } + PropertyChanges { + target: topLa + text: qsTr("starting...") + } + }, State { name: "RUNNING" //state when the timer is running - PropertyChanges { target: timer_1; font.pixelSize: root.landscape() ? parent.width * 0.2:parent.height * 0.3; scale: 1 } PropertyChanges { target: startButt; enabled: true; text: "stop" anchors.rightMargin: root.landscape() ? parent.width * 0.05:parent.width * 0.5 - startButt.width * 0.5 //put the button more to the right to hide the menu (only in landscape mode) @@ -565,11 +681,6 @@ Window { State { name: "STOPPED" //state when the meassuring is over - PropertyChanges { - target: timer_1; - font.pixelSize: root.landscape() ? parent.width * 0.15:parent.height * 0.1; - scale: 1 - } PropertyChanges { target: startButt; enabled: true; text: qsTr("reset"); @@ -578,7 +689,7 @@ Window { anchors.rightMargin: root.landscape() ? parent.height * 0.2 - startButt.height * 0.5:parent.width * 0.5 - startButt.width * 0.5 } PropertyChanges { - target: time_container; + target: topContainerItm; anchors.rightMargin: root.landscape() ? 0-startButt.width/2:undefined anchors.bottomMargin: root.landscape() ? undefined:0-startButt.height/2 } diff --git a/sources/climbingrace.cpp b/sources/climbingrace.cpp index cdd24b5..50922c1 100644 --- a/sources/climbingrace.cpp +++ b/sources/climbingrace.cpp @@ -226,9 +226,7 @@ void ClimbingRace::syncWithBaseStation() { case 1: { // case STARTING - if(speedTimers[0]->state != 1){ - speedTimers[0]->setState(SpeedTimer::STARTING); - } + this->refreshRemoteTimers(); tmpReply = this->baseConn->sendCommand(2005); if(tmpReply["status"] != 200){ @@ -247,23 +245,7 @@ void ClimbingRace::syncWithBaseStation() { default: { - // get current time - tmpReply = this->baseConn->sendCommand(2007); - if(tmpReply["status"] != 200){ - //handle error!! - qDebug() << "+ --- getting timers from basestation failed"; - this->baseStationSyncTimer->start(); - return; - } - 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(); - - speedTimers[0]->setState(SpeedTimer::timerState(timers[0].toMap()["state"].toInt())); - } + this->refreshRemoteTimers(); break; } @@ -443,6 +425,26 @@ void ClimbingRace::refreshTimerText() { this->timerTextRefreshTimer->start(); } +bool ClimbingRace::refreshRemoteTimers() { + // get current time + QVariantMap tmpReply = this->baseConn->sendCommand(2007); + if(tmpReply["status"] != 200){ + //handle error!! + qDebug() << "+ --- getting timers from basestation failed"; + this->baseStationSyncTimer->start(); + return false; + } + 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(); + + speedTimers[0]->setState(SpeedTimer::timerState(timers[0].toMap()["state"].toInt())); + } +} + // ------------------------- // --- functions for qml --- // ------------------------- diff --git a/sources/speedtimer.cpp b/sources/speedtimer.cpp index 5350e8a..8265870 100644 --- a/sources/speedtimer.cpp +++ b/sources/speedtimer.cpp @@ -132,6 +132,9 @@ QString SpeedTimer::getText() { case SpeedTimer::STARTING: newText = "0.000 sec"; break; + case SpeedTimer::WAITING: + newText = tr("Please wait..."); + break; case SpeedTimer::RUNNING: newText = QString::number( this->getCurrTime() / 1000.0, 'f', 3 ) + " sec"; break;