Ref T784, joystick (PTT) buttons

* style
* more detailed logs
This commit is contained in:
Klaus Basan
2020-05-17 22:44:58 +02:00
committed by Mat Sutcliffe
parent 3099464668
commit 8d51c42cfc
3 changed files with 26 additions and 19 deletions

View File

@@ -14,6 +14,7 @@
#include "blackcore/context/contextaudio.h" #include "blackcore/context/contextaudio.h"
#include "blackcore/inputmanager.h" #include "blackcore/inputmanager.h"
#include "blackmisc/input/actionhotkeydefs.h" #include "blackmisc/input/actionhotkeydefs.h"
#include "blackmisc/metadatautils.h"
#include "ui_settingshotkeycomponent.h" #include "ui_settingshotkeycomponent.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
@@ -81,6 +82,9 @@ namespace BlackGui
m_model.insertRows(position, 1, QModelIndex()); m_model.insertRows(position, 1, QModelIndex());
const QModelIndex index = m_model.index(position, 0, QModelIndex()); const QModelIndex index = m_model.index(position, 0, QModelIndex());
m_model.setData(index, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole); m_model.setData(index, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole);
// T784, further info about the "key"/button
CLogMessage(this).debug(u"%1, added key: '%2'") << classNameShort(this) << selectedActionHotkey.toQString(true);
} }
this->resizeView(); this->resizeView();
} }
@@ -88,18 +92,20 @@ namespace BlackGui
void CSettingsHotkeyComponent::editEntry() void CSettingsHotkeyComponent::editEntry()
{ {
const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex(); const auto index = ui->tv_Hotkeys->selectionModel()->currentIndex();
if (!index.isValid()) return; if (!index.isValid()) { return; }
const auto model = ui->tv_Hotkeys->model(); const auto model = ui->tv_Hotkeys->model();
const QModelIndex indexHotkey = model->index(index.row(), 0, QModelIndex()); const QModelIndex indexHotkey = model->index(index.row(), 0, QModelIndex());
Q_ASSERT_X(indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).canConvert<CActionHotkey>(), Q_FUNC_INFO, "No action hotkey"); Q_ASSERT_X(indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).canConvert<CActionHotkey>(), Q_FUNC_INFO, "No action hotkey");
CActionHotkey actionHotkey = indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).value<CActionHotkey>(); const CActionHotkey actionHotkey = indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).value<CActionHotkey>();
const CActionHotkey selectedActionHotkey = CHotkeyDialog::getActionHotkey(actionHotkey, getAllIdentifiers(), this); const CActionHotkey selectedActionHotkey = CHotkeyDialog::getActionHotkey(actionHotkey, getAllIdentifiers(), this);
if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey, { actionHotkey })) if (selectedActionHotkey.isValid() && checkAndConfirmConflicts(selectedActionHotkey, { actionHotkey }))
{ {
updateHotkeyInSettings(actionHotkey, selectedActionHotkey); updateHotkeyInSettings(actionHotkey, selectedActionHotkey);
m_model.setData(indexHotkey, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole); m_model.setData(indexHotkey, QVariant::fromValue(selectedActionHotkey), CActionHotkeyListModel::ActionHotkeyRole);
// T784, further info about the "key"/button
CLogMessage(this).debug(u"%1, edited key: '%2'") << classNameShort(this) << selectedActionHotkey.toQString(true);
} }
this->resizeView(); this->resizeView();
} }
@@ -109,7 +115,7 @@ namespace BlackGui
const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows(); const QModelIndexList indexes = ui->tv_Hotkeys->selectionModel()->selectedRows();
for (const auto &index : indexes) for (const auto &index : indexes)
{ {
CActionHotkey actionHotkey = index.data(CActionHotkeyListModel::ActionHotkeyRole).value<CActionHotkey>(); const CActionHotkey actionHotkey = index.data(CActionHotkeyListModel::ActionHotkeyRole).value<CActionHotkey>();
removeHotkeyFromSettings(actionHotkey); removeHotkeyFromSettings(actionHotkey);
m_model.removeRows(index.row(), 1, QModelIndex()); m_model.removeRows(index.row(), 1, QModelIndex());
} }

View File

