Skip to content

Commit 2167e75

Browse files
StartTiming新增一个可选参数控制计时单位
1 parent b3dc2ae commit 2167e75

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ void RepeatAfter(uint16_t IntervalMilliseconds);
6969
template <uint8_t TimerCode, uint16_t IntervalMilliseconds, void (*DoTask)(), void (*DoneCallback)() = nullptr>
7070
void RepeatAfter(int32_t RepeatTimes);
7171

72-
//将当前时刻设为0,计量经过的毫秒数。读取MillisecondsElapsed变量来获得经过的毫秒数。
72+
//将当前时刻设为0,计量经过的毫秒数。读取MillisecondsElapsed变量来获得经过的毫秒数。可选设置MillisecondsPerTick,控制计时单位是多少毫秒
7373
//Set the time now as 0 and start to record time elapsed. Read MillisecondsElapsed variable to get the time elapsed.
74-
template <uint8_t TimerCode>
74+
template <uint8_t TimerCode, uint16_t MillisecondsPerTick = 1>
7575
void StartTiming();
7676
//获取自上次调用StartTiming以来所经过的毫秒数。
7777
//Get MillisecondsElapsed after the last call of StartTiming.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TimersOneForAll
2-
version=1.4.2
2+
version=1.5.0
33
author=EbolaChan <[email protected]>
44
maintainer=EbolaChan <[email protected]>
55
sentence=Make full use of all your hardware timers on your Arduino board. 充分利用你开发板上所有的硬件计时器

src/Internal/Timing.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ namespace TimersOneForAll
1010
volatile uint32_t MillisecondsElapsed;
1111
namespace Internal
1212
{
13-
template <uint8_t TimerCode>
13+
template <uint8_t TimerCode, uint16_t MillsecondsPerTick>
1414
void MEAdd()
1515
{
1616
if (Running<TimerCode>)
17-
MillisecondsElapsed<TimerCode> ++;
17+
MillisecondsElapsed<TimerCode> += MillsecondsPerTick;
1818
}
1919
}
2020
//设置当前为零时刻进行计时。从MillisecondsElapsed变量读取经过的毫秒数
21-
template <uint8_t TimerCode>
21+
template <uint8_t TimerCode, uint16_t MillisecondsPerTick = 1>
2222
void StartTiming()
2323
{
24-
RepeatAfter<TimerCode, 1, Internal::MEAdd<TimerCode>>();
24+
RepeatAfter<TimerCode, MillisecondsPerTick, Internal::MEAdd<TimerCode, MillisecondsPerTick>>();
2525
MillisecondsElapsed<TimerCode> = 0;
2626
Running<TimerCode> = true;
2727
}

0 commit comments

Comments
 (0)