Soundharrajan
Fork of mbed by
Timeout.h@4:5d1359a283bc, 2008-11-27 (annotated)
- Committer:
- simon.ford@mbed.co.uk
- Date:
- Thu Nov 27 16:23:24 2008 +0000
- Revision:
- 4:5d1359a283bc
- Parent:
- 3:aefd12a1f1c5
- Child:
- 9:cf0d45ce28a6
New version of framework: vectors, environment, platform, base and file system
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon.ford@mbed.co.uk | 4:5d1359a283bc | 1 | /* mbed Microcontroller Library - Timeout |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 2 | * Copyright (c) 2007-2008, sford |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 3 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 4 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 5 | #ifndef MBED_TIMEOUT_H |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 6 | #define MBED_TIMEOUT_H |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 7 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 8 | #include "Ticker.h" |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 9 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 10 | namespace mbed { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 11 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 12 | /* Class: Timeout |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 13 | * A Timeout is used to call a function at a point in the future |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 14 | * |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 15 | * You can use as many seperate Timeout objects as you require. |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 16 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 17 | class Timeout : public Ticker { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 18 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 19 | #if 0 // For documentation |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 20 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 21 | /* Function: attach |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 22 | * Attach a function to be called by the Timeout, specifiying the delay in seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 23 | * |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 24 | * Variables: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 25 | * fptr - pointer to the function to be called |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 26 | * t - the time before the call in seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 27 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 28 | void attach(void (*fptr)(void), float t) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 29 | attach_us(fptr, t * 1000000.0f); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 30 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 31 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 32 | /* Function: attach |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 33 | * Attach a member function to be called by the Timeout, specifiying the delay in seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 34 | * |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 35 | * Variables: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 36 | * tptr - pointer to the object to call the member function on |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 37 | * mptr - pointer to the member function to be called |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 38 | * t - the time before the calls in seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 39 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 40 | template<typename T> |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 41 | void attach(T* tptr, void (T::*mptr)(void), float t) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 42 | attach_us(tptr, mptr, t * 1000000.0f); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 43 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 44 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 45 | /* Function: attach_us |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 46 | * Attach a function to be called by the Timeout, specifiying the delay in micro-seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 47 | * |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 48 | * Variables: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 49 | * fptr - pointer to the function to be called |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 50 | * t - the time before the call in micro-seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 51 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 52 | void attach_us(void (*fptr)(void), unsigned int t) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 53 | _function.attach(fptr); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 54 | setup(t); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 55 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 56 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 57 | /* Function: attach_us |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 58 | * Attach a member function to be called by the Timeout, specifiying the delay in micro-seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 59 | * |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 60 | * Variables: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 61 | * tptr - pointer to the object to call the member function on |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 62 | * mptr - pointer to the member function to be called |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 63 | * t - the time before the call in micro-seconds |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 64 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 65 | template<typename T> |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 66 | void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 67 | _function.attach(tptr, mptr); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 68 | setup(t); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 69 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 70 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 71 | /* Function: detach |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 72 | * Detach the function |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 73 | */ |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 74 | void detach(); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 75 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 76 | #endif |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 77 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 78 | protected: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 79 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 80 | virtual void handler(); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 81 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 82 | }; |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 83 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 84 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 85 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 86 | #endif |