Programme d'utilisation servomotors MX12 V1
Fork of Utilisation_MX12 by
mbed/LocalFileSystem.h@0:80df663dd15e, 2017-05-19 (annotated)
- Committer:
- R66Y
- Date:
- Fri May 19 14:32:14 2017 +0000
- Revision:
- 0:80df663dd15e
programme pour utiliser les servomoteurs MX12.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
R66Y | 0:80df663dd15e | 1 | /* mbed Microcontroller Library - LocalFileSystem |
R66Y | 0:80df663dd15e | 2 | * Copyright (c) 2008-2009 ARM Limited. All rights reserved. |
R66Y | 0:80df663dd15e | 3 | */ |
R66Y | 0:80df663dd15e | 4 | |
R66Y | 0:80df663dd15e | 5 | #ifndef MBED_LOCALFILESYSTEM_H |
R66Y | 0:80df663dd15e | 6 | #define MBED_LOCALFILESYSTEM_H |
R66Y | 0:80df663dd15e | 7 | |
R66Y | 0:80df663dd15e | 8 | #include "FileSystemLike.h" |
R66Y | 0:80df663dd15e | 9 | |
R66Y | 0:80df663dd15e | 10 | namespace mbed { |
R66Y | 0:80df663dd15e | 11 | |
R66Y | 0:80df663dd15e | 12 | FILEHANDLE local_file_open(const char* name, int flags); |
R66Y | 0:80df663dd15e | 13 | |
R66Y | 0:80df663dd15e | 14 | class LocalFileHandle : public FileHandle { |
R66Y | 0:80df663dd15e | 15 | |
R66Y | 0:80df663dd15e | 16 | public: |
R66Y | 0:80df663dd15e | 17 | LocalFileHandle(FILEHANDLE fh); |
R66Y | 0:80df663dd15e | 18 | |
R66Y | 0:80df663dd15e | 19 | virtual int close(); |
R66Y | 0:80df663dd15e | 20 | |
R66Y | 0:80df663dd15e | 21 | virtual ssize_t write(const void *buffer, size_t length); |
R66Y | 0:80df663dd15e | 22 | |
R66Y | 0:80df663dd15e | 23 | virtual ssize_t read(void *buffer, size_t length); |
R66Y | 0:80df663dd15e | 24 | |
R66Y | 0:80df663dd15e | 25 | virtual int isatty(); |
R66Y | 0:80df663dd15e | 26 | |
R66Y | 0:80df663dd15e | 27 | virtual off_t lseek(off_t position, int whence); |
R66Y | 0:80df663dd15e | 28 | |
R66Y | 0:80df663dd15e | 29 | virtual int fsync(); |
R66Y | 0:80df663dd15e | 30 | |
R66Y | 0:80df663dd15e | 31 | virtual off_t flen(); |
R66Y | 0:80df663dd15e | 32 | |
R66Y | 0:80df663dd15e | 33 | protected: |
R66Y | 0:80df663dd15e | 34 | FILEHANDLE _fh; |
R66Y | 0:80df663dd15e | 35 | int pos; |
R66Y | 0:80df663dd15e | 36 | }; |
R66Y | 0:80df663dd15e | 37 | |
R66Y | 0:80df663dd15e | 38 | /* Class: LocalFileSystem |
R66Y | 0:80df663dd15e | 39 | * A filesystem for accessing the local mbed Microcontroller USB disk drive |
R66Y | 0:80df663dd15e | 40 | * |
R66Y | 0:80df663dd15e | 41 | * This allows programs to read and write files on the same disk drive that is used to program the |
R66Y | 0:80df663dd15e | 42 | * mbed Microcontroller. Once created, the standard C file access functions are used to open, |
R66Y | 0:80df663dd15e | 43 | * read and write files. |
R66Y | 0:80df663dd15e | 44 | * |
R66Y | 0:80df663dd15e | 45 | * Example: |
R66Y | 0:80df663dd15e | 46 | * > #include "mbed.h" |
R66Y | 0:80df663dd15e | 47 | * > |
R66Y | 0:80df663dd15e | 48 | * > LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
R66Y | 0:80df663dd15e | 49 | * > |
R66Y | 0:80df663dd15e | 50 | * > int main() { |
R66Y | 0:80df663dd15e | 51 | * > FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
R66Y | 0:80df663dd15e | 52 | * > fprintf(fp, "Hello World!"); |
R66Y | 0:80df663dd15e | 53 | * > fclose(fp); |
R66Y | 0:80df663dd15e | 54 | * > remove("/local/out.txt"); // Removes the file "out.txt" from the local file system |
R66Y | 0:80df663dd15e | 55 | * > |
R66Y | 0:80df663dd15e | 56 | * > DIR *d = opendir("/local"); // Opens the root directory of the local file system |
R66Y | 0:80df663dd15e | 57 | * > struct dirent *p; |
R66Y | 0:80df663dd15e | 58 | * > while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system |
R66Y | 0:80df663dd15e | 59 | * > printf("%s\n", p->d_name); // to stdout. |
R66Y | 0:80df663dd15e | 60 | * > } |
R66Y | 0:80df663dd15e | 61 | * > closedir(d); |
R66Y | 0:80df663dd15e | 62 | * > } |
R66Y | 0:80df663dd15e | 63 | * |
R66Y | 0:80df663dd15e | 64 | * Implementation Notes: |
R66Y | 0:80df663dd15e | 65 | * If the microcontroller program makes an access to the local drive, it will be marked as "removed" |
R66Y | 0:80df663dd15e | 66 | * on the Host computer. This means it is no longer accessible from the Host Computer. |
R66Y | 0:80df663dd15e | 67 | * |
R66Y | 0:80df663dd15e | 68 | * The drive will only re-appear when the microcontroller program exists. Note that if the program does |
R66Y | 0:80df663dd15e | 69 | * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! |
R66Y | 0:80df663dd15e | 70 | */ |
R66Y | 0:80df663dd15e | 71 | class LocalFileSystem : public FileSystemLike { |
R66Y | 0:80df663dd15e | 72 | |
R66Y | 0:80df663dd15e | 73 | public: |
R66Y | 0:80df663dd15e | 74 | |
R66Y | 0:80df663dd15e | 75 | LocalFileSystem(const char* n) : FileSystemLike(n) { |
R66Y | 0:80df663dd15e | 76 | |
R66Y | 0:80df663dd15e | 77 | } |
R66Y | 0:80df663dd15e | 78 | |
R66Y | 0:80df663dd15e | 79 | virtual FileHandle *open(const char* name, int flags); |
R66Y | 0:80df663dd15e | 80 | virtual int remove(const char *filename); |
R66Y | 0:80df663dd15e | 81 | virtual DirHandle *opendir(const char *name); |
R66Y | 0:80df663dd15e | 82 | }; |
R66Y | 0:80df663dd15e | 83 | |
R66Y | 0:80df663dd15e | 84 | } // namespace mbed |
R66Y | 0:80df663dd15e | 85 | |
R66Y | 0:80df663dd15e | 86 | #endif |