Go to the documentation of this file.
30 #ifndef _IR_RC5_RC6_HPP
31 #define _IR_RC5_RC6_HPP
33 #if defined(DEBUG) && !defined(LOCAL_DEBUG)
79 #define RC5_ADDRESS_BITS 5
80 #define RC5_COMMAND_BITS 6
81 #define RC5_COMMAND_FIELD_BIT 1
82 #define RC5_TOGGLE_BIT 1
84 #define RC5_BITS (RC5_COMMAND_FIELD_BIT + RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS) // 13
86 #define RC5_UNIT 889 // 32 periods of 36 kHz (888.8888)
88 #define MIN_RC5_MARKS ((RC5_BITS + 1) / 2) // 7
90 #define RC5_DURATION (15L * RC5_UNIT) // 13335
91 #define RC5_REPEAT_PERIOD (128L * RC5_UNIT) // 113792
92 #define RC5_REPEAT_DISTANCE (RC5_REPEAT_PERIOD - RC5_DURATION) // 100 ms
102 void IRsend::sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats,
bool aEnableAutomaticToggle) {
117 if (aEnableAutomaticToggle) {
128 while (tNumberOfCommands > 0) {
135 if (tNumberOfCommands > 0) {
140 #if !defined(DISABLE_CODE_FOR_RECEIVER)
159 uint32_t tDecodedRawData = 0;
189 if ((tStartLevel ==
SPACE) && (tEndLevel ==
MARK)) {
191 tDecodedRawData = (tDecodedRawData << 1) | 1;
192 }
else if ((tStartLevel ==
MARK) && (tEndLevel ==
SPACE)) {
194 tDecodedRawData = (tDecodedRawData << 1) | 0;
196 #if defined(LOCAL_DEBUG)
197 Serial.print(F(
"RC5: "));
198 Serial.println(F(
"no transition found, decode failed"));
208 tValue.
ULong = tDecodedRawData;
256 #define MIN_RC6_SAMPLES 1
258 #define RC6_RPT_LENGTH 46000
260 #define RC6_LEADING_BIT 1
261 #define RC6_MODE_BITS 3 // never seen others than all 0 for Philips TV
262 #define RC6_TOGGLE_BIT 1 // toggles at every key press. Can be used to distinguish repeats from 2 key presses and has another timing :-(.
263 #define RC6_TOGGLE_BIT_INDEX RC6_MODE_BITS // fourth position, index = 3
264 #define RC6_ADDRESS_BITS 8
265 #define RC6_COMMAND_BITS 8
267 #define RC6_BITS (RC6_LEADING_BIT + RC6_MODE_BITS + RC6_TOGGLE_BIT + RC6_ADDRESS_BITS + RC6_COMMAND_BITS) // 13
269 #define RC6_UNIT 444 // 16 periods of 36 kHz (444.4444)
271 #define RC6_HEADER_MARK (6 * RC6_UNIT) // 2666
272 #define RC6_HEADER_SPACE (2 * RC6_UNIT) // 889
274 #define RC6_TRAILING_SPACE (6 * RC6_UNIT) // 2666
275 #define MIN_RC6_MARKS 4 + ((RC6_ADDRESS_BITS + RC6_COMMAND_BITS) / 2) // 12, 4 are for preamble
277 #define RC6_REPEAT_DISTANCE 107000 // just a guess but > 2.666ms
298 uint32_t mask = 1UL << (aNumberOfBitsToSend - 1);
299 for (uint_fast8_t i = 1; mask; i++, mask >>= 1) {
302 if (aRawData & mask) {
310 #if !defined(DISABLE_CODE_FOR_RECEIVER)
335 uint64_t mask = 1ULL << (aNumberOfBitsToSend - 1);
336 for (uint_fast8_t i = 1; mask; i++, mask >>= 1) {
339 if (aRawData & mask) {
347 #if !defined(DISABLE_CODE_FOR_RECEIVER)
357 void IRsend::sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats,
bool aEnableAutomaticToggle) {
364 if (aEnableAutomaticToggle) {
375 #if defined(LOCAL_DEBUG)
376 Serial.print(F(
"RC6: "));
377 Serial.print(F(
"sLastSendToggleValue="));
379 Serial.print(F(
" RawData="));
380 Serial.println(tIRRawData.
ULong, HEX);
384 while (tNumberOfCommands > 0) {
391 if (tNumberOfCommands > 0) {
403 uint32_t tDecodedRawData = 0;
446 #if defined(LOCAL_DEBUG)
447 Serial.print(F(
"RC6: "));
448 Serial.println(F(
"Toggle mark or space length is wrong"));
458 #if defined(LOCAL_DEBUG)
459 Serial.print(F(
"RC6: "));
460 Serial.println(F(
"Toggle mark or space length is wrong"));
469 if ((tStartLevel ==
MARK) && (tEndLevel ==
SPACE)) {
471 tDecodedRawData = (tDecodedRawData << 1) | 1;
472 }
else if ((tStartLevel ==
SPACE) && (tEndLevel ==
MARK)) {
474 tDecodedRawData = (tDecodedRawData << 1) | 0;
476 #if defined(LOCAL_DEBUG)
477 Serial.print(F(
"RC6: "));
478 Serial.println(F(
"Decode failed"));
489 tValue.
ULong = tDecodedRawData;
492 if (tBitIndex < 36) {
501 if (tBitIndex > 20) {
541 for (uint32_t mask = 1UL << (nbits - 1); mask; mask >>= 1) {
550 #if !defined(DISABLE_CODE_FOR_RECEIVER)
562 uint8_t addressBits = 5;
563 uint8_t commandBits = 7;
570 uint8_t cmdBit6 = (1UL << (commandBits - 1)) & cmd;
582 static int toggleBit = 1;
584 if (toggleBit == 0) {
599 for (uint_fast8_t mask = 1UL << (addressBits - 1); mask; mask >>= 1) {
610 for (uint_fast8_t mask = 1UL << (commandBits - 1); mask; mask >>= 1) {
619 #if !defined(DISABLE_CODE_FOR_RECEIVER)
625 #if defined(LOCAL_DEBUG)
628 #endif // _IR_RC5_RC6_HPP
uint16_t address
Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << ...
#define MICROS_PER_TICK
microseconds per clock interrupt tick
Union to specify parts / manifestations of a 32 bit Long without casts and shifts.
uint16_t numberOfBits
Number of bits received for data (address + command + parity) - to determine protocol length if diffe...
void uint8_t int_fast8_t aNumberOfRepeats
#define MICROS_IN_ONE_MILLI
struct LongUnion::@4 UByte
void mark(unsigned int aMarkMicros)
Sends an IR mark for the specified number of microseconds.
void sendRC6Raw(uint32_t data, uint8_t nbits)
void sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle=true)
Assemble raw data for RC6 from parameters and toggle state and send We do not wait for the minimal tr...
#define IRDATA_FLAGS_IS_REPEAT
uint8_t sLastSendToggleValue
void restartAfterSend()
Restarts receiver after send.
uint_fast8_t sBiphaseDecodeRawbuffOffset
#define RC5_REPEAT_DISTANCE
irparams_struct * rawDataPtr
Pointer of the raw timing data to be decoded. Mainly the OverflowFlag and the data buffer filled by r...
void initBiphaselevel(uint_fast8_t aRCDecodeRawbuffOffset, unsigned int aBiphaseTimeUnit)
IRRawDataType decodedRawData
Up to 32/64 bit decoded raw data, to be used for send functions.
#define IR_DEBUG_PRINT(...)
If DEBUG, print the arguments, otherwise do nothing.
void sendBiphaseData(unsigned int aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits)
Sends Biphase data MSB first Always send start bit, do not send the trailing space of the start bit 0...
uint_fast8_t getBiphaselevel()
Gets the level of one time interval (aBiphaseTimeUnit) at a time from the raw buffer.
uint_fast8_t rawlen
counter of entries in rawbuf
#define IRDATA_FLAGS_EXTRA_INFO
There is extra info not contained in address and data (e.g. Kaseikyo unknown vendor ID,...
bool matchSpace(unsigned int aMeasuredTicks, unsigned int aMatchValueMicros)
Compensate for spaces shortened by demodulator hardware.
uint8_t flags
See IRDATA_FLAGS_* definitions above.
void sendRC5ext(uint8_t addr, uint8_t cmd, bool toggle)
void checkForRepeatSpaceAndSetFlag(unsigned int aMediumRepeatSpaceMicros)
unsigned int rawbuf[RAW_BUFFER_LENGTH]
raw data / tick counts per mark/space, first entry is the length of the gap between previous and curr...
uint16_t command
Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort.
#define IRDATA_FLAGS_IS_MSB_FIRST
Value is mainly determined by the (known) protocol.
static void space(unsigned int aSpaceMicros)
Sends an IR space for the specified number of microseconds.
bool decodeRC5()
Try to decode data as RC5 protocol.
#define RC6_REPEAT_DISTANCE
#define IRDATA_FLAGS_TOGGLE_BIT
is set if RC5 or RC6 toggle bit is set
#define RC6_TOGGLE_BIT_INDEX
void sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle=true)
struct LongUnion::@6 UWord
#define IR_DEBUG_PRINTLN(...)
If DEBUG, print the arguments as a line, otherwise do nothing.
bool matchMark(unsigned int aMeasuredTicks, unsigned int aMatchValueMicros)
Compensate for marks exceeded by demodulator hardware.
decode_type_t protocol
UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
bool decodeRC6()
Try to decode data as RC6 protocol.
IRrecv IrReceiver
The receiver instance.
void enableIROut(uint_fast8_t aFrequencyKHz)
Enables IR output.