Skip to content

Commit

Permalink
feat: add SBUS 24 support
Browse files Browse the repository at this point in the history
  • Loading branch information
3djc committed Sep 25, 2023
1 parent 78a09de commit 1d6703a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
15 changes: 15 additions & 0 deletions radio/src/gui/colorlcd/access_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,21 @@ void RxOptions::update()
});
}

if (capabilities & (1 << RECEIVER_CAPABILITY_SBUS24)) {
line = form->newLine(&grid);
new StaticText(line, rect_t{}, "SBUS24");
new ToggleSwitch(
line, rect_t{},
[]() {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
return hwSettings.receiverSettings.sbus24;
},
[](int val) {
auto& hwSettings = getPXX2HardwareAndSettingsBuffer();
hwSettings.receiverSettings.sbus24 = val;
});
}

auto outputsCount = min<uint8_t>(16, hwSettings.receiverSettings.outputsCount);
for (uint8_t i = 0; i < outputsCount; i++) {
line = form->newLine(&grid);
Expand Down
23 changes: 16 additions & 7 deletions radio/src/gui/common/stdlcd/model_receiver_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum {
ITEM_RECEIVER_SETTINGS_TELEMETRY,
ITEM_RECEIVER_SETTINGS_TELEMETRY_25MW,
ITEM_RECEIVER_SETTINGS_SPORT_MODE,
ITEM_RECEIVER_SETTINGS_SBUS24,
ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1,
ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2,
ITEM_RECEIVER_SETTINGS_PINMAP_FIRST
Expand Down Expand Up @@ -88,13 +89,14 @@ void menuModelReceiverOptions(event_t event)
uint8_t receiverVariant = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.variant;

SUBMENU_NOTITLE(ITEM_RECEIVER_SETTINGS_PINMAP_FIRST + outputsCount, {
0, // PWM rate
isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && reusableBuffer.hardwareAndSettings.moduleSettings.txPower > 14 /*25mW*/ ? READONLY_ROW : (uint8_t)0, // Telemetry
IF_RECEIVER_CAPABILITY(RECEIVER_CAPABILITY_TELEMETRY_25MW, 0),
uint8_t((IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_FPORT) || IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_FPORT2)) ? 0 : HIDDEN_ROW),
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW),
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW),
0 // channels ...
0, // ITEM_RECEIVER_SETTINGS_PWM_RATE
isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && reusableBuffer.hardwareAndSettings.moduleSettings.txPower > 14 /*25mW*/ ? READONLY_ROW : (uint8_t)0, // ITEM_RECEIVER_SETTINGS_TELEMETRY
IF_RECEIVER_CAPABILITY(RECEIVER_CAPABILITY_TELEMETRY_25MW, 0), // ITEM_RECEIVER_SETTINGS_TELEMETRY_25MW
uint8_t((IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_FPORT) || IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_FPORT2)) ? 0 : HIDDEN_ROW), // ITEM_RECEIVER_SETTINGS_SPORT_MODE
uint8_t(IS_RECEIVER_CAPABILITY_ENABLED(RECEIVER_CAPABILITY_SBUS24) ? 0 : HIDDEN_ROW), // ITEM_RECEIVER_SETTINGS_SBUS24
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), // ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW), // ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2
0 // ITEM_RECEIVER_SETTINGS_PINMAP_FIRST ...
});

if (menuEvent) {
Expand Down Expand Up @@ -188,6 +190,13 @@ void menuModelReceiverOptions(event_t event)
break;
}

case ITEM_RECEIVER_SETTINGS_SBUS24:
reusableBuffer.hardwareAndSettings.receiverSettings.sbus24 = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.sbus24, RECEIVER_OPTIONS_2ND_COLUMN, y, "SBUS24", attr, event);
if (attr && checkIncDec_Ret) {
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY;
}
break;

case ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1:
lcdDrawText(LCD_W/2, y+1, STR_MORE_OPTIONS_AVAILABLE, SMLSIZE|CENTERED);
break;
Expand Down
2 changes: 2 additions & 0 deletions radio/src/pulses/pxx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ void Pxx2Pulses::setupReceiverSettingsFrame(uint8_t module, int16_t* channels, u
flag1 |= PXX2_RX_SETTINGS_FLAG1_ENABLE_PWM_CH5_CH6;
if (reusableBuffer.hardwareAndSettings.receiverSettings.fport2)
flag1 |= PXX2_RX_SETTINGS_FLAG1_FPORT2;
if (reusableBuffer.hardwareAndSettings.receiverSettings.sbus24)
flag1 |= PXX2_RX_SETTINGS_FLAG1_SBUS24;
Pxx2Transport::addByte(flag1);
uint8_t outputsCount = min<uint8_t>(24, reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount);
for (int i = 0; i < outputsCount; i++) {
Expand Down
3 changes: 3 additions & 0 deletions radio/src/pulses/pxx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#define PXX2_RX_SETTINGS_FLAG1_TELEMETRY_DISABLED (1 << 7)
#define PXX2_RX_SETTINGS_FLAG1_READONLY (1 << 6)
#define PXX2_RX_SETTINGS_FLAG1_SBUS24 (1 << 5)
#define PXX2_RX_SETTINGS_FLAG1_FASTPWM (1 << 4)
#define PXX2_RX_SETTINGS_FLAG1_FPORT (1 << 3)
#define PXX2_RX_SETTINGS_FLAG1_TELEMETRY_25MW (1 << 2)
Expand Down Expand Up @@ -124,6 +125,7 @@ enum ReceiverCapabilities {
RECEIVER_CAPABILITY_ENABLE_PWM_CH5_CH6,
RECEIVER_CAPABILITY_FPORT2,
RECEIVER_CAPABILITY_RACING_MODE,
RECEIVER_CAPABILITY_SBUS24,
RECEIVER_CAPABILITY_COUNT
};

Expand Down Expand Up @@ -236,6 +238,7 @@ class ReceiverSettings {
uint8_t fport;
uint8_t enablePwmCh5Ch6;
uint8_t fport2;
uint8_t sbus24;
uint8_t outputsCount;
uint8_t outputsMapping[24];
};
Expand Down
3 changes: 3 additions & 0 deletions radio/src/telemetry/frsky_pxx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ static void processReceiverSettingsFrame(uint8_t module, const uint8_t * frame)
if (frame[4] & PXX2_RX_SETTINGS_FLAG1_FPORT2)
destination->fport2 = 1;

if (frame[4] & PXX2_RX_SETTINGS_FLAG1_SBUS24)
destination->sbus24 = 1;

uint8_t outputsCount = min<uint8_t>(16, frame[0] - 4);
destination->outputsCount = outputsCount;
for (uint8_t pin = 0; pin < outputsCount; pin++) {
Expand Down

0 comments on commit 1d6703a

Please sign in to comment.