Mark Turner
/
lightsense_kl46z_basic_v2
Tried to initialize the buttons and slider but couldn't get it to work.
mbed/FileHandle.h@0:0d6b77c9ae01, 2016-09-19 (annotated)
- Committer:
- mturner5
- Date:
- Mon Sep 19 03:28:41 2016 +0000
- Revision:
- 0:0d6b77c9ae01
basic v2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mturner5 | 0:0d6b77c9ae01 | 1 | /* mbed Microcontroller Library |
mturner5 | 0:0d6b77c9ae01 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mturner5 | 0:0d6b77c9ae01 | 3 | * |
mturner5 | 0:0d6b77c9ae01 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mturner5 | 0:0d6b77c9ae01 | 5 | * you may not use this file except in compliance with the License. |
mturner5 | 0:0d6b77c9ae01 | 6 | * You may obtain a copy of the License at |
mturner5 | 0:0d6b77c9ae01 | 7 | * |
mturner5 | 0:0d6b77c9ae01 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mturner5 | 0:0d6b77c9ae01 | 9 | * |
mturner5 | 0:0d6b77c9ae01 | 10 | * Unless required by applicable law or agreed to in writing, software |
mturner5 | 0:0d6b77c9ae01 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mturner5 | 0:0d6b77c9ae01 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mturner5 | 0:0d6b77c9ae01 | 13 | * See the License for the specific language governing permissions and |
mturner5 | 0:0d6b77c9ae01 | 14 | * limitations under the License. |
mturner5 | 0:0d6b77c9ae01 | 15 | */ |
mturner5 | 0:0d6b77c9ae01 | 16 | #ifndef MBED_FILEHANDLE_H |
mturner5 | 0:0d6b77c9ae01 | 17 | #define MBED_FILEHANDLE_H |
mturner5 | 0:0d6b77c9ae01 | 18 | |
mturner5 | 0:0d6b77c9ae01 | 19 | typedef int FILEHANDLE; |
mturner5 | 0:0d6b77c9ae01 | 20 | |
mturner5 | 0:0d6b77c9ae01 | 21 | #include <stdio.h> |
mturner5 | 0:0d6b77c9ae01 | 22 | |
mturner5 | 0:0d6b77c9ae01 | 23 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
mturner5 | 0:0d6b77c9ae01 | 24 | typedef int ssize_t; |
mturner5 | 0:0d6b77c9ae01 | 25 | typedef long off_t; |
mturner5 | 0:0d6b77c9ae01 | 26 | |
mturner5 | 0:0d6b77c9ae01 | 27 | #else |
mturner5 | 0:0d6b77c9ae01 | 28 | # include <sys/types.h> |
mturner5 | 0:0d6b77c9ae01 | 29 | #endif |
mturner5 | 0:0d6b77c9ae01 | 30 | |
mturner5 | 0:0d6b77c9ae01 | 31 | namespace mbed { |
mturner5 | 0:0d6b77c9ae01 | 32 | |
mturner5 | 0:0d6b77c9ae01 | 33 | /** An OO equivalent of the internal FILEHANDLE variable |
mturner5 | 0:0d6b77c9ae01 | 34 | * and associated _sys_* functions. |
mturner5 | 0:0d6b77c9ae01 | 35 | * |
mturner5 | 0:0d6b77c9ae01 | 36 | * FileHandle is an abstract class, needing at least sys_write and |
mturner5 | 0:0d6b77c9ae01 | 37 | * sys_read to be implmented for a simple interactive device. |
mturner5 | 0:0d6b77c9ae01 | 38 | * |
mturner5 | 0:0d6b77c9ae01 | 39 | * No one ever directly tals to/instanciates a FileHandle - it gets |
mturner5 | 0:0d6b77c9ae01 | 40 | * created by FileSystem, and wrapped up by stdio. |
mturner5 | 0:0d6b77c9ae01 | 41 | */ |
mturner5 | 0:0d6b77c9ae01 | 42 | class FileHandle { |
mturner5 | 0:0d6b77c9ae01 | 43 | |
mturner5 | 0:0d6b77c9ae01 | 44 | public: |
mturner5 | 0:0d6b77c9ae01 | 45 | /** Write the contents of a buffer to the file |
mturner5 | 0:0d6b77c9ae01 | 46 | * |
mturner5 | 0:0d6b77c9ae01 | 47 | * @param buffer the buffer to write from |
mturner5 | 0:0d6b77c9ae01 | 48 | * @param length the number of characters to write |
mturner5 | 0:0d6b77c9ae01 | 49 | * |
mturner5 | 0:0d6b77c9ae01 | 50 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 51 | * The number of characters written (possibly 0) on success, -1 on error. |
mturner5 | 0:0d6b77c9ae01 | 52 | */ |
mturner5 | 0:0d6b77c9ae01 | 53 | virtual ssize_t write(const void* buffer, size_t length) = 0; |
mturner5 | 0:0d6b77c9ae01 | 54 | |
mturner5 | 0:0d6b77c9ae01 | 55 | /** Close the file |
mturner5 | 0:0d6b77c9ae01 | 56 | * |
mturner5 | 0:0d6b77c9ae01 | 57 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 58 | * Zero on success, -1 on error. |
mturner5 | 0:0d6b77c9ae01 | 59 | */ |
mturner5 | 0:0d6b77c9ae01 | 60 | virtual int close() = 0; |
mturner5 | 0:0d6b77c9ae01 | 61 | |
mturner5 | 0:0d6b77c9ae01 | 62 | /** Function read |
mturner5 | 0:0d6b77c9ae01 | 63 | * Reads the contents of the file into a buffer |
mturner5 | 0:0d6b77c9ae01 | 64 | * |
mturner5 | 0:0d6b77c9ae01 | 65 | * @param buffer the buffer to read in to |
mturner5 | 0:0d6b77c9ae01 | 66 | * @param length the number of characters to read |
mturner5 | 0:0d6b77c9ae01 | 67 | * |
mturner5 | 0:0d6b77c9ae01 | 68 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 69 | * The number of characters read (zero at end of file) on success, -1 on error. |
mturner5 | 0:0d6b77c9ae01 | 70 | */ |
mturner5 | 0:0d6b77c9ae01 | 71 | virtual ssize_t read(void* buffer, size_t length) = 0; |
mturner5 | 0:0d6b77c9ae01 | 72 | |
mturner5 | 0:0d6b77c9ae01 | 73 | /** Check if the handle is for a interactive terminal device. |
mturner5 | 0:0d6b77c9ae01 | 74 | * If so, line buffered behaviour is used by default |
mturner5 | 0:0d6b77c9ae01 | 75 | * |
mturner5 | 0:0d6b77c9ae01 | 76 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 77 | * 1 if it is a terminal, |
mturner5 | 0:0d6b77c9ae01 | 78 | * 0 otherwise |
mturner5 | 0:0d6b77c9ae01 | 79 | */ |
mturner5 | 0:0d6b77c9ae01 | 80 | virtual int isatty() = 0; |
mturner5 | 0:0d6b77c9ae01 | 81 | |
mturner5 | 0:0d6b77c9ae01 | 82 | /** Move the file position to a given offset from a given location. |
mturner5 | 0:0d6b77c9ae01 | 83 | * |
mturner5 | 0:0d6b77c9ae01 | 84 | * @param offset The offset from whence to move to |
mturner5 | 0:0d6b77c9ae01 | 85 | * @param whence SEEK_SET for the start of the file, SEEK_CUR for the |
mturner5 | 0:0d6b77c9ae01 | 86 | * current file position, or SEEK_END for the end of the file. |
mturner5 | 0:0d6b77c9ae01 | 87 | * |
mturner5 | 0:0d6b77c9ae01 | 88 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 89 | * new file position on success, |
mturner5 | 0:0d6b77c9ae01 | 90 | * -1 on failure or unsupported |
mturner5 | 0:0d6b77c9ae01 | 91 | */ |
mturner5 | 0:0d6b77c9ae01 | 92 | virtual off_t lseek(off_t offset, int whence) = 0; |
mturner5 | 0:0d6b77c9ae01 | 93 | |
mturner5 | 0:0d6b77c9ae01 | 94 | /** Flush any buffers associated with the FileHandle, ensuring it |
mturner5 | 0:0d6b77c9ae01 | 95 | * is up to date on disk |
mturner5 | 0:0d6b77c9ae01 | 96 | * |
mturner5 | 0:0d6b77c9ae01 | 97 | * @returns |
mturner5 | 0:0d6b77c9ae01 | 98 | * 0 on success or un-needed, |
mturner5 | 0:0d6b77c9ae01 | 99 | * -1 on error |
mturner5 | 0:0d6b77c9ae01 | 100 | */ |
mturner5 | 0:0d6b77c9ae01 | 101 | virtual int fsync() = 0; |
mturner5 | 0:0d6b77c9ae01 | 102 | |
mturner5 | 0:0d6b77c9ae01 | 103 | virtual off_t flen() { |
mturner5 | 0:0d6b77c9ae01 | 104 | /* remember our current position */ |
mturner5 | 0:0d6b77c9ae01 | 105 | off_t pos = lseek(0, SEEK_CUR); |
mturner5 | 0:0d6b77c9ae01 | 106 | if(pos == -1) return -1; |
mturner5 | 0:0d6b77c9ae01 | 107 | /* seek to the end to get the file length */ |
mturner5 | 0:0d6b77c9ae01 | 108 | off_t res = lseek(0, SEEK_END); |
mturner5 | 0:0d6b77c9ae01 | 109 | /* return to our old position */ |
mturner5 | 0:0d6b77c9ae01 | 110 | lseek(pos, SEEK_SET); |
mturner5 | 0:0d6b77c9ae01 | 111 | return res; |
mturner5 | 0:0d6b77c9ae01 | 112 | } |
mturner5 | 0:0d6b77c9ae01 | 113 | |
mturner5 | 0:0d6b77c9ae01 | 114 | virtual ~FileHandle(); |
mturner5 | 0:0d6b77c9ae01 | 115 | }; |
mturner5 | 0:0d6b77c9ae01 | 116 | |
mturner5 | 0:0d6b77c9ae01 | 117 | } // namespace mbed |
mturner5 | 0:0d6b77c9ae01 | 118 | |
mturner5 | 0:0d6b77c9ae01 | 119 | #endif |