diff --git a/headers/baseconn.h b/headers/baseconn.h index 928aa1f..c2650a3 100644 --- a/headers/baseconn.h +++ b/headers/baseconn.h @@ -106,6 +106,8 @@ public slots: Q_INVOKABLE QVariantMap sendCommand(int header, QJsonValue data); + Q_INVOKABLE int writeRemoteSetting(QString key, QString value); + Q_INVOKABLE bool refreshConnections(); void refreshTimers(); diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index a144a07..3ee914f 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -270,35 +270,29 @@ Popup { property string title: "Autostart" property int delegateHeight: height*0.18 - function updateSett(key, val, del){ + function updateSetting(key, val, del){ del.enabled = false - _cppAppSettings.writeSetting(key, val) + if(baseConn.state === "connected"){ - switch(key){ - case "ready_en": - key = "READY_EN" - break - case "ready_delay": - key = "READY_DELAY" - break - case "at_marks_en": - key = "AT_MARKS_EN" - break - case "at_marks_delay": - key = "AT_MARKS_DELAY" - break - } - baseConn.sendCommand(3000, [key, val]) + baseConn.writeRemoteSetting(key, val) } + else { + _cppAppSettings.writeSetting(key, val) + } + del.enabled = true } function loadSetting(key, del){ del.enabled = false - var val = _cppAppSettings.loadSetting(key) + var val if(baseConn.state === "connected"){ val = baseConn.sendCommand(3001, key)["data"] } + else { + val = _cppAppSettings.loadSetting(key) + } + del.enabled = true return val } @@ -319,7 +313,7 @@ Popup { font.pixelSize: options_stack.text_pixelSize onCheckedChanged: { - parent.updateSett("ready_en",checked, ready_del) + parent.updateSetting("ready_en",checked, ready_del) } @@ -352,7 +346,7 @@ Popup { text: autostart_col.loadSetting("ready_delay", ready_del) onTextChanged: { - autostart_col.updateSett("ready_delay", text, ready_delay_del) + autostart_col.updateSetting("ready_delay", text, ready_delay_del) } } } @@ -373,7 +367,7 @@ Popup { font.pixelSize: options_stack.text_pixelSize onCheckedChanged: { - parent.updateSett("at_marks_en",at_marks_del.checked, at_marks_del) + parent.updateSetting("at_marks_en",at_marks_del.checked, at_marks_del) } indicator: SimpleIndicator{} @@ -406,7 +400,7 @@ Popup { text: autostart_col.loadSetting("at_marks_delay", ready_del) onTextChanged: { - autostart_col.updateSett("at_marks_delay",text, at_marks_delay_del) + autostart_col.updateSetting("at_marks_delay",text, at_marks_delay_del) } } } diff --git a/qml/main.qml b/qml/main.qml index 5aaf498..e0f4350 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -119,7 +119,7 @@ Window { BaseStationConn { id: baseConn - ipAdress: "localhost" + ipAdress: "192.168.4.1" property var status: {'status': baseConn.state, 'progress': baseConn.progress, 'connections': baseConn.connections} @@ -138,79 +138,9 @@ Window { } onNextRemoteActionDelayProgChanged: { - console.log(nextRemoteActionDelayProg) prog.progress = baseConn.nextRemoteActionDelayProg * 100 - console.log(prog.progress) } } - - Timer { - id: baseRefreshTimer - running: false - repeat: false - - interval: 1 - onTriggered: { - switch(root.state){ - case "RUNNING": - var baseReactTime = parseInt(baseConn.sendCommand("GET_REACTTIME")) - console.log(baseReactTime) - if(baseReactTime !== 0){ - root.last_run.react_time = baseReactTime - } - timer_1.text = baseConn.getTime("readable") + " sec" - if(baseConn.sendCommand("GET_TIMER_STATE") === "STOPPED"){ - root.stop("manual") - } - break - case "STARTING": - var baseReactTime = parseInt(baseConn.sendCommand("GET_REACTTIME")) - if(baseReactTime !== 0){ - root.last_run.react_time = baseReactTime - } - - var baseNextAction = baseConn.sendCommand("GET_NEXT_ACTION") - - if(baseNextAction === "at_marks"){ - timer_1.text = qsTr("at your\nmarks") - var baseNextActionDelay = parseFloat(baseConn.sendCommand("GET_NEXT_ACTION_DELAY_PROG")) - prog.progress = baseNextActionDelay * 100 - } - else if(baseNextAction === "ready"){ - timer_1.text = qsTr("ready") - var baseNextActionDelay = parseFloat(baseConn.sendCommand("GET_NEXT_ACTION_DELAY_PROG")) - prog.progress = baseNextActionDelay * 100 - } - else if(baseNextAction === "start"){ - timer_1.text = "0.000 sec" - } - - - - var baseState = baseConn.sendCommand("GET_TIMER_STATE") - console.log(baseState) - if(baseState === "RUNNING"){ - timer_1.start(1) - root.state = "RUNNING"; - } - else if(baseState === "STOPPED"){ - var baseReactTime = parseInt(baseConn.sendCommand("GET_REACTTIME")) - if(baseReactTime<0){ - root.stop("false") - } - else{ - root.stop("cancel") - } - - - root.state = "STOPPED" - } - break - } - start() - } - } - } @@ -338,7 +268,6 @@ Window { text: "0.000 sec" onStateChanged: { - console.log(newState) root.state = timer_1.getState() } @@ -488,7 +417,7 @@ Window { :(360/100) * progress colorCircle: "grey" onProgressChanged: { - console.log(progress) + //console.log(progress) } animationDuration: baseConn.state === "connected" ? 150:0 @@ -499,7 +428,6 @@ Window { interval: 1 repeat: false onTriggered: { - console.log("prog refresh timer") prog.arcEnd = 360 * (( next_actionTimer.interval - ( new Date().getTime() - next_actionTimer.started_at ) ) / next_actionTimer.interval) prog_refresh.start() } diff --git a/sources/baseconn.cpp b/sources/baseconn.cpp index 004f11d..a0180b3 100644 --- a/sources/baseconn.cpp +++ b/sources/baseconn.cpp @@ -223,9 +223,12 @@ void BaseConn::readyRead() { } } -/*-----Functions to control the local stopwatch-----*/ - - +int BaseConn::writeRemoteSetting(QString key, QString value) { + QJsonArray requestData; + requestData.append(key); + requestData.append(value); + return this->sendCommand(3000, requestData)["status"].toInt(); +} void BaseConn::refreshTimers(){ if(this->state != "connected"){ @@ -412,6 +415,7 @@ bool BaseConn::refreshConnections() { if(reply["status"] != 200){ //handle Error!! + qDebug() << "+--- error refreshing connections: " << reply["status"]; return false; } connections = reply["data"].toString().split("|||"); diff --git a/sources/speedtimer.cpp b/sources/speedtimer.cpp index c345315..fe1d7a0 100644 --- a/sources/speedtimer.cpp +++ b/sources/speedtimer.cpp @@ -83,7 +83,7 @@ void SpeedTimer::reset(){ void SpeedTimer::setState(timerState newState){ this->state = newState; - qDebug() << "timer state changed: " << newState; + qDebug() << "+--- timer state changed: " << newState; emit this->stateChanged(newState); } diff --git a/sources/speedtimerqmladapter.cpp b/sources/speedtimerqmladapter.cpp index 7ab15e2..18f9759 100644 --- a/sources/speedtimerqmladapter.cpp +++ b/sources/speedtimerqmladapter.cpp @@ -30,7 +30,6 @@ QString SpeedTimerQmlAdapter::getState(){ void SpeedTimerQmlAdapter::setState(SpeedTimer::timerState newState){ this->state = newState; - qDebug() << "tmer state changed: " << newState; emit this->stateChanged(newState); }