Skip to content

Commit 370c7ff

Browse files
committed
LT/RT support
1 parent 68b9335 commit 370c7ff

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

src/controllertab.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ ControllerTab::ControllerTab(QWidget *parent) : QWidget(parent) {
8080
if (!rbApp->controllerManager()->controllers().empty()) {
8181
mainLayout->addSpacing(12);
8282

83+
/* diagnostics */
84+
/*
85+
_axesLabel = new QLabel(this);
86+
mainLayout->addWidget(_axesLabel);
87+
*/
88+
8389
QSizePolicy spCol(QSizePolicy::Preferred, QSizePolicy::Preferred);
8490
spCol.setHorizontalStretch(1);
8591

@@ -197,23 +203,45 @@ void ControllerTab::onActiveControllerChanged(DinputController *oldController,
197203
if (newController != nullptr) {
198204
connect(newController, &DinputController::buttonPressed, this,
199205
&ControllerTab::onButtonPressed);
206+
/* diagnostics */
207+
/*
208+
connect(newController, &DinputController::ticked, this,
209+
&ControllerTab::updateAxesLabel);
210+
*/
200211
newController->startTracking((HWND)rbApp->window()->winId());
201212
}
202213
reloadData();
203214
}
204215

205-
void ControllerTab::onButtonPressed(ControllerConfig::Button button) {
206-
auto &confBinds =
207-
rbApp->controllerManager()->activeController()->config()->binds;
208-
for (int i = 0; i < (int)ControllerConfig::Bind::Num; i++) {
209-
if (confBinds[i] == button) {
210-
confBinds[i] = ControllerConfig::Button::Invalid;
211-
_binds[i]->le()->setText("");
212-
}
213-
}
216+
void ControllerTab::updateAxesLabel() {
217+
/* diagnostics */
218+
/*
219+
_axesLabel->setText(
220+
QString("Two axes: %1, lZ: %2, lRZ: %3")
221+
.arg(rbApp->controllerManager()->activeController()->twoAxes())
222+
.arg(
223+
rbApp->controllerManager()->activeController()->lastState()->lZ,
224+
4, 16)
225+
.arg(rbApp->controllerManager()
226+
->activeController()
227+
->lastState()
228+
->lRz,
229+
4, 16));
230+
*/
231+
}
214232

233+
void ControllerTab::onButtonPressed(ControllerConfig::Button button) {
215234
BtnRow *br = findFocusedBtnRow();
216235
if (br != nullptr) {
236+
auto &confBinds =
237+
rbApp->controllerManager()->activeController()->config()->binds;
238+
for (int i = 0; i < (int)ControllerConfig::Bind::Num; i++) {
239+
if (confBinds[i] == button) {
240+
confBinds[i] = ControllerConfig::Button::Invalid;
241+
_binds[i]->le()->setText("");
242+
}
243+
}
244+
217245
rbApp->controllerManager()->activeController()->config()->preset =
218246
ControllerConfig::Preset::Custom;
219247
confBinds[(int)br->bind()] = button;

src/controllertab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ControllerTab : public QWidget {
2525
QPushButton* _resetButton;
2626
BtnRow* _binds[(int)ControllerConfig::Bind::Num];
2727
bool _firstShowCaught = false;
28+
QLabel* _axesLabel;
2829

2930
BtnRow* findFocusedBtnRow();
3031

@@ -36,4 +37,5 @@ class ControllerTab : public QWidget {
3637
void onActiveControllerChanged(DinputController* oldController,
3738
DinputController* newController);
3839
void onButtonPressed(ControllerConfig::Button button);
40+
void updateAxesLabel();
3941
};

src/dinputcontroller.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ DinputController::DinputController(const DIDEVICEINSTANCE* pdidInstance,
2828

2929
_config = new ControllerConfig(_guid, this);
3030

31+
DIDEVICEOBJECTINSTANCE obj = {0};
32+
obj.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);
33+
_joystick->GetObjectInfo(&obj, 20, DIPH_BYOFFSET);
34+
// this is how they do it in the original launcher...
35+
if (obj.dwType == DIDFT_ALL) {
36+
_twoAxes = false;
37+
} else {
38+
_twoAxes = true;
39+
}
40+
3141
_timer.setSingleShot(true);
3242
_timer.setInterval((int)(1000.f / 30.f));
3343
connect(&_timer, &QTimer::timeout, this, &DinputController::timerTick);
@@ -66,15 +76,28 @@ void DinputController::timerTick() {
6676
return;
6777
}
6878

69-
for (int i = 0; i < (int)ControllerConfig::Button::Num; i++) {
79+
for (int i = 0; i < (int)ControllerConfig::Button::LT; i++) {
7080
if (newState.rgbButtons[i] & 0x80 &&
7181
!(_lastState.rgbButtons[i] & 0x80)) {
7282
emit buttonPressed((ControllerConfig::Button)i);
7383
}
7484
}
7585

86+
if (_twoAxes) {
87+
// TODO: this
88+
} else {
89+
if (newState.lZ > 0x8FFF && _lastState.lZ <= 0x8FFF) {
90+
emit buttonPressed(ControllerConfig::Button::LT);
91+
}
92+
if (newState.lZ < 0x6FFF && _lastState.lZ >= 0x6FFF) {
93+
emit buttonPressed(ControllerConfig::Button::RT);
94+
}
95+
}
96+
7697
_lastState = newState;
7798

99+
emit ticked();
100+
78101
_timer.start();
79102
}
80103

src/dinputcontroller.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ class DinputController : public QObject {
3737
void startTracking(HWND topLevelWindow);
3838
void stopTracking();
3939

40+
/* diagnostics */
41+
const DIJOYSTATE* lastState() { return &_lastState; }
42+
bool twoAxes() { return _twoAxes; }
43+
4044
signals:
4145
void buttonPressed(ControllerConfig::Button button);
46+
/* diagnostics */
47+
void ticked();
4248

4349
private:
4450
bool _isXinput;
4551
QString _guid;
4652
ControllerConfig* _config = nullptr;
4753
QString _deviceName;
4854
LPDIRECTINPUTDEVICE8 _joystick = nullptr;
55+
bool _twoAxes;
4956
DIJOYSTATE _lastState = {0};
5057
QTimer _timer;
5158

0 commit comments

Comments
 (0)