temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IKobayashi 0:c88c3b616c00 1 /* mbed Microcontroller Library
IKobayashi 0:c88c3b616c00 2 * Copyright (c) 2006-2013 ARM Limited
IKobayashi 0:c88c3b616c00 3 *
IKobayashi 0:c88c3b616c00 4 * Licensed under the Apache License, Version 2.0 (the "License");
IKobayashi 0:c88c3b616c00 5 * you may not use this file except in compliance with the License.
IKobayashi 0:c88c3b616c00 6 * You may obtain a copy of the License at
IKobayashi 0:c88c3b616c00 7 *
IKobayashi 0:c88c3b616c00 8 * http://www.apache.org/licenses/LICENSE-2.0
IKobayashi 0:c88c3b616c00 9 *
IKobayashi 0:c88c3b616c00 10 * Unless required by applicable law or agreed to in writing, software
IKobayashi 0:c88c3b616c00 11 * distributed under the License is distributed on an "AS IS" BASIS,
IKobayashi 0:c88c3b616c00 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
IKobayashi 0:c88c3b616c00 13 * See the License for the specific language governing permissions and
IKobayashi 0:c88c3b616c00 14 * limitations under the License.
IKobayashi 0:c88c3b616c00 15 */
IKobayashi 0:c88c3b616c00 16 #ifndef MBED_TICKER_H
IKobayashi 0:c88c3b616c00 17 #define MBED_TICKER_H
IKobayashi 0:c88c3b616c00 18
IKobayashi 0:c88c3b616c00 19 #include "drivers/TimerEvent.h"
IKobayashi 0:c88c3b616c00 20 #include "platform/Callback.h"
IKobayashi 0:c88c3b616c00 21 #include "platform/toolchain.h"
IKobayashi 0:c88c3b616c00 22
IKobayashi 0:c88c3b616c00 23 namespace mbed {
IKobayashi 0:c88c3b616c00 24 /** \addtogroup drivers */
IKobayashi 0:c88c3b616c00 25 /** @{*/
IKobayashi 0:c88c3b616c00 26
IKobayashi 0:c88c3b616c00 27 /** A Ticker is used to call a function at a recurring interval
IKobayashi 0:c88c3b616c00 28 *
IKobayashi 0:c88c3b616c00 29 * You can use as many seperate Ticker objects as you require.
IKobayashi 0:c88c3b616c00 30 *
IKobayashi 0:c88c3b616c00 31 * @Note Synchronization level: Interrupt safe
IKobayashi 0:c88c3b616c00 32 *
IKobayashi 0:c88c3b616c00 33 * Example:
IKobayashi 0:c88c3b616c00 34 * @code
IKobayashi 0:c88c3b616c00 35 * // Toggle the blinking led after 5 seconds
IKobayashi 0:c88c3b616c00 36 *
IKobayashi 0:c88c3b616c00 37 * #include "mbed.h"
IKobayashi 0:c88c3b616c00 38 *
IKobayashi 0:c88c3b616c00 39 * Ticker timer;
IKobayashi 0:c88c3b616c00 40 * DigitalOut led1(LED1);
IKobayashi 0:c88c3b616c00 41 * DigitalOut led2(LED2);
IKobayashi 0:c88c3b616c00 42 *
IKobayashi 0:c88c3b616c00 43 * int flip = 0;
IKobayashi 0:c88c3b616c00 44 *
IKobayashi 0:c88c3b616c00 45 * void attime() {
IKobayashi 0:c88c3b616c00 46 * flip = !flip;
IKobayashi 0:c88c3b616c00 47 * }
IKobayashi 0:c88c3b616c00 48 *
IKobayashi 0:c88c3b616c00 49 * int main() {
IKobayashi 0:c88c3b616c00 50 * timer.attach(&attime, 5);
IKobayashi 0:c88c3b616c00 51 * while(1) {
IKobayashi 0:c88c3b616c00 52 * if(flip == 0) {
IKobayashi 0:c88c3b616c00 53 * led1 = !led1;
IKobayashi 0:c88c3b616c00 54 * } else {
IKobayashi 0:c88c3b616c00 55 * led2 = !led2;
IKobayashi 0:c88c3b616c00 56 * }
IKobayashi 0:c88c3b616c00 57 * wait(0.2);
IKobayashi 0:c88c3b616c00 58 * }
IKobayashi 0:c88c3b616c00 59 * }
IKobayashi 0:c88c3b616c00 60 * @endcode
IKobayashi 0:c88c3b616c00 61 */
IKobayashi 0:c88c3b616c00 62 class Ticker : public TimerEvent {
IKobayashi 0:c88c3b616c00 63
IKobayashi 0:c88c3b616c00 64 public:
IKobayashi 0:c88c3b616c00 65 Ticker() : TimerEvent() {
IKobayashi 0:c88c3b616c00 66 }
IKobayashi 0:c88c3b616c00 67
IKobayashi 0:c88c3b616c00 68 Ticker(const ticker_data_t *data) : TimerEvent(data) {
IKobayashi 0:c88c3b616c00 69 data->interface->init();
IKobayashi 0:c88c3b616c00 70 }
IKobayashi 0:c88c3b616c00 71
IKobayashi 0:c88c3b616c00 72 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
IKobayashi 0:c88c3b616c00 73 *
IKobayashi 0:c88c3b616c00 74 * @param func pointer to the function to be called
IKobayashi 0:c88c3b616c00 75 * @param t the time between calls in seconds
IKobayashi 0:c88c3b616c00 76 */
IKobayashi 0:c88c3b616c00 77 void attach(Callback<void()> func, float t) {
IKobayashi 0:c88c3b616c00 78 attach_us(func, t * 1000000.0f);
IKobayashi 0:c88c3b616c00 79 }
IKobayashi 0:c88c3b616c00 80
IKobayashi 0:c88c3b616c00 81 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
IKobayashi 0:c88c3b616c00 82 *
IKobayashi 0:c88c3b616c00 83 * @param obj pointer to the object to call the member function on
IKobayashi 0:c88c3b616c00 84 * @param method pointer to the member function to be called
IKobayashi 0:c88c3b616c00 85 * @param t the time between calls in seconds
IKobayashi 0:c88c3b616c00 86 * @deprecated
IKobayashi 0:c88c3b616c00 87 * The attach function does not support cv-qualifiers. Replaced by
IKobayashi 0:c88c3b616c00 88 * attach(callback(obj, method), t).
IKobayashi 0:c88c3b616c00 89 */
IKobayashi 0:c88c3b616c00 90 template<typename T, typename M>
IKobayashi 0:c88c3b616c00 91 MBED_DEPRECATED_SINCE("mbed-os-5.1",
IKobayashi 0:c88c3b616c00 92 "The attach function does not support cv-qualifiers. Replaced by "
IKobayashi 0:c88c3b616c00 93 "attach(callback(obj, method), t).")
IKobayashi 0:c88c3b616c00 94 void attach(T *obj, M method, float t) {
IKobayashi 0:c88c3b616c00 95 attach(callback(obj, method), t);
IKobayashi 0:c88c3b616c00 96 }
IKobayashi 0:c88c3b616c00 97
IKobayashi 0:c88c3b616c00 98 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
IKobayashi 0:c88c3b616c00 99 *
IKobayashi 0:c88c3b616c00 100 * @param fptr pointer to the function to be called
IKobayashi 0:c88c3b616c00 101 * @param t the time between calls in micro-seconds
IKobayashi 0:c88c3b616c00 102 */
IKobayashi 0:c88c3b616c00 103 void attach_us(Callback<void()> func, timestamp_t t) {
IKobayashi 0:c88c3b616c00 104 _function.attach(func);
IKobayashi 0:c88c3b616c00 105 setup(t);
IKobayashi 0:c88c3b616c00 106 }
IKobayashi 0:c88c3b616c00 107
IKobayashi 0:c88c3b616c00 108 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
IKobayashi 0:c88c3b616c00 109 *
IKobayashi 0:c88c3b616c00 110 * @param tptr pointer to the object to call the member function on
IKobayashi 0:c88c3b616c00 111 * @param mptr pointer to the member function to be called
IKobayashi 0:c88c3b616c00 112 * @param t the time between calls in micro-seconds
IKobayashi 0:c88c3b616c00 113 * @deprecated
IKobayashi 0:c88c3b616c00 114 * The attach_us function does not support cv-qualifiers. Replaced by
IKobayashi 0:c88c3b616c00 115 * attach_us(callback(obj, method), t).
IKobayashi 0:c88c3b616c00 116 */
IKobayashi 0:c88c3b616c00 117 template<typename T, typename M>
IKobayashi 0:c88c3b616c00 118 MBED_DEPRECATED_SINCE("mbed-os-5.1",
IKobayashi 0:c88c3b616c00 119 "The attach_us function does not support cv-qualifiers. Replaced by "
IKobayashi 0:c88c3b616c00 120 "attach_us(callback(obj, method), t).")
IKobayashi 0:c88c3b616c00 121 void attach_us(T *obj, M method, timestamp_t t) {
IKobayashi 0:c88c3b616c00 122 attach_us(Callback<void()>(obj, method), t);
IKobayashi 0:c88c3b616c00 123 }
IKobayashi 0:c88c3b616c00 124
IKobayashi 0:c88c3b616c00 125 virtual ~Ticker() {
IKobayashi 0:c88c3b616c00 126 detach();
IKobayashi 0:c88c3b616c00 127 }
IKobayashi 0:c88c3b616c00 128
IKobayashi 0:c88c3b616c00 129 /** Detach the function
IKobayashi 0:c88c3b616c00 130 */
IKobayashi 0:c88c3b616c00 131 void detach();
IKobayashi 0:c88c3b616c00 132
IKobayashi 0:c88c3b616c00 133 protected:
IKobayashi 0:c88c3b616c00 134 void setup(timestamp_t t);
IKobayashi 0:c88c3b616c00 135 virtual void handler();
IKobayashi 0:c88c3b616c00 136
IKobayashi 0:c88c3b616c00 137 protected:
IKobayashi 0:c88c3b616c00 138 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
IKobayashi 0:c88c3b616c00 139 Callback<void()> _function; /**< Callback. */
IKobayashi 0:c88c3b616c00 140 };
IKobayashi 0:c88c3b616c00 141
IKobayashi 0:c88c3b616c00 142 } // namespace mbed
IKobayashi 0:c88c3b616c00 143
IKobayashi 0:c88c3b616c00 144 #endif
IKobayashi 0:c88c3b616c00 145
IKobayashi 0:c88c3b616c00 146 /** @}*/