PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
Pokitto
Date:
Sat Oct 07 21:31:12 2017 +0000
Revision:
5:7e5c566b1760
mbed-pokitto integrated

Who changed what in which revision?

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