forked from alonf/WebControlledSwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPulseRelayManager.cpp
More file actions
35 lines (28 loc) · 764 Bytes
/
Copy pathPulseRelayManager.cpp
File metadata and controls
35 lines (28 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
//
//
#include "PulseRelayManager.h"
PulseRelayManager::PulseRelayManager(int pin, unsigned long pulseDelay, std::function<void(const String &)> logger) : RelayManager(pin, logger), _pulseDelay(pulseDelay)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
}
void PulseRelayManager::Set(int value)
{
RelayManager::Set(value);
_startTime = millis();
}
void PulseRelayManager::OnCommand(const String& commandName, int commandId)
{
Serial.print("Pulse relay manager received command:");
Serial.print(commandName.c_str());
if (commandName == "Activate")
Set(HIGH);
}
void PulseRelayManager::Loop()
{
if (_startTime == 0 || (_startTime != 0 && millis() - _startTime <= _pulseDelay))
return;
RelayManager::Set(LOW); //end pulse
_startTime = 0;
}