@@ -8,6 +8,8 @@
#include "joystickwindows.h" #include "joystickwindows.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/metadatautils.h"
#include "comdef.h" #include "comdef.h"
#include "Dbt.h" #include "Dbt.h"
@@ -25,11 +27,11 @@ namespace BlackInput
QObject(parent), QObject(parent),
m_guidDevice(pdidInstance->guidInstance), m_guidDevice(pdidInstance->guidInstance),
m_guidProduct(pdidInstance->guidProduct), m_guidProduct(pdidInstance->guidProduct),
m_deviceName(QString::fromWCharArray(pdidInstance->tszInstanceName)), m_deviceName(QString::fromWCharArray(pdidInstance->tszInstanceName).simplified()),
m_productName(QString::fromWCharArray(pdidInstance->tszProductName)), m_productName(QString::fromWCharArray(pdidInstance->tszProductName).simplified()),
m_directInput(directInputPtr) m_directInput(directInputPtr)
{ {
this->setObjectName("CJoystickDevice"); this->setObjectName(classNameShort(this));
} }
bool CJoystickDevice::init(HWND helperWindow) bool CJoystickDevice::init(HWND helperWindow)
@@ -98,7 +100,7 @@ namespace BlackInput
void CJoystickDevice::timerEvent(QTimerEvent *event) void CJoystickDevice::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event)
pollDeviceState(); pollDeviceState();
} }
@@ -126,11 +128,8 @@ namespace BlackInput
for (const CJoystickDeviceInput &input : as_const(m_joystickDeviceInputs)) for (const CJoystickDeviceInput &input : as_const(m_joystickDeviceInputs))
{ {
const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0; const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0;
bool isPressed = state.rgbButtons[buttonIndex] & 0x80; const bool isPressed = state.rgbButtons[buttonIndex] & 0x80;
emit this->buttonChanged(input.m_button, isPressed);
if (isPressed) { emit buttonChanged(input.m_button, true); }
else { emit buttonChanged(input.m_button, false); }
} }
return hr; return hr;
} }
@@ -151,12 +150,12 @@ namespace BlackInput
if (dev->guidType != GUID_Button) return DIENUM_CONTINUE; if (dev->guidType != GUID_Button) return DIENUM_CONTINUE;
CJoystickDeviceInput deviceInput; CJoystickDeviceInput deviceInput;
int number = joystickDevice->m_joystickDeviceInputs.size(); const int number = joystickDevice->m_joystickDeviceInputs.size();
deviceInput.m_offset = DIJOFS_BUTTON(number); deviceInput.m_offset = DIJOFS_BUTTON(number);
deviceInput.m_button = CJoystickButton(joystickDevice->m_deviceName, DIJOFS_BUTTON(number) - DIJOFS_BUTTON0); deviceInput.m_button = CJoystickButton(joystickDevice->m_deviceName, DIJOFS_BUTTON(number) - DIJOFS_BUTTON0);
joystickDevice->m_joystickDeviceInputs.append(deviceInput); joystickDevice->m_joystickDeviceInputs.append(deviceInput);
CLogMessage(static_cast<CJoystickWindows *>(nullptr)).debug() << "Found joystick button" << QString::fromWCharArray(dev->tszName); CLogMessage(static_cast<CJoystickWindows *>(nullptr)).debug() << "Found joystick button" << QString::fromWCharArray(dev->tszName) << joystickDevice->m_deviceName;
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -273,7 +272,7 @@ namespace BlackInput
ZeroMemory(&wce, sizeof(wce)); ZeroMemory(&wce, sizeof(wce));
wce.cbSize = sizeof(wce); wce.cbSize = sizeof(wce);
wce.lpfnWndProc = windowProc; wce.lpfnWndProc = windowProc;
wce.lpszClassName = (LPCWSTR) helperWindowClassName; wce.lpszClassName = static_cast<LPCWSTR>(helperWindowClassName);
wce.hInstance = hInstance; wce.hInstance = hInstance;
/* Register the class. */ /* Register the class. */
@@ -376,6 +375,7 @@ namespace BlackInput
} }
} }
//
// Window callback function (handles window messages) // Window callback function (handles window messages)
// //
LRESULT CALLBACK CJoystickWindows::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK CJoystickWindows::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -390,8 +390,8 @@ namespace BlackInput
{ {
if (wParam == DBT_DEVICEARRIVAL) if (wParam == DBT_DEVICEARRIVAL)
{ {
// DEV_BROADCAST_HDR *dbh = reinterpret_cast<DEV_BROADCAST_HDR *>(lParam); ??? DEV_BROADCAST_HDR *dbh = reinterpret_cast<DEV_BROADCAST_HDR *>(lParam);
DEV_BROADCAST_HDR *dbh = (DEV_BROADCAST_HDR *) lParam; // DEV_BROADCAST_HDR *dbh = (DEV_BROADCAST_HDR *) lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{ {
joystickWindows->enumJoystickDevices(); joystickWindows->enumJoystickDevices();

View File

@@ -26,7 +26,8 @@ namespace BlackMisc
const QString s = const QString s =
m_identifier.getMachineName() % m_identifier.getMachineName() %
u' ' % u' ' %
m_combination.toQString() % m_combination.asStringWithDeviceNames() %
// m_combination.toQString() %
u' ' % u' ' %
m_action; m_action;
return s; return s;