Basic fading in and out of leds with light sensor.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:24:58 2016 +0000
Revision:
0:cf7af2656659
Basic v1

Who changed what in which revision?

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