continued implementing the new JSON API (caution: START SEQUENCE SETTINGS STILL NOT WORKING)
This commit is contained in:
parent
3ee2d2ac57
commit
3cea0af9b5
3 changed files with 106 additions and 59 deletions
|
@ -288,11 +288,21 @@ Popup {
|
||||||
key = "AT_MARKS_DELAY"
|
key = "AT_MARKS_DELAY"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
baseConn.sendCommand("SET_SETTING_"+key+"_"+val)
|
baseConn.sendCommand(3000, [key, val])
|
||||||
}
|
}
|
||||||
del.enabled = true
|
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 {
|
SwitchDelegate {
|
||||||
id: ready_del
|
id: ready_del
|
||||||
text: qsTr("say 'ready'")
|
text: qsTr("say 'ready'")
|
||||||
|
@ -302,7 +312,7 @@ Popup {
|
||||||
font.pixelSize: options_stack.text_pixelSize
|
font.pixelSize: options_stack.text_pixelSize
|
||||||
}
|
}
|
||||||
|
|
||||||
checked: _cppAppSettings.loadSetting("ready_en") === "true"
|
checked: parent.loadSetting("ready_en", ready_del) === "true"
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.delegateHeight
|
height: parent.delegateHeight
|
||||||
|
|
||||||
|
@ -339,7 +349,7 @@ Popup {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
inputMethodHints: Qt.ImhFormattedNumbersOnly
|
inputMethodHints: Qt.ImhFormattedNumbersOnly
|
||||||
|
|
||||||
text: _cppAppSettings.loadSetting("ready_delay")
|
text: autostart_col.loadSetting("ready_delay", ready_del)
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
autostart_col.updateSett("ready_delay", text, ready_delay_del)
|
autostart_col.updateSett("ready_delay", text, ready_delay_del)
|
||||||
|
@ -356,7 +366,7 @@ Popup {
|
||||||
font.pixelSize: options_stack.text_pixelSize
|
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
|
width: parent.width
|
||||||
//height: parent.delegateHeight * 1.5
|
//height: parent.delegateHeight * 1.5
|
||||||
|
|
||||||
|
@ -393,7 +403,7 @@ Popup {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
inputMethodHints: Qt.ImhFormattedNumbersOnly
|
inputMethodHints: Qt.ImhFormattedNumbersOnly
|
||||||
|
|
||||||
text: _cppAppSettings.loadSetting("at_marks_delay")
|
text: autostart_col.loadSetting("at_marks_delay", ready_del)
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
autostart_col.updateSett("at_marks_delay",text, at_marks_delay_del)
|
autostart_col.updateSett("at_marks_delay",text, at_marks_delay_del)
|
||||||
|
|
|
@ -125,13 +125,13 @@ Window {
|
||||||
|
|
||||||
onNextRemoteActionChanged: {
|
onNextRemoteActionChanged: {
|
||||||
switch(nextRemoteAction){
|
switch(nextRemoteAction){
|
||||||
case "at_marks":
|
case "0":
|
||||||
timer_1.text = "at your\nmarks"
|
timer_1.text = "at your\nmarks"
|
||||||
break
|
break
|
||||||
case "ready":
|
case "1":
|
||||||
timer_1.text = "ready"
|
timer_1.text = "ready"
|
||||||
break
|
break
|
||||||
case "start":
|
case "2":
|
||||||
timer_1.text = "0.000 sec"
|
timer_1.text = "0.000 sec"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,81 +225,116 @@ void BaseConn::readyRead() {
|
||||||
|
|
||||||
/*-----Functions to control the local stopwatch-----*/
|
/*-----Functions to control the local stopwatch-----*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BaseConn::refreshTimers(){
|
void BaseConn::refreshTimers(){
|
||||||
if(this->state != "connected"){
|
if(this->state != "connected"){
|
||||||
this->refreshTimer->start();
|
this->refreshTimer->start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString remoteState;
|
QVariantMap tmpReply = this->sendCommand(2000);
|
||||||
QString remoteTime;
|
|
||||||
QString tmpNextRemoteAction;
|
|
||||||
QString tmpNextRemoteActionDelayProg;
|
|
||||||
|
|
||||||
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;
|
break;
|
||||||
case SpeedTimer::STARTING:
|
}
|
||||||
if(remoteState == "2"){
|
case 1:
|
||||||
speedTimers[0]->start();
|
{
|
||||||
}
|
// case STARTING
|
||||||
else if (remoteState == "3") {
|
if(speedTimers[0]->state != 1){
|
||||||
speedTimers[0]->stop("manual");
|
speedTimers[0]->setState(SpeedTimer::STARTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpNextRemoteAction = sendCommand(2004)["data"].toString();
|
tmpReply = sendCommand(2004);
|
||||||
if(tmpNextRemoteAction.startsWith("ERR")){
|
if(tmpReply["status"] != 200){
|
||||||
//handle Error!!
|
//handle Error!!
|
||||||
|
qDebug() << "+--- getting next start action from basestation failed: " << tmpReply["status"];
|
||||||
|
this->refreshTimer->start();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(this->nextRemoteAction != tmpNextRemoteAction){
|
if(this->nextRemoteAction != tmpReply["data"].toString()){
|
||||||
this->nextRemoteAction = tmpNextRemoteAction;
|
this->nextRemoteAction = tmpReply["data"].toString();
|
||||||
this->nextRemoteActionChanged();
|
this->nextRemoteActionChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpNextRemoteActionDelayProg = sendCommand(2005)["data"].toFloat();
|
tmpReply = sendCommand(2005);
|
||||||
if(tmpNextRemoteActionDelayProg.startsWith("ERR")){
|
if(tmpReply["status"] != 200){
|
||||||
//handle error!!
|
//handle error!!
|
||||||
|
qDebug() << "+--- getting next start action progress from basestation failed";
|
||||||
|
this->refreshTimer->start();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(this->nextRemoteActionDelayProg != tmpNextRemoteActionDelayProg.toFloat()){
|
if(this->nextRemoteActionDelayProg != tmpReply["data"].toFloat()){
|
||||||
this->nextRemoteActionDelayProg = tmpNextRemoteActionDelayProg.toFloat();
|
this->nextRemoteActionDelayProg = tmpReply["data"].toFloat();
|
||||||
this->nextRemoteActionDelayProgChanged();
|
this->nextRemoteActionDelayProgChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SpeedTimer::RUNNING:
|
}
|
||||||
|
case 2:
|
||||||
if(remoteState == "2"){
|
{
|
||||||
speedTimers[0]->stop("manual");
|
// 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!!
|
//handle error!!
|
||||||
|
qDebug() << "+--- getting current time (timer 0) from basestation failed";
|
||||||
|
this->refreshTimer->start();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
// case STOPPED
|
||||||
|
if(speedTimers[0]->state != 3){
|
||||||
|
speedTimers[0]->setState(SpeedTimer::STOPPED);
|
||||||
|
}
|
||||||
|
|
||||||
if(speedTimers[0]->state != speedTimers[0]->stateFromString(remoteState)){
|
// get current time
|
||||||
// speedTimers[0]->setState(speedTimers[0]->stateFromString(remoteState));
|
tmpReply = sendCommand(2001, 0);
|
||||||
qWarning() << "WARNING: Remote State not matching!!" << " remote state: " << remoteState << " local state: " << this->speedTimers[0]->getState();
|
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();
|
this->refreshTimer->start();
|
||||||
|
@ -308,9 +343,9 @@ void BaseConn::refreshTimers(){
|
||||||
bool BaseConn::startTimers(){
|
bool BaseConn::startTimers(){
|
||||||
qDebug() << "starting timers";
|
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!!
|
//handle Error!!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -322,10 +357,10 @@ bool BaseConn::startTimers(){
|
||||||
bool BaseConn::stopTimers(QString type){
|
bool BaseConn::stopTimers(QString type){
|
||||||
qDebug() << "stopping timers";
|
qDebug() << "stopping timers";
|
||||||
|
|
||||||
QString ret = this->sendCommand("CMD_STOP_TIMER");
|
QVariantMap reply = this->sendCommand(1001);
|
||||||
|
|
||||||
if(ret.startsWith("ERR")){
|
if(reply["status"] != 200){
|
||||||
//handle Error!
|
//handle Error!!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,10 +372,10 @@ bool BaseConn::stopTimers(QString type){
|
||||||
bool BaseConn::resetTimers(){
|
bool BaseConn::resetTimers(){
|
||||||
qDebug() << "resetting timers";
|
qDebug() << "resetting timers";
|
||||||
|
|
||||||
QString ret = this->sendCommand("CMD_RESET_TIMER");
|
QVariantMap reply = this->sendCommand(1002);
|
||||||
|
|
||||||
if(ret.startsWith("ERR")){
|
if(reply["status"] != 200){
|
||||||
//handle Error!
|
//handle Error!!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,11 +408,13 @@ int BaseConn::getProgress() const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConn::refreshConnections() {
|
bool BaseConn::refreshConnections() {
|
||||||
QString ret = this->sendCommand("GET_CONNECTIONS");
|
QVariantMap reply = this->sendCommand(2006);
|
||||||
if(ret.startsWith("ERR")){
|
|
||||||
|
if(reply["status"] != 200){
|
||||||
|
//handle Error!!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
connections = ret.split("|||");
|
connections = reply["data"].toString().split("|||");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue