changed the integration of the c++ classes into the qml code to make things cleaner,
everything seems to be working again added false start sound
This commit is contained in:
parent
cd3e485bf2
commit
24f9dcbc6f
9 changed files with 157 additions and 235 deletions
|
@ -19,6 +19,12 @@ typedef struct strReturnData{
|
|||
class BuzzerConn : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double lastTriggered READ getLastTriggered NOTIFY triggered)
|
||||
Q_PROPERTY(QString ipAdress WRITE setIP READ getIP)
|
||||
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
|
||||
Q_PROPERTY(int progress READ getProgress NOTIFY progressChanged)
|
||||
Q_PROPERTY(double offset READ getOffset NOTIFY offsetChanged)
|
||||
|
||||
public:
|
||||
explicit BuzzerConn(QObject *parent = nullptr, QString ip = "http://192.168.4.1", int port = 80);
|
||||
double offset;
|
||||
|
@ -31,6 +37,7 @@ public:
|
|||
int port;
|
||||
int errors;
|
||||
int errors_until_disconnect = 4;
|
||||
QString state;
|
||||
|
||||
|
||||
|
||||
|
@ -42,6 +49,13 @@ private:
|
|||
QStringList pending_commands;
|
||||
//QSemaphore dataPipe(1);
|
||||
signals:
|
||||
void triggered();
|
||||
|
||||
void stateChanged();
|
||||
|
||||
void progressChanged();
|
||||
|
||||
void offsetChanged();
|
||||
|
||||
public slots:
|
||||
ReturnData_t senddata(QNetworkAccessManager * NetMan, QUrl serviceUrl, int timeout);
|
||||
|
@ -73,6 +87,17 @@ public slots:
|
|||
//refreshed the connection to the buzzer
|
||||
Q_INVOKABLE void appendCommand(QString command);
|
||||
|
||||
void setIP(const QString &ipAdress);
|
||||
QString getIP() const;
|
||||
|
||||
QString getState() const;
|
||||
void setState(QString newState);
|
||||
|
||||
int getProgress() const;
|
||||
|
||||
double getOffset() const;
|
||||
|
||||
double getLastTriggered() const;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
id: buzzerConn
|
||||
height: 0
|
||||
width: 0
|
||||
opacity: 0
|
||||
visible: false
|
||||
|
||||
signal pushed()
|
||||
property bool connected: false
|
||||
property var status: {'status': buzzerConn.state, 'progress': get_progress()}
|
||||
|
||||
Timer {
|
||||
//timer that refreshes the connection state to the buzzer
|
||||
id: connectionRefreshTimer
|
||||
running: root.state !== "RUNNING" && root.state !== "STARTING" && buzzerConn.status !== "connecting"
|
||||
repeat: false
|
||||
interval: 1000
|
||||
onTriggered: {
|
||||
_cppBuzzerConn.refresh()
|
||||
if(!_cppBuzzerConn.get("connected") && buzzerConn.state !== "connecting"){
|
||||
buzzerConn.state = "disconnected"
|
||||
}
|
||||
|
||||
connectionRefreshTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
//timer that checks, if the button has been pushed
|
||||
id: running_refresh_timer
|
||||
running: root.state === "RUNNING"
|
||||
repeat: false
|
||||
interval: 1
|
||||
|
||||
onTriggered: {
|
||||
if(_cppBuzzerConn.buzzer_triggered()){
|
||||
buzzerConn.pushed()
|
||||
|
||||
}
|
||||
if(root.state === "RUNNING"){
|
||||
running_refresh_timer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: prog_refresh
|
||||
running: buzzerConn.state === "connecting"
|
||||
interval: 1
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
buzzerConn.status.progress = get_progress()
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "disconnected"
|
||||
PropertyChanges {
|
||||
target: buzzerConn
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "connecting"
|
||||
PropertyChanges {
|
||||
target: buzzerConn
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "connected"
|
||||
PropertyChanges {
|
||||
target: buzzerConn
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
function connect(){
|
||||
buzzerConn.state = "connecting"
|
||||
if(_cppBuzzerConn.connect()){
|
||||
buzzerConn.state = "connected"
|
||||
return(true)
|
||||
}
|
||||
else {
|
||||
buzzerConn.state = "disconnected"
|
||||
return(false)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function get_progress(){
|
||||
return(_cppBuzzerConn.get("connection_progress"))
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
id: startpadConn
|
||||
height: 0
|
||||
width: 0
|
||||
opacity: 0
|
||||
visible: false
|
||||
|
||||
signal pushed()
|
||||
property bool connected: false
|
||||
property var status: {'status': startpadConn.state, 'progress': get_progress()}
|
||||
property bool active
|
||||
|
||||
Timer {
|
||||
//timer that refreshes the connection state to the buzzer
|
||||
id: connectionRefreshTimer
|
||||
running: root.state !== "RUNNING" && root.state !== "STARTING" && startpadConn.status !== "connecting"
|
||||
repeat: false
|
||||
interval: 1000
|
||||
onTriggered: {
|
||||
_cppStartpadConn.refresh()
|
||||
if(!_cppStartpadConn.get("connected") && startpadConn.state !== "connecting"){
|
||||
startpadConn.state = "disconnected"
|
||||
}
|
||||
|
||||
connectionRefreshTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
//timer that checks, if the button has been pushed
|
||||
id: running_refresh_timer
|
||||
running: (root.state === "RUNNING" || root.state === "STARTING") && active
|
||||
repeat: false
|
||||
interval: 1
|
||||
|
||||
onTriggered: {
|
||||
if(_cppStartpadConn.buzzer_triggered()){
|
||||
startpadConn.pushed()
|
||||
|
||||
}
|
||||
if(root.state === "RUNNING" || root.state === "STARTING" && active){
|
||||
running_refresh_timer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: prog_refresh
|
||||
running: startpadConn.state === "connecting"
|
||||
interval: 1
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
startpadConn.status.progress = get_progress()
|
||||
}
|
||||
}
|
||||
|
||||
states: [
|
||||
State {
|
||||
name: "disconnected"
|
||||
PropertyChanges {
|
||||
target: startpadConn
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "connecting"
|
||||
PropertyChanges {
|
||||
target: startpadConn
|
||||
}
|
||||
},
|
||||
State {
|
||||
name: "connected"
|
||||
PropertyChanges {
|
||||
target: startpadConn
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
function connect(){
|
||||
startpadConn.state = "connecting"
|
||||
if(_cppStartpadConn.connect()){
|
||||
startpadConn.state = "connected"
|
||||
return(true)
|
||||
}
|
||||
else {
|
||||
startpadConn.state = "disconnected"
|
||||
return(false)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function get_progress(){
|
||||
return(_cppStartpadConn.get("connection_progress"))
|
||||
}
|
||||
}
|
84
qml/main.qml
84
qml/main.qml
|
@ -21,7 +21,6 @@ import QtQuick.Window 2.2
|
|||
import QtQuick.Controls 2.2
|
||||
import "."
|
||||
import "./components"
|
||||
import "./connections"
|
||||
import "./styles"
|
||||
//import QtQuick.Layouts 1.11
|
||||
|
||||
|
@ -47,8 +46,8 @@ Window {
|
|||
property double stoppedTime: 0
|
||||
property double currTime
|
||||
|
||||
property double buzzer_offset
|
||||
property double last_button_pressed
|
||||
property double buzzer_offset: buzzerConn.offset
|
||||
property double last_button_pressed: buzzerConn.lastTriggered
|
||||
|
||||
property var last_run : {
|
||||
'stop_type': "", 'time': 0, 'react_time': 0
|
||||
|
@ -69,6 +68,62 @@ Window {
|
|||
color: StyleSettings.backgroundColor
|
||||
}
|
||||
|
||||
BuzzerConn {
|
||||
id: buzzerConn
|
||||
ipAdress: "192.168.4.10"
|
||||
property var status: {'status': buzzerConn.state, 'progress': buzzerConn.progress}
|
||||
onLastTriggeredChanged: {
|
||||
console.log(lastTriggered)
|
||||
root.stop("buzzer")
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: buzzerRefreshTimer
|
||||
running: buzzerConn.state === "connected"
|
||||
interval: root.state === "RUNNING" ? 1:1000
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
buzzerConn.refresh()
|
||||
this.start()
|
||||
}
|
||||
}
|
||||
|
||||
StartpadConn {
|
||||
id: startpadConn
|
||||
ipAdress: "192.168.4.11"
|
||||
property var status: {'status': startpadConn.state, 'progress': startpadConn.progress}
|
||||
property string color: root.state === "RUNNING" ? "SET_LED_RUNNING":"SET_LED_STARTING"
|
||||
onColorChanged: {
|
||||
appendCommand(color)
|
||||
}
|
||||
|
||||
onLastTriggeredChanged: {
|
||||
console.log("startpad triggered")
|
||||
var offset = startpadConn.offset
|
||||
var last_pressed = startpadConn.lastTriggered
|
||||
var trigger_time = (last_pressed + offset)
|
||||
root.last_run.react_time = trigger_time - root.startTime
|
||||
if(trigger_time - root.startTime <= 0){
|
||||
root.stop("false")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: startpadRefreshTimer
|
||||
running: startpadConn.state === "connected"
|
||||
interval: root.state === "RUNNING" || root.state === "STARTING" ? 1:1000
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
startpadConn.refresh()
|
||||
this.start()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
BuzzerConn {
|
||||
id: buzzerConn
|
||||
onPushed: {
|
||||
|
@ -96,7 +151,7 @@ Window {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
Timer {
|
||||
//timer that updates the currTime variable
|
||||
running: true
|
||||
|
@ -183,20 +238,24 @@ Window {
|
|||
if(!playing && root.state==="STARTING"){
|
||||
|
||||
console.log(root.startTime)
|
||||
_cppStartpadConn.appendCommand("SET_LED_RUNNING")
|
||||
root.currTime = root.startTime
|
||||
time.text = ( ( root.currTime - root.startTime ) / 1000 ).toFixed(3) + " sec"
|
||||
root.state = "RUNNING"
|
||||
}
|
||||
else if(playing) {
|
||||
console.log("start sound started")
|
||||
root.startTime = _cppBuzzerConn.get("currtime") + 3100 //set the startime to be 0 after the starttone
|
||||
startpadConn.active = true
|
||||
root.startTime = new Date().getTime() + 3100 //set the startime to be 0 after the starttone
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SoundEffect {
|
||||
//start sound
|
||||
id: falseSound
|
||||
source: "qrc:/sounds/false.wav"
|
||||
}
|
||||
|
||||
/*------------------------
|
||||
Timer text an upper line
|
||||
------------------------*/
|
||||
|
@ -687,16 +746,16 @@ Window {
|
|||
}
|
||||
|
||||
function stop(type){
|
||||
_cppStartpadConn.appendCommand("SET_LED_STARTING");
|
||||
//_cppStartpadConn.appendCommand("SET_LED_STARTING");
|
||||
switch(type){
|
||||
case "buzzer":
|
||||
//the buzzer was pushed
|
||||
root.buzzer_offset = _cppBuzzerConn.get("offset")
|
||||
root.last_button_pressed = _cppBuzzerConn.get("lastpressed")
|
||||
root.buzzer_offset = buzzerConn.offset
|
||||
root.last_button_pressed = buzzerConn.lastTriggered
|
||||
root.stoppedTime = (root.last_button_pressed + root.buzzer_offset) - root.startTime
|
||||
root.state = "STOPPED"
|
||||
//time.text = ( root.stoppedTime / 1000 ).toFixed(3) + " sec"
|
||||
console.log("STOPPED: "+root.stoppedTime)
|
||||
console.log("STOPPED: "+root.stoppedTime + " started at: " + root.startTime + " offset: "+ root.buzzer_offset + "lastpressed: " + root.last_button_pressed)
|
||||
break
|
||||
case "manual":
|
||||
//the stop button was pressed
|
||||
|
@ -713,9 +772,10 @@ Window {
|
|||
at_marksSound.stop()
|
||||
readySound.stop()
|
||||
startSound.stop()
|
||||
falseSound.play()
|
||||
break
|
||||
}
|
||||
startpadConn.active = true
|
||||
//tartpadConn.active = true
|
||||
}
|
||||
|
||||
function reset(){
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
<file>components/SimpleIndicator.qml</file>
|
||||
<file>components/ConnectionDelegate.qml</file>
|
||||
<file>components/FadeAnimation.qml</file>
|
||||
<file>connections/BuzzerConn.qml</file>
|
||||
<file>connections/StartpadConn.qml</file>
|
||||
<file>styles/StyleSettings.qml</file>
|
||||
<file>styles/qmldir</file>
|
||||
<file>styles/Dark.js</file>
|
||||
|
|
|
@ -20,5 +20,6 @@
|
|||
<file>translations/de_DE.ts</file>
|
||||
<file>graphics/icons/settings_black.png</file>
|
||||
<file>graphics/icons/startpad_black.png</file>
|
||||
<file>sounds/false.wav</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
BIN
sounds/false.wav
Normal file
BIN
sounds/false.wav
Normal file
Binary file not shown.
|
@ -30,6 +30,8 @@ BuzzerConn::BuzzerConn(QObject *parent, QString ip, int port) : QObject(parent)
|
|||
|
||||
this->ip = ip;
|
||||
this->port = port;
|
||||
|
||||
this->setState("disconnected");
|
||||
// "http://192.168.4.1"
|
||||
}
|
||||
|
||||
|
@ -37,6 +39,8 @@ bool BuzzerConn::connect()
|
|||
{
|
||||
qDebug() << "connecting...";
|
||||
|
||||
setState("connecting");
|
||||
|
||||
//wait until the request has finished
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
|
@ -62,17 +66,21 @@ bool BuzzerConn::connect()
|
|||
this->latest_button_pressed = times[2];
|
||||
for(int i=0;i<=100;i++){
|
||||
this->connection_progress = i;
|
||||
emit this->progressChanged();
|
||||
if(!calcoffset(this->gettimes(1000))){
|
||||
this->connection_progress = 100;
|
||||
this->connected = false;
|
||||
setState("disconnected");
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
this->connected = true;
|
||||
setState("connected");
|
||||
return(true);
|
||||
}
|
||||
else{
|
||||
this->connected = false;
|
||||
setState("disconnected");
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +103,8 @@ bool BuzzerConn::calcoffset(QList<double> times)
|
|||
mem += latest_offsets[i];
|
||||
}
|
||||
this->offset = mem / double(latest_offsets.length());
|
||||
qDebug("%20f", this->offset);
|
||||
offsetChanged();
|
||||
//qDebug("%20f", this->offset);
|
||||
return(true);
|
||||
}
|
||||
else {
|
||||
|
@ -215,6 +224,41 @@ double BuzzerConn::get(QString key)
|
|||
}
|
||||
return(0);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
void BuzzerConn::setIP(const QString &ipAdress){
|
||||
this->ip = ipAdress;
|
||||
}
|
||||
|
||||
QString BuzzerConn::getIP() const
|
||||
{
|
||||
return(this->ip);
|
||||
}
|
||||
|
||||
QString BuzzerConn::getState() const
|
||||
{
|
||||
return(this->state);
|
||||
}
|
||||
|
||||
void BuzzerConn::setState(QString newState){
|
||||
this->state = newState;
|
||||
emit stateChanged();
|
||||
}
|
||||
|
||||
int BuzzerConn::getProgress() const
|
||||
{
|
||||
return(connection_progress);
|
||||
}
|
||||
|
||||
double BuzzerConn::getOffset() const
|
||||
{
|
||||
return(this->offset);
|
||||
}
|
||||
|
||||
double BuzzerConn::getLastTriggered() const
|
||||
{
|
||||
return(this->latest_button_pressed);
|
||||
}
|
||||
|
||||
QString BuzzerConn::test()
|
||||
|
@ -228,36 +272,23 @@ bool BuzzerConn::refresh()
|
|||
if(!this->connected){
|
||||
return(false);
|
||||
}
|
||||
// QList<double> times;
|
||||
// ReturnData_t ret = senddata(this->reloadNetworkManager, QUrl(this->ip), 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);
|
||||
// }
|
||||
|
||||
if(pending_commands.length() > 0){
|
||||
QString command = this->pending_commands.first();
|
||||
|
||||
signed long retval = this->sendCommand(command, 800);
|
||||
signed long retval = this->sendCommand(command, 2000);
|
||||
if(retval > 0){
|
||||
this->pending_commands.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
//refresh the times
|
||||
QList<double> ret = this->gettimes(800);
|
||||
QList<double> ret = this->gettimes(2000);
|
||||
if(ret[0] >= 0){
|
||||
if(ret[2] > this->latest_button_pressed){
|
||||
this->latest_button_pressed = ret[2];
|
||||
emit triggered();
|
||||
}
|
||||
this->errors = 0;
|
||||
return(this->calcoffset(ret));
|
||||
}
|
||||
|
@ -356,8 +387,8 @@ signed long BuzzerConn::sendCommand(QString command, int timeout){
|
|||
long data = 0;
|
||||
this->socket->read((char*)&data,4);
|
||||
|
||||
qDebug() << data;
|
||||
qDebug() << this->socket->bytesAvailable();
|
||||
//qDebug() << data;
|
||||
//qDebug() << this->socket->bytesAvailable();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -105,14 +105,18 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
connectToDatabase();
|
||||
BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, "192.168.4.10", 80);
|
||||
BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, "192.168.4.11", 80);
|
||||
//BuzzerConn * pBuzzerConn = new BuzzerConn(nullptr, "192.168.4.10", 80);
|
||||
//BuzzerConn * pStartpadConn = new BuzzerConn(nullptr, "192.168.4.11", 80);
|
||||
AppSettings * pAppSettings = new AppSettings();
|
||||
|
||||
//setup the sql storage model as a qml model
|
||||
qmlRegisterType<SqlProfileModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlProfileModel");
|
||||
qmlRegisterType<SqlStorageModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlStorageModel");
|
||||
|
||||
//setup the startpad and buzzer conn qml objects
|
||||
qmlRegisterType<BuzzerConn>("com.itsblue.speedclimbingstopwatch", 1, 0, "BuzzerConn");
|
||||
qmlRegisterType<BuzzerConn>("com.itsblue.speedclimbingstopwatch", 1, 0, "StartpadConn");
|
||||
|
||||
//setup translation engine
|
||||
//to the language of the system
|
||||
//if the system language is not found the language is set to english
|
||||
|
@ -125,16 +129,12 @@ int main(int argc, char *argv[])
|
|||
if (engine.rootObjects().isEmpty())
|
||||
return -1;
|
||||
|
||||
engine.rootContext()->setContextProperty("_cppBuzzerConn", pBuzzerConn);
|
||||
engine.rootContext()->setContextProperty("_cppStartpadConn", pStartpadConn);
|
||||
engine.rootContext()->setContextProperty("_cppAppSettings", pAppSettings);
|
||||
|
||||
int iRet = 0;
|
||||
iRet = app.exec();
|
||||
|
||||
//call the destructors of all objects
|
||||
delete pBuzzerConn;
|
||||
delete pStartpadConn;
|
||||
delete pAppSettings;
|
||||
|
||||
return iRet;
|
||||
|
|
Reference in a new issue