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

Method decodeDistanceWidth

src/ir_DistanceWidthProtocol.hpp:206–508  ·  view source on GitHub ↗

* Try to decode a pulse distance or pulse width protocol. * 1. Analyze all space and mark length * 2. Decide if we have an pulse width or distance protocol * 3. Try to decode with the mark and space data found in step 1 * No data and address decoding, only raw data as result. * * Restrictions: * Only protocols with at least 7 bits (+ start and trailing stop bit) are accepted. * Pulse or pa

Source from the content-addressed store, hash-verified

204 * calloc() version is 700 bytes larger :-(
205 */
206bool IRrecv::decodeDistanceWidth() {
207 /*
208 * Array for up to 49 ticks / 2500 us (or 199 ticks / 10 ms us if RAM > 2k)
209 * tick array index 0 covers mark or space durations from 0 to 49 us, and index 49 from 2450 to 2499 us
210 */
211 uint8_t tDurationArray[DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE];
212
213 /*
214 * Only protocols with at least 7 bits are accepted
215 */
216 if (decodedIRData.rawlen < (2 * 7) + 4) {
217#if defined(DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS)
218 Serial.print(F("PULSE_DISTANCE_WIDTH: "));
219 Serial.print(F("Data length="));
220 Serial.print(decodedIRData.rawlen);
221 Serial.println(F(" is less than 18"));
222#endif
223 return false;
224 }
225
226 // Reset duration array
227 memset(tDurationArray, 0, DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE);
228
229 uint8_t tIndexOfMaxDuration = 0;
230 /*
231 * Count number of mark durations. Skip leading start and trailing stop bit.
232 */
233 for (IRRawlenType i = 3; i < decodedIRData.rawlen - 2; i += 2) {
234#if(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE > 0xFF)
235 uint16_t tDurationTicks = irparams.rawbuf[i];
236#else
237 auto tDurationTicks = irparams.rawbuf[i];
238#endif
239 if (tDurationTicks < DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE) {
240 tDurationArray[tDurationTicks]++; // count duration if less than DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE
241 if (tIndexOfMaxDuration < tDurationTicks) {
242 tIndexOfMaxDuration = tDurationTicks;
243 }
244 } else {
245#if defined(LOCAL_DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS)
246 Serial.print(F("PULSE_DISTANCE_WIDTH: Mark "));
247 Serial.print(tDurationTicks * MICROS_PER_TICK);
248 Serial.print(F(" is longer than maximum "));
249 Serial.print(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE * MICROS_PER_TICK);
250 Serial.print(F(" us. Index="));
251 Serial.println(i);
252#endif
253 return false;
254 }
255 }
256
257 /*
258 * Aggregate mark counts to one duration bin
259 */
260 uint8_t tMarkTicksShort = 0;
261 uint8_t tMarkTicksLong = 0;
262 bool tSuccess = aggregateArrayCounts(tDurationArray, tIndexOfMaxDuration, &tMarkTicksShort, &tMarkTicksLong);
263#if defined(LOCAL_DEBUG)

Callers

nothing calls this directly

Calls 4

aggregateArrayCountsFunction · 0.85
printDurationsFunction · 0.85
printlnFunction · 0.85

Tested by

no test coverage detected