MCPcopy Create free account
hub / github.com/Arduino-IRremote/Arduino-IRremote / decodeSonyMSB

Method decodeSonyMSB

src/ir_Sony.hpp:145–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143 */
144#define SONY_DOUBLE_SPACE_USECS 500 // usually see 713 - not using ticks as get number wrap around
145bool IRrecv::decodeSonyMSB(decode_results *aResults) {
146 long data = 0;
147 uint8_t bits = 0;
148 unsigned int offset = 0; // Dont skip first space, check its size
149
150 if (aResults->rawlen < (2 * SONY_BITS_MIN) + 2) {
151 return false;
152 }
153
154 // Some Sony's deliver repeats fast after first
155 // unfortunately can't spot difference from of repeat from two fast clicks
156 if (aResults->rawbuf[0] < (SONY_DOUBLE_SPACE_USECS / MICROS_PER_TICK)) {
157 DEBUG_PRINTLN(F("IR Gap found"));
158
159 aResults->bits = 0;
160 aResults->value = 0xFFFFFFFF;
161 decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
162 decodedIRData.protocol = SONY;
163 return true;
164 }
165 offset++;
166
167 // Check header "mark"
168 if (!matchMark(aResults->rawbuf[offset], SONY_HEADER_MARK)) {
169 return false;
170 }
171 offset++;
172
173 // MSB first - Not compatible to standard, which says LSB first :-(
174 while (offset + 1 < aResults->rawlen) {
175
176 // First check for the constant space length, we do not have a space at the end of raw data
177 // we are lucky, since the start space is equal the data space.
178 if (!matchSpace(aResults->rawbuf[offset], SONY_SPACE)) {
179 return false;
180 }
181 offset++;
182
183 // bit value is determined by length of the mark
184 if (matchMark(aResults->rawbuf[offset], SONY_ONE_MARK)) {
185 data = (data << 1) | 1;
186 } else if (matchMark(aResults->rawbuf[offset], SONY_ZERO_MARK)) {
187 data = (data << 1) | 0;
188 } else {
189 return false;
190 }
191 offset++;
192 bits++;
193
194 }
195
196 aResults->bits = bits;
197 aResults->value = data;
198 aResults->decode_type = SONY;
199 decodedIRData.protocol = SONY;
200 return true;
201}
202

Callers

nothing calls this directly

Calls 2

matchMarkFunction · 0.85
matchSpaceFunction · 0.85

Tested by

no test coverage detected