This is a repository for all my programs or modified programs.

Committer:
mturner5
Date:
Sun Sep 11 23:48:09 2016 +0000
Revision:
0:72480818e4a9
Made delays for the LEDS and button presses

Who changed what in which revision?

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