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

Method decodeHash

src/IRReceive.hpp:1163–1185  ·  view source on GitHub ↗

* Decodes an arbitrary IR code to a 32-bit value. * Instead of decoding using a standard encoding scheme * (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value. * * The algorithm looks at the sequence of MARK and SPACE signals, and see if each one * is more than 20% shorter (0), the same (+/- 20%) length (1), or more than 20% longer (2) than the previous MARK or SPACE. * It hash the r

Source from the content-addressed store, hash-verified

1161 * see: http://www.righto.com/2010/01/using-arbitrary-remotes-with-arduino.html
1162 */
1163bool IRrecv::decodeHash() {
1164 unsigned long hash = FNV_BASIS_32; // the result is the same no matter if we use a long or unsigned long variable
1165
1166// Require at least 6 samples to prevent triggering on noise
1167 if (decodedIRData.rawlen < 6) {
1168 DEBUG_PRINT(F("HASH: Data length="));
1169 DEBUG_PRINT(decodedIRData.rawlen);
1170 DEBUG_PRINTLN(F(" is less than 6"));
1171 return false;
1172 }
1173 for (IRRawlenType i = 1; (i + 2) < decodedIRData.rawlen; i++) {
1174 // Compare mark with mark and space with space
1175 uint_fast8_t value = compare(irparams.rawbuf[i], irparams.rawbuf[i + 2]);
1176 // Add value into the hash - (0 if rawbuf[i + 2] is more than 20 % shorter, 1 if rawbuf[i + 2] is equal, and 2 if rawbuf[i + 2] is longer than rawbuf[i])
1177 hash = (hash * FNV_PRIME_32) ^ value;
1178 }
1179
1180 decodedIRData.decodedRawData = hash;
1181 decodedIRData.numberOfBits = 32;
1182 decodedIRData.protocol = UNKNOWN;
1183
1184 return true;
1185}
1186
1187bool IRrecv::decodeHashOld(decode_results *aResults) {
1188 unsigned long hash = FNV_BASIS_32;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected