IRremote
ir_Sony.cpp
Go to the documentation of this file.
1 #include "IRremote.h"
2 
3 //==============================================================================
4 // SSSS OOO N N Y Y
5 // S O O NN N Y Y
6 // SSS O O N N N Y
7 // S O O N NN Y
8 // SSSS OOO N N Y
9 //==============================================================================
10 
11 #define SONY_BITS 12
12 #define SONY_HDR_MARK 2400
13 #define SONY_HDR_SPACE 600
14 #define SONY_ONE_MARK 1200
15 #define SONY_ZERO_MARK 600
16 #define SONY_RPT_LENGTH 45000
17 #define SONY_DOUBLE_SPACE_USECS 500 // usually see 713 - not using ticks as get number wrap around
18 
19 //+=============================================================================
20 #if SEND_SONY
21 void IRsend::sendSony(unsigned long data, int nbits) {
22  // Set IR carrier frequency
23  enableIROut(40);
24 
25  // Header
28 
29  // Data
30  for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
31  if (data & mask) {
34  } else {
37  }
38  }
39 
40  // We will have ended with LED off
41 }
42 #endif
43 
44 //+=============================================================================
45 #if DECODE_SONY
46 bool IRrecv::decodeSony(decode_results *results) {
47  long data = 0;
48  unsigned int offset = 0; // Dont skip first space, check its size
49 
50  if (irparams.rawlen < (2 * SONY_BITS) + 2) {
51  return false;
52  }
53 
54  // Some Sony's deliver repeats fast after first
55  // unfortunately can't spot difference from of repeat from two fast clicks
56  if (results->rawbuf[offset] * USECPERTICK < SONY_DOUBLE_SPACE_USECS) {
57  // Serial.print("IR Gap found: ");
58  results->bits = 0;
59  results->value = REPEAT;
60 
61 # ifdef DECODE_SANYO
62  results->decode_type = SANYO;
63 # else
64  results->decode_type = UNKNOWN;
65 # endif
66 
67  return true;
68  }
69  offset++;
70 
71  // Initial mark
72  if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) {
73  return false;
74  }
75  offset++;
76 
77  while (offset + 1 < irparams.rawlen) {
78  if (!MATCH_SPACE(results->rawbuf[offset], SONY_HDR_SPACE)) {
79  break;
80  }
81  offset++;
82 
83  if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) {
84  data = (data << 1) | 1;
85  } else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) {
86  data = (data << 1) | 0;
87  } else {
88  return false;
89  }
90  offset++;
91  }
92 
93  // Success
94  results->bits = (offset - 1) / 2;
95  if (results->bits < 12) {
96  results->bits = 0;
97  return false;
98  }
99  results->value = data;
100  results->decode_type = SONY;
101  return true;
102 }
103 #endif
104 
UNKNOWN
@ UNKNOWN
Definition: IRremote.h:113
SONY
@ SONY
Definition: IRremote.h:118
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
SONY_HDR_MARK
#define SONY_HDR_MARK
Definition: ir_Sony.cpp:12
SONY_DOUBLE_SPACE_USECS
#define SONY_DOUBLE_SPACE_USECS
Definition: ir_Sony.cpp:17
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
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.
SONY_BITS
#define SONY_BITS
Definition: ir_Sony.cpp:11
USECPERTICK
#define USECPERTICK
Definition: IRremoteBoardDefs.h:166
SONY_HDR_SPACE
#define SONY_HDR_SPACE
Definition: ir_Sony.cpp:13
SANYO
@ SANYO
Definition: IRremote.h:125
IRsend::sendSony
void sendSony(unsigned long data, int nbits)
Definition: ir_Sony.cpp:21
IRremote.h
Public API to the library.
IRsend::space
void space(unsigned int usec)
Definition: irSend.cpp:103
REPEAT
#define REPEAT
Decoded value for NEC when a repeat code is received.
Definition: IRremote.h:188
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
SONY_ONE_MARK
#define SONY_ONE_MARK
Definition: ir_Sony.cpp:14
irparams_t::rawlen
unsigned int rawlen
counter of entries in rawbuf
Definition: IRremoteInt.h:45
SONY_ZERO_MARK
#define SONY_ZERO_MARK
Definition: ir_Sony.cpp:15