The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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