diff options
| author | hathach <[email protected]> | 2022-11-21 11:52:51 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-11-21 11:52:51 +0700 |
| commit | cab65acc464ca5876bd3682587ee2670268b13d2 (patch) | |
| tree | 1124d5ee60be6e9d6d09c8cc71d696fe37cfc935 /examples | |
| parent | 51873cd1be5291c15a24054e464d98d4953eebfa (diff) | |
add pwd
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/host/msc_file_explorer/src/main.c | 8 | ||||
| -rw-r--r-- | examples/host/msc_file_explorer/src/msc_app.c | 43 |
2 files changed, 42 insertions, 9 deletions
diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c index f46e5092b..652986b7c 100644 --- a/examples/host/msc_file_explorer/src/main.c +++ b/examples/host/msc_file_explorer/src/main.c @@ -43,7 +43,7 @@ int main(void) { board_init(); - printf("TinyUSB Host MSC Explorer Example\r\n"); + printf("TinyUSB Host MassStorage Explorer Example\r\n"); // init host stack on configured roothub port tuh_init(BOARD_TUH_RHPORT); @@ -67,14 +67,12 @@ int main(void) void tuh_mount_cb(uint8_t dev_addr) { - // application set-up - printf("A device with address %d is mounted\r\n", dev_addr); + (void) dev_addr; } void tuh_umount_cb(uint8_t dev_addr) { - // application tear-down - printf("A device with address %d is unmounted \r\n", dev_addr); + (void) dev_addr; } diff --git a/examples/host/msc_file_explorer/src/msc_app.c b/examples/host/msc_file_explorer/src/msc_app.c index 4500aedd2..6e5cb672a 100644 --- a/examples/host/msc_file_explorer/src/msc_app.c +++ b/examples/host/msc_file_explorer/src/msc_app.c @@ -108,7 +108,7 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun); printf("Disk Size: %lu MB\r\n", block_count / ((1024*1024)/block_size)); - printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size); + // printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size); // For simplicity: we only mount 1 LUN per device uint8_t const drive_num = dev_addr-1; @@ -120,8 +120,15 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const puts("mount failed"); } - f_chdrive(drive_path); // change to newly mounted drive - f_chdir("/"); // root as current dir + // change to newly mounted drive + f_chdir(drive_path); + + // print the drive label +// char label[34]; +// if ( FR_OK == f_getlabel(drive_path, label, NULL) ) +// { +// puts(label); +// } return true; } @@ -137,7 +144,6 @@ void tuh_msc_mount_cb(uint8_t dev_addr) void tuh_msc_umount_cb(uint8_t dev_addr) { - (void) dev_addr; printf("A MassStorage device is unmounted\r\n"); uint8_t const drive_num = dev_addr-1; @@ -273,6 +279,7 @@ void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context); void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context); void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context); void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context); +void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context); void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context); void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context); @@ -339,6 +346,14 @@ bool cli_init(void) }); embeddedCliAddBinding(_cli, (CliCommandBinding) { + "pwd", + "Usage: pwd\r\n\tPrint the name of the current working directory.", + true, + NULL, + cli_cmd_pwd + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { "mkdir", "Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..", true, @@ -531,6 +546,26 @@ void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context) f_closedir(&dir); } +void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + uint16_t argc = embeddedCliGetTokenCount(args); + + if (argc != 0) + { + printf("invalid arguments\r\n"); + return; + } + + char path[256]; + if (FR_OK != f_getcwd(path, sizeof(path))) + { + printf("cannot get current working directory\r\n"); + } + + puts(path); +} + void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context) { (void) cli; (void) context; |
