diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index f568ee0..a144a07 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -288,11 +288,21 @@ Popup { key = "AT_MARKS_DELAY" break } - baseConn.sendCommand("SET_SETTING_"+key+"_"+val) + baseConn.sendCommand(3000, [key, val]) } del.enabled = true } + function loadSetting(key, del){ + del.enabled = false + var val = _cppAppSettings.loadSetting(key) + if(baseConn.state === "connected"){ + val = baseConn.sendCommand(3001, key)["data"] + } + del.enabled = true + return val + } + SwitchDelegate { id: ready_del text: qsTr("say 'ready'") @@ -302,7 +312,7 @@ Popup { font.pixelSize: options_stack.text_pixelSize } - checked: _cppAppSettings.loadSetting("ready_en") === "true" + checked: parent.loadSetting("ready_en", ready_del) === "true" width: parent.width height: parent.delegateHeight @@ -339,7 +349,7 @@ Popup { anchors.verticalCenter: parent.verticalCenter inputMethodHints: Qt.ImhFormattedNumbersOnly - text: _cppAppSettings.loadSetting("ready_delay") + text: autostart_col.loadSetting("ready_delay", ready_del) onTextChanged: { autostart_col.updateSett("ready_delay", text, ready_delay_del) @@ -356,7 +366,7 @@ Popup { font.pixelSize: options_stack.text_pixelSize } - checked: _cppAppSettings.loadSetting("at_marks_en") === "true" + checked: autostart_col.loadSetting("at_marks_en", ready_del) === "true" width: parent.width //height: parent.delegateHeight * 1.5 @@ -393,7 +403,7 @@ Popup { anchors.verticalCenter: parent.verticalCenter inputMethodHints: Qt.ImhFormattedNumbersOnly - text: _cppAppSettings.loadSetting("at_marks_delay") + text: autostart_col.loadSetting("at_marks_delay", ready_del) onTextChanged: { autostart_col.updateSett("at_marks_delay",text, at_marks_delay_del) diff --git a/qml/main.qml b/qml/main.qml index b443ace..5aaf498 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -125,13 +125,13 @@ Window { onNextRemoteActionChanged: { switch(nextRemoteAction){ - case "at_marks": + case "0": timer_1.text = "at your\nmarks" break - case "ready": + case "1": timer_1.text = "ready" break - case "start": + case "2": timer_1.text = "0.000 sec" break } diff --git a/sources/baseconn.cpp b/sources/baseconn.cpp index e598ec7..004f11d 100644 --- a/sources/baseconn.cpp +++ b/sources/baseconn.cpp @@ -225,81 +225,116 @@ void BaseConn::readyRead() { /*-----Functions to control the local stopwatch-----*/ + + void BaseConn::refreshTimers(){ if(this->state != "connected"){ this->refreshTimer->start(); return; } - QString remoteState; - QString remoteTime; - QString tmpNextRemoteAction; - QString tmpNextRemoteActionDelayProg; + QVariantMap tmpReply = this->sendCommand(2000); - remoteState = sendCommand(2000)["data"].toString(); + if(tmpReply["status"] != 200){ + return; + } + + int remoteRaceState = tmpReply["data"].toInt(); + + switch (remoteRaceState) { + case 0: + { + // case IDLE + if(speedTimers[0]->state != 0){ + speedTimers[0]->setState(SpeedTimer::IDLE); + } - switch (speedTimers[0]->state) { - case SpeedTimer::IDLE: break; - case SpeedTimer::STARTING: - if(remoteState == "2"){ - speedTimers[0]->start(); - } - else if (remoteState == "3") { - speedTimers[0]->stop("manual"); + } + case 1: + { + // case STARTING + if(speedTimers[0]->state != 1){ + speedTimers[0]->setState(SpeedTimer::STARTING); } - tmpNextRemoteAction = sendCommand(2004)["data"].toString(); - if(tmpNextRemoteAction.startsWith("ERR")){ + tmpReply = sendCommand(2004); + if(tmpReply["status"] != 200){ //handle Error!! + qDebug() << "+--- getting next start action from basestation failed: " << tmpReply["status"]; + this->refreshTimer->start(); + return; } else { - if(this->nextRemoteAction != tmpNextRemoteAction){ - this->nextRemoteAction = tmpNextRemoteAction; + if(this->nextRemoteAction != tmpReply["data"].toString()){ + this->nextRemoteAction = tmpReply["data"].toString(); this->nextRemoteActionChanged(); } } - tmpNextRemoteActionDelayProg = sendCommand(2005)["data"].toFloat(); - if(tmpNextRemoteActionDelayProg.startsWith("ERR")){ + tmpReply = sendCommand(2005); + if(tmpReply["status"] != 200){ //handle error!! + qDebug() << "+--- getting next start action progress from basestation failed"; + this->refreshTimer->start(); + return; } else { - if(this->nextRemoteActionDelayProg != tmpNextRemoteActionDelayProg.toFloat()){ - this->nextRemoteActionDelayProg = tmpNextRemoteActionDelayProg.toFloat(); + if(this->nextRemoteActionDelayProg != tmpReply["data"].toFloat()){ + this->nextRemoteActionDelayProg = tmpReply["data"].toFloat(); this->nextRemoteActionDelayProgChanged(); } } break; - case SpeedTimer::RUNNING: - - if(remoteState == "2"){ - speedTimers[0]->stop("manual"); + } + case 2: + { + // case RUNNING + if(speedTimers[0]->state != 2){ + speedTimers[0]->setState(SpeedTimer::RUNNING); } - remoteTime = sendCommand("GET_CURRTIME"); - if(remoteTime.startsWith("ERR")){ + + // get current time + tmpReply = sendCommand(2001, 0); + if(tmpReply["status"] != 200){ //handle error!! + qDebug() << "+--- getting current time (timer 0) from basestation failed"; + this->refreshTimer->start(); + return; } else { - speedTimers[0]->stoppedTime = remoteTime.toInt(); + speedTimers[0]->stoppedTime = tmpReply["data"].toInt(); } - break; - case SpeedTimer::STOPPED: - remoteTime = sendCommand("GET_STOPPED_TIME"); - if(remoteTime.startsWith("ERR")){ - //handle error!! - } - else { - speedTimers[0]->stoppedTime = remoteTime.toInt(); - } break; } + case 3: + { + // case STOPPED + if(speedTimers[0]->state != 3){ + speedTimers[0]->setState(SpeedTimer::STOPPED); + } - if(speedTimers[0]->state != speedTimers[0]->stateFromString(remoteState)){ - // speedTimers[0]->setState(speedTimers[0]->stateFromString(remoteState)); - qWarning() << "WARNING: Remote State not matching!!" << " remote state: " << remoteState << " local state: " << this->speedTimers[0]->getState(); + // get current time + tmpReply = sendCommand(2001, 0); + if(tmpReply["status"] != 200){ + //handle error!! + qDebug() << "+--- getting current time (timer 0) from basestation failed"; + return; + } + else { + speedTimers[0]->stoppedTime = tmpReply["data"].toInt(); + } + + break; + } + default: + { + // some error + + break; + } } this->refreshTimer->start(); @@ -308,9 +343,9 @@ void BaseConn::refreshTimers(){ bool BaseConn::startTimers(){ qDebug() << "starting timers"; - QString ret = this->sendCommand("CMD_START_TIMER"); + QVariantMap reply = this->sendCommand(1000); - if(ret.startsWith("ERR")){ + if(reply["status"] != 200){ //handle Error!! return false; } @@ -322,10 +357,10 @@ bool BaseConn::startTimers(){ bool BaseConn::stopTimers(QString type){ qDebug() << "stopping timers"; - QString ret = this->sendCommand("CMD_STOP_TIMER"); + QVariantMap reply = this->sendCommand(1001); - if(ret.startsWith("ERR")){ - //handle Error! + if(reply["status"] != 200){ + //handle Error!! return false; } @@ -337,10 +372,10 @@ bool BaseConn::stopTimers(QString type){ bool BaseConn::resetTimers(){ qDebug() << "resetting timers"; - QString ret = this->sendCommand("CMD_RESET_TIMER"); + QVariantMap reply = this->sendCommand(1002); - if(ret.startsWith("ERR")){ - //handle Error! + if(reply["status"] != 200){ + //handle Error!! return false; } @@ -373,11 +408,13 @@ int BaseConn::getProgress() const } bool BaseConn::refreshConnections() { - QString ret = this->sendCommand("GET_CONNECTIONS"); - if(ret.startsWith("ERR")){ + QVariantMap reply = this->sendCommand(2006); + + if(reply["status"] != 200){ + //handle Error!! return false; } - connections = ret.split("|||"); + connections = reply["data"].toString().split("|||"); return true; }