Skip to content

Commit 95f93e6

Browse files
committed
Cleanup sendSharp and fix reliability
1 parent 24ba950 commit 95f93e6

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

IRremote.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,35 +1109,27 @@ linked LIRC file.
11091109
void IRsend::sendSharp(unsigned long data, int nbits) {
11101110
unsigned long invertdata = data ^ SHARP_TOGGLE_MASK;
11111111
enableIROut(38);
1112-
for (int i = 0; i < nbits; i++) {
1113-
if (data & 0x4000) {
1114-
mark(SHARP_BIT_MARK);
1115-
space(SHARP_ONE_SPACE);
1116-
}
1117-
else {
1118-
mark(SHARP_BIT_MARK);
1119-
space(SHARP_ZERO_SPACE);
1120-
}
1121-
data <<= 1;
1122-
}
1123-
1124-
mark(SHARP_BIT_MARK);
1125-
space(SHARP_ZERO_SPACE);
1126-
delay(46);
1127-
for (int i = 0; i < nbits; i++) {
1128-
if (invertdata & 0x4000) {
1129-
mark(SHARP_BIT_MARK);
1130-
space(SHARP_ONE_SPACE);
1131-
}
1132-
else {
1133-
mark(SHARP_BIT_MARK);
1134-
space(SHARP_ZERO_SPACE);
1112+
1113+
// Sending codes in bursts of 3 (normal, inverted, normal) makes transmission
1114+
// much more reliable. That's the exact behaviour of CD-S6470 remote control.
1115+
for (int n = 0; n < 3; n++) {
1116+
for (int i = 1 << (nbits-1); i > 0; i>>=1) {
1117+
if (data & i) {
1118+
mark(SHARP_BIT_MARK);
1119+
space(SHARP_ONE_SPACE);
1120+
}
1121+
else {
1122+
mark(SHARP_BIT_MARK);
1123+
space(SHARP_ZERO_SPACE);
1124+
}
11351125
}
1136-
invertdata <<= 1;
1126+
1127+
mark(SHARP_BIT_MARK);
1128+
space(SHARP_ZERO_SPACE);
1129+
delay(40);
1130+
1131+
data = data ^ SHARP_TOGGLE_MASK;
11371132
}
1138-
mark(SHARP_BIT_MARK);
1139-
space(SHARP_ZERO_SPACE);
1140-
delay(46);
11411133
}
11421134

11431135
void IRsend::sendDISH(unsigned long data, int nbits)

0 commit comments

Comments
 (0)