From b15d22a4e43f86058b3b053096ab885a4cef6603 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 3 Dec 2014 15:52:39 +0100 Subject: [PATCH] Make do_fat_stat() and do_fat_ls() interruptible --- avr/cmd_fat.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file 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); -- 2.39.2