2021-01-28 07:58:26 +08:00
/**
* @ file IRremoteInt . h
* @ brief Contains all declarations required for the internal functions .
*
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 07:58:26 +08:00
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MIT License
*
* Copyright ( c ) 2015 - 2021 Ken Shirriff http : //www.righto.com, Rafi Khan, Armin Joachimsmeyer
*
* 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 .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
# ifndef IRremoteInt_h
# define IRremoteInt_h
2021-03-06 08:21:46 +08:00
# include <Arduino.h>
2021-09-28 05:46:13 +08:00
/*
* The length of the buffer where the IR timing data is stored before decoding
* 100 is sufficient for most standard protocols , but air conditioners often send a longer protocol data stream
2021-11-02 02:58:11 +08:00
* ! ! ! RAW_BUFFER_LENGTH must be fixed for ALL compilation units ! ! !
2021-09-28 05:46:13 +08:00
*/
# if !defined(RAW_BUFFER_LENGTH)
2021-10-30 15:50:38 +08:00
2021-02-21 07:17:28 +08:00
# define RAW_BUFFER_LENGTH 100 ///< Maximum length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and 1 stop bit.
2021-11-03 13:57:27 +08:00
//#define RAW_BUFFER_LENGTH 112 // MagiQuest requires 112 bytes.
//#define RAW_BUFFER_LENGTH 750 // 750 is the value for air condition remotes.
2021-02-21 07:17:28 +08:00
# endif
# if RAW_BUFFER_LENGTH % 2 == 1
# error RAW_BUFFER_LENGTH must be even, since the array consists of space / mark pairs.
2021-01-28 07:58:26 +08:00
# endif
2021-03-19 05:01:39 +08:00
# define MARK 1
# define SPACE 0
2021-11-03 13:57:27 +08:00
# define MILLIS_IN_ONE_SECOND 1000L
# define MICROS_IN_ONE_SECOND 1000000L
# define MICROS_IN_ONE_MILLI 1000L
# if defined(PARTICLE)
# define F_CPU 16000000 // definition for a board for which F_CPU is not defined
# elif defined(ARDUINO_ARCH_MBED_RP2040)
# define F_CPU 133000000
# elif defined(ARDUINO_ARDUINO_NANO33BLE)
# define F_CPU 64000000
# endif
# if defined(F_CPU)
# define CLOCKS_PER_MICRO (F_CPU / MICROS_IN_ONE_SECOND)
# else
# error F_CPU not defined, please define it for your board in IRremoteInt.h
# endif
/*
* For backwards compatibility
*/
# if defined(SYSCLOCK) // allow for processor specific code to define F_CPU
# undef F_CPU
# define F_CPU SYSCLOCK // Clock frequency to be used for timing.
# endif
2021-06-16 07:02:18 +08:00
//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core and all protocol decoders.
//#define TRACE // Activate this for more debug output.
2021-04-27 03:50:31 +08:00
/**
* For better readability of code
*/
# define DISABLE_LED_FEEDBACK false
# define ENABLE_LED_FEEDBACK true
# define USE_DEFAULT_FEEDBACK_LED_PIN 0
2021-03-06 20:47:47 +08:00
# include "IRProtocol.h"
2021-01-28 07:58:26 +08:00
2021-03-09 20:45:01 +08:00
/****************************************************
* Declarations for the receiver Interrupt Service Routine
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-01-28 07:58:26 +08:00
// ISR State-Machine : Receiver States
# define IR_REC_STATE_IDLE 0
# define IR_REC_STATE_MARK 1
# define IR_REC_STATE_SPACE 2
2021-09-28 05:46:13 +08:00
# define IR_REC_STATE_STOP 3 // set to IR_REC_STATE_IDLE only by resume()
2021-01-28 07:58:26 +08:00
/**
2021-03-09 08:31:31 +08:00
* This struct contains the data and control used for receiver static functions and the ISR ( interrupt service routine )
2021-03-06 08:21:46 +08:00
* Only StateForISR needs to be volatile . All the other fields are not written by ISR after data available and before start / resume .
2021-01-28 07:58:26 +08:00
*/
struct irparams_struct {
// The fields are ordered to reduce memory over caused by struct-padding
2021-03-06 08:21:46 +08:00
volatile uint8_t StateForISR ; ///< State Machine state
uint8_t IRReceivePin ; ///< Pin connected to IR data from detector
2021-03-09 04:38:06 +08:00
# if defined(__AVR__)
volatile uint8_t * IRReceivePinPortInputRegister ;
uint8_t IRReceivePinMask ;
# endif
2021-04-08 13:59:45 +08:00
uint16_t TickCounterForISR ; ///< Counts 50uS ticks. The value is copied into the rawbuf array on every transition.
bool OverflowFlag ; ///< Raw buffer OverflowFlag occurred
2021-09-28 05:46:13 +08:00
# if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program space and speeds up ISR
2021-01-28 07:58:26 +08:00
uint8_t rawlen ; ///< counter of entries in rawbuf
# else
unsigned int rawlen ; ///< counter of entries in rawbuf
# endif
uint16_t rawbuf [ RAW_BUFFER_LENGTH ] ; ///< raw data / tick counts per mark/space, first entry is the length of the gap between previous and current command
} ;
2021-09-28 05:46:13 +08:00
/*
* Info directives
* Can be disabled to save program space
*/
# ifdef INFO
# define INFO_PRINT(...) Serial.print(__VA_ARGS__)
# define INFO_PRINTLN(...) Serial.println(__VA_ARGS__)
# else
/**
* If INFO , print the arguments , otherwise do nothing .
*/
# define INFO_PRINT(...) void()
/**
* If INFO , print the arguments as a line , otherwise do nothing .
*/
# define INFO_PRINTLN(...) void()
# endif
2021-03-09 04:38:06 +08:00
/*
* Debug directives
*/
2021-01-28 07:58:26 +08:00
# ifdef DEBUG
2021-04-29 23:33:05 +08:00
# define DEBUG_PRINT(...) Serial.print(__VA_ARGS__)
# define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__)
2021-01-28 07:58:26 +08:00
# else
/**
* If DEBUG , print the arguments , otherwise do nothing .
*/
2021-04-29 23:33:05 +08:00
# define DEBUG_PRINT(...) void()
2021-01-28 07:58:26 +08:00
/**
* If DEBUG , print the arguments as a line , otherwise do nothing .
*/
2021-04-29 23:33:05 +08:00
# define DEBUG_PRINTLN(...) void()
2021-01-28 07:58:26 +08:00
# endif
# ifdef TRACE
# define TRACE_PRINT(...) Serial.print(__VA_ARGS__)
# define TRACE_PRINTLN(...) Serial.println(__VA_ARGS__)
# else
# define TRACE_PRINT(...) void()
# define TRACE_PRINTLN(...) void()
# endif
/****************************************************
* RECEIVING
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-04-08 13:59:45 +08:00
/*
* Activating this saves 60 bytes program space and 14 bytes RAM
*/
//#define NO_LEGACY_COMPATIBILITY
# if !defined(NO_LEGACY_COMPATIBILITY)
2021-01-28 07:58:26 +08:00
/**
* Results returned from old decoders ! ! ! deprecated ! ! !
*/
struct decode_results {
decode_type_t decode_type ; // deprecated, moved to decodedIRData.protocol ///< UNKNOWN, NEC, SONY, RC5, ...
2021-04-10 22:49:28 +08:00
uint16_t address ; ///< Used by Panasonic & Sharp [16-bits]
2021-01-28 07:58:26 +08:00
uint32_t value ; // deprecated, moved to decodedIRData.decodedRawData ///< Decoded value / command [max 32-bits]
uint8_t bits ; // deprecated, moved to decodedIRData.numberOfBits ///< Number of bits in decoded value
uint16_t magnitude ; // deprecated, moved to decodedIRData.extra ///< Used by MagiQuest [16-bits]
bool isRepeat ; // deprecated, moved to decodedIRData.flags ///< True if repeat of value is detected
// next 3 values are copies of irparams values - see IRremoteint.h
uint16_t * rawbuf ; // deprecated, moved to decodedIRData.rawDataPtr->rawbuf ///< Raw intervals in 50uS ticks
uint16_t rawlen ; // deprecated, moved to decodedIRData.rawDataPtr->rawlen ///< Number of records in rawbuf
bool overflow ; // deprecated, moved to decodedIRData.flags ///< true if IR raw code too long
} ;
2021-04-08 13:59:45 +08:00
# endif
2021-03-18 04:52:41 +08:00
2021-01-28 07:58:26 +08:00
/*
2021-03-18 04:52:41 +08:00
* Definitions for member IRData . flags
2021-01-28 07:58:26 +08:00
*/
2021-03-09 20:45:01 +08:00
# define IRDATA_FLAGS_EMPTY 0x00
# define IRDATA_FLAGS_IS_REPEAT 0x01
# define IRDATA_FLAGS_IS_AUTO_REPEAT 0x02
2021-03-18 04:52:41 +08:00
# define IRDATA_FLAGS_PARITY_FAILED 0x04 ///< the current (autorepeat) frame violated parity check
2021-03-09 20:45:01 +08:00
# define IRDATA_TOGGLE_BIT_MASK 0x08
2021-03-18 04:52:41 +08:00
# define IRDATA_FLAGS_EXTRA_INFO 0x10 ///< there is unexpected extra info not contained in address and data (e.g. Kaseikyo unknown vendor ID)
# define IRDATA_FLAGS_WAS_OVERFLOW 0x40 ///< irparams.rawlen is 0 in this case to avoid endless OverflowFlag
2021-03-09 20:45:01 +08:00
# define IRDATA_FLAGS_IS_LSB_FIRST 0x00
2021-03-18 04:52:41 +08:00
# define IRDATA_FLAGS_IS_MSB_FIRST 0x80 ///< Just for info. Value is simply determined by the protocol
2021-01-28 07:58:26 +08:00
2021-03-18 04:52:41 +08:00
/**
* Data structure for the user application , available as decodedIRData .
* Filled by decoders and read by print functions or user application .
*/
2021-03-09 20:45:01 +08:00
struct IRData {
decode_type_t protocol ; ///< UNKNOWN, NEC, SONY, RC5, ...
uint16_t address ; ///< Decoded address
uint16_t command ; ///< Decoded command
2021-11-03 13:57:27 +08:00
uint16_t extra ; ///< Used by MagiQuest and for Kaseikyo unknown vendor ID. Ticks used for decoding Distance protocol.
uint16_t numberOfBits ; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible.
2021-03-18 04:52:41 +08:00
uint8_t flags ; ///< See IRDATA_FLAGS_* definitions above
2021-03-09 20:45:01 +08:00
uint32_t decodedRawData ; ///< Up to 32 bit decoded raw data, used for sendRaw functions.
2021-03-18 04:52:41 +08:00
irparams_struct * rawDataPtr ; ///< Pointer of the raw timing data to be decoded. Mainly the data buffer filled by receiving ISR.
2021-03-09 20:45:01 +08:00
} ;
2021-01-28 07:58:26 +08:00
/**
2021-03-18 04:52:41 +08:00
* Just for better readability of code
2021-01-28 07:58:26 +08:00
*/
2021-03-09 20:45:01 +08:00
# define USE_DEFAULT_FEEDBACK_LED_PIN 0
2021-03-18 04:52:41 +08:00
/**
* Main class for receiving IR signals
*/
2021-01-28 07:58:26 +08:00
class IRrecv {
public :
IRrecv ( ) ;
2021-03-06 08:21:46 +08:00
IRrecv ( uint8_t aReceivePin ) ;
IRrecv ( uint8_t aReceivePin , uint8_t aFeedbackLEDPin ) ;
2021-03-09 04:38:06 +08:00
void setReceivePin ( uint8_t aReceivePinNumber ) ;
2021-01-28 07:58:26 +08:00
void enableIRIn ( ) ;
void disableIRIn ( ) ;
/*
* Stream like API
*/
2021-03-06 08:21:46 +08:00
void begin ( uint8_t aReceivePin , bool aEnableLEDFeedback = false , uint8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN ) ;
2021-01-28 07:58:26 +08:00
void start ( ) ; // alias for enableIRIn
2021-09-28 05:46:13 +08:00
void start ( uint32_t aMicrosecondsToAddToGapCounter ) ;
2021-01-28 07:58:26 +08:00
bool available ( ) ;
IRData * read ( ) ; // returns decoded data
// write is a method of class IRsend below
2021-02-04 04:09:14 +08:00
// size_t write(IRData *aIRSendData, uint_fast8_t aNumberOfRepeats = NO_REPEATS);
2021-01-28 07:58:26 +08:00
void stop ( ) ; // alias for disableIRIn
void end ( ) ;
bool isIdle ( ) ;
/*
* The main functions
*/
bool decode ( ) ; // Check if available and try to decode
void resume ( ) ; // Enable receiving of the next value
/*
* Useful info and print functions
*/
void printIRResultShort ( Print * aSerial ) ;
2021-02-19 06:43:11 +08:00
void printIRResultMinimal ( Print * aSerial ) ;
2021-01-28 07:58:26 +08:00
void printIRResultRawFormatted ( Print * aSerial , bool aOutputMicrosecondsInsteadOfTicks = true ) ;
void printIRResultAsCVariables ( Print * aSerial ) ;
void compensateAndPrintIRResultAsCArray ( Print * aSerial , bool aOutputMicrosecondsInsteadOfTicks = true ) ;
void compensateAndPrintIRResultAsPronto ( Print * aSerial , unsigned int frequency = 38000U ) ;
/*
* Store the data for further processing
*/
void compensateAndStoreIRResultInArray ( uint8_t * aArrayPtr ) ;
size_t compensateAndStorePronto ( String * aString , unsigned int frequency = 38000U ) ;
/*
* The main decoding functions used by the individual decoders
*/
2021-02-11 09:14:35 +08:00
bool decodePulseDistanceData ( uint8_t aNumberOfBits , uint8_t aStartOffset , uint16_t aBitMarkMicros , uint16_t aOneSpaceMicros ,
uint16_t aZeroSpaceMicros , bool aMSBfirst ) ;
2021-01-28 07:58:26 +08:00
2021-02-11 09:14:35 +08:00
bool decodePulseWidthData ( uint8_t aNumberOfBits , uint8_t aStartOffset , uint16_t aOneMarkMicros , uint16_t aZeroMarkMicros ,
uint16_t aBitSpaceMicros , bool aMSBfirst ) ;
2021-01-28 07:58:26 +08:00
2021-04-10 22:49:28 +08:00
bool decodeBiPhaseData ( uint_fast8_t aNumberOfBits , uint_fast8_t aStartOffset , uint_fast8_t aStartClockCount ,
uint_fast8_t aValueOfSpaceToMarkTransition , uint16_t aBiphaseTimeUnit ) ;
2021-01-28 07:58:26 +08:00
2021-03-19 05:01:39 +08:00
void initBiphaselevel ( uint8_t aRCDecodeRawbuffOffset , uint16_t aBiphaseTimeUnit ) ;
uint8_t getBiphaselevel ( ) ;
2021-01-28 07:58:26 +08:00
/*
* All standard ( decode address + command ) protocol decoders
*/
bool decodeBoseWave ( ) ;
bool decodeDenon ( ) ;
bool decodeJVC ( ) ;
bool decodeKaseikyo ( ) ;
bool decodeLegoPowerFunctions ( ) ;
bool decodeLG ( ) ;
bool decodeMagiQuest ( ) ; // not completely standard
bool decodeNEC ( ) ;
bool decodeRC5 ( ) ;
bool decodeRC6 ( ) ;
bool decodeSamsung ( ) ;
bool decodeSharp ( ) ; // redirected to decodeDenon()
bool decodeSony ( ) ;
2021-04-28 00:30:41 +08:00
bool decodeDistance ( ) ;
2021-01-28 07:58:26 +08:00
bool decodeHash ( ) ;
// Template function :-)
bool decodeShuzu ( ) ;
/*
* Old functions
*/
2021-04-08 13:59:45 +08:00
# if !defined(NO_LEGACY_COMPATIBILITY)
bool decodeDenonOld ( decode_results * aResults ) ;
bool decodeJVCMSB ( decode_results * aResults ) ;
bool decodeLGMSB ( decode_results * aResults ) ;
bool decodeNECMSB ( decode_results * aResults ) ;
bool decodePanasonicMSB ( decode_results * aResults ) ;
bool decodeSonyMSB ( decode_results * aResults ) ;
bool decodeSAMSUNG ( decode_results * aResults ) ;
bool decodeHashOld ( decode_results * aResults ) ;
2021-04-10 22:49:28 +08:00
bool decode (
decode_results * aResults )
__attribute__ ( ( deprecated ( " Please use IrReceiver.decode() without a parameter and IrReceiver.decodedIRData.<fieldname> . " ) ) ) ; // deprecated
2021-04-08 13:59:45 +08:00
# endif
2021-01-28 07:58:26 +08:00
bool decodeWhynter ( ) ;
2021-09-09 21:53:50 +08:00
// for backward compatibility. Now in IRFeedbackLED.hpp
2021-09-06 16:37:22 +08:00
void blink13 ( bool aEnableLEDFeedback )
__attribute__ ( ( deprecated ( " Please use setLEDFeedback() or enableLEDFeedback() / disableLEDFeedback(). " ) ) ) ; // deprecated
2021-01-28 07:58:26 +08:00
/*
* Internal functions
*/
void initDecodedIRData ( ) ;
uint8_t compare ( unsigned int oldval , unsigned int newval ) ;
2021-03-06 08:21:46 +08:00
IRData decodedIRData ; // New: decoded IR data for the application
2021-01-28 07:58:26 +08:00
// Last decoded IR data for repeat detection
2021-04-29 23:33:05 +08:00
decode_type_t lastDecodedProtocol ;
2021-01-28 07:58:26 +08:00
uint32_t lastDecodedAddress ;
uint32_t lastDecodedCommand ;
2021-03-06 08:21:46 +08:00
uint8_t repeatCount ; // Used e.g. for Denon decode for autorepeat decoding.
2021-01-28 07:58:26 +08:00
} ;
2021-03-19 05:01:39 +08:00
extern uint8_t sBiphaseDecodeRawbuffOffset ; //
2021-03-09 20:45:01 +08:00
/*
* Mark & Space matching functions
*/
bool matchTicks ( uint16_t aMeasuredTicks , uint16_t aMatchValueMicros ) ;
bool matchMark ( uint16_t aMeasuredTicks , uint16_t aMatchValueMicros ) ;
bool matchSpace ( uint16_t aMeasuredTicks , uint16_t aMatchValueMicros ) ;
/*
* Old function names
*/
bool MATCH ( uint16_t measured , uint16_t desired ) ;
bool MATCH_MARK ( uint16_t measured_ticks , uint16_t desired_us ) ;
bool MATCH_SPACE ( uint16_t measured_ticks , uint16_t desired_us ) ;
int getMarkExcessMicros ( ) ;
2021-10-31 01:10:27 +08:00
void printActiveIRProtocols ( Print * aSerial ) ;
2021-01-28 07:58:26 +08:00
void printIRResultShort ( Print * aSerial , IRData * aIRDataPtr , uint16_t aLeadingSpaceDuration = 0 ) ;
2021-03-09 20:45:01 +08:00
/****************************************************
* Feedback LED related functions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void setFeedbackLED ( bool aSwitchLedOn ) ;
void setLEDFeedback ( uint8_t aFeedbackLEDPin , bool aEnableLEDFeedback ) ; // if aFeedbackLEDPin == 0, then take board BLINKLED_ON() and BLINKLED_OFF() functions
2021-09-06 16:37:22 +08:00
void setLEDFeedback ( bool aEnableLEDFeedback ) ; // Direct replacement for blink13()
2021-03-09 20:45:01 +08:00
void enableLEDFeedback ( ) ;
void disableLEDFeedback ( ) ;
void setBlinkPin ( uint8_t aFeedbackLEDPin ) __attribute__ ( ( deprecated ( " Please use setLEDFeedback(). " ) ) ) ; // deprecated
/**
* microseconds per clock interrupt tick
*/
# if ! defined(MICROS_PER_TICK)
# define MICROS_PER_TICK 50
# endif
/*
* Pulse parms are ( ( X * 50 ) - 100 ) for the Mark and ( ( X * 50 ) + 100 ) for the Space .
* First MARK is the one after the long gap
* Pulse parameters in uSec
*/
/** Relative tolerance (in percent) for some comparisons on measured data. */
# define TOLERANCE 25
/** Lower tolerance for comparison of measured data */
//#define LTOL (1.0 - (TOLERANCE/100.))
# define LTOL (100 - TOLERANCE)
/** Upper tolerance for comparison of measured data */
//#define UTOL (1.0 + (TOLERANCE/100.))
# define UTOL (100 + TOLERANCE)
//#define TICKS_LOW(us) ((int)(((us)*LTOL/MICROS_PER_TICK)))
//#define TICKS_HIGH(us) ((int)(((us)*UTOL/MICROS_PER_TICK + 1)))
# if MICROS_PER_TICK == 50 && TOLERANCE == 25 // Defaults
# define TICKS_LOW(us) ((us) / 67 ) // (us) / ((MICROS_PER_TICK:50 / LTOL:75 ) * 100)
# define TICKS_HIGH(us) ((us) / 40 + 1) // (us) / ((MICROS_PER_TICK:50 / UTOL:125) * 100) + 1
# else
# define TICKS_LOW(us) ((uint16_t) ((long) (us) * LTOL / (MICROS_PER_TICK * 100) ))
# define TICKS_HIGH(us) ((uint16_t) ((long) (us) * UTOL / (MICROS_PER_TICK * 100) + 1))
# endif
/*
* The receiver instance
*/
extern IRrecv IrReceiver ;
2021-01-28 07:58:26 +08:00
/****************************************************
* SENDING
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-18 04:52:41 +08:00
/**
2021-01-28 07:58:26 +08:00
* Just for better readability of code
*/
# define NO_REPEATS 0
2021-03-09 20:45:01 +08:00
# define SEND_STOP_BIT true
2021-03-18 04:52:41 +08:00
# define SEND_REPEAT_COMMAND true ///< used for e.g. NEC, where a repeat is different from just repeating the data.
2021-03-09 20:45:01 +08:00
/**
* Duty cycle in percent for sent signals .
*/
# if ! defined(IR_SEND_DUTY_CYCLE)
# define IR_SEND_DUTY_CYCLE 30 // 30 saves power and is compatible to the old existing code
# endif
2021-01-28 07:58:26 +08:00
/**
2021-03-18 04:52:41 +08:00
* Main class for sending IR signals
2021-01-28 07:58:26 +08:00
*/
class IRsend {
public :
2021-11-03 13:57:27 +08:00
IRsend ( ) ;
# if defined(IR_SEND_PIN) || defined(SEND_PWM_BY_TIMER)
void begin ( ) ;
# endif
# if !defined(IR_SEND_PIN) && !defined(SEND_PWM_BY_TIMER)
2021-03-02 22:25:39 +08:00
IRsend ( uint8_t aSendPin ) ;
2021-03-01 18:41:14 +08:00
void setSendPin ( uint8_t aSendPinNumber ) ;
2021-11-03 13:57:27 +08:00
# endif
void begin ( bool aEnableLEDFeedback , uint8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN ) ;
// Not guarded for backward compatibility
2021-03-06 08:21:46 +08:00
void begin ( uint8_t aSendPin , bool aEnableLEDFeedback = true , uint8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN ) ;
2021-03-02 22:25:39 +08:00
2021-01-28 07:58:26 +08:00
2021-02-04 04:09:14 +08:00
size_t write ( IRData * aIRSendData , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
2021-01-28 07:58:26 +08:00
2021-02-04 04:09:14 +08:00
void enableIROut ( uint8_t aFrequencyKHz ) ;
2021-01-28 07:58:26 +08:00
void sendPulseDistanceWidthData ( unsigned int aOneMarkMicros , unsigned int aOneSpaceMicros , unsigned int aZeroMarkMicros ,
unsigned int aZeroSpaceMicros , uint32_t aData , uint8_t aNumberOfBits , bool aMSBfirst , bool aSendStopBit = false ) ;
2021-02-04 04:09:14 +08:00
void sendBiphaseData ( unsigned int aBiphaseTimeUnit , uint32_t aData , uint_fast8_t aNumberOfBits ) ;
2021-01-28 07:58:26 +08:00
2021-03-01 18:41:14 +08:00
void mark ( unsigned int aMarkMicros ) ;
void space ( unsigned int aSpaceMicros ) ;
2021-04-11 19:16:53 +08:00
void IRLedOff ( ) ;
2021-01-28 07:58:26 +08:00
// 8 Bit array
2021-02-04 04:09:14 +08:00
void sendRaw ( const uint8_t aBufferWithTicks [ ] , uint_fast8_t aLengthOfBuffer , uint_fast8_t aIRFrequencyKilohertz ) ;
void sendRaw_P ( const uint8_t aBufferWithTicks [ ] , uint_fast8_t aLengthOfBuffer , uint_fast8_t aIRFrequencyKilohertz ) ;
2021-01-28 07:58:26 +08:00
// 16 Bit array
2021-02-04 04:09:14 +08:00
void sendRaw ( const uint16_t aBufferWithMicroseconds [ ] , uint_fast8_t aLengthOfBuffer , uint_fast8_t aIRFrequencyKilohertz ) ;
void sendRaw_P ( const uint16_t aBufferWithMicroseconds [ ] , uint_fast8_t aLengthOfBuffer , uint_fast8_t aIRFrequencyKilohertz ) ;
2021-01-28 07:58:26 +08:00
/*
* New send functions
*/
2021-02-04 04:09:14 +08:00
void sendBoseWave ( uint8_t aCommand , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
void sendDenon ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , bool aSendSharp = false ) ;
2021-04-10 22:49:28 +08:00
void sendDenonRaw ( uint16_t aRawData , uint_fast8_t aNumberOfRepeats = 0 )
2021-06-21 06:32:42 +08:00
# if !defined (DOXYGEN)
2021-04-10 22:49:28 +08:00
__attribute__ ( ( deprecated ( " Please use sendDenon(aAddress, aCommand, aNumberOfRepeats). " ) ) ) ;
2021-06-21 06:32:42 +08:00
# endif
2021-02-04 04:09:14 +08:00
void sendJVC ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats ) ;
2021-01-28 07:58:26 +08:00
2021-06-16 07:02:18 +08:00
void sendLGRepeat ( bool aUseLG2Protocol = false ) ;
void sendLG ( uint8_t aAddress , uint16_t aCommand , uint_fast8_t aNumberOfRepeats , bool aIsRepeat = false , bool aUseLG2Protocol =
false ) ;
void sendLGRaw ( uint32_t aRawData , uint_fast8_t aNumberOfRepeats = 0 , bool aIsRepeat = false , bool aUseLG2Protocol = false ) ;
2021-02-03 23:07:01 +08:00
2021-01-28 07:58:26 +08:00
void sendNECRepeat ( ) ;
2021-02-04 04:09:14 +08:00
void sendNEC ( uint16_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , bool aIsRepeat = false ) ;
void sendNECRaw ( uint32_t aRawData , uint_fast8_t aNumberOfRepeats = 0 , bool aIsRepeat = false ) ;
2021-04-08 07:51:03 +08:00
// NEC variants
void sendOnkyo ( uint16_t aAddress , uint16_t aCommand , uint_fast8_t aNumberOfRepeats , bool aIsRepeat = false ) ;
2021-02-04 04:09:14 +08:00
void sendApple ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , bool aIsRepeat = false ) ;
2021-02-03 23:07:01 +08:00
2021-02-04 04:09:14 +08:00
void sendKaseikyo ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats , uint16_t aVendorCode ) ; // LSB first
2021-09-24 22:12:37 +08:00
void sendPanasonic ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats ) ; // LSB first
void sendKaseikyo_Denon ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats ) ; // LSB first
void sendKaseikyo_Mitsubishi ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats ) ; // LSB first
void sendKaseikyo_Sharp ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats ) ; // LSB first
void sendKaseikyo_JVC ( uint16_t aAddress , uint8_t aData , uint_fast8_t aNumberOfRepeats ) ; // LSB first
2021-01-28 07:58:26 +08:00
2021-02-04 04:09:14 +08:00
void sendRC5 ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , bool aEnableAutomaticToggle = true ) ;
void sendRC6 ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , bool aEnableAutomaticToggle = true ) ;
2021-01-28 07:58:26 +08:00
void sendSamsungRepeat ( ) ;
2021-02-04 04:09:14 +08:00
void sendSamsung ( uint16_t aAddress , uint16_t aCommand , uint_fast8_t aNumberOfRepeats , bool aIsRepeat = false ) ;
void sendSharp ( uint8_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats ) ; // redirected to sendDenon
void sendSony ( uint16_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats , uint8_t numberOfBits = SIRCS_12_PROTOCOL ) ;
2021-01-28 07:58:26 +08:00
void sendLegoPowerFunctions ( uint8_t aChannel , uint8_t tCommand , uint8_t aMode , bool aDoSend5Times = true ) ;
void sendLegoPowerFunctions ( uint16_t aRawData , bool aDoSend5Times = true ) ;
void sendLegoPowerFunctions ( uint16_t aRawData , uint8_t aChannel , bool aDoSend5Times = true ) ;
void sendMagiQuest ( uint32_t wand_id , uint16_t magnitude ) ;
2021-02-04 04:09:14 +08:00
void sendPronto ( const __FlashStringHelper * str , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
void sendPronto ( const char * prontoHexString , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
void sendPronto ( const uint16_t * data , unsigned int length , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
2021-01-28 07:58:26 +08:00
# if defined(__AVR__)
2021-02-04 04:09:14 +08:00
void sendPronto_PF ( uint_farptr_t str , uint_fast8_t aNumberOfRepeats = NO_REPEATS ) ;
void sendPronto_P ( const char * str , uint_fast8_t aNumberOfRepeats ) ;
2021-01-28 07:58:26 +08:00
# endif
// Template protocol :-)
2021-02-04 04:09:14 +08:00
void sendShuzu ( uint16_t aAddress , uint8_t aCommand , uint_fast8_t aNumberOfRepeats ) ;
2021-01-28 07:58:26 +08:00
/*
* OLD send functions
*/
void sendDenon ( unsigned long data , int nbits ) ;
void sendDISH ( unsigned long data , int nbits ) ;
2021-04-27 03:50:31 +08:00
void sendJVC ( unsigned long data , int nbits ,
bool repeat )
__attribute__ ( ( deprecated ( " This old function sends MSB first! Please use sendJVC(aAddress, aCommand, aNumberOfRepeats). " ) ) ) {
2021-04-10 22:49:28 +08:00
sendJVCMSB ( data , nbits , repeat ) ;
}
2021-01-30 07:50:58 +08:00
void sendJVCMSB ( unsigned long data , int nbits , bool repeat = false ) ;
2021-04-10 22:49:28 +08:00
2021-01-28 07:58:26 +08:00
void sendLG ( unsigned long data , int nbits ) ;
2021-04-10 22:49:28 +08:00
2021-04-27 03:50:31 +08:00
void sendNEC ( uint32_t aRawData ,
uint8_t nbits )
__attribute__ ( ( deprecated ( " This old function sends MSB first! Please use sendNEC(aAddress, aCommand, aNumberOfRepeats). " ) ) ) {
2021-04-10 22:49:28 +08:00
sendNECMSB ( aRawData , nbits ) ;
}
2021-01-30 07:50:58 +08:00
void sendNECMSB ( uint32_t data , uint8_t nbits , bool repeat = false ) ;
2021-01-28 07:58:26 +08:00
void sendPanasonic ( uint16_t aAddress ,
uint32_t aData )
__attribute__ ( ( deprecated ( " This old function sends MSB first! Please use sendPanasonic(aAddress, aCommand, aNumberOfRepeats). " ) ) ) ;
void sendRC5 ( uint32_t data , uint8_t nbits ) ;
2021-03-04 07:54:25 +08:00
void sendRC5ext ( uint8_t addr , uint8_t cmd , bool toggle ) ;
2021-01-28 07:58:26 +08:00
void sendRC6 ( uint32_t data , uint8_t nbits ) ;
void sendRC6 ( uint64_t data , uint8_t nbits ) ;
void sendSharpRaw ( unsigned long data , int nbits ) ;
void sendSharp ( unsigned int address , unsigned int command ) ;
void sendSAMSUNG ( unsigned long data , int nbits ) ;
__attribute__ ( ( deprecated ( " This old function sends MSB first! Please use sendSamsung(). " ) ) ) ;
void sendSony ( unsigned long data ,
int nbits )
__attribute__ ( ( deprecated ( " This old function sends MSB first! Please use sendSony(aAddress, aCommand, aNumberOfRepeats). " ) ) ) ;
;
void sendWhynter ( unsigned long data , int nbits ) ;
2021-11-03 13:57:27 +08:00
# if !defined(IR_SEND_PIN) && !defined(SEND_PWM_BY_TIMER)
2021-01-28 07:58:26 +08:00
uint8_t sendPin ;
2021-11-03 13:57:27 +08:00
# endif
2021-01-28 07:58:26 +08:00
unsigned int periodTimeMicros ;
2021-03-22 21:32:09 +08:00
unsigned int periodOnTimeMicros ; // compensated with PULSE_CORRECTION_NANOS for duration of digitalWrite.
2021-04-27 03:57:55 +08:00
unsigned int getPulseCorrectionNanos ( ) ;
2021-01-28 07:58:26 +08:00
2021-03-01 18:41:14 +08:00
void customDelayMicroseconds ( unsigned long aMicroseconds ) ;
2021-01-28 07:58:26 +08:00
} ;
2021-03-09 04:38:06 +08:00
/*
2021-03-09 20:45:01 +08:00
* The sender instance
2021-03-09 04:38:06 +08:00
*/
2021-03-09 20:45:01 +08:00
extern IRsend IrSender ;
2021-01-28 07:58:26 +08:00
# endif // IRremoteInt_h
# pragma once