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.
Fork of autonomousRobotAndroid by
Task.h
00001 #ifndef _TASK_H_ 00002 #define _TASK_H_ 00003 00004 #include "mbed.h" 00005 00006 /** 00007 * @author Christian Burri 00008 * 00009 * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe 00010 * All rights reserved. 00011 * 00012 * @brief 00013 * The <code>Task</code> class allows to install periodic, time-triggered 00014 * tasks. An example of a simple user-defined task is given below: 00015 * <pre><code> 00016 * class MyTask : public Task { 00017 * public: 00018 * void run(); 00019 * }; 00020 * 00021 * void MyTask::run() { 00022 * <span style="color:#FF0000">// code to be executed periodically</span> 00023 * } 00024 * </code></pre> 00025 * This task can then be created and started as follows: 00026 * <pre><code> 00027 * MyTask myTask(0.1); <span style="color:#FF0000">// period in seconds</span> 00028 * myTask.start(); 00029 * ... 00030 * 00031 * myTask.stop(); 00032 * </code></pre> 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00035 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00036 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00037 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00038 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00039 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00040 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00041 */ 00042 class Task 00043 { 00044 00045 private: 00046 00047 /** specifiying the interval in seconds */ 00048 float period; 00049 /** The Ticker interface is used to setup a recurring interrupt to 00050 * repeatedly call a function at a specified rate. 00051 */ 00052 Ticker ticker; 00053 00054 public: 00055 00056 /** 00057 * Creates a task object with a given period. 00058 * @param period the period of this task in seconds. 00059 */ 00060 Task(float period); 00061 00062 virtual ~Task(); 00063 00064 /** 00065 * Gets the period of this task. 00066 * @return the period in seconds. 00067 */ 00068 float getPeriod(); 00069 00070 /** 00071 * Starts this task. 00072 */ 00073 void start(); 00074 00075 /** 00076 * Stops this task. 00077 */ 00078 void stop(); 00079 00080 /** 00081 * This method needs to be implemented by a user task. 00082 */ 00083 virtual void run(); 00084 }; 00085 00086 #endif
Generated on Wed Jul 13 2022 04:37:19 by
1.7.2
