mbed

Dependents:   DHTSensor_Test K64F_eCompass_OneNET_JW

Committer:
mbotkinl
Date:
Wed Feb 25 20:22:22 2015 +0000
Revision:
0:2cc6bb4d7fea
Working code to read Temperature and Humidity readings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbotkinl 0:2cc6bb4d7fea 1 /* mbed Microcontroller Library
mbotkinl 0:2cc6bb4d7fea 2 * Copyright (c) 2006-2013 ARM Limited
mbotkinl 0:2cc6bb4d7fea 3 *
mbotkinl 0:2cc6bb4d7fea 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbotkinl 0:2cc6bb4d7fea 5 * you may not use this file except in compliance with the License.
mbotkinl 0:2cc6bb4d7fea 6 * You may obtain a copy of the License at
mbotkinl 0:2cc6bb4d7fea 7 *
mbotkinl 0:2cc6bb4d7fea 8 * http://www.apache.org/licenses/LICENSE-2.0
mbotkinl 0:2cc6bb4d7fea 9 *
mbotkinl 0:2cc6bb4d7fea 10 * Unless required by applicable law or agreed to in writing, software
mbotkinl 0:2cc6bb4d7fea 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbotkinl 0:2cc6bb4d7fea 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbotkinl 0:2cc6bb4d7fea 13 * See the License for the specific language governing permissions and
mbotkinl 0:2cc6bb4d7fea 14 * limitations under the License.
mbotkinl 0:2cc6bb4d7fea 15 */
mbotkinl 0:2cc6bb4d7fea 16 #ifndef MBED_DIRHANDLE_H
mbotkinl 0:2cc6bb4d7fea 17 #define MBED_DIRHANDLE_H
mbotkinl 0:2cc6bb4d7fea 18
mbotkinl 0:2cc6bb4d7fea 19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
mbotkinl 0:2cc6bb4d7fea 20 # define NAME_MAX 255
mbotkinl 0:2cc6bb4d7fea 21 typedef int mode_t;
mbotkinl 0:2cc6bb4d7fea 22
mbotkinl 0:2cc6bb4d7fea 23 #else
mbotkinl 0:2cc6bb4d7fea 24 # include <sys/syslimits.h>
mbotkinl 0:2cc6bb4d7fea 25 #endif
mbotkinl 0:2cc6bb4d7fea 26
mbotkinl 0:2cc6bb4d7fea 27 #include "FileHandle.h"
mbotkinl 0:2cc6bb4d7fea 28
mbotkinl 0:2cc6bb4d7fea 29 struct dirent {
mbotkinl 0:2cc6bb4d7fea 30 char d_name[NAME_MAX+1];
mbotkinl 0:2cc6bb4d7fea 31 };
mbotkinl 0:2cc6bb4d7fea 32
mbotkinl 0:2cc6bb4d7fea 33 namespace mbed {
mbotkinl 0:2cc6bb4d7fea 34
mbotkinl 0:2cc6bb4d7fea 35 /** Represents a directory stream. Objects of this type are returned
mbotkinl 0:2cc6bb4d7fea 36 * by a FileSystemLike's opendir method. Implementations must define
mbotkinl 0:2cc6bb4d7fea 37 * at least closedir, readdir and rewinddir.
mbotkinl 0:2cc6bb4d7fea 38 *
mbotkinl 0:2cc6bb4d7fea 39 * If a FileSystemLike class defines the opendir method, then the
mbotkinl 0:2cc6bb4d7fea 40 * directories of an object of that type can be accessed by
mbotkinl 0:2cc6bb4d7fea 41 * DIR *d = opendir("/example/directory") (or opendir("/example")
mbotkinl 0:2cc6bb4d7fea 42 * to open the root of the filesystem), and then using readdir(d) etc.
mbotkinl 0:2cc6bb4d7fea 43 *
mbotkinl 0:2cc6bb4d7fea 44 * The root directory is considered to contain all FileLike and
mbotkinl 0:2cc6bb4d7fea 45 * FileSystemLike objects, so the DIR* returned by opendir("/") will
mbotkinl 0:2cc6bb4d7fea 46 * reflect this.
mbotkinl 0:2cc6bb4d7fea 47 */
mbotkinl 0:2cc6bb4d7fea 48 class DirHandle {
mbotkinl 0:2cc6bb4d7fea 49
mbotkinl 0:2cc6bb4d7fea 50 public:
mbotkinl 0:2cc6bb4d7fea 51 /** Closes the directory.
mbotkinl 0:2cc6bb4d7fea 52 *
mbotkinl 0:2cc6bb4d7fea 53 * @returns
mbotkinl 0:2cc6bb4d7fea 54 * 0 on success,
mbotkinl 0:2cc6bb4d7fea 55 * -1 on error.
mbotkinl 0:2cc6bb4d7fea 56 */
mbotkinl 0:2cc6bb4d7fea 57 virtual int closedir()=0;
mbotkinl 0:2cc6bb4d7fea 58
mbotkinl 0:2cc6bb4d7fea 59 /** Return the directory entry at the current position, and
mbotkinl 0:2cc6bb4d7fea 60 * advances the position to the next entry.
mbotkinl 0:2cc6bb4d7fea 61 *
mbotkinl 0:2cc6bb4d7fea 62 * @returns
mbotkinl 0:2cc6bb4d7fea 63 * A pointer to a dirent structure representing the
mbotkinl 0:2cc6bb4d7fea 64 * directory entry at the current position, or NULL on reaching
mbotkinl 0:2cc6bb4d7fea 65 * end of directory or error.
mbotkinl 0:2cc6bb4d7fea 66 */
mbotkinl 0:2cc6bb4d7fea 67 virtual struct dirent *readdir()=0;
mbotkinl 0:2cc6bb4d7fea 68
mbotkinl 0:2cc6bb4d7fea 69 /** Resets the position to the beginning of the directory.
mbotkinl 0:2cc6bb4d7fea 70 */
mbotkinl 0:2cc6bb4d7fea 71 virtual void rewinddir()=0;
mbotkinl 0:2cc6bb4d7fea 72
mbotkinl 0:2cc6bb4d7fea 73 /** Returns the current position of the DirHandle.
mbotkinl 0:2cc6bb4d7fea 74 *
mbotkinl 0:2cc6bb4d7fea 75 * @returns
mbotkinl 0:2cc6bb4d7fea 76 * the current position,
mbotkinl 0:2cc6bb4d7fea 77 * -1 on error.
mbotkinl 0:2cc6bb4d7fea 78 */
mbotkinl 0:2cc6bb4d7fea 79 virtual off_t telldir() { return -1; }
mbotkinl 0:2cc6bb4d7fea 80
mbotkinl 0:2cc6bb4d7fea 81 /** Sets the position of the DirHandle.
mbotkinl 0:2cc6bb4d7fea 82 *
mbotkinl 0:2cc6bb4d7fea 83 * @param location The location to seek to. Must be a value returned by telldir.
mbotkinl 0:2cc6bb4d7fea 84 */
mbotkinl 0:2cc6bb4d7fea 85 virtual void seekdir(off_t location) { }
mbotkinl 0:2cc6bb4d7fea 86
mbotkinl 0:2cc6bb4d7fea 87 virtual ~DirHandle() {}
mbotkinl 0:2cc6bb4d7fea 88 };
mbotkinl 0:2cc6bb4d7fea 89
mbotkinl 0:2cc6bb4d7fea 90 } // namespace mbed
mbotkinl 0:2cc6bb4d7fea 91
mbotkinl 0:2cc6bb4d7fea 92 typedef mbed::DirHandle DIR;
mbotkinl 0:2cc6bb4d7fea 93
mbotkinl 0:2cc6bb4d7fea 94 extern "C" {
mbotkinl 0:2cc6bb4d7fea 95 DIR *opendir(const char*);
mbotkinl 0:2cc6bb4d7fea 96 struct dirent *readdir(DIR *);
mbotkinl 0:2cc6bb4d7fea 97 int closedir(DIR*);
mbotkinl 0:2cc6bb4d7fea 98 void rewinddir(DIR*);
mbotkinl 0:2cc6bb4d7fea 99 long telldir(DIR*);
mbotkinl 0:2cc6bb4d7fea 100 void seekdir(DIR*, long);
mbotkinl 0:2cc6bb4d7fea 101 int mkdir(const char *name, mode_t n);
mbotkinl 0:2cc6bb4d7fea 102 };
mbotkinl 0:2cc6bb4d7fea 103
mbotkinl 0:2cc6bb4d7fea 104 #endif /* MBED_DIRHANDLE_H */