2021-01-28 00:28:44 +08:00
/**
2021-03-06 20:47:47 +08:00
* @ file IRProtocol . h
2021-01-28 00:28:44 +08:00
* @ brief Common declarations for receiving and sending .
*
2021-03-03 02:59:41 +08:00
* This file is part of Arduino - IRremote https : //github.com/Arduino-IRremote/Arduino-IRremote.
2021-01-28 00:28:44 +08:00
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MIT License
*
2024-04-26 03:16:40 +08:00
* Copyright ( c ) 2020 - 2024 Armin Joachimsmeyer
2021-01-28 00:28:44 +08:00
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is furnished
* to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR IMPLIED ,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF
* CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2022-03-30 17:55:04 +08:00
# ifndef _IR_PROTOCOL_H
# define _IR_PROTOCOL_H
2021-01-28 00:28:44 +08:00
/**
* An enum consisting of all supported formats .
* You do NOT need to remove entries from this list when disabling protocols !
2022-08-31 20:07:41 +08:00
* ! ! ! Must be the same order as ProtocolNames in IRReceive . hpp ! ! !
2021-01-28 00:28:44 +08:00
*/
typedef enum {
UNKNOWN = 0 ,
2021-04-29 23:33:05 +08:00
PULSE_WIDTH ,
2022-07-12 17:46:04 +08:00
PULSE_DISTANCE ,
2022-08-31 20:07:41 +08:00
APPLE ,
2021-01-28 00:28:44 +08:00
DENON ,
JVC ,
LG ,
2021-06-16 07:02:18 +08:00
LG2 ,
2021-01-28 00:28:44 +08:00
NEC ,
2022-08-31 20:07:41 +08:00
NEC2 , /* NEC with full frame as repeat */
ONKYO ,
2021-01-28 00:28:44 +08:00
PANASONIC ,
KASEIKYO ,
KASEIKYO_DENON ,
KASEIKYO_SHARP ,
2022-07-12 17:46:04 +08:00
KASEIKYO_JVC ,
2021-01-28 00:28:44 +08:00
KASEIKYO_MITSUBISHI ,
RC5 ,
RC6 ,
SAMSUNG ,
2024-02-24 02:28:33 +08:00
SAMSUNGLG ,
2022-12-27 23:59:32 +08:00
SAMSUNG48 ,
2022-08-31 20:07:41 +08:00
SHARP ,
2021-01-28 00:28:44 +08:00
SONY ,
2022-08-31 20:07:41 +08:00
/* Now the exotic protocols */
2022-10-02 16:00:58 +08:00
BANG_OLUFSEN ,
2021-01-28 07:58:26 +08:00
BOSEWAVE ,
LEGO_PF ,
MAGIQUEST ,
2021-01-28 00:28:44 +08:00
WHYNTER ,
2023-02-24 09:40:21 +08:00
FAST
2021-01-28 00:28:44 +08:00
} decode_type_t ;
2023-02-24 09:40:21 +08:00
# define SIRCS_12_PROTOCOL 12
# define SIRCS_15_PROTOCOL 15
# define SIRCS_20_PROTOCOL 20
struct DistanceWidthTimingInfoStruct {
uint16_t HeaderMarkMicros ;
uint16_t HeaderSpaceMicros ;
uint16_t OneMarkMicros ;
uint16_t OneSpaceMicros ;
uint16_t ZeroMarkMicros ;
uint16_t ZeroSpaceMicros ;
2022-08-28 02:22:58 +08:00
} ;
2022-11-14 22:53:29 +08:00
/*
* Definitions for member IRData . flags
*/
# define IRDATA_FLAGS_EMPTY 0x00
2023-01-08 03:52:51 +08:00
# define IRDATA_FLAGS_IS_REPEAT 0x01 ///< The gap between the preceding frame is as smaller than the maximum gap expected for a repeat. !!!We do not check for changed command or address, because it is almost not possible to press 2 different buttons on the remote within around 100 ms!!!
2023-01-02 22:19:42 +08:00
# define IRDATA_FLAGS_IS_AUTO_REPEAT 0x02 ///< The current repeat frame is a repeat, that is always sent after a regular frame and cannot be avoided. Only specified for protocols DENON, and LEGO.
# define IRDATA_FLAGS_PARITY_FAILED 0x04 ///< The current (autorepeat) frame violated parity check.
2023-03-14 05:26:06 +08:00
# define IRDATA_FLAGS_TOGGLE_BIT 0x08 ///< Is set if RC5 or RC6 toggle bit is set.
# define IRDATA_TOGGLE_BIT_MASK 0x08 ///< deprecated -is set if RC5 or RC6 toggle bit is set.
# define IRDATA_FLAGS_EXTRA_INFO 0x10 ///< There is extra info not contained in address and data (e.g. Kaseikyo unknown vendor ID, or in decodedRawDataArray).
2024-02-24 02:28:33 +08:00
# define IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT 0x20 ///< Here we have a repeat of type NEC2 or SamsungLG
2023-03-14 05:26:06 +08:00
# define IRDATA_FLAGS_WAS_OVERFLOW 0x40 ///< irparams.rawlen is set to 0 in this case to avoid endless OverflowFlag.
# define IRDATA_FLAGS_IS_MSB_FIRST 0x80 ///< Value is mainly determined by the (known) protocol.
2022-11-14 22:53:29 +08:00
# define IRDATA_FLAGS_IS_LSB_FIRST 0x00
2023-02-24 09:40:21 +08:00
# define RAW_DATA_ARRAY_SIZE ((((RAW_BUFFER_LENGTH - 2) - 1) / (2 * BITS_IN_RAW_DATA_TYPE)) + 1) // The -2 is for initial gap + stop bit mark, 128 mark + spaces for 64 bit.
2022-11-14 22:53:29 +08:00
/**
* Data structure for the user application , available as decodedIRData .
* Filled by decoders and read by print functions or user application .
*/
struct IRData {
decode_type_t protocol ; ///< UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ...
uint16_t address ; ///< Decoded address, Distance protocol (tMarkTicksLong (if tMarkTicksLong == 0, then tMarkTicksShort) << 8) | tSpaceTicksLong
uint16_t command ; ///< Decoded command, Distance protocol (tMarkTicksShort << 8) | tSpaceTicksShort
uint16_t extra ; ///< Contains upper 16 bit of Magiquest WandID, Kaseikyo unknown vendor ID and Distance protocol (HeaderMarkTicks << 8) | HeaderSpaceTicks.
2022-11-22 19:28:10 +08:00
IRRawDataType decodedRawData ; ///< Up to 32/64 bit decoded raw data, to be used for send functions.
# if defined(DECODE_DISTANCE_WIDTH)
2023-02-24 09:40:21 +08:00
// This replaces the address, command, extra and decodedRawData in case of protocol == PULSE_DISTANCE or -rather seldom- protocol == PULSE_WIDTH.
DistanceWidthTimingInfoStruct DistanceWidthTimingInfo ; // 12 bytes
2022-11-22 19:28:10 +08:00
IRRawDataType decodedRawDataArray [ RAW_DATA_ARRAY_SIZE ] ; ///< 32/64 bit decoded raw data, to be used for send function.
# endif
2023-02-24 09:40:21 +08:00
uint16_t numberOfBits ; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible.
2023-03-14 05:26:06 +08:00
uint8_t flags ; ///< IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above
2024-02-24 02:28:33 +08:00
2024-03-16 03:54:05 +08:00
// These 2 variables allow to call resume() directly after decode, if no dump is required. Since 4.3.0.
2024-03-16 08:15:06 +08:00
IRRawlenType rawlen ; ///< counter of entries in rawbuf
2024-02-24 02:28:33 +08:00
uint16_t initialGap ; ///< rawbuf[0] contains the initial gap of the last frame.
2022-11-14 22:53:29 +08:00
irparams_struct * rawDataPtr ; ///< Pointer of the raw timing data to be decoded. Mainly the OverflowFlag and the data buffer filled by receiving ISR.
} ;
2023-02-24 09:40:21 +08:00
struct PulseDistanceWidthProtocolConstants {
decode_type_t ProtocolIndex ;
uint_fast8_t FrequencyKHz ;
DistanceWidthTimingInfoStruct DistanceWidthTimingInfo ;
uint8_t Flags ;
unsigned int RepeatPeriodMillis ;
void ( * SpecialSendRepeatFunction ) ( ) ; // using non member functions here saves up to 250 bytes for send demo
// void (IRsend::*SpecialSendRepeatFunction)();
} ;
/*
* Definitions for member PulseDistanceWidthProtocolConstants . Flags
*/
2024-03-16 08:15:06 +08:00
# define SUPPRESS_STOP_BIT_FOR_THIS_DATA 0x20 // Stop bit is otherwise sent for all pulse distance protocols.
2023-02-24 09:40:21 +08:00
# define PROTOCOL_IS_MSB_FIRST IRDATA_FLAGS_IS_MSB_FIRST
# define PROTOCOL_IS_LSB_FIRST IRDATA_FLAGS_IS_LSB_FIRST
2021-01-28 00:28:44 +08:00
2021-09-07 15:46:08 +08:00
/*
* Carrier frequencies for various protocols
*/
2022-10-03 02:45:57 +08:00
# if !defined(BEO_KHZ) // guard used for unit test, which sends and receive Bang&Olufsen with 38 kHz.
2022-10-02 16:00:58 +08:00
# define BEO_KHZ 455
2022-10-03 02:45:57 +08:00
# endif
2021-09-07 15:46:08 +08:00
# define SONY_KHZ 40
# define BOSEWAVE_KHZ 38
# define DENON_KHZ 38
# define JVC_KHZ 38
# define LG_KHZ 38
# define NEC_KHZ 38
# define SAMSUNG_KHZ 38
# define KASEIKYO_KHZ 37
# define RC5_RC6_KHZ 36
2021-09-07 05:09:48 +08:00
2022-11-14 22:53:29 +08:00
# if defined(__AVR__)
const __FlashStringHelper * getProtocolString ( decode_type_t aProtocol ) ;
# else
const char * getProtocolString ( decode_type_t aProtocol ) ;
# endif
void printIRResultShort ( Print * aSerial , IRData * aIRDataPtr , bool aPrintGap ) ; // A static function to be able to print send or copied received data.
/*
* Convenience functions to convert MSB to LSB values
*/
uint8_t bitreverseOneByte ( uint8_t aValue ) ;
uint32_t bitreverse32Bit ( uint32_t aInput ) ;
2022-03-30 17:55:04 +08:00
# endif // _IR_PROTOCOL_H