Skip to content

Commit

Permalink
Vastly improved logging
Browse files Browse the repository at this point in the history
Better debugging. More power to the developers. :D
Will log to a file sometime in the future.
  • Loading branch information
kitswas committed Apr 24, 2024
1 parent e0bc834 commit cee2d13
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

int main(int argc, char *argv[])
{
qSetMessagePattern(
"[%{time h:mm:ss.zzz} %{if-category}%{category}: %{endif}%{type}] %{message}");

qInfo() << "App launched.";

QApplication a(argc, argv);
QApplication::setStyle(QStyleFactory::create("Fusion"));
QApplication::setOrganizationName("Kitswas");
QApplication::setOrganizationDomain("io.github.kitswas");
QApplication::setApplicationName("VirtualGamePad");

MainWindow w;
w.show();
return a.exec();
Expand Down
12 changes: 11 additions & 1 deletion src/networking/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t l
size_t decoded_octects = vgp_data_exchange_gamepad_reading_unmarshal(&reading, data, len);
if (decoded_octects == 0)
{
qDebug() << "Failed to deserialize data";
qWarning() << "Failed to deserialize data";
return reading;
}

// Log the gamepad state
qDebug() << "Gamepad state:"
<< "\nButtons up: " << reading.buttons_up << "\nButtons down: " << reading.buttons_down
<< "\nLeft trigger: " << reading.left_trigger
<< "\nRight trigger: " << reading.right_trigger
<< "\nLeft thumbstick x: " << reading.left_thumbstick_x
<< "\nLeft thumbstick y: " << reading.left_thumbstick_y
<< "\nRight thumbstick x: " << reading.right_thumbstick_x
<< "\nRight thumbstick y: " << reading.right_thumbstick_y;

return reading;
}

Expand Down
18 changes: 5 additions & 13 deletions src/networking/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Server::~Server()
isGamepadConnected = false;
}
tcpServer->close(); // And then close the server
qInfo() << "Server stopped.";
tcpServer->deleteLater();
delete ui;
}
Expand Down Expand Up @@ -114,6 +115,7 @@ void Server::initServer()
}
});
connect(tcpServer, &QTcpServer::newConnection, this, &Server::handleConnection);
qInfo() << "Server started.";
}

void Server::handleConnection()
Expand All @@ -127,13 +129,14 @@ void Server::handleConnection()
: clientConnection->peerName(),
clientConnection->peerAddress().toString(),
QString::number(clientConnection->peerPort()));
qDebug() << connectionMessage;
qInfo().noquote() << connectionMessage;
ui->clientLabel->setText(connectionMessage);
tcpServer->pauseAccepting();
connect(clientConnection, &QAbstractSocket::disconnected, clientConnection,
&QObject::deleteLater);
connect(clientConnection, &QAbstractSocket::disconnected, this, [this]() {
ui->clientLabel->setText(tr("No device connected"));
qInfo() << "Device disconnected.";
isGamepadConnected = false;
tcpServer->resumeAccepting();
});
Expand All @@ -142,23 +145,12 @@ void Server::handleConnection()

void Server::serveClient()
{
qDebug() << "Received: " << clientConnection->bytesAvailable() << "bytes";
qInfo() << "Received: " << clientConnection->bytesAvailable() << "bytes";
QByteArray request = clientConnection->readAll();
qDebug() << "Request: " << request;
// vgp_data_exchange_message message;
// vgp_data_exchange_message_unmarshal(&message, request.constData(), request.size());
// qDebug() << "Message: " << message.contents.utf8;

vgp_data_exchange_gamepad_reading gamepad_reading =
parse_gamepad_state(request.constData(), request.size());
qDebug() << "Reading (Btn down): " << gamepad_reading.buttons_down;
qDebug() << "Reading (Btn up): " << gamepad_reading.buttons_up;
qDebug() << "Reading (Left trigger): " << gamepad_reading.left_trigger;
qDebug() << "Reading (Right trigger): " << gamepad_reading.right_trigger;
qDebug() << "Reading (Left thumbstick X): " << gamepad_reading.left_thumbstick_x;
qDebug() << "Reading (Left thumbstick Y): " << gamepad_reading.left_thumbstick_y;
qDebug() << "Reading (Right thumbstick X): " << gamepad_reading.right_thumbstick_x;
qDebug() << "Reading (Right thumbstick Y): " << gamepad_reading.right_thumbstick_y;
inject_gamepad_state(gamepad_reading);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event)
valid = true;
break;
default:
qDebug() << "[!] Error Occurred. No Legal Mouse Button Found";
qWarning() << "No legal mouse button found.";
}
if (valid)
ptr->setText(QString(buffer));
Expand Down

0 comments on commit cee2d13

Please sign in to comment.