Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2006-2013 ARM Limited
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sahilmgandhi 18:6a4db94011d3 5 * you may not use this file except in compliance with the License.
sahilmgandhi 18:6a4db94011d3 6 * You may obtain a copy of the License at
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * http://www.apache.org/licenses/LICENSE-2.0
sahilmgandhi 18:6a4db94011d3 9 *
sahilmgandhi 18:6a4db94011d3 10 * Unless required by applicable law or agreed to in writing, software
sahilmgandhi 18:6a4db94011d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sahilmgandhi 18:6a4db94011d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sahilmgandhi 18:6a4db94011d3 13 * See the License for the specific language governing permissions and
sahilmgandhi 18:6a4db94011d3 14 * limitations under the License.
sahilmgandhi 18:6a4db94011d3 15 */
sahilmgandhi 18:6a4db94011d3 16 #ifndef MBED_FILEHANDLE_H
sahilmgandhi 18:6a4db94011d3 17 #define MBED_FILEHANDLE_H
sahilmgandhi 18:6a4db94011d3 18
sahilmgandhi 18:6a4db94011d3 19 typedef int FILEHANDLE;
sahilmgandhi 18:6a4db94011d3 20
sahilmgandhi 18:6a4db94011d3 21 #include <stdio.h>
sahilmgandhi 18:6a4db94011d3 22 #include "platform/platform.h"
sahilmgandhi 18:6a4db94011d3 23
sahilmgandhi 18:6a4db94011d3 24 namespace mbed {
sahilmgandhi 18:6a4db94011d3 25 /** \addtogroup drivers */
sahilmgandhi 18:6a4db94011d3 26 /** @{*/
sahilmgandhi 18:6a4db94011d3 27
sahilmgandhi 18:6a4db94011d3 28 /** An OO equivalent of the internal FILEHANDLE variable
sahilmgandhi 18:6a4db94011d3 29 * and associated _sys_* functions.
sahilmgandhi 18:6a4db94011d3 30 *
sahilmgandhi 18:6a4db94011d3 31 * FileHandle is an abstract class, needing at least sys_write and
sahilmgandhi 18:6a4db94011d3 32 * sys_read to be implmented for a simple interactive device.
sahilmgandhi 18:6a4db94011d3 33 *
sahilmgandhi 18:6a4db94011d3 34 * No one ever directly tals to/instanciates a FileHandle - it gets
sahilmgandhi 18:6a4db94011d3 35 * created by FileSystem, and wrapped up by stdio.
sahilmgandhi 18:6a4db94011d3 36 *
sahilmgandhi 18:6a4db94011d3 37 * @Note Synchronization level: Set by subclass
sahilmgandhi 18:6a4db94011d3 38 */
sahilmgandhi 18:6a4db94011d3 39 class FileHandle {
sahilmgandhi 18:6a4db94011d3 40
sahilmgandhi 18:6a4db94011d3 41 public:
sahilmgandhi 18:6a4db94011d3 42 MBED_DEPRECATED_SINCE("mbed-os-5.4",
sahilmgandhi 18:6a4db94011d3 43 "The mbed 2 filesystem classes have been superseeded by the FileSystem api, "
sahilmgandhi 18:6a4db94011d3 44 "Replaced by File")
sahilmgandhi 18:6a4db94011d3 45 FileHandle() {}
sahilmgandhi 18:6a4db94011d3 46
sahilmgandhi 18:6a4db94011d3 47 /** Write the contents of a buffer to the file
sahilmgandhi 18:6a4db94011d3 48 *
sahilmgandhi 18:6a4db94011d3 49 * @param buffer the buffer to write from
sahilmgandhi 18:6a4db94011d3 50 * @param length the number of characters to write
sahilmgandhi 18:6a4db94011d3 51 *
sahilmgandhi 18:6a4db94011d3 52 * @returns
sahilmgandhi 18:6a4db94011d3 53 * The number of characters written (possibly 0) on success, -1 on error.
sahilmgandhi 18:6a4db94011d3 54 */
sahilmgandhi 18:6a4db94011d3 55 virtual ssize_t write(const void* buffer, size_t length) = 0;
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57 /** Close the file
sahilmgandhi 18:6a4db94011d3 58 *
sahilmgandhi 18:6a4db94011d3 59 * @returns
sahilmgandhi 18:6a4db94011d3 60 * Zero on success, -1 on error.
sahilmgandhi 18:6a4db94011d3 61 */
sahilmgandhi 18:6a4db94011d3 62 virtual int close() = 0;
sahilmgandhi 18:6a4db94011d3 63
sahilmgandhi 18:6a4db94011d3 64 /** Function read
sahilmgandhi 18:6a4db94011d3 65 * Reads the contents of the file into a buffer
sahilmgandhi 18:6a4db94011d3 66 *
sahilmgandhi 18:6a4db94011d3 67 * @param buffer the buffer to read in to
sahilmgandhi 18:6a4db94011d3 68 * @param length the number of characters to read
sahilmgandhi 18:6a4db94011d3 69 *
sahilmgandhi 18:6a4db94011d3 70 * @returns
sahilmgandhi 18:6a4db94011d3 71 * The number of characters read (zero at end of file) on success, -1 on error.
sahilmgandhi 18:6a4db94011d3 72 */
sahilmgandhi 18:6a4db94011d3 73 virtual ssize_t read(void* buffer, size_t length) = 0;
sahilmgandhi 18:6a4db94011d3 74
sahilmgandhi 18:6a4db94011d3 75 /** Check if the handle is for a interactive terminal device.
sahilmgandhi 18:6a4db94011d3 76 * If so, line buffered behaviour is used by default
sahilmgandhi 18:6a4db94011d3 77 *
sahilmgandhi 18:6a4db94011d3 78 * @returns
sahilmgandhi 18:6a4db94011d3 79 * 1 if it is a terminal,
sahilmgandhi 18:6a4db94011d3 80 * 0 otherwise
sahilmgandhi 18:6a4db94011d3 81 */
sahilmgandhi 18:6a4db94011d3 82 virtual int isatty() = 0;
sahilmgandhi 18:6a4db94011d3 83
sahilmgandhi 18:6a4db94011d3 84 /** Move the file position to a given offset from a given location.
sahilmgandhi 18:6a4db94011d3 85 *
sahilmgandhi 18:6a4db94011d3 86 * @param offset The offset from whence to move to
sahilmgandhi 18:6a4db94011d3 87 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
sahilmgandhi 18:6a4db94011d3 88 * current file position, or SEEK_END for the end of the file.
sahilmgandhi 18:6a4db94011d3 89 *
sahilmgandhi 18:6a4db94011d3 90 * @returns
sahilmgandhi 18:6a4db94011d3 91 * new file position on success,
sahilmgandhi 18:6a4db94011d3 92 * -1 on failure or unsupported
sahilmgandhi 18:6a4db94011d3 93 */
sahilmgandhi 18:6a4db94011d3 94 virtual off_t lseek(off_t offset, int whence) = 0;
sahilmgandhi 18:6a4db94011d3 95
sahilmgandhi 18:6a4db94011d3 96 /** Flush any buffers associated with the FileHandle, ensuring it
sahilmgandhi 18:6a4db94011d3 97 * is up to date on disk
sahilmgandhi 18:6a4db94011d3 98 *
sahilmgandhi 18:6a4db94011d3 99 * @returns
sahilmgandhi 18:6a4db94011d3 100 * 0 on success or un-needed,
sahilmgandhi 18:6a4db94011d3 101 * -1 on error
sahilmgandhi 18:6a4db94011d3 102 */
sahilmgandhi 18:6a4db94011d3 103 virtual int fsync() = 0;
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 virtual off_t flen() {
sahilmgandhi 18:6a4db94011d3 106 lock();
sahilmgandhi 18:6a4db94011d3 107 /* remember our current position */
sahilmgandhi 18:6a4db94011d3 108 off_t pos = lseek(0, SEEK_CUR);
sahilmgandhi 18:6a4db94011d3 109 if(pos == -1) {
sahilmgandhi 18:6a4db94011d3 110 unlock();
sahilmgandhi 18:6a4db94011d3 111 return -1;
sahilmgandhi 18:6a4db94011d3 112 }
sahilmgandhi 18:6a4db94011d3 113 /* seek to the end to get the file length */
sahilmgandhi 18:6a4db94011d3 114 off_t res = lseek(0, SEEK_END);
sahilmgandhi 18:6a4db94011d3 115 /* return to our old position */
sahilmgandhi 18:6a4db94011d3 116 lseek(pos, SEEK_SET);
sahilmgandhi 18:6a4db94011d3 117 unlock();
sahilmgandhi 18:6a4db94011d3 118 return res;
sahilmgandhi 18:6a4db94011d3 119 }
sahilmgandhi 18:6a4db94011d3 120
sahilmgandhi 18:6a4db94011d3 121 virtual ~FileHandle() {};
sahilmgandhi 18:6a4db94011d3 122
sahilmgandhi 18:6a4db94011d3 123 protected:
sahilmgandhi 18:6a4db94011d3 124
sahilmgandhi 18:6a4db94011d3 125 /** Acquire exclusive access to this object.
sahilmgandhi 18:6a4db94011d3 126 */
sahilmgandhi 18:6a4db94011d3 127 virtual void lock() {
sahilmgandhi 18:6a4db94011d3 128 // Stub
sahilmgandhi 18:6a4db94011d3 129 }
sahilmgandhi 18:6a4db94011d3 130
sahilmgandhi 18:6a4db94011d3 131 /** Release exclusive access to this object.
sahilmgandhi 18:6a4db94011d3 132 */
sahilmgandhi 18:6a4db94011d3 133 virtual void unlock() {
sahilmgandhi 18:6a4db94011d3 134 // Stub
sahilmgandhi 18:6a4db94011d3 135 }
sahilmgandhi 18:6a4db94011d3 136 };
sahilmgandhi 18:6a4db94011d3 137
sahilmgandhi 18:6a4db94011d3 138 } // namespace mbed
sahilmgandhi 18:6a4db94011d3 139
sahilmgandhi 18:6a4db94011d3 140 #endif
sahilmgandhi 18:6a4db94011d3 141
sahilmgandhi 18:6a4db94011d3 142 /** @}*/