mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 14:25:20 +03:00
Cleaned up resource related commands in CLI.
This commit is contained in:
parent
0969cef970
commit
932ef0d22e
1 changed files with 83 additions and 35 deletions
|
@ -147,7 +147,8 @@ static void cliTasks(char *cmdline);
|
||||||
#endif
|
#endif
|
||||||
static void cliVersion(char *cmdline);
|
static void cliVersion(char *cmdline);
|
||||||
static void cliRxRange(char *cmdline);
|
static void cliRxRange(char *cmdline);
|
||||||
#if (FLASH_SIZE > 64) && !defined(CLI_MINIMAL_VERBOSITY)
|
#if (FLASH_SIZE > 64)
|
||||||
|
static void printResource(uint8_t dumpMask, master_t *defaultConfig);
|
||||||
static void cliResource(char *cmdline);
|
static void cliResource(char *cmdline);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPS
|
#ifdef GPS
|
||||||
|
@ -202,6 +203,7 @@ typedef enum {
|
||||||
DUMP_ALL = (1 << 3),
|
DUMP_ALL = (1 << 3),
|
||||||
DO_DIFF = (1 << 4),
|
DO_DIFF = (1 << 4),
|
||||||
SHOW_DEFAULTS = (1 << 5),
|
SHOW_DEFAULTS = (1 << 5),
|
||||||
|
HIDE_UNUSED = (1 << 6),
|
||||||
} dumpFlags_e;
|
} dumpFlags_e;
|
||||||
|
|
||||||
static const char* const emptyName = "-";
|
static const char* const emptyName = "-";
|
||||||
|
@ -236,7 +238,7 @@ static const rxFailsafeChannelMode_e rxFailsafeModesTable[RX_FAILSAFE_TYPE_COUNT
|
||||||
{ RX_FAILSAFE_MODE_INVALID, RX_FAILSAFE_MODE_HOLD, RX_FAILSAFE_MODE_SET }
|
{ RX_FAILSAFE_MODE_INVALID, RX_FAILSAFE_MODE_HOLD, RX_FAILSAFE_MODE_SET }
|
||||||
};
|
};
|
||||||
|
|
||||||
#if (FLASH_SIZE > 64) && !defined(CLI_MINIMAL_VERBOSITY)
|
#if (FLASH_SIZE > 64)
|
||||||
// sync this with sensors_e
|
// sync this with sensors_e
|
||||||
static const char * const sensorTypeNames[] = {
|
static const char * const sensorTypeNames[] = {
|
||||||
"GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
|
"GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
|
||||||
|
@ -330,7 +332,7 @@ const clicmd_t cmdTable[] = {
|
||||||
CLI_COMMAND_DEF("profile", "change profile",
|
CLI_COMMAND_DEF("profile", "change profile",
|
||||||
"[<index>]", cliProfile),
|
"[<index>]", cliProfile),
|
||||||
CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
|
CLI_COMMAND_DEF("rateprofile", "change rate profile", "[<index>]", cliRateProfile),
|
||||||
#if (FLASH_SIZE > 64) && !defined(CLI_MINIMAL_VERBOSITY)
|
#if (FLASH_SIZE > 64)
|
||||||
CLI_COMMAND_DEF("resource", "view currently used resources", NULL, cliResource),
|
CLI_COMMAND_DEF("resource", "view currently used resources", NULL, cliResource),
|
||||||
#endif
|
#endif
|
||||||
CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange),
|
CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange),
|
||||||
|
@ -2738,6 +2740,11 @@ static void printConfig(char *cmdline, bool doDiff)
|
||||||
#endif
|
#endif
|
||||||
printName(dumpMask);
|
printName(dumpMask);
|
||||||
|
|
||||||
|
#ifndef CLI_MINIMAL_VERBOSITY
|
||||||
|
cliPrint("\r\n# resources\r\n");
|
||||||
|
#endif
|
||||||
|
printResource(dumpMask, &defaultConfig);
|
||||||
|
|
||||||
#ifndef USE_QUAD_MIXER_ONLY
|
#ifndef USE_QUAD_MIXER_ONLY
|
||||||
#ifndef CLI_MINIMAL_VERBOSITY
|
#ifndef CLI_MINIMAL_VERBOSITY
|
||||||
cliPrint("\r\n# mixer\r\n");
|
cliPrint("\r\n# mixer\r\n");
|
||||||
|
@ -3720,7 +3727,7 @@ void cliProcess(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (FLASH_SIZE > 64) && !defined(CLI_MINIMAL_VERBOSITY)
|
#if (FLASH_SIZE > 64)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const uint8_t owner;
|
const uint8_t owner;
|
||||||
|
@ -3746,13 +3753,72 @@ const cliResourceValue_t resourceTable[] = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void printResource(uint8_t dumpMask, master_t *defaultConfig)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < ARRAYLEN(resourceTable); i++) {
|
||||||
|
const char* owner;
|
||||||
|
owner = ownerNames[resourceTable[i].owner];
|
||||||
|
|
||||||
|
if (resourceTable[i].maxIndex > 0) {
|
||||||
|
for (int index = 0; index < resourceTable[i].maxIndex; index++) {
|
||||||
|
ioTag_t ioPtr = *(resourceTable[i].ptr + index);
|
||||||
|
ioTag_t ioPtrDefault = *(resourceTable[i].ptr + index - (uint32_t)&masterConfig + (uint32_t)defaultConfig);
|
||||||
|
|
||||||
|
IO_t io = IOGetByTag(ioPtr);
|
||||||
|
IO_t ioDefault = IOGetByTag(ioPtrDefault);
|
||||||
|
bool equalsDefault = io == ioDefault;
|
||||||
|
const char *format = "resource %s %d %c%02d\r\n";
|
||||||
|
const char *formatUnassigned = "resource %s %d NONE\r\n";
|
||||||
|
if (DEFIO_TAG_ISEMPTY(ioDefault)) {
|
||||||
|
cliDefaultPrintf(dumpMask, equalsDefault, formatUnassigned, owner, RESOURCE_INDEX(index));
|
||||||
|
} else {
|
||||||
|
cliDefaultPrintf(dumpMask, equalsDefault, format, owner, RESOURCE_INDEX(index), IO_GPIOPortIdx(ioDefault) + 'A', IO_GPIOPinIdx(ioDefault));
|
||||||
|
}
|
||||||
|
if (DEFIO_TAG_ISEMPTY(io)) {
|
||||||
|
if (!(dumpMask & HIDE_UNUSED)) {
|
||||||
|
cliDumpPrintf(dumpMask, equalsDefault, formatUnassigned, owner, RESOURCE_INDEX(index));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cliDumpPrintf(dumpMask, equalsDefault, format, owner, RESOURCE_INDEX(index), IO_GPIOPortIdx(io) + 'A', IO_GPIOPinIdx(io));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ioTag_t ioPtr = *resourceTable[i].ptr;
|
||||||
|
ioTag_t ioPtrDefault = *(resourceTable[i].ptr - (uint32_t)&masterConfig + (uint32_t)defaultConfig);
|
||||||
|
|
||||||
|
IO_t io = IOGetByTag(ioPtr);
|
||||||
|
IO_t ioDefault = IOGetByTag(ioPtrDefault);
|
||||||
|
bool equalsDefault = io == ioDefault;
|
||||||
|
const char *format = "resource %s %c%02d\r\n";
|
||||||
|
const char *formatUnassigned = "resource %s NONE\r\n";
|
||||||
|
if (DEFIO_TAG_ISEMPTY(ioDefault)) {
|
||||||
|
cliDefaultPrintf(dumpMask, equalsDefault, formatUnassigned, owner);
|
||||||
|
} else {
|
||||||
|
cliDefaultPrintf(dumpMask, equalsDefault, format, owner, IO_GPIOPortIdx(ioDefault) + 'A', IO_GPIOPinIdx(ioDefault));
|
||||||
|
}
|
||||||
|
if (DEFIO_TAG_ISEMPTY(io)) {
|
||||||
|
if (!(dumpMask & HIDE_UNUSED)) {
|
||||||
|
cliDumpPrintf(dumpMask, equalsDefault, formatUnassigned, owner);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cliDumpPrintf(dumpMask, equalsDefault, format, owner, IO_GPIOPortIdx(io) + 'A', IO_GPIOPinIdx(io));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void cliResource(char *cmdline)
|
static void cliResource(char *cmdline)
|
||||||
{
|
{
|
||||||
int len;
|
int len = strlen(cmdline);
|
||||||
len = strlen(cmdline);
|
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
cliPrintf("IO:\r\n----------------------\r\n");
|
printResource(DUMP_MASTER | HIDE_UNUSED, NULL);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (strncasecmp(cmdline, "list", len) == 0) {
|
||||||
|
#ifndef CLI_MINIMAL_VERBOSITY
|
||||||
|
cliPrintf("Currently active IO resource assignments:\r\n(reboot to update)\r\n----------------------\r\n");
|
||||||
|
#endif
|
||||||
for (uint32_t i = 0; i < DEFIO_IO_USED_COUNT; i++) {
|
for (uint32_t i = 0; i < DEFIO_IO_USED_COUNT; i++) {
|
||||||
const char* owner;
|
const char* owner;
|
||||||
owner = ownerNames[ioRecs[i].owner];
|
owner = ownerNames[ioRecs[i].owner];
|
||||||
|
@ -3766,34 +3832,10 @@ static void cliResource(char *cmdline)
|
||||||
cliPrintf("%c%02d: %s %s\r\n", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner, resource);
|
cliPrintf("%c%02d: %s %s\r\n", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner, resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cliPrintf("\r\nUse: 'resource list' to see how to change resources.\r\n");
|
#ifndef CLI_MINIMAL_VERBOSITY
|
||||||
return;
|
cliPrintf("\r\nUse: 'resource' to see how to change resources.\r\n");
|
||||||
} else if (strncasecmp(cmdline, "list", len) == 0) {
|
#endif
|
||||||
for (uint8_t i = 0; i < ARRAYLEN(resourceTable); i++) {
|
|
||||||
const char* owner;
|
|
||||||
owner = ownerNames[resourceTable[i].owner];
|
|
||||||
|
|
||||||
if (resourceTable[i].maxIndex > 0) {
|
|
||||||
for (int index = 0; index < resourceTable[i].maxIndex; index++) {
|
|
||||||
|
|
||||||
if (DEFIO_TAG_ISEMPTY(*(resourceTable[i].ptr + index))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
IO_t io = IOGetByTag(*(resourceTable[i].ptr + index));
|
|
||||||
if (!io) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cliPrintf("resource %s %d %c%02d\r\n", owner, RESOURCE_INDEX(index), IO_GPIOPortIdx(io) + 'A', IO_GPIOPinIdx(io));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (DEFIO_TAG_ISEMPTY(*(resourceTable[i].ptr))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
IO_t io = IOGetByTag(*resourceTable[i].ptr);
|
|
||||||
cliPrintf("resource %s %c%02d\r\n", owner, IO_GPIOPortIdx(io) + 'A', IO_GPIOPinIdx(io));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3834,7 +3876,11 @@ static void cliResource(char *cmdline)
|
||||||
cliPrintf("Resource is freed!");
|
cliPrintf("Resource is freed!");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
uint8_t port = (*pch)-'A';
|
uint8_t port = (*pch) - 'A';
|
||||||
|
if (port >= 8) {
|
||||||
|
port = (*pch) - 'a';
|
||||||
|
}
|
||||||
|
|
||||||
if (port < 8) {
|
if (port < 8) {
|
||||||
pch++;
|
pch++;
|
||||||
pin = atoi(pch);
|
pin = atoi(pch);
|
||||||
|
@ -3859,7 +3905,9 @@ static void cliResource(char *cmdline)
|
||||||
void cliDfu(char *cmdLine)
|
void cliDfu(char *cmdLine)
|
||||||
{
|
{
|
||||||
UNUSED(cmdLine);
|
UNUSED(cmdLine);
|
||||||
|
#ifndef CLI_MINIMAL_VERBOSITY
|
||||||
cliPrint("\r\nRestarting in DFU mode");
|
cliPrint("\r\nRestarting in DFU mode");
|
||||||
|
#endif
|
||||||
cliRebootEx(true);
|
cliRebootEx(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue