BLE temperature profile using digital DS1820 or analog LM35 sensors

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sat Mar 07 16:23:41 2015 +0000
Revision:
0:637031152314
Working version 1.0

Who changed what in which revision?

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