Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface SDFileSystem mbed-rtos mbed
main.cpp@2:e699312248f3, 2016-12-05 (annotated)
- Committer:
- micbio
- Date:
- Mon Dec 05 22:46:14 2016 +0000
- Revision:
- 2:e699312248f3
- Parent:
- 1:58d2021e301d
ad
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| micbio | 0:1649f66cf32a | 1 | #include "mbed.h" |
| micbio | 0:1649f66cf32a | 2 | #include "SDFileSystem.h" |
| micbio | 1:58d2021e301d | 3 | #include "cli.hpp" |
| micbio | 1:58d2021e301d | 4 | #include "file_manager.hpp" |
| micbio | 0:1649f66cf32a | 5 | |
| micbio | 1:58d2021e301d | 6 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
| micbio | 1:58d2021e301d | 7 | Serial pc(USBTX, USBRX); |
| micbio | 1:58d2021e301d | 8 | // DigitalIn enable(SW2); |
| micbio | 1:58d2021e301d | 9 | DigitalOut led(LED1); |
| micbio | 1:58d2021e301d | 10 | |
| micbio | 1:58d2021e301d | 11 | int main() |
| micbio | 1:58d2021e301d | 12 | { |
| micbio | 1:58d2021e301d | 13 | cli_sd cli; |
| micbio | 1:58d2021e301d | 14 | file_manager fm; |
| micbio | 1:58d2021e301d | 15 | char cmd; |
| micbio | 1:58d2021e301d | 16 | |
| micbio | 2:e699312248f3 | 17 | cli.welcome(); |
| micbio | 2:e699312248f3 | 18 | cli.print_help(); |
| micbio | 0:1649f66cf32a | 19 | |
| micbio | 1:58d2021e301d | 20 | while(1) |
| micbio | 1:58d2021e301d | 21 | { |
| micbio | 2:e699312248f3 | 22 | cmd = cli.get_cmd(); |
| micbio | 1:58d2021e301d | 23 | |
| micbio | 1:58d2021e301d | 24 | switch(cmd) |
| micbio | 1:58d2021e301d | 25 | { |
| micbio | 1:58d2021e301d | 26 | case 'm': |
| micbio | 1:58d2021e301d | 27 | break; |
| micbio | 1:58d2021e301d | 28 | case 'p': |
| micbio | 2:e699312248f3 | 29 | fm.set_path(); |
| micbio | 1:58d2021e301d | 30 | break; |
| micbio | 1:58d2021e301d | 31 | case 'w': |
| micbio | 2:e699312248f3 | 32 | fm.write_to_file(); |
| micbio | 1:58d2021e301d | 33 | break; |
| micbio | 1:58d2021e301d | 34 | case 'a': |
| micbio | 2:e699312248f3 | 35 | fm.append_to_file(); |
| micbio | 1:58d2021e301d | 36 | break; |
| micbio | 1:58d2021e301d | 37 | case 'r': |
| micbio | 2:e699312248f3 | 38 | fm.read_file(); |
| micbio | 1:58d2021e301d | 39 | break; |
| micbio | 1:58d2021e301d | 40 | default: |
| micbio | 2:e699312248f3 | 41 | pc.printf("Error.\n"); // should never enter this |
| micbio | 1:58d2021e301d | 42 | break; |
| micbio | 1:58d2021e301d | 43 | } |
| micbio | 1:58d2021e301d | 44 | } |
| micbio | 1:58d2021e301d | 45 | |
| micbio | 1:58d2021e301d | 46 | while(1) { |
| micbio | 2:e699312248f3 | 47 | if(!true) { |
| micbio | 1:58d2021e301d | 48 | //pc.printf("\r\nThis is: %c", cmd); |
| micbio | 1:58d2021e301d | 49 | //pc.scanf(cmd); |
| micbio | 1:58d2021e301d | 50 | if (pc.writeable()) |
| micbio | 1:58d2021e301d | 51 | { |
| micbio | 1:58d2021e301d | 52 | led = !led; |
| micbio | 1:58d2021e301d | 53 | } |
| micbio | 1:58d2021e301d | 54 | } |
| micbio | 1:58d2021e301d | 55 | wait(0.25); |
| micbio | 1:58d2021e301d | 56 | } |
| micbio | 1:58d2021e301d | 57 | |
| micbio | 0:1649f66cf32a | 58 | while(1) { |
| micbio | 0:1649f66cf32a | 59 | FILE *fp = fopen("/sd/testfile.txt", "a"); |
| micbio | 2:e699312248f3 | 60 | fprintf(fp, "hello world!\r\n"); |
| micbio | 0:1649f66cf32a | 61 | fclose(fp); |
| micbio | 0:1649f66cf32a | 62 | wait(1); |
| micbio | 0:1649f66cf32a | 63 | } |
| micbio | 0:1649f66cf32a | 64 | } |