Home Alert System

Dependencies:   PWM_Tone_Library DHT

Committer:
ethaderu
Date:
Tue Mar 05 02:34:44 2019 +0000
Revision:
3:78f223d34f36
Publish 1

Who changed what in which revision?

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