mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
Merge c78b07f78a
into acbab53d13
This commit is contained in:
commit
3709594405
3 changed files with 47 additions and 9 deletions
|
@ -3505,13 +3505,21 @@ static void printMap(dumpFlags_t dumpMask, const rxConfig_t *rxConfig, const rxC
|
|||
char buf[16];
|
||||
char bufDefault[16];
|
||||
uint32_t i;
|
||||
uint8_t rcMapIdx;
|
||||
uint8_t defaultRcMapIdx;
|
||||
|
||||
headingStr = cliPrintSectionHeading(dumpMask, false, headingStr);
|
||||
for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) {
|
||||
buf[rxConfig->rcmap[i]] = rcChannelLetters[i];
|
||||
rcMapIdx = rxConfig->rcmap[i];
|
||||
if (rcMapIdx != RCMAP_UNMAPPED_INDEX) {
|
||||
buf[rcMapIdx] = rcChannelLetters[i];
|
||||
}
|
||||
if (defaultRxConfig) {
|
||||
bufDefault[defaultRxConfig->rcmap[i]] = rcChannelLetters[i];
|
||||
equalsDefault = equalsDefault && (rxConfig->rcmap[i] == defaultRxConfig->rcmap[i]);
|
||||
defaultRcMapIdx = defaultRxConfig->rcmap[i];
|
||||
if (defaultRcMapIdx != RCMAP_UNMAPPED_INDEX) {
|
||||
bufDefault[defaultRcMapIdx] = rcChannelLetters[i];
|
||||
}
|
||||
equalsDefault = equalsDefault && (defaultRcMapIdx == rcMapIdx);
|
||||
}
|
||||
}
|
||||
buf[i] = '\0';
|
||||
|
@ -3528,18 +3536,24 @@ static void printMap(dumpFlags_t dumpMask, const rxConfig_t *rxConfig, const rxC
|
|||
static void cliMap(const char *cmdName, char *cmdline)
|
||||
{
|
||||
uint32_t i;
|
||||
uint8_t mapIdx;
|
||||
// Working buffer (+1 for the null terminator). Re-used later when we render the map back to the user. */
|
||||
char buf[RX_MAPPABLE_CHANNEL_COUNT + 1];
|
||||
|
||||
uint32_t len = strlen(cmdline);
|
||||
if (len == RX_MAPPABLE_CHANNEL_COUNT) {
|
||||
if (len <= RX_MAPPABLE_CHANNEL_COUNT && len >= NON_AUX_CHANNEL_COUNT) {
|
||||
|
||||
for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) {
|
||||
buf[i] = toupper((unsigned char)cmdline[i]);
|
||||
if (i < len) {
|
||||
buf[i] = toupper((unsigned char) cmdline[i]);
|
||||
} else {
|
||||
buf[i] = (unsigned char) RCMAP_UNMAPPED_INDEX;
|
||||
}
|
||||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) {
|
||||
buf[i] = toupper((unsigned char)cmdline[i]);
|
||||
for (i = 0; i < len; i++) {
|
||||
buf[i] = toupper((unsigned char) cmdline[i]);
|
||||
|
||||
if (strchr(rcChannelLetters, buf[i]) && !strchr(buf + i + 1, buf[i]))
|
||||
continue;
|
||||
|
@ -3553,8 +3567,19 @@ static void cliMap(const char *cmdName, char *cmdline)
|
|||
return;
|
||||
}
|
||||
|
||||
// Reset buffer, so we can rebuild it from rcmap[]
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
// Translate the numerical rcmap[] back into channel letters. Skip unmapped or invalid indices for robustness
|
||||
for (i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) {
|
||||
buf[rxConfig()->rcmap[i]] = rcChannelLetters[i];
|
||||
mapIdx = rxConfig()->rcmap[i];
|
||||
if (mapIdx == RCMAP_UNMAPPED_INDEX) {
|
||||
continue; // Skip unmapped indices
|
||||
}
|
||||
if (mapIdx >= RX_MAPPABLE_CHANNEL_COUNT) {
|
||||
continue; // Skip invalid indices
|
||||
}
|
||||
buf[mapIdx] = rcChannelLetters[i];
|
||||
}
|
||||
|
||||
buf[i] = '\0';
|
||||
|
|
|
@ -658,6 +658,7 @@ STATIC_UNIT_TESTED float applyRxChannelRangeConfiguraton(float sample, const rxC
|
|||
|
||||
static void readRxChannelsApplyRanges(void)
|
||||
{
|
||||
uint8_t unmappedCount = 0;
|
||||
for (int channel = 0; channel < rxChannelCount; channel++) {
|
||||
|
||||
const uint8_t rawChannel = channel < RX_MAPPABLE_CHANNEL_COUNT ? rxConfig()->rcmap[channel] : channel;
|
||||
|
@ -670,7 +671,14 @@ static void readRxChannelsApplyRanges(void)
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
sample = rxRuntimeState.rcReadRawFn(&rxRuntimeState, rawChannel);
|
||||
if (rawChannel == RCMAP_UNMAPPED_INDEX) {
|
||||
sample = rxConfig()->midrc;
|
||||
unmappedCount++;
|
||||
} else {
|
||||
sample = rxRuntimeState.rcReadRawFn(&rxRuntimeState, channel < RX_MAPPABLE_CHANNEL_COUNT
|
||||
? rawChannel
|
||||
: rawChannel - unmappedCount);
|
||||
}
|
||||
}
|
||||
|
||||
// apply the rx calibration
|
||||
|
@ -800,6 +808,10 @@ bool calculateRxChannelsAndUpdateFailsafe(timeUs_t currentTimeUs)
|
|||
|
||||
void parseRcChannels(const char *input, rxConfig_t *rxConfig)
|
||||
{
|
||||
// Initialize all rc map values to 255 (indicating unmapped)
|
||||
for (unsigned i = 0; i < RX_MAPPABLE_CHANNEL_COUNT; i++) {
|
||||
rxConfig->rcmap[i] = RCMAP_UNMAPPED_INDEX;
|
||||
}
|
||||
for (const char *c = input; *c; c++) {
|
||||
const char *s = strchr(rcChannelLetters, *c);
|
||||
if (s && (s < rcChannelLetters + RX_MAPPABLE_CHANNEL_COUNT)) {
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
// Extracted from rx/rx.c and rx/rx.h
|
||||
|
||||
#define RX_MAPPABLE_CHANNEL_COUNT 8
|
||||
#define RCMAP_UNMAPPED_INDEX 255
|
||||
|
||||
#ifndef RX_SPI_DEFAULT_PROTOCOL
|
||||
#define RX_SPI_DEFAULT_PROTOCOL 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue