- fixed a bug in baseconn

- added volume regulation for base station
This commit is contained in:
Dorian Zedler 2019-04-08 18:03:23 +02:00
parent 575b508d56
commit ab7154cfd0
9 changed files with 152 additions and 22 deletions

View file

@ -53,6 +53,7 @@ private:
// helper vars // helper vars
QVariantList qmlTimers; QVariantList qmlTimers;
const QStringList remoteSettings = {"ready_en", "ready_delay", "at_marks_en", "at_marks_delay"}; const QStringList remoteSettings = {"ready_en", "ready_delay", "at_marks_en", "at_marks_delay"};
const QStringList remoteOnlySettings = {"soundVolume"};
private slots: private slots:
// helper functions // helper functions

View file

@ -330,7 +330,7 @@ Popup {
inputText: autostart_col.loadSetting("ready_delay", ready_del) inputText: autostart_col.loadSetting("ready_delay", ready_del)
onInputTextChanged: { onInputFinished: {
autostart_col.updateSetting("ready_delay", inputText, ready_delay_del) autostart_col.updateSetting("ready_delay", inputText, ready_delay_del)
} }
} }
@ -364,7 +364,7 @@ Popup {
inputText: autostart_col.loadSetting("at_marks_delay", at_marks_delay_del) inputText: autostart_col.loadSetting("at_marks_delay", at_marks_delay_del)
onInputTextChanged: { onInputFinished: {
autostart_col.updateSetting("at_marks_delay", inputText, at_marks_delay_del) autostart_col.updateSetting("at_marks_delay", inputText, at_marks_delay_del)
} }
} }
@ -380,8 +380,19 @@ Popup {
spacing: options_stack.rowSpacing spacing: options_stack.rowSpacing
function baseConnected(){ property bool baseConnected: false
return speedBackend.baseStationState === "connected"
Connections {
target: speedBackend
onBaseStationStateChanged: {
if(speedBackend.baseStationState === "connected"){
connectCol.baseConnected = true
}
else {
connectCol.baseConnected = false
}
}
} }
ConnectionDelegate { ConnectionDelegate {
@ -414,7 +425,7 @@ Popup {
} }
width: parent.width width: parent.width
height: !connectCol.baseConnected() ? options_stack.delegateHeight:0 height: !connectCol.baseConnected ? options_stack.delegateHeight:0
visible: height > 5 visible: height > 5
@ -426,12 +437,48 @@ Popup {
} }
} }
SmoothSliderDelegate {
id: baseStationVolumeDel
text: qsTr("volume")
property bool active: connectCol.baseConnected
width: parent.width
height: active ? options_stack.delegateHeight:0
visible: height > 5
sliderValue: 0
onSliderFinished: {
speedBackend.writeSetting("soundVolume", sliderValue)
}
onActiveChanged: {
if(active){
var val = speedBackend.readSetting("soundVolume")
console.log(val)
if(val !== "false"){
sliderValue = parseFloat(val)
}
}
}
Behavior on height {
NumberAnimation {
duration: 400
easing.type: Easing.Linear
}
}
}
NextPageDelegate { NextPageDelegate {
id: baseStationConnectionsDel id: baseStationConnectionsDel
text: qsTr("connected extensions") text: qsTr("connected extensions")
width: parent.width width: parent.width
height: connectCol.baseConnected() ? options_stack.delegateHeight:0 height: connectCol.baseConnected ? options_stack.delegateHeight:0
visible: height > 5 visible: height > 5

View file

@ -7,6 +7,8 @@ SmoothItemDelegate {
property string inputText: "" property string inputText: ""
property string inputHint: "" property string inputHint: ""
signal inputFinished()
property int inputMethodHints: Qt.ImhNone property int inputMethodHints: Qt.ImhNone
property int inputTextFieldWidth: control.width * 0.3 property int inputTextFieldWidth: control.width * 0.3
@ -15,8 +17,6 @@ SmoothItemDelegate {
textField.text = inputText textField.text = inputText
} }
text: qsTr("delay (ms)")
width: parent.width width: parent.width
rightPadding: textField.width + width * 0.02 rightPadding: textField.width + width * 0.02
height: parent.delegateHeight height: parent.delegateHeight
@ -44,6 +44,12 @@ SmoothItemDelegate {
control.inputTextChanged() control.inputTextChanged()
} }
onActiveFocusChanged: {
if(!activeFocus){
control.inputFinished()
}
}
background: Rectangle { background: Rectangle {
implicitWidth: 200 implicitWidth: 200
implicitHeight: 40 implicitHeight: 40

View file

@ -1,5 +1,71 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 2.4
Item { SmoothItemDelegate {
id: control
property double sliderValue: 0.5
signal sliderFinished()
onSliderValueChanged: {
slider.value = control.sliderValue
}
rightPadding: slider.width + width * 0.02
Slider {
id: slider
anchors {
right: parent.right
rightMargin: parent.width * 0.01
verticalCenter: parent.verticalCenter
}
height: control.height * 0.4
width: parent.width * 0.6
onValueChanged: {
control.sliderValue = value
}
onPressedChanged: {
if(!pressed){
control.sliderFinished()
}
}
background: Rectangle {
x: slider.leftPadding
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 4
width: slider.availableWidth
height: slider.height * 0.2
radius: height * 0.5
color: "#bdbebf"
Rectangle {
width: slider.visualPosition * parent.width
height: parent.height
color: "#21be2b"
radius: height * 0.5
}
}
handle: Rectangle {
x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width)
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: 26
implicitHeight: 26
width: slider.height
height: width
radius: height * 0.5
color: slider.pressed ? "#f0f0f0" : "#f6f6f6"
border.color: "#bdbebf"
}
}
} }

View file

@ -212,6 +212,7 @@ Window {
scale: 0 scale: 0
height: !root.landscape()? parent.height*0.17:parent.width*0.17 height: !root.landscape()? parent.height*0.17:parent.width*0.17
width: status === "disconnected" ? 0:height
Component.onCompleted: { Component.onCompleted: {
scale = 1 scale = 1
@ -222,6 +223,12 @@ Window {
duration: 200 duration: 200
} }
} }
Behavior on width {
NumberAnimation {
duration: 200
}
}
} }
} }
} }

