Skip to content

Commit 49431b3

Browse files
committed
Mix PWM buttons into single channel
1 parent b02cd51 commit 49431b3

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/Joystick/Joystick.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ AssignedButtonAction::AssignedButtonAction(
109109
{
110110
}
111111

112-
int16_t AssignedButtonAction::calculatePwm(Vehicle *vehicle, bool buttonDown)
112+
int16_t AssignedButtonAction::calculatePwm(bool buttonDown)
113113
{
114114
if (!_isPwmOverrideAction) {
115115
qCWarning(JoystickLog) << "send called on non-pwm action";
@@ -126,10 +126,7 @@ int16_t AssignedButtonAction::calculatePwm(Vehicle *vehicle, bool buttonDown)
126126
}
127127
pwmValue = _pwmLatchButtonDown ? _hiPwmValue : _loPwmValue;
128128
}
129-
130129
qCDebug(JoystickLog) << " Calculated PWM Value " << pwmValue << " for action " << _action;
131-
//vehicle->rcChannelOverride(_pwmRcChannel, pwmValue);
132-
133130
return pwmValue;
134131
}
135132

@@ -626,12 +623,16 @@ void Joystick::_handleButtons()
626623
if(!_buttonActionArray[buttonIndex]->repeat()) {
627624
//-- This button just went down
628625
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) {
629-
// Check for a multi-button action
626+
// Check for a multi-button action except for PWM actions.
627+
// PWM buttons can produce different PWM values on same channel.
628+
// Therefore low value must be the same for all buttons at the same channel.
630629
QList<int> rgButtons = { buttonIndex };
631630
bool executeButtonAction = true;
632631
for (int multiIndex = 0; multiIndex < _totalButtonCount; multiIndex++) {
633632
if (multiIndex != buttonIndex) {
634-
if (_buttonActionArray[multiIndex] && _buttonActionArray[multiIndex]->action() == buttonAction) {
633+
if (_buttonActionArray[multiIndex] && _buttonActionArray[multiIndex]->action() == buttonAction
634+
&& !_buttonActionArray[multiIndex]->isPwmOverrideAction()) {
635+
qCDebug(JoystickLog) << "Multi-button action:" << buttonAction;
635636
// We found a multi-button action
636637
if (_rgButtonValues[multiIndex] == BUTTON_DOWN || _rgButtonValues[multiIndex] == BUTTON_REPEAT) {
637638
// So far so good
@@ -1390,7 +1391,7 @@ bool Joystick::_executeRcOverrideButtonAction(int buttonIndex, bool buttonDown)
13901391
{
13911392
if (_buttonActionArray[buttonIndex]) {
13921393
uint8_t channel = _buttonActionArray[buttonIndex]->rcChannel();
1393-
auto pwm = _buttonActionArray[buttonIndex]->calculatePwm(_activeVehicle, buttonDown);
1394+
auto pwm = _buttonActionArray[buttonIndex]->calculatePwm(buttonDown);
13941395
_rcOverride[channel-1] = pwm;
13951396
_rcOverrideActive = true;
13961397
return true;

src/Joystick/Joystick.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AssignedButtonAction : public QObject {
5151
void pwmLatchMode(bool latch) { _pwmLatchMode = latch; }
5252
bool pwmLatchMode() const { return _pwmLatchMode; }
5353
bool isPwmOverrideAction() const { return _isPwmOverrideAction; }
54-
int16_t calculatePwm(Vehicle* vehicle, bool buttonDown);
54+
int16_t calculatePwm(bool buttonDown);
5555
uint8_t rcChannel() const { return _pwmRcChannel; }
5656

5757
private:

src/Vehicle/Vehicle.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,9 +4352,11 @@ void Vehicle::rcChannelsOverride(uint16_t *override_data) {
43524352
return;
43534353
}
43544354

4355-
for (int i = 0; i < 18; i++) {
4356-
qCDebug(VehicleLog) << "Override data " << i << " is " << override_data[i];
4357-
if (override_data[i] > UINT16_MAX - 2 && override_data[i] != 0) {
4355+
if (VehicleLog().isDebugEnabled()) {
4356+
for (int i = 0; i < 18; i++) {
4357+
if (override_data[i] > 0 && override_data[i] < UINT16_MAX - 1) {
4358+
qCDebug(VehicleLog) << "RC Override ch " << i << " => " << override_data[i];
4359+
}
43584360
}
43594361
}
43604362

0 commit comments

Comments
 (0)