summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2014-12-03 15:52:39 +0100
committerLeo C2014-12-03 15:52:39 +0100
commitb15d22a4e43f86058b3b053096ab885a4cef6603 (patch)
tree07f2192b98c642f3056efa94fbaf99410da89dfb /avr
parentd332e3337306d5f8b5c810048bbd145391c33f29 (diff)
downloadz180-stamp-b15d22a4e43f86058b3b053096ab885a4cef6603.zip
Make do_fat_stat() and do_fat_ls() interruptible
Diffstat (limited to 'avr')
-rw-r--r--avr/cmd_fat.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c
index 9db3b0a..16a5157 100644
--- a/avr/cmd_fat.c
+++ b/avr/cmd_fat.c
@@ -29,6 +29,17 @@ DWORD get_fattime (void)
}
+static bool check_abort(void)
+{
+ bool ret = ctrlc();
+
+ if (ret)
+ printf_P(PSTR("Abort\n"));
+
+ return ret;
+}
+
+
static const FLASH char * const FLASH rc_names[] = {
FSTR("OK"),
FSTR("DISK_ERR"),
@@ -54,13 +65,15 @@ static const FLASH char * const FLASH rc_names[] = {
static
void put_rc (FRESULT rc)
{
+ if (rc < ARRAY_SIZE(rc_names)) {
#if GCC_BUG_61443
- printf_P(PSTR("rc=%u FR_"), rc);
- my_puts_P(rc_names[rc]);
- my_puts_P(PSTR("\n"));
+ printf_P(PSTR("rc=%u FR_"), rc);
+ my_puts_P(rc_names[rc]);
+ my_puts_P(PSTR("\n"));
#else
- printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]);
+ printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]);
#endif
+ }
}
/* Work register for fs command */
@@ -76,6 +89,20 @@ FILINFO Finfo = {
FILINFO Finfo;
#endif
+static const FLASH char swirlchar[] = { '-','\\','|','/' };
+
+static void swirl(void)
+{
+ static uint_fast8_t cnt;
+ static uint32_t tstamp;
+
+ if (get_timer(0) > tstamp) {
+ printf_P(PSTR("\b%c"), swirlchar[cnt]);
+ cnt = (cnt+1) % ARRAY_SIZE(swirlchar);
+ tstamp = get_timer(0) + 300;
+ }
+}
+
static
FRESULT scan_files (
char* path /* Pointer to the working buffer with start path */
@@ -87,7 +114,7 @@ FRESULT scan_files (
char *fn;
res = f_opendir(&dirs, path);
-
+ swirl();
if (res == FR_OK) {
i = strlen(path);
while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) {
@@ -108,6 +135,10 @@ FRESULT scan_files (
AccFiles++;
AccSize += Finfo.fsize;
}
+ if (check_abort()) {
+ res = 255;
+ break;
+ }
}
}
@@ -167,7 +198,7 @@ command_ret_t do_fat_stat(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
}
#endif
if (!res) {
- my_puts_P(PSTR("\n..."));
+ my_puts_P(PSTR("\nCounting... "));
AccSize = AccFiles = AccDirs = 0;
strcpy(buffer, argv[1]);
@@ -246,6 +277,8 @@ command_ret_t do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
#else
printf_P(PSTR("%s\n"), Finfo.fname);
#endif
+ if (check_abort())
+ break;
}
if (res == FR_OK) {
@@ -362,10 +395,8 @@ command_ret_t do_fat_rw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
printf_P(PSTR("Disk full?\n"));
break;
}
- if (ctrlc()) {
- printf_P(PSTR("Abort\n"));
+ if (check_abort())
break;
- }
}
FRESULT fr = f_close(&File);