Yihui Xiong / Seeed_nRF51822_MPU9250

Dependencies:   eMPL_MPU

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Thu Dec 10 08:00:18 2015 +0000
Revision:
5:9b240c1d5251
get 9dof data from mpu9250

Who changed what in which revision?

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