FRDM-K64F, Avnet M14A2A, Grove Shield, to create smart home system. In use with AT&Ts M2x & Flow.

Dependencies:   mbed FXOS8700CQ MODSERIAL

Committer:
jwhammel
Date:
Mon Apr 29 04:24:38 2019 +0000
Revision:
85:0cf65ceb4492
Parent:
84:fc8c9b39723a
We have added an alarm trigger that gets sent to AT&T Flow.

Who changed what in which revision?

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