-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCSwitchWarema.cpp
More file actions
56 lines (50 loc) · 2.06 KB
/
RCSwitchWarema.cpp
File metadata and controls
56 lines (50 loc) · 2.06 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "RCSwitchWarema.h"
#include "esphome/core/log.h"
namespace esphome
{
namespace waremacode_sender
{
void RCSwitchWarema::sendMC(std::string const &codeWord, unsigned int const &dataLength, unsigned int const &syncLength, uint8_t const &numberOfTransmissions, unsigned int const &sendDelay)
{
ESP_LOGD("RCSwitchWarema", "sendMC: %s, %i, %i, %i, %i",
codeWord.c_str(),
dataLength,
syncLength,
numberOfTransmissions,
sendDelay);
auto const halfDataLength{dataLength / 2};
for (uint8_t repeat{0}; repeat < numberOfTransmissions; ++repeat)
{
digitalWrite(m_transmitterPin, LOW);
for (auto const &c : codeWord)
{
if (c == 's' || c == 'S')
{
digitalWrite(m_transmitterPin, (c == 's') ? LOW : HIGH);
delayMicroseconds(syncLength);
}
else if (c == '0' || c == '1')
{
auto const isZero{c == '0'};
digitalWrite(m_transmitterPin, isZero ? HIGH : LOW);
delayMicroseconds(halfDataLength);
digitalWrite(m_transmitterPin, isZero ? LOW : HIGH);
delayMicroseconds(halfDataLength);
}
}
digitalWrite(m_transmitterPin, LOW);
if (repeat != numberOfTransmissions - 1)
{
delayMicroseconds(sendDelay);
}
}
ESP_LOGD("RCSwitchWarema", "sendMC: ready");
}
void RCSwitchWarema::enableTransmit(int const &transmitterPin)
{
ESP_LOGD("RCSwitchWarema", "enableTransmit: %d", transmitterPin);
m_transmitterPin = transmitterPin;
Base::enableTransmit(transmitterPin);
}
} // namespace waremacode_sender
} // namespace esphome