Skip to content

Commit 3bf1367

Browse files
committed
feat(Enable): Add enable/disable function
1 parent 3288f5b commit 3bf1367

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/PPMEncoder.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void PPMEncoder::begin(uint8_t pin, uint8_t ch, boolean inverted) {
2020
pinMode(pin, OUTPUT);
2121
digitalWrite(pin, offState);
2222

23+
enabled = true;
2324
state = true;
2425
elapsedUs = 0;
2526
currentChannel = 0;
@@ -49,7 +50,24 @@ void PPMEncoder::setChannelPercent(uint8_t channel, uint8_t percent) {
4950
setChannel(channel, map(percent, 0, 100, PPMEncoder::MIN, PPMEncoder::MAX));
5051
}
5152

53+
void PPMEncoder::enable() {
54+
enabled = true;
55+
}
56+
57+
void PPMEncoder::disable() {
58+
enabled = false;
59+
state = false;
60+
elapsedUs = 0;
61+
currentChannel = 0;
62+
63+
digitalWrite(outputPin, offState);
64+
}
65+
5266
void PPMEncoder::interrupt() {
67+
if (!enabled) {
68+
return;
69+
}
70+
5371
TCNT1 = 0;
5472

5573
if (state) {

src/PPMEncoder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PPMEncoder {
2222
uint8_t currentChannel;
2323
byte outputPin;
2424
boolean state;
25+
boolean enabled;
2526

2627
uint8_t onState;
2728
uint8_t offState;
@@ -38,6 +39,9 @@ class PPMEncoder {
3839
void begin(uint8_t pin, uint8_t ch);
3940
void begin(uint8_t pin, uint8_t ch, boolean inverted);
4041

42+
void disable();
43+
void enable();
44+
4145
void interrupt();
4246
};
4347

0 commit comments

Comments
 (0)