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_CALLCHAIN_H
skrawool 0:3954a906acc2 17 #define MBED_CALLCHAIN_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/Callback.h"
skrawool 0:3954a906acc2 20 #include "platform/toolchain.h"
skrawool 0:3954a906acc2 21 #include <string.h>
skrawool 0:3954a906acc2 22
skrawool 0:3954a906acc2 23 namespace mbed {
skrawool 0:3954a906acc2 24 /** \addtogroup platform */
skrawool 0:3954a906acc2 25 /** @{*/
skrawool 0:3954a906acc2 26
skrawool 0:3954a906acc2 27 /** Group one or more functions in an instance of a CallChain, then call them in
skrawool 0:3954a906acc2 28 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
skrawool 0:3954a906acc2 29 * but can be used for other purposes.
skrawool 0:3954a906acc2 30 *
skrawool 0:3954a906acc2 31 * @Note Synchronization level: Not protected
skrawool 0:3954a906acc2 32 *
skrawool 0:3954a906acc2 33 * Example:
skrawool 0:3954a906acc2 34 * @code
skrawool 0:3954a906acc2 35 * #include "mbed.h"
skrawool 0:3954a906acc2 36 *
skrawool 0:3954a906acc2 37 * CallChain chain;
skrawool 0:3954a906acc2 38 *
skrawool 0:3954a906acc2 39 * void first(void) {
skrawool 0:3954a906acc2 40 * printf("'first' function.\n");
skrawool 0:3954a906acc2 41 * }
skrawool 0:3954a906acc2 42 *
skrawool 0:3954a906acc2 43 * void second(void) {
skrawool 0:3954a906acc2 44 * printf("'second' function.\n");
skrawool 0:3954a906acc2 45 * }
skrawool 0:3954a906acc2 46 *
skrawool 0:3954a906acc2 47 * class Test {
skrawool 0:3954a906acc2 48 * public:
skrawool 0:3954a906acc2 49 * void f(void) {
skrawool 0:3954a906acc2 50 * printf("A::f (class member).\n");
skrawool 0:3954a906acc2 51 * }
skrawool 0:3954a906acc2 52 * };
skrawool 0:3954a906acc2 53 *
skrawool 0:3954a906acc2 54 * int main() {
skrawool 0:3954a906acc2 55 * Test test;
skrawool 0:3954a906acc2 56 *
skrawool 0:3954a906acc2 57 * chain.add(second);
skrawool 0:3954a906acc2 58 * chain.add_front(first);
skrawool 0:3954a906acc2 59 * chain.add(&test, &Test::f);
skrawool 0:3954a906acc2 60 * chain.call();
skrawool 0:3954a906acc2 61 * }
skrawool 0:3954a906acc2 62 * @endcode
skrawool 0:3954a906acc2 63 */
skrawool 0:3954a906acc2 64
skrawool 0:3954a906acc2 65 typedef Callback<void()> *pFunctionPointer_t;
skrawool 0:3954a906acc2 66 class CallChainLink;
skrawool 0:3954a906acc2 67
skrawool 0:3954a906acc2 68 class CallChain {
skrawool 0:3954a906acc2 69 public:
skrawool 0:3954a906acc2 70 /** Create an empty chain
skrawool 0:3954a906acc2 71 *
skrawool 0:3954a906acc2 72 * @param size (optional) Initial size of the chain
skrawool 0:3954a906acc2 73 */
skrawool 0:3954a906acc2 74 CallChain(int size = 4);
skrawool 0:3954a906acc2 75 virtual ~CallChain();
skrawool 0:3954a906acc2 76
skrawool 0:3954a906acc2 77 /** Add a function at the end of the chain
skrawool 0:3954a906acc2 78 *
skrawool 0:3954a906acc2 79 * @param func A pointer to a void function
skrawool 0:3954a906acc2 80 *
skrawool 0:3954a906acc2 81 * @returns
skrawool 0:3954a906acc2 82 * The function object created for 'func'
skrawool 0:3954a906acc2 83 */
skrawool 0:3954a906acc2 84 pFunctionPointer_t add(Callback<void()> func);
skrawool 0:3954a906acc2 85
skrawool 0:3954a906acc2 86 /** Add a function at the end of the chain
skrawool 0:3954a906acc2 87 *
skrawool 0:3954a906acc2 88 * @param obj pointer to the object to call the member function on
skrawool 0:3954a906acc2 89 * @param method pointer to the member function to be called
skrawool 0:3954a906acc2 90 *
skrawool 0:3954a906acc2 91 * @returns
skrawool 0:3954a906acc2 92 * The function object created for 'obj' and 'method'
skrawool 0:3954a906acc2 93 *
skrawool 0:3954a906acc2 94 * @deprecated
skrawool 0:3954a906acc2 95 * The add function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 96 * add(callback(obj, method)).
skrawool 0:3954a906acc2 97 */
skrawool 0:3954a906acc2 98 template<typename T, typename M>
skrawool 0:3954a906acc2 99 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 100 "The add function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 101 "add(callback(obj, method)).")
skrawool 0:3954a906acc2 102 pFunctionPointer_t add(T *obj, M method) {
skrawool 0:3954a906acc2 103 return add(callback(obj, method));
skrawool 0:3954a906acc2 104 }
skrawool 0:3954a906acc2 105
skrawool 0:3954a906acc2 106 /** Add a function at the beginning of the chain
skrawool 0:3954a906acc2 107 *
skrawool 0:3954a906acc2 108 * @param func A pointer to a void function
skrawool 0:3954a906acc2 109 *
skrawool 0:3954a906acc2 110 * @returns
skrawool 0:3954a906acc2 111 * The function object created for 'func'
skrawool 0:3954a906acc2 112 */
skrawool 0:3954a906acc2 113 pFunctionPointer_t add_front(Callback<void()> func);
skrawool 0:3954a906acc2 114
skrawool 0:3954a906acc2 115 /** Add a function at the beginning of the chain
skrawool 0:3954a906acc2 116 *
skrawool 0:3954a906acc2 117 * @param tptr pointer to the object to call the member function on
skrawool 0:3954a906acc2 118 * @param mptr pointer to the member function to be called
skrawool 0:3954a906acc2 119 *
skrawool 0:3954a906acc2 120 * @returns
skrawool 0:3954a906acc2 121 * The function object created for 'tptr' and 'mptr'
skrawool 0:3954a906acc2 122 *
skrawool 0:3954a906acc2 123 * @deprecated
skrawool 0:3954a906acc2 124 * The add_front function does not support cv-qualifiers. Replaced by
skrawool 0:3954a906acc2 125 * add_front(callback(obj, method)).
skrawool 0:3954a906acc2 126 */
skrawool 0:3954a906acc2 127 template<typename T, typename M>
skrawool 0:3954a906acc2 128 MBED_DEPRECATED_SINCE("mbed-os-5.1",
skrawool 0:3954a906acc2 129 "The add_front function does not support cv-qualifiers. Replaced by "
skrawool 0:3954a906acc2 130 "add_front(callback(obj, method)).")
skrawool 0:3954a906acc2 131 pFunctionPointer_t add_front(T *obj, M method) {
skrawool 0:3954a906acc2 132 return add_front(callback(obj, method));
skrawool 0:3954a906acc2 133 }
skrawool 0:3954a906acc2 134
skrawool 0:3954a906acc2 135 /** Get the number of functions in the chain
skrawool 0:3954a906acc2 136 */
skrawool 0:3954a906acc2 137 int size() const;
skrawool 0:3954a906acc2 138
skrawool 0:3954a906acc2 139 /** Get a function object from the chain
skrawool 0:3954a906acc2 140 *
skrawool 0:3954a906acc2 141 * @param i function object index
skrawool 0:3954a906acc2 142 *
skrawool 0:3954a906acc2 143 * @returns
skrawool 0:3954a906acc2 144 * The function object at position 'i' in the chain
skrawool 0:3954a906acc2 145 */
skrawool 0:3954a906acc2 146 pFunctionPointer_t get(int i) const;
skrawool 0:3954a906acc2 147
skrawool 0:3954a906acc2 148 /** Look for a function object in the call chain
skrawool 0:3954a906acc2 149 *
skrawool 0:3954a906acc2 150 * @param f the function object to search
skrawool 0:3954a906acc2 151 *
skrawool 0:3954a906acc2 152 * @returns
skrawool 0:3954a906acc2 153 * The index of the function object if found, -1 otherwise.
skrawool 0:3954a906acc2 154 */
skrawool 0:3954a906acc2 155 int find(pFunctionPointer_t f) const;
skrawool 0:3954a906acc2 156
skrawool 0:3954a906acc2 157 /** Clear the call chain (remove all functions in the chain).
skrawool 0:3954a906acc2 158 */
skrawool 0:3954a906acc2 159 void clear();
skrawool 0:3954a906acc2 160
skrawool 0:3954a906acc2 161 /** Remove a function object from the chain
skrawool 0:3954a906acc2 162 *
skrawool 0:3954a906acc2 163 * @arg f the function object to remove
skrawool 0:3954a906acc2 164 *
skrawool 0:3954a906acc2 165 * @returns
skrawool 0:3954a906acc2 166 * true if the function object was found and removed, false otherwise.
skrawool 0:3954a906acc2 167 */
skrawool 0:3954a906acc2 168 bool remove(pFunctionPointer_t f);
skrawool 0:3954a906acc2 169
skrawool 0:3954a906acc2 170 /** Call all the functions in the chain in sequence
skrawool 0:3954a906acc2 171 */
skrawool 0:3954a906acc2 172 void call();
skrawool 0:3954a906acc2 173
skrawool 0:3954a906acc2 174 void operator ()(void) {
skrawool 0:3954a906acc2 175 call();
skrawool 0:3954a906acc2 176 }
skrawool 0:3954a906acc2 177 pFunctionPointer_t operator [](int i) const {
skrawool 0:3954a906acc2 178 return get(i);
skrawool 0:3954a906acc2 179 }
skrawool 0:3954a906acc2 180
skrawool 0:3954a906acc2 181 /* disallow copy constructor and assignment operators */
skrawool 0:3954a906acc2 182 private:
skrawool 0:3954a906acc2 183 CallChain(const CallChain&);
skrawool 0:3954a906acc2 184 CallChain & operator = (const CallChain&);
skrawool 0:3954a906acc2 185 CallChainLink *_chain;
skrawool 0:3954a906acc2 186 };
skrawool 0:3954a906acc2 187
skrawool 0:3954a906acc2 188 } // namespace mbed
skrawool 0:3954a906acc2 189
skrawool 0:3954a906acc2 190 #endif
skrawool 0:3954a906acc2 191
skrawool 0:3954a906acc2 192 /** @}*/