added symbol to indicate buzzer connectivity
added timer to refresh connectivity
This commit is contained in:
parent
66c322c1d4
commit
1e56e372e7
7 changed files with 77 additions and 23 deletions
|
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- added profiles dialog
|
- added profiles dialog
|
||||||
|
- buzzer icon in the upper left corner indicating that the buzzer is connected
|
||||||
### Fixed
|
### Fixed
|
||||||
- start seqnece continues in a buggy way when cancel is being pressed while 'at your marks' or 'ready'
|
- start seqnece continues in a buggy way when cancel is being pressed while 'at your marks' or 'ready'
|
||||||
- bug that made the start sequence freeze if a delay of zero or lower or a non valid number was set as delay
|
- bug that made the start sequence freeze if a delay of zero or lower or a non valid number was set as delay
|
||||||
|
|
Binary file not shown.
BIN
graphics/icons/buzzer_black.png
Normal file
BIN
graphics/icons/buzzer_black.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
|
@ -30,19 +30,29 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *networkManager;
|
QNetworkAccessManager *networkManager;
|
||||||
|
QNetworkAccessManager *reloadNetworkManager;
|
||||||
QDateTime *date;
|
QDateTime *date;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ReturnData_t senddata(QUrl serviceUrl, int timeout);
|
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
|
||||||
|
//function to communicate with the buzzer
|
||||||
Q_INVOKABLE QList<double> gettimes(int timeout);
|
Q_INVOKABLE QList<double> gettimes(int timeout);
|
||||||
|
//function to get the times from the buzzer as a list with the normal network manager
|
||||||
Q_INVOKABLE bool connect();
|
Q_INVOKABLE bool connect();
|
||||||
Q_INVOKABLE bool calcoffset();
|
//function to connect to buzzer
|
||||||
|
Q_INVOKABLE bool calcoffset(QList<double> times);
|
||||||
|
//function that calculates the average time offset between the buzzer and the device
|
||||||
Q_INVOKABLE bool buzzer_triggered();
|
Q_INVOKABLE bool buzzer_triggered();
|
||||||
|
//function that checks ih the buzzer has been pushed since the last call of this function
|
||||||
Q_INVOKABLE bool start();
|
Q_INVOKABLE bool start();
|
||||||
|
//syncs the buzzer and the base to make a start possible
|
||||||
Q_INVOKABLE double get(QString key);
|
Q_INVOKABLE double get(QString key);
|
||||||
|
//can return some things (offset, lastpressed, currtime, connection_progress, connected)
|
||||||
Q_INVOKABLE QString test();
|
Q_INVOKABLE QString test();
|
||||||
|
Q_INVOKABLE bool refresh();
|
||||||
|
//refreshed the connection to the buzzer
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUZZERCONN_H
|
#endif // BUZZERCONN_H
|
||||||
|
|
34
qml/main.qml
34
qml/main.qml
|
@ -43,11 +43,13 @@ Window {
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
//timer that refreshes the connection state to the buzzer
|
//timer that refreshes the connection state to the buzzer
|
||||||
running: false
|
id: connectionRefreshTimer
|
||||||
repeat: true
|
running: root.state !== "RUNNING" && root.state !== "STARTING"
|
||||||
interval: 500
|
repeat: false
|
||||||
|
interval: 1000
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.log(_cppBuzzerConn.calcoffset())
|
_cppBuzzerConn.refresh()
|
||||||
|
connectionRefreshTimer.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +151,7 @@ Window {
|
||||||
onPlayingChanged: {
|
onPlayingChanged: {
|
||||||
if(!playing && root.state==="STARTING"){
|
if(!playing && root.state==="STARTING"){
|
||||||
root.startTime = _cppBuzzerConn.get("currtime")
|
root.startTime = _cppBuzzerConn.get("currtime")
|
||||||
_cppBuzzerConn.start()
|
|
||||||
root.currTime = _cppBuzzerConn.get("currtime")
|
root.currTime = _cppBuzzerConn.get("currtime")
|
||||||
time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec"
|
time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec"
|
||||||
root.state = "RUNNING"
|
root.state = "RUNNING"
|
||||||
|
@ -181,17 +183,31 @@ Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Image {
|
||||||
|
id: buzzerLogo
|
||||||
|
source: "qrc:/graphics/icons/buzzer_black.png"
|
||||||
|
mipmap: true
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
topMargin: 10
|
topMargin: 10
|
||||||
left: parent.left
|
left: parent.left
|
||||||
leftMargin: 10
|
leftMargin: 10
|
||||||
}
|
}
|
||||||
|
visible: _cppBuzzerConn.get("connected")===1
|
||||||
|
height: root.landscape()? root.height*0.1:root.width*0.1
|
||||||
width: height
|
width: height
|
||||||
radius: height*0.5
|
Component.onCompleted: {
|
||||||
color: "#6efc0f"
|
visible= _cppBuzzerConn.get("connected")===1
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 100
|
||||||
|
running: true
|
||||||
|
repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
buzzerLogo.visible= _cppBuzzerConn.get("connected")===1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
|
@ -13,5 +13,6 @@
|
||||||
<file>sounds/at_marks_1.wav</file>
|
<file>sounds/at_marks_1.wav</file>
|
||||||
<file>sounds/ready_2.wav</file>
|
<file>sounds/ready_2.wav</file>
|
||||||
<file>sounds/at_marks_2.wav</file>
|
<file>sounds/at_marks_2.wav</file>
|
||||||
|
<file>graphics/icons/buzzer_black.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
BuzzerConn::BuzzerConn(QObject *parent) : QObject(parent)
|
BuzzerConn::BuzzerConn(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->networkManager = new QNetworkAccessManager();
|
this->networkManager = new QNetworkAccessManager();
|
||||||
|
this->reloadNetworkManager = new QNetworkAccessManager();
|
||||||
|
|
||||||
this->date = new QDateTime;
|
this->date = new QDateTime;
|
||||||
this->latest_button_pressed = 0;
|
this->latest_button_pressed = 0;
|
||||||
|
@ -15,30 +16,31 @@ bool BuzzerConn::connect()
|
||||||
QList<double> times = gettimes(1000);
|
QList<double> times = gettimes(1000);
|
||||||
qDebug() << times[0];
|
qDebug() << times[0];
|
||||||
if(times[0] == 200.0){
|
if(times[0] == 200.0){
|
||||||
this->connected = true;
|
|
||||||
this->latest_button_pressed = times[2];
|
this->latest_button_pressed = times[2];
|
||||||
for(int i=0;i<=100;i++){
|
for(int i=0;i<=100;i++){
|
||||||
this->connection_progress = i;
|
this->connection_progress = i;
|
||||||
if(!calcoffset()){
|
if(!calcoffset(this->gettimes(1000))){
|
||||||
this->connection_progress = 100;
|
this->connection_progress = 100;
|
||||||
|
this->connected = false;
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->connected = true;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
this->connected = false;
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuzzerConn::calcoffset()
|
bool BuzzerConn::calcoffset(QList<double> times)
|
||||||
{
|
{
|
||||||
QList<double> times = gettimes(1000);
|
|
||||||
if(times.length() != 3){
|
if(times.length() != 3){
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
if(times[0] == 200.0 && this->connected){
|
if(times[0] == 200.0){
|
||||||
|
this->latest_button_pressed = times[2];
|
||||||
double offset = date->currentMSecsSinceEpoch() - times[1];
|
double offset = date->currentMSecsSinceEpoch() - times[1];
|
||||||
if(this->latest_offsets.length()>=100){
|
if(this->latest_offsets.length()>=100){
|
||||||
this->latest_offsets.removeFirst();
|
this->latest_offsets.removeFirst();
|
||||||
|
@ -54,7 +56,7 @@ bool BuzzerConn::calcoffset()
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->connected = false;
|
//this->connected = false;
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@ bool BuzzerConn::calcoffset()
|
||||||
QList<double> BuzzerConn::gettimes(int timeout)
|
QList<double> BuzzerConn::gettimes(int timeout)
|
||||||
{
|
{
|
||||||
QList<double> times;
|
QList<double> times;
|
||||||
ReturnData_t ret = senddata(QUrl("http://192.168.4.1"), timeout);
|
ReturnData_t ret = senddata(this->networkManager, QUrl("http://192.168.4.1"), timeout);
|
||||||
times.append(double(ret.status_code));
|
times.append(double(ret.status_code));
|
||||||
|
|
||||||
if(ret.status_code == 200){
|
if(ret.status_code == 200){
|
||||||
|
@ -142,11 +144,35 @@ double BuzzerConn::get(QString key)
|
||||||
|
|
||||||
QString BuzzerConn::test()
|
QString BuzzerConn::test()
|
||||||
{
|
{
|
||||||
ReturnData_t ret = this->senddata(QUrl("http://www.google.de"), 500);
|
ReturnData_t ret = this->senddata(this->networkManager, QUrl("http://www.google.de"), 500);
|
||||||
return(ret.text);
|
return(ret.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnData_t BuzzerConn::senddata(QUrl serviceUrl, int timeout)
|
bool BuzzerConn::refresh()
|
||||||
|
{
|
||||||
|
if(!this->connected){
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
QList<double> times;
|
||||||
|
ReturnData_t ret = senddata(this->reloadNetworkManager, QUrl("http://192.168.4.1"), 1000);
|
||||||
|
times.append(double(ret.status_code));
|
||||||
|
|
||||||
|
if(ret.status_code == 200){
|
||||||
|
ret.text.replace("\n","");
|
||||||
|
ret.text.replace("\r","");
|
||||||
|
QStringList times_cache = ret.text.split("<br>");
|
||||||
|
times.append(times_cache[0].toDouble());
|
||||||
|
times.append(times_cache[1].toDouble());
|
||||||
|
calcoffset(times);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this->connected = false;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnData_t BuzzerConn::senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
ReturnData_t ret; //this is a custom type to store the returned data
|
ReturnData_t ret; //this is a custom type to store the returned data
|
||||||
|
@ -166,10 +192,10 @@ ReturnData_t BuzzerConn::senddata(QUrl serviceUrl, int timeout)
|
||||||
|
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
|
||||||
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
loop.connect(NetMan, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
|
||||||
|
|
||||||
timer.start(timeout);
|
timer.start(timeout);
|
||||||
reply = this->networkManager->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
reply = NetMan->post(request, pdata.toString(QUrl::FullyEncoded).toUtf8());
|
||||||
loop.exec();
|
loop.exec();
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
|
|
Reference in a new issue