Skip to content

Commit f2dafe5

Browse files
committed
Merge pull request Arduino-IRremote#84 from Informatic/sendsharp
sendSharp cleanup and API change
2 parents 24ba950 + b04b312 commit f2dafe5

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

IRremote.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,42 +1106,37 @@ i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the
11061106
linked LIRC file.
11071107
*/
11081108

1109-
void IRsend::sendSharp(unsigned long data, int nbits) {
1110-
unsigned long invertdata = data ^ SHARP_TOGGLE_MASK;
1109+
void IRsend::sendSharpRaw(unsigned long data, int nbits) {
11111110
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);
1111+
1112+
// Sending codes in bursts of 3 (normal, inverted, normal) makes transmission
1113+
// much more reliable. That's the exact behaviour of CD-S6470 remote control.
1114+
for (int n = 0; n < 3; n++) {
1115+
for (int i = 1 << (nbits-1); i > 0; i>>=1) {
1116+
if (data & i) {
1117+
mark(SHARP_BIT_MARK);
1118+
space(SHARP_ONE_SPACE);
1119+
}
1120+
else {
1121+
mark(SHARP_BIT_MARK);
1122+
space(SHARP_ZERO_SPACE);
1123+
}
11351124
}
1136-
invertdata <<= 1;
1125+
1126+
mark(SHARP_BIT_MARK);
1127+
space(SHARP_ZERO_SPACE);
1128+
delay(40);
1129+
1130+
data = data ^ SHARP_TOGGLE_MASK;
11371131
}
1138-
mark(SHARP_BIT_MARK);
1139-
space(SHARP_ZERO_SPACE);
1140-
delay(46);
11411132
}
11421133

1143-
void IRsend::sendDISH(unsigned long data, int nbits)
1144-
{
1134+
// Sharp send compatible with data obtained through decodeSharp
1135+
void IRsend::sendSharp(unsigned int address, unsigned int command) {
1136+
sendSharpRaw((address << 10) | (command << 2) | 2, 15);
1137+
}
1138+
1139+
void IRsend::sendDISH(unsigned long data, int nbits) {
11451140
enableIROut(56);
11461141
mark(DISH_HDR_MARK);
11471142
space(DISH_HDR_SPACE);

IRremote.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
class decode_results {
2929
public:
3030
int decode_type; // NEC, SONY, RC5, UNKNOWN
31-
unsigned int panasonicAddress; // This is only used for decoding Panasonic data
31+
union { // This is used for decoding Panasonic and Sharp data
32+
unsigned int panasonicAddress;
33+
unsigned int sharpAddress;
34+
};
3235
unsigned long value; // Decoded value
3336
int bits; // Number of bits in decoded value
3437
volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks
@@ -101,7 +104,8 @@ class IRsend
101104
void sendRC5(unsigned long data, int nbits);
102105
void sendRC6(unsigned long data, int nbits);
103106
void sendDISH(unsigned long data, int nbits);
104-
void sendSharp(unsigned long data, int nbits);
107+
void sendSharp(unsigned int address, unsigned int command);
108+
void sendSharpRaw(unsigned long data, int nbits);
105109
void sendPanasonic(unsigned int address, unsigned long data);
106110
void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does.
107111
// private:

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ sendRC5 KEYWORD2
2828
sendRC6 KEYWORD2
2929
sendDISH KEYWORD2
3030
sendSharp KEYWORD2
31+
sendSharpRaw KEYWORD2
3132
sendPanasonic KEYWORD2
3233
sendJVC KEYWORD2
3334

@@ -47,4 +48,4 @@ SHARP LITERAL1
4748
PANASONIC LITERAL1
4849
JVC LITERAL1
4950
UNKNOWN LITERAL1
50-
REPEAT LITERAL1
51+
REPEAT LITERAL1

0 commit comments

Comments
 (0)