new ticker

Dependents:   newTicker_demo

Committer:
lisper
Date:
Fri Oct 31 08:12:40 2014 +0000
Revision:
1:c8bc7e989caf
Parent:
0:c143e6906ab5
fix little

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lisper 0:c143e6906ab5 1 /*******************************************************************************
lisper 0:c143e6906ab5 2 * This file is part of the NewTicker library. *
lisper 0:c143e6906ab5 3 * *
lisper 0:c143e6906ab5 4 * NewTicker is free software: you can redistribute it and/or *
lisper 0:c143e6906ab5 5 * modify it under the terms of the GNU General Public License as *
lisper 0:c143e6906ab5 6 * published by the Free Software Foundation, either version 3 of *
lisper 0:c143e6906ab5 7 * the License, or any later version. *
lisper 0:c143e6906ab5 8 * *
lisper 0:c143e6906ab5 9 * NewTicker is distributed in the hope that it will be useful, *
lisper 0:c143e6906ab5 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
lisper 0:c143e6906ab5 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
lisper 0:c143e6906ab5 12 * GNU Lesser General Public License for more details. *
lisper 0:c143e6906ab5 13 * *
lisper 0:c143e6906ab5 14 * NewTicker is distributed in the hope that it will be useful, *
lisper 0:c143e6906ab5 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
lisper 0:c143e6906ab5 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
lisper 0:c143e6906ab5 17 * GNU Lesser General Public License for more details. *
lisper 0:c143e6906ab5 18 * *
lisper 0:c143e6906ab5 19 * You should have received a copy of the GNU Lesser General Public *
lisper 0:c143e6906ab5 20 * License along with NewTicker. If not, see *
lisper 0:c143e6906ab5 21 * <http://www.gnu.org/licenses/>. *
lisper 0:c143e6906ab5 22 ******************************************************************************/
lisper 0:c143e6906ab5 23
lisper 0:c143e6906ab5 24 /*
lisper 0:c143e6906ab5 25 * Copyright: DFRobot
lisper 0:c143e6906ab5 26 * name: NewTicker
lisper 0:c143e6906ab5 27 * version: 1.0
lisper 0:c143e6906ab5 28 * Author: lisper (lisper.li@dfrobot.com)
lisper 0:c143e6906ab5 29 * Date: 2014-10-30
lisper 0:c143e6906ab5 30 * Description: new ticker library for mbed
lisper 0:c143e6906ab5 31 */
lisper 0:c143e6906ab5 32
lisper 0:c143e6906ab5 33 #include "mbed.h"
lisper 0:c143e6906ab5 34 #include "millis.h"
lisper 0:c143e6906ab5 35 #include "NewTicker.h"
lisper 0:c143e6906ab5 36
lisper 0:c143e6906ab5 37 NewTicker::NewTicker (void)
lisper 0:c143e6906ab5 38 {
lisper 1:c8bc7e989caf 39 //nowTime = millis ();
lisper 0:c143e6906ab5 40 }
lisper 0:c143e6906ab5 41
lisper 0:c143e6906ab5 42 void NewTicker::attach (void (*theTickerHandler) (), uint32_t theDelayTime)
lisper 0:c143e6906ab5 43 {
lisper 0:c143e6906ab5 44 tickerHandler = theTickerHandler;
lisper 0:c143e6906ab5 45 delayTime = theDelayTime;
lisper 1:c8bc7e989caf 46 nowTime = millis ();
lisper 0:c143e6906ab5 47 }
lisper 0:c143e6906ab5 48
lisper 0:c143e6906ab5 49 void NewTicker::detach ()
lisper 0:c143e6906ab5 50 {
lisper 0:c143e6906ab5 51 tickerHandler = NULL;
lisper 0:c143e6906ab5 52 }
lisper 0:c143e6906ab5 53
lisper 0:c143e6906ab5 54 void NewTicker::update ()
lisper 0:c143e6906ab5 55 {
lisper 0:c143e6906ab5 56 if (tickerHandler == NULL)
lisper 0:c143e6906ab5 57 return;
lisper 0:c143e6906ab5 58 if (millis () - nowTime > delayTime) {
lisper 0:c143e6906ab5 59 nowTime = millis ();
lisper 0:c143e6906ab5 60 tickerHandler ();
lisper 0:c143e6906ab5 61 }
lisper 0:c143e6906ab5 62 }
lisper 0:c143e6906ab5 63