strat des robots

Fork of CRAC-Strat_2017 by CRAC Team

Committer:
ClementBreteau
Date:
Fri May 19 17:14:07 2017 +0000
Revision:
17:d1594579eec6
Parent:
0:ad97421fb1fb
strat du robot, 19-05-2017, 19h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
antbig 0:ad97421fb1fb 1 /* mbed Microcontroller Library - Timeout
antbig 0:ad97421fb1fb 2 * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
antbig 0:ad97421fb1fb 3 */
antbig 0:ad97421fb1fb 4
antbig 0:ad97421fb1fb 5 #ifndef MBED_TIMEOUT_H
antbig 0:ad97421fb1fb 6 #define MBED_TIMEOUT_H
antbig 0:ad97421fb1fb 7
antbig 0:ad97421fb1fb 8 #include "Ticker.h"
antbig 0:ad97421fb1fb 9
antbig 0:ad97421fb1fb 10 namespace mbed {
antbig 0:ad97421fb1fb 11
antbig 0:ad97421fb1fb 12 /* Class: Timeout
antbig 0:ad97421fb1fb 13 * A Timeout is used to call a function at a point in the future
antbig 0:ad97421fb1fb 14 *
antbig 0:ad97421fb1fb 15 * You can use as many seperate Timeout objects as you require.
antbig 0:ad97421fb1fb 16 *
antbig 0:ad97421fb1fb 17 * Example:
antbig 0:ad97421fb1fb 18 * > // Blink until timeout.
antbig 0:ad97421fb1fb 19 * >
antbig 0:ad97421fb1fb 20 * > #include "mbed.h"
antbig 0:ad97421fb1fb 21 * >
antbig 0:ad97421fb1fb 22 * > Timeout timeout;
antbig 0:ad97421fb1fb 23 * > DigitalOut led(LED1);
antbig 0:ad97421fb1fb 24 * >
antbig 0:ad97421fb1fb 25 * > int on = 1;
antbig 0:ad97421fb1fb 26 * >
antbig 0:ad97421fb1fb 27 * > void attimeout() {
antbig 0:ad97421fb1fb 28 * > on = 0;
antbig 0:ad97421fb1fb 29 * > }
antbig 0:ad97421fb1fb 30 * >
antbig 0:ad97421fb1fb 31 * > int main() {
antbig 0:ad97421fb1fb 32 * > timeout.attach(&attimeout, 5);
antbig 0:ad97421fb1fb 33 * > while(on) {
antbig 0:ad97421fb1fb 34 * > led = !led;
antbig 0:ad97421fb1fb 35 * > wait(0.2);
antbig 0:ad97421fb1fb 36 * > }
antbig 0:ad97421fb1fb 37 * > }
antbig 0:ad97421fb1fb 38 */
antbig 0:ad97421fb1fb 39 class Timeout : public Ticker {
antbig 0:ad97421fb1fb 40
antbig 0:ad97421fb1fb 41 #if 0 // For documentation
antbig 0:ad97421fb1fb 42
antbig 0:ad97421fb1fb 43 /* Function: attach
antbig 0:ad97421fb1fb 44 * Attach a function to be called by the Timeout, specifiying the delay in seconds
antbig 0:ad97421fb1fb 45 *
antbig 0:ad97421fb1fb 46 * Variables:
antbig 0:ad97421fb1fb 47 * fptr - pointer to the function to be called
antbig 0:ad97421fb1fb 48 * t - the time before the call in seconds
antbig 0:ad97421fb1fb 49 */
antbig 0:ad97421fb1fb 50 void attach(void (*fptr)(void), float t) {
antbig 0:ad97421fb1fb 51 attach_us(fptr, t * 1000000.0f);
antbig 0:ad97421fb1fb 52 }
antbig 0:ad97421fb1fb 53
antbig 0:ad97421fb1fb 54 /* Function: attach
antbig 0:ad97421fb1fb 55 * Attach a member function to be called by the Timeout, specifiying the delay in seconds
antbig 0:ad97421fb1fb 56 *
antbig 0:ad97421fb1fb 57 * Variables:
antbig 0:ad97421fb1fb 58 * tptr - pointer to the object to call the member function on
antbig 0:ad97421fb1fb 59 * mptr - pointer to the member function to be called
antbig 0:ad97421fb1fb 60 * t - the time before the calls in seconds
antbig 0:ad97421fb1fb 61 */
antbig 0:ad97421fb1fb 62 template<typename T>
antbig 0:ad97421fb1fb 63 void attach(T* tptr, void (T::*mptr)(void), float t) {
antbig 0:ad97421fb1fb 64 attach_us(tptr, mptr, t * 1000000.0f);
antbig 0:ad97421fb1fb 65 }
antbig 0:ad97421fb1fb 66
antbig 0:ad97421fb1fb 67 /* Function: attach_us
antbig 0:ad97421fb1fb 68 * Attach a function to be called by the Timeout, specifiying the delay in micro-seconds
antbig 0:ad97421fb1fb 69 *
antbig 0:ad97421fb1fb 70 * Variables:
antbig 0:ad97421fb1fb 71 * fptr - pointer to the function to be called
antbig 0:ad97421fb1fb 72 * t - the time before the call in micro-seconds
antbig 0:ad97421fb1fb 73 */
antbig 0:ad97421fb1fb 74 void attach_us(void (*fptr)(void), unsigned int t) {
antbig 0:ad97421fb1fb 75 _function.attach(fptr);
antbig 0:ad97421fb1fb 76 setup(t);
antbig 0:ad97421fb1fb 77 }
antbig 0:ad97421fb1fb 78
antbig 0:ad97421fb1fb 79 /* Function: attach_us
antbig 0:ad97421fb1fb 80 * Attach a member function to be called by the Timeout, specifiying the delay in micro-seconds
antbig 0:ad97421fb1fb 81 *
antbig 0:ad97421fb1fb 82 * Variables:
antbig 0:ad97421fb1fb 83 * tptr - pointer to the object to call the member function on
antbig 0:ad97421fb1fb 84 * mptr - pointer to the member function to be called
antbig 0:ad97421fb1fb 85 * t - the time before the call in micro-seconds
antbig 0:ad97421fb1fb 86 */
antbig 0:ad97421fb1fb 87 template<typename T>
antbig 0:ad97421fb1fb 88 void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) {
antbig 0:ad97421fb1fb 89 _function.attach(tptr, mptr);
antbig 0:ad97421fb1fb 90 setup(t);
antbig 0:ad97421fb1fb 91 }
antbig 0:ad97421fb1fb 92
antbig 0:ad97421fb1fb 93 /* Function: detach
antbig 0:ad97421fb1fb 94 * Detach the function
antbig 0:ad97421fb1fb 95 */
antbig 0:ad97421fb1fb 96 void detach();
antbig 0:ad97421fb1fb 97
antbig 0:ad97421fb1fb 98 #endif
antbig 0:ad97421fb1fb 99
antbig 0:ad97421fb1fb 100 protected:
antbig 0:ad97421fb1fb 101
antbig 0:ad97421fb1fb 102 virtual void handler();
antbig 0:ad97421fb1fb 103
antbig 0:ad97421fb1fb 104 };
antbig 0:ad97421fb1fb 105
antbig 0:ad97421fb1fb 106 } // namespace mbed
antbig 0:ad97421fb1fb 107
antbig 0:ad97421fb1fb 108 #endif