Skip to content

Commit

Permalink
扩大计时上限,允许暂停
Browse files Browse the repository at this point in the history
  • Loading branch information
Silver-Fang committed Jul 8, 2021
1 parent fa92b2f commit 6178d69
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ void StartTiming();
//Get MillisecondsElapsed after the last call of StartTiming.
template <uint8_t TimerCode>
static volatile uint16_t MillisecondsElapsed;
//设为false可以暂停计时,重新设为true可继续计时
//Set to false can freeze MillisecondsElapsed from being ticked by the timer (lock the variable only, timer still running). Set to true to continue timing.
template <uint8_t TimerCode>
static volatile bool Running;

//在指定引脚上无限播放指定频率的音调
//Play a tone of FrequencyHz on PinCode endlessly.
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.2.0
version=1.3.0
author=EbolaChan <Leenrung@outlook.com>
maintainer=EbolaChan <Leenrung@outlook.com>
sentence=Make full use of all your hardware timers on your Arduino board. 充分利用你开发板上所有的硬件计时器
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace TimersOneForAll
}
//取得上次调用StartTiming以来经过的毫秒数
template <uint8_t TimerCode>
static volatile uint16_t MillisecondsElapsed;
static volatile uint32_t MillisecondsElapsed;
template <uint8_t TimerCode, uint16_t AfterMilliseconds, void (*DoTask)()>
void DoAfter();
//不要使用这个命名空间,除非你很清楚自己在做什么
Expand Down
13 changes: 9 additions & 4 deletions src/Internal/StartTiming.h → src/Internal/Timing.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#pragma once
#include "Kernel.h"
namespace TimersOneForAll
{
{
//设为false可以暂停计时,重新设为true可继续计时
template <uint8_t TimerCode>
static volatile bool Running;
namespace Internal
{
{
template <uint8_t TimerCode>
void MEAdd()
{
MillisecondsElapsed<TimerCode> ++;
if (Running<TimerCode>)
MillisecondsElapsed<TimerCode> ++;
}
}
//设置当前为零时刻进行计时。从MillisecondsElapsed变量读取经过的毫秒数
template <uint8_t TimerCode>
void StartTiming()
{
MillisecondsElapsed<TimerCode> = 0;
RepeatAfter<TimerCode, 1, Internal::MEAdd<TimerCode>>();
MillisecondsElapsed<TimerCode> = 0;
Running<TimerCode> = true;
}
}
2 changes: 1 addition & 1 deletion src/TimersOneForAll.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "Internal\DoAfter.h"
#include "Internal\RepeatAfter.h"
#include "Internal\StartTiming.h"
#include "Internal\Timing.h"
#include "Internal\PlayTone.h"
#include "Internal\SquareWave.h"
#include "Internal\Delay.h"
Expand Down

0 comments on commit 6178d69

Please sign in to comment.