]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Make do_fat_stat() and do_fat_ls() interruptible
authorLeo C <erbl259-lmu@yahoo.de>
Wed, 3 Dec 2014 14:52:39 +0000 (15:52 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Wed, 3 Dec 2014 14:52:39 +0000 (15:52 +0100)
avr/cmd_fat.c

index 9db3b0a55a852590b8ac453ba2f287df84c2ca5e..16a5157ee041309fed2fd2feb6f9c15406ce556f 100644 (file)
@@ -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);