AntiMicroX
Loading...
Searching...
No Matches
joysensor.h
Go to the documentation of this file.
1/* antimicrox Gamepad to KB+M event mapper
2 * Copyright (C) 2022 Max Maisel <max.maisel@posteo.de>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <QHash>
21#include <QObject>
22#include <QTimer>
23
24#include "joysensordirection.h"
25#include "joysensortype.h"
26#include "pt1filter.h"
27
28class SetJoystick;
29class JoySensorButton;
32
39class JoySensor : public QObject
40{
42
43 public:
44 explicit JoySensor(JoySensorType type, int originset, SetJoystick *parent_set, QObject *parent);
45 virtual ~JoySensor();
46
47 void joyEvent(float *values, bool ignoresets = false);
48 void queuePendingEvent(float *values, bool ignoresets = false);
50 bool hasPendingEvent() const;
51 void clearPendingEvent();
52
54 bool hasSlotsAssigned() const;
55
56 QString getPartialName(bool forceFullFormat = false, bool displayNames = false) const;
57 QString getSensorName() const;
58
59 JoySensorType getType() const;
61 double getDeadZone() const;
62 double getDiagonalRange() const;
63 double getMaxZone() const;
64 unsigned int getSensorDelay() const;
65 virtual float getXCoordinate() const = 0;
66 virtual float getYCoordinate() const = 0;
67 virtual float getZCoordinate() const = 0;
68 virtual QString sensorTypeName() const = 0;
69
70 bool inDeadZone(float *values) const;
71 double getDistanceFromDeadZone() const;
72 double getDistanceFromDeadZone(double x, double y, double z) const;
73 double calculateXDistanceFromDeadZone() const;
74 double calculateXDistanceFromDeadZone(double x, double y, double z) const;
75 double calculateYDistanceFromDeadZone() const;
76 double calculateYDistanceFromDeadZone(double x, double y, double z) const;
77 double calculateZDistanceFromDeadZone() const;
78 double calculateZDistanceFromDeadZone(double x, double y, double z) const;
79 double calculateDistance() const;
80 double calculateDistance(double x, double y, double z) const;
81 double calculatePitch() const;
82 double calculatePitch(double x, double y, double z) const;
83 double calculateRoll() const;
84 double calculateRoll(double x, double y, double z) const;
86
87 static double radToDeg(double value);
88 static double degToRad(double value);
89
90 bool isCalibrated() const;
91 void resetCalibration();
92 virtual void getCalibration(double *offsetX, double *offsetY, double *offsetZ) const = 0;
93 virtual void setCalibration(double offsetX, double offsetY, double offsetZ) = 0;
94
97
98 bool isDefault() const;
100 void writeConfig(QXmlStreamWriter *xml) const;
101
102 SetJoystick *getParentSet() const;
103
104 signals:
105 void moved(float xaxis, float yaxis, float zaxis);
106 void active(float xaxis, float yaxis, float zaxis);
107 void released(float xaxis, float yaxis, float zaxis);
108 void deadZoneChanged(double value);
109 void diagonalRangeChanged(double value);
110 void maxZoneChanged(double value);
111 void sensorDelayChanged(int value);
114
115 public slots:
116 virtual void reset();
117 void setDeadZone(double value);
118 void setMaxZone(double value);
119 void setDiagonalRange(double value);
120 void setSensorDelay(unsigned int value);
123
124 private slots:
125 void delayTimerExpired();
126
127 protected:
128 void resetButtons();
129 virtual void populateButtons() = 0;
131 virtual void applyCalibration() = 0;
134
139 unsigned int m_sensor_delay;
140
142 static const size_t ACTIVE_BUTTON_COUNT = 3;
144
151
155
159};
Definition joydpadxml.h:27
Represents a sensor mapping in a SetJoystick.
Definition joysensorbutton.h:31
Represents one sensor in a SetJoystick and its connections to other parts of the application....
Definition joysensor.h:40
void setMaxZone(double value)
Sets the maximum zone of the sensor to the given value.
Definition joysensor.cpp:614
bool m_calibrated
Definition joysensor.h:147
void resetCalibration()
Resets the calibration of the sensor back to uncalibrated state.
Definition joysensor.cpp:535
void moved(float xaxis, float yaxis, float zaxis)
void setSensorDelay(unsigned int value)
Sets the sensor input delaqy to the given value.
Definition joysensor.cpp:649
JoySensorButton * getDirectionButton(JoySensorDirection direction)
Get a pointer to the sensor direction button for the desired direction.
Definition joysensor.cpp:550
double getDistanceFromDeadZone() const
Get current radial distance of the sensor past the assigned dead zone.
Definition joysensor.cpp:289
double getDeadZone() const
Get the assigned dead zone value.
Definition joysensor.cpp:258
JoySensorType m_type
Definition joysensor.h:135
double m_diagonal_range
Definition joysensor.h:137
bool hasPendingEvent() const
Checks if an event is queued.
Definition joysensor.cpp:152
SetJoystick * getParentSet() const
Get pointer to the set that a sensor belongs to.
Definition joysensor.cpp:774
bool inDeadZone(float *values) const
Checks if the sensor vector is currently in the dead zone.
Definition joysensor.cpp:282
void sensorNameChanged()
double calculatePitch() const
Calculate the pitch angle (in degrees) corresponding to the current position of controller.
Definition joysensor.cpp:425
void readConfig(QXmlStreamReader *xml)
Take a XML stream and set the sensor and direction button properties according to the values containe...
Definition joysensor.cpp:682
double calculateYDistanceFromDeadZone() const
Get current Y distance of the sensor past the assigned dead zone.
Definition joysensor.cpp:345
void setDiagonalRange(double value)
Set the diagonal range value for a sensor.
Definition joysensor.cpp:629
QString getSensorName() const
Returns the sensor name.
Definition joysensor.cpp:242
float m_pending_value[3]
Definition joysensor.h:146
bool m_pending_ignore_sets
Definition joysensor.h:150
JoySensorType getType() const
Returns the sensor type.
Definition joysensor.cpp:247
void diagonalRangeChanged(double value)
double calculateZDistanceFromDeadZone() const
Get current Z distance of the sensor past the assigned dead zone.
Definition joysensor.cpp:377
void setDeadZone(double value)
Sets the dead zone of the sensor to the given value.
Definition joysensor.cpp:599
bool m_pending_event
Definition joysensor.h:149
bool isDefault() const
Checks if all sensor settings and button mappings are the their default values. This is used during X...
Definition joysensor.cpp:557
double calculateXDistanceFromDeadZone() const
Get current X distance of the sensor past the assigned dead zone.
Definition joysensor.cpp:313
void active(float xaxis, float yaxis, float zaxis)
void released(float xaxis, float yaxis, float zaxis)
static double degToRad(double value)
Utility function which converts a given value from degree to radians.
Definition joysensor.cpp:524
virtual float getXCoordinate() const =0
virtual void applyCalibration()=0
virtual void setCalibration(double offsetX, double offsetY, double offsetZ)=0
void resetButtons()
Reset all the properties of the sensor direction buttons.
Definition joysensor.cpp:785
void copyAssignments(JoySensor *dest_sensor)
Copy slots from all sensor buttons and properties from a sensor onto another.
Definition joysensor.cpp:168
virtual ~JoySensor()
Definition joysensor.cpp:43
static double radToDeg(double value)
Utility function which converts a given value from radians to degree.
Definition joysensor.cpp:519
JoySensorDirection getCurrentDirection() const
Returns the current sensor direction.
Definition joysensor.cpp:252
virtual float getZCoordinate() const =0
void delayTimerExpired()
Slot called when m_delay_timer has timed out. The method will call createDeskEvent.
Definition joysensor.cpp:780
JoySensorDirection m_current_direction
Definition joysensor.h:156
virtual JoySensorDirection calculateSensorDirection()=0
void sensorDelayChanged(int value)
virtual void populateButtons()=0
QTimer m_delay_timer
Definition joysensor.h:154
virtual float getYCoordinate() const =0
void writeConfig(QXmlStreamWriter *xml) const
Write the status of the properties of a sensor and direction buttons to an XML stream.
Definition joysensor.cpp:738
double calculateRoll() const
Calculate the roll angle (in degrees) corresponding to the current position of controller.
Definition joysensor.cpp:455
void determineSensorEvent(JoySensorButton **eventbutton) const
Set buttons for current sensor direction zone.
Definition joysensor.cpp:800
virtual void getCalibration(double *offsetX, double *offsetY, double *offsetZ) const =0
bool hasSlotsAssigned() const
Check if any direction is mapped to a keyboard or mouse event.
Definition joysensor.cpp:202
unsigned int getSensorDelay() const
Get the assigned input delay.
Definition joysensor.cpp:276
virtual void reset()
Resets internal variables back to default.
Definition joysensor.cpp:578
void setSensorName(QString tempName)
Sets the name of this sensor.
Definition joysensor.cpp:663
SetJoystick * m_parent_set
Definition joysensor.h:157
bool isCalibrated() const
Check if the sensor is calibrated.
Definition joysensor.cpp:530
void createDeskEvent(JoySensorDirection direction, bool ignoresets=false)
Find the position of the three sensor axes, deactivate no longer used sensor direction button and the...
Definition joysensor.cpp:825
void maxZoneChanged(double value)
double m_calibration_value[3]
Definition joysensor.h:148
double calculateDirectionalDistance(JoySensorDirection direction) const
Used to calculate the distance value that should be used by the JoyButton in the given direction.
Definition joysensor.cpp:488
void deadZoneChanged(double value)
double calculateDistance() const
Get the vector length of the sensor.
Definition joysensor.cpp:408
JoySensorButton * m_active_button[ACTIVE_BUTTON_COUNT]
Definition joysensor.h:143
virtual QString sensorTypeName() const =0
double getMaxZone() const
Get the assigned max zone value.
Definition joysensor.cpp:270
int m_originset
Definition joysensor.h:152
void queuePendingEvent(float *values, bool ignoresets=false)
Queues next movement event from InputDaemon.
Definition joysensor.cpp:121
bool m_active
Definition joysensor.h:141
static const size_t ACTIVE_BUTTON_COUNT
Definition joysensor.h:142
void propertyUpdated()
void activatePendingEvent()
Activates previously queued movement event This is called by InputDevice.
Definition joysensor.cpp:138
QString getPartialName(bool forceFullFormat=false, bool displayNames=false) const
Get the name of this sensor.
Definition joysensor.cpp:219
double m_dead_zone
Definition joysensor.h:136
void joyEvent(float *values, bool ignoresets=false)
Main sensor mapping function. When activated, it generates a "moved" QT event which updates various p...
Definition joysensor.cpp:53
QHash< JoySensorDirection, JoySensorButton * > * getButtons()
Returns a QHash which maps the SensorDirection to the corresponding JoySensorButton.
Definition joysensor.cpp:541
void clearPendingEvent()
Clears a previously queued event.
Definition joysensor.cpp:157
double getDiagonalRange() const
Get the assigned diagonal range value.
Definition joysensor.cpp:264
unsigned int m_sensor_delay
Definition joysensor.h:139
double m_max_zone
Definition joysensor.h:138
void establishPropertyUpdatedConnection()
Definition joysensor.cpp:672
float m_current_value[3]
Definition joysensor.h:145
QString m_sensor_name
Definition joysensor.h:153
QHash< JoySensorDirection, JoySensorButton * > m_buttons
Definition joysensor.h:158
A set of mapped events which can by switched by a controller event. Contains controller input objects...
Definition setjoystick.h:40
JoySensorDirection
A bitfield style enum which encodes all possible three dimensional sensor directions....
Definition joysensordirection.h:28
JoySensorType
Definition joysensortype.h:24