Update IRRemoteESP8266 version to 2.5.5
factorize IR send signal function between the 2 types of receiving Add new IRRemoteESP8266 protocols replace pins on mega according schema remove unecessaries spaces
This commit is contained in:
1 parent
0180a0dbd5
commit
f0305236db
149 files changed
+20957
-7850
No files matched your search
@@ -22,27 +22,27 @@
|
||||
// Ref:
|
||||
// GlobalCache's IR Control Tower data.
|
||||
// http://www.sbprojects.com/knowledge/ir/sharp.php
|
||||
#define SHARP_TICK 26U
|
||||
#define SHARP_BIT_MARK_TICKS 10U
|
||||
#define SHARP_BIT_MARK (SHARP_BIT_MARK_TICKS * SHARP_TICK)
|
||||
#define SHARP_ONE_SPACE_TICKS 70U
|
||||
#define SHARP_ONE_SPACE (SHARP_ONE_SPACE_TICKS * SHARP_TICK)
|
||||
#define SHARP_ZERO_SPACE_TICKS 30U
|
||||
#define SHARP_ZERO_SPACE (SHARP_ZERO_SPACE_TICKS * SHARP_TICK)
|
||||
#define SHARP_GAP_TICKS 1677U
|
||||
#define SHARP_GAP (SHARP_GAP_TICKS * SHARP_TICK)
|
||||
|
||||
const uint16_t kSharpTick = 26;
|
||||
const uint16_t kSharpBitMarkTicks = 10;
|
||||
const uint16_t kSharpBitMark = kSharpBitMarkTicks * kSharpTick;
|
||||
const uint16_t kSharpOneSpaceTicks = 70;
|
||||
const uint16_t kSharpOneSpace = kSharpOneSpaceTicks * kSharpTick;
|
||||
const uint16_t kSharpZeroSpaceTicks = 30;
|
||||
const uint16_t kSharpZeroSpace = kSharpZeroSpaceTicks * kSharpTick;
|
||||
const uint16_t kSharpGapTicks = 1677;
|
||||
const uint16_t kSharpGap = kSharpGapTicks * kSharpTick;
|
||||
// Address(5) + Command(8) + Expansion(1) + Check(1)
|
||||
#define SHARP_TOGGLE_MASK ((1 << (SHARP_BITS - SHARP_ADDRESS_BITS)) - 1)
|
||||
#define SHARP_ADDRESS_MASK ((1 << SHARP_ADDRESS_BITS) - 1)
|
||||
#define SHARP_COMMAND_MASK ((1 << SHARP_COMMAND_BITS) - 1)
|
||||
const uint64_t kSharpToggleMask =
|
||||
((uint64_t)1 << (kSharpBits - kSharpAddressBits)) - 1;
|
||||
const uint64_t kSharpAddressMask = ((uint64_t)1 << kSharpAddressBits) - 1;
|
||||
const uint64_t kSharpCommandMask = ((uint64_t)1 << kSharpCommandBits) - 1;
|
||||
|
||||
#if (SEND_SHARP || SEND_DENON)
|
||||
// Send a (raw) Sharp message
|
||||
//
|
||||
// Args:
|
||||
// data: Contents of the message to be sent.
|
||||
// nbits: Nr. of bits of data to be sent. Typically SHARP_BITS.
|
||||
// nbits: Nr. of bits of data to be sent. Typically kSharpBits.
|
||||
// repeat: Nr. of additional times the message is to be sent.
|
||||
//
|
||||
// Status: BETA / Previously working fine.
|
||||
@@ -67,14 +67,13 @@ void IRsend::sendSharpRaw(uint64_t data, uint16_t nbits, uint16_t repeat) {
|
||||
// normal), however all data points to that being incorrect.
|
||||
for (uint8_t n = 0; n < 2; n++) {
|
||||
sendGeneric(0, 0, // No Header
|
||||
SHARP_BIT_MARK, SHARP_ONE_SPACE,
|
||||
SHARP_BIT_MARK, SHARP_ZERO_SPACE,
|
||||
SHARP_BIT_MARK, SHARP_GAP,
|
||||
data, nbits, 38, true, 0, // Repeats are handled already.
|
||||
kSharpBitMark, kSharpOneSpace, kSharpBitMark, kSharpZeroSpace,
|
||||
kSharpBitMark, kSharpGap, data, nbits, 38, true,
|
||||
0, // Repeats are handled already.
|
||||
33);
|
||||
// Invert the data per protocol. This is always called twice, so it's
|
||||
// retured to original upon exiting the inner loop.
|
||||
data ^= SHARP_TOGGLE_MASK;
|
||||
data ^= kSharpToggleMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,17 +106,17 @@ uint32_t IRsend::encodeSharp(uint16_t address, uint16_t command,
|
||||
uint16_t expansion, uint16_t check,
|
||||
bool MSBfirst) {
|
||||
// Mask any unexpected bits.
|
||||
address &= ((1 << SHARP_ADDRESS_BITS) - 1);
|
||||
command &= ((1 << SHARP_COMMAND_BITS) - 1);
|
||||
address &= ((1 << kSharpAddressBits) - 1);
|
||||
command &= ((1 << kSharpCommandBits) - 1);
|
||||
expansion &= 1;
|
||||
check &= 1;
|
||||
|
||||
if (!MSBfirst) { // Correct bit order if needed.
|
||||
address = reverseBits(address, SHARP_ADDRESS_BITS);
|
||||
command = reverseBits(command, SHARP_COMMAND_BITS);
|
||||
address = reverseBits(address, kSharpAddressBits);
|
||||
command = reverseBits(command, kSharpCommandBits);
|
||||
}
|
||||
// Concatinate all the bits.
|
||||
return (address << (SHARP_COMMAND_BITS + 2)) | (command << 2) |
|
||||
return (address << (kSharpCommandBits + 2)) | (command << 2) |
|
||||
(expansion << 1) | check;
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ uint32_t IRsend::encodeSharp(uint16_t address, uint16_t command,
|
||||
// Args:
|
||||
// address: Address value to be sent.
|
||||
// command: Command value to be sent.
|
||||
// nbits: Nr. of bits of data to be sent. Typically SHARP_BITS.
|
||||
// nbits: Nr. of bits of data to be sent. Typically kSharpBits.
|
||||
// repeat: Nr. of additional times the message is to be sent.
|
||||
//
|
||||
// Status: DEPRICATED / Previously working fine.
|
||||
@@ -156,7 +155,7 @@ void IRsend::sendSharp(uint16_t address, uint16_t command, uint16_t nbits,
|
||||
//
|
||||
// Args:
|
||||
// results: Ptr to the data to decode and where to store the decode result.
|
||||
// nbits: Nr. of data bits to expect. Typically SHARP_BITS.
|
||||
// nbits: Nr. of data bits to expect. Typically kSharpBits.
|
||||
// strict: Flag indicating if we should perform strict matching.
|
||||
// expansion: Should we expect the expansion bit to be set. Default is true.
|
||||
// Returns:
|
||||
@@ -175,90 +174,83 @@ void IRsend::sendSharp(uint16_t address, uint16_t command, uint16_t nbits,
|
||||
// http://www.hifi-remote.com/johnsfine/DecodeIR.html#Sharp
|
||||
bool IRrecv::decodeSharp(decode_results *results, uint16_t nbits, bool strict,
|
||||
bool expansion) {
|
||||
if (results->rawlen < 2 * nbits + FOOTER - 1)
|
||||
if (results->rawlen < 2 * nbits + kFooter - 1)
|
||||
return false; // Not enough entries to be a Sharp message.
|
||||
// Compliance
|
||||
if (strict) {
|
||||
if (nbits != SHARP_BITS)
|
||||
return false; // Request is out of spec.
|
||||
if (nbits != kSharpBits) return false; // Request is out of spec.
|
||||
// DISABLED - See TODO
|
||||
#ifdef UNIT_TEST
|
||||
// An in spec message has the data sent normally, then inverted. So we
|
||||
// expect twice as many entries than to just get the results.
|
||||
if (results->rawlen < 2 * (2 * nbits + FOOTER))
|
||||
return false;
|
||||
if (results->rawlen < 2 * (2 * nbits + kFooter)) return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t data = 0;
|
||||
uint16_t offset = OFFSET_START;
|
||||
uint16_t offset = kStartOffset;
|
||||
|
||||
// No header
|
||||
// But try to auto-calibrate off the initial mark signal.
|
||||
if (!matchMark(results->rawbuf[offset], SHARP_BIT_MARK, 35)) return false;
|
||||
if (!matchMark(results->rawbuf[offset], kSharpBitMark, 35)) return false;
|
||||
// Calculate how long the common tick time is based on the header mark.
|
||||
uint32_t tick = results->rawbuf[offset] * RAWTICK / SHARP_BIT_MARK_TICKS;
|
||||
uint32_t tick = results->rawbuf[offset] * kRawTick / kSharpBitMarkTicks;
|
||||
// Data
|
||||
for (uint16_t i = 0; i < nbits; i++, offset++) {
|
||||
// Use a higher tolerance value for SHARP_BIT_MARK as it is quite small.
|
||||
if (!matchMark(results->rawbuf[offset++], SHARP_BIT_MARK_TICKS * tick, 35))
|
||||
// Use a higher tolerance value for kSharpBitMark as it is quite small.
|
||||
if (!matchMark(results->rawbuf[offset++], kSharpBitMarkTicks * tick, 35))
|
||||
return false;
|
||||
if (matchSpace(results->rawbuf[offset], SHARP_ONE_SPACE_TICKS * tick))
|
||||
if (matchSpace(results->rawbuf[offset], kSharpOneSpaceTicks * tick))
|
||||
data = (data << 1) | 1; // 1
|
||||
else if (matchSpace(results->rawbuf[offset], SHARP_ZERO_SPACE_TICKS * tick))
|
||||
else if (matchSpace(results->rawbuf[offset], kSharpZeroSpaceTicks * tick))
|
||||
data <<= 1; // 0
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// Footer
|
||||
if (!match(results->rawbuf[offset++], SHARP_BIT_MARK_TICKS * tick))
|
||||
if (!match(results->rawbuf[offset++], kSharpBitMarkTicks * tick))
|
||||
return false;
|
||||
if (offset < results->rawlen &&
|
||||
!matchAtLeast(results->rawbuf[offset], SHARP_GAP_TICKS * tick))
|
||||
!matchAtLeast(results->rawbuf[offset], kSharpGapTicks * tick))
|
||||
return false;
|
||||
|
||||
// Compliance
|
||||
if (strict) {
|
||||
// Check the state of the expansion bit is what we expect.
|
||||
if ((data & 0b10) >> 1 != expansion)
|
||||
return false;
|
||||
if ((data & 0b10) >> 1 != expansion) return false;
|
||||
// The check bit should be cleared in a normal message.
|
||||
if (data & 0b1)
|
||||
return false;
|
||||
// DISABLED - See TODO
|
||||
if (data & 0b1) return false;
|
||||
// DISABLED - See TODO
|
||||
#ifdef UNIT_TEST
|
||||
// Grab the second copy of the data (i.e. inverted)
|
||||
// Header
|
||||
// i.e. The inter-data/command repeat gap.
|
||||
if (!matchSpace(results->rawbuf[offset++], SHARP_GAP_TICKS * tick))
|
||||
if (!matchSpace(results->rawbuf[offset++], kSharpGapTicks * tick))
|
||||
return false;
|
||||
|
||||
// Data
|
||||
uint64_t second_data = 0;
|
||||
for (uint16_t i = 0; i < nbits; i++, offset++) {
|
||||
// Use a higher tolerance value for SHARP_BIT_MARK as it is quite small.
|
||||
if (!matchMark(results->rawbuf[offset++], SHARP_BIT_MARK_TICKS * tick,
|
||||
35))
|
||||
// Use a higher tolerance value for kSharpBitMark as it is quite small.
|
||||
if (!matchMark(results->rawbuf[offset++], kSharpBitMarkTicks * tick, 35))
|
||||
return false;
|
||||
if (matchSpace(results->rawbuf[offset], SHARP_ONE_SPACE_TICKS * tick))
|
||||
if (matchSpace(results->rawbuf[offset], kSharpOneSpaceTicks * tick))
|
||||
second_data = (second_data << 1) | 1; // 1
|
||||
else if (matchSpace(results->rawbuf[offset],
|
||||
SHARP_ZERO_SPACE_TICKS * tick))
|
||||
else if (matchSpace(results->rawbuf[offset], kSharpZeroSpaceTicks * tick))
|
||||
second_data <<= 1; // 0
|
||||
else
|
||||
return false;
|
||||
}
|
||||
// Footer
|
||||
if (!match(results->rawbuf[offset++], SHARP_BIT_MARK_TICKS * tick))
|
||||
if (!match(results->rawbuf[offset++], kSharpBitMarkTicks * tick))
|
||||
return false;
|
||||
if (offset < results->rawlen &&
|
||||
!matchAtLeast(results->rawbuf[offset], SHARP_GAP_TICKS * tick))
|
||||
!matchAtLeast(results->rawbuf[offset], kSharpGapTicks * tick))
|
||||
return false;
|
||||
|
||||
// Check that second_data has been inverted correctly.
|
||||
if (data != (second_data ^ SHARP_TOGGLE_MASK))
|
||||
return false;
|
||||
if (data != (second_data ^ kSharpToggleMask)) return false;
|
||||
#endif // UNIT_TEST
|
||||
}
|
||||
|
||||
@@ -267,9 +259,9 @@ bool IRrecv::decodeSharp(decode_results *results, uint16_t nbits, bool strict,
|
||||
results->bits = nbits;
|
||||
results->value = data;
|
||||
// Address & command are actually transmitted in LSB first order.
|
||||
results->address = reverseBits(data, nbits) & SHARP_ADDRESS_MASK;
|
||||
results->command = reverseBits((data >> 2) & SHARP_COMMAND_MASK,
|
||||
SHARP_COMMAND_BITS);
|
||||
results->address = reverseBits(data, nbits) & kSharpAddressMask;
|
||||
results->command =
|
||||
reverseBits((data >> 2) & kSharpCommandMask, kSharpCommandBits);
|
||||
return true;
|
||||
}
|
||||
#endif // (DECODE_SHARP || DECODE_DENON)
|
||||
Reference in new issue
Block a user