PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

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