Skip to content

Commit

Permalink
StartTiming新增一个可选参数控制计时单位
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola-Chan-bot committed Aug 10, 2021
1 parent b3dc2ae commit 2167e75
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ void RepeatAfter(uint16_t IntervalMilliseconds);
template <uint8_t TimerCode, uint16_t IntervalMilliseconds, void (*DoTask)(), void (*DoneCallback)() = nullptr>
void RepeatAfter(int32_t RepeatTimes);

//将当前时刻设为0,计量经过的毫秒数。读取MillisecondsElapsed变量来获得经过的毫秒数。
//将当前时刻设为0,计量经过的毫秒数。读取MillisecondsElapsed变量来获得经过的毫秒数。可选设置MillisecondsPerTick,控制计时单位是多少毫秒
//Set the time now as 0 and start to record time elapsed. Read MillisecondsElapsed variable to get the time elapsed.
template <uint8_t TimerCode>
template <uint8_t TimerCode, uint16_t MillisecondsPerTick = 1>
void StartTiming();
//获取自上次调用StartTiming以来所经过的毫秒数。
//Get MillisecondsElapsed after the last call of StartTiming.
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TimersOneForAll
version=1.4.2
version=1.5.0
author=EbolaChan <[email protected]>
maintainer=EbolaChan <[email protected]>
sentence=Make full use of all your hardware timers on your Arduino board. 充分利用你开发板上所有的硬件计时器
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/Timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace TimersOneForAll
volatile uint32_t MillisecondsElapsed;
namespace Internal
{
template <uint8_t TimerCode>
template <uint8_t TimerCode, uint16_t MillsecondsPerTick>
void MEAdd()
{
if (Running<TimerCode>)
MillisecondsElapsed<TimerCode> ++;
MillisecondsElapsed<TimerCode> += MillsecondsPerTick;
}
}
//设置当前为零时刻进行计时。从MillisecondsElapsed变量读取经过的毫秒数
template <uint8_t TimerCode>
template <uint8_t TimerCode, uint16_t MillisecondsPerTick = 1>
void StartTiming()
{
RepeatAfter<TimerCode, 1, Internal::MEAdd<TimerCode>>();
RepeatAfter<TimerCode, MillisecondsPerTick, Internal::MEAdd<TimerCode, MillisecondsPerTick>>();
MillisecondsElapsed<TimerCode> = 0;
Running<TimerCode> = true;
}
Expand Down

0 comments on commit 2167e75

Please sign in to comment.