1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

Show errors when resetting to custom defaults.

This commit is contained in:
mikeller 2020-03-02 00:24:28 +13:00
parent 86b81baa18
commit 5f733da444
2 changed files with 60 additions and 40 deletions

View file

@ -182,6 +182,7 @@ static serialPort_t *cliPort = NULL;
#define CLI_OUT_BUFFER_SIZE 64 #define CLI_OUT_BUFFER_SIZE 64
static bufWriter_t *cliWriter = NULL; static bufWriter_t *cliWriter = NULL;
static bufWriter_t *cliErrorWriter = NULL;
static uint8_t cliWriteBuffer[sizeof(*cliWriter) + CLI_OUT_BUFFER_SIZE]; static uint8_t cliWriteBuffer[sizeof(*cliWriter) + CLI_OUT_BUFFER_SIZE];
static char cliBuffer[CLI_IN_BUFFER_SIZE]; static char cliBuffer[CLI_IN_BUFFER_SIZE];
@ -315,26 +316,31 @@ typedef struct serialPassthroughPort_s {
serialPort_t *port; serialPort_t *port;
} serialPassthroughPort_t; } serialPassthroughPort_t;
static void cliWriterFlush() static void cliWriterFlushInternal(bufWriter_t *writer)
{ {
if (cliWriter) { if (writer) {
bufWriterFlush(cliWriter); bufWriterFlush(writer);
} }
} }
void cliPrintInternal(bufWriter_t *writer, const char *str)
{
if (writer) {
while (*str) {
bufWriterAppend(writer, *str++);
}
cliWriterFlushInternal(writer);
}
}
static void cliWriterFlush()
{
cliWriterFlushInternal(cliWriter);
}
void cliPrint(const char *str) void cliPrint(const char *str)
{ {
if (!cliMode) { cliPrintInternal(cliWriter, str);
return;
}
if (cliWriter) {
while (*str) {
bufWriterAppend(cliWriter, *str++);
}
cliWriterFlush();
}
} }
void cliPrintLinefeed(void) void cliPrintLinefeed(void)
@ -410,10 +416,6 @@ static bool cliDefaultPrintLinef(dumpFlags_t dumpMask, bool equalsDefault, const
void cliPrintf(const char *format, ...) void cliPrintf(const char *format, ...)
{ {
if (!cliMode) {
return;
}
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintfva(format, va); cliPrintfva(format, va);
@ -423,10 +425,6 @@ void cliPrintf(const char *format, ...)
void cliPrintLinef(const char *format, ...) void cliPrintLinef(const char *format, ...)
{ {
if (!cliMode) {
return;
}
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintfva(format, va); cliPrintfva(format, va);
@ -436,10 +434,14 @@ void cliPrintLinef(const char *format, ...)
static void cliPrintErrorVa(const char *format, va_list va) static void cliPrintErrorVa(const char *format, va_list va)
{ {
cliPrint("###ERROR: "); if (cliErrorWriter) {
cliPrintfva(format, va); cliPrintInternal(cliErrorWriter, "###ERROR: ");
va_end(va);
cliPrint("###"); tfp_format(cliErrorWriter, cliPutp, format, va);
va_end(va);
cliPrintInternal(cliErrorWriter, "###");
}
#ifdef USE_CLI_BATCH #ifdef USE_CLI_BATCH
if (commandBatchActive) { if (commandBatchActive) {
@ -453,6 +455,13 @@ static void cliPrintError(const char *format, ...)
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintErrorVa(format, va); cliPrintErrorVa(format, va);
if (!cliWriter) {
// Supply our own linefeed in case we are printing inside a custom defaults operation
// TODO: Fix this by rewriting the entire CLI to have self contained line feeds
// instead of expecting the directly following command to supply the line feed.
cliPrintInternal(cliErrorWriter, "\r\n");
}
} }
static void cliPrintErrorLinef(const char *format, ...) static void cliPrintErrorLinef(const char *format, ...)
@ -460,7 +469,7 @@ static void cliPrintErrorLinef(const char *format, ...)
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintErrorVa(format, va); cliPrintErrorVa(format, va);
cliPrintLinefeed(); cliPrintInternal(cliErrorWriter, "\r\n");
} }
static void getMinMax(const clivalue_t *var, int *min, int *max) static void getMinMax(const clivalue_t *var, int *min, int *max)
@ -693,7 +702,7 @@ static bool isWritingConfigToCopy()
} }
#if defined(USE_CUSTOM_DEFAULTS) #if defined(USE_CUSTOM_DEFAULTS)
static bool cliProcessCustomDefaults(void); static bool cliProcessCustomDefaults(bool quiet);
#endif #endif
static void backupAndResetConfigs(const bool useCustomDefaults) static void backupAndResetConfigs(const bool useCustomDefaults)
@ -705,7 +714,7 @@ static void backupAndResetConfigs(const bool useCustomDefaults)
#if defined(USE_CUSTOM_DEFAULTS) #if defined(USE_CUSTOM_DEFAULTS)
if (useCustomDefaults) { if (useCustomDefaults) {
if (!cliProcessCustomDefaults()) { if (!cliProcessCustomDefaults(true)) {
cliPrintLine("###WARNING: NO CUSTOM DEFAULTS FOUND###"); cliPrintLine("###WARNING: NO CUSTOM DEFAULTS FOUND###");
} }
} }
@ -4201,7 +4210,7 @@ bool resetConfigToCustomDefaults(void)
commandBatchError = false; commandBatchError = false;
#endif #endif
cliProcessCustomDefaults(); cliProcessCustomDefaults(true);
return prepareSave(); return prepareSave();
} }
@ -4272,7 +4281,7 @@ static void cliDefaults(char *cmdline)
#if defined(USE_CUSTOM_DEFAULTS) #if defined(USE_CUSTOM_DEFAULTS)
if (useCustomDefaults) { if (useCustomDefaults) {
cliProcessCustomDefaults(); cliProcessCustomDefaults(false);
} }
#endif #endif
@ -6550,17 +6559,26 @@ void cliProcess(void)
} }
#if defined(USE_CUSTOM_DEFAULTS) #if defined(USE_CUSTOM_DEFAULTS)
static bool cliProcessCustomDefaults(void) static bool cliProcessCustomDefaults(bool quiet)
{ {
char *customDefaultsPtr = customDefaultsStart; char *customDefaultsPtr = customDefaultsStart;
if (processingCustomDefaults || !isCustomDefaults(customDefaultsPtr)) { if (processingCustomDefaults || !isCustomDefaults(customDefaultsPtr)) {
return false; return false;
} }
bufWriter_t *cliWriterTemp = NULL;
if (quiet
#if !defined(DEBUG_CUSTOM_DEFAULTS) #if !defined(DEBUG_CUSTOM_DEFAULTS)
bufWriter_t *cliWriterTemp = cliWriter; || true
cliWriter = NULL;
#endif #endif
) {
cliWriterTemp = cliWriter;
cliWriter = NULL;
}
if (quiet) {
cliErrorWriter = NULL;
}
memcpy(cliBufferTemp, cliBuffer, sizeof(cliBuffer)); memcpy(cliBufferTemp, cliBuffer, sizeof(cliBuffer));
uint32_t bufferIndexTemp = bufferIndex; uint32_t bufferIndexTemp = bufferIndex;
bufferIndex = 0; bufferIndex = 0;
@ -6575,9 +6593,12 @@ static bool cliProcessCustomDefaults(void)
processCharacter('\r'); processCharacter('\r');
processingCustomDefaults = false; processingCustomDefaults = false;
#if !defined(DEBUG_CUSTOM_DEFAULTS)
cliWriter = cliWriterTemp; if (cliWriterTemp) {
#endif cliWriter = cliWriterTemp;
cliErrorWriter = cliWriter;
}
memcpy(cliBuffer, cliBufferTemp, sizeof(cliBuffer)); memcpy(cliBuffer, cliBufferTemp, sizeof(cliBuffer));
bufferIndex = bufferIndexTemp; bufferIndex = bufferIndexTemp;
@ -6593,6 +6614,7 @@ void cliEnter(serialPort_t *serialPort)
cliPort = serialPort; cliPort = serialPort;
setPrintfSerialPort(cliPort); setPrintfSerialPort(cliPort);
cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufShim, serialPort); cliWriter = bufWriterInit(cliWriteBuffer, sizeof(cliWriteBuffer), (bufWrite_t)serialWriteBufShim, serialPort);
cliErrorWriter = cliWriter;
schedulerSetCalulateTaskStatistics(systemConfig()->task_statistics); schedulerSetCalulateTaskStatistics(systemConfig()->task_statistics);

View file

@ -27,6 +27,8 @@
#ifdef USE_MSP_DISPLAYPORT #ifdef USE_MSP_DISPLAYPORT
#include "cli/cli.h"
#include "common/utils.h" #include "common/utils.h"
#include "drivers/display.h" #include "drivers/display.h"
@ -39,10 +41,6 @@
static displayPort_t mspDisplayPort; static displayPort_t mspDisplayPort;
#ifdef USE_CLI
extern uint8_t cliMode;
#endif
static int output(displayPort_t *displayPort, uint8_t cmd, uint8_t *buf, int len) static int output(displayPort_t *displayPort, uint8_t cmd, uint8_t *buf, int len)
{ {
UNUSED(displayPort); UNUSED(displayPort);