From d0a332ffd4bcc238f89d042c770d841ef1166039 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 21 Apr 2015 01:06:39 -0700 Subject: [PATCH] Qt: Add incomplete sensor mapping editor --- src/platform/qt/InputController.cpp | 8 + src/platform/qt/InputController.h | 3 +- src/platform/qt/SensorView.cpp | 45 +++- src/platform/qt/SensorView.h | 10 +- src/platform/qt/SensorView.ui | 391 +++++++++++++++++++--------- src/platform/qt/Window.cpp | 2 +- 6 files changed, 337 insertions(+), 122 deletions(-) diff --git a/src/platform/qt/InputController.cpp b/src/platform/qt/InputController.cpp index f364f4b4c..321ec113b 100644 --- a/src/platform/qt/InputController.cpp +++ b/src/platform/qt/InputController.cpp @@ -165,6 +165,14 @@ GBARumble* InputController::rumble() { GBARotationSource* InputController::rotationSource() { return &m_sdlPlayer.rotation.d; } +#else +GBARumble* InputController::rumble() { + return nullptr; +} + +GBARotationSource* InputController::rotationSource() { + return nullptr; +} #endif GBAKey InputController::mapKeyboard(int key) const { diff --git a/src/platform/qt/InputController.h b/src/platform/qt/InputController.h index 94ce15574..a7c607af5 100644 --- a/src/platform/qt/InputController.h +++ b/src/platform/qt/InputController.h @@ -65,9 +65,10 @@ public: int gamepad(uint32_t type) const { return m_sdlPlayer.joystickIndex; } void setGamepad(uint32_t type, int index) { GBASDLPlayerChangeJoystick(&s_sdlEvents, &m_sdlPlayer, index); } void setPreferredGamepad(uint32_t type, const QString& device); +#endif + GBARumble* rumble(); GBARotationSource* rotationSource(); -#endif public slots: void testGamepad(); diff --git a/src/platform/qt/SensorView.cpp b/src/platform/qt/SensorView.cpp index 31914f0b4..5d637c427 100644 --- a/src/platform/qt/SensorView.cpp +++ b/src/platform/qt/SensorView.cpp @@ -6,12 +6,15 @@ #include "SensorView.h" #include "GameController.h" +#include "InputController.h" using namespace QGBA; -SensorView::SensorView(GameController* controller, QWidget* parent) +SensorView::SensorView(GameController* controller, InputController* input, QWidget* parent) : QWidget(parent) , m_controller(controller) + , m_input(input) + , m_rotation(input->rotationSource()) { m_ui.setupUi(this); @@ -33,7 +36,45 @@ SensorView::SensorView(GameController* controller, QWidget* parent) }); connect(m_controller, SIGNAL(luminanceValueChanged(int)), this, SLOT(luminanceValueChanged(int))); - } + + m_timer.setInterval(2); + connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateSensors())); + if (!m_rotation || !m_rotation->readTiltX || !m_rotation->readTiltY) { + m_ui.tilt->hide(); + } else { + m_timer.start(); + } + + if (!m_rotation || !m_rotation->readGyroZ) { + m_ui.gyro->hide(); + } else { + m_timer.start(); + } +} + +void SensorView::updateSensors() { + m_controller->threadInterrupt(); + if (m_rotation->sample && (!m_controller->isLoaded() || !(m_controller->thread()->gba->memory.hw.devices & (HW_GYRO | HW_TILT)))) { + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + m_rotation->sample(m_rotation); + } + if (m_rotation->readTiltX && m_rotation->readTiltY) { + float x = m_rotation->readTiltX(m_rotation); + float y = m_rotation->readTiltY(m_rotation); + m_ui.tiltX->setValue(x / 469762048.0f); // TODO: Document this value (0xE0 << 21) + m_ui.tiltY->setValue(y / 469762048.0f); + } + if (m_rotation->readGyroZ) { + m_ui.gyroView->setValue(m_rotation->readGyroZ(m_rotation)); + } + m_controller->threadContinue(); +} void SensorView::setLuminanceValue(int value) { value = std::max(0, std::min(value, 255)); diff --git a/src/platform/qt/SensorView.h b/src/platform/qt/SensorView.h index bd7ef8f27..8d0e223aa 100644 --- a/src/platform/qt/SensorView.h +++ b/src/platform/qt/SensorView.h @@ -6,22 +6,27 @@ #ifndef QGBA_SENSOR_VIEW #define QGBA_SENSOR_VIEW +#include #include #include "ui_SensorView.h" +struct GBARotationSource; + namespace QGBA { class ConfigController; class GameController; +class InputController; class SensorView : public QWidget { Q_OBJECT public: - SensorView(GameController* controller, QWidget* parent = nullptr); + SensorView(GameController* controller, InputController* input, QWidget* parent = nullptr); private slots: + void updateSensors(); void setLuminanceValue(int); void luminanceValueChanged(int); @@ -29,6 +34,9 @@ private: Ui::SensorView m_ui; GameController* m_controller; + InputController* m_input; + GBARotationSource* m_rotation; + QTimer m_timer; }; } diff --git a/src/platform/qt/SensorView.ui b/src/platform/qt/SensorView.ui index b484511d1..a6f9a27e9 100644 --- a/src/platform/qt/SensorView.ui +++ b/src/platform/qt/SensorView.ui @@ -6,8 +6,8 @@ 0 0 - 411 - 170 + 508 + 258 @@ -19,124 +19,281 @@ Sensors - + - - - Realtime clock - - - - - - Start time at - - - timeButtons - - - - - - - Fixed time - - - timeButtons - - - - - - - System time - - - true - - - timeButtons - - - - - - - true - - - - 2100 - 1 - 2 - - - - - 2000 - 1 - 1 - - - - QDateTimeEdit::MonthSection - - - MM/dd/yy hh:mm:ss AP - - - Qt::UTC - - - - - - - Now - - - - - + + + + + Realtime clock + + + + + + Fixed time + + + timeButtons + + + + + + + System time + + + true + + + timeButtons + + + + + + + Start time at + + + timeButtons + + + + + + + Now + + + + + + + true + + + + 2100 + 1 + 6 + + + + + 2000 + 1 + 1 + + + + QDateTimeEdit::MonthSection + + + MM/dd/yy hh:mm:ss AP + + + Qt::UTC + + + + + + + + + + Light sensor + + + + + + Brightness + + + + + + + 255 + + + + + + + 255 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 16 + + + + + + + - - - Light sensor - - - - - - Brightness - - - - - - - 255 - - - - - - - 255 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 16 - - - - - + + + + + Tilt sensor + + + + + + + + Set Y + + + + + + + Set X + + + + + + + + 0 + 0 + + + + Qt::AlignCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1.000000000000000 + + + 1.000000000000000 + + + 0.010000000000000 + + + + + + + + 0 + 0 + + + + Qt::AlignCenter + + + true + + + QAbstractSpinBox::NoButtons + + + -1.000000000000000 + + + 1.000000000000000 + + + 0.010000000000000 + + + + + + + + + + + + Gyroscope + + + + + + + + Set Y + + + + + + + Set X + + + + + + + Sensitivity + + + + + + + 0 + + + 1000.000000000000000 + + + + + + + false + + + -2147483647 + + + 2147483647 + + + 0 + + + false + + + Qt::Horizontal + + + + + + + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index d5178ec84..6984fb7e2 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -312,7 +312,7 @@ void Window::openOverrideWindow() { } void Window::openSensorWindow() { - SensorView* sensorWindow = new SensorView(m_controller); + SensorView* sensorWindow = new SensorView(m_controller, &m_inputController); openView(sensorWindow); }