IRremote
ir_Sharp.cpp
Go to the documentation of this file.
1 #include "IRremote.h"
2 
3 //==============================================================================
4 // SSSS H H AAA RRRR PPPP
5 // S H H A A R R P P
6 // SSS HHHHH AAAAA RRRR PPPP
7 // S H H A A R R P
8 // SSSS H H A A R R P
9 //==============================================================================
10 
11 // Sharp and DISH support by Todd Treece: http://unionbridge.org/design/ircommand
12 //
13 // The send function has the necessary repeat built in because of the need to
14 // invert the signal.
15 //
16 // Sharp protocol documentation:
17 // http://www.sbprojects.com/knowledge/ir/sharp.htm
18 //
19 // Here is the LIRC file I found that seems to match the remote codes from the
20 // oscilloscope:
21 // Sharp LCD TV:
22 // http://lirc.sourceforge.net/remotes/sharp/GA538WJSA
23 
24 #define SHARP_BITS 15
25 #define SHARP_ONE_SPACE 1805
26 //#define SHARP_ONE_SPACE 1850
27 
28 #define SHARP_ADDR_BITS 5
29 #define SHARP_DATA_BITS 8
30 #define SHARP_BIT_MARK_SEND 250
31 #define SHARP_BIT_MARK_RECV 150
32 
33 #define SHARP_ZERO_SPACE 795
34 #define SHARP_GAP 600000
35 #define SHARP_RPT_SPACE 3000
36 
37 #define SHARP_TOGGLE_MASK 0x3FF
38 
39 //+=============================================================================
40 #if SEND_SHARP
41 void IRsend::sendSharpRaw(unsigned long data, int nbits) {
42  enableIROut(38);
43 
44  // Sending codes in bursts of 3 (normal, inverted, normal) makes transmission
45  // much more reliable. That's the exact behavior of CD-S6470 remote control.
46  for (int n = 0; n < 3; n++) {
47  for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
48  if (data & mask) {
51  } else {
54  }
55  }
56 
59  delay(40);
60 
61  data = data ^ SHARP_TOGGLE_MASK;
62  }
63 }
64 #endif
65 
66 //+=============================================================================
67 // Sharp send compatible with data obtained through decodeSharp()
68 // ^^^^^^^^^^^^^ FUNCTION MISSING!
69 //
70 #if SEND_SHARP
71 void IRsend::sendSharp(unsigned int address, unsigned int command) {
72  sendSharpRaw((address << 10) | (command << 2) | 2, SHARP_BITS);
73 /*
74  * Use this code instead of the line above to be code compatible to the decoded values from decodeSharp
75  */
76 // //Change address to big-endian (five bits swap place)
77 // address = (address & 0x10) >> 4 | (address & 0x01) << 4 | (address & 0x08) >> 2 | (address & 0x02) << 2 | (address & 0x04) ;
78 // //Change command to big-endian (eight bit swap place)
79 // command = (command & 0xF0) >> 4 | (command & 0x0F) << 4;
80 // command = (command & 0xCC) >> 2 | (command & 0x33) << 2;
81 // command = (command & 0xAA) >> 1 | (command & 0x55) << 1;
82 // sendSharpRaw((address << 10) | (command << 2) | 0, SHARP_BITS);
83 }
84 
85 #endif // SEND_SHARP
86 
87 //+=============================================================================
88 // Sharp decode function written based on Sharp protocol documentation:
89 // http://www.sbprojects.com/knowledge/ir/sharp.htm
90 // Tesded on a DENON AVR-1804 reciever
91 
92 #if DECODE_SHARP
93 bool IRrecv::decodeSharp(decode_results *results) {
94  unsigned long addr = 0; // Somewhere to build our address
95  unsigned long data = 0; // Somewhere to build our data
96  unsigned long lastData = 0; // Somewhere to store last data
97  int offset = 1; //skip long space
98  int loops = 1; //number of bursts
99 
100  // Check we have the right amount of data
101  // Either one burst or three where second is inverted
102  // The setting #define _GAP 5000 in IRremoteInt.h will give one burst and possibly three calls to this function
103  if (irparams.rawlen == (SHARP_BITS + 1) * 2)
104  loops = 1;
105  else if (irparams.rawlen == (SHARP_BITS + 1) * 2 * 3)
106  loops = 3;
107  else
108  return false;
109 
110  // Check the first mark to see if it fits the SHARP_BIT_MARK_RECV length
111  if (!MATCH_MARK(results->rawbuf[offset], SHARP_BIT_MARK_RECV))
112  return false;
113  //check the first pause and see if it fits the SHARP_ONE_SPACE or SHARP_ZERO_SPACE length
114  if (!(MATCH_SPACE(results->rawbuf[offset + 1], SHARP_ONE_SPACE) || MATCH_SPACE(results->rawbuf[offset + 1], SHARP_ZERO_SPACE)))
115  return false;
116 
117  // Read the bits in
118  for (int j = 0; j < loops; j++) {
119  data = 0;
120  addr = 0;
121  for (int i = 0; i < SHARP_ADDR_BITS; i++) {
122  // Each bit looks like: SHARP_BIT_MARK_RECV + SHARP_ONE_SPACE -> 1
123  // or : SHARP_BIT_MARK_RECV + SHARP_ZERO_SPACE -> 0
124  if (!MATCH_MARK(results->rawbuf[offset++], SHARP_BIT_MARK_RECV))
125  return false;
126  // IR data is big-endian, so we shuffle it in from the right:
127  if (MATCH_SPACE(results->rawbuf[offset], SHARP_ONE_SPACE))
128  addr += 1 << i;
129  else if (MATCH_SPACE(results->rawbuf[offset], SHARP_ZERO_SPACE))
130  addr = addr;
131  else
132  return false;
133  offset++;
134  }
135  for (int i = 0; i < SHARP_DATA_BITS; i++) {
136  // Each bit looks like: SHARP_BIT_MARK_RECV + SHARP_ONE_SPACE -> 1
137  // or : SHARP_BIT_MARK_RECV + SHARP_ZERO_SPACE -> 0
138  if (!MATCH_MARK(results->rawbuf[offset++], SHARP_BIT_MARK_RECV))
139  return false;
140  // IR data is big-endian, so we shuffle it in from the right:
141  if (MATCH_SPACE(results->rawbuf[offset], SHARP_ONE_SPACE))
142  data += 1 << i;
143  else if (MATCH_SPACE(results->rawbuf[offset], SHARP_ZERO_SPACE))
144  data = data;
145  else
146  return false;
147  offset++;
148  //Serial.print(i);
149  //Serial.print(":");
150  //Serial.println(data, HEX);
151  }
152  //skip exp bit (mark+pause), chk bit (mark+pause), mark and long pause before next burst
153  offset += 6;
154 
155  //Check if last burst data is equal to this burst (lastData already inverted)
156  if (lastData != 0 && data != lastData)
157  return false;
158  //save current burst of data but invert (XOR) the last 10 bits (8 data bits + exp bit + chk bit)
159  lastData = data ^ 0xFF;
160  }
161 
162  // Success
163  results->bits = SHARP_BITS;
164  results->value = data;
165  results->address = addr;
166  results->decode_type = SHARP;
167  return true;
168 }
169 #endif
SHARP_DATA_BITS
#define SHARP_DATA_BITS
Definition: ir_Sharp.cpp:29
decode_results
Results returned from the decoder.
Definition: IRremote.h:174
decode_results::bits
int bits
Number of bits in decoded value.
Definition: IRremote.h:179
SHARP_BIT_MARK_SEND
#define SHARP_BIT_MARK_SEND
Definition: ir_Sharp.cpp:30
SHARP_ZERO_SPACE
#define SHARP_ZERO_SPACE
Definition: ir_Sharp.cpp:33
decode_results::address
unsigned int address
Used by Panasonic & Sharp [16-bits].
Definition: IRremote.h:177
decode_results::rawbuf
volatile unsigned int * rawbuf
Raw intervals in 50uS ticks.
Definition: IRremote.h:180
IRsend::mark
void mark(unsigned int usec)
Definition: irSend.cpp:69
IRsend::enableIROut
void enableIROut(int khz)
Definition: irSend.cpp:127
SHARP_ONE_SPACE
#define SHARP_ONE_SPACE
Definition: ir_Sharp.cpp:25
decode_results::decode_type
decode_type_t decode_type
UNKNOWN, NEC, SONY, RC5, ...
Definition: IRremote.h:176
MATCH_SPACE
int MATCH_SPACE(int measured_ticks, int desired_us)
Definition: IRremote.cpp:89
irparams
volatile irparams_t irparams
Allow all parts of the code access to the ISR data NB.
SHARP
@ SHARP
Definition: IRremote.h:128
IRremote.h
Public API to the library.
IRsend::sendSharp
void sendSharp(unsigned int address, unsigned int command)
Definition: ir_Sharp.cpp:71
IRsend::space
void space(unsigned int usec)
Definition: irSend.cpp:103
SHARP_BITS
#define SHARP_BITS
Definition: ir_Sharp.cpp:24
decode_results::value
unsigned long value
Decoded value [max 32-bits].
Definition: IRremote.h:178
MATCH_MARK
int MATCH_MARK(int measured_ticks, int desired_us)
Definition: IRremote.cpp:63
SHARP_BIT_MARK_RECV
#define SHARP_BIT_MARK_RECV
Definition: ir_Sharp.cpp:31
SHARP_ADDR_BITS
#define SHARP_ADDR_BITS
Definition: ir_Sharp.cpp:28
SHARP_TOGGLE_MASK
#define SHARP_TOGGLE_MASK
Definition: ir_Sharp.cpp:37
IRsend::sendSharpRaw
void sendSharpRaw(unsigned long data, int nbits)
Definition: ir_Sharp.cpp:41
irparams_t::rawlen
unsigned int rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:45