Mouse code for the MacroRat
mbed-dev/drivers/LocalFileSystem.h@32:69acb14778ea, 2017-05-26 (annotated)
- Committer:
- kyleliangus
- Date:
- Fri May 26 03:46:03 2017 +0000
- Revision:
- 32:69acb14778ea
- Parent:
- 18:6a4db94011d3
PID values still wonky. IR PID vs Encoder PID also wonky
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2006-2013 ARM Limited |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sahilmgandhi | 18:6a4db94011d3 | 5 | * you may not use this file except in compliance with the License. |
sahilmgandhi | 18:6a4db94011d3 | 6 | * You may obtain a copy of the License at |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
sahilmgandhi | 18:6a4db94011d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sahilmgandhi | 18:6a4db94011d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sahilmgandhi | 18:6a4db94011d3 | 13 | * See the License for the specific language governing permissions and |
sahilmgandhi | 18:6a4db94011d3 | 14 | * limitations under the License. |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | #ifndef MBED_LOCALFILESYSTEM_H |
sahilmgandhi | 18:6a4db94011d3 | 17 | #define MBED_LOCALFILESYSTEM_H |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | #include "platform/platform.h" |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | #if DEVICE_LOCALFILESYSTEM |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | #include "drivers/FileSystemLike.h" |
sahilmgandhi | 18:6a4db94011d3 | 24 | #include "platform/PlatformMutex.h" |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | namespace mbed { |
sahilmgandhi | 18:6a4db94011d3 | 27 | /** \addtogroup drivers */ |
sahilmgandhi | 18:6a4db94011d3 | 28 | /** @{*/ |
sahilmgandhi | 18:6a4db94011d3 | 29 | |
sahilmgandhi | 18:6a4db94011d3 | 30 | FILEHANDLE local_file_open(const char* name, int flags); |
sahilmgandhi | 18:6a4db94011d3 | 31 | |
sahilmgandhi | 18:6a4db94011d3 | 32 | class LocalFileHandle : public FileHandle { |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | public: |
sahilmgandhi | 18:6a4db94011d3 | 35 | LocalFileHandle(FILEHANDLE fh); |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | virtual int close(); |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | virtual ssize_t write(const void *buffer, size_t length); |
sahilmgandhi | 18:6a4db94011d3 | 40 | |
sahilmgandhi | 18:6a4db94011d3 | 41 | virtual ssize_t read(void *buffer, size_t length); |
sahilmgandhi | 18:6a4db94011d3 | 42 | |
sahilmgandhi | 18:6a4db94011d3 | 43 | virtual int isatty(); |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | virtual off_t lseek(off_t position, int whence); |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | virtual int fsync(); |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | virtual off_t flen(); |
sahilmgandhi | 18:6a4db94011d3 | 50 | |
sahilmgandhi | 18:6a4db94011d3 | 51 | protected: |
sahilmgandhi | 18:6a4db94011d3 | 52 | virtual void lock(); |
sahilmgandhi | 18:6a4db94011d3 | 53 | virtual void unlock(); |
sahilmgandhi | 18:6a4db94011d3 | 54 | FILEHANDLE _fh; |
sahilmgandhi | 18:6a4db94011d3 | 55 | int pos; |
sahilmgandhi | 18:6a4db94011d3 | 56 | PlatformMutex _mutex; |
sahilmgandhi | 18:6a4db94011d3 | 57 | }; |
sahilmgandhi | 18:6a4db94011d3 | 58 | |
sahilmgandhi | 18:6a4db94011d3 | 59 | /** A filesystem for accessing the local mbed Microcontroller USB disk drive |
sahilmgandhi | 18:6a4db94011d3 | 60 | * |
sahilmgandhi | 18:6a4db94011d3 | 61 | * This allows programs to read and write files on the same disk drive that is used to program the |
sahilmgandhi | 18:6a4db94011d3 | 62 | * mbed Microcontroller. Once created, the standard C file access functions are used to open, |
sahilmgandhi | 18:6a4db94011d3 | 63 | * read and write files. |
sahilmgandhi | 18:6a4db94011d3 | 64 | * |
sahilmgandhi | 18:6a4db94011d3 | 65 | * @Note Synchronization level: Thread safe |
sahilmgandhi | 18:6a4db94011d3 | 66 | * |
sahilmgandhi | 18:6a4db94011d3 | 67 | * Example: |
sahilmgandhi | 18:6a4db94011d3 | 68 | * @code |
sahilmgandhi | 18:6a4db94011d3 | 69 | * #include "mbed.h" |
sahilmgandhi | 18:6a4db94011d3 | 70 | * |
sahilmgandhi | 18:6a4db94011d3 | 71 | * LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
sahilmgandhi | 18:6a4db94011d3 | 72 | * |
sahilmgandhi | 18:6a4db94011d3 | 73 | * int main() { |
sahilmgandhi | 18:6a4db94011d3 | 74 | * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing |
sahilmgandhi | 18:6a4db94011d3 | 75 | * fprintf(fp, "Hello World!"); |
sahilmgandhi | 18:6a4db94011d3 | 76 | * fclose(fp); |
sahilmgandhi | 18:6a4db94011d3 | 77 | * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system |
sahilmgandhi | 18:6a4db94011d3 | 78 | * |
sahilmgandhi | 18:6a4db94011d3 | 79 | * DIR *d = opendir("/local"); // Opens the root directory of the local file system |
sahilmgandhi | 18:6a4db94011d3 | 80 | * struct dirent *p; |
sahilmgandhi | 18:6a4db94011d3 | 81 | * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system |
sahilmgandhi | 18:6a4db94011d3 | 82 | * printf("%s\n", p->d_name); // to stdout. |
sahilmgandhi | 18:6a4db94011d3 | 83 | * } |
sahilmgandhi | 18:6a4db94011d3 | 84 | * closedir(d); |
sahilmgandhi | 18:6a4db94011d3 | 85 | * } |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @endcode |
sahilmgandhi | 18:6a4db94011d3 | 87 | * |
sahilmgandhi | 18:6a4db94011d3 | 88 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 89 | * If the microcontroller program makes an access to the local drive, it will be marked as "removed" |
sahilmgandhi | 18:6a4db94011d3 | 90 | * on the Host computer. This means it is no longer accessible from the Host Computer. |
sahilmgandhi | 18:6a4db94011d3 | 91 | * |
sahilmgandhi | 18:6a4db94011d3 | 92 | * The drive will only re-appear when the microcontroller program exists. Note that if the program does |
sahilmgandhi | 18:6a4db94011d3 | 93 | * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again! |
sahilmgandhi | 18:6a4db94011d3 | 94 | */ |
sahilmgandhi | 18:6a4db94011d3 | 95 | class LocalFileSystem : public FileSystemLike { |
sahilmgandhi | 18:6a4db94011d3 | 96 | // No modifiable state |
sahilmgandhi | 18:6a4db94011d3 | 97 | |
sahilmgandhi | 18:6a4db94011d3 | 98 | public: |
sahilmgandhi | 18:6a4db94011d3 | 99 | LocalFileSystem(const char* n) : FileSystemLike(n) { |
sahilmgandhi | 18:6a4db94011d3 | 100 | |
sahilmgandhi | 18:6a4db94011d3 | 101 | } |
sahilmgandhi | 18:6a4db94011d3 | 102 | |
sahilmgandhi | 18:6a4db94011d3 | 103 | virtual FileHandle *open(const char* name, int flags); |
sahilmgandhi | 18:6a4db94011d3 | 104 | virtual int remove(const char *filename); |
sahilmgandhi | 18:6a4db94011d3 | 105 | virtual DirHandle *opendir(const char *name); |
sahilmgandhi | 18:6a4db94011d3 | 106 | }; |
sahilmgandhi | 18:6a4db94011d3 | 107 | |
sahilmgandhi | 18:6a4db94011d3 | 108 | } // namespace mbed |
sahilmgandhi | 18:6a4db94011d3 | 109 | |
sahilmgandhi | 18:6a4db94011d3 | 110 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 111 | |
sahilmgandhi | 18:6a4db94011d3 | 112 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 113 | |
sahilmgandhi | 18:6a4db94011d3 | 114 | /** @}*/ |