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

Method decodePulseDistanceWidthData

src/IRReceive.hpp:758–816  ·  view source on GitHub ↗

* Common decode functions **********************************************************************************************************************/ * Decode pulse distance width protocols. We only check the mark or space length of a 1 against a threshold value, otherwise we always assume a 0! * We do not check the length of the constant pulse for the widely used PulseDistance width and the constan

Source from the content-addressed store, hash-verified

756 * @param aMSBfirst If true send Most Significant Bit first, else send Least Significant Bit (lowest bit) first.
757 */
758void IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMicros,
759 bool aIsPulseWidthProtocol, bool aMSBfirst) {
760
761 DEBUG_PRINT(F("aOneMicros="));
762 DEBUG_PRINT(aOneMicros);
763 DEBUG_PRINT(F(", 0.75*aOneMicros="));
764 DEBUG_PRINT((aOneMicros * 3) / 4);
765 DEBUG_PRINT(F(", MARK_EXCESS_MICROS=" STR(MARK_EXCESS_MICROS) " isPulseWidthProtocol="));
766 DEBUG_PRINT(aIsPulseWidthProtocol);
767 DEBUG_PRINTLN();
768
769 IRDecodedRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop
770 IRDecodedRawDataType tMask = 1UL; // Mask is only used for LSB first
771 auto *tRawBufPointer = &irparams.rawbuf[aStartOffset];
772
773 for (uint_fast8_t i = aNumberOfBits; i > 0; i--) {
774
775 bool tBitValue;
776 uint16_t tCurrentTicks;
777 if (aIsPulseWidthProtocol) {
778 /*
779 * PULSE_WIDTH here.
780 * !!!We only check variable length mark indicating a 1 or 0!!!
781 */
782 tCurrentTicks = *tRawBufPointer++;
783 tBitValue = matchMark(tCurrentTicks, aOneMicros); // Check for variable length mark indicating a 1 or 0
784 tRawBufPointer++;
785 } else {
786 /*
787 * PULSE_DISTANCE -including PULSE_DISTANCE_WIDTH- here.
788 * !!!We only check variable length space indicating a 1 or 0!!!
789 */
790 tRawBufPointer++;
791 tCurrentTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-)
792 tBitValue = matchSpace(tCurrentTicks, aOneMicros); // Check for variable length space indicating a 1 or 0
793 }
794
795 if (aMSBfirst) {
796 tDecodedData <<= 1;
797 }
798
799 if (tBitValue) {
800 // It's a 1 -> set the bit
801 if (aMSBfirst) {
802 tDecodedData |= 1;
803 } else {
804 tDecodedData |= tMask;
805 }
806 TRACE_PRINT(tCurrentTicks);
807 TRACE_PRINTLN(F(" => 1"));
808 } else {
809 // do not set the bit
810 TRACE_PRINT(tCurrentTicks);
811 TRACE_PRINTLN(F(" => 0"));
812 }
813 tMask <<= 1;
814 }
815 decodedIRData.decodedRawData = tDecodedData;

Callers

nothing calls this directly

Calls 2

matchMarkFunction · 0.85
matchSpaceFunction · 0.85

Tested by

no test coverage detected