Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

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_FILELIKE_H
sahilmgandhi 18:6a4db94011d3 17 #define MBED_FILELIKE_H
sahilmgandhi 18:6a4db94011d3 18
sahilmgandhi 18:6a4db94011d3 19 #include "platform/mbed_toolchain.h"
sahilmgandhi 18:6a4db94011d3 20 #include "drivers/FileBase.h"
sahilmgandhi 18:6a4db94011d3 21
sahilmgandhi 18:6a4db94011d3 22 namespace mbed {
sahilmgandhi 18:6a4db94011d3 23 /** \addtogroup drivers */
sahilmgandhi 18:6a4db94011d3 24 /** @{*/
sahilmgandhi 18:6a4db94011d3 25
sahilmgandhi 18:6a4db94011d3 26
sahilmgandhi 18:6a4db94011d3 27 /* Class FileLike
sahilmgandhi 18:6a4db94011d3 28 * A file-like object is one that can be opened with fopen by
sahilmgandhi 18:6a4db94011d3 29 * fopen("/name", mode).
sahilmgandhi 18:6a4db94011d3 30 *
sahilmgandhi 18:6a4db94011d3 31 * @Note Synchronization level: Set by subclass
sahilmgandhi 18:6a4db94011d3 32 */
sahilmgandhi 18:6a4db94011d3 33 class FileLike : public FileBase {
sahilmgandhi 18:6a4db94011d3 34 public:
sahilmgandhi 18:6a4db94011d3 35 /** Constructor FileLike
sahilmgandhi 18:6a4db94011d3 36 *
sahilmgandhi 18:6a4db94011d3 37 * @param name The name to use to open the file.
sahilmgandhi 18:6a4db94011d3 38 */
sahilmgandhi 18:6a4db94011d3 39 FileLike(const char *name = NULL) : FileBase(name, FilePathType) {}
sahilmgandhi 18:6a4db94011d3 40 virtual ~FileLike() {}
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 /** Read the contents of a file into a buffer
sahilmgandhi 18:6a4db94011d3 43 *
sahilmgandhi 18:6a4db94011d3 44 * @param buffer The buffer to read in to
sahilmgandhi 18:6a4db94011d3 45 * @param size The number of bytes to read
sahilmgandhi 18:6a4db94011d3 46 * @return The number of bytes read, 0 at end of file, negative error on failure
sahilmgandhi 18:6a4db94011d3 47 */
sahilmgandhi 18:6a4db94011d3 48 virtual ssize_t read(void *buffer, size_t len) = 0;
sahilmgandhi 18:6a4db94011d3 49
sahilmgandhi 18:6a4db94011d3 50 /** Write the contents of a buffer to a file
sahilmgandhi 18:6a4db94011d3 51 *
sahilmgandhi 18:6a4db94011d3 52 * @param buffer The buffer to write from
sahilmgandhi 18:6a4db94011d3 53 * @param size The number of bytes to write
sahilmgandhi 18:6a4db94011d3 54 * @return The number of bytes written, negative error on failure
sahilmgandhi 18:6a4db94011d3 55 */
sahilmgandhi 18:6a4db94011d3 56 virtual ssize_t write(const void *buffer, size_t len) = 0;
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 /** Close a file
sahilmgandhi 18:6a4db94011d3 59 *
sahilmgandhi 18:6a4db94011d3 60 * @return 0 on success, negative error code on failure
sahilmgandhi 18:6a4db94011d3 61 */
sahilmgandhi 18:6a4db94011d3 62 virtual int close() = 0;
sahilmgandhi 18:6a4db94011d3 63
sahilmgandhi 18:6a4db94011d3 64 /** Flush any buffers associated with the file
sahilmgandhi 18:6a4db94011d3 65 *
sahilmgandhi 18:6a4db94011d3 66 * @return 0 on success, negative error code on failure
sahilmgandhi 18:6a4db94011d3 67 */
sahilmgandhi 18:6a4db94011d3 68 virtual int sync() = 0;
sahilmgandhi 18:6a4db94011d3 69
sahilmgandhi 18:6a4db94011d3 70 /** Check if the file in an interactive terminal device
sahilmgandhi 18:6a4db94011d3 71 *
sahilmgandhi 18:6a4db94011d3 72 * @return True if the file is a terminal
sahilmgandhi 18:6a4db94011d3 73 */
sahilmgandhi 18:6a4db94011d3 74 virtual int isatty() = 0;
sahilmgandhi 18:6a4db94011d3 75
sahilmgandhi 18:6a4db94011d3 76 /** Move the file position to a given offset from from a given location
sahilmgandhi 18:6a4db94011d3 77 *
sahilmgandhi 18:6a4db94011d3 78 * @param offset The offset from whence to move to
sahilmgandhi 18:6a4db94011d3 79 * @param whence The start of where to seek
sahilmgandhi 18:6a4db94011d3 80 * SEEK_SET to start from beginning of file,
sahilmgandhi 18:6a4db94011d3 81 * SEEK_CUR to start from current position in file,
sahilmgandhi 18:6a4db94011d3 82 * SEEK_END to start from end of file
sahilmgandhi 18:6a4db94011d3 83 * @return The new offset of the file
sahilmgandhi 18:6a4db94011d3 84 */
sahilmgandhi 18:6a4db94011d3 85 virtual off_t seek(off_t offset, int whence = SEEK_SET) = 0;
sahilmgandhi 18:6a4db94011d3 86
sahilmgandhi 18:6a4db94011d3 87 /** Get the file position of the file
sahilmgandhi 18:6a4db94011d3 88 *
sahilmgandhi 18:6a4db94011d3 89 * @return The current offset in the file
sahilmgandhi 18:6a4db94011d3 90 */
sahilmgandhi 18:6a4db94011d3 91 virtual off_t tell() = 0;
sahilmgandhi 18:6a4db94011d3 92
sahilmgandhi 18:6a4db94011d3 93 /** Rewind the file position to the beginning of the file
sahilmgandhi 18:6a4db94011d3 94 *
sahilmgandhi 18:6a4db94011d3 95 * @note This is equivalent to file_seek(file, 0, FS_SEEK_SET)
sahilmgandhi 18:6a4db94011d3 96 */
sahilmgandhi 18:6a4db94011d3 97 virtual void rewind() = 0;
sahilmgandhi 18:6a4db94011d3 98
sahilmgandhi 18:6a4db94011d3 99 /** Get the size of the file
sahilmgandhi 18:6a4db94011d3 100 *
sahilmgandhi 18:6a4db94011d3 101 * @return Size of the file in bytes
sahilmgandhi 18:6a4db94011d3 102 */
sahilmgandhi 18:6a4db94011d3 103 virtual size_t size() = 0;
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 /** Move the file position to a given offset from a given location.
sahilmgandhi 18:6a4db94011d3 106 *
sahilmgandhi 18:6a4db94011d3 107 * @param offset The offset from whence to move to
sahilmgandhi 18:6a4db94011d3 108 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
sahilmgandhi 18:6a4db94011d3 109 * current file position, or SEEK_END for the end of the file.
sahilmgandhi 18:6a4db94011d3 110 *
sahilmgandhi 18:6a4db94011d3 111 * @returns
sahilmgandhi 18:6a4db94011d3 112 * new file position on success,
sahilmgandhi 18:6a4db94011d3 113 * -1 on failure or unsupported
sahilmgandhi 18:6a4db94011d3 114 */
sahilmgandhi 18:6a4db94011d3 115 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::seek")
sahilmgandhi 18:6a4db94011d3 116 virtual off_t lseek(off_t offset, int whence) { return seek(offset, whence); }
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118 /** Flush any buffers associated with the FileHandle, ensuring it
sahilmgandhi 18:6a4db94011d3 119 * is up to date on disk
sahilmgandhi 18:6a4db94011d3 120 *
sahilmgandhi 18:6a4db94011d3 121 * @returns
sahilmgandhi 18:6a4db94011d3 122 * 0 on success or un-needed,
sahilmgandhi 18:6a4db94011d3 123 * -1 on error
sahilmgandhi 18:6a4db94011d3 124 */
sahilmgandhi 18:6a4db94011d3 125 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::sync")
sahilmgandhi 18:6a4db94011d3 126 virtual int fsync() { return sync(); }
sahilmgandhi 18:6a4db94011d3 127
sahilmgandhi 18:6a4db94011d3 128 /** Find the length of the file
sahilmgandhi 18:6a4db94011d3 129 *
sahilmgandhi 18:6a4db94011d3 130 * @returns
sahilmgandhi 18:6a4db94011d3 131 * Length of the file
sahilmgandhi 18:6a4db94011d3 132 */
sahilmgandhi 18:6a4db94011d3 133 MBED_DEPRECATED_SINCE("mbed-os-5.4", "Replaced by FileLike::size")
sahilmgandhi 18:6a4db94011d3 134 virtual off_t flen() { return size(); }
sahilmgandhi 18:6a4db94011d3 135
sahilmgandhi 18:6a4db94011d3 136 protected:
sahilmgandhi 18:6a4db94011d3 137 /** Acquire exclusive access to this object.
sahilmgandhi 18:6a4db94011d3 138 */
sahilmgandhi 18:6a4db94011d3 139 virtual void lock() {
sahilmgandhi 18:6a4db94011d3 140 // Stub
sahilmgandhi 18:6a4db94011d3 141 }
sahilmgandhi 18:6a4db94011d3 142
sahilmgandhi 18:6a4db94011d3 143 /** Release exclusive access to this object.
sahilmgandhi 18:6a4db94011d3 144 */
sahilmgandhi 18:6a4db94011d3 145 virtual void unlock() {
sahilmgandhi 18:6a4db94011d3 146 // Stub
sahilmgandhi 18:6a4db94011d3 147 }
sahilmgandhi 18:6a4db94011d3 148 };
sahilmgandhi 18:6a4db94011d3 149
sahilmgandhi 18:6a4db94011d3 150
sahilmgandhi 18:6a4db94011d3 151 /** @}*/
sahilmgandhi 18:6a4db94011d3 152 } // namespace mbed
sahilmgandhi 18:6a4db94011d3 153
sahilmgandhi 18:6a4db94011d3 154 #endif