mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
trashed old eeprom config struct and retarded eeprom code. replaced with config_t stuff to allow more dynamic changes
implemented cli (press # in serial to enter it). no commands except exit/version yet. added uartPrint fixed bug in task switching with missing breaks - was failing baro and perhaps mag readings dynamic yaw direction, camtilt feature, camtrig feature. ported some of 2.0-pre1 features: * gyro smoothing * baro/althold cleanup git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@102 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
14e12ce0bf
commit
9b48d45bca
14 changed files with 680 additions and 536 deletions
117
cli.c
Normal file
117
cli.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
#include "board.h"
|
||||
#include "mw.h"
|
||||
|
||||
// we unset this on 'exit'
|
||||
extern uint8_t cliMode;
|
||||
static void cliExit(char *cmdline);
|
||||
static void cliHelp(char *cmdline);
|
||||
static void cliVersion(char *cmdline);
|
||||
|
||||
// buffer
|
||||
char cliBuffer[32];
|
||||
uint8_t bufferIndex = 0;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *param;
|
||||
void (*func)(char *cmdline);
|
||||
} cliCmd;
|
||||
|
||||
// should be sorted a..z for bsearch()
|
||||
const cliCmd cmdTable[] = {
|
||||
{ "exit", "", cliExit },
|
||||
{ "help", "", cliHelp },
|
||||
{ "version", "", cliVersion },
|
||||
};
|
||||
#define CMD_COUNT (sizeof cmdTable / sizeof cmdTable[0])
|
||||
|
||||
static void cliPrompt(void)
|
||||
{
|
||||
uartPrint("\r\n# ");
|
||||
memset(cliBuffer, 0, sizeof(cliBuffer));
|
||||
bufferIndex = 0;
|
||||
}
|
||||
|
||||
static int cliCompare(const void *a, const void *b)
|
||||
{
|
||||
const cliCmd *ca = a, *cb = b;
|
||||
return strncasecmp(ca->name, cb->name, strlen(cb->name));
|
||||
}
|
||||
|
||||
static void cliExit(char *cmdline)
|
||||
{
|
||||
uartPrint("Leaving CLI mode...\r\n");
|
||||
memset(cliBuffer, 0, sizeof(cliBuffer));
|
||||
bufferIndex = 0;
|
||||
cliMode = 0;
|
||||
}
|
||||
|
||||
static void cliHelp(char *cmdline)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
uartPrint("Available commands:\r\n");
|
||||
|
||||
for (i = 0; i < CMD_COUNT; i++) {
|
||||
uartPrint((uint8_t *)cmdTable[i].name);
|
||||
uartWrite(' ');
|
||||
uartPrint((uint8_t *)cmdTable[i].param);
|
||||
uartPrint("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void cliVersion(char *cmdline)
|
||||
{
|
||||
uartPrint("Afro32 CLI version 2.0-pre1");
|
||||
}
|
||||
|
||||
void cliProcess(void)
|
||||
{
|
||||
while (uartAvailable()) {
|
||||
uint8_t c = uartRead();
|
||||
|
||||
cliBuffer[bufferIndex++] = c;
|
||||
if (bufferIndex == sizeof(cliBuffer)) {
|
||||
bufferIndex--;
|
||||
c = '\n';
|
||||
}
|
||||
|
||||
if (bufferIndex && (c == '\n' || c == '\r')) {
|
||||
// enter pressed
|
||||
cliCmd *cmd = NULL;
|
||||
cliCmd target;
|
||||
uartPrint("\r\n");
|
||||
cliBuffer[bufferIndex] = 0; // null terminate
|
||||
|
||||
target.name = cliBuffer;
|
||||
target.param = NULL;
|
||||
|
||||
cmd = bsearch(&target, cmdTable, CMD_COUNT, sizeof cmdTable[0], cliCompare);
|
||||
if (cmd)
|
||||
cmd->func(cliBuffer + strlen(cmd->name));
|
||||
else
|
||||
uartPrint("ERR: Unknown command, try 'HELP'");
|
||||
|
||||
// 'exit' will reset this flag, so we don't need to print prompt again
|
||||
if (cliMode)
|
||||
cliPrompt();
|
||||
|
||||
} else if (c == 127) {
|
||||
// backspace
|
||||
if (bufferIndex > 1) {
|
||||
cliBuffer[bufferIndex - 2] = 0;
|
||||
uartPrint("\r# ");
|
||||
uartPrint((uint8_t *)cliBuffer);
|
||||
uartWrite(' ');
|
||||
uartPrint("\r# ");
|
||||
uartPrint((uint8_t *)cliBuffer);
|
||||
bufferIndex -= 2;
|
||||
}
|
||||
} else if (c < 32 || c > 126) {
|
||||
// non-printable ascii
|
||||
bufferIndex--;
|
||||
} else {
|
||||
uartWrite(c);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue