Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
drivers/Timeout.h@1:8a094db1347f, 2020-11-09 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Nov 09 00:02:47 2020 -0500
- Revision:
- 1:8a094db1347f
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elijahsj | 1:8a094db1347f | 1 | /* mbed Microcontroller Library |
elijahsj | 1:8a094db1347f | 2 | * Copyright (c) 2006-2013 ARM Limited |
elijahsj | 1:8a094db1347f | 3 | * |
elijahsj | 1:8a094db1347f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
elijahsj | 1:8a094db1347f | 5 | * you may not use this file except in compliance with the License. |
elijahsj | 1:8a094db1347f | 6 | * You may obtain a copy of the License at |
elijahsj | 1:8a094db1347f | 7 | * |
elijahsj | 1:8a094db1347f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
elijahsj | 1:8a094db1347f | 9 | * |
elijahsj | 1:8a094db1347f | 10 | * Unless required by applicable law or agreed to in writing, software |
elijahsj | 1:8a094db1347f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
elijahsj | 1:8a094db1347f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
elijahsj | 1:8a094db1347f | 13 | * See the License for the specific language governing permissions and |
elijahsj | 1:8a094db1347f | 14 | * limitations under the License. |
elijahsj | 1:8a094db1347f | 15 | */ |
elijahsj | 1:8a094db1347f | 16 | #ifndef MBED_TIMEOUT_H |
elijahsj | 1:8a094db1347f | 17 | #define MBED_TIMEOUT_H |
elijahsj | 1:8a094db1347f | 18 | |
elijahsj | 1:8a094db1347f | 19 | #include "drivers/Ticker.h" |
elijahsj | 1:8a094db1347f | 20 | #include "platform/NonCopyable.h" |
elijahsj | 1:8a094db1347f | 21 | #include "platform/mbed_sleep.h" |
elijahsj | 1:8a094db1347f | 22 | |
elijahsj | 1:8a094db1347f | 23 | namespace mbed { |
elijahsj | 1:8a094db1347f | 24 | /** \addtogroup drivers */ |
elijahsj | 1:8a094db1347f | 25 | |
elijahsj | 1:8a094db1347f | 26 | /** A Timeout is used to call a function at a point in the future |
elijahsj | 1:8a094db1347f | 27 | * |
elijahsj | 1:8a094db1347f | 28 | * You can use as many seperate Timeout objects as you require. |
elijahsj | 1:8a094db1347f | 29 | * |
elijahsj | 1:8a094db1347f | 30 | * @note Synchronization level: Interrupt safe |
elijahsj | 1:8a094db1347f | 31 | * |
elijahsj | 1:8a094db1347f | 32 | * Example: |
elijahsj | 1:8a094db1347f | 33 | * @code |
elijahsj | 1:8a094db1347f | 34 | * // Blink until timeout. |
elijahsj | 1:8a094db1347f | 35 | * |
elijahsj | 1:8a094db1347f | 36 | * #include "mbed.h" |
elijahsj | 1:8a094db1347f | 37 | * |
elijahsj | 1:8a094db1347f | 38 | * Timeout timeout; |
elijahsj | 1:8a094db1347f | 39 | * DigitalOut led(LED1); |
elijahsj | 1:8a094db1347f | 40 | * |
elijahsj | 1:8a094db1347f | 41 | * int on = 1; |
elijahsj | 1:8a094db1347f | 42 | * |
elijahsj | 1:8a094db1347f | 43 | * void attimeout() { |
elijahsj | 1:8a094db1347f | 44 | * on = 0; |
elijahsj | 1:8a094db1347f | 45 | * } |
elijahsj | 1:8a094db1347f | 46 | * |
elijahsj | 1:8a094db1347f | 47 | * int main() { |
elijahsj | 1:8a094db1347f | 48 | * timeout.attach(&attimeout, 5); |
elijahsj | 1:8a094db1347f | 49 | * while(on) { |
elijahsj | 1:8a094db1347f | 50 | * led = !led; |
elijahsj | 1:8a094db1347f | 51 | * wait(0.2); |
elijahsj | 1:8a094db1347f | 52 | * } |
elijahsj | 1:8a094db1347f | 53 | * } |
elijahsj | 1:8a094db1347f | 54 | * @endcode |
elijahsj | 1:8a094db1347f | 55 | * @ingroup drivers |
elijahsj | 1:8a094db1347f | 56 | */ |
elijahsj | 1:8a094db1347f | 57 | class Timeout : public Ticker, private NonCopyable<Timeout> { |
elijahsj | 1:8a094db1347f | 58 | |
elijahsj | 1:8a094db1347f | 59 | protected: |
elijahsj | 1:8a094db1347f | 60 | virtual void handler(); |
elijahsj | 1:8a094db1347f | 61 | }; |
elijahsj | 1:8a094db1347f | 62 | |
elijahsj | 1:8a094db1347f | 63 | } // namespace mbed |
elijahsj | 1:8a094db1347f | 64 | |
elijahsj | 1:8a094db1347f | 65 | #endif |