|
|
|
@ -30,11 +30,14 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
@@ -30,11 +30,14 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
|
|
|
|
|
"ThrottleAxis" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, MultiVehicleManager* multiVehicleManager) |
|
|
|
|
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager) |
|
|
|
|
: _exitThread(false) |
|
|
|
|
, _name(name) |
|
|
|
|
, _axisCount(axisCount) |
|
|
|
|
, _buttonCount(buttonCount) |
|
|
|
|
, _hatCount(hatCount) |
|
|
|
|
, _hatButtonCount(4*hatCount) |
|
|
|
|
, _totalButtonCount(_buttonCount+_hatButtonCount) |
|
|
|
|
, _calibrationMode(CalibrationModeOff) |
|
|
|
|
, _rgAxisValues(NULL) |
|
|
|
|
, _rgCalibration(NULL) |
|
|
|
@ -46,15 +49,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, MultiVeh
@@ -46,15 +49,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, MultiVeh
|
|
|
|
|
, _pollingStartedForCalibration(false) |
|
|
|
|
, _multiVehicleManager(multiVehicleManager) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
_rgAxisValues = new int[_axisCount]; |
|
|
|
|
_rgCalibration = new Calibration_t[_axisCount]; |
|
|
|
|
_rgButtonValues = new bool[_buttonCount]; |
|
|
|
|
_rgButtonActions = new QString[_buttonCount]; |
|
|
|
|
_rgButtonValues = new bool[_totalButtonCount]; |
|
|
|
|
_rgButtonActions = new QString[_totalButtonCount]; |
|
|
|
|
|
|
|
|
|
for (int i=0; i<_axisCount; i++) { |
|
|
|
|
_rgAxisValues[i] = 0; |
|
|
|
|
} |
|
|
|
|
for (int i=0; i<_buttonCount; i++) { |
|
|
|
|
for (int i=0; i<_totalButtonCount; i++) { |
|
|
|
|
_rgButtonValues[i] = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -242,6 +246,21 @@ void Joystick::run(void)
@@ -242,6 +246,21 @@ void Joystick::run(void)
|
|
|
|
|
emit rawButtonPressedChanged(buttonIndex, newButtonValue); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update hat - append hat buttons to the end of the normal button list
|
|
|
|
|
int numHatButtons = 4; |
|
|
|
|
for (int hatIndex=0; hatIndex<_hatCount; hatIndex++) { |
|
|
|
|
for (int hatButtonIndex=0; hatButtonIndex<numHatButtons; hatButtonIndex++) { |
|
|
|
|
// Create new index value that includes the normal button list
|
|
|
|
|
int rgButtonValueIndex = hatIndex*numHatButtons + hatButtonIndex + _buttonCount; |
|
|
|
|
// Get hat value from joystick
|
|
|
|
|
bool newButtonValue = _getHat(hatIndex,hatButtonIndex); |
|
|
|
|
if (newButtonValue != _rgButtonValues[rgButtonValueIndex]) { |
|
|
|
|
_rgButtonValues[rgButtonValueIndex] = newButtonValue; |
|
|
|
|
emit rawButtonPressedChanged(rgButtonValueIndex, newButtonValue); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_calibrationMode != CalibrationModeCalibrating) { |
|
|
|
|
int axis = _rgFunctionAxis[rollFunction]; |
|
|
|
@ -279,13 +298,13 @@ void Joystick::run(void)
@@ -279,13 +298,13 @@ void Joystick::run(void)
|
|
|
|
|
// We only send the buttons the firmwware has reserved
|
|
|
|
|
int reservedButtonCount = _activeVehicle->manualControlReservedButtonCount(); |
|
|
|
|
if (reservedButtonCount == -1) { |
|
|
|
|
reservedButtonCount = _buttonCount; |
|
|
|
|
reservedButtonCount = _totalButtonCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
quint16 newButtonBits = 0; // New set of button which are down
|
|
|
|
|
quint16 buttonPressedBits = 0; // Buttons pressed for manualControl signal
|
|
|
|
|
|
|
|
|
|
for (int buttonIndex=0; buttonIndex<_buttonCount; buttonIndex++) { |
|
|
|
|
for (int buttonIndex=0; buttonIndex<_totalButtonCount; buttonIndex++) { |
|
|
|
|
quint16 buttonBit = 1 << buttonIndex; |
|
|
|
|
|
|
|
|
|
if (!_rgButtonValues[buttonIndex]) { |
|
|
|
@ -313,7 +332,7 @@ void Joystick::run(void)
@@ -313,7 +332,7 @@ void Joystick::run(void)
|
|
|
|
|
_lastButtonBits = newButtonBits; |
|
|
|
|
|
|
|
|
|
qCDebug(JoystickValuesLog) << "name:roll:pitch:yaw:throttle" << name() << roll << -pitch << yaw << throttle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -535,6 +554,6 @@ bool Joystick::_validAxis(int axis)
@@ -535,6 +554,6 @@ bool Joystick::_validAxis(int axis)
|
|
|
|
|
|
|
|
|
|
bool Joystick::_validButton(int button) |
|
|
|
|
{ |
|
|
|
|
return button >= 0 && button < _buttonCount; |
|
|
|
|
return button >= 0 && button < _totalButtonCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|