Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

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