-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRCSwitchWarema.h
63 lines (50 loc) · 1.6 KB
/
RCSwitchWarema.h
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
57
58
59
60
61
62
63
#pragma once
#include <RCSwitch.h>
class RCSwitchWarema : public RCSwitch
{
using Base=RCSwitch;
public:
void sendMC(char* Code,int dLen,int sLen,int repeat,int delay);
void enableTransmit(int nTransmitterPin);
private:
int m_transmitterPin{};
};
void RCSwitchWarema::enableTransmit(int nTransmitterPin)
{
m_transmitterPin = nTransmitterPin;
Base::enableTransmit(nTransmitterPin);
}
void RCSwitchWarema::sendMC(char* sCodeWord, int dataLength, int syncLength, int sendCommand, int sendDelay )
{
for (int nRepeat=0; nRepeat<sendCommand; nRepeat++)
{
digitalWrite(this->m_transmitterPin, LOW);
for (int i = 0; i < strlen(sCodeWord); i++) {
switch (sCodeWord[i]) {
case 's':
digitalWrite(this->m_transmitterPin, LOW);
delayMicroseconds(syncLength);
break;
case 'S':
digitalWrite(this->m_transmitterPin, HIGH);
delayMicroseconds(syncLength);
break;
case '0':
digitalWrite(this->m_transmitterPin, HIGH);
delayMicroseconds(dataLength/2);
digitalWrite(this->m_transmitterPin, LOW);
delayMicroseconds(dataLength/2);
break;
case '1':
digitalWrite(this->m_transmitterPin, LOW);
delayMicroseconds(dataLength/2);
digitalWrite(this->m_transmitterPin, HIGH);
delayMicroseconds(dataLength/2);
break;
}
}
digitalWrite(this->m_transmitterPin, LOW);
if (nRepeat != sendCommand-1)
delayMicroseconds(sendDelay);
}
}