1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

cli improvements by simonk

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@117 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop 2012-03-17 08:27:06 +00:00
parent 3748f2b72d
commit 2861482bb6
4 changed files with 2641 additions and 2501 deletions

View file

@ -507,8 +507,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>0</TopLine> <TopLine>120</TopLine>
<CurrentLine>0</CurrentLine> <CurrentLine>131</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\cli.c</PathWithFileName> <PathWithFileName>.\src\cli.c</PathWithFileName>
<FilenameWithoutPath>cli.c</FilenameWithoutPath> <FilenameWithoutPath>cli.c</FilenameWithoutPath>
@ -519,10 +519,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>15</ColumnNumber> <ColumnNumber>14</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>116</TopLine> <TopLine>91</TopLine>
<CurrentLine>131</CurrentLine> <CurrentLine>123</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\config.c</PathWithFileName> <PathWithFileName>.\src\config.c</PathWithFileName>
<FilenameWithoutPath>config.c</FilenameWithoutPath> <FilenameWithoutPath>config.c</FilenameWithoutPath>
@ -535,8 +535,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>320</TopLine> <TopLine>0</TopLine>
<CurrentLine>340</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\imu.c</PathWithFileName> <PathWithFileName>.\src\imu.c</PathWithFileName>
<FilenameWithoutPath>imu.c</FilenameWithoutPath> <FilenameWithoutPath>imu.c</FilenameWithoutPath>
@ -549,8 +549,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>13</ColumnNumber> <ColumnNumber>13</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>11</TopLine> <TopLine>0</TopLine>
<CurrentLine>25</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\main.c</PathWithFileName> <PathWithFileName>.\src\main.c</PathWithFileName>
<FilenameWithoutPath>main.c</FilenameWithoutPath> <FilenameWithoutPath>main.c</FilenameWithoutPath>
@ -563,8 +563,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>37</TopLine> <TopLine>0</TopLine>
<CurrentLine>68</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\mixer.c</PathWithFileName> <PathWithFileName>.\src\mixer.c</PathWithFileName>
<FilenameWithoutPath>mixer.c</FilenameWithoutPath> <FilenameWithoutPath>mixer.c</FilenameWithoutPath>
@ -575,10 +575,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>20</ColumnNumber> <ColumnNumber>9</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>359</TopLine> <TopLine>130</TopLine>
<CurrentLine>376</CurrentLine> <CurrentLine>130</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\mw.c</PathWithFileName> <PathWithFileName>.\src\mw.c</PathWithFileName>
<FilenameWithoutPath>mw.c</FilenameWithoutPath> <FilenameWithoutPath>mw.c</FilenameWithoutPath>
@ -591,8 +591,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>41</ColumnNumber> <ColumnNumber>41</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>276</TopLine> <TopLine>0</TopLine>
<CurrentLine>298</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\sensors.c</PathWithFileName> <PathWithFileName>.\src\sensors.c</PathWithFileName>
<FilenameWithoutPath>sensors.c</FilenameWithoutPath> <FilenameWithoutPath>sensors.c</FilenameWithoutPath>
@ -603,10 +603,10 @@
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>18</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>199</TopLine> <TopLine>1</TopLine>
<CurrentLine>233</CurrentLine> <CurrentLine>4</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\serial.c</PathWithFileName> <PathWithFileName>.\src\serial.c</PathWithFileName>
<FilenameWithoutPath>serial.c</FilenameWithoutPath> <FilenameWithoutPath>serial.c</FilenameWithoutPath>
@ -619,8 +619,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>20</ColumnNumber> <ColumnNumber>20</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>0</TopLine>
<CurrentLine>29</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\board.h</PathWithFileName> <PathWithFileName>.\src\board.h</PathWithFileName>
<FilenameWithoutPath>board.h</FilenameWithoutPath> <FilenameWithoutPath>board.h</FilenameWithoutPath>
@ -631,10 +631,10 @@
<FileType>5</FileType> <FileType>5</FileType>
<tvExp>0</tvExp> <tvExp>0</tvExp>
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>32</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>248</TopLine> <TopLine>70</TopLine>
<CurrentLine>262</CurrentLine> <CurrentLine>101</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\mw.h</PathWithFileName> <PathWithFileName>.\src\mw.h</PathWithFileName>
<FilenameWithoutPath>mw.h</FilenameWithoutPath> <FilenameWithoutPath>mw.h</FilenameWithoutPath>
@ -654,8 +654,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>23</ColumnNumber> <ColumnNumber>23</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>0</TopLine>
<CurrentLine>1</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\drv_adc.c</PathWithFileName> <PathWithFileName>.\src\drv_adc.c</PathWithFileName>
<FilenameWithoutPath>drv_adc.c</FilenameWithoutPath> <FilenameWithoutPath>drv_adc.c</FilenameWithoutPath>
@ -668,8 +668,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>31</ColumnNumber> <ColumnNumber>31</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>11</TopLine> <TopLine>0</TopLine>
<CurrentLine>15</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\drv_adxl345.c</PathWithFileName> <PathWithFileName>.\src\drv_adxl345.c</PathWithFileName>
<FilenameWithoutPath>drv_adxl345.c</FilenameWithoutPath> <FilenameWithoutPath>drv_adxl345.c</FilenameWithoutPath>
@ -724,8 +724,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>32</ColumnNumber> <ColumnNumber>32</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>0</TopLine>
<CurrentLine>1</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\drv_mpu3050.c</PathWithFileName> <PathWithFileName>.\src\drv_mpu3050.c</PathWithFileName>
<FilenameWithoutPath>drv_mpu3050.c</FilenameWithoutPath> <FilenameWithoutPath>drv_mpu3050.c</FilenameWithoutPath>
@ -794,8 +794,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>21</ColumnNumber> <ColumnNumber>21</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>3</TopLine> <TopLine>0</TopLine>
<CurrentLine>3</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\drv_mpu6050.c</PathWithFileName> <PathWithFileName>.\src\drv_mpu6050.c</PathWithFileName>
<FilenameWithoutPath>drv_mpu6050.c</FilenameWithoutPath> <FilenameWithoutPath>drv_mpu6050.c</FilenameWithoutPath>
@ -808,8 +808,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>1</TopLine> <TopLine>0</TopLine>
<CurrentLine>4</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\drv_mpu6050.h</PathWithFileName> <PathWithFileName>.\src\drv_mpu6050.h</PathWithFileName>
<FilenameWithoutPath>drv_mpu6050.h</FilenameWithoutPath> <FilenameWithoutPath>drv_mpu6050.h</FilenameWithoutPath>
@ -997,8 +997,8 @@
<Focus>0</Focus> <Focus>0</Focus>
<ColumnNumber>0</ColumnNumber> <ColumnNumber>0</ColumnNumber>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<TopLine>133</TopLine> <TopLine>0</TopLine>
<CurrentLine>133</CurrentLine> <CurrentLine>0</CurrentLine>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>.\src\baseflight_startups\startup_stm32f10x_md.s</PathWithFileName> <PathWithFileName>.\src\baseflight_startups\startup_stm32f10x_md.s</PathWithFileName>
<FilenameWithoutPath>startup_stm32f10x_md.s</FilenameWithoutPath> <FilenameWithoutPath>startup_stm32f10x_md.s</FilenameWithoutPath>

