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