Skip to content

Commit 7cebbd9

Browse files
committed
0.3.1 HeartBeat
1 parent 5621101 commit 7cebbd9

File tree

14 files changed

+241
-57
lines changed

14 files changed

+241
-57
lines changed

libraries/HeartBeat/.arduino-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ compile:
99
- esp32
1010
# - esp8266
1111
# - mega2560
12+
libraries:
13+
- "SRF05"

libraries/HeartBeat/HeartBeat.cpp

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: HeartBeat.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.1
4+
// VERSION: 0.3.1
55
// PURPOSE: Arduino library for HeartBeat with frequency and dutyCycle
66
// DATE: 2019-06-12
77
// URL: https://github.com/RobTillaart/HeartBeat
@@ -12,13 +12,20 @@
1212
// 0.1.2 2021-01-15 renamed all to HeartBeat
1313
// added dutyCycle
1414
// 0.1.3 2021-05-27 fix Arduino-lint
15+
//
1516
// 0.2.0 2021-11-02 update Build-CI, add badges
1617
// add getFrequency(), getDutyCycle();
1718
// add getState().
1819
// removed set()
1920
// 0.2.1 2021-12-18 update library.json, license, minor edits
21+
//
2022
// 0.3.0 2022-02-04 added HeartBeatDiag class.
2123
// added HeartBeatSL class (slightly simpler).
24+
// 0.3.1 2022-07-26 move all code to .cpp
25+
// add isEnabled()
26+
// rename examples
27+
// add example SRF05 distance sensor
28+
2229

2330

2431
#include "HeartBeat.h"
@@ -50,11 +57,43 @@ void HeartBeat::setFrequency(float frequency)
5057

5158
void HeartBeat::setDutyCycle(float dutyCycle)
5259
{
53-
_dutyCycle = constrain(dutyCycle, 0, 100); // percentage
60+
_dutyCycle = dutyCycle;
61+
if (_dutyCycle < 0) _dutyCycle = 0;
62+
if (_dutyCycle > 100) _dutyCycle = 100;
5463
_setFreqDuty();
5564
}
5665

5766

67+
float HeartBeat::getFrequency()
68+
{
69+
return _frequency;
70+
};
71+
72+
73+
float HeartBeat::getDutyCycle()
74+
{
75+
return _dutyCycle;
76+
};
77+
78+
79+
void HeartBeat::enable()
80+
{
81+
_running = true;
82+
};
83+
84+
85+
void HeartBeat::disable()
86+
{
87+
_running = false;
88+
};
89+
90+
91+
bool HeartBeat::isEnabled()
92+
{
93+
return _running;
94+
};
95+
96+
5897
void HeartBeat::beat()
5998
{
6099
if (_running == false)
@@ -73,7 +112,10 @@ void HeartBeat::beat()
73112
}
74113

75114

76-
115+
uint8_t HeartBeat::getState()
116+
{
117+
return _state;
118+
};
77119

78120

79121
/////////////////////////////////
@@ -157,6 +199,12 @@ bool HeartBeatDiag::code(uint32_t pattern)
157199
}
158200

159201

202+
void HeartBeatDiag::codeOff()
203+
{
204+
_codeMask = 0;
205+
}
206+
207+
160208
/////////////////////////////////////////////////////////////////////////////
161209
//
162210
// HEARTBEATSL
@@ -238,5 +286,11 @@ bool HeartBeatSL::code(const char * str)
238286
}
239287

240288

289+
void HeartBeatSL::codeOff()
290+
{
291+
_codeMask = 0;
292+
}
293+
294+
241295
// -- END OF FILE --
242296

libraries/HeartBeat/HeartBeat.h

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,40 @@
22
//
33
// FILE: HeartBeat.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.0
5+
// VERSION: 0.3.1
66
// PURPOSE: Arduino library for HeartBeat with frequency and dutyCycle
77
// DATE: 2019-06-12
88
// URL: https://github.com/RobTillaart/HeartBeat
99

1010

1111
#include "Arduino.h"
1212

13-
#define HEARTBEAT_LIB_VERSION (F("0.3.0"))
13+
#define HEARTBEAT_LIB_VERSION (F("0.3.1"))
1414

1515

1616
class HeartBeat
1717
{
1818
public:
19+
// CONSTRUCTOR
1920
HeartBeat();
2021

2122
void begin(const uint8_t pin, float frequency = 1.0);
2223

24+
// CONFIGURATION
2325
void setFrequency(float frequency = 1.0);
2426
void setDutyCycle(float dutyCycle = 50);
25-
float getFrequency() { return _frequency; };
26-
float getDutyCycle() { return _dutyCycle; };
27+
float getFrequency();
28+
float getDutyCycle();
2729

28-
inline void enable() { _running = true; };
29-
inline void disable() { _running = false; };
30+
// START STOP interface
31+
void enable();
32+
void disable();
33+
bool isEnabled();
3034

35+
// WORKER
3136
void beat();
32-
uint8_t getState() { return _state; };
37+
uint8_t getState();
38+
3339

3440
protected:
3541
void _setFreqDuty();
@@ -55,14 +61,18 @@ class HeartBeat
5561
class HeartBeatDiag : public HeartBeat
5662
{
5763
public:
64+
// CONSTRUCTOR
5865
HeartBeatDiag();
5966

67+
// WORKER
6068
void beat();
6169

70+
// CONFIGURATION PATTERN
6271
// pattern = up to 9 digits, indicating the relative length of the pulses
6372
// of the error or diagnostic code
64-
bool code(uint32_t pattern); // executes ONE time
65-
void codeOff() { _codeMask = 0; }; // explicit stop.
73+
bool code(uint32_t pattern); // executes ONE time
74+
void codeOff(); // explicit stop.
75+
6676

6777
protected:
6878
uint32_t _code = 0; // up to 9 digits
@@ -80,14 +90,18 @@ class HeartBeatDiag : public HeartBeat
8090
class HeartBeatSL : public HeartBeat
8191
{
8292
public:
93+
// CONSTRUCTOR
8394
HeartBeatSL();
8495

96+
// WORKER
8597
void beat();
8698

99+
// CONFIGURATION PATTERN
87100
// str = string of L (long) and S or non-L (short) characters.
88101
// L is a pulse of 3 units, S is a pulse of 1 unit.
89-
bool code(const char * str); // executes ONE time
90-
void codeOff() { _codeMask = 0; }; // explicit stop.
102+
bool code(const char * str); // executes ONE time
103+
void codeOff(); // explicit stop.
104+
91105

92106
protected:
93107
uint8_t _code = 0; // up to 7 bits

0 commit comments

Comments
 (0)