File diff suppressed because it is too large Load diff

163
src/cli.c
View file

@ -5,44 +5,86 @@
extern uint8_t cliMode; extern uint8_t cliMode;
static void cliExit(char *cmdline); static void cliExit(char *cmdline);
static void cliHelp(char *cmdline); static void cliHelp(char *cmdline);
static void cliMixer(char *cmdline);
static void cliRMode(char *cmdline); static void cliRMode(char *cmdline);
static void cliSet(char *cmdline);
static void cliVersion(char *cmdline); static void cliVersion(char *cmdline);
// buffer // buffer
char cliBuffer[32]; static char cliBuffer[32];
uint8_t bufferIndex = 0; static uint8_t bufferIndex = 0;
static bool unsaved = false;
const char *mixerNames[] = {
"TRI", "QUADP", "QUADX", "BI",
"GIMBAL", "Y6", "HEX6",
"FLYING_WING", "Y4", "HEX6X", "OCTOX8", "OCTOFLATP", "OCTOFLATX",
"AIRPLANE", "HELI_120_CCPM", "HELI_90_DEG", "VTAIL4"
};
typedef struct { typedef struct {
char *name; char *name;
char *param; char *param;
void (*func)(char *cmdline); void (*func)(char *cmdline);
} cliCmd; } clicmd_t;
// should be sorted a..z for bsearch() // should be sorted a..z for bsearch()
const cliCmd cmdTable[] = { const clicmd_t cmdTable[] = {
{ "exit", "", cliExit }, { "exit", "", cliExit },
{ "help", "", cliHelp }, { "help", "", cliHelp },
{ "mixer", "mixer name", cliMixer },
{ "rmode", "pwm / ppm", cliRMode }, { "rmode", "pwm / ppm", cliRMode },
{ "set", "name=value", cliSet },
{ "version", "", cliVersion }, { "version", "", cliVersion },
}; };
#define CMD_COUNT (sizeof cmdTable / sizeof cmdTable[0]) #define CMD_COUNT (sizeof(cmdTable) / sizeof(cmdTable[0]))
typedef enum {
VAR_BOOL, // yes/no true/false 1/0 type stuff
VAR_UINT8,
VAR_INT8,
VAR_UINT16,
VAR_INT16
} vartype_e;
typedef struct {
const char *name;
const uint8_t type; // vartype_e
void *ptr;
const int32_t min;
const int32_t max;
} clivalue_t;
const clivalue_t valueTable[] = {
{ "deadband", VAR_UINT8, &cfg.deadband, 0, 32 },
{ "midrc", VAR_UINT16, &cfg.midrc, 1200, 1700 },
{ "minthrottle", VAR_UINT16, &cfg.minthrottle, 0, 2000 },
{ "maxthrottle", VAR_UINT16, &cfg.maxthrottle, 0, 2000 },
{ "mincommand", VAR_UINT16, &cfg.mincommand, 0, 2000 },
{ "yaw_direction", VAR_INT8, &cfg.yaw_direction, -1, 1 },
{ "wing_left_mid", VAR_UINT16, &cfg.wing_left_mid, 0, 2000 },
{ "wing_right_mid", VAR_UINT16, &cfg.wing_right_mid, 0, 2000 },
{ "tri_yaw_middle", VAR_UINT16, &cfg.tri_yaw_middle, 0, 2000 },
{ "tilt_pitch_prop", VAR_INT8, &cfg.tilt_pitch_prop, -100, 100 },
{ "tilt_roll_prop", VAR_INT8, &cfg.tilt_roll_prop, -100, 100 },
};
#define VALUE_COUNT (sizeof(valueTable) / sizeof(valueTable[0]))
static void cliPrompt(void) static void cliPrompt(void)
{ {
uartPrint("\r\n# "); uartPrint("\r\n# ");
memset(cliBuffer, 0, sizeof(cliBuffer));
bufferIndex = 0;
} }
static int cliCompare(const void *a, const void *b) static int cliCompare(const void *a, const void *b)
{ {
const cliCmd *ca = a, *cb = b; const clicmd_t *ca = a, *cb = b;
return strncasecmp(ca->name, cb->name, strlen(cb->name)); return strncasecmp(ca->name, cb->name, strlen(cb->name));
} }
static void cliExit(char *cmdline) static void cliExit(char *cmdline)
{ {
uartPrint("Leaving CLI mode...\r\n"); uartPrint("\r\nLeaving CLI mode...\r\n");
memset(cliBuffer, 0, sizeof(cliBuffer)); memset(cliBuffer, 0, sizeof(cliBuffer));
bufferIndex = 0; bufferIndex = 0;
cliMode = 0; cliMode = 0;
@ -62,6 +104,12 @@ static void cliHelp(char *cmdline)
} }
} }
static void cliMixer(char *cmdline)
{
}
static void cliRMode(char *cmdline) static void cliRMode(char *cmdline)
{ {
if (strncasecmp(cmdline, "pwm", 3) == 0) { if (strncasecmp(cmdline, "pwm", 3) == 0) {
@ -71,31 +119,78 @@ static void cliRMode(char *cmdline)
uartPrint("PPM Mode"); uartPrint("PPM Mode");
featureSet(FEATURE_PPM); featureSet(FEATURE_PPM);
} }
cliExit(cmdline);
writeParams(); writeParams();
systemReset(false); systemReset(false);
} }
static void cliSet(char *cmdline)
{
}
static void cliVersion(char *cmdline) static void cliVersion(char *cmdline)
{ {
uartPrint("Afro32 CLI version 2.0-pre1"); uartPrint("Afro32 CLI version 2.0-pre3");
} }
void cliProcess(void) void cliProcess(void)
{ {
if (!cliMode) {
cliMode = 1;
uartPrint("\r\nEntering CLI Mode, type 'exit' to return, or 'help'\r\n");
cliPrompt();
}
while (uartAvailable()) { while (uartAvailable()) {
uint8_t c = uartRead(); uint8_t c = uartRead();
cliBuffer[bufferIndex++] = c; if (c == '\t' || c == '?') {
if (bufferIndex == sizeof(cliBuffer)) { const clicmd_t *cmd, *pstart = NULL, *pend = NULL;
bufferIndex--; int i = bufferIndex;
c = '\n'; for (cmd = cmdTable;cmd < cmdTable + CMD_COUNT;cmd++) {
} if (bufferIndex && (strncasecmp(cliBuffer, cmd->name, bufferIndex) != 0))
continue;
if (bufferIndex && (c == '\n' || c == '\r')) { if (!pstart)
pstart = cmd;
pend = cmd;
}
if (pstart) { /* Buffer matches one or more commands */
for (;;bufferIndex++) {
if (pstart->name[bufferIndex] != pend->name[bufferIndex])
break;
if (!pstart->name[bufferIndex]) {
/* Unambiguous -- append a space */
cliBuffer[bufferIndex++] = ' ';
break;
}
cliBuffer[bufferIndex] = pstart->name[bufferIndex];
}
}
if (!bufferIndex || pstart != pend) {
/* Print list of ambiguous matches */
uartPrint("\r\033[K");
for (cmd = pstart;cmd <= pend;cmd++) {
uartPrint(cmd->name);
uartWrite('\t');
}
cliPrompt();
i = 0; /* Redraw prompt */
}
for (;i < bufferIndex;i++)
uartWrite(cliBuffer[i]);
} else if (!bufferIndex && c == 4) {
cliExit(cliBuffer);
return;
} else if (c == 12) {
uartPrint("\033[2J\033[1;1H");
cliPrompt();
} else if (bufferIndex && (c == '\n' || c == '\r')) {
// enter pressed // enter pressed
cliCmd *cmd = NULL; clicmd_t *cmd = NULL;
cliCmd target; clicmd_t target;
uartPrint("\r\n"); uartPrint("\r\n");
cliBuffer[bufferIndex] = 0; // null terminate cliBuffer[bufferIndex] = 0; // null terminate
@ -108,25 +203,23 @@ void cliProcess(void)
else else
uartPrint("ERR: Unknown command, try 'HELP'"); uartPrint("ERR: Unknown command, try 'HELP'");
// 'exit' will reset this flag, so we don't need to print prompt again memset(cliBuffer, 0, sizeof(cliBuffer));
if (cliMode) bufferIndex = 0;
cliPrompt();
// 'exit' will reset this flag, so we don't need to print prompt again
if (!cliMode)
return;
cliPrompt();
} else if (c == 127) { } else if (c == 127) {
// backspace // backspace
if (bufferIndex > 1) { if (bufferIndex) {
cliBuffer[bufferIndex - 2] = 0; cliBuffer[--bufferIndex] = 0;
uartPrint("\r# "); uartPrint("\010 \010");
uartPrint(cliBuffer);
uartWrite(' ');
uartPrint("\r# ");
uartPrint(cliBuffer);
bufferIndex -= 2;
} }
} else if (c < 32 || c > 126) { } else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) {
// non-printable ascii if (!bufferIndex && c == 32)
bufferIndex--; continue;
} else { cliBuffer[bufferIndex++] = c;
uartWrite(c); uartWrite(c);
} }
} }

View file

@ -15,11 +15,6 @@ void serialize8(uint8_t a)
uartWrite(a); uartWrite(a);
} }
void UartSendData()
{
// Data transmission acivated when the ring is not empty
}
void serialCom(void) void serialCom(void)
{ {
uint8_t i; uint8_t i;
@ -33,8 +28,7 @@ void serialCom(void)
if (uartAvailable()) { if (uartAvailable()) {
switch (uartRead()) { switch (uartRead()) {
case '#': case '#':
uartPrint("\r\nEntering CLI Mode, type 'exit' to return\r\n"); cliProcess();
cliMode = 1;
break; break;
#ifdef BTSERIAL #ifdef BTSERIAL
@ -197,7 +191,6 @@ void serialCom(void)
serialize16(debug3); // debug3 serialize16(debug3); // debug3
serialize16(debug4); // debug4 serialize16(debug4); // debug4
serialize8('M'); serialize8('M');
// UartSendData();
break; break;
case 'O': // arduino to OSD data - contribution from MIS case 'O': // arduino to OSD data - contribution from MIS
serialize8('O'); serialize8('O');