DHT11

Committer:
jhon309
Date:
Thu Aug 13 00:21:57 2015 +0000
Revision:
0:c52df770855b
DHT11

Who changed what in which revision?

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