From c2dce0c722ab8aa855d4d53d23288680102201ad Mon Sep 17 00:00:00 2001 From: Pierre Ferran Date: Thu, 9 May 2024 01:03:09 -0400 Subject: [PATCH] Tweaks to input handler --- .github/workflows/release.yml | 2 +- backend/include/Shared.hpp | 2 +- backend/src/InputHandler.cpp | 51 ++++++++++++++++++++--------------- package-lock.json | 2 +- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a38484..33dc1fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -147,7 +147,7 @@ jobs: - name: Upload artifacts uses: softprops/action-gh-release@v2 - if: matrix.os == 'windows-2019' + if: matrix.os == 'windows-2019' && always() with: tag_name: ${{ steps.relinfo.outputs.release }} files: "out/make/**/*.exe" diff --git a/backend/include/Shared.hpp b/backend/include/Shared.hpp index f8cba48..42b7b3c 100644 --- a/backend/include/Shared.hpp +++ b/backend/include/Shared.hpp @@ -63,7 +63,7 @@ struct RemoteDataStatus { struct UserSettings { public: - inline static int PttKey = 0; + inline static int PttKey = -1; inline static int JoystickId = 0; inline static bool isJoystickButton = false; // NOLINTNEXTLINE diff --git a/backend/src/InputHandler.cpp b/backend/src/InputHandler.cpp index 61971e2..0aab8c5 100644 --- a/backend/src/InputHandler.cpp +++ b/backend/src/InputHandler.cpp @@ -1,6 +1,7 @@ #include "InputHandler.hpp" #include "Helpers.hpp" #include "Shared.hpp" +#include #include #include @@ -44,8 +45,8 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/) if (isPttSetupRunning) { // Check for Key presses - for (int i = 0; i < sf::Keyboard::Scan::ScancodeCount; i++) { - if (sf::Keyboard::isKeyPressed(static_cast(i))) { + for (int i = sf::Keyboard::Scancode::A; i < sf::Keyboard::Scancode::ScancodeCount; i++) { + if (sf::Keyboard::isKeyPressed(static_cast(i))) { TRACK_LOG_INFO("Ptt Key set: {}", i); updatePttKey(i, false); @@ -56,15 +57,17 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/) // Check for Joystick presses for (int i = 0; i < sf::Joystick::Count; i++) { - if (sf::Joystick::isConnected(i)) { - for (int j = 0; j < sf::Joystick::getButtonCount(i); j++) { - if (sf::Joystick::isButtonPressed(i, j)) { - TRACK_LOG_INFO("Joystick Ptt Key set: {} on Joystick {}", j, i); - updatePttKey(j, true, i); - - isPttSetupRunning = false; - return; - } + if (!sf::Joystick::isConnected(i)) { + continue; + } + + for (int j = 0; j < sf::Joystick::getButtonCount(i); j++) { + if (sf::Joystick::isButtonPressed(i, j)) { + TRACK_LOG_INFO("Joystick Ptt Key set: {} on Joystick {}", j, i); + updatePttKey(j, true, i); + + isPttSetupRunning = false; + return; } } } @@ -72,28 +75,31 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/) return; } - if (UserSettings::PttKey == 0) { + if (UserSettings::PttKey == -1) { return; } if (UserSettings::isJoystickButton) { - if (sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey) - && !isPttOpen) { + if (!sf::Joystick::isConnected(UserSettings::JoystickId)) { + return; + } + + auto isButtonPressed + = sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey); + if (isButtonPressed && !isPttOpen) { mClient->SetPtt(true); isPttOpen = true; - } else if (!sf::Joystick::isButtonPressed(UserSettings::JoystickId, UserSettings::PttKey) - && isPttOpen) { + } else if (!isButtonPressed && isPttOpen) { mClient->SetPtt(false); isPttOpen = false; } } else { - if (sf::Keyboard::isKeyPressed(static_cast(UserSettings::PttKey)) - && !isPttOpen) { + auto isKeyPressed + = sf::Keyboard::isKeyPressed(static_cast(UserSettings::PttKey)); + if (isKeyPressed && !isPttOpen) { mClient->SetPtt(true); isPttOpen = true; - } else if (!sf::Keyboard::isKeyPressed( - static_cast(UserSettings::PttKey)) - && isPttOpen) { + } else if (!isKeyPressed && isPttOpen) { mClient->SetPtt(false); isPttOpen = false; } @@ -115,7 +121,8 @@ std::string InputHandler::getPttKeyName() } if (UserSettings::isJoystickButton) { - return "Joystick " + std::to_string(UserSettings::PttKey); + return sf::Joystick::getIdentification(UserSettings::JoystickId).name + " " + + std::to_string(UserSettings::PttKey); } return sf::Keyboard::getDescription( diff --git a/package-lock.json b/package-lock.json index 71b6e6a..959acb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16137,7 +16137,7 @@ "node_modules/trackaudio-afv": { "version": "1.0.0", "resolved": "file:backend/trackaudio-afv-1.0.0.tgz", - "integrity": "sha512-dxkjMKjWQUJzK0ZO3t0GbNu6oLCmuJF+z8bj6+1wqVF/jZN/LlaZhTJ8lVXvsOJ5ZzfOAxaCtfUgw1LohIopjw==", + "integrity": "sha512-wZpnZZ31t+sW62/qJwnifyMEHoPznRwMUn+S0Y6DR7K7wE3Wg1FrpDVo9f2FSAhQAaRq4G6Pyz4uNfwqLqhrhQ==", "dependencies": { "bindings": "^1.5.0", "node-addon-api": "^1.1.0"