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

Method getBiphaselevel

src/ir_RC5_RC6.hpp:303–345  ·  view source on GitHub ↗

* Gets the level of one time interval (aBiphaseTimeUnit) at a time from the raw buffer. * The RC5/6 decoding is easier if the data is broken into time intervals. * E.g. if the buffer has mark for 2 time intervals and space for 1, * successive calls to getBiphaselevel will return 1, 1, 0. * * _ _ _ _ _ _ _ _ _ _ _ _ _ * _____| |_| |_| |_| |_| |_|

Source from the content-addressed store, hash-verified

301 * Returns current level [MARK or SPACE] or NO_MARK_OR_SPACE for error (measured time interval is not a multiple of BiphaseTimeUnit).
302 */
303uint_fast8_t IRrecv::getBiphaselevel() {
304 uint_fast8_t tLevelOfCurrentInterval; // Return value: 0 (SPACE) or 1 (MARK)
305
306 if (irparams.RawbuffOffsetForNextBiphaseLevel >= decodedIRData.rawlen) {
307 return SPACE; // After end of recorded buffer, assume space.
308 }
309
310 tLevelOfCurrentInterval = (irparams.RawbuffOffsetForNextBiphaseLevel) & 1; // on odd rawbuf offsets we have mark timings
311
312 /*
313 * Refill NumberOfTimingIntervalsInCurrentInterval if AlreadyUsedTimingIntervalsOfCurrentInterval is 0
314 * i.e. we went to next rawbuf interval
315 */
316 if (irparams.AlreadyUsedTimingIntervalsOfCurrentInterval == 0) {
317 uint16_t tCurrentIntervalWithMicros = irparams.rawbuf[irparams.RawbuffOffsetForNextBiphaseLevel] * MICROS_PER_TICK;
318 uint16_t tMarkExcessCorrectionMicros = (tLevelOfCurrentInterval == MARK) ? MARK_EXCESS_MICROS : -MARK_EXCESS_MICROS;
319 irparams.NumberOfTimingIntervalsInCurrentInterval = getNumberOfUnitsInInterval(
320 tCurrentIntervalWithMicros + tMarkExcessCorrectionMicros, irparams.BiphaseTimeUnit);
321 // 666 is 3/4 of RC5 time unit
322 TRACE_PRINT(tLevelOfCurrentInterval);
323 TRACE_PRINT(F("="));
324 TRACE_PRINT(tCurrentIntervalWithMicros + tMarkExcessCorrectionMicros);
325 TRACE_PRINT(F(" "));
326 TRACE_PRINTLN(irparams.NumberOfTimingIntervalsInCurrentInterval);
327 }
328 if (irparams.NumberOfTimingIntervalsInCurrentInterval == 0) {
329 return NO_MARK_OR_SPACE;
330 }
331
332// We use another interval from tCurrentTimingIntervals
333 irparams.AlreadyUsedTimingIntervalsOfCurrentInterval++;
334
335 if (irparams.AlreadyUsedTimingIntervalsOfCurrentInterval >= irparams.NumberOfTimingIntervalsInCurrentInterval) {
336 /*
337 * We have used all intervals of current interval (mark or space duration in rawbuf), go to next rawbuf interval
338 */
339 irparams.AlreadyUsedTimingIntervalsOfCurrentInterval = 0;
340 irparams.RawbuffOffsetForNextBiphaseLevel++;
341 }
342
343
344 return tLevelOfCurrentInterval;
345}
346# endif // defined(DECODE_RC5) || defined(DECODE_MARANTZ) || defined(DECODE_RC6)
347
348#if defined(DECODE_RC5) || defined(DECODE_MARANTZ)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected