mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 19:40:31 +03:00
beginnings of cli editing support by cehteh; (still buggy)
added and began work on integrating failsafe_detect_threshold got rid of acc_lpf_for_velocity since that seemed no longer used. git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@317 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
3f8fc1b509
commit
b6fc652b20
8 changed files with 103 additions and 25 deletions
88
src/cli.c
88
src/cli.c
|
@ -133,7 +133,6 @@ const clivalue_t valueTable[] = {
|
|||
{ "gyro_cmpf_factor", VAR_UINT16, &mcfg.gyro_cmpf_factor, 100, 1000 },
|
||||
{ "gyro_cmpfm_factor", VAR_UINT16, &mcfg.gyro_cmpfm_factor, 100, 1000 },
|
||||
{ "gps_type", VAR_UINT8, &mcfg.gps_type, 0, 3 },
|
||||
|
||||
{ "deadband", VAR_UINT8, &cfg.deadband, 0, 32 },
|
||||
{ "yawdeadband", VAR_UINT8, &cfg.yawdeadband, 0, 100 },
|
||||
{ "alt_hold_throttle_neutral", VAR_UINT8, &cfg.alt_hold_throttle_neutral, 1, 250 },
|
||||
|
@ -146,6 +145,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "failsafe_delay", VAR_UINT8, &cfg.failsafe_delay, 0, 200 },
|
||||
{ "failsafe_off_delay", VAR_UINT8, &cfg.failsafe_off_delay, 0, 200 },
|
||||
{ "failsafe_throttle", VAR_UINT16, &cfg.failsafe_throttle, 1000, 2000 },
|
||||
{ "failsafe_detect_threshold", VAR_UINT16, &cfg.failsafe_detect_threshold, 100, 2000 },
|
||||
{ "yaw_direction", VAR_INT8, &cfg.yaw_direction, -1, 1 },
|
||||
{ "tri_yaw_middle", VAR_UINT16, &cfg.tri_yaw_middle, 0, 2000 },
|
||||
{ "tri_yaw_min", VAR_UINT16, &cfg.tri_yaw_min, 0, 2000 },
|
||||
|
@ -170,7 +170,6 @@ const clivalue_t valueTable[] = {
|
|||
{ "gimbal_roll_max", VAR_UINT16, &cfg.gimbal_roll_max, 100, 3000 },
|
||||
{ "gimbal_roll_mid", VAR_UINT16, &cfg.gimbal_roll_mid, 100, 3000 },
|
||||
{ "acc_lpf_factor", VAR_UINT8, &cfg.acc_lpf_factor, 0, 250 },
|
||||
{ "acc_lpf_for_velocity", VAR_UINT8, &cfg.acc_lpf_for_velocity, 1, 250 },
|
||||
{ "acc_trim_pitch", VAR_INT16, &cfg.angleTrim[PITCH], -300, 300 },
|
||||
{ "acc_trim_roll", VAR_INT16, &cfg.angleTrim[ROLL], -300, 300 },
|
||||
{ "baro_tab_size", VAR_UINT8, &cfg.baro_tab_size, 0, BARO_TAB_SIZE_MAX },
|
||||
|
@ -599,7 +598,7 @@ static void cliDump(char *cmdline)
|
|||
static void cliExit(char *cmdline)
|
||||
{
|
||||
uartPrint("\r\nLeaving CLI mode...\r\n");
|
||||
memset(cliBuffer, 0, sizeof(cliBuffer));
|
||||
*cliBuffer = '\0';
|
||||
bufferIndex = 0;
|
||||
cliMode = 0;
|
||||
// save and reboot... I think this makes the most sense
|
||||
|
@ -905,6 +904,35 @@ void cliProcess(void)
|
|||
|
||||
while (uartAvailable()) {
|
||||
uint8_t c = uartRead();
|
||||
|
||||
/* first step: translate "ESC[" -> "CSI" */
|
||||
if (c == '\033') {
|
||||
c = uartReadPoll();
|
||||
if (c == '[')
|
||||
c = 0x9b;
|
||||
else
|
||||
/* ignore unknown sequences */
|
||||
c = 0;
|
||||
}
|
||||
|
||||
/* second step: translate known CSI sequence into singlebyte control sequences */
|
||||
if (c == 0x9b) {
|
||||
c = uartReadPoll();
|
||||
if (c == 'A') //up
|
||||
c = 0x0b;
|
||||
else if (c == 'B') //down
|
||||
c = 0x0a;
|
||||
else if (c == 'C') //right
|
||||
c = 0x0c;
|
||||
else if (c == 'D') //left
|
||||
c = 0x08;
|
||||
else if (c == 0x33 && uartReadPoll() == 0x7e) //delete
|
||||
c = 0xff; // nonstandard, borrowing 0xff for the delete key
|
||||
else
|
||||
c = 0;
|
||||
}
|
||||
|
||||
/* from here on everything is a single byte */
|
||||
if (c == '\t' || c == '?') {
|
||||
// do tab completion
|
||||
const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
|
||||
|
@ -943,27 +971,43 @@ void cliProcess(void)
|
|||
} else if (!bufferIndex && c == 4) {
|
||||
cliExit(cliBuffer);
|
||||
return;
|
||||
} else if (c == 0x0b) {
|
||||
//uartPrint("up unimplemented");
|
||||
} else if (c == 0x0a) {
|
||||
//uartPrint("down unimplemend");
|
||||
} else if (c == 0x08) {
|
||||
if (bufferIndex > 0) {
|
||||
bufferIndex--;
|
||||
uartPrint("\033[D");
|
||||
}
|
||||
} else if (c == 12) {
|
||||
// clear screen
|
||||
uartPrint("\033[2J\033[1;1H");
|
||||
cliPrompt();
|
||||
} else if (bufferIndex && (c == '\n' || c == '\r')) {
|
||||
if (cliBuffer[bufferIndex]) {
|
||||
bufferIndex++;
|
||||
uartPrint("\033[C");
|
||||
}
|
||||
} else if (c == 0xff) {
|
||||
// delete key
|
||||
if (cliBuffer[bufferIndex]) {
|
||||
int len = strlen(cliBuffer + bufferIndex);
|
||||
memmove(cliBuffer + bufferIndex, cliBuffer + bufferIndex + 1, len + 1);
|
||||
printf("%s \033[%dD", cliBuffer + bufferIndex, len);
|
||||
}
|
||||
} else if (*cliBuffer && (c == '\n' || c == '\r')) {
|
||||
// enter pressed
|
||||
clicmd_t *cmd = NULL;
|
||||
clicmd_t 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) + 1);
|
||||
else
|
||||
uartPrint("ERR: Unknown command, try 'help'");
|
||||
|
||||
memset(cliBuffer, 0, sizeof(cliBuffer));
|
||||
*cliBuffer = '\0';
|
||||
bufferIndex = 0;
|
||||
|
||||
// 'exit' will reset this flag, so we don't need to print prompt again
|
||||
|
@ -972,15 +1016,25 @@ void cliProcess(void)
|
|||
cliPrompt();
|
||||
} else if (c == 127) {
|
||||
// backspace
|
||||
if (bufferIndex) {
|
||||
cliBuffer[--bufferIndex] = 0;
|
||||
uartPrint("\010 \010");
|
||||
if (bufferIndex && *cliBuffer) {
|
||||
int len = strlen(cliBuffer + bufferIndex);
|
||||
|
||||
--bufferIndex;
|
||||
memmove(cliBuffer + bufferIndex, cliBuffer + bufferIndex + 1, len + 1);
|
||||
printf("\033[D%s \033[%dD", cliBuffer + bufferIndex, len + 1);
|
||||
}
|
||||
} else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) {
|
||||
} else if (strlen(cliBuffer) + 1 < sizeof(cliBuffer) && c >= 32 && c <= 126) {
|
||||
int len;
|
||||
|
||||
if (!bufferIndex && c == 32)
|
||||
continue;
|
||||
cliBuffer[bufferIndex++] = c;
|
||||
uartWrite(c);
|
||||
|
||||
len = strlen(cliBuffer + bufferIndex);
|
||||
|
||||
memmove(cliBuffer + bufferIndex + 1, cliBuffer + bufferIndex, len + 1);
|
||||
cliBuffer[bufferIndex] = c;
|
||||
printf("%s \033[%dD", cliBuffer + bufferIndex, len + 1);
|
||||
++bufferIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue