finished to implement new JSON API, everything seems to work fine, but there are still some crashes and bugs

This commit is contained in:
Dorian Zedler 2019-03-03 17:31:24 +01:00
parent 3cea0af9b5
commit 88cf8a4328
6 changed files with 28 additions and 101 deletions

View file

@ -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();

View file

@ -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)
}
}
}

View file

@ -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()
}

View file

@ -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("|||");

View file

@ -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);
}

View file

@ -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);
}