View file

@ -13,5 +13,6 @@
<file>components/SmoothItemDelegate.qml</file> <file>components/SmoothItemDelegate.qml</file>
<file>components/SmoothSwitchDelegate.qml</file> <file>components/SmoothSwitchDelegate.qml</file>
<file>components/InputDelegate.qml</file> <file>components/InputDelegate.qml</file>
<file>components/SmoothSliderDelegate.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -42,7 +42,6 @@ bool BaseConn::connectToHost() {
if(timer.remainingTime() == -1){ if(timer.remainingTime() == -1){
//the time has been triggered -> timeout //the time has been triggered -> timeout
this->socket->abort(); this->socket->abort();
setState("disconnected");
return(false); return(false);
} }
@ -50,7 +49,9 @@ bool BaseConn::connectToHost() {
timer.stop(); timer.stop();
connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead); connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead);
this->connection_progress = 100; this->connection_progress = 100;
setState("connected");
this->setState("connected");
return(true); return(true);
} }
@ -113,6 +114,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
// generate id and witing requests entry // generate id and witing requests entry
int thisId = nextConnectionId; int thisId = nextConnectionId;
//qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId;
nextConnectionId ++; nextConnectionId ++;
QEventLoop loop; QEventLoop loop;
@ -163,7 +165,6 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){
timer.deleteLater(); timer.deleteLater();
//remoteSessions.release(1);
return {{"status", reply.value("header").toInt()}, {"data", reply.value("data").toVariant()}}; return {{"status", reply.value("header").toInt()}, {"data", reply.value("data").toVariant()}};
} }
@ -227,7 +228,7 @@ void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) {
} }
case QAbstractSocket::ConnectedState: case QAbstractSocket::ConnectedState:
{ {
this->setState("connected"); //this->setState("connected");
break; break;
} }
default: default:

View file

@ -470,28 +470,30 @@ double ClimbingRace::getNextStartActionDelayProgress() {
void ClimbingRace::writeSetting(QString key, QVariant value) { void ClimbingRace::writeSetting(QString key, QVariant value) {
this->refreshMode(); this->refreshMode();
if(this->mode == REMOTE && this->remoteSettings.contains(key)){ if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) ) ){
this->baseConn->writeRemoteSetting(key, value.toString()); this->baseConn->writeRemoteSetting(key, value.toString());
} }
else { else if(!this->remoteOnlySettings.contains(key)){
this->appSettings->writeSetting(key, value); this->appSettings->writeSetting(key, value);
} }
} }
QString ClimbingRace::readSetting(QString key) { QString ClimbingRace::readSetting(QString key) {
this->refreshMode(); this->refreshMode();
if(this->mode == REMOTE && this->remoteSettings.contains(key)){ if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) )){
QVariantMap reply = this->baseConn->sendCommand(3001, key); QVariantMap reply = this->baseConn->sendCommand(3001, key);
if(reply["status"] != 200){ if(reply["status"] != 200){
return "false"; return "false";
} }
return reply["data"].toString(); return reply["data"].toString();
} }
else { else if(!this->remoteOnlySettings.contains(key)){
return this->appSettings->loadSetting(key); return this->appSettings->loadSetting(key);
} }
else {
return "false";
}
} }
bool ClimbingRace::connectBaseStation() { bool ClimbingRace::connectBaseStation() {

View file

@ -27,7 +27,6 @@ bool SpeedTimer::start(bool force) {
this->setState(RUNNING); this->setState(RUNNING);
return true; return true;
//this->startPad->appendCommand("SET_LED_RUNNING");
} }
bool SpeedTimer::stop(int type, bool force) { bool SpeedTimer::stop(int type, bool force) {
@ -128,7 +127,7 @@ QString SpeedTimer::getText() {
QString newText; QString newText;
switch (this->state) { switch (this->state) {
case SpeedTimer::IDLE: case SpeedTimer::IDLE:
newText = "Click Start to start"; newText = tr("Click Start to start");
break; break;
case SpeedTimer::STARTING: case SpeedTimer::STARTING:
newText = "0.000 sec"; newText = "0.000 sec";
@ -140,10 +139,10 @@ QString SpeedTimer::getText() {
newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec"; newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec";
break; break;
case SpeedTimer::FAILED: case SpeedTimer::FAILED:
newText = "False Start"; newText = tr("False Start");
break; break;
case SpeedTimer::CANCELLED: case SpeedTimer::CANCELLED:
newText = "Cancelled"; newText = tr("Cancelled");
break; break;
} }