console_countdown: add possibility to abort countdown by external commands
This patch makes it possible to abort a console countdown by an external command, for example when fastboot is used. This requires additional modifications in the external commands, a call to "console_countdown_abort()" has to be inserted. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
3d92ea4738
commit
e3dda8553e
|
@ -32,7 +32,7 @@ static int do_timeout(int argc, char *argv[])
|
||||||
char str[2] = { };
|
char str[2] = { };
|
||||||
const char *varname = NULL;
|
const char *varname = NULL;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "crsav:")) > 0) {
|
while ((opt = getopt(argc, argv, "crsav:e")) > 0) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'r':
|
case 'r':
|
||||||
flags |= CONSOLE_COUNTDOWN_RETURN;
|
flags |= CONSOLE_COUNTDOWN_RETURN;
|
||||||
|
@ -46,6 +46,9 @@ static int do_timeout(int argc, char *argv[])
|
||||||
case 's':
|
case 's':
|
||||||
flags |= CONSOLE_COUNTDOWN_SILENT;
|
flags |= CONSOLE_COUNTDOWN_SILENT;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
flags |= CONSOLE_COUNTDOWN_EXTERN;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
varname = optarg;
|
varname = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -73,6 +76,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
|
||||||
BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key")
|
BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key")
|
||||||
BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C")
|
BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C")
|
||||||
BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN")
|
BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN")
|
||||||
|
BAREBOX_CMD_HELP_OPT("-e", "interrupt on external commands (i.e. fastboot")
|
||||||
BAREBOX_CMD_HELP_OPT("-s", "silent mode")
|
BAREBOX_CMD_HELP_OPT("-s", "silent mode")
|
||||||
BAREBOX_CMD_HELP_OPT("-v <VARIABLE>", "export pressed key to environment")
|
BAREBOX_CMD_HELP_OPT("-v <VARIABLE>", "export pressed key to environment")
|
||||||
BAREBOX_CMD_HELP_END
|
BAREBOX_CMD_HELP_END
|
||||||
|
@ -80,7 +84,7 @@ BAREBOX_CMD_HELP_END
|
||||||
BAREBOX_CMD_START(timeout)
|
BAREBOX_CMD_START(timeout)
|
||||||
.cmd = do_timeout,
|
.cmd = do_timeout,
|
||||||
BAREBOX_CMD_DESC("wait for a specified timeout")
|
BAREBOX_CMD_DESC("wait for a specified timeout")
|
||||||
BAREBOX_CMD_OPTS("[-acrsv] SECONDS")
|
BAREBOX_CMD_OPTS("[-acrsev] SECONDS")
|
||||||
BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
|
BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
|
||||||
BAREBOX_CMD_HELP(cmd_timeout_help)
|
BAREBOX_CMD_HELP(cmd_timeout_help)
|
||||||
BAREBOX_CMD_END
|
BAREBOX_CMD_END
|
||||||
|
|
|
@ -23,6 +23,13 @@
|
||||||
#include <console_countdown.h>
|
#include <console_countdown.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static bool console_countdown_timeout_abort;
|
||||||
|
|
||||||
|
void console_countdown_abort(void)
|
||||||
|
{
|
||||||
|
console_countdown_timeout_abort = true;
|
||||||
|
}
|
||||||
|
|
||||||
int console_countdown(int timeout_s, unsigned flags, char *out_key)
|
int console_countdown(int timeout_s, unsigned flags, char *out_key)
|
||||||
{
|
{
|
||||||
uint64_t start, second;
|
uint64_t start, second;
|
||||||
|
@ -48,6 +55,9 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
|
||||||
goto out;
|
goto out;
|
||||||
key = 0;
|
key = 0;
|
||||||
}
|
}
|
||||||
|
if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
|
||||||
|
console_countdown_timeout_abort)
|
||||||
|
goto out;
|
||||||
if (!(flags & CONSOLE_COUNTDOWN_SILENT) &&
|
if (!(flags & CONSOLE_COUNTDOWN_SILENT) &&
|
||||||
is_timeout(second, SECOND)) {
|
is_timeout(second, SECOND)) {
|
||||||
printf("\b\b\b\b%4d", countdown--);
|
printf("\b\b\b\b%4d", countdown--);
|
||||||
|
@ -55,6 +65,10 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
|
||||||
}
|
}
|
||||||
} while (!is_timeout(start, timeout_s * SECOND));
|
} while (!is_timeout(start, timeout_s * SECOND));
|
||||||
|
|
||||||
|
if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
|
||||||
|
console_countdown_timeout_abort)
|
||||||
|
goto out;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -62,6 +76,7 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (key && out_key)
|
if (key && out_key)
|
||||||
*out_key = key;
|
*out_key = key;
|
||||||
|
console_countdown_timeout_abort = false;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
#define CONSOLE_COUNTDOWN_ANYKEY (1 << 1)
|
#define CONSOLE_COUNTDOWN_ANYKEY (1 << 1)
|
||||||
#define CONSOLE_COUNTDOWN_RETURN (1 << 3)
|
#define CONSOLE_COUNTDOWN_RETURN (1 << 3)
|
||||||
#define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
|
#define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
|
||||||
|
#define CONSOLE_COUNTDOWN_EXTERN (1 << 5)
|
||||||
|
|
||||||
int console_countdown(int timeout_s, unsigned flags, char *out_key);
|
int console_countdown(int timeout_s, unsigned flags, char *out_key);
|
||||||
|
void console_countdown_abort(void);
|
||||||
|
|
||||||
#endif /* __CONSOLE_COUNTDOWN_H */
|
#endif /* __CONSOLE_COUNTDOWN_H */
|
||||||
|
|
Loading…
Reference in New Issue