|
|
@ -42,7 +42,6 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC |
|
|
|
, _rgAxisValues(NULL) |
|
|
|
, _rgAxisValues(NULL) |
|
|
|
, _rgCalibration(NULL) |
|
|
|
, _rgCalibration(NULL) |
|
|
|
, _rgButtonValues(NULL) |
|
|
|
, _rgButtonValues(NULL) |
|
|
|
, _rgButtonActions(NULL) |
|
|
|
|
|
|
|
, _lastButtonBits(0) |
|
|
|
, _lastButtonBits(0) |
|
|
|
, _throttleMode(ThrottleModeCenterZero) |
|
|
|
, _throttleMode(ThrottleModeCenterZero) |
|
|
|
, _activeVehicle(NULL) |
|
|
|
, _activeVehicle(NULL) |
|
|
@ -53,7 +52,6 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC |
|
|
|
_rgAxisValues = new int[_axisCount]; |
|
|
|
_rgAxisValues = new int[_axisCount]; |
|
|
|
_rgCalibration = new Calibration_t[_axisCount]; |
|
|
|
_rgCalibration = new Calibration_t[_axisCount]; |
|
|
|
_rgButtonValues = new bool[_totalButtonCount]; |
|
|
|
_rgButtonValues = new bool[_totalButtonCount]; |
|
|
|
_rgButtonActions = new QString[_totalButtonCount]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<_axisCount; i++) { |
|
|
|
for (int i=0; i<_axisCount; i++) { |
|
|
|
_rgAxisValues[i] = 0; |
|
|
|
_rgAxisValues[i] = 0; |
|
|
@ -61,7 +59,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC |
|
|
|
for (int i=0; i<_totalButtonCount; i++) { |
|
|
|
for (int i=0; i<_totalButtonCount; i++) { |
|
|
|
_rgButtonValues[i] = false; |
|
|
|
_rgButtonValues[i] = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_loadSettings(); |
|
|
|
_loadSettings(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -70,66 +68,65 @@ Joystick::~Joystick() |
|
|
|
delete _rgAxisValues; |
|
|
|
delete _rgAxisValues; |
|
|
|
delete _rgCalibration; |
|
|
|
delete _rgCalibration; |
|
|
|
delete _rgButtonValues; |
|
|
|
delete _rgButtonValues; |
|
|
|
delete _rgButtonActions; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Joystick::_loadSettings(void) |
|
|
|
void Joystick::_loadSettings(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QSettings settings; |
|
|
|
QSettings settings; |
|
|
|
|
|
|
|
|
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_name); |
|
|
|
settings.beginGroup(_name); |
|
|
|
|
|
|
|
|
|
|
|
bool badSettings = false; |
|
|
|
bool badSettings = false; |
|
|
|
bool convertOk; |
|
|
|
bool convertOk; |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_loadSettings " << _name; |
|
|
|
qCDebug(JoystickLog) << "_loadSettings " << _name; |
|
|
|
|
|
|
|
|
|
|
|
_calibrated = settings.value(_calibratedSettingsKey, false).toBool(); |
|
|
|
_calibrated = settings.value(_calibratedSettingsKey, false).toBool(); |
|
|
|
|
|
|
|
|
|
|
|
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); |
|
|
|
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk; |
|
|
|
badSettings |= !convertOk; |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_loadSettings calibrated:throttlemode:badsettings" << _calibrated << _throttleMode << badSettings; |
|
|
|
qCDebug(JoystickLog) << "_loadSettings calibrated:throttlemode:badsettings" << _calibrated << _throttleMode << badSettings; |
|
|
|
|
|
|
|
|
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
|
QString trimTpl ("Axis%1Trim"); |
|
|
|
QString trimTpl ("Axis%1Trim"); |
|
|
|
QString revTpl ("Axis%1Rev"); |
|
|
|
QString revTpl ("Axis%1Rev"); |
|
|
|
|
|
|
|
|
|
|
|
for (int axis=0; axis<_axisCount; axis++) { |
|
|
|
for (int axis=0; axis<_axisCount; axis++) { |
|
|
|
Calibration_t* calibration = &_rgCalibration[axis]; |
|
|
|
Calibration_t* calibration = &_rgCalibration[axis]; |
|
|
|
|
|
|
|
|
|
|
|
calibration->center = settings.value(trimTpl.arg(axis), 0).toInt(&convertOk); |
|
|
|
calibration->center = settings.value(trimTpl.arg(axis), 0).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk; |
|
|
|
badSettings |= !convertOk; |
|
|
|
|
|
|
|
|
|
|
|
calibration->min = settings.value(minTpl.arg(axis), -32768).toInt(&convertOk); |
|
|
|
calibration->min = settings.value(minTpl.arg(axis), -32768).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk; |
|
|
|
badSettings |= !convertOk; |
|
|
|
|
|
|
|
|
|
|
|
calibration->max = settings.value(maxTpl.arg(axis), 32767).toInt(&convertOk); |
|
|
|
calibration->max = settings.value(maxTpl.arg(axis), 32767).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk; |
|
|
|
badSettings |= !convertOk; |
|
|
|
|
|
|
|
|
|
|
|
calibration->reversed = settings.value(revTpl.arg(axis), false).toBool(); |
|
|
|
calibration->reversed = settings.value(revTpl.arg(axis), false).toBool(); |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << badSettings; |
|
|
|
qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << badSettings; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int function=0; function<maxFunction; function++) { |
|
|
|
for (int function=0; function<maxFunction; function++) { |
|
|
|
int functionAxis; |
|
|
|
int functionAxis; |
|
|
|
|
|
|
|
|
|
|
|
functionAxis = settings.value(_rgFunctionSettingsKey[function], -1).toInt(&convertOk); |
|
|
|
functionAxis = settings.value(_rgFunctionSettingsKey[function], -1).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk || (functionAxis == -1); |
|
|
|
badSettings |= !convertOk || (functionAxis == -1); |
|
|
|
|
|
|
|
|
|
|
|
_rgFunctionAxis[function] = functionAxis; |
|
|
|
_rgFunctionAxis[function] = functionAxis; |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_loadSettings function:axis:badsettings" << function << functionAxis << badSettings; |
|
|
|
qCDebug(JoystickLog) << "_loadSettings function:axis:badsettings" << function << functionAxis << badSettings; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
_rgButtonActions[button] = settings.value(QString(_buttonActionSettingsKey).arg(button), QString()).toString();
|
|
|
|
_rgButtonActions << settings.value(QString(_buttonActionSettingsKey).arg(button), QString()).toString(); |
|
|
|
qCDebug(JoystickLog) << "_loadSettings button:action" << button << _rgButtonActions[button]; |
|
|
|
qCDebug(JoystickLog) << "_loadSettings button:action" << button << _rgButtonActions[button]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (badSettings) { |
|
|
|
if (badSettings) { |
|
|
|
_calibrated = false; |
|
|
|
_calibrated = false; |
|
|
|
settings.setValue(_calibratedSettingsKey, false); |
|
|
|
settings.setValue(_calibratedSettingsKey, false); |
|
|
@ -139,28 +136,28 @@ void Joystick::_loadSettings(void) |
|
|
|
void Joystick::_saveSettings(void) |
|
|
|
void Joystick::_saveSettings(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QSettings settings; |
|
|
|
QSettings settings; |
|
|
|
|
|
|
|
|
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_settingsGroup); |
|
|
|
settings.beginGroup(_name); |
|
|
|
settings.beginGroup(_name); |
|
|
|
|
|
|
|
|
|
|
|
settings.setValue(_calibratedSettingsKey, _calibrated); |
|
|
|
settings.setValue(_calibratedSettingsKey, _calibrated); |
|
|
|
settings.setValue(_throttleModeSettingsKey, _throttleMode); |
|
|
|
settings.setValue(_throttleModeSettingsKey, _throttleMode); |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode" << _calibrated << _throttleMode; |
|
|
|
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode" << _calibrated << _throttleMode; |
|
|
|
|
|
|
|
|
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
|
QString trimTpl ("Axis%1Trim"); |
|
|
|
QString trimTpl ("Axis%1Trim"); |
|
|
|
QString revTpl ("Axis%1Rev"); |
|
|
|
QString revTpl ("Axis%1Rev"); |
|
|
|
|
|
|
|
|
|
|
|
for (int axis=0; axis<_axisCount; axis++) { |
|
|
|
for (int axis=0; axis<_axisCount; axis++) { |
|
|
|
Calibration_t* calibration = &_rgCalibration[axis]; |
|
|
|
Calibration_t* calibration = &_rgCalibration[axis]; |
|
|
|
|
|
|
|
|
|
|
|
settings.setValue(trimTpl.arg(axis), calibration->center); |
|
|
|
settings.setValue(trimTpl.arg(axis), calibration->center); |
|
|
|
settings.setValue(minTpl.arg(axis), calibration->min); |
|
|
|
settings.setValue(minTpl.arg(axis), calibration->min); |
|
|
|
settings.setValue(maxTpl.arg(axis), calibration->max); |
|
|
|
settings.setValue(maxTpl.arg(axis), calibration->max); |
|
|
|
settings.setValue(revTpl.arg(axis), calibration->reversed); |
|
|
|
settings.setValue(revTpl.arg(axis), calibration->reversed); |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_saveSettings name:axis:min:max:trim:reversed" |
|
|
|
qCDebug(JoystickLog) << "_saveSettings name:axis:min:max:trim:reversed" |
|
|
|
<< _name |
|
|
|
<< _name |
|
|
|
<< axis |
|
|
|
<< axis |
|
|
@ -169,12 +166,12 @@ void Joystick::_saveSettings(void) |
|
|
|
<< calibration->center |
|
|
|
<< calibration->center |
|
|
|
<< calibration->reversed; |
|
|
|
<< calibration->reversed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int function=0; function<maxFunction; function++) { |
|
|
|
for (int function=0; function<maxFunction; function++) { |
|
|
|
settings.setValue(_rgFunctionSettingsKey[function], _rgFunctionAxis[function]); |
|
|
|
settings.setValue(_rgFunctionSettingsKey[function], _rgFunctionAxis[function]); |
|
|
|
qCDebug(JoystickLog) << "_saveSettings name:function:axis" << _name << function << _rgFunctionSettingsKey[function]; |
|
|
|
qCDebug(JoystickLog) << "_saveSettings name:function:axis" << _name << function << _rgFunctionSettingsKey[function]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
settings.setValue(QString(_buttonActionSettingsKey).arg(button), _rgButtonActions[button]); |
|
|
|
settings.setValue(QString(_buttonActionSettingsKey).arg(button), _rgButtonActions[button]); |
|
|
|
qCDebug(JoystickLog) << "_saveSettings button:action" << button << _rgButtonActions[button]; |
|
|
|
qCDebug(JoystickLog) << "_saveSettings button:action" << button << _rgButtonActions[button]; |
|
|
@ -187,7 +184,7 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) |
|
|
|
float valueNormalized; |
|
|
|
float valueNormalized; |
|
|
|
float axisLength; |
|
|
|
float axisLength; |
|
|
|
float axisBasis; |
|
|
|
float axisBasis; |
|
|
|
|
|
|
|
|
|
|
|
if (value > calibration.center) { |
|
|
|
if (value > calibration.center) { |
|
|
|
axisBasis = 1.0f; |
|
|
|
axisBasis = 1.0f; |
|
|
|
valueNormalized = value - calibration.center; |
|
|
|
valueNormalized = value - calibration.center; |
|
|
@ -197,15 +194,15 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) |
|
|
|
valueNormalized = calibration.center - value; |
|
|
|
valueNormalized = calibration.center - value; |
|
|
|
axisLength = calibration.center - calibration.min; |
|
|
|
axisLength = calibration.center - calibration.min; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float axisPercent = valueNormalized / axisLength; |
|
|
|
float axisPercent = valueNormalized / axisLength; |
|
|
|
|
|
|
|
|
|
|
|
float correctedValue = axisBasis * axisPercent; |
|
|
|
float correctedValue = axisBasis * axisPercent; |
|
|
|
|
|
|
|
|
|
|
|
if (calibration.reversed) { |
|
|
|
if (calibration.reversed) { |
|
|
|
correctedValue *= -1.0f; |
|
|
|
correctedValue *= -1.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
#if 0 |
|
|
|
qCDebug(JoystickLog) << "_adjustRange corrected:value:min:max:center:reversed:basis:normalized:length" |
|
|
|
qCDebug(JoystickLog) << "_adjustRange corrected:value:min:max:center:reversed:basis:normalized:length" |
|
|
|
<< correctedValue |
|
|
|
<< correctedValue |
|
|
@ -226,7 +223,7 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) |
|
|
|
void Joystick::run(void) |
|
|
|
void Joystick::run(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_open(); |
|
|
|
_open(); |
|
|
|
|
|
|
|
|
|
|
|
while (!_exitThread) { |
|
|
|
while (!_exitThread) { |
|
|
|
_update(); |
|
|
|
_update(); |
|
|
|
|
|
|
|
|
|
|
@ -237,7 +234,7 @@ void Joystick::run(void) |
|
|
|
_rgAxisValues[axisIndex] = newAxisValue; |
|
|
|
_rgAxisValues[axisIndex] = newAxisValue; |
|
|
|
emit rawAxisValueChanged(axisIndex, newAxisValue); |
|
|
|
emit rawAxisValueChanged(axisIndex, newAxisValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update buttons
|
|
|
|
// Update buttons
|
|
|
|
for (int buttonIndex=0; buttonIndex<_buttonCount; buttonIndex++) { |
|
|
|
for (int buttonIndex=0; buttonIndex<_buttonCount; buttonIndex++) { |
|
|
|
bool newButtonValue = _getButton(buttonIndex); |
|
|
|
bool newButtonValue = _getButton(buttonIndex); |
|
|
@ -261,14 +258,14 @@ void Joystick::run(void) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_calibrationMode != CalibrationModeCalibrating) { |
|
|
|
if (_calibrationMode != CalibrationModeCalibrating) { |
|
|
|
int axis = _rgFunctionAxis[rollFunction]; |
|
|
|
int axis = _rgFunctionAxis[rollFunction]; |
|
|
|
float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
|
|
|
|
|
|
|
|
axis = _rgFunctionAxis[pitchFunction]; |
|
|
|
axis = _rgFunctionAxis[pitchFunction]; |
|
|
|
float pitch = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
float pitch = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
|
|
|
|
|
|
|
|
axis = _rgFunctionAxis[yawFunction]; |
|
|
|
axis = _rgFunctionAxis[yawFunction]; |
|
|
|
float yaw = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
float yaw = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); |
|
|
|
|
|
|
|
|
|
|
@ -285,28 +282,28 @@ void Joystick::run(void) |
|
|
|
pitch = std::max(-1.0f, std::min(tanf(asinf(pitch_limited)), 1.0f)); |
|
|
|
pitch = std::max(-1.0f, std::min(tanf(asinf(pitch_limited)), 1.0f)); |
|
|
|
yaw = std::max(-1.0f, std::min(tanf(asinf(yaw_limited)), 1.0f)); |
|
|
|
yaw = std::max(-1.0f, std::min(tanf(asinf(yaw_limited)), 1.0f)); |
|
|
|
throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); |
|
|
|
throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); |
|
|
|
|
|
|
|
|
|
|
|
// Adjust throttle to 0:1 range
|
|
|
|
// Adjust throttle to 0:1 range
|
|
|
|
if (_throttleMode == ThrottleModeCenterZero) { |
|
|
|
if (_throttleMode == ThrottleModeCenterZero) { |
|
|
|
throttle = std::max(0.0f, throttle); |
|
|
|
throttle = std::max(0.0f, throttle); |
|
|
|
} else {
|
|
|
|
} else { |
|
|
|
throttle = (throttle + 1.0f) / 2.0f; |
|
|
|
throttle = (throttle + 1.0f) / 2.0f; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set up button pressed information
|
|
|
|
// Set up button pressed information
|
|
|
|
|
|
|
|
|
|
|
|
// We only send the buttons the firmwware has reserved
|
|
|
|
// We only send the buttons the firmwware has reserved
|
|
|
|
int reservedButtonCount = _activeVehicle->manualControlReservedButtonCount(); |
|
|
|
int reservedButtonCount = _activeVehicle->manualControlReservedButtonCount(); |
|
|
|
if (reservedButtonCount == -1) { |
|
|
|
if (reservedButtonCount == -1) { |
|
|
|
reservedButtonCount = _totalButtonCount; |
|
|
|
reservedButtonCount = _totalButtonCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
quint16 newButtonBits = 0; // New set of button which are down
|
|
|
|
quint16 newButtonBits = 0; // New set of button which are down
|
|
|
|
quint16 buttonPressedBits = 0; // Buttons pressed for manualControl signal
|
|
|
|
quint16 buttonPressedBits = 0; // Buttons pressed for manualControl signal
|
|
|
|
|
|
|
|
|
|
|
|
for (int buttonIndex=0; buttonIndex<_totalButtonCount; buttonIndex++) { |
|
|
|
for (int buttonIndex=0; buttonIndex<_totalButtonCount; buttonIndex++) { |
|
|
|
quint16 buttonBit = 1 << buttonIndex; |
|
|
|
quint16 buttonBit = 1 << buttonIndex; |
|
|
|
|
|
|
|
|
|
|
|
if (!_rgButtonValues[buttonIndex]) { |
|
|
|
if (!_rgButtonValues[buttonIndex]) { |
|
|
|
// Button up, just record it
|
|
|
|
// Button up, just record it
|
|
|
|
newButtonBits |= buttonBit; |
|
|
|
newButtonBits |= buttonBit; |
|
|
@ -314,7 +311,7 @@ void Joystick::run(void) |
|
|
|
if (_lastButtonBits & buttonBit) { |
|
|
|
if (_lastButtonBits & buttonBit) { |
|
|
|
// Button was up last time through, but is now down which indicates a button press
|
|
|
|
// Button was up last time through, but is now down which indicates a button press
|
|
|
|
qCDebug(JoystickLog) << "button triggered" << buttonIndex; |
|
|
|
qCDebug(JoystickLog) << "button triggered" << buttonIndex; |
|
|
|
|
|
|
|
|
|
|
|
if (buttonIndex >= reservedButtonCount) { |
|
|
|
if (buttonIndex >= reservedButtonCount) { |
|
|
|
// Button is above firmware reserved set
|
|
|
|
// Button is above firmware reserved set
|
|
|
|
QString buttonAction =_rgButtonActions[buttonIndex]; |
|
|
|
QString buttonAction =_rgButtonActions[buttonIndex]; |
|
|
@ -328,18 +325,18 @@ void Joystick::run(void) |
|
|
|
buttonPressedBits |= buttonBit; |
|
|
|
buttonPressedBits |= buttonBit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_lastButtonBits = newButtonBits; |
|
|
|
_lastButtonBits = newButtonBits; |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickValuesLog) << "name:roll:pitch:yaw:throttle" << name() << roll << -pitch << yaw << throttle; |
|
|
|
qCDebug(JoystickValuesLog) << "name:roll:pitch:yaw:throttle" << name() << roll << -pitch << yaw << throttle; |
|
|
|
|
|
|
|
|
|
|
|
emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode()); |
|
|
|
emit manualControl(roll, -pitch, yaw, throttle, buttonPressedBits, _activeVehicle->joystickMode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sleep, update rate of joystick is approx. 25 Hz (1000 ms / 25 = 40 ms)
|
|
|
|
// Sleep, update rate of joystick is approx. 25 Hz (1000 ms / 25 = 40 ms)
|
|
|
|
QGC::SLEEP::msleep(40); |
|
|
|
QGC::SLEEP::msleep(40); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_close(); |
|
|
|
_close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -385,7 +382,7 @@ void Joystick::stopPolling(void) |
|
|
|
} |
|
|
|
} |
|
|
|
// FIXME: ****
|
|
|
|
// FIXME: ****
|
|
|
|
//disconnect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
|
|
|
|
//disconnect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
|
|
|
|
|
|
|
|
|
|
|
|
_exitThread = true; |
|
|
|
_exitThread = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -396,7 +393,7 @@ void Joystick::setCalibration(int axis, Calibration_t& calibration) |
|
|
|
qCWarning(JoystickLog) << "Invalid axis index" << axis; |
|
|
|
qCWarning(JoystickLog) << "Invalid axis index" << axis; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_calibrated = true; |
|
|
|
_calibrated = true; |
|
|
|
_rgCalibration[axis] = calibration; |
|
|
|
_rgCalibration[axis] = calibration; |
|
|
|
_saveSettings(); |
|
|
|
_saveSettings(); |
|
|
@ -408,7 +405,7 @@ Joystick::Calibration_t Joystick::getCalibration(int axis) |
|
|
|
if (!_validAxis(axis)) { |
|
|
|
if (!_validAxis(axis)) { |
|
|
|
qCWarning(JoystickLog) << "Invalid axis index" << axis; |
|
|
|
qCWarning(JoystickLog) << "Invalid axis index" << axis; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return _rgCalibration[axis]; |
|
|
|
return _rgCalibration[axis]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -443,7 +440,7 @@ QStringList Joystick::actions(void) |
|
|
|
if (_activeVehicle) { |
|
|
|
if (_activeVehicle) { |
|
|
|
list << _activeVehicle->flightModes(); |
|
|
|
list << _activeVehicle->flightModes(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -453,9 +450,9 @@ void Joystick::setButtonAction(int button, const QString& action) |
|
|
|
qCWarning(JoystickLog) << "Invalid button index" << button; |
|
|
|
qCWarning(JoystickLog) << "Invalid button index" << button; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "setButtonAction" << action; |
|
|
|
qDebug() << "setButtonAction" << action; |
|
|
|
|
|
|
|
|
|
|
|
_rgButtonActions[button] = action; |
|
|
|
_rgButtonActions[button] = action; |
|
|
|
_saveSettings(); |
|
|
|
_saveSettings(); |
|
|
|
emit buttonActionsChanged(buttonActions()); |
|
|
|
emit buttonActionsChanged(buttonActions()); |
|
|
@ -466,18 +463,18 @@ QString Joystick::getButtonAction(int button) |
|
|
|
if (!_validButton(button)) { |
|
|
|
if (!_validButton(button)) { |
|
|
|
qCWarning(JoystickLog) << "Invalid button index" << button; |
|
|
|
qCWarning(JoystickLog) << "Invalid button index" << button; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return _rgButtonActions[button]; |
|
|
|
return _rgButtonActions[button]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QVariantList Joystick::buttonActions(void) |
|
|
|
QVariantList Joystick::buttonActions(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QVariantList list; |
|
|
|
QVariantList list; |
|
|
|
|
|
|
|
|
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
for (int button=0; button<_buttonCount; button++) { |
|
|
|
list += QVariant::fromValue(_rgButtonActions[button]); |
|
|
|
list += QVariant::fromValue(_rgButtonActions[button]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -492,7 +489,7 @@ void Joystick::setThrottleMode(int mode) |
|
|
|
qCWarning(JoystickLog) << "Invalid throttle mode" << mode; |
|
|
|
qCWarning(JoystickLog) << "Invalid throttle mode" << mode; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_throttleMode = (ThrottleMode_t)mode; |
|
|
|
_throttleMode = (ThrottleMode_t)mode; |
|
|
|
_saveSettings(); |
|
|
|
_saveSettings(); |
|
|
|
emit throttleModeChanged(_throttleMode); |
|
|
|
emit throttleModeChanged(_throttleMode); |
|
|
@ -504,9 +501,9 @@ void Joystick::startCalibrationMode(CalibrationMode_t mode) |
|
|
|
qWarning() << "Incorrect mode CalibrationModeOff"; |
|
|
|
qWarning() << "Incorrect mode CalibrationModeOff"; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_calibrationMode = mode; |
|
|
|
_calibrationMode = mode; |
|
|
|
|
|
|
|
|
|
|
|
if (!isRunning()) { |
|
|
|
if (!isRunning()) { |
|
|
|
_pollingStartedForCalibration = true; |
|
|
|
_pollingStartedForCalibration = true; |
|
|
|
startPolling(_multiVehicleManager->activeVehicle()); |
|
|
|
startPolling(_multiVehicleManager->activeVehicle()); |
|
|
@ -519,7 +516,7 @@ void Joystick::stopCalibrationMode(CalibrationMode_t mode) |
|
|
|
qWarning() << "Incorrect mode: CalibrationModeOff"; |
|
|
|
qWarning() << "Incorrect mode: CalibrationModeOff"; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (mode == CalibrationModeCalibrating) { |
|
|
|
if (mode == CalibrationModeCalibrating) { |
|
|
|
_calibrationMode = CalibrationModeMonitor; |
|
|
|
_calibrationMode = CalibrationModeMonitor; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|