Qt: Add incomplete sensor mapping editor
Jeffrey Pfau jeffrey@endrift.com
Tue, 21 Apr 2015 01:06:39 -0700
6 files changed,
337 insertions(+),
122 deletions(-)
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -165,6 +165,14 @@
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 {
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -65,9 +65,10 @@ QStringList connectedGamepads(uint32_t type) const;
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();
M
src/platform/qt/SensorView.cpp
→
src/platform/qt/SensorView.cpp
@@ -6,12 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#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 @@ m_ui.time->setDateTime(QDateTime::currentDateTime());
}); 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));
M
src/platform/qt/SensorView.h
→
src/platform/qt/SensorView.h
@@ -6,22 +6,27 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef QGBA_SENSOR_VIEW #define QGBA_SENSOR_VIEW +#include <QTimer> #include <QWidget> #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; }; }
M
src/platform/qt/SensorView.ui
→
src/platform/qt/SensorView.ui
@@ -6,8 +6,8 @@ <property name="geometry">
<rect> <x>0</x> <y>0</y> - <width>411</width> - <height>170</height> + <width>508</width> + <height>258</height> </rect> </property> <property name="sizePolicy">@@ -19,124 +19,281 @@ </property>
<property name="windowTitle"> <string>Sensors</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout"> + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Realtime clock</string> - </property> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="2" column="0"> - <widget class="QRadioButton" name="timeFakeEpoch"> - <property name="text"> - <string>Start time at</string> - </property> - <attribute name="buttonGroup"> - <string notr="true">timeButtons</string> - </attribute> - </widget> - </item> - <item row="1" column="0"> - <widget class="QRadioButton" name="timeFixed"> - <property name="text"> - <string>Fixed time</string> - </property> - <attribute name="buttonGroup"> - <string notr="true">timeButtons</string> - </attribute> - </widget> - </item> - <item row="0" column="0"> - <widget class="QRadioButton" name="timeNoOverride"> - <property name="text"> - <string>System time</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <attribute name="buttonGroup"> - <string notr="true">timeButtons</string> - </attribute> - </widget> - </item> - <item row="3" column="0" colspan="2"> - <widget class="QDateTimeEdit" name="time"> - <property name="wrapping"> - <bool>true</bool> - </property> - <property name="maximumDate"> - <date> - <year>2100</year> - <month>1</month> - <day>2</day> - </date> - </property> - <property name="minimumDate"> - <date> - <year>2000</year> - <month>1</month> - <day>1</day> - </date> - </property> - <property name="currentSection"> - <enum>QDateTimeEdit::MonthSection</enum> - </property> - <property name="displayFormat"> - <string>MM/dd/yy hh:mm:ss AP</string> - </property> - <property name="timeSpec"> - <enum>Qt::UTC</enum> - </property> - </widget> - </item> - <item row="0" column="1" rowspan="3"> - <widget class="QPushButton" name="timeNow"> - <property name="text"> - <string>Now</string> - </property> - </widget> - </item> - </layout> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Realtime clock</string> + </property> + <layout class="QGridLayout" name="gridLayout_4"> + <item row="1" column="0"> + <widget class="QRadioButton" name="timeFixed"> + <property name="text"> + <string>Fixed time</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">timeButtons</string> + </attribute> + </widget> + </item> + <item row="0" column="0"> + <widget class="QRadioButton" name="timeNoOverride"> + <property name="text"> + <string>System time</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <attribute name="buttonGroup"> + <string notr="true">timeButtons</string> + </attribute> + </widget> + </item> + <item row="2" column="0"> + <widget class="QRadioButton" name="timeFakeEpoch"> + <property name="text"> + <string>Start time at</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">timeButtons</string> + </attribute> + </widget> + </item> + <item row="0" column="1" rowspan="3"> + <widget class="QPushButton" name="timeNow"> + <property name="text"> + <string>Now</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QDateTimeEdit" name="time"> + <property name="wrapping"> + <bool>true</bool> + </property> + <property name="maximumDate"> + <date> + <year>2100</year> + <month>1</month> + <day>6</day> + </date> + </property> + <property name="minimumDate"> + <date> + <year>2000</year> + <month>1</month> + <day>1</day> + </date> + </property> + <property name="currentSection"> + <enum>QDateTimeEdit::MonthSection</enum> + </property> + <property name="displayFormat"> + <string>MM/dd/yy hh:mm:ss AP</string> + </property> + <property name="timeSpec"> + <enum>Qt::UTC</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Light sensor</string> + </property> + <layout class="QGridLayout" name="gridLayout_6"> + <item row="0" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Brightness</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QSpinBox" name="lightSpin"> + <property name="maximum"> + <number>255</number> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QSlider" name="lightSlide"> + <property name="maximum"> + <number>255</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="tickPosition"> + <enum>QSlider::TicksBelow</enum> + </property> + <property name="tickInterval"> + <number>16</number> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> </item> <item> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Light sensor</string> - </property> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Brightness</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="lightSpin"> - <property name="maximum"> - <number>255</number> - </property> - </widget> - </item> - <item row="1" column="0" colspan="2"> - <widget class="QSlider" name="lightSlide"> - <property name="maximum"> - <number>255</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="tickPosition"> - <enum>QSlider::TicksBelow</enum> - </property> - <property name="tickInterval"> - <number>16</number> - </property> - </widget> - </item> - </layout> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QGroupBox" name="tilt"> + <property name="title"> + <string>Tilt sensor</string> + </property> + <layout class="QGridLayout" name="gridLayout_10"> + <item row="0" column="0" colspan="2"> + <layout class="QGridLayout" name="gridLayout_11"> + <item row="0" column="1"> + <widget class="QPushButton" name="tiltSetY"> + <property name="text"> + <string>Set Y</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QPushButton" name="tiltSetX"> + <property name="text"> + <string>Set X</string> + </property> + </widget> + </item> + <item row="1" column="0" alignment="Qt::AlignHCenter"> + <widget class="QDoubleSpinBox" name="tiltX"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Ignored" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="minimum"> + <double>-1.000000000000000</double> + </property> + <property name="maximum"> + <double>1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + </widget> + </item> + <item row="1" column="1" alignment="Qt::AlignHCenter"> + <widget class="QDoubleSpinBox" name="tiltY"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Ignored" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::NoButtons</enum> + </property> + <property name="minimum"> + <double>-1.000000000000000</double> + </property> + <property name="maximum"> + <double>1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="gyro"> + <property name="title"> + <string>Gyroscope</string> + </property> + <layout class="QGridLayout" name="gridLayout_12"> + <item row="0" column="0" colspan="2"> + <layout class="QGridLayout" name="gridLayout_17"> + <item row="0" column="1"> + <widget class="QPushButton" name="gyroSetY"> + <property name="text"> + <string>Set Y</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QPushButton" name="gyroSetX"> + <property name="text"> + <string>Set X</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Sensitivity</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="gyroSensitivity"> + <property name="decimals"> + <number>0</number> + </property> + <property name="maximum"> + <double>1000.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QSlider" name="gyroView"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="minimum"> + <number>-2147483647</number> + </property> + <property name="maximum"> + <number>2147483647</number> + </property> + <property name="value"> + <number>0</number> + </property> + <property name="tracking"> + <bool>false</bool> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> </item> </layout> </widget>
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -312,7 +312,7 @@ openView(overrideWindow);
} void Window::openSensorWindow() { - SensorView* sensorWindow = new SensorView(m_controller); + SensorView* sensorWindow = new SensorView(m_controller, &m_inputController); openView(sensorWindow); }