diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 662af9989..56e71e9f3 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -11,41 +11,22 @@ body: **Issues are expected to lead to changes in the repository, like code or documentation improvements or bug fixes.** If you have handling problems or questions, consider to post in [Discussions](../discussions) instead. - # Environment - - - type: dropdown - id: Board - attributes: - label: The type of board you are using. - options: - - Arduino ATmega328* board (UNO, Nano, etc.) - - Arduino ATmega2560 board (Mega) - - Arduino ATmega32U4 board (Leonardo, etc.) - - Arduino ATmega4809 megaAVR board (NanoEvery) - - Arduino SAM board (Due) - - Arduino SAMD board (Zero, MKR*) - - ATtiny85 board (ATTinyCore by Spence Conde) - - Digispark board - - ATtiny3217 board (TinyCore) - - ESP32 board - first check https://github.com/crankyoldgit/IRremoteESP8266 - - STM32F1 board (BluePill) - - Teensy board - - Other - please specify below - validations: - required: true - - type: input - id: Other_board_NAME_FQBN - attributes: - label: The boards name or FQBN (e.g. esp8266:esp8266:d1_mini:eesz=4M3M,xtal=80) for unspecified board. + id: Board_FQBN + attributes: + label: Please specify "FQBN" (Fully Qualified Board Name). + It is the first line in the compiler output in the Arduino IDE 2.x. + E.g. "esp32:esp32:featheresp32:FlashFreq=80". + The FQBN starts with the core name, which is essential for bugfixing. + For example, at least two prominent cores are available for the Bluepill board, namely STMicroelectronics and STM32duino. + Without the FQBN we are most likely not able to fix the the issue. validations: - required: false + required: true - type: input - id: Other_board_URL + id: Exotic_core_URL attributes: - label: The board manager URL used for unspecified board. - value: "https://" + label: The board manager URL used for exotic cores. validations: required: false @@ -54,11 +35,11 @@ body: attributes: label: What IDE are you using? options: - - Arduino IDE + - Arduino 2.x IDE + - PlatformIO IDE + - Arduino 1.x IDE - Arduino Web Editor - - Arduino Pro IDE - Sloeber IDE - - PlatformIO IDE - Other - please specify below multiple: false validations: @@ -83,6 +64,7 @@ body: - Samsung - Sharp - Sony + - Universal Pulse Distance - Whynter - Other - please specify below multiple: true @@ -107,33 +89,33 @@ body: - label: ReceiveDemo - label: SendRawDemo - label: ReceiverTimingAnalysis + - label: ReceiveDump - label: TinyReceiver - label: TinySender - label: ReceiveAndSend - label: SimpleSender - label: SendDemo - - label: SendLGAirConditionerDemo - label: UnitTest - label: Other - please specify below - - label: I checked, if at least one of the examples was working. + - label: I checked, whether at least one of the examples was working. required: true - type: checkboxes id: Failed_examples attributes: label: Example(s) to reproduce the issue. - description: Select only the examples which shows your error. + description: Select only the examples which shows your error! options: - label: SimpleReceiver - label: ReceiveDemo - label: SendRawDemo - label: ReceiverTimingAnalysis + - label: ReceiveDump - label: TinyReceiver - label: TinySender - label: ReceiveAndSend - label: SimpleSender - label: SendDemo - - label: SendLGAirConditionerDemo - label: UnitTest - label: Other - please specify below @@ -162,7 +144,7 @@ body: 1. 2. 3. - 4. See error + 4. validations: required: true @@ -177,9 +159,9 @@ body: - type: textarea id: bug-logs attributes: - label: The serial output which indicates the error happened. + label: The output which indicates the error happened. description: | - Please copy and paste any relevant serial output. This will be automatically formatted into code, so no need for backticks. + Please copy and paste any relevant output. This will be automatically formatted into code, so no need for backticks. render: shell validations: required: false @@ -212,9 +194,7 @@ body: options: - label: I have **read** the README.md file thoroughly required: true - - label: I have searched existing issues to see if there is anything I have missed. - required: true - - label: I have browsed the examples for one, that matches my use case. + - label: I have browsed the examples for one that matches my use case. required: true - label: The title of the issue is helpful and relevant. required: true @@ -222,6 +202,6 @@ body: - type: markdown attributes: value: | - ** We will start to close or delete issues that do not follow these guidelines - as it doesn't help the contributors who spend time trying to solve issues if the community ignores guidelines!** + We will start to close or delete issues that do not follow these guidelines + as it doesn't help the contributors who spend time trying to solve issues if the community ignores guidelines! diff --git a/.github/workflows/LibraryBuild.yml b/.github/workflows/LibraryBuild.yml index 444d3bde9..854aa2089 100644 --- a/.github/workflows/LibraryBuild.yml +++ b/.github/workflows/LibraryBuild.yml @@ -1,7 +1,7 @@ # https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/.github/workflows/LibraryBuild.yml # Github workflow script to test compile all examples of an Arduino library repository. # -# Copyright (C) 2020 Armin Joachimsmeyer +# Copyright (C) 2020-2026 Armin Joachimsmeyer # https://github.com/ArminJo/Github-Actions # # Before being able to push to my .github\workflows directories, @@ -47,15 +47,18 @@ jobs: ############################################################################################################# arduino-boards-fqbn: - arduino:avr:uno - - arduino:avr:uno|DEBUG + - arduino:avr:uno|DEBUG_TRACE - arduino:avr:uno|USE_NO_SEND_PWM - arduino:avr:uno|SEND_PWM_BY_TIMER - arduino:avr:uno|USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN + - arduino:avr:uno|USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN - arduino:avr:mega:cpu=atmega2560 - arduino:avr:leonardo - arduino:megaavr:nona4809:mode=off - arduino:samd:arduino_zero_native + - arduino:renesas_uno:unor4wifi - adafruit:samd:adafruit_metro_m4:cache=on,speed=120,opt=small,maxqspi=50,usbstack=arduino,debug=off + - adafruit:samd:adafruit_itsybitsy_m4 - arduino:mbed:nano33ble - arduino:mbed_rp2040:pico - rp2040:rp2040:arduino_nano_connect @@ -64,15 +67,20 @@ jobs: - ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz - MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os_flto,clock=8MHz_internal # ATmega128 - SparkFun:avr:promicro -# - megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal # https://github.com/SpenceKonde/megaTinyCore/issues/935 -# - megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal # https://github.com/SpenceKonde/megaTinyCore/issues/935 +# - megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal +# - megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal - esp8266:esp8266:d1_mini:eesz=4M3M,xtal=80 - esp32:esp32:featheresp32:FlashFreq=80 + - esp32:esp32:esp32c3 + - esp32:esp32:esp32s3 + - esp32:esp32:lolin_s2_mini + - esp32:esp32:nano_nora - STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 - STMicroelectronics:stm32:GenL0:pnum=THUNDERPACK_L072 - stm32duino:STM32F1:genericSTM32F103C - sandeepmistry:nRF5:BBCmicrobit - Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off,sercom4=include +# - vega:riscv:aries_v3 # Specify parameters for each board. # With sketches-exclude you may exclude specific examples for a board. Use a comma separated list. @@ -80,24 +88,31 @@ jobs: include: - arduino-boards-fqbn: arduino:avr:uno build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DIR_SEND_PIN=3 + ReceiveDemo: -DUSE_STRICT_DECODER -DDEBUG -DIR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK + SimpleSender: -DUSE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=1200 -DIR_SEND_PIN=3 - - arduino-boards-fqbn: arduino:avr:uno|DEBUG + - arduino-boards-fqbn: arduino:avr:uno|DEBUG_TRACE build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DIR_SEND_PIN=3 - All: -DEBUG + ReceiveDemo: -DUSE_THRESHOLD_DECODER -DEBUG -DTRACE + IRremoteExtensionTest: -DIR_SEND_PIN=3 -DEBUG -DTRACE + TinyReceiver: -DUSE_CALLBACK_FOR_TINY_RECEIVER -DEBUG -DTRACE + UnitTest: -DEBUG # otherwise Sketch uses 32486 bytes (100%) of program storage space. Maximum is 32256 bytes. + All: -DEBUG -DTRACE - arduino-boards-fqbn: arduino:avr:uno|USE_NO_SEND_PWM build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DIR_SEND_PIN=3 + SimpleSender: -DUSE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM + IRremoteExtensionTest: -DIR_SEND_PIN=3 TinyReceiver: -DUSE_FAST_PROTOCOL TinySender: -DUSE_FAST_PROTOCOL All: -DUSE_NO_SEND_PWM - arduino-boards-fqbn: arduino:avr:uno|SEND_PWM_BY_TIMER - sketches-exclude: UnitTest + sketches-exclude: UnitTest,MultipleSendPins build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DIR_SEND_PIN=3 -DSEND_PWM_BY_TIMER + SimpleSender: -DUSE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + IRremoteExtensionTest: -DIR_SEND_PIN=3 ReceiveDemo: -DDECODE_ONKYO TinyReceiver: -DUSE_ONKYO_PROTOCOL TinySender: -DUSE_ONKYO_PROTOCOL @@ -105,162 +120,224 @@ jobs: - arduino-boards-fqbn: arduino:avr:uno|USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DIR_SEND_PIN=3 -DUSE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN + IRremoteExtensionTest: -DIR_SEND_PIN=3 -DUSE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN SimpleSender: -DSEND_PWM_BY_TIMER TinyReceiver: -DENABLE_NEC2_REPEATS TinySender: -DENABLE_NEC2_REPEATS All: -DUSE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN + - arduino-boards-fqbn: arduino:avr:uno|USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + build-properties: # the flags were put in compiler.cpp.extra_flags + IRremoteExtensionTest: -DIR_SEND_PIN=3 -DUSE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + SimpleSender: -DSEND_PWM_BY_TIMER + TinyReceiver: -DENABLE_NEC2_REPEATS + TinySender: -DENABLE_NEC2_REPEATS + All: -DUSE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + - arduino-boards-fqbn: arduino:avr:mega:cpu=atmega2560 build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 + IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=1500 SimpleSender: -DSEND_PWM_BY_TIMER TinyReceiver: -DDISABLE_PARITY_CHECKS TinySender: -DDISABLE_PARITY_CHECKS - arduino-boards-fqbn: arduino:avr:leonardo build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 + SimpleSender: -DSEND_PWM_BY_TIMER TinyReceiver: -DNO_LED_FEEDBACK_CODE TinySender: -DNO_LED_FEEDBACK_CODE -# sketches-exclude: ReceiveAndSend # Not enough RAM for default RAW_BUFFER_LENGTH + sketches-exclude: UnitTest # Sketch uses 28764 bytes (100%) of program storage space. Maximum is 28672 bytes - arduino-boards-fqbn: arduino:megaavr:nona4809:mode=off sketches-exclude: TinyReceiver,IRDispatcherDemo build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 SimpleSender: -DSEND_PWM_BY_TIMER - TinyReceiver: -DUSE_ONKYO_PROTOCOL -DENABLE_NEC2_REPEATS -DNO_LED_FEEDBACK_CODE + TinyReceiver: -DUSE_ONKYO_PROTOCOL -DENABLE_NEC2_REPEATS -DNO_LED_FEEDBACK_CODE -DUSE_CALLBACK_FOR_TINY_RECEIVER TinySender: -DUSE_ONKYO_PROTOCOL -DENABLE_NEC2_REPEATS -DNO_LED_FEEDBACK_CODE - arduino-boards-fqbn: arduino:samd:arduino_zero_native +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware is not yet implemented for SAMD + sketches-exclude: TinyReceiver,IRDispatcherDemo + + - arduino-boards-fqbn: arduino:renesas_uno:unor4wifi +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware not yet implemented for Arduino Uno R4 sketches-exclude: TinyReceiver,IRDispatcherDemo - build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 - arduino-boards-fqbn: adafruit:samd:adafruit_metro_m4:cache=on,speed=120,opt=small,maxqspi=50,usbstack=arduino,debug=off platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware is not yet implemented for SAMD + sketches-exclude: TinyReceiver,IRDispatcherDemo + + - arduino-boards-fqbn: adafruit:samd:adafruit_itsybitsy_m4 + platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware is not yet implemented for SAMD sketches-exclude: TinyReceiver,IRDispatcherDemo - build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 - arduino-boards-fqbn: arduino:mbed:nano33ble - build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 - SimpleSender: -DSEND_PWM_BY_TIMER +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #warning INFO: For ESP32, RP2040, mbed and particle boards SEND_PWM_BY_TIMER is enabled by default +# +# RP2040 +# - arduino-boards-fqbn: arduino:mbed_rp2040:pico build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 SimpleSender: -DSEND_PWM_BY_TIMER - arduino-boards-fqbn: rp2040:rp2040:arduino_nano_connect platform-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 -DSEND_PWM_BY_TIMER + IRremoteExtensionTest: -DSEND_PWM_BY_TIMER SimpleSender: -DSEND_PWM_BY_TIMER - All: -DRAW_BUFFER_LENGTH=700 + SendDemo: -DSEND_PWM_BY_TIMER -DUSE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN + All: -DRAW_BUFFER_LENGTH=750 -# https://github.com/SpenceKonde/megaTinyCore/issues/935 +# +# megaTinyCore +# # - arduino-boards-fqbn: megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal # arduino-platform: megaTinyCore:megaavr -# platform-url: http://drazzy.com/package_drazzy.com_index.json -# sketches-exclude: AllProtocolsOnLCD -# build-properties: # the flags were put in compiler.cpp.extra_flags -# IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 +# platform-url: https://felias-fogg.github.io/downloads/package_debug_enabled_index.json +# sketches-exclude: AllProtocolsOnLCD,UnitTest # UnitTest region `text' overflowed by 997 bytes -# https://github.com/SpenceKonde/megaTinyCore/issues/935 # - arduino-boards-fqbn: megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal # arduino-platform: megaTinyCore:megaavr -# platform-url: http://drazzy.com/package_drazzy.com_index.json +# platform-url: https://felias-fogg.github.io/downloads/package_debug_enabled_index.json # sketches-exclude: AllProtocolsOnLCD -# build-properties: # the flags were put in compiler.cpp.extra_flags -# IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100 +# +# ATTinyCore +# - arduino-boards-fqbn: ATTinyCore:avr:attinyx5micr:LTO=enable,sketchclock=16pll - platform-url: http://drazzy.com/package_drazzy.com_index.json + platform-url: https://felias-fogg.github.io/downloads/package_debug_enabled_index.json required-libraries: ATtinySerialOut - sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino + sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino build-properties: # the flags were put in compiler.cpp.extra_flags SimpleSender: -DSEND_PWM_BY_TIMER + SimpleReceiver: -DDECODE_NEC - arduino-boards-fqbn: ATTinyCore:avr:attinyx7micr:LTO=enable,sketchclock=16external,pinmapping=new,millis=enabled - platform-url: http://drazzy.com/package_drazzy.com_index.json + platform-url: https://felias-fogg.github.io/downloads/package_debug_enabled_index.json required-libraries: ATtinySerialOut - sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino + sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino build-properties: # the flags were put in compiler.cpp.extra_flags SimpleSender: -DSEND_PWM_BY_TIMER - arduino-boards-fqbn: ATTinyCore:avr:attinyx8micr:LTO=enable,sketchclock=16external,pinmapping=mhtiny,millis=enabled # ATtiny88 China clone board @16 MHz - platform-url: http://drazzy.com/package_drazzy.com_index.json + platform-url: https://felias-fogg.github.io/downloads/package_debug_enabled_index.json required-libraries: ATtinySerialOut - sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino + sketch-names: TinyReceiver.ino,IRremoteInfo.ino,SimpleReceiver.ino,ReceiveDemo.ino,ControlRelay.ino,SimpleSender.ino,SendDemo.ino,SendRawDemo.ino,SendAndReceive.ino,SimpleReceiverForHashCodes.ino build-properties: # the flags were put in compiler.cpp.extra_flags SimpleSender: -DSEND_PWM_BY_TIMER + SimpleReceiver: -DDECODE_NEC +# +# MegaCore +# - arduino-boards-fqbn: MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os_flto,clock=8MHz_internal platform-url: https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json arduino-platform: arduino:avr,MegaCore:avr # gcc is taken from arduino:avr build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=300 SimpleSender: -DSEND_PWM_BY_TIMER - All: -DRAW_BUFFER_LENGTH=700 + All: -DRAW_BUFFER_LENGTH=750 +# +# ESP +# - arduino-boards-fqbn: esp8266:esp8266:d1_mini:eesz=4M3M,xtal=80 platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json sketches-exclude: TinyReceiver build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=200 - All: -DRAW_BUFFER_LENGTH=300 + All: -DRAW_BUFFER_LENGTH=750 - arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80 platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))' build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=500 -Wno-error=maybe-uninitialized - All: -DRAW_BUFFER_LENGTH=300 -Wno-error=maybe-uninitialized # https://github.com/espressif/arduino-esp32/issues/7024 + All: -DRAW_BUFFER_LENGTH=1500 -DDEBUG -DTRACE + + - arduino-boards-fqbn: esp32:esp32:esp32c3 + platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))' + build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! + All: -DRAW_BUFFER_LENGTH=1500 + - arduino-boards-fqbn: esp32:esp32:esp32s3 + platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))' + build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! + All: -DRAW_BUFFER_LENGTH=1500 -DDEBUG + + - arduino-boards-fqbn: esp32:esp32:lolin_s2_mini + platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))' + build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! + All: -DRAW_BUFFER_LENGTH=1500 + + - arduino-boards-fqbn: esp32:esp32:nano_nora + platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + sketches-exclude: TinyReceiver # undefined reference to `TwoWire::onReceive(void (*)(int))' + build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! + All: -DRAW_BUFFER_LENGTH=1500 + +# +# STM +# - arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 # ST version platform-url: https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json sketches-exclude: TinyReceiver build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware not implemented for STM32 + All: -DRAW_BUFFER_LENGTH=750 - arduino-boards-fqbn: STMicroelectronics:stm32:GenL0:pnum=THUNDERPACK_L072 # ST version platform-url: https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json sketches-exclude: TinyReceiver,IRDispatcherDemo - build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware not implemented for STM32 - arduino-boards-fqbn: stm32duino:STM32F1:genericSTM32F103C # Roger Clark version platform-url: http://dan.drown.org/stm32duino/package_STM32duino_index.json sketches-exclude: TinyReceiver build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 +# SimpleSender: -DSEND_PWM_BY_TIMER # PWM generation by hardware not implemented for STM32 + All: -DRAW_BUFFER_LENGTH=750 +# +# Others +# - arduino-boards-fqbn: SparkFun:avr:promicro arduino-platform: arduino:avr,SparkFun:avr platform-url: https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json # Arduino URL is not required here build-properties: # the flags were put in compiler.cpp.extra_flags. SEND_PWM_BY_TIMER is always enabled! - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 + SimpleSender: -DSEND_PWM_BY_TIMER + All: -DRAW_BUFFER_LENGTH=750 + sketches-exclude: UnitTest # Sketch uses 28762 bytes (100%) of program storage space. Maximum is 28672 bytes. - arduino-boards-fqbn: sandeepmistry:nRF5:BBCmicrobit platform-url: https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json sketches-exclude: IRDispatcherDemo,MicroGirs,TinyReceiver build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware not implemented for NRF5 + All: -DRAW_BUFFER_LENGTH=750 - arduino-boards-fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off,sercom4=include platform-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json - sketches-exclude: AllProtocolsOnLCD,UnitTest,ReceiveAndSendDistanceWidth # No print(uint64_t,.) available + sketches-exclude: AllProtocolsOnLCD,UnitTest,ReceiveAndSendDistanceWidth,ReceiveDemo,SimpleReceiverForHashCodes # No print(uint64_t,.) available build-properties: # the flags were put in compiler.cpp.extra_flags - IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700 - All: -DRAW_BUFFER_LENGTH=300 +# SimpleSender: -DSEND_PWM_BY_TIMER #error PWM generation by hardware is not yet implemented for SAMD + All: -DRAW_BUFFER_LENGTH=750 + +# - arduino-boards-fqbn: vega:riscv:aries_v3 +# platform-url: https://gitlab.com/riscv-vega/vega-arduino/-/raw/main/package_vega_index.json +# sketches-exclude: MicroGirs,SendLGAirConditionerDemo # No Stream:: available and readBytesUntil +# build-properties: # the flags were put in compiler.cpp.extra_flags +# SimpleSender: -DSEND_PWM_BY_TIMER +# All: -DF_CPU=100000000LL -DVEGA_ARIES_V3 -DRAW_BUFFER_LENGTH=750 -DCHANGE=1 # fail-fast: false # false -> do not cancel all jobs / architectures if one job fails @@ -272,9 +349,12 @@ jobs: uses: ArminJo/arduino-test-compile@master with: arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }} - arduino-platform: ${{ matrix.arduino-platform }} + arduino-platform: ${{ matrix.arduino-platform }} # for MegaCore platform-url: ${{ matrix.platform-url }} required-libraries: ${{ matrix.required-libraries }} - sketch-names: ${{ matrix.sketch-names }} + sketch-names: ${{ matrix.sketch-names }} # Comma separated list of sketch names (without path, but with extension) or patterns to use in build sketches-exclude: ${{ matrix.sketches-exclude }} build-properties: ${{ toJson(matrix.build-properties) }} +# cli-version: 0.33.0 # to avoid errors for ATTinyCore +# debug-install: true +# debug-compile: true \ No newline at end of file diff --git a/.github/workflows/PlatformIoPublish.yml b/.github/workflows/PlatformIoPublish.yml index cc9b32a1a..d8727408c 100644 --- a/.github/workflows/PlatformIoPublish.yml +++ b/.github/workflows/PlatformIoPublish.yml @@ -36,8 +36,7 @@ jobs: env: PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }} run: | - pio package publish --owner arminjo --non-interactive + pio package publish --owner Arduino-IRremote --non-interactive # run: | # pio package pack -# pio package publish --owner arminjo --non-interactive - \ No newline at end of file +# pio package publish --owner Arduino-IRremote --non-interactive diff --git a/Contributing.md b/Contributing.md index 4424f809c..7483472d1 100644 --- a/Contributing.md +++ b/Contributing.md @@ -18,7 +18,7 @@ Refrain from using overly long or capitalized titles as they are usually annoyin We use the original [C Style by Kerninghan / Ritchie](https://en.wikipedia.org/wiki/Indentation_style#K&R_style) in [variant: 1TBS (OTBS)](https://en.wikipedia.org/wiki/Indentation_style#Variant:_1TBS_(OTBS)).
In short: 4 spaces indentation, no tabs, opening braces on the same line, braces are mandatory on all if/while/do, no hard line length limit.
To beautify your code, you may use the online formatter [here](https://www.freecodeformat.com/c-format.php). -#### Cover **all** occurences of the problem / addition you address with your PR +#### Cover **all** occurrences of the problem / addition you address with your PR Do not forget the documentation like it is done for existing code. Code changes without proper documentation will be rejected! ## Adding new protocols diff --git a/Contributors.md b/Contributors.md index 00dd4c826..033dba251 100644 --- a/Contributors.md +++ b/Contributors.md @@ -30,5 +30,13 @@ These are the active contributors of this project that you may contact if there - [Daniel Wallner](https://github.com/danielwallner) Bang & Olufsen protocol. - [slott](https://stackoverflow.com/users/11680056/sklott) Seeduino print(unsigned long long...) support. - [Joe Ostrander](https://github.com/joeostrander) Added support for attiny1614. +- [Buzzerb](https://github.com/Buzzerb) Added Extended NEC protocol to TinyIR and making it more consistent. +- [akellai](https://github.com/akellai) Added ESP 3.0 support. +- [Hayden McAfee](https://github.com/haydenmc) Help with UnoR4 support. +- [Yonghwan SO](https://github.com/sio4) Fixed bug in ReceiveDemo.cpp if DEBUG_BUTTON_PIN is not defined. #1306. +- [A.R.Jung](https://github.com/arjung467) Marantz-RC5 extension support #1314. +- [silen72](https://github.com/silen72) Fixing ESP32 multiple attach bug #1324. +- [danielweidman](https://github.com/danielweidman) Adding OpenLASIR protocol. +- [Craig Leres](https://github.com/leres) Found bug #1347 in RC5/RC6 autorepeat bit handling. Note: Please let [ArminJo](https://github.com/ArminJo) know if you have been missed. diff --git a/Doxyfile b/Doxyfile index 0ce0d4bf5..9e4c94a05 100644 --- a/Doxyfile +++ b/Doxyfile @@ -58,7 +58,7 @@ PROJECT_LOGO = # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = ..\Arduino-IRremote_gh-pages +OUTPUT_DIRECTORY = E:\WORKSPACE_ARDUINO\lib\Arduino-IRremote_gh-pages # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and @@ -2339,7 +2339,7 @@ INCLUDED_BY_GRAPH = YES # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -CALL_GRAPH = NO +CALL_GRAPH = YES # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. @@ -2351,7 +2351,7 @@ CALL_GRAPH = NO # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. -CALLER_GRAPH = NO +CALLER_GRAPH = YES # If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical # hierarchy of all classes instead of a textual one. diff --git a/Migrating.md b/Migrating.md new file mode 100644 index 000000000..8b3177658 --- /dev/null +++ b/Migrating.md @@ -0,0 +1,192 @@ +# Migrating legacy projects to the latest version + +## Table of contents + * [New features and changes in version 4.6](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#new-features-and-changes-in-version-46) + * [New features of version 4.x](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#new-features-of-version-4x) + * [New features of version 3.x](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#new-features-of-version-3x) + * [Converting your 2.x program to the 4.x version](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#converting-your-2x-program-to-the-4x-version) + * [How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes) + * [Errors when using the 3.x versions for old tutorials](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#errors-when-using-the-3x-versions-for-old-tutorials) + * [Staying on 2.x](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#staying-on-2x) + +This library has been refactored, breaking backward compatibility with the old version, on which many examples on the Internet are based.
+If your code uses `irrecv.decode(&results)`, it is written for Version 2.x. This library (Version 4.x) now uses a simpler `IrReceiver.decode()` syntax. See the Conversion guide below. + +## New features and changes in version 4.6 +** Version 4.5.0 does not work for ESP platform, because of missing ESP IRAM_ATTR for receiving interrupt.** +- Support for **multiple receiver instances**.
+`irparams_struct irparams` is now member of `IRrecv`. Thus `rawDataPtr` (pointer to irparams) was removed from `IrReceiver.decodedIRData`.
+Old `IrReceiver.decodedIRData.rawDataPtr->rawbuf` is now `IrReceiver.irparams.rawbuf`, the same holds for `IrReceiver.irparams.rawlen`. +- LED feedback is always enabled for sending. It can only be disabled by using `#define NO_LED_SEND_FEEDBACK_CODE` or `#define NO_LED_FEEDBACK_CODE`. +- The second parameter of the function `IrSender.begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback)` has changed to `uint_fast8_t aFeedbackLEDPin`. Therefore this function call no longer works as expected because it uses the old boolean value of e.g. `ENABLE_LED_FEEDBACK` which evaluates to true or 1 as pin number of the LED feedback pin number. +- New experimental Velux send function. +- Send function for Marantz version of the RC5x protocol. This protocol has an additional 6 bit command extension and adds a short pause after the address is sent to identify this variant of the protocol. + +## New features of version 4.x +- **Since 4.3 `IrSender.begin(DISABLE_LED_FEEDBACK)` will no longer work**, use `#define NO_LED_SEND_FEEDBACK_CODE` instead. +- New universal **Pulse Distance / Pulse Width / Pulse Distance Width decoder** added, which covers many previous unknown protocols. +- Printout of code how to send received command by `IrReceiver.printIRSendUsage(&Serial)`. +- RawData type is now 64 bit for 32 bit platforms and therefore `decodedIRData.decodedRawData` can contain complete frame information for more protocols than with 32 bit as before. +- **Callback** after receiving a command - It calls your code as soon as a frame was received. +- Improved handling of `PULSE_DISTANCE` + `PULSE_WIDTH` protocols. +- New FAST protocol. +- Automatic printout of the **corresponding send function** with `printIRSendUsage()`. + +### Converting your 3.x program to the 4.x version +- You must replace `#define DECODE_DISTANCE` by `#define DECODE_DISTANCE_WIDTH` (only if you explicitly enabled this decoder). +- The parameter `bool hasStopBit` is no longer required and removed e.g. for function `sendPulseDistanceWidth()`. + +## New features of version 3.x +- **Any pin** can be used for receiving and if `SEND_PWM_BY_TIMER` is not defined also for sending. +- Feedback LED can be activated for sending / receiving. +- An 8/16 bit ****command** value as well as a 16-bit **address** and a protocol number is provided for decoding (instead of the old 32 bit value). +- Protocol values comply to **protocol standards**.
+ NEC, Panasonic, Sony, Samsung and JVC decode & send LSB first. +- Supports **Universal Distance protocol**, which covers a lot of previous unknown protocols. +- Compatible with **tone()** library. See the [ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298) example. +- Simultaneous sending and receiving. See the [SendAndReceive](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendAndReceive/SendAndReceive.ino#L167-L170) example. +- Supports **more platforms**. +- Allows for the generation of non-PWM signal to just **simulate an active low receiver signal** for direct connect to existing receiving devices without using IR. +- Easy protocol configuration, **directly in your [source code](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino#L33-L57)**.
+ Reduces memory footprint and decreases decoding time. +- Contains a [very small NEC only decoder](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#minimal-nec-receiver), which **does not require any timer resource**. + +[-> Feature comparison of 5 Arduino IR libraries](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#quick-comparison-of-5-arduino-ir-receiving-libraries). + +
+ +## Converting your 2.x program to the 4.x version +Starting with the 3.1 version, **the generation of PWM for sending is done by software**, thus saving the hardware timer and **enabling arbitrary output pins for sending**.
+If you use an (old) Arduino core that does not use the `-flto` flag for compile, you can activate the line `#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN` in IRRemote.h, +if you get false error messages regarding begin() during compilation. + +- **IRreceiver** and **IRsender** object have been added and can be used without defining them, like the well known Arduino **Serial** object. +- Just remove the line `IRrecv IrReceiver(IR_RECEIVE_PIN);` and/or `IRsend IrSender;` in your program and replace all occurrences of `IRrecv.` or `irrecv.` with `IrReceiver` and replace all `IRsend` or `irsend` with `IrSender`. +- Like for the Serial object, call [`IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK)`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L106) + or `IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK)` instead of the `IrReceiver.enableIRIn()` or `irrecv.enableIRIn()` in setup().
+If IR_SEND_PIN is not defined (before the line `#include `) you must use e.g. `IrSender.begin(3);` +- Old `decode(decode_results *aResults)` function is replaced by simple `decode()`. So if you have a statement `if(irrecv.decode(&results))` replace it with `if (IrReceiver.decode())`. +- The decoded result is now in in `IrReceiver.decodedIRData` and not in `results` any more, therefore replace any occurrences of `results.value` and `results.decode_type` (and similar) to + `IrReceiver.decodedIRData.decodedRawData` and `IrReceiver.decodedIRData.protocol`. +- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRProtocol.h#L90-L101). +- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.irparams.rawbuf` and `IrReceiver.decodedIRData.rawlen`. + +- The 5 protocols **NEC, Panasonic, Sony, Samsung and JVC** have been converted to LSB first. Send functions for sending old MSB data were renamed to `sendNECMSB`, `sendSamsungMSB()`, `sendSonyMSB()` and `sendJVCMSB()`. +The old `sendSAMSUNG()` and `sendSony()` MSB functions are still available. +The old MSB version of `sendPanasonic()` function was deleted, since it had bugs nobody recognized and therefore was assumed to be never used.
+For converting MSB codes to LSB see [below](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes) or use the new functions `bitreverseOneByte()` or `bitreverse32Bit()` for reversing. + +### Example +#### Old 2.x program: + +```c++ +#include +#define RECV_PIN 2 + +IRrecv irrecv(RECV_PIN); +decode_results results; + +void setup() +{ +... + Serial.begin(115200); // Establish serial communication + irrecv.enableIRIn(); // Start the receiver +} + +void loop() { + if (irrecv.decode(&results)) { + Serial.println(results.value, HEX); + ... + irrecv.resume(); // Receive the next value + } + ... +} +``` + +#### New 4.x program: + +```c++ +#include +#define IR_RECEIVE_PIN 2 + +void setup() +{ +... + Serial.begin(115200); // // Establish serial communication + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver +} + +void loop() { + if (IrReceiver.decode()) { + Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data + IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line + IrReceiver.printIRSendUsage(&Serial); // Print the statement required to send this data + ... + IrReceiver.resume(); // Enable receiving of the next value + } + ... +} +``` + +#### Sample output +For more, see the [UnitTest log](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/UnitTest/UnitTest.log). + +``` +Protocol=NEC Address=0xF1 Command=0x76 Raw-Data=0x89760EF1 32 bits LSB first +Send with: IrSender.sendNEC(0xF1, 0x76, ); + +Protocol=Kaseikyo_Denon Address=0xFF1 Command=0x76 Raw-Data=0x9976FF10 48 bits LSB first +Send with: IrSender.sendKaseikyo_Denon(0xFF1, 0x76, ); +``` + +## How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes +For the new decoders for **NEC, Panasonic, Sony, Samsung and JVC**, the result `IrReceiver.decodedIRData.decodedRawData` is now **LSB-first**, as the definition of these protocols suggests!
+
+To convert one into the other, you must reverse the nibble (4 bit / Hex numbers) positions and then reverse all bit positions of each nibble or write it as one binary string and reverse/mirror it.
+This can be done by using the new functions `bitreverseOneByte()` or `bitreverse32Bit()`. + +### Nibble reverse +`0xCB 34 01 02` MSB value
+`0x20 10 43 BC` after nibble reverse
+`0x40 80 2C D3` LSB value after bit reverse of each nibble + +### Nibble reverse map +``` + 0->0 1->8 2->4 3->C + 4->2 5->A 6->6 7->E + 8->1 9->9 A->5 B->D + C->3 D->B E->7 F->F +``` + +### Binary string reverse +If you **read the first binary sequence backwards** (right to left), you get the second sequence.
+`0xCB340102` is binary `1100 1011 0011 0100 0000 0001 0000 0010`.
+`0x40802CD3` is binary `0100 0000 1000 0000 0010 1100 1101 0011`. + +### Online tool which reverses every byte, but not the order of the bytes +Use this [tool provided by analysir](https://www.analysir.com/hex2nec.php). + +### Send MSB directly +Sending old MSB codes without conversion can be done by using `sendNECMSB()`, `sendSonyMSB()`, `sendSamsungMSB()`, `sendJVCMSB()`. + +
+ +## Errors when using the 4.x versions for old tutorials +If you suffer from errors with old tutorial code including `IRremote.h` instead of `IRremote.hpp`, +just try to rollback to [Version 2.4.0](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/v2.4.0).
+Most likely your code will run and you will not miss the new features. + +
+ +## Staying on 2.x +Consider using the [original 2.4 release from 2017](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/v2.4.0) +or the last backwards compatible [2.8 version](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/2.8.0) for you project.
+It may be sufficient and deals flawlessly with 32 bit IR codes.
+If this doesn't work for you, you can be sure that 4.x is trying to be compatible with earlier versions, so your old examples should work just fine. + +### Drawbacks of using 2.x +- Only the following decoders are available:
+ ` NEC `     ` Denon `     ` Panasonic `     ` JVC `     ` LG `
+ ` RC5 `     ` RC6 `     ` Samsung `     ` Sony ` +- The call of `irrecv.decode(&results)` uses the old MSB first decoders like in 2.x and sets the 32 bit codes in `results.value`. +- No decoding to a more meaningful (constant) 8/16 bit address and 8 bit command. diff --git a/README.md b/README.md index 5d186af5f..9b3d9c64a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@
# Arduino IRremote -A library enabling the sending & receiving of infra-red signals. +A library enabling the sending & receiving of infrared signals. [![Badge License: MIT](https://img.shields.io/badge/License-MIT-ac8b11.svg?style=for-the-badge&labelColor=yellow)](https://opensource.org/licenses/MIT)     -[![Badge Version](https://img.shields.io/github/v/release/Arduino-IRremote/Arduino-IRremote?include_prereleases&style=for-the-badge&color=33660e&labelColor=428813&logoColor=white&logo=DocuSign)](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/latest) +[![Badge Version](https://img.shields.io/github/v/release/Arduino-IRremote/Arduino-IRremote?style=for-the-badge&color=33660e&labelColor=428813&logoColor=white&logo=DocuSign)](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/latest)     [![Badge Commits since latest](https://img.shields.io/github/commits-since/Arduino-IRremote/Arduino-IRremote/latest?style=for-the-badge&color=004463&labelColor=00557f)](https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master)     @@ -24,68 +24,92 @@ Available as [Arduino library "IRremote"](https://www.arduinolibraries.info/libr     [![Button Contribute](https://img.shields.io/badge/Contribute-752a61?style=for-the-badge&logoColor=white&logo=GitHub)](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/Contributing.md) +#### If you find this program useful, please give it a star. + +🌎 [Google Translate](https://translate.google.com/translate?sl=en&u=https://github.com/Arduino-IRremote/Arduino-IRremote) +
-# Overview -- [Supported IR Protocols](https://github.com/Arduino-IRremote/Arduino-IRremote#supported-ir-protocols) -- [Features](https://github.com/Arduino-IRremote/Arduino-IRremote#features) - * [New features with version 4.x](https://github.com/Arduino-IRremote/Arduino-IRremote#new-features-with-version-4x) - * [New features with version 3.x](https://github.com/Arduino-IRremote/Arduino-IRremote#new-features-with-version-3x) -- [Converting your 2.x program to the 4.x version](https://github.com/Arduino-IRremote/Arduino-IRremote#converting-your-2x-program-to-the-4x-version) - * [How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes](https://github.com/Arduino-IRremote/Arduino-IRremote#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes) -- [Errors with using the 3.x versions for old tutorials](https://github.com/Arduino-IRremote/Arduino-IRremote#errors-with-using-the-3x-versions-for-old-tutorials) - * [Staying on 2.x](https://github.com/Arduino-IRremote/Arduino-IRremote#staying-on-2x) -- [Why *.hpp instead of *.cpp](https://github.com/Arduino-IRremote/Arduino-IRremote#why-hpp-instead-of-cpp) -- [Using the new *.hpp files](https://github.com/Arduino-IRremote/Arduino-IRremote#using-the-new-hpp-files) -- [Receiving IR codes](https://github.com/Arduino-IRremote/Arduino-IRremote#receiving-ir-codes) - * [Data format](https://github.com/Arduino-IRremote/Arduino-IRremote#data-format) - * [Ambiguous protocols](https://github.com/Arduino-IRremote/Arduino-IRremote#ambiguous-protocols) -- [Sending IR codes](https://github.com/Arduino-IRremote/Arduino-IRremote#sending-ir-codes) - * [Send pin](https://github.com/Arduino-IRremote/Arduino-IRremote#send-pin) - + [List of public IR code databases](https://github.com/Arduino-IRremote/Arduino-IRremote#list-of-public-ir-code-databases) -- [Tiny NEC receiver and sender](https://github.com/Arduino-IRremote/Arduino-IRremote#tiny-nec-receiver-and-sender) -- [The FAST protocol](https://github.com/Arduino-IRremote/Arduino-IRremote#the-fast-protocol) -- [FAQ and hints](https://github.com/Arduino-IRremote/Arduino-IRremote#faq-and-hints) - * [Problems with Neopixels, FastLed etc.](https://github.com/Arduino-IRremote/Arduino-IRremote#problems-with-neopixels-fastled-etc) - * [Does not work/compile with another library](https://github.com/Arduino-IRremote/Arduino-IRremote#does-not-workcompile-with-another-library) - * [Multiple IR receiver](https://github.com/Arduino-IRremote/Arduino-IRremote#multiple-ir-receiver) - * [Increase strength of sent output signal](https://github.com/Arduino-IRremote/Arduino-IRremote#increase-strength-of-sent-output-signal) - * [Minimal CPU clock frequency](https://github.com/Arduino-IRremote/Arduino-IRremote#minimal-cpu-clock-frequency) - * [Bang & Olufsen protocol](https://github.com/Arduino-IRremote/Arduino-IRremote#bang--olufsen-protocol) -- [Handling unknown Protocols](https://github.com/Arduino-IRremote/Arduino-IRremote#handling-unknown-protocols) - * [Disclaimer](https://github.com/Arduino-IRremote/Arduino-IRremote#disclaimer) - * [Protocol=PULSE_DISTANCE](https://github.com/Arduino-IRremote/Arduino-IRremote#protocolpulse_distance) - * [Protocol=UNKNOWN](https://github.com/Arduino-IRremote/Arduino-IRremote#protocolunknown) - * [How to deal with protocols not supported by IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote#how-to-deal-with-protocols-not-supported-by-irremote) -- [Examples for this library](https://github.com/Arduino-IRremote/Arduino-IRremote#examples-for-this-library) -- [WOKWI online examples](https://github.com/Arduino-IRremote/Arduino-IRremote#wokwi-online-examples) -- [Issues and discussions](https://github.com/Arduino-IRremote/Arduino-IRremote#issues-and-discussions) -- [Compile options / macros for this library](https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library) - + [Changing include (*.h) files with Arduino IDE](https://github.com/Arduino-IRremote/Arduino-IRremote#changing-include-h-files-with-arduino-ide) - + [Modifying compile options with Sloeber IDE](https://github.com/Arduino-IRremote/Arduino-IRremote#modifying-compile-options--macros-with-sloeber-ide) -- [Supported Boards](https://github.com/Arduino-IRremote/Arduino-IRremote#supported-boards) -- [Timer and pin usage](https://github.com/Arduino-IRremote/Arduino-IRremote#timer-and-pin-usage) - * [Incompatibilities to other libraries and Arduino commands like tone() and analogWrite()](https://github.com/Arduino-IRremote/Arduino-IRremote#incompatibilities-to-other-libraries-and-arduino-commands-like-tone-and-analogwrite) - * [Hardware-PWM signal generation for sending](https://github.com/Arduino-IRremote/Arduino-IRremote#hardware-pwm-signal-generation-for-sending) - * [Why do we use 30% duty cycle for sending](https://github.com/Arduino-IRremote/Arduino-IRremote#why-do-we-use-30-duty-cycle-for-sending) -- [How we decode signals](https://github.com/Arduino-IRremote/Arduino-IRremote#how-we-decode-signals) -- [NEC encoding diagrams](https://github.com/Arduino-IRremote/Arduino-IRremote#nec-encoding-diagrams) -- [Quick comparison of 5 Arduino IR receiving libraries](https://github.com/Arduino-IRremote/Arduino-IRremote#quick-comparison-of-5-arduino-ir-receiving-libraries) -- [Useful links](https://github.com/Arduino-IRremote/Arduino-IRremote#useful-links) +# Table of contents +- [Supported IR Protocols](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#supported-ir-protocols) +- [Common issues when using IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#common-issues-when-using-irremote) +- [Migrating legacy projects to the latest version](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/Migrating.md) + * [New features and changes in version 4.6](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#new-features-and-changes-in-version-46) +- [Why *.hpp instead of *.cpp files](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#why-hpp-instead-of-cpp-files) +- [Using the new *.hpp files](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#using-the-new-hpp-files) +- [Tutorials](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tutorials) +- [3 ways to specify an IR code](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#3-ways-to-specify-an-ir-code) +- [IRReceiver pinouts](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#irreceiver-pinouts) +- [Receiving IR codes](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#receiving-ir-codes) + * [decodedIRData structure](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#decodedirdata-structure) + * [Callback functionality](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#callback-functionality) + * [Ambiguous protocols](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#ambiguous-protocols) + * [RAM usage of different protocols](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#ram-usage-of-different-protocols) + * [Handling unknown Protocols](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#handling-unknown-protocols) + * [Disclaimer](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#disclaimer) + * [Other libraries, which may cover these protocols](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#other-libraries-which-may-cover-these-protocols) + * [Protocol=PULSE_DISTANCE](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#protocolpulse_distance) + * [Protocol=UNKNOWN](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#protocolunknown) + * [How to deal with protocols not supported by IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-to-deal-with-protocols-not-supported-by-irremote) + * [Multiple IR receivers](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#multiple-ir-receivers) +- [Sending IR codes](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#sending-ir-codes) + * [Sending UNKNOWN protocol](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#sending-unknown-protocol) + * [Sending protocol from description](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#sending-protocol-from-description) + * [Sending IRDB IR codes](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#sending-irdb-ir-codes) + + [List of public IR code databases](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#list-of-public-ir-code-databases) + * [Flipper Zero Codes](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#flipper-zero-codes) + * [Send pin](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#send-pin) + * [Polarity of send pin](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#polarity-of-send-pin) + * [Simulate an IR receiver module for sending](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#simulate-an-ir-receiver-module-for-sending) + * [Increase strength of sent output signal](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#increase-strength-of-sent-output-signal) + * [Multiple IR sender instances](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#multiple-ir-sender-instances) +- [Tiny NEC receiver and sender](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tiny-nec-receiver-and-sender) +- [The FAST protocol](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#the-fast-protocol) +- [Feedback LED](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#feedback-led) +- [IRCommandDispatcher class](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#ircommanddispatcher-class) +- [FAQ and hints](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#faq-and-hints) + * [Receiving stops after analogWrite() or tone() or after running a motor](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#receiving-stops-after-analogwrite-or-tone-or-after-running-a-motor) + * [Receiving sets overflow flag](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#receiving-sets-overflow-flag) + * [Problems with Neopixels, FastLed etc.](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#problems-with-neopixels-fastled-etc) + * [Does not work/compile with another library](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#does-not-workcompile-with-another-library) + * [Minimal CPU clock frequency](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#minimal-cpu-clock-frequency) + * [Bang & Olufsen protocol](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#bang--olufsen-protocol) +- [Examples for this library](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#examples-for-this-library) +- [WOKWI online examples](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#wokwi-online-examples) +- [IR control of a robot car](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#ir-control-of-a-robot-car) +- [Issues and discussions](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#issues-and-discussions) +- [Compile options / macros for IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#compile-options--macros-for-irremote) +- [Macros for TinyIR](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#macros-for-tinyir) +- [Macros for IRCommandDispatcher](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#macros-for-ircommanddispatcher) + + [Changing include (*.h) files with Arduino IDE](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#changing-include-h-files-with-arduino-ide) + + [Modifying compile options / macros with PlatformIO](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#modifying-compile-options--macros-with-platformio) + + [Modifying compile options with Sloeber IDE](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#modifying-compile-options--macros-with-sloeber-ide) +- [Supported Boards](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#supported-boards) +- [Timer and pin usage](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage) + * [Incompatibilities to other libraries and Arduino commands like tone() and analogWrite()](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#incompatibilities-to-other-libraries-and-arduino-commands-like-tone-and-analogwrite) + * [Hardware-PWM signal generation for sending](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#hardware-pwm-signal-generation-for-sending) + * [Why do we use 30% duty cycle for sending](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#why-do-we-use-30-duty-cycle-for-sending) +- [How we decode signals](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-we-decode-signals) +- [NEC encoding diagrams](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#nec-encoding-diagrams) +- [Quick comparison of 5 Arduino IR receiving libraries](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#quick-comparison-of-5-arduino-ir-receiving-libraries) +- [History](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/changelog.md) +- [Useful links](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#useful-links) - [Contributors](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/Contributors.md) -- [License](https://github.com/Arduino-IRremote/Arduino-IRremote#license) -- [Copyright](https://github.com/Arduino-IRremote/Arduino-IRremote#copyright) +- [License](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#license) +- [Copyright](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#copyright)
# Supported IR Protocols -` NEC / Onkyo / Apple `     ` Denon / Sharp `     ` Panasonic / Kaseikyo ` +` NEC / Onkyo / Apple `,     ` Denon / Sharp `,     ` Panasonic / Kaseikyo `, -` JVC `     ` LG `     ` RC5 `     ` RC6 `     ` Samsung `     ` Sony ` +` JVC `,     ` LG `,     ` RC5 `,     ` RC6 `,     ` Samsung `,     ` Sony `,     ` Marantz ` -` Universal Pulse Distance `     ` Universal Pulse Width `     ` Hash `     ` Pronto ` +` Universal Pulse Distance `,     ` Universal Pulse Width `,     ` Universal Pulse Distance Width` -` BoseWave `     ` Bang & Olufsen `     ` Lego `     ` FAST `     ` Whynter `     ` MagiQuest ` +` Hash `,     ` Pronto ` + +` BoseWave `,     ` Bang & Olufsen `,     ` Lego `,     ` FAST `,     ` Whynter `,     ` Marantz `,     ` MagiQuest `,     ` Velux `,     ` OpenLASIR ` Protocols can be switched off and on by defining macros before the line `#include ` like [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino#L33): @@ -96,162 +120,35 @@ Protocols can be switched off and on by defining macros before the line `#includ ```
-# Features -- Lots of tutorials and examples. -- Actively maintained. -- Allows receiving and sending of **raw timing data**. - -## New features with version 4.x -- New universal **Pulse Distance / Pulse Width decoder** added, which covers many previous unknown protocols. -- Printout of code how to send received command by `IrReceiver.printIRSendUsage(&Serial)`. -- RawData type is now 64 bit for 32 bit platforms and therefore `decodedIRData.decodedRawData` can contain complete frame information for more protocols than with 32 bit as before. -- Callback after receiving a command - It calls your code as soon as a message was received. -- Improved handling of `PULSE_DISTANCE` + `PULSE_WIDTH` protocols. -- New FAST protocol. - -#### Converting your 3.x program to the 4.x version -- You must replace `#define DECODE_DISTANCE` by `#define DECODE_DISTANCE_WIDTH` (only if you explicitly enabled this decoder). -- The parameter `bool hasStopBit` is not longer required and removed e.g. for function `sendPulseDistanceWidth()`. - -## New features with version 3.x -- **Any pin** can be used for sending -if `SEND_PWM_BY_TIMER` is not defined- and receiving. -- Feedback LED can be activated for sending / receiving. -- An 8/16 bit ****command** value as well as an 16 bit **address** and a protocol number is provided for decoding (instead of the old 32 bit value). -- Protocol values comply to **protocol standards**.
- NEC, Panasonic, Sony, Samsung and JVC decode & send LSB first. -- Supports **Universal Distance protocol**, which covers a lot of previous unknown protocols. -- Compatible with **tone()** library. See the [ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/21b5747a58e9d47c9e3f1beb056d58c875a92b47/examples/ReceiveDemo/ReceiveDemo.ino#L159-L169) example. -- Simultaneous sending and receiving. See the [SendAndReceive](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendAndReceive/SendAndReceive.ino#L167-L170) example. -- Supports **more platforms**. -- Allows for the generation of non PWM signal to just **simulate an active low receiver signal** for direct connect to existent receiving devices without using IR. -- Easy protocol configuration, **directly in your [source code](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino#L33-L57)**.
- Reduces memory footprint and decreases decoding time. -- Contains a [very small NEC only decoder](https://github.com/Arduino-IRremote/Arduino-IRremote#minimal-nec-receiver), which **does not require any timer resource**. - -[-> Feature comparison of 5 Arduino IR libraries](https://github.com/Arduino-IRremote/Arduino-IRremote#quick-comparison-of-5-arduino-ir-receiving-libraries). +# Common issues when using IRremote +Or *"I build a gadget with 2 motors controlled by IR and the [IR stops after the first motor command](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#receiving-stops-after-analogwrite-or-tone-or-after-running-a-motor)"*.
+This is due to the fact, that the motor control by AnalogWrite() uses the same timer as IR receiving.
+See [this table](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage) for the list of timers and pins.
-# Converting your 2.x program to the 4.x version -Starting with the 3.1 version, **the generation of PWM for sending is done by software**, thus saving the hardware timer and **enabling arbitrary output pins for sending**.
-If you use an (old) Arduino core that does not use the `-flto` flag for compile, you can activate the line `#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN` in IRRemote.h, if you get false error messages regarding begin() during compilation. - -- **IRreceiver** and **IRsender** object have been added and can be used without defining them, like the well known Arduino **Serial** object. -- Just remove the line `IRrecv IrReceiver(IR_RECEIVE_PIN);` and/or `IRsend IrSender;` in your program, and replace all occurrences of `IRrecv.` or `irrecv.` with `IrReceiver` and replace all `IRsend` or `irsend` with `IrSender`. -- Since the decoded values are now in `IrReceiver.decodedIRData` and not in `results` any more, remove the line `decode_results results` or similar. -- Like for the Serial object, call [`IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK)`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L106) - or `IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK)` instead of the `IrReceiver.enableIRIn()` or `irrecv.enableIRIn()` in setup().
-For sending, call `IrSender.begin(ENABLE_LED_FEEDBACK);` or `IrSender.begin(DISABLE_LED_FEEDBACK);` in setup().
-If IR_SEND_PIN is not defined you must use e.g. `IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);` -- Old `decode(decode_results *aResults)` function is replaced by simple `decode()`. So if you have a statement `if(irrecv.decode(&results))` replace it with `if (IrReceiver.decode())`. -- The decoded result is now in in `IrReceiver.decodedIRData` and not in `results` any more, therefore replace any occurrences of `results.value` and `results.decode_type` (and similar) to - `IrReceiver.decodedIRData.decodedRawData` and `IrReceiver.decodedIRData.protocol`. -- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRProtocol.h#L90-L101). -- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`. - -- The 5 protocols **NEC, Panasonic, Sony, Samsung and JVC** have been converted to LSB first. Send functions for sending old MSB data for **NEC** and **JVC** were renamed to `sendNECMSB`, and `sendJVCMSB()`. The old `sendSAMSUNG()` and `sendSony()` MSB functions are still available. The old MSB version of `sendPanasonic()` function was deleted, since it had bugs nobody recognized.
-For converting MSB codes to LSB see [below](https://github.com/Arduino-IRremote/Arduino-IRremote#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes). - -### Example -#### Old 2.x program: - -```c++ -#include - -IRrecv irrecv(RECV_PIN); -decode_results results; - -void setup() -{ -... - irrecv.enableIRIn(); // Start the receiver -} - -void loop() { - if (irrecv.decode(&results)) { - Serial.println(results.value, HEX); - ... - irrecv.resume(); // Receive the next value - } - ... -} -``` - -#### New 4.x program: +# [Migrating legacy projects to the latest version](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/Migrating.md) -```c++ -#include - -void setup() -{ -... - IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver -} - -void loop() { - if (IrReceiver.decode()) { - Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data - // USE NEW 3.x FUNCTIONS - IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line - IrReceiver.printIRSendUsage(&Serial); // Print the statement required to send this data - ... - IrReceiver.resume(); // Enable receiving of the next value - } - ... -} -``` +## New features and changes in version 4.6 +** Version 4.5.0 does not work for ESP platform, because of missing ESP IRAM_ATTR for receiving interrupt.** +- Support for **multiple receiver instances**.
+`irparams_struct irparams` is now member of `IRrecv`. Thus `rawDataPtr` (pointer to irparams) was removed from `IrReceiver.decodedIRData`.
+Old `IrReceiver.decodedIRData.rawDataPtr->rawbuf` is now `IrReceiver.irparams.rawbuf`, the same holds for `IrReceiver.irparams.rawlen`. +- LED feedback is always enabled for sending. It can only be disabled by using `#define NO_LED_SEND_FEEDBACK_CODE` or `#define NO_LED_FEEDBACK_CODE`. +- The second parameter of the function `IrSender.begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback)` has changed to `uint_fast8_t aFeedbackLEDPin`. Therefore this function call no longer works as expected because it uses the old boolean value of e.g. `ENABLE_LED_FEEDBACK` which evaluates to true or 1 as pin number of the LED feedback pin number. +- New experimental Velux send function. +- Send function for Marantz version of the RC5x protocol. This protocol has an additional 6 bit command extension and adds a short pause after the address is sent to identify this variant of the protocol. -## How to convert old MSB first 32 bit IR data codes to new LSB first 32 bit IR data codes -For the new decoders for **NEC, Panasonic, Sony, Samsung and JVC**, the result `IrReceiver.decodedIRData.decodedRawData` is now **LSB-first**, as the definition of these protocols suggests!

-To convert one into the other, you must reverse the byte/nibble positions and then reverse all bit positions of each byte/nibble or write it as one binary string and reverse/mirror it.

-Example: -`0xCB 34 01 02`
-`0x20 10 43 BC` after nibble reverse
-`0x40 80 2C D3` after bit reverse of each nibble

-### Nibble reverse map: -``` - 0->0 1->8 2->4 3->C - 4->2 5->A 6->6 7->E - 8->1 9->9 A->5 B->D - C->3 D->B E->7 F->F -``` -`0xCB340102` is binary `1100 1011 0011 0100 0000 0001 0000 0010`.
-`0x40802CD3` is binary `0100 0000 1000 0000 0010 1100 1101 0011`.
-If you **read the first binary sequence backwards** (right to left), you get the second sequence. - -
- -# Errors with using the 4.x versions for old tutorials -If you suffer from errors with old tutorial code including `IRremote.h` instead of `IRremote.hpp`, just try to rollback to [Version 2.4.0](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/v2.4.0).
-Most likely your code will run and you will not miss the new features... -
- -## Staying on 2.x -Consider using the [original 2.4 release form 2017](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/v2.4.0) -or the last backwards compatible [2.8 version](https://github.com/Arduino-IRremote/Arduino-IRremote/releases/tag/2.8.0) for you project.
-It may be sufficient and deals flawlessly with 32 bit IR codes.
-If this doesn't fit your case, be assured that 3.x is at least trying to be backwards compatible, so your old examples should still work fine. - -### Drawbacks -- Only the following decoders are available:
- ` NEC `     ` Denon `     ` Panasonic `     ` JVC `     ` LG `
- ` RC5 `     ` RC6 `     ` Samsung `     ` Sony ` -- The call of `irrecv.decode(&results)` uses the old MSB first decoders like in 2.x and sets the 32 bit codes in `results.value`. -- The old functions `sendNEC()` and `sendJVC()` are renamed to `sendNECMSB()` and `sendJVCMSB()`.
- Use them to send your **old MSB-first 32 bit IR data codes**. -- No decoding by a (constant) 8/16 bit address and an 8 bit command. - -
- -# Why *.hpp instead of *.cpp? +# Why *.hpp instead of *.cpp files? **Every \*.cpp file is compiled separately** by a call of the compiler exclusively for this cpp file. These calls are managed by the IDE / make system. In the Arduino IDE the calls are executed when you click on *Verify* or *Upload*. -And now our problem with Arduino is:
-**How to set [compile options](#compile-options--macros-for-this-library) for all *.cpp files, especially for libraries used?**
-IDE's like [Sloeber](https://github.com/ArminJo/ServoEasing#modifying-compile-options--macros-with-sloeber-ide) or [PlatformIO](https://github.com/ArminJo/ServoEasing#modifying-compile-options--macros-with-platformio) support this by allowing to specify a set of options per project. +And now **our problem with Arduino** is:
+**How to set [compile options](#compile-options--macros-for-irremote) for all *.cpp files, especially for libraries used?**
+IDE's like [Sloeber](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#modifying-compile-options--macros-with-sloeber-ide) or +[PlatformIO](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#modifying-compile-options--macros-with-platformio) support this by allowing to specify a set of options per project. They add these options at each compiler call e.g. `-DTRACE`. But Arduino lacks this feature. @@ -259,14 +156,14 @@ So the **workaround** is not to compile all sources separately, but to concatena This is done by e.g. `#include "IRremote.hpp"`. But why not `#include "IRremote.cpp"`?
-Try it and you will see tons of errors, because each function of the *.cpp file is now compiled twice, -first by compiling the huge file and second by compiling the *.cpp file separately, like described above.
-So using the extension *cpp* is not longer possible, and one solution is to use *hpp* as extension, to show that it is an included *.cpp file.
-Every other extension e.g. *cinclude* would do, but *hpp* seems to be common sense. +If you try it, you will see lots of errors, because each function of the *.cpp file is now compiled twice:
+first when the huge file is compiled, and second when the .cpp file is compiled separately, as described above.
+Therefore, using the **.cpp** extension is no longer possible. One solution is to use the **.hpp** extension to indicate that it is an included .cpp file.
+Any other extension would work, e.g. *cinclude*, but *hpp* seems to be common sense. # Using the new *.hpp files -In order to support [compile options](#compile-options--macros-for-this-library) more easily, -you must use the statement `#include ` instead of `#include ` in your main program (aka *.ino file with setup() and loop()). +In order to support [compile options](#compile-options--macros-for-irremote) more easily, +you **must** use the statement `#include ` instead of `#include ` in your main program (aka *.ino file with setup() and loop()). In **all other files** you must use the following, to **prevent `multiple definitions` linker errors**: @@ -283,39 +180,99 @@ The following macros will definitely be overridden with default values otherwise
+# Tutorials +- A very elaborated introduction to IR remotes and IRremote library from [DroneBot Workshop ](https://dronebotworkshop.com/ir-remotes/). + + +# 3 ways to specify an IR code +There are 3 different ways of specifying a particular IR code. +- **Timing (Raw):** Records the exact duration of pulses. Uses the most memory but works for everything. +- **Encoding Schemes:** General rules for each data bit (like how 1s and 0s are shaped). +- **Protocols (Recommended):** Uses predefined names (like NEC or Sony) and small 8 or 16-bit addresses and commands. Most efficient and easiest to read. + +## 1. Timing +The timing of each mark/pulse and space/distance_between_pulses is specified in a list or array. +This enables specifying **all IR codes**, but requires a lot of memory and is **not readable at all**. +One formal definition of such a timing array, including **specification of frequency and repeats** is the [**Pronto** format](http://www.harctoolbox.org/Glossary.html#ProntoSemantics).
+Memory can be saved by using a lower time resolution. +For IRremote you can use a 50 µs resolution which halves the memory requirement by using byte values instead of int16 values. +For receiving purposes you can use the **hash of the timing** provided by the `decodeHash()` decoder. + +## 2. Encoding schemes +There are 3 main encoding schemes which encode a binary bitstream / hex value: +1. `PULSE_DISTANCE`. The distance between pulses determines the bit value. This always requires a stop bit! +Examples are NEC and KASEIKYO protocols. The pulse width is constant for most protocols. +2. `PULSE_WIDTH`. The width of a pulse determines the bit value, pulse distance is constant. This requires no stop bit! +The only known example is the SONY protocol. +3. [Phase / Manchester encoding](https://en.wikipedia.org/wiki/Manchester_code). +The time of the pulse/pause transition (phase) relative to the clock determines the bit value. Examples are RC5 and RC6 protocols. + +Phase encoding has a **constant bit length**, `PULSE_DISTANCE` with constant pulse width and `PULSE_WIDTH` have **no constant bit length**! + +A well known example for `PULSE_DISTANCE` with non constant pulse width encoding is the **RS232 serial encoding**. +Here the non constant pulse width is used to enable a **constant bit length**. + +Most IR signals have a **special header** to help in setting the automatic gain of the receiver circuit. +This header is not part of the encoding, but is often significant for a special protocol and therefore must be reproducible. + +Be aware that there are codes using a `PULSE_DISTANCE` encoding where more than a binary 0/1 is put into a pulse/pause combination. +This requires more than 2 different pulse or pause length combinations. +The [HobToHood protocol](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveAndSendHob2Hood/ReceiveAndSendHob2Hood.ino) uses such an encoding. + +Using encoding schemes reduces the specification of an IR code to a bitstream / hex value, which is LSB by default and pulse / pause timings of header, 0, and 1. +The hex value is **quite readable**. +These schemes can not put any semantics like address, command or checksum on this bitstream. + +## 3. Protocols +There are a few common protocols that are implemented directly in IRremote. +They specify the frequency, the timings of header, 0, and 1 as well as other values like checksum, repeat distance, repeat coding, bit toggling etc. +The semantics of the hex value is also specified, allowing the usage of only 2 parameters **address** and **command** to specify an IR code. +This saves memory and is **highly readable**. +Often the address is also constant, which further reduces memory requirements. + + +# IRReceiver pinouts +![IRReceiver Pinout](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/IRReceiverPinout.jpg) + +[Adafruit IR Sensor tutorial](https://learn.adafruit.com/ir-sensor) + + # Receiving IR codes -Check for **received data** with:
+In your program you check for a **completely received IR frame** with:
`if (IrReceiver.decode()) {}`
-This also decodes the received data. - -## Data format +This also decodes the received data.
After successful decoding, the IR data is contained in the IRData structure, available as `IrReceiver.decodedIRData`. +## decodedIRData structure ```c++ struct IRData { decode_type_t protocol; // UNKNOWN, NEC, SONY, RC5, PULSE_DISTANCE, ... uint16_t address; // Decoded address uint16_t command; // Decoded command uint16_t extra; // Used for Kaseikyo unknown vendor ID. Ticks used for decoding Distance protocol. + IRDecodedRawDataType decodedRawData; // Up to 32 (64 bit for 32 bit CPU architectures) bit decoded raw data, used for sendRaw functions. +#if defined(DECODE_DISTANCE_WIDTH) + DistanceWidthTimingInfoStruct DistanceWidthTimingInfo; // 12 bytes + IRDecodedRawDataType decodedRawDataArray[DECODED_RAW_DATA_ARRAY_SIZE]; // 32/64 bit decoded raw data, to be used for sendPulseDistanceWidthFromArray functions. +#endif uint16_t numberOfBits; // Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible. uint8_t flags; // IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions - IRRawDataType decodedRawData; // Up to 32 (64 bit for 32 bit CPU architectures) bit decoded raw data, used for sendRaw functions. - uint32_t decodedRawDataArray[RAW_DATA_ARRAY_SIZE]; // 32 bit decoded raw data, to be used for send function. - irparams_struct *rawDataPtr; // Pointer of the raw timing data to be decoded. Mainly the data buffer filled by receiving ISR. + IRRawlenType rawlen; // Counter of entries in rawbuf of last received frame. + uint16_t initialGapTicks; // Contains the initial gap of the last received frame. }; ``` #### Flags -This is the [list of flags](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRProtocol.h#L88) contained in the flags field.
+This is the [list of flags](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRProtocol.h#L143) contained in the flags field.
Check it with e.g. `if(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)`. | Flag name | Description | |:---|----| -| IRDATA_FLAGS_IS_REPEAT | 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!!! +| IRDATA_FLAGS_IS_REPEAT | 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 virtually impossible to press 2 different buttons on the remote within around 100 ms!!! | IRDATA_FLAGS_IS_AUTO_REPEAT | 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. | | IRDATA_FLAGS_PARITY_FAILED | The current (autorepeat) frame violated parity check. | | IRDATA_FLAGS_TOGGLE_BIT | Is set if RC5 or RC6 toggle bit is set. | | IRDATA_FLAGS_EXTRA_INFO | There is extra info not contained in address and data (e.g. Kaseikyo unknown vendor ID, or in decodedRawDataArray). | -| IRDATA_FLAGS_WAS_OVERFLOW | irparams.rawlen is set to 0 in this case to avoid endless OverflowFlag. | +| IRDATA_FLAGS_WAS_OVERFLOW | Too many marks and spaces for the specified `RAW_BUFFER_LENGTH`. To avoid endless flagging of overflow, irparams.rawlen is set to 0 in this case. | | IRDATA_FLAGS_IS_MSB_FIRST | This value is mainly determined by the (known) protocol. | #### To access the **RAW data**, use: @@ -334,15 +291,21 @@ IrReceiver.printIRResultShort(&Serial); ```c++ IrReceiver.printIRResultRawFormatted(&Serial, true);` ``` -The raw data depends on the internal state of the Arduino timer in relation to the received signal and might therefore be slightly different each time. (resolution problem). The decoded values are the interpreted ones which are tolerant to such slight differences! +The raw data depends on the internal state of the Arduino timer in relation to the received signal and might therefore be slightly different each time. (resolution problem). +The decoded values are the interpreted ones which are tolerant to such slight differences! #### Print how to send the received data: ```c++ IrReceiver.printIRSendUsage(&Serial); ``` +## Callback functionality +Sometimes it can be difficult to call decode() periodically in the main loop to avoid missing any IR frames. +In this case you can use the callback functionality as demonstrated in the [CallbackDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/CallbackDemo/CallbackDemo.ino#L126) example. +This enables you to perform `resume()` and short actions independently of the state of your main loop. + ## Ambiguous protocols -### NEC, Extended NEC, ONKYO +### NEC, Extended NEC, ONKYO, OpenLASIR The **NEC protocol** is defined as 8 bit address and 8 bit command. But the physical address and data fields are each 16 bit wide. The additional 8 bits are used to send the inverted address or command for parity checking.
The **extended NEC protocol** uses the additional 8 parity bit of address for a 16 bit address, thus disabling the parity check for address.
@@ -357,18 +320,109 @@ The decoder interprets this as a NEC 8 bit address 0x00 / 0x32 with correct pari One way to handle this, is to force the library to **always** use the ONKYO protocol interpretation by using `#define DECODE_ONKYO`. Another way is to check if `IrReceiver.decodedIRData.protocol` is NEC and not ONKYO and to revert the parity reducing manually. +The **[OpenLASIR protocol](https://github.com/danielweidman/OpenLASIR)** is binary identical to ONKYO but has a different semantics. It is recommended to disable `#define DECODE_ONKYO` and enable `#define DECODE_OPENLASIR` when working with OpenLASIR. + ### NEC, NEC2 On a long press, the **NEC protocol** does not repeat its frame, it sends a special short repeat frame. This enables an easy distinction between long presses and repeated presses and saves a bit of battery energy. -This behavior is quite unique for NEC and its derived protocols like LG. +This behavior is quite unique for NEC and its derived protocols like LG and Samsung. -So there are of course also remote control systems, which uses the NEC protocol but on a long press just repeat the first frame instead of sending the special short repeat frame. We named this the **NEC2** protocol and it is sent with `sendNEC2()`.
+But of course there are also remote control systems, that uses the NEC protocol but only repeat the first frame when a long press is made instead of sending the special short repeat frame. We named this the **NEC2** protocol and it is sent with `sendNEC2()`.
But be careful, the NEC2 protocol can only be detected by the NEC library decoder **after** the first frame and if you do a long press! +### Samsung, SamsungLG +On a long press, the **SamsungLG protocol** does not repeat its frame, it sends a special short repeat frame. + +## RAM usage of different protocols +The `RAW_BUFFER_LENGTH` determines the length of the **byte buffer** where the received IR timing data is stored before decoding.
+**100** is sufficient for standard protocols **up to 48 bits**, with 1 bit consisting of one mark and space. +We always require additional 4 bytes, 1 byte for initial gap, 2 bytes for header and 1 byte for stop bit. +- **48** bit protocols are PANASONIC, KASEIKYO, SAMSUNG48, RC6. +- **32** bit protocols like NEC, SAMSUNG, WHYNTER, SONY(20), LG(28), OpenLASIR require a **buffer length of 68**. +- **16** bit protocols like BOSEWAVE, DENON, FAST, JVC, LEGO_PF, RC5, SONY(12 or 15) require a **buffer length of 36**. +- MAGIQUEST requires a buffer length of **112**. +- Air conditioners often send a longer protocol data stream **up to 750 bits**. + +If the record gap determined by `RECORD_GAP_MICROS` is changed from the default 8 ms to more than 20 ms, the buffer is no longer a byte but a uint16_t buffer, requiring twice as much RAM. +
+ +## Handling unknown Protocols +### Disclaimer +**This library was designed to fit inside MCUs with relatively low levels of resources and was intended to work as a library together with other applications which also require some resources of the MCU to operate.** + +Use the **ReceiveDemo example** to print out all informations about your IR protocol.
+The **ReceiveDump example** gives you more information but has bad repeat detection due to the time required for printing the information. + +### Other libraries, which may cover these protocols +#### IRMP +If your protocol seems not to be supported by this library, you may try the [IRMP library](https://github.com/IRMP-org/IRMP), which especially supports manchester protocols much better. + +#### IRremoteESP8266 +For **air conditioners** , you may try the [IRremoteESP8266 library](https://github.com/crankyoldgit/IRremoteESP8266), which supports an impressive set of protocols and a lot of air conditioners and works also on ESP32. + +#### rawirdecode and HeatpumpIR +[Raw-IR-decoder-for-Arduino](https://github.com/ToniA/Raw-IR-decoder-for-Arduino) is not a library, but an arduino example sketch, which provides many methods of decoding especially **air conditioner** protocols. Sending of these protocols can be done by the Arduino library [HeatpumpIR](https://github.com/ToniA/arduino-heatpumpir). + + +### Protocol=PULSE_DISTANCE +If you get something like this: +``` +PULSE_DISTANCE: HeaderMarkMicros=8900 HeaderSpaceMicros=4450 MarkMicros=550 OneSpaceMicros=1700 ZeroSpaceMicros=600 NumberOfBits=56 0x43D8613C 0x3BC3BC +``` +then you have a code consisting of **56 bits**, which is probably from an air conditioner remote.
+You can send it with `sendPulseDistanceWidth()`. +```c++ +uint32_t tRawData[] = { 0xB02002, 0xA010 }; +IrSender.sendPulseDistance(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, false, 0, 0); +``` +You can send it with calling `sendPulseDistanceWidthData()` twice, once for the first 32 bit and next for the remaining 24 bits.
+The `PULSE_DISTANCE` / `PULSE_WIDTH` decoder just decodes a timing stream to a bitstream stored as hex values. +These decoders can not put any semantics like address, command or checksum on this bitstream. +But the bitstream is way more readable, than a timing stream. This bitstream is read **LSB first by default**. +If LSB does not suit for further research, you can change it [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_DistanceProtocol.hpp#L78). + +**If RAM is not more than 2k, the decoder only accepts mark or space durations up to 2500 microseconds to save RAM space, otherwise it accepts durations up to 10 ms.** + +### Protocol=UNKNOWN +If you see something like `Protocol=UNKNOWN Hash=0x13BD886C 35 bits received` as output of e.g. the ReceiveDemo example, you either have a problem with decoding a protocol, or an unsupported protocol. + +- If you have an **odd number of bits** received, your receiver circuit probably has problems. Maybe because the IR signal is too weak. +- If you see timings like `+ 600,- 600 + 550,- 150 + 200,- 100 + 750,- 550` then one 450 µs space was split into two 150 and 100 µs spaces with a spike / error signal of 200 µs between. Maybe because of a defective receiver or a weak signal in conjunction with another light emitting source nearby. +- If you see timings like `+ 500,- 550 + 450,- 550 + 450,- 500 + 500,-1550`, then marks are generally shorter than spaces and therefore `MARK_EXCESS_MICROS` (specified in your ino file) should be **negative** to compensate for this at decoding. +- If you see `Protocol=UNKNOWN Hash=0x0 1 bits received` it may be that the space after the initial mark is longer than [`RECORD_GAP_MICROS`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L124). + This was observed for some LG air conditioner protocols. Try again with a line e.g. `#define RECORD_GAP_MICROS 12000` before the line `#include ` in your .ino file. +- To see more info supporting you to find the reason for your UNKNOWN protocol, you must enable the line `//#define DEBUG` in IRremoteInt.h. + +### How to deal with protocols not supported by IRremote +If you do not know which protocol your IR transmitter uses, you have several choices. +- Just use the hash value to decide which command was received. See the [SimpleReceiverForHashCodes example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiverForHashCodes/SimpleReceiverForHashCodes.ino). +- Use the [IRreceiveDemo example](examples/ReceiveDemo) or [IRreceiveDump example](examples/ReceiveDump) to dump out the IR timing. + You can then reproduce/send this timing with the [SendRawDemo example](examples/SendRawDemo). +- The [IRMP AllProtocol example](https://github.com/IRMP-org/IRMP#allprotocol-example) prints the protocol and data for one of the **[40 supported protocols](https://github.com/IRMP-org/IRMP?tab=readme-ov-file#list-of-protocols)**. + The same library can be used to send this codes. +- If you have a bigger Arduino board at hand (> 100 kByte program memory) you can try the + [IRremoteDecode example](https://github.com/bengtmartensson/Arduino-DecodeIR/blob/master/examples/IRremoteDecode/IRremoteDecode.ino) of the Arduino library [DecodeIR](https://github.com/bengtmartensson/Arduino-DecodeIR). +- Use [IrScrutinizer](http://www.harctoolbox.org/IrScrutinizer.html). + It can automatically generate a send sketch for your protocol by exporting as "Arduino Raw". It supports IRremote, + the old [IRLib](https://github.com/cyborg5/IRLib) and [Infrared4Arduino](https://github.com/bengtmartensson/Infrared4Arduino). + +## Multiple IR receivers +**This library now supports multiple IR receiver instances (IRrecv) per CPU** by activating `SUPPORT_MULTIPLE_RECEIVER_INSTANCES` +and providing the simple function `UserIRReceiveTimerInterruptHandler()`. +See the [MultipleReceivers example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/MultipleReceivers/MultipleReceivers.ino). + +There is also another way to use multiple receivers. +You can connect the output pins of each IR receiver to one input pin. +Then you can use the standard receiver object (IrReceiver). +The IR receiver modules internally use an NPN transistor as output device with just a 30k resistor to VCC. +This is basically an "open collector" and allows multiple output pins to be connected to one Arduino input pin.
+However, keep in mind that any weak / disturbed signal from one of the receivers will also interfere with a good signal from another receiver. +
# Sending IR codes -If you have a device at hand which can generate the IR codes you want to work with (aka IR remote), **it is recommended** to receive the codes with the [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino), which will tell you on the serial output how to send them. +If you have a device at hand which can generate the IR codes you want to work with (aka IR remote), +**it is recommended** to receive the codes with the [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino), which will tell you on the serial output how to send them. ``` Protocol=LG Address=0x2 Command=0x3434 Raw-Data=0x23434E 28 bits MSB first @@ -377,33 +431,128 @@ Send with: IrSender.sendLG(0x2, 0x3434, ); You will discover that **the address is a constant** and the commands sometimes are sensibly grouped.
If you are uncertain about the numbers of repeats to use for sending, **3** is a good starting point. If this works, you can check lower values afterwards. -The codes found in the [irdb database](https://github.com/probonopd/irdb/tree/master/codes) specify a **device**, a **subdevice** and a **function**. Most of the times, *device* and *subdevice* can be taken as upper and lower byte of the **address parameter** and *function* is the **command parameter** for the **new structured functions** with address, command and repeat-count parameters like e.g. `IrSender.sendNEC((device << 8) | subdevice, 0x19, 2)`.
-An **exact mapping** can be found in the [IRP definition files for IR protocols](https://github.com/probonopd/MakeHex/tree/master/protocols). "D" and "S" denotes device and subdevice and "F" denotes the function. +If you have enabled `DECODE_DISTANCE_WIDTH`, the code printed by `printIRSendUsage()` **differs between 8 and 32 bit platforms**, +so it is best to run the receiving program on the same platform as the sending program. **All sending functions support the sending of repeats** if sensible. Repeat frames are sent at a fixed period determined by the protocol. e.g. 110 ms from start to start for NEC.
Keep in mind, that **there is no delay after the last sent mark**. If you handle the sending of repeat frames by your own, you must insert sensible delays before the repeat frames to enable correct decoding. -The old send*Raw() functions for sending like e.g. `IrSender.sendNECRaw(0xE61957A8,2)` are kept for backward compatibility to **(old)** tutorials and unsupported as well as error prone. +Bear in mind, that **some devices only accept commands if they are repeated one or two times**. -## Send pin -Any pin can be choosen as send pin, because the PWM signal is generated by default with software bit banging, since `SEND_PWM_BY_TIMER` is not active. -If `IR_SEND_PIN` is specified (as constant), it reduces program size and improves send timing for AVR. If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must disable this macro. Then you can change send pin at any time before sending an IR frame. See also [Compile options / macros for this library](https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library). +Sending **old MSB codes without conversion** can be done by using `sendNECMSB()`, `sendSonyMSB()`, `sendSamsungMSB()`, `sendJVCMSB()` +or by [converting them manually to LSB](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#how-to-convert-old-msb-first-32-bit-ir-data-codes-to-new-lsb-first-32-bit-ir-data-codes). + +## Sending UNKNOWN protocol +If the protocol is unknown by IRremote, which often is the case for airconditioner codes, +you can store the timing sequence in an array and send it with IrSender.sendRaw() or IrSender.sendRaw_P() +like done in [SendDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendDemo/SendDemo.ino#L180). +Do not forget to send repeats. + +## Sending protocol from description +If you only have the description of the protocol, but no sender which can generate the IR codes, +then you can try to send the protocol with: + +``` +sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, + uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, + IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + int_fast8_t aNumberOfRepeats, void (*aSpecialSendRepeatFunction)() = nullptr) +``` + +E.g. for the CDTV IR Keyboard protocol a description can be found [here](https://github.com/Korinel/Amiga-CDTV-IR-Keyboard). +Thus, the right parameters for CDTV IR Keyboard Protocol on a 32 bit platform are: + +``` +sendPulseDistanceWidth(40, 9000, 4500, 1200, 400, 400, 400, , 40, + IRDATA_FLAGS_IS_MSB_FIRST, 110, 3); // 110 and 3 are guessed values! +``` + +On an 8 bit platform, you must store the 40 bits into an array of two 32 bit unsigned integers and send it with: + +``` +sendPulseDistanceWidthFromArray(40, 9000, 4500, 1200, 400, 400, 400,
40, + IRDATA_FLAGS_IS_MSB_FIRST, 110, 3); // 110 and 3 are guessed values! +``` + +## Sending IRDB IR codes +The codes found in the [irdb database](https://github.com/probonopd/irdb/tree/master/codes) specify a **device**, a **subdevice** and a **function**. +Most of the times, *device* and *subdevice* can be taken as upper and lower byte of the **address parameter** and *function* +is the **command parameter** for the **new structured functions** with address, command and repeat-count parameters +like e.g. `IrSender.sendNEC((device << 8) | subdevice, 0x19, 2)`.
+An **exact mapping** can be found in the [IRP definition files for IR protocols](https://github.com/probonopd/MakeHex/tree/master/protocols). +"D" and "S" denotes device and subdevice and "F" denotes the function. ### List of public IR code databases http://www.harctoolbox.org/IR-resources.html -
+## Flipper Zero codes +The codes found in the [Flipper-IRDB database](https://github.com/Lucaslhm/Flipper-IRDB) are quite straightforward to convert, because the also use the address / command scheme.
+Protocol matching is NECext -> Onkyo, Samsung32 -> Samsung, SIRC20 -> Sony with 20 bits etc. + +| [Flipper decoding](https://github.com/flipperdevices/flipperzero-firmware/tree/release/lib/infrared/encoder_decoder) | [IRremote decoding](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/src) | +|-|-| +| Samsung32 | Samsung | +| NEC | NEC | +| NECext | ONKYO | +| [\\\\\\\\\](https://github.com/flipperdevices/flipperzero-firmware/blob/027ea9ea36da137144548295c016d99255af53c3/lib/infrared/encoder_decoder/kaseikyo/infrared_decoder_kaseikyo.c#L26)
and ID is MSB of address.
address: 8A 02 20 00
command: 56 03 00 00
-> **IRremote:**
Address 0x6A8, sendPanasonic (for 02 20) and Command 0x35 | \\\\\\\ | + +## Send pin +Any pin can be chosen as send pin as long as `IR_SEND_PIN` is **not** defined. +This is because the PWM signal is generated by default with software bit banging, since `SEND_PWM_BY_TIMER` is not active.
+On **ESP32** ledc channel 0 is used for generating the IR PWM.
+If `IR_SEND_PIN` is specified (as C macro), it reduces program size and improves send timing for AVR. +If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must disable this `IR_SEND_PIN` macro e.g. with `#undef IR_SEND_PIN`. +Then you can change send pin at any time before sending an IR frame. +See also [Compile options / macros for this library](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#compile-options--macros-for-this-library). + +## Polarity of send pin +By default the polarity is HIGH for active and LOW for inactive or pause. +This corresponds to the connection schema: Pin -> Resistor-> IR-LED -> Ground.
+If you want to use the connection schema: VCC -> IR-LED -> Resistor -> Pin, you must specify `USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN`. + +## Simulate an IR receiver module for sending +To simulate an IR receiver (such as the TSOP1738) which provides an active-low output, you only need to enable the `USE_NO_SEND_PWM` macro. +In the case you must simulate exotic IR receivers, which provides an active-high output, you also need to enable the `USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM` macro. + +## Increase strength of sent output signal +**The best way to increase the IR power for free** is to use 2 or 3 IR diodes in series. One diode requires 1.2 volt at 20 mA or 1.5 volt at 100 mA so you can supply up to 3 diodes with a 5 volt output.
+To power **2 diodes** with 1.2 V and 20 mA and a 5 V supply, set the resistor to: (5 V - 2.4 V) -> 2.6 V / 20 mA = **130 Ω**.
+For **3 diodes** it requires 1.4 V / 20 mA = **70 Ω**.
+The actual current might be lower since of **loss at the AVR pin**. E.g. 0.3 V at 20 mA.
+If you do not require more current than 20 mA, there is no need to use an external transistor (at least for AVR chips). + +On my Arduino Nanos, I always use a 100 Ω series resistor and one IR LED :grinning:. +## Multiple IR sender instances +**This library only supports one IR sender object (IRsend) per CPU.**
+However since sending is a serial task, you can use `setSendPin()` to switch the pin to send, thus emulating multiple sender. + +
# Tiny NEC receiver and sender -For applications only requiring NEC or FAST -see below- protocol, there is a special receiver / sender included,
+For applications only requiring NEC, NEC variants or FAST -see below- protocol, there is a special receiver / sender included, which has very **small code size of 500 bytes and does NOT require any timer**. -Check out the [TinyReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote#tinyreceiver--tinysender) and [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote#irdispatcherdemo) examples.
+## Principle of operation +Unlike IRremote, which samples the input every 50 µs, the TinyIRReceiver uses a **pin change interrupt** for on-the-fly decoding. +This restricts the range of protocols that can be recognised.
+On each level change, the level and the time since the last change are used to incrementally decode the protocol.
+With this operating principle, we **cannot wait for a timeout** and then decode the protocol as IRremote does.
+Instead, we need to know which is the last bit (level change) of a protocol in order to perform the final decoding +and call of the optional **user-provided callback function** `handleReceivedTinyIRData()`.
+This means that **we need to know the number of bits in a protocol** and therefore the protocol family in order to decode successfully. + +For each complete IR frame/command received, the decoded data is copied to the `TinyIRReceiverData` structure +and the user-provided `handleReceivedTinyIRData()` function is called in an interrupt context. +However, **interrupts are explicitly enabled here** to allow the use of delay() and millis() etc. + +Check out the [TinyReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tinyreceiver--tinysender) and [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#irdispatcherdemo) examples.
Take care to include `TinyIRReceiver.hpp` or `TinyIRSender.hpp` instead of `IRremote.hpp`. +The **TinyIRSender** generates its 38 kHz PWM signal by **[software bit banging](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/TinyIRSender.hpp#L68)** using the `delayMicroseconds()` and `micros()` functions. + ### TinyIRReceiver usage ```c++ //#define USE_ONKYO_PROTOCOL // Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. @@ -411,15 +560,14 @@ Take care to include `TinyIRReceiver.hpp` or `TinyIRSender.hpp` instead of `IRre #include "TinyIRReceiver.hpp" void setup() { - initPCIInterruptForTinyReceiver(); // Enables the interrupt generation on change of IR input signal + initPCIInterruptForTinyIRReceiver(); // Enables the interrupt generation on change of IR input signal } -void loop() {} - -// This is the function, which is called if a complete command was received -// It runs in an ISR context with interrupts enabled, so functions like delay() etc. should work here -void handleReceivedTinyIRData(uint8_t aAddress, uint8_t aCommand, uint8_t aFlags) { - printTinyReceiverResultMinimal(&Serial, aAddress, aCommand, aFlags); +void loop() { + if (TinyIRReceiverDecode()) { + printTinyIRReceiverResultMinimal(&Serial); + } + // No resume() required :-) } ``` @@ -428,13 +576,13 @@ void handleReceivedTinyIRData(uint8_t aAddress, uint8_t aCommand, uint8_t aFlags #include "TinyIRSender.hpp" void setup() { - sendNECMinimal(3, 0, 11, 2); // Send address 0 and command 11 on pin 3 with 2 repeats. + sendNEC(3, 0, 11, 2); // Send address 0 and command 11 on pin 3 with 2 repeats. } void loop() {} ``` -Another tiny receiver and sender **supporting more protocols** can be found [here](https://github.com/LuisMiCa/IRsmallDecoder). +Another tiny receiver **supporting more protocols** can be found [here](https://github.com/LuisMiCa/IRsmallDecoder). # The FAST protocol The FAST protocol is a proprietary modified JVC protocol **without address, with parity and with a shorter header**. @@ -475,174 +623,227 @@ void loop() {} The FAST protocol can be received by IRremote and TinyIRReceiver. +# Feedback LED +The feedback LED output is enabled by default. This means that **the LED is on when we receive or send a mark**. +The feedback LED code can be completely removed at compile time using the following macros: +- `NO_LED_RECEIVE_FEEDBACK_CODE` for receiving +- `NO_LED_SEND_FEEDBACK_CODE` for sending +- `NO_LED_FEEDBACK_CODE` for receiving and sending + +### Receiving +For receiving, feedback LED can be activated or deactivated programmatically by `enableLEDFeedback()`, `disableLEDFeedback()` or `setLEDFeedback(bool aEnableLEDFeedback)`.
+The starting value is set by the second parameter of `begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin)`. You can use the macros `ENABLE_LED_FEEDBACK` and `DISABLE_LED_FEEDBACK` for the second parameter. + +### Sending +LED feedback is **always enabled** when sending and cannot be deactivated programmatically. +It can only be deactivated at compile time. + +# IRCommandDispatcher class +If you want to **handle many IR commands** in a structured way, you can use a big **switch statement**, or use the class `IRCommandDispatcher`.
+The IRCommandDispatcher class receives IR commands and maps them to different functions by means of a mapping array `IRMapping[]`. + +By default, every mapped command is **blocking**. However it can be declared as **non-blocking** and / or **repeatable**.
+Non-blocking commands are executed immediately, blocking commands are executed if no other command is just running. +If another blocking command is currently running, a **request to stop** is set +and the command is stored for the main loop to be executed by `checkAndRunSuspendedBlockingCommands()`. +The request to stop must be checked by any blocking function using the macros `DELAY_AND_RETURN_IF_STOP()`, `RETURN_IF_STOP`, `BREAK_IF_STOP` and `IS_STOP_REQUESTED`.
+Only commands that are marked as **repeatable** will be exectuted when a IR repeat frame is received. +Therefore this only makes sense for non-blocking comands :-). + +Code snippets are from [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRDispatcherDemo). + +```c++ +// IR code mapping which is useful if more than one remote is supported +#define IR_0 0x19 +#define IR_HASH 0x0D +#define COMMAND_BLINK IR_0 +#define COMMAND_STOP IR_HASH + +// Strings of commands for Serial output +static const char blink20times[] PROGMEM ="blink 20 times"; +static const char stop[] PROGMEM ="stop"; + +/* + * Main mapping array of commands to C functions and command strings + * The macro COMMAND_STRING() removes the strings from memory, if USE_DISPATCHER_COMMAND_STRINGS is not enabled + */ +const struct IRToCommandMappingStruct IRMapping[] = { +{ COMMAND_BLINK, IR_COMMAND_FLAG_BLOCKING | IR_COMMAND_FLAG_BEEP, &doLedBlink20times, COMMAND_STRING(blink20times) }, +{ COMMAND_STOP, IR_COMMAND_FLAG_BLOCKING, &doStop, COMMAND_STRING(stop) }, +/* + * Short commands that can always be executed + */ +{ COMMAND_TONE1, IR_COMMAND_FLAG_NON_BLOCKING, &doTone1800, tone1800 }, +... +/* + * Repeatable short commands + */ +{ COMMAND_INCREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doIncreaseBlinkFrequency, increaseBlink }, +... + +/* + * This is a blocking function which checks for stop + */ +void doLedBlink20times() { + for (int i = 0; i < 20; ++i) { + digitalWrite(LED_BUILTIN, HIGH); + DELAY_AND_RETURN_IF_STOP(200); + digitalWrite(LED_BUILTIN, LOW); + DELAY_AND_RETURN_IF_STOP(200); + } +} +// Other useful macros are RETURN_IF_STOP, BREAK_IF_STOP and IS_STOP_REQUESTED. +``` + +Examples of mapping arrays can be found in the [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRDispatcherDemo/DemoIRCommandMapping.h#L185), for [QuadrupedControl](https://github.com/ArminJo/QuadrupedControl/blob/master/examples/QuadrupedControl/QuadrupedIRCommandMapping.h#L445), for [RobotArmControl](https://github.com/ArminJo/RobotArmControl/blob/master/RobotArmControl/RobotArmIRCommandMapping.h#L320) or for [4 WD RobotCar control](https://github.com/ArminJo/PWMMotorControl/blob/master/examples/IRDispatcherControl/RobotCarIRCommandMapping.h#L308)
+ +
+ + # FAQ and hints +## Receiving stops after analogWrite() or tone() or after running a motor +The receiver sample interval of 50 µs is generated by a timer. On many boards this must be a [hardware timer](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage). +On some boards where a software timer is available, the software timer is used.
+Be aware that the hardware timer used for receiving should not be used for `analogWrite()`.
+Especially **motor** control often uses the `analogWrite()` function and will therefore stop the receiving if used on the pins indicated [here](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage).
+On the Uno and other AVR boards the receiver timer ist the same as the tone timer. Thus receiving will stop after a `tone()` command. +See [ReceiveDemo example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298) how to deal with it, i.e. how to use `IrReceiver.restartTimer()`. + +## Receiving sets overflow flag +The flag `IRDATA_FLAGS_WAS_OVERFLOW` is set, if `RAW_BUFFER_LENGTH` is too small for all the marks and spaces of the protocol. +This can happen on long protocol frames like the ones from air conditioner. +It also can happen, if `RECORD_GAP_MICROS` is smaller than the real gap between a frame and the repetition frame, thus interpreting both as one consecutive frame. +Best is to dump the timing then, to see which reason holds. ## Problems with Neopixels, FastLed etc. IRremote will not work right when you use **Neopixels** (aka WS2811/WS2812/WS2812B) or other libraries blocking interrupts for a longer time (> 50 µs).
-Whether you use the Adafruit Neopixel lib, or FastLED, interrupts get disabled on many lower end CPUs like the basic Arduinos for longer than 50 µs. -In turn, this stops the IR interrupt handler from running when it needs to. See also this [video](https://www.youtube.com/watch?v=62-nEJtm070). +Whether you use the Adafruit Neopixel library, or FastLED, interrupts get disabled on many lower end CPUs like the basic Arduinos for longer than 50 µs.
+In turn, this stops the IR interrupt handler from sampling the IR signal. + +Each WS2812 LED requires 30 µs at **800 kHz**, an **8 pixel** strip requires 240 µs and therefore **skips 4 samples** of the IR signal, which is sampled each 50 µs.
+For example, the standard timing for the NEC protocol is 560 µs or 11 samples. However, with a loss of four samples, however, we **exceed the accepted 25 %** decoding deviation threshold. One **workaround** is to wait for the IR receiver to be idle before you send the Neopixel data with `if (IrReceiver.isIdle()) { strip.show();}`.
-This **prevents at least breaking a running IR transmission** and -depending of the update rate of the Neopixel- may work quite well.
-There are some other solutions to this on more powerful processors, +This **prevents a running IR transmission from beeing broken**, and depending on the update rate of the Neopixel, it may work quite well.
+There are some other solutions to this on **more powerful CPU's**, [see this page from Marc MERLIN](http://marc.merlins.org/perso/arduino/post_2017-04-03_Arduino-328P-Uno-Teensy3_1-ESP8266-ESP32-IR-and-Neopixels.html) ## Does not work/compile with another library **Another library is only working/compiling** if you deactivate the line `IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);`.
-This is often due to **timer resource conflicts** with the other library. Please see [below](https://github.com/Arduino-IRremote/Arduino-IRremote#timer-and-pin-usage). - -## Multiple IR receivers -IRreceiver consists of one timer triggered function reading the digital IR signal value from one pin every 50 µs.
-So **multiple IR receivers** can only be used by connecting the output pins of several IR receivers together. -The IR receivers use an NPN transistor as output device with just a 30k resistor to VCC. -This is almost "open collector" and allows connecting of several output pins to one Arduino input pin.
-But keep in mind, that any weak / disturbed signal from one of the receivers will in turn also disturb a good signal from another one. - -## Increase strength of sent output signal -**The best way to increase the IR power for free** is to use 2 or 3 IR diodes in series. One diode requires 1.2 volt at 20 mA or 1.5 volt at 100 mA so you can supply up to 3 diodes with a 5 volt output.
-To power **2 diodes** with 1.2 V and 20 mA and a 5 V supply, set the resistor to: (5 V - 2.4 V) -> 2.6 V / 20 mA = **130 Ω**.
-For **3 diodes** it requires 1.4 V / 20 mA = **70 Ω**.
-The actual current might be lower since of **loss at the AVR pin**. E.g. 0.3 V at 20 mA.
-If you do not require more current than 20 mA, there is no need to use an external transistor (at least for AVR chips). - -On my Arduino Nanos, I always use a 100 Ω series resistor and one IR LED :grinning:. +This is often due to **timer resource conflicts** with the other library. Please see [below](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage). ## Minimal CPU clock frequency For receiving, the **minimal CPU clock frequency is 4 MHz**, since the 50 µs timer ISR (Interrupt Service Routine) takes around 12 µs on a 16 MHz ATmega.
-The TinyReceiver, which reqires no polling, runs with 1 MHz.
-For sending, the **default software generated PWM has problems on AVR running with 8 MHz**. The PWM frequency is around 30 instead of 38 kHz and RC6 is not reliable. You can switch to timer PWM generation by `#define SEND_PWM_BY_TIMER`. +The TinyIRReceiver, which requires no polling, works down to 1 MHz.
+For sending, the **minimal CPU clock frequency for software generated PWM is 8 MHz**. +You can switch to timer and hardware PWM generation at fixed pins by `#define SEND_PWM_BY_TIMER`. +### Hardware PWM generation of sending signal with 8 bit timer +- 16 MHZ F_CPU and 38 kHz -> prescaling = 2, divider = 210.526 -> 38.1 kHz with divider 210 +- 8 MHZ F_CPU and 38 kHz -> no prescaling , divider = 210.526 -> 38.1 kHz with divider 210 +- 4 MHZ F_CPU and 38 kHz -> no prescaling , divider = 105.26 -> 38.1 kHz with divider 105 +- 1 MHZ F_CPU and 38 kHz -> no prescaling , divider = 26.31 -> 38.4 kHz with divider 36 +TinyIRSender does not support hardware PWM generation. ## Bang & Olufsen protocol The Bang & Olufsen protocol decoder is not enabled by default, i.e if no protocol is enabled explicitly by #define `DECODE_`. It must always be enabled explicitly by `#define DECODE_BEO`. This is because it has an **IR transmit frequency of 455 kHz** and therefore requires a different receiver hardware (TSOP7000).
And because **generating a 455 kHz PWM signal is currently only implemented for `SEND_PWM_BY_TIMER`**, sending only works if `SEND_PWM_BY_TIMER` or `USE_NO_SEND_PWM` is defined.
-For more info, see [ir_BangOlufsen.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_BangOlufsen.hpp#L44). - -# Handling unknown Protocols -## Disclaimer -**This library was designed to fit inside MCUs with relatively low levels of resources and was intended to work as a library together with other applications which also require some resources of the MCU to operate.** - -For **air conditioners** [see this fork](https://github.com/crankyoldgit/IRremoteESP8266), which supports an impressive set of protocols and a lot of air conditioners. - -For **long signals** see the blog entry: ["Recording long Infrared Remote control signals with Arduino"](https://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino). - - -## Protocol=PULSE_DISTANCE -If you get something like this: -``` -PULSE_DISTANCE: HeaderMarkMicros=8900 HeaderSpaceMicros=4450 MarkMicros=550 OneSpaceMicros=1700 ZeroSpaceMicros=600 NumberOfBits=56 0x43D8613C 0x3BC3BC -``` -then you have a code consisting of **56 bits**, which is probably from an air conditioner remote.
-You can send it with sendPulseDistance(). -```c++ -uint32_t tRawData[] = { 0xB02002, 0xA010 }; -IrSender.sendPulseDistance(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, false, 0, 0); -``` -You can send it with calling sendPulseDistanceWidthData() twice, once for the first 32 bit and next for the remaining 24 bits.
-**The PulseDistance or PulseWidth decoders just decode a timing steam to a bit stream**. -They can not put any semantics like address, command or checksum on this bitstream, since it is no known protocol. -But the bitstream is way more readable, than a timing stream. This bitstream is read **LSB first by default**. -If this does not suit you for further research, you can change it [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_DistanceProtocol.hpp#L48). - -## Protocol=UNKNOWN -If you see something like `Protocol=UNKNOWN Hash=0x13BD886C 35 bits received` as output of e.g. the ReceiveDemo example, you either have a problem with decoding a protocol, or an unsupported protocol. - -- If you have an **odd number of bits** received, your receiver circuit probably has problems. Maybe because the IR signal is too weak. -- If you see timings like `+ 600,- 600 + 550,- 150 + 200,- 100 + 750,- 550` then one 450 µs space was split into two 150 and 100 µs spaces with a spike / error signal of 200 µs between. Maybe because of a defective receiver or a weak signal in conjunction with another light emitting source nearby. -- If you see timings like `+ 500,- 550 + 450,- 550 + 500,- 500 + 500,-1550`, then marks are generally shorter than spaces and therefore `MARK_EXCESS_MICROS` (specified in your ino file) should be **negative** to compensate for this at decoding. -- If you see `Protocol=UNKNOWN Hash=0x0 1 bits received` it may be that the space after the initial mark is longer than [`RECORD_GAP_MICROS`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L124). - This was observed for some LG air conditioner protocols. Try again with a line e.g. `#define RECORD_GAP_MICROS 12000` before the line `#include ` in your .ino file. -- To see more info supporting you to find the reason for your UNKNOWN protocol, you must enable the line `//#define DEBUG` in IRremoteInt.h. - -## How to deal with protocols not supported by IRremote -If you do not know which protocol your IR transmitter uses, you have several choices. -- Use the [IRreceiveDump example](examples/ReceiveDump) to dump out the IR timing. - You can then reproduce/send this timing with the [SendRawDemo example](examples/SendRawDemo). - For **long codes** with more than 48 bits like from air conditioners, you can **change the length of the input buffer** in [IRremote.h](src/IRremoteInt.h#L36). -- The [IRMP AllProtocol example](https://github.com/IRMP-org/IRMP#allprotocol-example) prints the protocol and data for one of the **40 supported protocols**. - The same library can be used to send this codes. -- If you have a bigger Arduino board at hand (> 100 kByte program memory) you can try the - [IRremoteDecode example](https://github.com/bengtmartensson/Arduino-DecodeIR/blob/master/examples/IRremoteDecode/IRremoteDecode.ino) of the Arduino library [DecodeIR](https://github.com/bengtmartensson/Arduino-DecodeIR). -- Use [IrScrutinizer](http://www.harctoolbox.org/IrScrutinizer.html). - It can automatically generate a send sketch for your protocol by exporting as "Arduino Raw". It supports IRremote, - the old [IRLib](https://github.com/cyborg5/IRLib) and [Infrared4Arduino](https://github.com/bengtmartensson/Infrared4Arduino). - -
+For more info, see [ir_BangOlufsen.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/ir_BangOlufsen.hpp#L46). # Examples for this library -The examples are available at File > Examples > Examples from Custom Libraries / IRremote.
- In order to fit the examples to the 8K flash of ATtiny85 and ATtiny88, the [Arduino library ATtinySerialOut](https://github.com/ArminJo/ATtinySerialOut) is required for this CPU's. +These examples can be found in the Arduino IDE under File > Examples > Examples from Custom Libraries / IRremote.
+**In order to fit the examples to the 8K flash of ATtiny85 and ATtiny88, the [Arduino library ATtinySerialOut](https://github.com/ArminJo/ATtinySerialOut) is required for this CPU's.**
+See also [DroneBot Workshop SimpleReceiver](https://dronebotworkshop.com/ir-remotes/#SimpleReceiver_Example_Code) and [SimpleSender](https://dronebotworkshop.com/ir-remotes/#SimpleSender_Example_Code). -#### SimpleReceiver + SimpleSender -The **[SimpleReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino)** and **[SimpleSender](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleSender/SimpleSender.ino)** examples are a good starting point. +### [SimpleReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiver/SimpleReceiver.ino) + [SimpleSender](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleSender/SimpleSender.ino) +The **SimpleReceiver** and **SimpleSender** examples are a good starting point. A simple example can be tested online with [WOKWI](https://wokwi.com/projects/338611596994544210). -#### TinyReceiver + TinySender +### [SimpleReceiverForHashCodes](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleReceiverForHashCodes/SimpleReceiverForHashCodes.ino) +The **SimpleReceiverForHashCodes** uses only the hash decoder. +It converts all IR frames longer than 6 to a 32 bit hash code, thus enabling receiving of unknown protocols.
+See: http://www.righto.com/2010/01/using-arbitrary-remotes-with-arduino.html + +### [TinyReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/TinyReceiver/TinyReceiver.ino) + [TinySender](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/TinySender/TinySender.ino) If **code size** or **timer usage** matters, look at these examples.
-The **[TinyReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/TinyReceiver/TinyReceiver.ino)** example uses the **TinyIRReceiver** library which can **only receive NEC, ONKYO and FAST protocols, but does not require any timer**. They use pin change interrupt for on the fly decoding, which is the reason for the restricted protocol choice.
+The **TinyReceiver** example uses the **TinyIRReceiver** library +which can **only receive NEC, Extended NEC, ONKYO and FAST protocols, but does not require any timer**. +They use pin change interrupt for on the fly decoding, which is the reason for the restricted protocol choice.
TinyReceiver can be tested online with [WOKWI](https://wokwi.com/arduino/projects/339264565653013075). -The **[TinySender](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/TinySender/TinySender.ino)** example uses the **TinyIRSender** library which can **only send NEC, ONKYO and FAST protocols**.
-It sends NEC protocol codes in standard format with 8 bit address and 8 bit command as in SimpleSender example. +The **TinySender** example uses the **TinyIRSender** library which can **only send NEC, ONKYO and FAST protocols**.
+It sends NEC protocol codes in standard format with 8 bit address and 8 bit command as in SimpleSender example. It has options to send using Extended NEC, ONKYO and FAST protocols. Saves 780 bytes program memory and 26 bytes RAM compared to SimpleSender, which does the same, but uses the IRRemote library (and is therefore much more flexible). -#### SmallReceiver +### [SmallReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino) If the protocol is not NEC and code size matters, look at this [example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SmallReceiver/SmallReceiver.ino).
-#### ReceiveDemo + AllProtocolsOnLCD -[ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino) receives all protocols and **generates a beep with the Arduino tone() function** on each packet received.
+### [ReceiveDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino) + [AllProtocolsOnLCD](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino) +ReceiveDemo receives all protocols and **generates a beep with the Arduino tone() function** on each packet received.
Long press of one IR button (receiving of multiple repeats for one command) is detected.
-[AllProtocolsOnLCD](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino) additionally **displays the short result on a 1602 LCD**. The LCD can be connected parallel or serial (I2C).
+AllProtocolsOnLCD additionally **displays the short result on a 1602 LCD**. +The LCD can be connected parallel or serial (I2C).
By connecting debug pin to ground, you can force printing of the raw values for each frame. The pin number of the debug pin is printed during setup, because it depends on board and LCD connection type.
This example also serves as an **example how to use IRremote and tone() together**. -#### ReceiveDump -Receives all protocols and dumps the received signal in different flavors including Pronto format. Since the printing takes much time, repeat signals may be skipped or interpreted as UNKNOWN. +#### [ReceiveDump](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDump/ReceiveDump.ino) +Receives all protocols and dumps the received signal in different flavors including **Pronto format**.
+Since the printing takes much time, repeat signals may be skipped or interpreted as UNKNOWN. -#### SendDemo +#### [SendDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendDemo/SendDemo.ino) Sends all available protocols at least once. -#### SendAndReceive +#### [MultipleSendPins](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/MultipleSendPins/MultipleSendPins.ino) +Demonstrates sending IR codes toggling between 2 **different send pins**. + +#### [SendAndReceive](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendAndReceive/SendAndReceive.ino) Demonstrates **receiving while sending**. -#### ReceiveAndSend -Record and **play back last received IR signal** at button press. IR frames of known protocols are sent by the approriate protocol encoder. `UNKNOWN` protocol frames are stored as raw data and sent with `sendRaw()`. +#### [ReceiveAndSend](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveAndSend/ReceiveAndSend.ino) +Record and **play back last received IR signal** at button press. IR frames of known protocols are sent by the appropriate protocol encoder. +`UNKNOWN` protocol frames are stored as raw data and sent with `sendRaw()`. -#### ReceiveAndSendDistanceWidth +#### [ReceiveAndSendDistanceWidth](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino) Try to decode each IR frame with the *universal* **DistanceWidth decoder**, store the data and send it on button press with `sendPulseDistanceWidthFromArray()`.
+If RAM is not more than 2k, the decoder only accepts mark or space durations up to 2500 microseconds to save RAM space, otherwise it accepts durations up to 10 ms.
Storing data for distance width protocol requires 17 bytes. The ReceiveAndSend example requires 16 bytes for known protocol data and 37 bytes for raw data of e.g.NEC protocol. -#### ReceiveOneAndSendMultiple +#### [ReceiveOneAndSendMultiple](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveOneAndSendMultiple/ReceiveOneAndSendMultiple.ino) Serves as a IR **remote macro expander**. Receives Samsung32 protocol and on receiving a specified input frame, it sends multiple Samsung32 frames with appropriate delays in between. This serves as a **Netflix-key emulation** for my old Samsung H5273 TV. -#### IRDispatcherDemo -Framework for **calling different functions of your program** for different IR codes. +#### [IRDispatcherDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRDispatcherDemo/IRDispatcherDemo.ino) +**Calling different functions** of your program for different IR codes. -#### IRrelay +#### [ControlRelay](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ControlRelay/ControlRelay.ino) **Control a relay** (connected to an output pin) with your remote. -#### IRremoteExtensionTest -[Example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino) for a user defined class, which itself uses the IRrecv class from IRremote. +#### [IRremoteExtensionTest](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino) +Example for a user defined class, which itself uses the IRrecv class from IRremote. -#### SendLGAirConditionerDemo -[Example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino) for sending LG air conditioner IR codes controlled by Serial input.
+#### [SendLGAirConditionerDemo](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino) +Example for sending LG air conditioner IR codes controlled by Serial input.
By just using the function `bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter)` you can control the air conditioner by any other command source.
The file *acLG.h* contains the command documentation of the LG air conditioner IR protocol. Based on reverse engineering of the LG AKB73315611 remote. ![LG AKB73315611 remote](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/LG_AKB73315611.jpg)
IReceiverTimingAnalysis can be tested online with [WOKWI](https://wokwi.com/projects/299033930562011656) Click on the receiver while simulation is running to specify individual IR codes. -#### ReceiverTimingAnalysis -This [example](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino) analyzes the signal delivered by your IR receiver module. +#### [ReceiveAndSendHob2Hood](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveAndSendHob2Hood/ReceiveAndSendHob2Hood.ino) +Example for receiving and sending AEG / Elektrolux Hob2Hood protocol.
+ +#### [ReceiverTimingAnalysis](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino) +This example analyzes the signal delivered by your IR receiver module. Values can be used to determine the stability of the received signal as well as a hint for determining the protocol.
It also computes the `MARK_EXCESS_MICROS` value, which is the extension of the mark (pulse) duration introduced by the IR receiver module.
It can be tested online with [WOKWI](https://wokwi.com/arduino/projects/299033930562011656). Click on the receiver while simulation is running to specify individual NEC IR codes. -#### UnitTest +#### [UnitTest](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/UnitTest/UnitTest.ino) ReceiveDemo + SendDemo in one program. Demonstrates **receiving while sending**. +Here you see the delay of the receiver output (blue) from the IR diode input (yellow). +![Delay](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/IR_UnitTest_delay.bmp) # WOKWI online examples - [Simple receiver](https://wokwi.com/projects/338611596994544210) @@ -651,57 +852,88 @@ ReceiveDemo + SendDemo in one program. Demonstrates **receiving while sending**. - [ReceiverTimingAnalysis](https://wokwi.com/projects/299033930562011656) - [Receiver with LCD output and switch statement](https://wokwi.com/projects/298934082074575369) +# IR control of a robot car +This [example](https://github.com/ArminJo/PWMMotorControl?tab=readme-ov-file#basicircontrol) of the **Arduino PWMMotorControl library** controls the basic functions of a robot car using the IRremote library.
+It controls 2 PWM motor channels, 2 motors at each channel.
+[Here](https://www.instructables.com/Arduino-4WD-Car-Assembly-and-Code-With-Optional-In/) you can find the instructable for car assembly and code.
+ +IR_RobotCar with TL1838 IR receiver plugged into expansion board.
+![IR_RobotCar](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/IR_RobotCar.jpg) +
# Issues and discussions - Do not open an issue without first testing some of the examples! - If you have a problem, please post the MCVE (Minimal Complete Verifiable Example) showing this problem. My experience is, that most of the times you will find the problem while creating this MCVE :smile:. -- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); **it helps us help you when we can read your code!** +- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); **it helps us to help you when we can read your code!**
-# Compile options / macros for this library +# Compile options / macros for IRremote To customize the library to different requirements, there are some compile options / macros available.
These macros must be defined in your program **before** the line `#include ` to take effect.
Modify them by enabling / disabling them, or change the values if applicable. | Name | Default value | Description | -|:---|---:|----| -| `RAW_BUFFER_LENGTH` | 100 | Buffer size of raw input buffer. Must be even! 100 is sufficient for *regular* protocols of up to 48 bits, but for most air conditioner protocols a value of up to 750 is required. Use the ReceiveDump example to find smallest value for your requirements. | -| `EXCLUDE_UNIVERSAL_PROTOCOLS` | disabled | Excludes the universal decoder for pulse distance protocols and decodeHash (special decoder for all protocols) from `decode()`. Saves up to 1000 bytes program memory. | -| `DECODE_` | all | Selection of individual protocol(s) to be decoded. You can specify multiple protocols. See [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.hpp#L98-L121) | -| `DECODE_STRICT_CHECKS` | disabled | Check for additional characteristics of protocol timing like length of mark for a constant mark protocol, where space length determines the bit value. Requires up to 194 additional bytes of program memory. | +|-|-:|-| +| `RAW_BUFFER_LENGTH` | 200 | Buffer size of raw input uint16_t buffer. Must be even! If it is too small, overflow flag will be set. 100 is sufficient for *regular* protocols of up to 48 bits, but for most air conditioner protocols a value of up to 750 is required. Use the ReceiveDump example to find smallest value for your requirements. A value of 200 requires 200 bytes RAM. | +| `USE_16_BIT_TIMING_BUFFER` | disabled | Use a 16-bit buffer if raw timing capture is required and exact values above 12750 us must be preserved. This doubles the RAM size of the buffer. | +| `EXCLUDE_UNIVERSAL_PROTOCOLS` | disabled | Excludes the universal decoder for pulse distance width protocols and decodeHash (special decoder for all protocols) from `decode()`. Saves up to 1000 bytes program memory. | +| `EXCLUDE_EXOTIC_PROTOCOLS` | disabled | Excludes BANG_OLUFSEN, BOSEWAVE, WHYNTER, FAST LEGO_PF, and OpenLASIR from `decode()` and from sending with `IrSender.write()`. Saves up to 650 bytes program memory. | +| `DECODE_` | all | Selection of individual protocol(s) to be decoded. You can specify multiple protocols. See [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.hpp#L98-L121) | +| `USE_THRESHOLD_DECODER` | disabled | If enabled, may give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses and forces value of MARK_EXCESS_MICROS to 0 to save program memory. Requires up to additional 120 bytes program memory. | +| `USE_STRICT_DECODER` | disabled | Check for all 4 one and zero protocol timings. Only sensible for development or very exotic requirements. Requires up to 300 additional bytes of program memory. | | `IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK` | disabled | Saves up to 60 bytes of program memory and 2 bytes RAM. | -| `MARK_EXCESS_MICROS` | 20 | MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules. | -| `RECORD_GAP_MICROS` | 5000 | Minimum gap between IR transmissions, to detect the end of a protocol.
Must be greater than any space of a protocol e.g. the NEC header space of 4500 µs.
Must be smaller than any gap between a command and a repeat; e.g. the retransmission gap for Sony is around 24 ms.
Keep in mind, that this is the delay between the end of the received command and the start of decoding. | -| `IR_INPUT_IS_ACTIVE_HIGH` | disabled | Enable it if you use a RF receiver, which has an active HIGH output signal. | -| `IR_SEND_PIN` | disabled | If specified (as constant), it reduces program size and improves send timing for AVR. If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must not use / disable this macro in your source. | -| `SEND_PWM_BY_TIMER` | disabled | Disables carrier PWM generation in software and use hardware PWM (by timer). Has the advantage of more exact PWM generation, especially the duty cycle (which is not very relevant for most IR receiver circuits), and the disadvantage of using a hardware timer, which in turn is not available for other libraries and to fix the send pin (but not the receive pin) at the [dedicated timer output pin(s)](https://github.com/Arduino-IRremote/Arduino-IRremote#timer-and-pin-usage). Is enabled for ESP32 and RP2040 in all examples, since they support PWM gereration for each pin without using a shared resource (timer). | -| `USE_NO_SEND_PWM` | disabled | Uses no carrier PWM, just simulate an **active low** receiver signal. Used for transferring signal by cable instead of IR. Overrides `SEND_PWM_BY_TIMER` definition. | -| `IR_SEND_DUTY_CYCLE_PERCENT` | 30 | Duty cycle of IR send signal. | -| `USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN` | disabled | Uses or simulates open drain output mode at send pin. **Attention, active state of open drain is LOW**, so connect the send LED between positive supply and send pin! | -| `DISABLE_CODE_FOR_RECEIVER` | disabled | Saves up to 450 bytes program memory and 269 bytes RAM if receiving functionality is not required. | -| `EXCLUDE_EXOTIC_PROTOCOLS` | disabled | Excludes BANG_OLUFSEN, BOSEWAVE, WHYNTER, FAST and LEGO_PF from `decode()` and from sending with `IrSender.write()`. Saves up to 650 bytes program memory. | -| `FEEDBACK_LED_IS_ACTIVE_LOW` | disabled | Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low. | -| `NO_LED_FEEDBACK_CODE` | disabled | Disables the LED feedback code for send and receive. Saves around 100 bytes program memory for receiving, around 500 bytes for sending and halving the receiver ISR (Interrupt Service Routine) processing time. | -| `MICROS_PER_TICK` | 50 | Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 µs at 38 kHz. | -| `TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING` | 25 | Relative tolerance (in percent) for matchTicks(), matchMark() and matchSpace() functions used for protocol decoding. | +| `MARK_EXCESS_MICROS` | 20 | MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules. Is set to 20 if `DO_NOT_USE_THRESHOLD_DECODER` is enabled. | +| `RECORD_GAP_MICROS` | 5000 | Minimum gap between IR transmissions, to detect the end of a protocol.
Must be greater than any space of a protocol e.g. the NEC header space of 4500 µs.
Must be smaller than any gap between a command and a repeat; e.g. the retransmission gap for Sony is around 24 ms.
Keep in mind, that this is the delay between the end of the received command and the start of decoding. | +| `DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE` | 50 if RAM <= 2k, else 200 | A value of 200 allows to decode mark or space durations up to 10 ms. | +| `SHOW_DISTANCE_WIDTH_DECODER_ERRORS` | disabled | Prints the reason which prevents data to be decoded as distance width data. | +| `IR_INPUT_IS_ACTIVE_HIGH` | disabled | Enable it if you use a RF receiver, which has an active HIGH output signal. | +| `IR_SEND_PIN` | disabled | If specified, it reduces program size and improves send timing for AVR. If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must not use / disable this macro in your source. | +| `SEND_PWM_BY_TIMER` | disabled | Disables carrier PWM generation in software and use hardware PWM (by timer). Has the **advantage of more exact PWM generation**, especially the duty cycle (which is not very relevant for most IR receiver circuits), and the **disadvantage of using a hardware timer**, which in turn is not available for other libraries and to fix the send pin (but not the receive pin) at the [dedicated timer output pin(s)](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#timer-and-pin-usage). Is enabled for ESP32 and RP2040 in all examples, since they support PWM generation for each pin without using a shared resource (timer). | +| `IR_SEND_DUTY_CYCLE_PERCENT` | 30 | Duty cycle of IR send signal. | +| `USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN` | disabled | Reverses the polarity of space level for PWM at the send pin, i.e. space is high. Can be used to connect IR LED between VCC and the send pin. It is like open drain but with electrical active high in its logical inactive state. | +| `USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN` | disabled | Uses or simulates open drain output mode for PWM at send pin. **Attention, active state of open drain is LOW**, so connect the send LED between positive supply and send pin! | +| `USE_NO_SEND_PWM` | disabled | Uses no carrier PWM, just simulate an **active low** receiver signal. Used for transferring signal by cable instead of IR. Overrides `SEND_PWM_BY_TIMER` definition. | +| `USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM` | disabled | Only evaluated if `USE_NO_SEND_PWM` is enabled. Simulate an **active high** receiver signal instead of an active low signal. | +| `DISABLE_CODE_FOR_RECEIVER` | disabled | Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. | +| `FEEDBACK_LED_IS_ACTIVE_LOW` | disabled | Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low. | +| `NO_LED_FEEDBACK_CODE` | disabled | Disables the LED feedback code for send and receive. Saves around 100 bytes program memory for receiving, around 500 bytes for sending and halving the receiver ISR (Interrupt Service Routine) processing time. | +| `NO_LED_RECEIVE_FEEDBACK_CODE` | disabled | Disables the LED feedback code for receive. Saves around 100 bytes program memory for receiving and halving the receiver ISR (Interrupt Service Routine) processing time. | +| `NO_LED_SEND_FEEDBACK_CODE` | disabled | Disables the LED feedback code for send. Saves around 322 bytes for sending. | +| `MICROS_PER_TICK` | 50 | Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 µs at 38 kHz. | +| `TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT` | 25 | Relative tolerance for matchTicks(), matchMark() and matchSpace() functions used for protocol decoding. | | `DEBUG` | disabled | Enables lots of lovely debug output. | | `IR_USE_AVR_TIMER*` | | Selection of timer to be used for generating IR receiving sample interval. | -These next macros for **TinyIRReceiver** must be defined in your program before the line `#include ` to take effect. +# Macros for TinyIR +These macros must be defined in your program before the line `#include ` to take effect. | Name | Default value | Description | -|:---|---:|----| -| `IR_RECEIVE_PIN` | 2 | The pin number for TinyIRReceiver IR input, which gets compiled in. | +|-|-:|-| +| `IR_RECEIVE_PIN` | 2 | The pin number for TinyIRReceiver IR input, which gets compiled in. Not used in IRremote. | | `IR_FEEDBACK_LED_PIN` | `LED_BUILTIN` | The pin number for TinyIRReceiver feedback LED, which gets compiled in. | -| `NO_LED_FEEDBACK_CODE` | disabled | Disables the feedback LED function. Saves 14 bytes program memory. | -| `DISABLE_PARITY_CHECKS` | disabled | Disables the addres and command parity checks. Saves 48 bytes program memory. | -| `USE_ONKYO_PROTOCOL` | disabled | Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. | +| `NO_LED_FEEDBACK_CODE` | disabled | Disables the feedback LED code for send and receive. Saves 14 bytes program memory. | +| `NO_LED_RECEIVE_FEEDBACK_CODE` | disabled | Disables the LED feedback code for receive. | +| `NO_LED_SEND_FEEDBACK_CODE` | disabled | Disables the LED feedback code for send. | +| `DISABLE_PARITY_CHECKS` | disabled | Disables the address and command parity checks. Saves 48 bytes program memory. | +| `USE_EXTENDED_NEC_PROTOCOL` | disabled | Like NEC, but take the 16 bit address as one 16 bit value and not as 8 bit normal and 8 bit inverted value. || `USE_ONKYO_PROTOCOL` | disabled | Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. | | `USE_FAST_PROTOCOL` | disabled | Use FAST protocol (no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command) instead of NEC. | | `ENABLE_NEC2_REPEATS` | disabled | Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. | +| `USE_CALLBACK_FOR_TINY_RECEIVER` | disabled | Call the user provided function `void handleReceivedTinyIRData()` each time a frame or repeat is received. | + +
-The next macro for **IRCommandDispatcher** must be defined in your program before the line `#include ` to take effect. -| `IR_COMMAND_HAS_MORE_THAN_8_BIT` | disabled | Enables mapping and dispatching of IR commands consisting of more than 8 bits. Saves up to 160 bytes program memory and 4 bytes RAM + 1 byte RAM per mapping entry. | +# Macros for IRCommandDispatcher +These macros must be defined in your program before the line `#include ` to take effect. +| Name | Default value | Description | +|-|-:|-| +| `USE_TINY_IR_RECEIVER` | disabled | Use [TinyIRReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tinyreceiver--tinysender) for receiving IR codes. | +| `IR_COMMAND_HAS_MORE_THAN_8_BIT` | disabled | Enables mapping and dispatching of IR commands consisting of more than 8 bits. Saves up to 160 bytes program memory and 5 bytes RAM + 1 byte RAM per mapping entry. | +| `IR_ADDRESS` | empty | If set, compare the address returned by the IR library with this value before executing a command. | +| `DISPATCHER_BUZZER_FEEDBACK_PIN` | | If `USE_TINY_IR_RECEIVER` is enabled, the pin to be used for the optional 50 ms buzzer feedback before executing a command. Other IR libraries than Tiny are not compatible with tone() command. | +| `USE_DISPATCHER_COMMAND_STRINGS` | disabled | Enables printing of command strings. Requires additional 2 bytes RAM for each command mapping. Requires program memory for strings, but saves snprintf() code (1.5k) if INFO or DEBUG is activated, which has no effect if snprintf() is also used in other parts of your program / libraries. | + +
### Changing include (*.h) files with Arduino IDE First, use *Sketch > Show Sketch Folder (Ctrl+K)*.
@@ -721,9 +953,14 @@ If you are using [Sloeber](https://eclipse.baeyens.it) as your IDE, you can easi # Supported Boards **Issues and discussions with the content "Is it possible to use this library with the ATTinyXYZ? / board XYZ" without any reasonable explanations will be immediately closed without further notice.**
+For **ESP8266/ESP32**, [the IRremoteESP8266 library](https://github.com/crankyoldgit/IRremoteESP8266) supports an [impressive set of protocols and a lot of air conditioners](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md).
+**ATtiny CPU's are tested with the [Arduino library ATtinySerialOut](https://github.com/ArminJo/ATtinySerialOut) library**.

-ATtiny and Digispark boards are only tested with the recommended [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) using `New Style` pin mapping for the pro board. +Digispark boards are tested only with [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore) using the `New Style` pin mapping for the Digispark Pro board.
+**ATtiny boards** are tested only with **[ATTinyCore](https://github.com/SpenceKonde/ATTinyCore#supported-devices) or [megaTinyCore](https://github.com/SpenceKonde/megaTinyCore)**. + - Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc. +- Arduino Uno R4, but not yet tested, because of lack of a R4 board. **Sending does not work** on the `arduino:renesas_uno:unor4wifi`. - Teensy 1.0 / 1.0++ / 2.0 / 2++ / 3.0 / 3.1 / 3.2 / Teensy-LC - but [limited support](https://forum.pjrc.com/threads/65912-Enable-Continuous-Integration-with-arduino-cli-for-3-party-libraries); Credits: PaulStoffregen (Teensy Team) - Sanguino - ATmega8, 48, 88, 168, 328 @@ -732,15 +969,15 @@ ATtiny and Digispark boards are only tested with the recommended [ATTinyCore](ht - ATmega4809 (Nano every) - ATtiny3217 (Tiny Core 32 Dev Board) - ATtiny84, 85, 167 (Digispark + Digispark Pro) -- SAMD21 (Zero, MKR*, **but not SAMD51 and not DUE, the latter is SAM architecture**) +- SAMD (Zero, MKR*, **but not DUE, the latter is SAM architecture**) - ESP8266 -- ESP32 (ESP32 C3 since board package 2.0.2 from Espressif) +- ESP32, ESP32-C3 since board package 2.0.2 from Espressif. Other CPUs are not tested! SP32-S3 is not supported (yet). - Sparkfun Pro Micro - Nano Every, Uno WiFi Rev2, nRF5 BBC MicroBit, Nano33_BLE - BluePill with STM32 - RP2040 based boards (Raspberry Pi Pico, Nano RP2040 Connect etc.) +- Indian VEGA RISC-V boards - not tested -For ESP8266/ESP32, [this library](https://github.com/crankyoldgit/IRremoteESP8266) supports an [impressive set of protocols and a lot of air conditioners](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md) We are open to suggestions for adding support to new boards, however we highly recommend you contact your supplier first and ask them to provide support from their side.
If you can provide **examples of using a periodic timer for interrupts** for the new board, and the board name for selection in the Arduino IDE, then you have way better chances to get your board supported by IRremote. @@ -749,44 +986,51 @@ If you can provide **examples of using a periodic timer for interrupts** for the # Timer and pin usage The **receiver sample interval of 50 µs is generated by a timer**. On many boards this must be a hardware timer. On some boards where a software timer is available, the software timer is used.
-Every pin can be used for receiving. +On **ESP8266** `timer1` is used for receive interrupts, which makes it incompatible to the Servo and other libraries.
+On **ESP32** `hw_timer_t` is used for receive interrupts. + +Every pin can be used for receiving.
+If software PWM is selected, which is default, every pin can also be used for sending. Sending with software PWM does not require a timer! The TinyReceiver example uses the **TinyReceiver** library, which can **only receive NEC codes, but does not require any timer** and runs even on a 1 MHz ATtiny85. -The code for the timer and the **timer selection** is located in [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp). It can be adjusted here.
+The code for the timer and the **timer selection** is located in [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp). The selected timer can be adjusted here. + **Be aware that the hardware timer used for receiving should not be used for analogWrite()!**.
-| Board/CPU | Receive
& PWM Timers| Hardware-PWM Pin | analogWrite()
pins occupied by timer | -|--------------------------------------------------------------------------|-------------------|---------------------|-----------------------| -| [ATtiny84](https://github.com/SpenceKonde/ATTinyCore) | **1** | **6** | -| [ATtiny85 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore) | **0**, 1 | **0**, 4 | **0**, 1 & 4 | -| [ATtiny88 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore) | **1** | **PB1 / 8** | **PB1 / 8 & PB2 / 9** | -| [ATtiny167 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore) | **1** | **9**, 8 - 15 | **8 - 15** | -| [ATtiny1604](https://github.com/SpenceKonde/megaTinyCore) | **TCB0** | **PA05** | -| [ATtiny1614, ATtiny816](https://github.com/SpenceKonde/megaTinyCore) | **TCA0** | **PA3** | -| [ATtiny3217](https://github.com/SpenceKonde/megaTinyCore) | **TCA0**, TCD | % | -| [ATmega8](https://github.com/MCUdude/MiniCore) | **1** | **9** | +| Board/CPU | Receive
& send PWM Timer
Default timer is **bold** | Hardware-Send-PWM Pin | analogWrite()
pins occupied by timer | +|-|-|-|-| +| [ATtiny84](https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/extras/ATtiny_x4.md) | **1** | **6** | | +| [ATtiny85 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/extras/ATtiny_x5.md) | **0**, 1 | **0**, 4 | **0**, 1 & 4 | +| [ATtiny88 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/extras/ATtiny_x8.md) | **1** | **PB1 / 8** | **PB1 / 8 & PB2 / 9** | +| [ATtiny167 > 4 MHz](https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/extras/ATtiny_x7.md) | **1** | **9**, 8 - 15 | **8 - 15** | +| [ATtiny1604](https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x04.md) | **TCB0** | **PA05** | +| [ATtiny1614, ATtiny816](https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x14.md) | **TCA0** | **PA3** | +| [ATtiny1624](https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x24.md) | **TCA0** | **PA3** | +| [ATtiny3217](https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x17.md) | **TCA0**, TCD | % | +| [ATmega8](https://github.com/MCUdude/MiniCore#supported-microcontrollers) | **1** | **9** | +| [ATmega1284](https://github.com/MCUdude/MightyCore#supported-microcontrollers) | 1, **2**, 3 | 13, 14, 6 | +| [ATmega164, ATmega324, ATmega644](https://github.com/MCUdude/MightyCore#supported-microcontrollers) | 1, **2** | 13, **14** | +| [ATmega8535 ATmega16, ATmega32](https://github.com/MCUdude/MightyCore#supported-microcontrollers) | **1** | **13** | +| [ATmega64, ATmega128, ATmega1281, ATmega2561](https://github.com/MCUdude/MegaCore#supported-microcontrollers) | **1** | **13** | +| [ATmega8515, ATmega162](https://github.com/MCUdude/MajorCore#pinout ) | **1** | **13** | | ATmega168, **ATmega328** | 1, **2** | 9, **3** | 9 & 10, **3 & 11** | -| [ATmega1284](https://github.com/MCUdude/MightyCore) | 1, **2**, 3 | 13, 14, 6 | -| [ATmega164, ATmega324, ATmega644](https://github.com/MCUdude/MightyCore) | 1, **2** | 13, **14** | -| [ATmega8535 ATmega16, ATmega32](https://github.com/MCUdude/MightyCore) | **1** | **13** | -| [ATmega64, ATmega128, ATmega1281, ATmega2561](https://github.com/MCUdude/MegaCore) | **1** | **13** | -| [ATmega8515, ATmega162](https://github.com/MCUdude/MajorCore) | **1** | **13** | -| ATmega1280, ATmega2560 | 1, **2**, 3, 4, 5 | 5, 6, **9**, 11, 46 | -| ATmega4809 | **TCB0** | **A4** | -| Leonardo (Atmega32u4) | 1, 3, **4_HS** | 5, **9**, 13 | -| Zero (SAMD) | **TC3** | \*, **9** | -| [ESP32](http://esp32.net/) | **Ledc chan. 0** | All pins | -| [Sparkfun Pro Micro](https://www.sparkfun.com/products/12640) | 1, **3** | **5**, 9 | +| ATmega1280, **ATmega2560** | 1, **2**, 3, 4, 5 | 5, 6, **9**, 11, 46 | 5, 6, **9**, 11, 46 | +| ATmega4809 | **TCB0** | **A4** | | +| Leonardo (Atmega32u4) | 1, 3, **4_HS** | 5, **9**, 13 | 5, **9**, 13 | +| Zero (SAMD) | **TC3** | \*, **9** | | +| [ESP8266](http://esp8266.net/) | **timer1** | % | | +| [ESP32](http://esp32.net/) | **hw_timer_t**
**Ledc channel 0** | All pins | | +| [Sparkfun Pro Micro](https://www.sparkfun.com/products/12640) | 1, **3** | **5**, 9 | | | [Teensy 1.0](https://www.pjrc.com/teensy/pinout.html) | **1** | **17** | 15, 18 | | [Teensy 2.0](https://www.pjrc.com/teensy/pinout.html) | 1, 3, **4_HS** | 9, **10**, 14 | 12 | | [Teensy++ 1.0 / 2.0](https://www.pjrc.com/teensy/pinout.html) | 1, **2**, 3 | **1**, 16, 25 | 0 | | [Teensy-LC](https://www.pjrc.com/teensy/pinout.html) | **TPM1** | **16** | 17 | -| [Teensy 3.0 - 3.6](https://www.pjrc.com/teensy/pinout.html) | **CMT** | **5** | +| [Teensy 3.0 - 3.6](https://www.pjrc.com/teensy/pinout.html) | **CMT** | **5** | | | [Teensy 4.0 - 4.1](https://www.pjrc.com/teensy/pinout.html) | **FlexPWM1.3** | **8** | 7, 25 | -| [BluePill / STM32F103C8T6](https://github.com/stm32duino/Arduino_Core_STM32) | **3** | % | **PA6 & PA7 & PB0 & PB1** | +| [BluePill / STM32F103C8T6](https://github.com/stm32duino/Arduino_Core_STM32) | **3** | % | **PA6 & PA7 & PB0 & PB1** | | [BluePill / STM32F103C8T6](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill) | **TIM4** | % | **PB6 & PB7 & PB8 & PB9** | -| [RP2040 / Pi Pico](https://github.com/earlephilhower/arduino-pico) | [default alarm pool](https://raspberrypi.github.io/pico-sdk-doxygen/group__repeating__timer.html) | All pins | No pin | +| [RP2040 / Pi Pico](https://github.com/earlephilhower/arduino-pico) | [default alarm pool](https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#group_alarm_1ga40b4a03bf9e967d4e7170d20c5c9fb15) | All pins | No pin | | [RP2040 / Mbed based](https://github.com/arduino/ArduinoCore-mbed) | Mbed Ticker | All pins | No pin | ### No timer required for sending @@ -803,8 +1047,11 @@ Since the Arduino `micros()` function has a resolution of 4 µs at 16 MHz, ## Incompatibilities to other libraries and Arduino commands like tone() and analogWrite() If you use a library which requires the same timer as IRremote, you have a problem, since **the timer resource cannot be shared simultaneously** by both libraries. +### Use NEC protocol and TinyIRReceiver +[TinyIRReceiver](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#tiny-nec-receiver-and-sender) does not require a timer, it relies on interrupts, thus avoiding any timer resource problems. + ### Change timer -The best approach is to change the timer used for IRremote, which can be accomplished by specifying the timer before `#include `.
+The best approach is to **change the timer** used for IRremote, which can be accomplished by specifying the timer before `#include `.
The timer specifications available for your board can be found in [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp).
```c++ @@ -821,23 +1068,29 @@ The timer specifications available for your board can be found in [private/IRTim Here you see the Arduino Mega board and the available specifications are `IR_USE_AVR_TIMER[1,2,3,4,5]`.
You **just have to include a line** e.g. `#define IR_USE_AVR_TIMER3` before `#include ` to enable timer 3. -But be aware that the new timer in turn might be incompatible with other libraries or commands.
-For other boards/platforms you must look for the appropriate section guarded by e.g. `#elif defined(ESP32)`. +But be aware that the new timer in turn might be again incompatible with other libraries or Arduino functions.
+For non AVR boards/platforms you must look for the appropriate section guarded by e.g. `#elif defined(ESP32)`. ### Stop and start timer Another approach can be to share the timer **sequentially** if their functionality is used only for a short period of time like for the **Arduino tone() command**. -An example can be seen [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/21b5747a58e9d47c9e3f1beb056d58c875a92b47/examples/ReceiveDemo/ReceiveDemo.ino#L159-L169), where the timer settings for IR receive are restored after the tone has stopped. -For this we must call `IrReceiver.start()` or better `IrReceiver.start(microsecondsOfToneDuration)`.
-This only works since each call to` tone()` completely initializes the timer 2 used by the `tone()` command. +An example can be seen [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/ReceiveDemo/ReceiveDemo.ino#L284-L298), where the IR timer is restarted after the tone has stopped. + +```c++ +IrReceiver.stopTimer(); // Stop timer consistently before calling tone() or other functions using the timer resource. +tone(TONE_PIN, 2200, 8); +delay(8); +IrReceiver.restartTimer(); // Restart IR timer after timer resource is no longer blocked. +``` +This works on AVR boards like Uno because each call to` tone()` completely initializes the timer 2 used by the `tone()` command. ## Hardware-PWM signal generation for sending If you define `SEND_PWM_BY_TIMER`, the send PWM signal is forced to be generated by a hardware timer on most platforms.
By default, the same timer as for the receiver is used.
Since each hardware timer has its dedicated output pin(s), you must change timer or timer sub-specifications to change PWM output pin. See [private/IRTimer.hpp](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/private/IRTimer.hpp)
-**Exeptions** are currently [ESP32, ARDUINO_ARCH_RP2040, PARTICLE and ARDUINO_ARCH_MBED](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/39bdf8d7bf5b90dc221f8ae9fb3efed9f0a8a1db/examples/SimpleSender/PinDefinitionsAndMore.h#L273), where **PWM generation does not require a timer**. +**Exceptions** are currently [ESP32, ARDUINO_ARCH_RP2040, PARTICLE and ARDUINO_ARCH_MBED](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/SimpleSender/PinDefinitionsAndMore.h#L341), where **PWM generation does not require a timer**. ## Why do we use 30% duty cycle for sending -We do it according to the statement in the [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf): +We [do it](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRSend.hpp#L1194) according to the statement in the [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf): - Carrier duty cycle 50 %, peak current of emitter IF = 200 mA, the resulting transmission distance is 25 m. - Carrier duty cycle 10 %, peak current of emitter IF = 800 mA, the resulting transmission distance is 29 m. - Factor 1.16 The reason is, that it is not the pure energy of the fundamental which is responsible for the receiver to detect a signal. @@ -848,11 +1101,14 @@ Due to automatic gain control and other bias effects, high intensity of the 38 k # How we decode signals The IR signal is sampled at a **50 µs interval**. For a constant 525 µs pulse or pause we therefore get 10 or 11 samples, each with 50% probability.
And believe me, if you send a 525 µs signal, your receiver will output something between around 400 and 700 µs!
-Therefore **we decode by default with a +/- 25% margin** using the formulas [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremoteInt.h#L376-L399).
-E.g. for the NEC protocol with its 560 µs unit length, we have TICKS_LOW = 8.358 and TICKS_HIGH = 15.0. This means, we accept any value between 8 ticks / 400 µs and 15 ticks / 750 µs (inclusive) as a mark or as a zero space. For a one space we have TICKS_LOW = 25.07 and TICKS_HIGH = 45.0.
-And since the receivers generated marks are longer or shorter than the spaces, we have introduced the [`MARK_EXCESS_MICROS` value]/https://github.com/Arduino-IRremote/Arduino-IRremote#protocolunknown) -to compensate for this receiver (and signal strength as well as ambient light dependent :disappointed: ) specific deviation.
-Welcome to the world of **real world signal processing**. +Therefore **we decode by default with a +/- 25% margin** using the formulas [here](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremoteInt.h#L469-L491).
+E.g. for the NEC protocol with its 560 µs unit length, we have TICKS_LOW = 8.358 and TICKS_HIGH = 15.0. +This means, we accept any value between 8 ticks / 400 µs and 15 ticks / 750 µs (inclusive) as a mark or as a zero space. +For a one space we have TICKS_LOW = 25.07 and TICKS_HIGH = 45.0.
+And since the receivers generated marks are longer or shorter than the spaces, +we have introduced the [`MARK_EXCESS_MICROS`](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#compile-options--macros-for-this-library) macro +to compensate for this receiver and signal strength as well as ambient light dependent :disappointed: specific deviation.
+**Welcome to the world of real world signal processing**.
@@ -866,16 +1122,16 @@ Created with sigrok PulseView with IR_NEC decoder by DjordjeMandic.

# Quick comparison of 5 Arduino IR receiving libraries -[Here](https://github.com/crankyoldgit/IRremoteESP8266) you find an **ESP8266/ESP32** version of IRremote with an **[impressive list of supported protocols](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md)**. - **This is a short comparison and may not be complete or correct.** -I created this comparison matrix for [myself](https://github.com/ArminJo) in order to choose a small IR lib for my project and to have a quick overview, when to choose which library.
-It is dated from **24.06.2022**. If you have complains about the data or request for extensions, please send a PM or open a discussion. +I created this comparison matrix for [myself](https://github.com/ArminJo) in order to choose a small IR library for my project and to have a quick overview, when to choose which library.
+It is dated from **24.06.2022** and updated 10/2023. If you have complains about the data or request for extensions, please send a PM or open a discussion. + +[Here](https://github.com/crankyoldgit/IRremoteESP8266) you find an **ESP8266/ESP32** version of IRremote with an **[impressive list of supported protocols](https://github.com/crankyoldgit/IRremoteESP8266/blob/master/SupportedProtocols.md)**. -| Subject | [IRMP](https://github.com/IRMP-org/IRMP) | [IRLremote](https://github.com/NicoHood/IRLremote) | [IRLib2](https://github.com/cyborg5/IRLib2)
**mostly unmaintained** | [IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote) | [Minimal NEC](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/TinyReceiver) | [IRsmallDecoder](https://github.com/LuisMiCa/IRsmallDecoder) -|---------|------|-----------|--------|----------|----------|----------| -| Number of protocols | **50** | Nec + Panasonic + Hash \* | 12 + Hash \* | 17 + PulseDistance + Hash \* | NEC | NEC + RC5 + Sony + Samsung | +| Subject | [IRMP](https://github.com/IRMP-org/IRMP) | [IRLremote](https://github.com/NicoHood/IRLremote) | [IRLib2](https://github.com/cyborg5/IRLib2)
**mostly unmaintained** | [IRremote](https://github.com/Arduino-IRremote/Arduino-IRremote) | [TinyIR](https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/TinyReceiver/TinyReceiver.ino) | [IRsmallDecoder](https://github.com/LuisMiCa/IRsmallDecoder) +|-|-|-|-|-|-|-| +| Number of protocols | **50** | Nec + Panasonic + Hash \* | 12 + Hash \* | 17 + PulseDistance + Hash \* | NEC + FAST | NEC + RC5 + Sony + Samsung | | Timing method receive | Timer2 or interrupt for pin 2 or 3 | **Interrupt** | Timer2 or interrupt for pin 2 or 3 | Timer2 | **Interrupt** | **Interrupt** | | Timing method send | PWM and timing with Timer2 interrupts | Timer2 interrupts | Timer2 and blocking wait | PWM with Timer2 and/or blocking wait with delay
Microseconds() | blocking wait with delay
Microseconds() | % | | Send pins| All | All | All ? | Timer dependent | All | % | @@ -887,30 +1143,37 @@ It is dated from **24.06.2022**. If you have complains about the data or request | FLASH usage (simple NEC example with 5 prints) | 1820
(4300 for 15 main / 8000 for all 40 protocols)
(+200 for callback)
(+80 for interrupt at pin 2+3)| 1270
(1400 for pin 2+3) | 4830 | 1770 | **900** | ?1100? | | RAM usage | 52
(73 / 100 for 15 (main) / 40 protocols) | 62 | 334 | 227 | **19** | 29 | | Supported platforms | **avr, megaavr, attiny, Digispark (Pro), esp8266, ESP32, STM32, SAMD 21, Apollo3
(plus arm and pic for non Arduino IDE)** | avr, esp8266 | avr, SAMD 21, SAMD 51 | avr, attiny, [esp8266](https://github.com/crankyoldgit/IRremoteESP8266), esp32, SAM, SAMD | **All platforms with attach
Interrupt()** | **All platforms with attach
Interrupt()** | -| Last library update | 6/2022 | 4/2018 | 3/2022 | 6/2022 | 6/2022 | 2/2022 | -| Remarks | Decodes 40 protocols concurrently.
39 Protocols to send.
Work in progress. | Only one protocol at a time. | Consists of 5 libraries. **Project containing bugs - 45 issues, no reaction for at least one year.** | Universal decoder and encoder.
Supports **Pronto** codes and sending of raw timing values. | Requires no timer. | Requires no timer. | +| Last library update | 5/2023 | 4/2018 | 11/2022 | 9/2023 | 5/2023 | 2/2022 | +| Remarks | Decodes 40 protocols concurrently.
39 Protocols to send.
Work in progress. | Only one protocol at a time. | Consists of 5 libraries. **Project containing bugs - 63 issues, 10 pull requests.* | Universal decoder and encoder.
Supports **Pronto** codes and sending of raw timing values. | Requires no timer. | Requires no timer. | \* The Hash protocol gives you a hash as code, which may be sufficient to distinguish your keys on the remote, but may not work with some protocols like Mitsubishi
+# [History](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/changelog.md) + # Useful links +- [Online NEC to Pronto converting tool](https://www.yamaha.com/ypab/irhex_converter.asp) - [List of public IR code databases](http://www.harctoolbox.org/IR-resources.html) - [LIRC database](http://lirc-remotes.sourceforge.net/remotes-table.html) - [IRMP list of IR protocols](https://www.mikrocontroller.net/articles/IRMP_-_english#IR_Protocols) - [IRDB database for IR codes](https://github.com/probonopd/irdb/tree/master/codes) - [IRP definition files for IR protocols](https://github.com/probonopd/MakeHex/tree/master/protocols) +- [Good introduction to IR remotes by DroneBot Workshop](https://dronebotworkshop.com/ir-remotes/) - [IR Remote Control Theory and some protocols (upper right hamburger icon)](https://www.sbprojects.net/knowledge/ir/) -- [Interpreting Decoded IR Signals (v2.45)](http://www.hifi-remote.com/johnsfine/DecodeIR.html) +- [Overviev of many protocols](https://www.hifi-remote.com/wiki/index.php/Category:DecodeIR) +- [Overviev of many protocols on one page (v2.45)](http://www.hifi-remote.com/johnsfine/DecodeIR.html) - ["Recording long Infrared Remote control signals with Arduino"](https://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino) - The original blog post of Ken Shirriff [A Multi-Protocol Infrared Remote Library for the Arduino](http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html) - [Vishay datasheet](https://www.vishay.com/docs/80069/circuit.pdf) +# [Contributors](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/Contributors.md) + # License Up to the version 2.7.0, the License is GPLv2. From the version 2.8.0, the license is the MIT license. # Copyright Initially coded 2009 Ken Shirriff http://www.righto.com
-Copyright (c) 2016-2017 Rafi Khan
-Copyright (c) 2020-2023 [Armin Joachimsmeyer](https://github.com/ArminJo) +Copyright (c) 2016-2017 Rafi Khan https://rafikhan.io
+Copyright (c) 2020-2025 [Armin Joachimsmeyer](https://github.com/ArminJo) diff --git a/changelog.md b/changelog.md index 748f7e2bf..c20528f30 100644 --- a/changelog.md +++ b/changelog.md @@ -2,19 +2,128 @@ The latest version may not be released! See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-IRremote/commits/master +# 4.7.1 +- Changed wrong &Serial to aSerial at 2 places. + +# 4.7.0 +- Added removed typedef `IRRawDataType` for backward compatibility. +- Modified and renamed function `setToggleBitValueForRC5AndRC6()` to `setNextToggleBitValueForRC5AndRC6()`. +- Fixed bug in sending RC6A. +- Updated `LG` protocol and removed useless `LG2` protocol. +- Added new functions `match*WithGreaterRange()`, e.g. `matchMarkWithGreaterRange()`. +- Improved B&O decoding using new functions. + +# 4.6.1 +- Fixed bug #1347 in RC5/RC6 autorepeat bit handling. Thanks to Craig Leres. +- Added function `setToggleBitValueForRC5AndRC6()`. + +# 4.6.0 +- Fixed missing ESP IRAM_ATTR for receiving interrupt. +- Changed `USE_DEFAULT_FEEDBACK_LED_PIN` from 0 to 0xFF, because megaTinyCore defines the not special pin PIN_PA4 as 0. +- Changed timer for **ATtiny16X4**. +- Fixed missing initialization with `pinMode()` for feedback LED. +- Fixed bitmask error in `sendBiphaseData()` when not sending start bit. +- Improved `decodeSamsung()`. +- `OpenLASIR` protocol added by [danielweidman](https://github.com/danielweidman). +- Added `DECODE_MARANTZ` and swapped parameter aMarantzExtension and aNumberOfRepeats of `sendMaranz()` to be consistent with other extensions. +- Improved biphase decoding. +- Improved debug output handling. +- Moved `IRCommandDispatcher` from demo to main library folder. +- Changed `IRRawDataType` to `IRDecodedRawDataType`. + +# 4.5.0 - does not work for ESP platform, because of missing ESP IRAM_ATTR for receiving interrupt. +- Added support for **multiple receiver instances**. +- irparams_struct `irparams` is now member of IRrecv. Thus removed `rawDataPt`r (pointer to irparams) from `IrReceiver.decodedIRData`. +- Removed return value for all `decodePulseDistanceWidthData()` decoding functions, which returned a constant true. +- Removed parameter `aEnableLEDFeedback` in function `IRsend::begin(bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin)` and `IRsend::begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin)`. +- **LED feedback is always enabled for sending**. It can only be disabled by using the macro `NO_LED_SEND_FEEDBACK_CODE`. +- Added output for UNKNOWN protocol to `printIRSendUsage()`. +- Added experimental `sendVelux()`. +- Added `sendMaranz()`. +- Fixed bug in ReceiveDemo.cpp if DEBUG_BUTTON_PIN is not defined. #1306. +- Fixed minor bugs in Denon decoder. +- Minor bug fixes for DEBUG. +- New handling of `MARK_EXCESS_MICROS` without strange rounding inconsistency. +- Added experimental threshold decoding. + +# 4.4.3 +- Added `USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN` to make the software aware of send LED connected between VCC and send pin. +- Fixed backward compatibility bug for `printIRResultShort(Print *aSerial, bool aPrintRepeatGap, bool aCheckForRecordGapsMicros)`. +- Minor improvements. + +# 4.4.2 +- Support for `SAMD51` timer3 if timer 5 is not available (Adafruit ItsyBitsy M4). +- attachInterrupt() on `SAMD` has a different semantic :-(. See: https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/. +- Fixed overflow handling. +- Improved repeat detection for `DistanceWidthProtocol`. +- Print of IR frame duration in `printIRResultShort()`; +- `PulseDistanceWidthProtocolConstants` now in PROGMEM, this saves 190 bytes RAM for unit test. +- Support for PROGMEM PulseDistanceWidthProtocol data. +- Support duplicated 8 bit address for `sendSamsungLG()`. + +# 4.4.1 +- Support for **ESP core 3.x** by akellai. +- `restartTimer()` now uses variable sMicrosAtLastStopTimer to keep track of uncounted ticks between stopTimer() and restartTimer(). +- **Removed functions** addTicksToInternalTickCounter() and addMicrosToInternalTickCounter(), which were added in 4.1.0. +- Version 2.2.0 of TinyIR with new `TinyReceiverDecode()` function to be used as **drop in for IrReceiver.decode()**. +- Support of `RC6A`. + +# 4.4.0 +- Using 8 bit raw timing buffer for all timings except frame gap (former rawbuf[0]). +- Renamed `decodedIRData.initialGap` to `decodedIRData.initialGapTicks`. +- `sendNEC()` and `sendNEC2()` now **accepts 16 bit command** to better map to **NECext protocol** found in IRDB databases. +- `ir_DistanceWidthProtocol()` now decodes up to 10 ms mark or spaces if RAM is bigger than 2 k. +- Improved sensitivity and decoding of `PULSE_DISTANCE` + `PULSE_WIDTH` protocols. +- Changed `TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING` to `TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT`. +- Improved examples AllProtocolsOnLCD, UnitTest and SimpleReceiver. +- New functions `decodePulseDistanceWidthData()` with 6 parameters and `decodePulseDistanceWidthDataStrict()` with 7 parameters. + +# 4.3.2 +- Added sendSonyMSB(unsigned long data, int nbits) as a clone of sendSony(unsigned long data, int nbits) to be more consistent. +- Added sendSamsungMSB(unsigned long data, int nbits) as a clone of sendSAMSUNG(unsigned long data, int nbits) to be more consistent. +- Added ESP32 core 3.x error message. + +# 4.3.1 + - Fixed overflow bug for rawlen > 254. + - Removed deprecated sendPulseDistance... functions with parameter aSendStopBit. + +# 4.3.0 +- Removed default value USE_DEFAULT_FEEDBACK_LED_PIN for last parameter of IRsend::begin(bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin). + Therefore IrSender.begin(DISABLE_LED_FEEDBACK) will not longer work! +- Added convenience function isIRReceiverAttachedForTinyReceiver(). +- Added Extended NEC Protocol macro to TinyIR by Buzzerb. +- Fixed sendSamsung() / sendSamsungLG() bug. +- Added functions stopTimer(), restartTimer() and restartTimerWithTicksToAdd(). +- Added rawlen and initialGap to IRData. +- Added ReceiveAndSendHobToHood example. +- Changed RECORD_GAP_MICROS default value from 5000 to 8000. + +# 4.2.1 +- Fix wrong type of tEnableLEDFeedback in IRSend.hpp and IRReceive.hpp. +- TinyReceiver 2.0 + - New TinyIRReceiverData which is filled with address, command and flags. + - Removed parameters address, command and flags from callback handleReceivedTinyIRData() and printTinyReceiverResultMinimal(). + - Callback function now only enabled if USE_CALLBACK_FOR_TINY_RECEIVER is activated. +- Fix changing IR_SEND_PIN dynamically for ESP32. +- Fix wrong type of tEnableLEDFeedback. +- Support for ESP32-C3. + # 4.2.0 - The old decode function is renamed to decode_old(decode_results *aResults). decode (decode_results *aResults) is only available in IRremote.h and prints a message. - Added DECODE_ONKYO, to force 16 bit command and data decoding. - Enable Bang&Olufsen 455 kHz if SEND_PWM_BY_TIMER is defined. - Fixed bug: TinyReceiver throwing ISR not in IRAM on ESP8266. - Usage of ATTinyCore pin numbering scheme e.g. PIN_PB2. +- Added ARDUINO_ARCH_NRF52 to support Seeed XIAO nRF52840 Sense. +- First untested support of Uno R4. +- Extracted version macros to IRVersion.h. ## 4.1.2 - Workaround for ESP32 RTOS delay() timing bug influencing the mark() function. ## 4.1.1 - SAMD51 use timer3 if timer5 not available. -- Disabled #define LOCAL_DEBUG in IRReceive.hpp, which was accidently enabled at 4.1.0. +- Disabled #define LOCAL_DEBUG in IRReceive.hpp, which was accidentally enabled at 4.1.0. ## 4.1.0 - Fixed bug in printing durations > 64535 in printIRResultRawFormatted(). @@ -41,7 +150,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I - Introduced common structure PulseDistanceWidthProtocolConstants. - Where possible, changed all send and decode functions to use PulseDistanceWidthProtocolConstants. - Improved MSB/LSB handling -- New convenience fuctions bitreverse32Bit() and bitreverseOneByte(). +- New convenience functions bitreverse32Bit() and bitreverseOneByte(). - Improved Magiquest protocol. - Fix for #1028 - Prevent long delay caused by overflow when frame duration < repeat period - Thanks to Stephen Humphries! - Support for ATtiny816 - Thanks to elockman. @@ -85,7 +194,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I - Improved pin mapping for TinyReceiver. ## 3.7.1 -- SendRaw now supports bufferlenght > 255. +- SendRaw now supports buffer length > 255. - Improved DistanceProtocol decoder output. - Fixed ESP32 send bug for 2.x ESP32 cores. @@ -253,7 +362,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I - Corrected keywords.txt. - BoseWave protocol added PR #690. - Formatting comply to the new stylesheet. -- Renamed "boarddefs.h" [ISSUE #375](https://github.com/Arduino-IRremote/Arduino-IRremote/issues/375). +- Renamed "boarddefs.h". - Renamed `SEND_PIN` to `IR_SEND_PIN`. - Renamed state macros. - Enabled `DUTY_CYCLE` for send signal. @@ -320,7 +429,7 @@ Changes from #268 by adamlhumphreys - Fixed #110 Mess - Created Gitter Room - Added Gitter Badge -- Standardised Code Base +- Standardized Code Base - Clean Debug Output - Optimized Send Loops - Modularized Design @@ -348,4 +457,4 @@ Changes from #268 by adamlhumphreys - Broke Teensy 3 / 3.1 Support ### Not Working -- Teensy 3 / 3.1 Support is in Development +- Teensy 3 / 3.1 Support is in Development \ No newline at end of file diff --git a/examples/AllProtocolsOnLCD/ADCUtils.h b/examples/AllProtocolsOnLCD/ADCUtils.h index 5aaaaf718..38aa471eb 100644 --- a/examples/AllProtocolsOnLCD/ADCUtils.h +++ b/examples/AllProtocolsOnLCD/ADCUtils.h @@ -2,7 +2,6 @@ * ADCUtils.h * * Copyright (C) 2016-2022 Armin Joachimsmeyer - * Email: armin.joachimsmeyer@gmail.com * * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. * @@ -29,6 +28,10 @@ #if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) && (!defined(__AVR_ATmega4809__)) #define ADC_UTILS_ARE_AVAILABLE +// External Reference Current is 150 uA for 5 V and 100 uA for 3.5 V +#define READING_FOR_AREF 1024 // Datasheet 24.2: The minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB +#define MAX_ADC_VALUE 1023 + // PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz #define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz #define ADC_PRESCALE4 2 // 52 microseconds per ADC conversion at 1 MHz @@ -85,6 +88,7 @@ #define ADC_TEMPERATURE_CHANNEL_MUX 15 #define ADC_1_1_VOLT_CHANNEL_MUX 12 #define ADC_GND_CHANNEL_MUX 13 +#define ADC_CHANNEL_MUX_MASK 0x0F #elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) #define ADC_ISCR_CHANNEL_MUX 3 @@ -92,56 +96,110 @@ #define ADC_1_1_VOLT_CHANNEL_MUX 12 #define ADC_GND_CHANNEL_MUX 14 #define ADC_VCC_4TH_CHANNEL_MUX 13 +#define ADC_CHANNEL_MUX_MASK 0x1F #elif defined(__AVR_ATmega328P__) #define ADC_TEMPERATURE_CHANNEL_MUX 8 #define ADC_1_1_VOLT_CHANNEL_MUX 14 #define ADC_GND_CHANNEL_MUX 15 +#define ADC_CHANNEL_MUX_MASK 0x0F + +#elif defined(__AVR_ATmega644P__) +#define ADC_TEMPERATURE_CHANNEL_MUX // not existent +#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E +#define ADC_GND_CHANNEL_MUX 0x1F +#define ADC_CHANNEL_MUX_MASK 0x0F #elif defined(__AVR_ATmega32U4__) #define ADC_TEMPERATURE_CHANNEL_MUX 0x27 #define ADC_1_1_VOLT_CHANNEL_MUX 0x1E #define ADC_GND_CHANNEL_MUX 0x1F +#define ADC_CHANNEL_MUX_MASK 0x3F #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) #define ADC_1_1_VOLT_CHANNEL_MUX 0x1E #define ADC_GND_CHANNEL_MUX 0x1F +#define ADC_CHANNEL_MUX_MASK 0x1F + #define INTERNAL INTERNAL1V1 #else #error "No temperature channel definitions specified for this AVR CPU" #endif -extern float sVCCVoltage; -extern uint16_t sVCCVoltageMillivolt; +/* + * Thresholds for OVER and UNDER voltage and detection of kind of power supply (USB or Li-ion) + * + * Default values are suitable for Li-ion batteries. + * We normally have voltage drop at the connectors, so the battery voltage is assumed slightly higher, than the Arduino VCC. + * But keep in mind that the ultrasonic distance module HC-SR04 may not work reliable below 3.7 volt. + */ +#if !defined(LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) +#define LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT 3400 // Do not stress your battery and we require some power for standby +#endif +#if !defined(LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) +#define LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT 3000 // Many Li-ions are specified down to 3.0 volt +#endif + +#if !defined(VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) +#define VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT LI_ION_VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT +#endif +#if !defined(VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) +#define VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT LI_ION_VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT +#endif +#if !defined(VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT) +#define VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT 5250 // + 5 % operation voltage +#endif +#if !defined(VCC_EMERGENCY_OVERVOLTAGE_THRESHOLD_MILLIVOLT) +#define VCC_EMERGENCY_OVERVOLTAGE_THRESHOLD_MILLIVOLT 5500 // +10 %. Max recommended operation voltage +#endif +#if !defined(VCC_CHECK_PERIOD_MILLIS) +#define VCC_CHECK_PERIOD_MILLIS 10000L // 10 seconds period of VCC checks +#endif +#if !defined(VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP) +#define VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP 6 // Shutdown after 6 times (60 seconds) VCC below VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT or 1 time below VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT +#endif + +#if !defined(VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT) +#define VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT 4300 // Assume USB powered above this voltage +#endif + +#if !defined(VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT) +#define VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT 4950 // Assume USB powered below this voltage, because of the loss in USB cable. If we have > 4950, we assume to be powered by VIN. +// In contrast to e.g. powered by VIN, which results in almost perfect 5 volt supply +#endif -extern long sLastVoltageCheckMillis; -extern uint8_t sVoltageTooLowCounter; - -uint16_t readADCChannel(uint8_t aChannelNumber); -uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference); -uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference); -uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aChannelNumber, uint8_t aReference); -uint16_t readADCChannelWithOversample(uint8_t aChannelNumber, uint8_t aOversampleExponent); -void setADCMultiplexerAndReferenceForNextConversion(uint8_t aChannelNumber, uint8_t aReference); -uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent); -uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent); -uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples); -uint16_t readADCChannelWithReferenceMax(uint8_t aChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples); -uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire); -uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aChannelNumber, uint8_t aDelay, uint8_t aAllowedDifference, - uint8_t aMaxRetries); - -uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aChannelNumber, uint8_t aReference); +extern long sLastVCCCheckMillis; +extern uint8_t sVCCTooLowCounter; + +uint16_t readADCChannel(); +uint16_t readADCChannel(uint8_t aADCChannelNumber); +uint16_t readADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t aReference); +uint16_t readADCChannelWithReferenceUsingInternalReference(uint8_t aADCChannelNumber); +uint16_t waitAndReadADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t aReference); +uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aADCChannelNumber, uint8_t aReference); +uint16_t readADCChannelWithOversample(uint8_t aADCChannelNumber, uint8_t aOversampleExponent); +void setADCChannelAndReferenceForNextConversion(uint8_t aADCChannelNumber, uint8_t aReference); +uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent); +uint32_t readADCChannelMultiSamples(uint8_t aPrescale, uint16_t aNumberOfSamples); +uint16_t readADCChannelMultiSamplesWithReference(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples); +uint32_t readADCChannelMultiSamplesWithReferenceAndPrescaler(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aPrescale, + uint16_t aNumberOfSamples); +uint16_t readADCChannelWithReferenceMax(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples); +uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire); +uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aDelay, + uint8_t aAllowedDifference, uint8_t aMaxRetries); + +void setADCChannelForNextConversionAndWaitUsingInternalReference(uint8_t aADCChannelNumber); +void setADCChannelForNextConversionAndWaitUsingDefaultReference(uint8_t aADCChannelNumber); +uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aADCChannelNumber, uint8_t aReference); /* * readVCC*() functions store the result in sVCCVoltageMillivolt or sVCCVoltage */ float getVCCVoltageSimple(void); void readVCCVoltageSimple(void); -uint16_t getVCCVoltageMillivoltSimple(void); void readVCCVoltageMillivoltSimple(void); -float getVCCVoltage(void); void readVCCVoltage(void); uint16_t getVCCVoltageMillivolt(void); void readVCCVoltageMillivolt(void); @@ -152,12 +210,32 @@ void readAndPrintVCCVoltageMillivolt(Print *aSerial); uint16_t getVoltageMillivolt(uint16_t aVCCVoltageMillivolt, uint8_t aADCChannelForVoltageMeasurement); uint16_t getVoltageMillivolt(uint8_t aADCChannelForVoltageMeasurement); uint16_t getVoltageMillivoltWith_1_1VoltReference(uint8_t aADCChannelForVoltageMeasurement); -float getTemperatureSimple(void); -float getTemperature(void); - -bool isVCCTooLowMultipleTimes(); -void resetVCCTooLowMultipleTimes(); -bool isVoltageTooLow(); +float getCPUTemperatureSimple(void); +float getCPUTemperature(void); +float getTemperature(void) __attribute__ ((deprecated ("Renamed to getCPUTemperature()"))); // deprecated + +bool isVCCUSBPowered(); +bool isVCCUSBPowered(Print *aSerial); +bool isVCCUndervoltageMultipleTimes(); +void resetCounterForVCCUndervoltageMultipleTimes(); +bool isVCCUndervoltage(); +bool isVCCEmergencyUndervoltage(); +bool isVCCOvervoltage(); +bool isVCCOvervoltageSimple(); // Version using readVCCVoltageMillivoltSimple() +bool isVCCTooHighSimple(); // Version not using readVCCVoltageMillivoltSimple() #endif // defined(__AVR__) ... + +/* + * The next variables and functions are defined as stubs on non-AVR platforms to allow for seamless compiling + */ +extern float sVCCVoltage; +extern uint16_t sVCCVoltageMillivolt; + +uint16_t readADCChannelWithReferenceOversample(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent); + +uint16_t getVCCVoltageMillivoltSimple(void); +float getVCCVoltage(void); +float getCPUTemperature(void); + #endif // _ADC_UTILS_H diff --git a/examples/AllProtocolsOnLCD/ADCUtils.hpp b/examples/AllProtocolsOnLCD/ADCUtils.hpp index 079d177da..ef9aad8da 100644 --- a/examples/AllProtocolsOnLCD/ADCUtils.hpp +++ b/examples/AllProtocolsOnLCD/ADCUtils.hpp @@ -3,8 +3,7 @@ * * ADC utility functions. Conversion time is defined as 0.104 milliseconds for 16 MHz Arduinos in ADCUtils.h. * - * Copyright (C) 2016-2022 Armin Joachimsmeyer - * Email: armin.joachimsmeyer@gmail.com + * Copyright (C) 2016-2023 Armin Joachimsmeyer * * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. * @@ -26,19 +25,25 @@ #define _ADC_UTILS_HPP #include "ADCUtils.h" -#if defined(ADC_UTILS_ARE_AVAILABLE) +#if defined(ADC_UTILS_ARE_AVAILABLE) // set in ADCUtils.h, if supported architecture was detected +#define ADC_UTILS_ARE_INCLUDED -#if !defined(STR_HELPER) +// Helper macro for getting a macro definition as string +#if !defined(STR_HELPER) && !defined(STR) #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) #endif +#if !defined(BITS_PER_BYTE) +#define BITS_PER_BYTE 8 +#endif /* * By replacing this value with the voltage you measured a the AREF pin after a conversion * with INTERNAL you can calibrate your ADC readout. For my Nanos I measured e.g. 1060 mV and 1093 mV. + * If value > real AREF voltage, measured values are > real values */ #if !defined(ADC_INTERNAL_REFERENCE_MILLIVOLT) -#define ADC_INTERNAL_REFERENCE_MILLIVOLT 1100L // Change to value measured at the AREF pin. If value > real AREF voltage, measured values are > real values +#define ADC_INTERNAL_REFERENCE_MILLIVOLT 1100 // Change to value measured at the AREF pin. #endif // Union to speed up the combination of low and high bytes to a word @@ -54,22 +59,37 @@ union WordUnionForADCUtils { uint8_t *BytePointer; }; +/* + * Enable this to see information on each call. + * Since there should be no library which uses Serial, it should only be enabled for development purposes. + */ +#if defined(DEBUG) +#define LOCAL_DEBUG +#else +//#define LOCAL_DEBUG // This enables debug output only for this file +#endif +#if defined(INFO) +#define LOCAL_INFO +#else +//#define LOCAL_INFO // This enables debug output only for this file +#endif + /* * Persistent storage for VCC value */ float sVCCVoltage; -uint16_t sVCCVoltageMillivolt; +uint16_t sVCCVoltageMillivolt; // Set by readVCCVoltageMillivoltSimple(), readVCCVoltageMillivolt() // for isVCCTooLowMultipleTimes() -long sLastVoltageCheckMillis; -uint8_t sVoltageTooLowCounter = 0; +long sLastVCCCheckMillis; +uint8_t sVCCTooLowCounter = 0; /* * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. + * Use previous settings */ -uint16_t readADCChannel(uint8_t aChannelNumber) { +uint16_t readADCChannel() { WordUnionForADCUtils tUValue; - ADMUX = aChannelNumber | (DEFAULT << SHIFT_VALUE_FOR_REFERENCE); // ADCSRB = 0; // Only active if ADATE is set to 1. // ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode @@ -85,12 +105,32 @@ uint16_t readADCChannel(uint8_t aChannelNumber) { // return ADCL | (ADCH <<8); // needs 4 bytes more } +/* + * Use new channel aADCChannelNumber, but do not wait for channel switching + */ +uint16_t readADCChannel(uint8_t aADCChannelNumber) { + WordUnionForADCUtils tUValue; + ADMUX = aADCChannelNumber | (DEFAULT << SHIFT_VALUE_FOR_REFERENCE); + + // ADCSRB = 0; // Only active if ADATE is set to 1. + // ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode + ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADIF) | ADC_PRESCALE); + + // wait for single conversion to finish + loop_until_bit_is_clear(ADCSRA, ADSC); + + // Get value + tUValue.UByte.LowByte = ADCL; + tUValue.UByte.HighByte = ADCH; + return tUValue.UWord; + // return ADCL | (ADCH <<8); // needs 4 bytes more +} /* * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. */ -uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference) { +uint16_t readADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t aReference) { WordUnionForADCUtils tUValue; - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); // ADCSRB = 0; // Only active if ADATE is set to 1. // ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode @@ -105,22 +145,38 @@ uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference) return tUValue.UWord; } +uint16_t readADCChannelWithReferenceUsingInternalReference(uint8_t aADCChannelNumber) { + WordUnionForADCUtils tUValue; + ADMUX = aADCChannelNumber | (INTERNAL << SHIFT_VALUE_FOR_REFERENCE); + + // ADCSRB = 0; // Only active if ADATE is set to 1. + // ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode + ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADIF) | ADC_PRESCALE); + + // wait for single conversion to finish + loop_until_bit_is_clear(ADCSRA, ADSC); + + // Get value + tUValue.UByte.LowByte = ADCL; + tUValue.UByte.HighByte = ADCH; + return tUValue.UWord; +} /* * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. * Does NOT restore ADMUX after reading */ -uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference) { - checkAndWaitForReferenceAndChannelToSwitch(aChannelNumber, aReference); - return readADCChannelWithReference(aChannelNumber, aReference); +uint16_t waitAndReadADCChannelWithReference(uint8_t aADCChannelNumber, uint8_t aReference) { + checkAndWaitForReferenceAndChannelToSwitch(aADCChannelNumber, aReference); + return readADCChannelWithReference(aADCChannelNumber, aReference); } /* * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. * Restores ADMUX after reading */ -uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aChannelNumber, uint8_t aReference) { - uint8_t tOldADMUX = checkAndWaitForReferenceAndChannelToSwitch(aChannelNumber, aReference); - uint16_t tResult = readADCChannelWithReference(aChannelNumber, aReference); +uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t aADCChannelNumber, uint8_t aReference) { + uint8_t tOldADMUX = checkAndWaitForReferenceAndChannelToSwitch(aADCChannelNumber, aReference); + uint16_t tResult = readADCChannelWithReference(aADCChannelNumber, aReference); checkAndWaitForReferenceAndChannelToSwitch(tOldADMUX & MASK_FOR_ADC_CHANNELS, tOldADMUX >> SHIFT_VALUE_FOR_REFERENCE); return tResult; } @@ -128,15 +184,28 @@ uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t a /* * To prepare reference and ADMUX for next measurement */ -void setADCMultiplexerAndReferenceForNextConversion(uint8_t aChannelNumber, uint8_t aReference) { - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); +void setADCChannelAndReferenceForNextConversion(uint8_t aADCChannelNumber, uint8_t aReference) { + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); +} + +/* + * 100 kOhm requires < 100 us, 1 MOhm requires 120 us S&H switching time + */ +void setADCChannelForNextConversionAndWaitUsingInternalReference(uint8_t aADCChannelNumber) { + ADMUX = aADCChannelNumber | (INTERNAL << SHIFT_VALUE_FOR_REFERENCE); + delayMicroseconds(120); // experimental value is <= 1100 us for Nano board +} + +void setADCChannelForNextConversionAndWaitUsingDefaultReference(uint8_t aADCChannelNumber) { + ADMUX = aADCChannelNumber | (DEFAULT << SHIFT_VALUE_FOR_REFERENCE); + delayMicroseconds(120); // experimental value is <= 1100 us for Nano board } /* * @return original ADMUX register content for optional later restoring values * All experimental values are acquired by using the ADCSwitchingTest example from this library */ -uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aChannelNumber, uint8_t aReference) { +uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aADCChannelNumber, uint8_t aReference) { uint8_t tOldADMUX = ADMUX; /* * Must wait >= 7 us if reference has to be switched from 1.1 volt/INTERNAL to VCC/DEFAULT (seen on oscilloscope) @@ -146,18 +215,21 @@ uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aChannelNumber, uint8 * Must wait >= 200 us if channel has to be switched to 1.1 volt internal channel if S&H was at 5 Volt */ uint8_t tNewReference = (aReference << SHIFT_VALUE_FOR_REFERENCE); - ADMUX = aChannelNumber | tNewReference; + ADMUX = aADCChannelNumber | tNewReference; #if defined(INTERNAL2V56) if ((tOldADMUX & MASK_FOR_ADC_REFERENCE) != tNewReference && (aReference == INTERNAL || aReference == INTERNAL2V56)) { #else if ((tOldADMUX & MASK_FOR_ADC_REFERENCE) != tNewReference && aReference == INTERNAL) { +#endif +#if defined(LOCAL_DEBUG) + Serial.println(F("Switch from DEFAULT to INTERNAL")); #endif /* * Switch reference from DEFAULT to INTERNAL */ - delayMicroseconds(8000); // experimental value is >= 7600 us for Nano board and 6200 for UNO board - } else if ((tOldADMUX & 0x0F) != aChannelNumber) { - if (aChannelNumber == ADC_1_1_VOLT_CHANNEL_MUX) { + delayMicroseconds(8000); // experimental value is >= 7600 us for Nano board and 6200 for Uno board + } else if ((tOldADMUX & ADC_CHANNEL_MUX_MASK) != aADCChannelNumber) { + if (aADCChannelNumber == ADC_1_1_VOLT_CHANNEL_MUX) { /* * Internal 1.1 Volt channel requires <= 200 us for Nano board */ @@ -176,16 +248,16 @@ uint8_t checkAndWaitForReferenceAndChannelToSwitch(uint8_t aChannelNumber, uint8 * Oversample and multiple samples only makes sense if you expect a noisy input signal * It does NOT increase the precision of the measurement, since the ADC has insignificant noise */ -uint16_t readADCChannelWithOversample(uint8_t aChannelNumber, uint8_t aOversampleExponent) { - return readADCChannelWithReferenceOversample(aChannelNumber, DEFAULT, aOversampleExponent); +uint16_t readADCChannelWithOversample(uint8_t aADCChannelNumber, uint8_t aOversampleExponent) { + return readADCChannelWithReferenceOversample(aADCChannelNumber, DEFAULT, aOversampleExponent); } /* * Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h. */ -uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent) { +uint16_t readADCChannelWithReferenceOversample(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent) { uint16_t tSumValue = 0; - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag @@ -212,9 +284,9 @@ uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t a /* * Use ADC_PRESCALE32 which gives 26 us conversion time and good linearity for 16 MHz Arduino */ -uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent) { +uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent) { uint16_t tSumValue = 0; - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag @@ -239,11 +311,12 @@ uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aChannelNumber, uint8 /* * Returns sum of all sample values - * Conversion time is defined as 0.104 milliseconds for 16 MHz Arduino by ADC_PRESCALE in ADCUtils.h. + * Conversion time is defined as 0.104 milliseconds for 16 MHz Arduino by ADC_PRESCALE (=ADC_PRESCALE128) in ADCUtils.h. + * @ param aNumberOfSamples If > 64 an overflow may occur. */ -uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples) { +uint16_t readADCChannelMultiSamplesWithReference(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples) { uint16_t tSumValue = 0; - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag @@ -265,14 +338,73 @@ uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aChannelNumber, uint8_t return tSumValue; } +/* + * Returns sum of all sample values + * Conversion time is defined as 0.104 milliseconds for 16 MHz Arduino for ADC_PRESCALE128 in ADCUtils.h. + * @ param aPrescale can be one of ADC_PRESCALE2, ADC_PRESCALE4, 8, 16, 32, 64, 128. + * ADC_PRESCALE32 is recommended for excellent linearity and fast readout of 26 microseconds + * @ param aNumberOfSamples If > 16k an overflow may occur. + */ +uint32_t readADCChannelMultiSamplesWithReferenceAndPrescaler(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aPrescale, + uint16_t aNumberOfSamples) { + uint32_t tSumValue = 0; + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + + ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. + // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag + ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADIF) | aPrescale); + + for (uint16_t i = 0; i < aNumberOfSamples; i++) { + /* + * wait for free running conversion to finish. + * Do not wait for ADSC here, since ADSC is only low for 1 ADC Clock cycle on free running conversion. + */ + loop_until_bit_is_set(ADCSRA, ADIF); + + ADCSRA |= _BV(ADIF); // clear bit to enable recognizing next conversion has finished + // Add value + tSumValue += ADCL | (ADCH << 8); // using WordUnionForADCUtils does not save space here + // tSumValue += (ADCH << 8) | ADCL; // this does NOT work! + } + ADCSRA &= ~_BV(ADATE); // Disable auto-triggering (free running mode) + return tSumValue; +} + +/* + * Returns sum of all sample values + * Assumes, that channel and reference are still set to the right values + * @ param aNumberOfSamples If > 16k an overflow may occur. + */ +uint32_t readADCChannelMultiSamples(uint8_t aPrescale, uint16_t aNumberOfSamples) { + uint32_t tSumValue = 0; + + ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. + // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag + ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADIF) | aPrescale); + + for (uint16_t i = 0; i < aNumberOfSamples; i++) { + /* + * wait for free running conversion to finish. + * Do not wait for ADSC here, since ADSC is only low for 1 ADC Clock cycle on free running conversion. + */ + loop_until_bit_is_set(ADCSRA, ADIF); + + ADCSRA |= _BV(ADIF); // clear bit to enable recognizing next conversion has finished + // Add value + tSumValue += ADCL | (ADCH << 8); // using WordUnionForADCUtils does not save space here + // tSumValue += (ADCH << 8) | ADCL; // this does NOT work! + } + ADCSRA &= ~_BV(ADATE); // Disable auto-triggering (free running mode) + return tSumValue; +} /* * use ADC_PRESCALE32 which gives 26 us conversion time and good linearity - * @return the maximum of aNumberOfSamples measurements. + * @return the maximum value of aNumberOfSamples samples. */ -uint16_t readADCChannelWithReferenceMax(uint8_t aChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples) { +uint16_t readADCChannelWithReferenceMax(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples) { uint16_t tADCValue = 0; uint16_t tMaximum = 0; - ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); + ADMUX = aADCChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE); ADCSRB = 0; // Free running mode. Only active if ADATE is set to 1. // ADSC-StartConversion ADATE-AutoTriggerEnable ADIF-Reset Interrupt Flag @@ -298,33 +430,41 @@ uint16_t readADCChannelWithReferenceMax(uint8_t aChannelNumber, uint8_t aReferen /* * use ADC_PRESCALE32 which gives 26 us conversion time and good linearity + * @return the maximum value during aMicrosecondsToAquire measurement. */ -uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire) { +uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire) { uint16_t tNumberOfSamples = aMicrosecondsToAquire / 26; - return readADCChannelWithReferenceMax(aChannelNumber, aReference, tNumberOfSamples); + return readADCChannelWithReferenceMax(aADCChannelNumber, aReference, tNumberOfSamples); } /* * aMaxRetries = 255 -> try forever * @return (tMax + tMin) / 2 */ -uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aChannelNumber, uint8_t aDelay, uint8_t aAllowedDifference, - uint8_t aMaxRetries) { - int tValues[4]; +uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aDelay, + uint8_t aAllowedDifference, uint8_t aMaxRetries) { + int tValues[4]; // last value is in tValues[3] int tMin; int tMax; - tValues[0] = readADCChannel(aChannelNumber); + /* + * Initialize first 4 values before checking + */ + tValues[0] = readADCChannelWithReference(aADCChannelNumber, aReference); for (int i = 1; i < 4; ++i) { - delay(aDelay); // Only 3 delays! - tValues[i] = readADCChannel(aChannelNumber); + if (aDelay != 0) { + delay(aDelay); // Minimum is only 3 delays! + } + tValues[i] = readADCChannelWithReference(aADCChannelNumber, aReference); } do { - // find min and max - tMin = 1024; + /* + * Get min and max of the last 4 values + */ + tMin = READING_FOR_AREF; tMax = 0; - for (int i = 0; i < 4; ++i) { + for (uint_fast8_t i = 0; i < 4; ++i) { if (tValues[i] < tMin) { tMin = tValues[i]; } @@ -338,22 +478,44 @@ uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aChannelNumber, uint8_t aDe if ((tMax - tMin) <= aAllowedDifference) { break; } else { + /* + * Get next value + */ // Serial.print("Difference="); // Serial.println(tMax - tMin); - - // move values + // Move values to front for (int i = 0; i < 3; ++i) { tValues[i] = tValues[i + 1]; } - // and wait - delay(aDelay); - tValues[3] = readADCChannel(aChannelNumber); + // and wait before getting next value + if (aDelay != 0) { + delay(aDelay); + } + tValues[3] = readADCChannelWithReference(aADCChannelNumber, aReference); } if (aMaxRetries != 255) { aMaxRetries--; } } while (aMaxRetries > 0); +#if defined(LOCAL_DEBUG) + if(aMaxRetries == 0) { + Serial.print(F("No 4 equal values for difference ")); + Serial.print(aAllowedDifference); + Serial.print(F(" found ")); + Serial.print(tValues[0]); + Serial.print(' '); + Serial.print(tValues[1]); + Serial.print(' '); + Serial.print(tValues[2]); + Serial.print(' '); + Serial.println(tValues[3]); + } else { + Serial.print(aMaxRetries); + Serial.println(F(" retries left")); + } +#endif + return (tMax + tMin) / 2; } @@ -361,11 +523,15 @@ uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aChannelNumber, uint8_t aDe * !!! Function without handling of switched reference and channel.!!! * Use it ONLY if you only call getVCCVoltageSimple() or getVCCVoltageMillivoltSimple() in your program. * !!! Resolution is only 20 millivolt !!! + * Raw reading of 1.1 V is 225 at 5 V. + * Raw reading of 1.1 V is 221 at 5.1 V. + * Raw reading of 1.1 V is 214 at 5.25 V (+5 %). + * Raw reading of 1.1 V is 204 at 5.5 V (+10 %). */ float getVCCVoltageSimple(void) { // use AVCC with (optional) external capacitor at AREF pin as reference - float tVCC = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); - return ((1023 * 1.1 * 4) / tVCC); + float tVCC = readADCChannelMultiSamplesWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); + return ((READING_FOR_AREF * 1.1 * 4) / tVCC); } /* @@ -375,20 +541,20 @@ float getVCCVoltageSimple(void) { */ uint16_t getVCCVoltageMillivoltSimple(void) { // use AVCC with external capacitor at AREF pin as reference - uint16_t tVCC = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); - return ((1023L * ADC_INTERNAL_REFERENCE_MILLIVOLT * 4) / tVCC); + uint16_t tVCC = readADCChannelMultiSamplesWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); + return (((uint32_t)READING_FOR_AREF * ADC_INTERNAL_REFERENCE_MILLIVOLT * 4) / tVCC); } /* * Gets the hypothetical 14 bit reading of VCC using 1.1 volt reference - * Similar to getVCCVoltageMillivolt() * 1023 / 1100 + * Similar to getVCCVoltageMillivolt() * 1024 / 1100 */ uint16_t getVCCVoltageReadingFor1_1VoltReference(void) { - uint16_t tVCC = waitAndReadADCChannelWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT); // 225 for 1.1 V at 5 V VCC + uint16_t tVCC = waitAndReadADCChannelWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT); /* * Do not switch back ADMUX to enable checkAndWaitForReferenceAndChannelToSwitch() to work correctly for the next measurement */ - return ((1023L * 1023L) / tVCC); + return (((uint32_t)READING_FOR_AREF * READING_FOR_AREF) / tVCC); } /* @@ -402,15 +568,22 @@ float getVCCVoltage(void) { * Read value of 1.1 volt internal channel using VCC (DEFAULT) as reference. * Handles reference and channel switching by introducing the appropriate delays. * !!! Resolution is only 20 millivolt !!! + * Raw reading of 1.1 V is 225 at 5 V. + * Raw reading of 1.1 V is 221 at 5.1 V. + * Raw reading of 1.1 V is 214 at 5.25 V (+5 %). + * Raw reading of 1.1 V is 204 at 5.5 V (+10 %). */ uint16_t getVCCVoltageMillivolt(void) { uint16_t tVCC = waitAndReadADCChannelWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT); /* * Do not switch back ADMUX to enable checkAndWaitForReferenceAndChannelToSwitch() to work correctly for the next measurement */ - return ((1023L * ADC_INTERNAL_REFERENCE_MILLIVOLT) / tVCC); + return (((uint32_t)READING_FOR_AREF * ADC_INTERNAL_REFERENCE_MILLIVOLT) / tVCC); } +/* + * Does not set sVCCVoltageMillivolt + */ uint16_t printVCCVoltageMillivolt(Print *aSerial) { aSerial->print(F("VCC=")); uint16_t tVCCVoltageMillivolt = getVCCVoltageMillivolt(); @@ -432,8 +605,8 @@ void readAndPrintVCCVoltageMillivolt(Print *aSerial) { */ void readVCCVoltageSimple(void) { // use AVCC with (optional) external capacitor at AREF pin as reference - float tVCC = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); - sVCCVoltage = (1023 * 1.1 * 4) / tVCC; + float tVCC = readADCChannelMultiSamplesWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); + sVCCVoltage = (READING_FOR_AREF * (((float) ADC_INTERNAL_REFERENCE_MILLIVOLT) / 1000) * 4) / tVCC; } /* @@ -443,8 +616,8 @@ void readVCCVoltageSimple(void) { */ void readVCCVoltageMillivoltSimple(void) { // use AVCC with external capacitor at AREF pin as reference - uint16_t tVCCVoltageMillivoltRaw = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); - sVCCVoltageMillivolt = (1023L * ADC_INTERNAL_REFERENCE_MILLIVOLT * 4) / tVCCVoltageMillivoltRaw; + uint16_t tVCCVoltageMillivoltRaw = readADCChannelMultiSamplesWithReference(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4); + sVCCVoltageMillivolt = ((uint32_t)READING_FOR_AREF * ADC_INTERNAL_REFERENCE_MILLIVOLT * 4) / tVCCVoltageMillivoltRaw; } /* @@ -465,7 +638,7 @@ void readVCCVoltageMillivolt(void) { /* * Do not switch back ADMUX to enable checkAndWaitForReferenceAndChannelToSwitch() to work correctly for the next measurement */ - sVCCVoltageMillivolt = (1023L * ADC_INTERNAL_REFERENCE_MILLIVOLT) / tVCCVoltageMillivoltRaw; + sVCCVoltageMillivolt = ((uint32_t)READING_FOR_AREF * ADC_INTERNAL_REFERENCE_MILLIVOLT) / tVCCVoltageMillivoltRaw; } /* @@ -474,7 +647,7 @@ void readVCCVoltageMillivolt(void) { */ uint16_t getVoltageMillivolt(uint16_t aVCCVoltageMillivolt, uint8_t aADCChannelForVoltageMeasurement) { uint16_t tInputVoltageRaw = waitAndReadADCChannelWithReference(aADCChannelForVoltageMeasurement, DEFAULT); - return (aVCCVoltageMillivolt * (uint32_t) tInputVoltageRaw) / 1023; + return (aVCCVoltageMillivolt * (uint32_t) tInputVoltageRaw) / READING_FOR_AREF; } /* @@ -483,42 +656,54 @@ uint16_t getVoltageMillivolt(uint16_t aVCCVoltageMillivolt, uint8_t aADCChannelF */ uint16_t getVoltageMillivolt(uint8_t aADCChannelForVoltageMeasurement) { uint16_t tInputVoltageRaw = waitAndReadADCChannelWithReference(aADCChannelForVoltageMeasurement, DEFAULT); - return (getVCCVoltageMillivolt() * (uint32_t) tInputVoltageRaw) / 1023; + return (getVCCVoltageMillivolt() * (uint32_t) tInputVoltageRaw) / READING_FOR_AREF; } uint16_t getVoltageMillivoltWith_1_1VoltReference(uint8_t aADCChannelForVoltageMeasurement) { uint16_t tInputVoltageRaw = waitAndReadADCChannelWithReference(aADCChannelForVoltageMeasurement, INTERNAL); - return (ADC_INTERNAL_REFERENCE_MILLIVOLT * (uint32_t) tInputVoltageRaw) / 1023; + return (ADC_INTERNAL_REFERENCE_MILLIVOLT * (uint32_t) tInputVoltageRaw) / READING_FOR_AREF; } /* - * Default values are suitable for Li-ion batteries. - * We normally have voltage drop at the connectors, so the battery voltage is assumed slightly higher, than the Arduino VCC. - * But keep in mind that the ultrasonic distance module HC-SR04 may not work reliable below 3.7 volt. + * Return true if sVCCVoltageMillivolt is > 4.3 V and < 4.95 V + * This does not really work for the UNO board, because it has no series Diode in the USB VCC + * and therefore a very low voltage drop. */ -#if !defined(VCC_STOP_THRESHOLD_MILLIVOLT) -#define VCC_STOP_THRESHOLD_MILLIVOLT 3400 // Do not stress your battery and we require some power for standby -#endif -#if !defined(VCC_EMERGENCY_STOP_MILLIVOLT) -#define VCC_EMERGENCY_STOP_MILLIVOLT 3000 // Many Li-ions are specified down to 3.0 volt -#endif -#if !defined(VCC_CHECK_PERIOD_MILLIS) -#define VCC_CHECK_PERIOD_MILLIS 10000 // Period of VCC checks -#endif -#if !defined(VCC_CHECKS_TOO_LOW_BEFORE_STOP) -#define VCC_CHECKS_TOO_LOW_BEFORE_STOP 6 // Shutdown after 6 times (60 seconds) VCC below VCC_STOP_THRESHOLD_MILLIVOLT or 1 time below VCC_EMERGENCY_STOP_MILLIVOLT -#endif +bool isVCCUSBPowered() { + readVCCVoltageMillivolt(); + return (VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT < sVCCVoltageMillivolt + && sVCCVoltageMillivolt < VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT); +} + +/* + * Return true if sVCCVoltageMillivolt is > 4.3 V and < 4.95 V + */ +bool isVCCUSBPowered(Print *aSerial) { + readVCCVoltageMillivolt(); + aSerial->print(F("USB powered is ")); + bool tReturnValue; + if (VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT + < sVCCVoltageMillivolt&& sVCCVoltageMillivolt < VOLTAGE_USB_POWERED_UPPER_THRESHOLD_MILLIVOLT) { + tReturnValue = true; + aSerial->print(F("true ")); + } else { + tReturnValue = false; + aSerial->print(F("false ")); + } + printVCCVoltageMillivolt(aSerial); + return tReturnValue; +} /* - * @ return true only once, when VCC_CHECKS_TOO_LOW_BEFORE_STOP (6) times voltage too low -> shutdown + * It checks every 10 seconds for 6 times, and then returns once true if the undervoltage condition ( <3.4V ) still applies. + * @ return true only once, when VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP (6) times voltage too low -> shutdown */ -bool isVCCTooLowMultipleTimes() { +bool isVCCUndervoltageMultipleTimes() { /* - * Check VCC every VCC_CHECK_PERIOD_MILLIS (10) seconds + * Check VCC every VCC_CHECK_PERIOD_MILLIS - default is 10 seconds */ - - if (millis() - sLastVoltageCheckMillis >= VCC_CHECK_PERIOD_MILLIS) { - sLastVoltageCheckMillis = millis(); + if (millis() - sLastVCCCheckMillis >= VCC_CHECK_PERIOD_MILLIS) { + sLastVCCCheckMillis = millis(); # if defined(INFO) readAndPrintVCCVoltageMillivolt(&Serial); @@ -526,33 +711,37 @@ bool isVCCTooLowMultipleTimes() { readVCCVoltageMillivolt(); # endif - if (sVoltageTooLowCounter < VCC_CHECKS_TOO_LOW_BEFORE_STOP) { - /* - * Do not check again if shutdown has happened - */ - if (sVCCVoltageMillivolt > VCC_STOP_THRESHOLD_MILLIVOLT) { - sVoltageTooLowCounter = 0; // reset counter + /* + * Do not check again if shutdown signaling (sVCCTooLowCounter >= 6) has happened + */ + if (sVCCTooLowCounter < VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP) { // VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP = 6 + if (sVCCVoltageMillivolt > VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) { + sVCCTooLowCounter = 0; // reset counter } else { /* - * Voltage too low, wait VCC_CHECKS_TOO_LOW_BEFORE_STOP (6) times and then shut down. + * Voltage too low, wait VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP (6) times and then signal shut down. */ - if (sVCCVoltageMillivolt < VCC_EMERGENCY_STOP_MILLIVOLT) { + if (sVCCVoltageMillivolt < VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) { // emergency shutdown - sVoltageTooLowCounter = VCC_CHECKS_TOO_LOW_BEFORE_STOP; -# if defined(INFO) - Serial.println(F("Voltage < " STR(VCC_EMERGENCY_STOP_MILLIVOLT) " mV detected -> emergency shutdown")); + sVCCTooLowCounter = VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP; +# if defined(LOCAL_INFO) + Serial.println( + F( + "Undervoltage < " STR(VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) " mV detected -> emergency shutdown")); # endif } else { - sVoltageTooLowCounter++; -# if defined(INFO) - Serial.print(F("Voltage < " STR(VCC_STOP_THRESHOLD_MILLIVOLT) " mV detected: ")); - Serial.print(VCC_CHECKS_TOO_LOW_BEFORE_STOP - sVoltageTooLowCounter); - Serial.println(F(" tries left")); + sVCCTooLowCounter++; +# if defined(LOCAL_INFO) + Serial.print(sVCCVoltageMillivolt); + Serial.print(F(" mV < " STR(VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT) " mV -> undervoltage detected: ")); + + Serial.print(VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP - sVCCTooLowCounter); + Serial.println(F(" attempts left")); # endif } - if (sVoltageTooLowCounter == VCC_CHECKS_TOO_LOW_BEFORE_STOP) { + if (sVCCTooLowCounter == VCC_UNDERVOLTAGE_CHECKS_BEFORE_STOP) { /* - * 6 times voltage too low -> shutdown + * 6 times voltage too low -> return signal for shutdown etc. */ return true; } @@ -562,47 +751,134 @@ bool isVCCTooLowMultipleTimes() { return false; } -void resetVCCTooLowMultipleTimes(){ - sVoltageTooLowCounter = 0; +/* + * Return true if VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT (3 V) reached + */ +bool isVCCUndervoltage() { + readVCCVoltageMillivolt(); + return (sVCCVoltageMillivolt < VCC_UNDERVOLTAGE_THRESHOLD_MILLIVOLT); +} + +/* + * Return true if VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT (3 V) reached + */ +bool isVCCEmergencyUndervoltage() { + readVCCVoltageMillivolt(); + return (sVCCVoltageMillivolt < VCC_EMERGENCY_UNDERVOLTAGE_THRESHOLD_MILLIVOLT); } -bool isVoltageTooLow(){ - return (sVoltageTooLowCounter >= VCC_CHECKS_TOO_LOW_BEFORE_STOP); +void resetCounterForVCCUndervoltageMultipleTimes() { + sVCCTooLowCounter = 0; +} + +/* + * Recommended VCC is 1.8 V to 5.5 V, absolute maximum VCC is 6.0 V. + * Check for 5.25 V, because such overvoltage is quite unlikely to happen during regular operation. + * Raw reading of 1.1 V is 225 at 5 V. + * Raw reading of 1.1 V is 221 at 5.1 V. + * Raw reading of 1.1 V is 214 at 5.25 V (+5 %). + * Raw reading of 1.1 V is 204 at 5.5 V (+10 %). + * Raw reading of 1.1 V is 1126000 / VCC_MILLIVOLT + * @return true if 5 % overvoltage reached + */ +bool isVCCOvervoltage() { + readVCCVoltageMillivolt(); + return (sVCCVoltageMillivolt > VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT); +} +bool isVCCOvervoltageSimple() { + readVCCVoltageMillivoltSimple(); + return (sVCCVoltageMillivolt > VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT); +} + +// Version not using readVCCVoltageMillivoltSimple() +bool isVCCTooHighSimple() { + ADMUX = ADC_1_1_VOLT_CHANNEL_MUX | (DEFAULT << SHIFT_VALUE_FOR_REFERENCE); +// ADCSRB = 0; // Only active if ADATE is set to 1. +// ADSC-StartConversion ADIF-Reset Interrupt Flag - NOT free running mode + ADCSRA = (_BV(ADEN) | _BV(ADSC) | _BV(ADIF) | ADC_PRESCALE128); // 128 -> 104 microseconds per ADC conversion at 16 MHz --- Arduino default +// wait for single conversion to finish + loop_until_bit_is_clear(ADCSRA, ADSC); + +// Get value + uint16_t tRawValue = ADCL | (ADCH << 8); + + return tRawValue < 1126000 / VCC_OVERVOLTAGE_THRESHOLD_MILLIVOLT; } /* + * Temperature sensor is enabled by selecting the appropriate channel. + * Different formula for 328P and 328PB! * !!! Function without handling of switched reference and channel.!!! - * Use it ONLY if you only use INTERNAL reference (call getTemperatureSimple()) in your program. + * Use it ONLY if you only use INTERNAL reference (e.g. only call getTemperatureSimple()) in your program. */ -float getTemperatureSimple(void) { +float getCPUTemperatureSimple(void) { #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) return 0.0; #else -// use internal 1.1 volt as reference - float tTemp = (readADCChannelWithReferenceMultiSamples(ADC_TEMPERATURE_CHANNEL_MUX, INTERNAL, 2) - 317); - return (tTemp * (4 / 1.22)); + // use internal 1.1 volt as reference. 4 times oversample. Assume the signal has noise, but never verified :-( + uint16_t tTemperatureRaw = readADCChannelWithReferenceOversample(ADC_TEMPERATURE_CHANNEL_MUX, INTERNAL, 2); +#if defined(LOCAL_DEBUG) + Serial.print(F("TempRaw=")); + Serial.println(tTemperatureRaw); +#endif + +#if defined(__AVR_ATmega328PB__) + tTemperatureRaw -= 245; + return (float)tTemperatureRaw; +#elif defined(__AVR_ATtiny85__) + tTemperatureRaw -= 273; // 273 and 1.1666 are values from the datasheet + return (float)tTemperatureRaw / 1.1666; +#else + tTemperatureRaw -= 317; + return (float) tTemperatureRaw / 1.22; +#endif #endif } /* - * Handles reference and channel switching by introducing the appropriate delays. + * Handles usage of 1.1 V reference and channel switching by introducing the appropriate delays. */ float getTemperature(void) { + return getCPUTemperature(); +} +float getCPUTemperature(void) { #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) return 0.0; #else // use internal 1.1 volt as reference checkAndWaitForReferenceAndChannelToSwitch(ADC_TEMPERATURE_CHANNEL_MUX, INTERNAL); - // assume the signal has noise, but never verified :-( - float tTemp = (readADCChannelWithReferenceOversample(ADC_TEMPERATURE_CHANNEL_MUX, INTERNAL, 1) - 317); - return (tTemp / 1.22); + return getCPUTemperatureSimple(); #endif } -#elif defined(ARDUINO_ARCH_APOLLO3) // defined(ADC_UTILS_ARE_AVAILABLE) - void ADCUtilsDummyToAvoidBFDAssertions(){ - ; - } +#else // defined(ADC_UTILS_ARE_AVAILABLE) +// Dummy definition of functions defined in ADCUtils to compile examples for non AVR platforms without errors +/* + * Persistent storage for VCC value + */ +float sVCCVoltage; +uint16_t sVCCVoltageMillivolt; + +uint16_t getVCCVoltageMillivoltSimple(void){ + return 3300; +} + +uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber __attribute__((unused)), + uint8_t aReference __attribute__((unused)), uint8_t aOversampleExponent __attribute__((unused))) { + return 0; +} +float getCPUTemperature() { + return 20.0; +} +float getVCCVoltage() { + return 3.3; +} #endif // defined(ADC_UTILS_ARE_AVAILABLE) +#if defined(LOCAL_DEBUG) +#undef LOCAL_DEBUG +#endif +#if defined(LOCAL_INFO) +#undef LOCAL_INFO +#endif #endif // _ADC_UTILS_HPP diff --git a/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino b/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino index bc514a194..62a8a9282 100644 --- a/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino +++ b/examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino @@ -9,7 +9,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -33,15 +33,22 @@ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 180 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 600 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else -#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Here we most likely have 2 k RAM or more +#define RAW_BUFFER_LENGTH 750 +# endif + +# if RAMSIZE <= 0x800 +#define DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE 200 // The decoder accepts mark or space durations up to 200 * 50 (MICROS_PER_TICK) = 10 milliseconds +# else +#define DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE 400 // The decoder accepts mark or space durations up to 400 * 50 (MICROS_PER_TICK) = 20 milliseconds # endif #endif @@ -54,12 +61,14 @@ #endif //#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. //#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active +//#define USE_THRESHOLD_DECODER // May give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses. Requires additional 120 bytes program memory. // MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, -// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142. -#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules. +// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 135. +// 20 is taken as default if not otherwise specified / defined. +#define MARK_EXCESS_MICROS 40 // Adapt it to your IR receiver module. 40 is recommended for the cheap VS1838 modules at high intensity. -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols. +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols. //#define DEBUG // Activate this for lots of lovely debug output from the decoders. //#define DECODE_NEC // Includes Apple and Onkyo @@ -73,19 +82,30 @@ * because of the long lasting serial communication. */ //#define USE_NO_LCD -//#define USE_SERIAL_LCD -// Definitions for the 1602 LCD -#define LCD_COLUMNS 16 -#define LCD_ROWS 2 - -#if defined(USE_SERIAL_LCD) -#include "LiquidCrystal_I2C.h" // Use an up to date library version, which has the init method +#if !defined(USE_NO_LCD) +#define USE_LCD +#define USE_PARALLEL_2004_LCD // Is default +//#define USE_SERIAL_1602_LCD +#include "LCDPrintUtils.hpp" // sets USE_PARALLEL_LCD or USE_SERIAL_LCD +# if defined(USE_SERIAL_LCD) LiquidCrystal_I2C myLCD(0x27, LCD_COLUMNS, LCD_ROWS); // set the LCD address to 0x27 for a 16 chars and 2 line display -#elif !defined(USE_NO_LCD) -#define USE_PARALLEL_LCD -#include "LiquidCrystal.h" +# else //LiquidCrystal myLCD(4, 5, 6, 7, 8, 9); LiquidCrystal myLCD(7, 8, 3, 4, 5, 6); +# endif +# if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) +// For cyclically display of VCC and isVCCUSBPowered() +#define VOLTAGE_USB_POWERED_LOWER_THRESHOLD_MILLIVOLT 4250 +#include "ADCUtils.hpp" +#define MILLIS_BETWEEN_VOLTAGE_PRINT 5000 +#define LCD_VOLTAGE_START_INDEX 11 +uint32_t volatile sMillisOfLastVoltagePrint = 0; +bool ProtocolStringOverwritesVoltage = false; +# endif +#define LCD_IR_COMMAND_START_INDEX 9 + +void printsVCCVoltageMillivoltOnLCD(); +void printIRResultOnLCD(); #endif #if defined(USE_PARALLEL_LCD) @@ -95,31 +115,13 @@ LiquidCrystal myLCD(7, 8, 3, 4, 5, 6); #else #define DEBUG_BUTTON_PIN 6 #endif -#define AUXILIARY_DEBUG_BUTTON_PIN 12 // Is set to low to enable using of a simple connector for enabling debug +#if defined(__AVR_ATmega328P__) +#define AUXILIARY_DEBUG_BUTTON_PIN 12 // Is set to low to enable using of a simple connector for enabling debug with pin 11 +#endif #define MILLIS_BETWEEN_ATTENTION_BEEP 60000 // 60 sec uint32_t sMillisOfLastReceivedIRFrame = 0; -#if defined(USE_SERIAL_LCD) || defined(USE_PARALLEL_LCD) -#define USE_LCD -# if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) -// For cyclically display of VCC -#include "ADCUtils.hpp" -#define MILLIS_BETWEEN_VOLTAGE_PRINT 5000 -#define LCD_VOLTAGE_START_INDEX 11 -uint32_t volatile sMillisOfLastVoltagePrint = 0; -bool ProtocolStringOverwritesVoltage = false; -# endif -#define LCD_IR_COMMAND_START_INDEX 9 - -#endif // defined(USE_SERIAL_LCD) || defined(USE_PARALLEL_LCD) - -void printIRResultOnLCD(); -size_t printByteHexOnLCD(uint16_t aHexByteValue); -void printSpacesOnLCD(uint_fast8_t aNumberOfSpacesToPrint); - -uint16_t sVCCMillivolt; - void setup() { #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP); @@ -130,7 +132,9 @@ void setup() { #endif Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino @@ -158,31 +162,37 @@ void setup() { #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. Serial.println(); - Serial.print(F("If you connect debug pin ")); -# if defined(APPLICATION_PIN_STRING) - Serial.print(APPLICATION_PIN_STRING); -# else - Serial.print(DEBUG_BUTTON_PIN); -# endif - Serial.print(F(" to ground or to pin ")); - Serial.print(AUXILIARY_DEBUG_BUTTON_PIN); - Serial.println(F(", raw data is always printed")); + if (digitalRead(DEBUG_BUTTON_PIN) != LOW) { + Serial.print(F("If you connect debug pin ")); + Serial.print(DEBUG_BUTTON_PIN); + Serial.print(F(" to ground")); +# if defined(AUXILIARY_DEBUG_BUTTON_PIN) + Serial.print(F(" or to pin ")); + Serial.print(AUXILIARY_DEBUG_BUTTON_PIN); +#endif + Serial.println(F(", raw data is always printed")); + } - // infos for receive + // Info for receive Serial.print(RECORD_GAP_MICROS); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); + +# if defined(USE_THRESHOLD_DECODER) + Serial.println(F("Threshold decoding is active and thus MARK_EXCESS_MICROS is set to 0")); +# else Serial.print(MARK_EXCESS_MICROS); Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); +# endif #endif -#if defined(USE_LCD) && defined(__AVR__) && defined(ADCSRA) && defined(ADATE) - getVCCVoltageMillivoltSimple(); // to initialize ADC mux and reference +#if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) + readVCCVoltageMillivolt(); #endif #if defined(USE_SERIAL_LCD) myLCD.init(); myLCD.clear(); - myLCD.backlight(); + myLCD.backlight(); // Switch backlight LED on #endif #if defined(USE_PARALLEL_LCD) myLCD.begin(LCD_COLUMNS, LCD_ROWS); // This also clears display @@ -196,7 +206,7 @@ void setup() { #endif #if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) - sVCCMillivolt = getVCCVoltageMillivoltSimple(); + readVCCVoltageMillivolt(); #endif } @@ -226,17 +236,18 @@ void loop() { } else { // play tone auto tStartMillis = millis(); - IrReceiver.stop(); +// IrReceiver.stopTimer(); // Not really required for Uno, but we then should use restartTimer(aMicrosecondsToAddToGapCounter) tone(TONE_PIN, 2200); if ((IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) #if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) - && sVCCMillivolt > 4222 + || isVCCUSBPowered() #endif - ) { - // Print more info, but only if we are connected to USB, i.e. VCC is > 4222 mV, because this may take to long to detect some fast repeats + ) { + // Print more info, but only if we are connected to USB, i.e. VCC is > 4300 mV, because this may take to long to detect some fast repeats IrReceiver.printIRSendUsage(&Serial); - IrReceiver.printIRResultRawFormatted(&Serial, false); // print ticks, this is faster :-) +// IrReceiver.printIRResultRawFormatted(&Serial, false); // print ticks, this is faster :-) + IrReceiver.printIRResultRawFormatted(&Serial); // print us, this is better to compare :-) } // Guarantee at least 5 millis for tone. decode starts 5 millis (RECORD_GAP_MICROS) after end of frame @@ -244,9 +255,7 @@ void loop() { while ((millis() - tStartMillis) < 5) ; noTone(TONE_PIN); - - // Restore IR timer. millis() - tStartMillis to compensate for stop of receiver. This enables a correct gap measurement. - IrReceiver.startWithTicksToAdd((millis() - tStartMillis) * (MICROS_IN_ONE_MILLI / MICROS_PER_TICK)); + IrReceiver.restartTimer(5000); // Restart IR timer. #if defined(USE_LCD) printIRResultOnLCD(); @@ -261,15 +270,22 @@ void loop() { } // if (IrReceiver.decode()) /* - * Check for attention every 10 minute, after the current measurement was finished + * Check if generating attention beep every minute, after the current measurement was finished */ - if (millis() - sMillisOfLastReceivedIRFrame >= MILLIS_BETWEEN_ATTENTION_BEEP) { + if ((millis() - sMillisOfLastReceivedIRFrame) >= MILLIS_BETWEEN_ATTENTION_BEEP +#if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) + && !isVCCUSBPowered() +#endif + ) { sMillisOfLastReceivedIRFrame = millis(); - IrReceiver.stop(); +#if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) + printsVCCVoltageMillivoltOnLCD(); +#endif +// IrReceiver.stopTimer(); // Not really required for Uno, but we then should use restartTimer(aMicrosecondsToAddToGapCounter) tone(TONE_PIN, 2200); delay(50); noTone(TONE_PIN); - IrReceiver.startWithTicksToAdd(50 * (MICROS_IN_ONE_MILLI / MICROS_PER_TICK)); + IrReceiver.restartTimer(50000); } #if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE) @@ -279,18 +295,25 @@ void loop() { * Periodically print VCC */ sMillisOfLastVoltagePrint = millis(); - sVCCMillivolt = getVCCVoltageMillivoltSimple(); - char tVoltageString[5]; - dtostrf(sVCCMillivolt / 1000.0, 4, 2, tVoltageString); - myLCD.setCursor(LCD_VOLTAGE_START_INDEX - 1, 0); - myLCD.print(' '); - myLCD.print(tVoltageString); - myLCD.print('V'); + readVCCVoltageMillivolt(); + printsVCCVoltageMillivoltOnLCD(); } #endif } +#if defined(USE_LCD) +void printsVCCVoltageMillivoltOnLCD() { +# if defined(ADC_UTILS_ARE_AVAILABLE) + char tVoltageString[5]; + dtostrf(sVCCVoltageMillivolt / 1000.0, 4, 2, tVoltageString); + myLCD.setCursor(LCD_VOLTAGE_START_INDEX - 1, 0); + myLCD.print(' '); + myLCD.print(tVoltageString); + myLCD.print('V'); +# endif +} + /* * LCD output for 1602 LCDs * 40 - 55 Milliseconds per initial output @@ -300,7 +323,6 @@ void loop() { * */ void printIRResultOnLCD() { -#if defined(USE_LCD) static uint16_t sLastProtocolIndex = 4711; static uint16_t sLastProtocolAddress = 4711; static uint16_t sLastCommand = 0; @@ -321,42 +343,45 @@ void printIRResultOnLCD() { // we overwrite the voltage -> clear rest of line and inhibit new printing of voltage ProtocolStringOverwritesVoltage = true; if (tProtocolStringLength < LCD_COLUMNS) { - printSpacesOnLCD(LCD_COLUMNS - tProtocolStringLength); + LCDPrintSpaces(&myLCD, LCD_COLUMNS - tProtocolStringLength); } } else { // Trigger printing of VCC in main loop sMillisOfLastVoltagePrint = 0; ProtocolStringOverwritesVoltage = false; - printSpacesOnLCD(LCD_VOLTAGE_START_INDEX - tProtocolStringLength); + LCDPrintSpaces(&myLCD, LCD_VOLTAGE_START_INDEX - tProtocolStringLength); } # else - printSpacesOnLCD(LCD_COLUMNS - tProtocolStringLength); + LCDPrintSpaces(&myLCD, LCD_COLUMNS - tProtocolStringLength); # endif } if (IrReceiver.decodedIRData.protocol == UNKNOWN) { /* - * Print number of bits received and microseconds of signal + * Print number of bits received and hash code + * "123 bit 5E7E4778" */ myLCD.setCursor(0, 1); - uint8_t tNumberOfBits = (IrReceiver.decodedIRData.rawDataPtr->rawlen + 1) / 2; + uint8_t tNumberOfBits = (IrReceiver.irparams.rawlen + 1) / 2; + uint_fast8_t tPrintedStringLength = myLCD.print(tNumberOfBits); // tPrintedStringLength = 1 to 3 + myLCD.print(F(" bit ")); // 5 characters + if (tNumberOfBits < 10) { - myLCD.print(' '); // padding space + myLCD.print(F("0x")); + tPrintedStringLength += 2; } - myLCD.print(tNumberOfBits); - myLCD.print(F(" bit ")); - uint_fast8_t tDurationStringLength = myLCD.print(IrReceiver.getTotalDurationOfRawData()); - myLCD.print(F(" \xE4s")); // \xE4 is micro symbol - printSpacesOnLCD(7 - tDurationStringLength); + tPrintedStringLength += myLCD.print(IrReceiver.decodedIRData.decodedRawData, HEX); // maximum is += 8; + LCDPrintSpaces(&myLCD, (LCD_COLUMNS - 5) - tPrintedStringLength); sLastProtocolAddress = 4711; - sLastCommand = 44711; + sLastCommand = 4711; } else { /* - * Print only if address has changed + * Protocol is know here + * Print address only if it has changed or is PULSE_DISTANCE or PULSE_WIDTH */ - if (sLastProtocolAddress != IrReceiver.decodedIRData.address) { - sLastProtocolAddress = IrReceiver.decodedIRData.address; + if (sLastProtocolAddress != IrReceiver.decodedIRData.address || IrReceiver.decodedIRData.protocol == PULSE_DISTANCE + || IrReceiver.decodedIRData.protocol == PULSE_WIDTH) { myLCD.setCursor(0, 1); /* @@ -364,16 +389,24 @@ void printIRResultOnLCD() { */ # if defined(DECODE_DISTANCE_WIDTH) if (IrReceiver.decodedIRData.protocol == PULSE_DISTANCE || IrReceiver.decodedIRData.protocol == PULSE_WIDTH) { + sLastProtocolAddress = 4711; // To enforce next print of address myLCD.print(F("[0]=0x")); uint_fast8_t tAddressStringLength = myLCD.print(IrReceiver.decodedIRData.decodedRawDataArray[0], HEX); - printSpacesOnLCD(LCD_COLUMNS - tAddressStringLength); - sLastCommand = 0; // to trigger restoration of "C=" string - return; // no command here + LCDPrintSpaces(&myLCD, LCD_COLUMNS - tAddressStringLength); + sLastCommand = 0; // to trigger restoration of "C=" string, if another protocol is received + /* + * No command here! + */ + return; + } else { # endif + sLastProtocolAddress = IrReceiver.decodedIRData.address; +// Serial.print(F("Print address 0x")); +// Serial.println(IrReceiver.decodedIRData.address, HEX); myLCD.print(F("A=")); - uint_fast8_t tAddressStringLength = printByteHexOnLCD(IrReceiver.decodedIRData.address); - printSpacesOnLCD((LCD_IR_COMMAND_START_INDEX - 2) - tAddressStringLength); + uint_fast8_t tAddressStringLength = LCDPrintHex(&myLCD, IrReceiver.decodedIRData.address); + LCDPrintSpaces(&myLCD, (LCD_IR_COMMAND_START_INDEX - 2) - tAddressStringLength); # if defined(DECODE_DISTANCE_WIDTH) } # endif @@ -403,8 +436,12 @@ void printIRResultOnLCD() { /* * Command data */ +// Serial.print(F("Print command 0x")); +// Serial.print(tCommand, HEX); +// Serial.print(F(" at ")); +// Serial.println(sLastCommandPrintPosition); myLCD.setCursor(sLastCommandPrintPosition, 1); - printByteHexOnLCD(tCommand); + LCDPrintHex(&myLCD, tCommand); /* * Show or clear repetition flag @@ -416,23 +453,5 @@ void printIRResultOnLCD() { myLCD.print(' '); } } // IrReceiver.decodedIRData.protocol == UNKNOWN -#endif // defined(USE_LCD) -} - -#if defined(USE_LCD) -size_t printByteHexOnLCD(uint16_t aHexByteValue) { - myLCD.print(F("0x")); - size_t tPrintSize = 2; - if (aHexByteValue < 0x10 || (aHexByteValue > 0x100 && aHexByteValue < 0x1000)) { - myLCD.print('0'); // leading 0 - tPrintSize++; - } - return myLCD.print(aHexByteValue, HEX) + tPrintSize; -} - -void printSpacesOnLCD(uint_fast8_t aNumberOfSpacesToPrint) { - for (uint_fast8_t i = 0; i < aNumberOfSpacesToPrint; ++i) { - myLCD.print(' '); - } } -#endif +#endif // defined(USE_LCD) diff --git a/examples/AllProtocolsOnLCD/LCDPrintUtils.hpp b/examples/AllProtocolsOnLCD/LCDPrintUtils.hpp new file mode 100644 index 000000000..84b78300b --- /dev/null +++ b/examples/AllProtocolsOnLCD/LCDPrintUtils.hpp @@ -0,0 +1,397 @@ +/* + * LCDPrintUtils.hpp + * + * Contains LCD related variables and functions + * Sets symbols USE_SERIAL_LCD or USE_PARALLEL_LCD and LCD_COLUMNS and LCD_ROWS + * + * Copyright (C) 2024-2025 Armin Joachimsmeyer + * + * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. + * + * Arduino-Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _LCD_PRINT_UTILS_HPP +#define _LCD_PRINT_UTILS_HPP + +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development + +//#define USE_PARALLEL_2004_LCD // Is default +//#define USE_PARALLEL_1602_LCD +//#define USE_SERIAL_2004_LCD +//#define USE_SERIAL_1602_LCD + +#if !defined(USE_PARALLEL_2004_LCD) && !defined(USE_PARALLEL_1602_LCD) && !defined(USE_SERIAL_2004_LCD) && !defined(USE_SERIAL_1602_LCD) +#warning "No LCD type like USE_SERIAL_2004_LCD specified, therefore using USE_PARALLEL_2004_LCD as default" +#define USE_PARALLEL_2004_LCD // Use parallel 2004 LCD as default +#endif + +#if defined(USE_PARALLEL_2004_LCD) || defined(USE_PARALLEL_1602_LCD) +#define USE_PARALLEL_LCD +#include "LiquidCrystal.h" +#else +#define USE_SERIAL_LCD +#include "LiquidCrystal_I2C.hpp" // Here we use an enhanced version, which supports SoftI2CMaster +#endif + +#if defined(USE_PARALLEL_1602_LCD) || defined(USE_SERIAL_1602_LCD) +#define LCD_COLUMNS 16 +#define LCD_ROWS 2 +#else +#define LCD_COLUMNS 20 +#define LCD_ROWS 4 +#endif + +// Helper macro for getting a macro definition as string +#if !defined(STR_HELPER) && !defined(STR) +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) +#endif + +#define DEGREE_SIGN_STRING "\xDF" + +extern char sStringBuffer[]; // For rendering a LCD row with snprintf_P() + +#if defined(USE_PARALLEL_LCD) +void LCDResetCursor(LiquidCrystal *aLCD); +void LCDPrintSpaces(LiquidCrystal *aLCD, uint_fast8_t aNumberOfSpacesToPrint); +void LCDClearLine(LiquidCrystal *aLCD, uint_fast8_t aLineNumber); // Cursor is a start of line +size_t LCDPrintHex(LiquidCrystal *aLCD, uint16_t aHexByteValue); +void LCDPrintAsFloatAs5CharacterString_2_3_Decimals(LiquidCrystal *aLCD, uint16_t aValueInMilliUnits); +void LCDPrintFloatValueRightAligned(LiquidCrystal *aLCD, float aFloatValue, uint8_t aNumberOfCharactersToPrint, + bool aNoLeadingSpaceForPositiveValues = false); +void LCDUnitTestPrintFloatValueRightAligned(Print *aSerial, LiquidCrystal *aLCD); +void LCDShowSpecialCharacters(LiquidCrystal *aLCD); +void LCDShowCustomCharacters(LiquidCrystal *aLCD); +#else +void LCDResetCursor(LiquidCrystal_I2C *aLCD); +void LCDPrintSpaces(LiquidCrystal_I2C *aLCD, uint_fast8_t aNumberOfSpacesToPrint); +void LCDClearLine(LiquidCrystal_I2C *aLCD, uint_fast8_t aLineNumber); +size_t LCDPrintHex(LiquidCrystal_I2C *aLCD, uint16_t aHexByteValue); +void LCDPrintAsFloatAs5CharacterString_2_3_Decimals(LiquidCrystal_I2C *aLCD, uint16_t aValueInMillivolts); +void LCDPrintFloatValueRightAligned(LiquidCrystal_I2C *aLCD, float aFloatValue, uint8_t aNumberOfCharactersToPrint, + bool aNoLeadingSpaceForPositiveValues = false); +void LCDTestPrintFloatValueRightAligned(LiquidCrystal_I2C *aLCD); +void LCDShowSpecialCharacters(LiquidCrystal_I2C *aLCD); +void LCDShowCustomCharacters(LiquidCrystal_I2C *aLCD); +#endif +uint8_t getNumberOfDecimalsFor16BitValues(uint16_t a16BitValue); + +/* + * Code starts here + */ + +#if defined(USE_PARALLEL_LCD) +void LCDResetCursor(LiquidCrystal *aLCD) +#else +void LCDResetCursor(LiquidCrystal_I2C *aLCD) +#endif + { + aLCD->setCursor(0, 0); +} + +#if defined(USE_PARALLEL_LCD) +void LCDPrintSpaces(LiquidCrystal *aLCD, uint_fast8_t aNumberOfSpacesToPrint) +#else +void LCDPrintSpaces(LiquidCrystal_I2C *aLCD, uint_fast8_t aNumberOfSpacesToPrint) +#endif + { + for (uint_fast8_t i = 0; i < aNumberOfSpacesToPrint; ++i) { + aLCD->print(' '); + } +} + +#if defined(USE_PARALLEL_LCD) +void LCDClearLine(LiquidCrystal *aLCD, uint_fast8_t aLineNumber) +#else +void LCDClearLine(LiquidCrystal_I2C *aLCD, uint_fast8_t aLineNumber) +#endif + { + aLCD->setCursor(0, aLineNumber); + LCDPrintSpaces(aLCD, LCD_COLUMNS); + aLCD->setCursor(0, aLineNumber); +} + +#if defined(USE_PARALLEL_LCD) +size_t LCDPrintHex(LiquidCrystal *aLCD, uint16_t aHexByteValue) +#else +size_t LCDPrintHex(LiquidCrystal_I2C *aLCD, uint16_t aHexByteValue) +#endif + { + aLCD->print(F("0x")); + size_t tPrintSize = 2; + if (aHexByteValue < 0x10 || (aHexByteValue > 0x100 && aHexByteValue < 0x1000)) { + aLCD->print('0'); // leading 0 + tPrintSize++; + } + return aLCD->print(aHexByteValue, HEX) + tPrintSize; +} + +/* + * Use 2 decimals, if value is >= 10 + */ +#if defined(USE_PARALLEL_LCD) +void LCDPrintAsFloatAs5CharacterString_2_3_Decimals(LiquidCrystal *aLCD, uint16_t aValueInMilliUnits) +#else +void LCDPrintAsFloatAs5CharacterString_2_3_Decimals(LiquidCrystal_I2C *aLCD, uint16_t aValueInMilliUnits) +#endif + { + if (aValueInMilliUnits < 10000) { + aLCD->print(((float) (aValueInMilliUnits)) / 1000, 3); + } else { + aLCD->print(((float) (aValueInMilliUnits)) / 1000, 2); + } +} + +/* + * @return 1 for values from 0 to 9, 2 for 10 to 99 up to 5 for >= 10,000 + */ +uint8_t getNumberOfDecimalsFor16BitValues(uint16_t a16BitValue) { + uint16_t tCompareValue = 1; + /* + * Check for 10, 100, 1000 + */ + for (uint_fast8_t tNumberOfDecimals = 0; tNumberOfDecimals < 5; ++tNumberOfDecimals) { + if (a16BitValue < tCompareValue) { + return tNumberOfDecimals; + } + tCompareValue *= 10; + } + // here we have values >= 10,000 + return 5; +} + +/* + * @return 1 for values from 0 to 9, 2 for 10 to 99 up to 10 for >= 1,000,000,000 + * Requires 26 bytes more program space than getNumberOfDecimalsFor16BitValues() + */ +uint8_t getNumberOfDecimalsFor32BitValues(uint32_t a32BitValue) { + uint_fast8_t tNumberOfDecimals = 1; + uint32_t tCompareValue = 10; + /* + * Check for 10, 100, 1000 up to 100,000,000 + */ + for (; tNumberOfDecimals < 10; ++tNumberOfDecimals) { + if (a32BitValue < tCompareValue) { + return tNumberOfDecimals; + } + tCompareValue *= 10; + } + // here we have values >= 1,000,000,000 + return 10; +} +/* + * !!! We internally use uint16_t, thus for bigger values (> 65,536 or < -65,536) we have an overflow. + * @param aNoLeadingSpaceForPositiveValues - Normally each positive value has a leading space as placeholder for the minus sign. + * If we know, that values are always positive, this space can be omitted by aNoLeadingSpaceForPositiveValues == true. + * @param aNumberOfCharactersToPrint - The characters to be used for the most negative value to show. !!! MUST BE < 8, This is NOT checked!!! + * I.e. 4 => max negative value is "-999" max positive value is " 999". + * Values below 10 and -10 are displayed as floats with decimal point " 9.9" and "-9.9". + * Values below 1 and -1 are displayed as floats without 0 before decimal point " .9" and "-.9". + * If positive, there is a leading space, which improves readability if directly concatenated to another value. + * e.g. "71V1.189A" is not readable, "71V 1.18A" is as well as "71V-1.18A". + * + * Saves programming space if used more than 1 times for printing floats if used instead of myLCD.print(JKComputedData.BatteryVoltageFloat, 2); + */ +#if defined(USE_PARALLEL_LCD) +void LCDPrintFloatValueRightAligned(LiquidCrystal *aLCD, float aFloatValue, uint8_t aNumberOfCharactersToPrint, + bool aNoLeadingSpaceForPositiveValues) +#else +void LCDPrintFloatValueRightAligned(LiquidCrystal_I2C *aLCD, float aFloatValue, uint8_t aNumberOfCharactersToPrint, + bool aNoLeadingSpaceForPositiveValues) +#endif + { + + uint8_t tNumberOfDecimals = getNumberOfDecimalsFor16BitValues(abs(aFloatValue)); // remove sign for length computation + int8_t tNumberOfDecimalPlaces = (aNumberOfCharactersToPrint - 2) - tNumberOfDecimals; + if (aNoLeadingSpaceForPositiveValues && aFloatValue >= 0) { + tNumberOfDecimalPlaces++; // Use this increased value internally, since we do not eventually print the '-' + } +#if defined(LOCAL_DEBUG) + Serial.print(F("NumberOfDecimalPlaces(")); + Serial.print(tNumberOfDecimals); + Serial.print(F(", ")); + Serial.print(aNumberOfCharactersToPrint); + Serial.print(F(")=")); + Serial.print(tNumberOfDecimalPlaces); + Serial.print(F(" NumberOfDecimals=")); + Serial.println(tNumberOfDecimals); +#endif + if (tNumberOfDecimalPlaces < 0) { + tNumberOfDecimalPlaces = 0; + } + + char tStringBuffer[9]; // For aNumberOfCharactersToPrint up to 8 + uint8_t tStartIndex = 0; + if (tNumberOfDecimals == 0 && tNumberOfDecimalPlaces > 0) { + if (aFloatValue >= 0) { + if (!aNoLeadingSpaceForPositiveValues) { + aLCD->print(' '); + } + tStartIndex = 1; + } else { + aLCD->print('-'); + tStartIndex = 2; + } + } +#if defined(__AVR__) + dtostrf(aFloatValue, aNumberOfCharactersToPrint, tNumberOfDecimalPlaces, tStringBuffer); +#else + snprintf(sStringBuffer, sizeof(tStringBuffer), "%f", aFloatValue); +#endif + aLCD->print(&tStringBuffer[tStartIndex]); +} +/** + * Unit test for LCDPrintFloatValueRightAligned() + * @param aSerial + * @param aLCD + */ +#if defined(USE_PARALLEL_LCD) +void LCDUnitTestPrintFloatValueRightAligned(Print *aSerial, LiquidCrystal *aLCD) +#else +void LCDUnitTestPrintFloatValueRightAligned(Print *aSerial, LiquidCrystal_I2C *aLCD) +#endif + { + aSerial->println(F("LCDTestPrintFloatValueRightAligned: 1.")); + + aLCD->clear(); + float tTestValue = 123.45; + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4); // no leading space here + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3); // no leading space here + // Result=" 123.4 123 123123" + + aLCD->setCursor(0, 1); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 6); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 5); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 4); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 3); // requires also 5 character + // Result="-123.4 -123-123-123" + + aLCD->setCursor(0, 2); + tTestValue = -1.234; + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 2); + // Result="-1.234-1.23-1.2 -1-1" + + aLCD->setCursor(0, 3); + tTestValue = -0.1234; + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 2); + // Result="-.1234-.123-.12-.1-0" + + delay(4000); + aSerial->println(F("LCDTestPrintFloatValueRightAligned: 2.")); + + aLCD->clear(); + tTestValue = 123.45; + // no leading space here + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3, true); + // Result="123.45123.4 123123" + + aLCD->setCursor(0, 1); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 6, true); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 5, true); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 4, true); + LCDPrintFloatValueRightAligned(aLCD, -tTestValue, 3, true); + // Result="-123.4 -123-123-123" + + tTestValue = 1.2344; // .12345 leads to rounding up for .1235 + aLCD->setCursor(0, 2); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 2, true); + // Result="1.23441.2341.231.2 1" + + tTestValue = 0.12344; // .12345 leads to rounding up for .1235 + aLCD->setCursor(0, 3); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 6, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 5, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 4, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 3, true); + LCDPrintFloatValueRightAligned(aLCD, tTestValue, 2, true); + // Result=".12344.1234.123.12.1" + + delay(4000); + aSerial->println(F("LCDTestPrintFloatValueRightAligned: End")); +} + +/* + * On my 2004 LCD the custom characters are available under 0 to 7 and mirrored to 8 to 15 + * The characters 0x80 to 0x8F are blanks + */ +#if defined(USE_PARALLEL_LCD) +void LCDShowSpecialCharacters(LiquidCrystal *aLCD) +#else +void LCDShowSpecialCharacters(LiquidCrystal_I2C *aLCD) +#endif + { + aLCD->setCursor(0, 0); + // 0 to 7 are mirrored to 8 to 15 as described in datasheet + for (uint_fast8_t i = 0; i < 0x8; ++i) { + aLCD->write(i); + } + // Print some interesting characters + aLCD->write(0xA1); + aLCD->write(0xA5); + aLCD->write(0xB0); + aLCD->write(0xDB); + aLCD->write(0xDF); + + aLCD->setCursor(0, 1); + // The characters 0x10 to 0x1F seem to be all blanks => ROM Code: A00 + for (uint_fast8_t i = 0x10; i < 0x20; ++i) { + aLCD->write(i); + } + aLCD->setCursor(0, 2); + // The characters 0x80 to 0x8F seem to be all blanks => ROM Code: A00 + for (uint_fast8_t i = 0x80; i < 0x90; ++i) { + aLCD->write(i); + } + aLCD->setCursor(0, 3); + // The characters 0x90 to 0x9F seem to be all blanks => ROM Code: A00 + for (uint_fast8_t i = 0x90; i < 0xA0; ++i) { + aLCD->write(i); + } + delay(2000); +} + +#if defined(USE_PARALLEL_LCD) +void LCDShowCustomCharacters(LiquidCrystal *aLCD) +#else +void LCDShowCustomCharacters(LiquidCrystal_I2C *aLCD) +#endif + { + aLCD->setCursor(0, 0); + for (uint_fast8_t i = 0; i < 0x08; ++i) { + aLCD->write(i); + } +} + +#if defined(LOCAL_DEBUG) +#undef LOCAL_DEBUG +#endif +#endif // _LCD_PRINT_UTILS_HPP diff --git a/examples/AllProtocolsOnLCD/LiquidCrystal.cpp b/examples/AllProtocolsOnLCD/LiquidCrystal.cpp index 5dcef0838..240524a95 100644 --- a/examples/AllProtocolsOnLCD/LiquidCrystal.cpp +++ b/examples/AllProtocolsOnLCD/LiquidCrystal.cpp @@ -5,6 +5,20 @@ #include #include "Arduino.h" +#if defined(__AVR__) +/* + * The datasheet says: a command need > 37us to settle. + * Use a delay of 2 us instead of 100 us after each command, + * because the overhead of this library seems to be using the other 35 us. + * At least it works perfectly for all my LCD's connected to Uno, Nano etc. + * and it saves a lot of time in realtime applications using LCD as display, + * like https://github.com/ArminJo/Arduino-DTSU666H_PowerMeter + */ +# if !defined(DO_NOT_USE_FAST_LCD_TIMING) +#define USE_FAST_LCD_TIMING +# endif +#endif + // When the display powers up, it is configured as follows: // // 1. Display clear @@ -21,7 +35,7 @@ // S = 0; No shift // // Note, however, that resetting the Arduino doesn't reset the LCD, so we -// can't assume that its in that state when a sketch starts (and the +// can't assume that it is in that state when a sketch starts (and the // LiquidCrystal constructor is called). LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, @@ -72,7 +86,7 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - begin(16, 1); + begin(16, 1); // initializing for a 1601 LCD, but the user must call begin() with the right values at startup. Outcommenting increases program size } void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { @@ -262,12 +276,14 @@ void LiquidCrystal::noAutoscroll(void) { // Allows us to fill the first 8 CGRAM locations // with custom characters +// This also sets cursor to 0.0 void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) { location &= 0x7; // we only have 8 locations 0-7 command(LCD_SETCGRAMADDR | (location << 3)); for (int i=0; i<8; i++) { write(charmap[i]); } + // command(LCD_SETDDRAMADDR); // set cursor to 0.0, this avoids overwriting CGRAM by next write() command. Not contained anymore in the Arduino version } /*********** mid level commands, for sending data/cmds */ @@ -278,7 +294,7 @@ inline void LiquidCrystal::command(uint8_t value) { inline size_t LiquidCrystal::write(uint8_t value) { send(value, HIGH); - return 1; // assume sucess + return 1; // assume success } /************ low level data pushing commands **********/ @@ -306,7 +322,11 @@ void LiquidCrystal::pulseEnable(void) { digitalWrite(_enable_pin, HIGH); delayMicroseconds(1); // enable pulse must be >450ns digitalWrite(_enable_pin, LOW); +#if defined(USE_FAST_LCD_TIMING) + delayMicroseconds(2); // commands need > 37us to settle +#else delayMicroseconds(100); // commands need > 37us to settle +#endif } void LiquidCrystal::write4bits(uint8_t value) { diff --git a/examples/AllProtocolsOnLCD/LiquidCrystal_I2C.cpp b/examples/AllProtocolsOnLCD/LiquidCrystal_I2C.hpp similarity index 87% rename from examples/AllProtocolsOnLCD/LiquidCrystal_I2C.cpp rename to examples/AllProtocolsOnLCD/LiquidCrystal_I2C.hpp index f89c98109..d8de0ef42 100644 --- a/examples/AllProtocolsOnLCD/LiquidCrystal_I2C.cpp +++ b/examples/AllProtocolsOnLCD/LiquidCrystal_I2C.hpp @@ -1,9 +1,20 @@ +// LiquidCrystal_I2C.hpp // Based on the work by DFRobot +/* + * Extensions made by AJ 2023 + * Removed Arduino 0.x support + * Added SoftI2CMaste support, which drastically reduces program size. + * Added OLED stuff + * Added createChar() with PROGMEM input + * Added fast timing + */ +#ifndef _LIQUID_CRYSTAL_I2C_HPP +#define _LIQUID_CRYSTAL_I2C_HPP #include "Arduino.h" #if defined(__AVR__) && !defined(USE_SOFT_I2C_MASTER) && __has_include("SoftI2CMasterConfig.h") -#define USE_SOFT_I2C_MASTER // must be before #include "LiquidCrystal_I2C.h" +#define USE_SOFT_I2C_MASTER // must be before #include "LiquidCrystal_I2C.hpp" #endif #include "LiquidCrystal_I2C.h" @@ -23,6 +34,18 @@ inline size_t LiquidCrystal_I2C::write(uint8_t value) { #include "SoftWire.h" #endif +#if defined(__AVR__) +/* + * The datasheet says: a command need > 37us to settle. Enable pulse must be > 450ns. + * Use no delay for enable pulse after each command, + * because the overhead of this library seems to be using the 37 us and 450 ns. + * At least it works perfectly for all my LCD's connected to Uno, Nano etc. + * and it saves a lot of time in realtime applications using LCD as display, + * like https://github.com/ArminJo/Arduino-DTSU666H_PowerMeter + */ +#define USE_FAST_TIMING +#endif + // When the display powers up, it is configured as follows: // // 1. Display clear @@ -131,7 +154,11 @@ void LiquidCrystal_I2C::begin(uint8_t cols __attribute__((unused)), uint8_t line /********** high level commands, for the user! */ void LiquidCrystal_I2C::clear() { command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero +#if defined(USE_FAST_TIMING) + delayMicroseconds(1500); // this command takes a long time! // AJ 20.9.23 1200 is too short for my 2004 LCD's, 1400 is OK +#else delayMicroseconds(2000); // this command takes a long time! +#endif if (_oled) setCursor(0, 0); } @@ -274,10 +301,13 @@ void LiquidCrystal_I2C::expanderWrite(uint8_t _data) { void LiquidCrystal_I2C::pulseEnable(uint8_t _data) { expanderWrite(_data | En); // En high - delayMicroseconds(1); // enable pulse must be >450ns - +#if !defined(USE_FAST_TIMING) + delayMicroseconds(1); // enable pulse must be > 450ns // AJ 20.9.23 not required for my LCD's +#endif expanderWrite(_data & ~En); // En low - delayMicroseconds(50); // commands need > 37us to settle +#if !defined(USE_FAST_TIMING) + delayMicroseconds(50); // commands need > 37us to settle // AJ 20.9.23 not required for my LCD's +#endif } // Alias functions @@ -342,3 +372,4 @@ void LiquidCrystal_I2C::setContrast(uint8_t new_val) { } #pragma GCC diagnostic pop +#endif // _LIQUID_CRYSTAL_I2C_HPP diff --git a/examples/AllProtocolsOnLCD/PinDefinitionsAndMore.h b/examples/AllProtocolsOnLCD/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/AllProtocolsOnLCD/PinDefinitionsAndMore.h +++ b/examples/AllProtocolsOnLCD/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SimpleReceiverWithCallback/SimpleReceiverWithCallback.ino b/examples/CallbackDemo/CallbackDemo.ino similarity index 67% rename from examples/SimpleReceiverWithCallback/SimpleReceiverWithCallback.ino rename to examples/CallbackDemo/CallbackDemo.ino index 3c1a3f40a..05342d827 100644 --- a/examples/SimpleReceiverWithCallback/SimpleReceiverWithCallback.ino +++ b/examples/CallbackDemo/CallbackDemo.ino @@ -1,14 +1,15 @@ /* - * SimpleReceiverWithCallback.cpp + * CallbackDemo.cpp * - * Demonstrates receiving NEC IR codes with IRrecv + * Demonstrates receiving NEC IR codes with IRrecv using callback function + * Based on SimpleReceiver example * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2022 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -37,8 +38,7 @@ */ //#define DECODE_DENON // Includes Sharp //#define DECODE_JVC -//#define DECODE_KASEIKYO -//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO +//#define DECODE_KASEIKYO // Includes Panasonic ~ 640 bytes //#define DECODE_LG #define DECODE_NEC // Includes Apple and Onkyo //#define DECODE_SAMSUNG @@ -59,34 +59,38 @@ //#define DEBUG // Activate this for lots of lovely debug output from the decoders. -//#define RAW_BUFFER_LENGTH 180 // Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +//#define RAW_BUFFER_LENGTH 750 // For air condition remotes it may require up to 750. Default is 200. #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include /* - * For callback + * Callback specific variables and functions */ -#define PROCESS_IR_RESULT_IN_MAIN_LOOP -#if defined(PROCESS_IR_RESULT_IN_MAIN_LOOP) || defined(ARDUINO_ARCH_MBED) || defined(ESP32) volatile bool sIRDataJustReceived = false; -#endif void ReceiveCompleteCallbackHandler(); void setup() { Serial.begin(115200); + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); + + /* + * Tell the ISR to call this function, when a complete frame has been received + */ IrReceiver.registerReceiveCompleteCallback(ReceiveCompleteCallbackHandler); Serial.print(F("Ready to receive IR signals of protocols: ")); - printActiveIRProtocols (&Serial); + printActiveIRProtocols(&Serial); Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); + Serial.print(F("Using callback function for processing received data")); + } void loop() { @@ -94,17 +98,24 @@ void loop() { * Print in loop (interrupts are enabled here) if received data is available. */ if (sIRDataJustReceived) { - // Print a short summary of received data - IrReceiver.printIRResultShort(&Serial); - IrReceiver.printIRSendUsage(&Serial); + sIRDataJustReceived = false; + /* + * Print info of the received data + */ if (IrReceiver.decodedIRData.protocol == UNKNOWN) { Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); /* * We have an unknown protocol here, print more info. - * !!!Attention!!! This prints incorrect values, if we are late (not in this simple example :-)) - * and the the first mark of the next (repeat) data was yet received + * This will print incorrect timing values, if we are late (not in this simple example :-)) + * and the the first mark of the next (repeat) data was yet received. + * Therefore we first test for this condition. */ - IrReceiver.printIRResultRawFormatted(&Serial, true); // + if (!IrReceiver.isIdle()) { + IrReceiver.printIRResultRawFormatted(&Serial, true); + } + } else { + IrReceiver.printIRResultShort(&Serial); + IrReceiver.printIRSendUsage(&Serial); } Serial.println(); } @@ -113,17 +124,30 @@ void loop() { /* * Callback function * Here we know, that data is available. - * This function is executed in ISR (Interrupt Service Routine) context (interrupts are blocked here). - * Make it short and fast and keep in mind, that you can not use delay(), prints longer than print buffer size etc., - * because they require interrupts enabled to return. - * In order to enable other interrupts you can call sei() (enable interrupt again) after evaluating/copying data. - * Good practice, but somewhat more complex, is to copy relevant data and signal receiving to main loop. + * This function is executed in an ISR (Interrupt Service Routine) context. + * This means that interrupts are blocked here, so delay(), millis() and Serial prints of data longer than the print buffer size etc. will block forever. + * This is because they require their internal interrupt routines to run in order to return. + * Therefore it is best to make this callback function short and fast! + * A dirty hack is to enable interrupts again by calling sei() (enable interrupt again), but you should know what you are doing, + * + * A good practice -but somewhat more complex- is to perform small and time critical actions in the callback function, + * copy the relevant data to local variables and signal the receiving to main loop, which in turn processes this data. + * This is similar to simply using "if (IrReceiver.decode())", but has the advantage, + * that it does not block the receiving of the next IR frame, until the main loop reaches this statement. */ #if defined(ESP32) || defined(ESP8266) IRAM_ATTR # endif void ReceiveCompleteCallbackHandler() { - IrReceiver.decode(); // fill IrReceiver.decodedIRData + /* + * Fill IrReceiver.decodedIRData + */ + IrReceiver.decode(); + + /* + * Enable receiving of the next frame. + */ + IrReceiver.resume(); /* * Check the received data and perform actions according to the received command @@ -145,14 +169,4 @@ void ReceiveCompleteCallbackHandler() { * running in ISR (Interrupt Service Routine) context where interrupts are disabled. */ sIRDataJustReceived = true; - - /* - * Enable receiving of the next value. - * !!!Attention!!! - * After receiving the first mark of the next (repeat) data, 3 variables required for printing are reset/overwritten. - * - IrReceiver.irparams.rawlen - * - IrReceiver.irparams.rawbuf[0] - * - IrReceiver.irparams.OverflowFlag) - */ - IrReceiver.resume(); } diff --git a/examples/SimpleReceiverWithCallback/PinDefinitionsAndMore.h b/examples/CallbackDemo/PinDefinitionsAndMore.h similarity index 71% rename from examples/SimpleReceiverWithCallback/PinDefinitionsAndMore.h rename to examples/CallbackDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SimpleReceiverWithCallback/PinDefinitionsAndMore.h +++ b/examples/CallbackDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ControlRelay/ControlRelay.ino b/examples/ControlRelay/ControlRelay.ino index 1460872f4..a475c6771 100644 --- a/examples/ControlRelay/ControlRelay.ino +++ b/examples/ControlRelay/ControlRelay.ino @@ -33,9 +33,9 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. -#if FLASHEND <= 0x1FFF || (RAMEND <= 0x4FF || RAMSIZE < 0x4FF) // For 8k flash or 512 bytes RAM or less, like ATtiny85, ATtiny167 +#if FLASHEND <= 0x1FFF || RAMSIZE <= 0x400 // For 8k flash or 512 bytes RAM or less, like ATtiny85, ATtiny167 #define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. #define EXCLUDE_EXOTIC_PROTOCOLS #endif @@ -53,7 +53,9 @@ void setup() { pinMode(RELAY_PIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino diff --git a/examples/ControlRelay/PinDefinitionsAndMore.h b/examples/ControlRelay/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ControlRelay/PinDefinitionsAndMore.h +++ b/examples/ControlRelay/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/IRDispatcherDemo/DemoIRCommandMapping.h b/examples/IRDispatcherDemo/DemoIRCommandMapping.h index 26110da23..38b344752 100644 --- a/examples/IRDispatcherDemo/DemoIRCommandMapping.h +++ b/examples/IRDispatcherDemo/DemoIRCommandMapping.h @@ -1,10 +1,25 @@ /* * DemoIRCommandMapping.h * - * IR remote button codes, strings, and functions to call + * Contains IR remote button codes, strings, and the mapping of codes to functions to call by the dispatcher * - * Copyright (C) 2019-2022 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2019-2026 Armin Joachimsmeyer + * + * This file is part of IRMP https://github.com/IRMP-org/IRMP. + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * IRMP is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * */ @@ -12,15 +27,16 @@ #define _IR_COMMAND_MAPPING_H #include -//#include "Commands.h" // includes all the commands used in the mapping arrays below + +#include "IRCommandDispatcher.h" // IRToCommandMappingStruct, IR_COMMAND_FLAG_BLOCKING etc. are defined here /* * !!! Choose your remote !!! */ -//#define USE_KEYES_REMOTE_CLONE With number pad and direction control switched, will be taken as default +//#define USE_KEYES_REMOTE_CLONE With number pad and direction control swapped, will be taken as default //#define USE_KEYES_REMOTE #if !defined(USE_KEYES_REMOTE) && !defined(USE_KEYES_REMOTE_CLONE) -#define USE_KEYES_REMOTE_CLONE // the one you can buy at aliexpress +#define USE_KEYES_REMOTE_CLONE // the one you can buy at Aliexpress #endif #if (defined(USE_KEYES_REMOTE) && defined(USE_KEYES_REMOTE_CLONE)) @@ -30,11 +46,7 @@ #if defined(USE_KEYES_REMOTE_CLONE) #define IR_REMOTE_NAME "KEYES_CLONE" // Codes for the KEYES CLONE remote control with 17 keys with number pad above direction control -#if defined(USE_IRMP_LIBRARY) -#define IR_ADDRESS 0xFF00 // IRMP interprets NEC addresses always as 16 bit -#else #define IR_ADDRESS 0x00 -#endif #define IR_UP 0x18 #define IR_DOWN 0x52 @@ -88,11 +100,7 @@ * IR code to button mapping for better reading. IR codes should only referenced here. */ // Codes for the KEYES remote control with 17 keys and direction control above number pad -#if defined(USE_IRMP_LIBRARY) -#define IR_ADDRESS 0xFF00 // IRMP interprets NEC addresses always as 16 bit -#else #define IR_ADDRESS 0x00 -#endif #define IR_UP 0x46 #define IR_DOWN 0x15 @@ -144,7 +152,7 @@ * Main mapping of commands to C functions */ -// IR strings of functions for output +// Strings of commands for Serial output static const char LEDon[] PROGMEM ="LED on"; static const char LEDoff[] PROGMEM ="LED off"; @@ -161,33 +169,33 @@ static const char printMenu[] PROGMEM ="printMenu"; static const char reset[] PROGMEM ="reset"; static const char stop[] PROGMEM ="stop"; -// not used yet -static const char test[] PROGMEM ="test"; -static const char pattern[] PROGMEM ="pattern"; -static const char unknown[] PROGMEM ="unknown"; - /* * Main mapping array of commands to C functions and command strings + * The macro COMMAND_STRING() removes the strings from memory, if USE_DISPATCHER_COMMAND_STRINGS is not enabled */ const struct IRToCommandMappingStruct IRMapping[] = { /**/ -{ COMMAND_BLINK, IR_COMMAND_FLAG_BLOCKING, &doLedBlink20times, blink20times }, /**/ -{ COMMAND_STOP, IR_COMMAND_FLAG_BLOCKING, &doStop, stop }, +{ COMMAND_BLINK, IR_COMMAND_FLAG_BLOCKING | IR_COMMAND_FLAG_BEEP, &doLedBlink20times, COMMAND_STRING(blink20times) }, /**/ +{ COMMAND_STOP, IR_COMMAND_FLAG_BLOCKING, &doStop, COMMAND_STRING(stop) }, /* */ + +/* + * Short commands that can always be executed, but must be able to terminate other blocking commands (only doLedBlink20times() in this example) + */ +{ COMMAND_START, IR_COMMAND_FLAG_BLOCKING, &doLedBlinkStart, COMMAND_STRING(blinkStart) }, /**/ +{ COMMAND_ON, IR_COMMAND_FLAG_BLOCKING, &doLedOn, COMMAND_STRING(LEDon) }, /**/ +{ COMMAND_OFF, IR_COMMAND_FLAG_BLOCKING, &doLedOff, COMMAND_STRING(LEDoff) }, /**/ /* - * Short commands, which can be executed always + * Short commands that can always be executed */ -{ COMMAND_TONE1, IR_COMMAND_FLAG_BLOCKING, &doTone1800, tone1800 }, /**/ -{ COMMAND_TONE3, IR_COMMAND_FLAG_BLOCKING, &doPrintMenu, printMenu }, /**/ -{ COMMAND_ON, IR_COMMAND_FLAG_NON_BLOCKING, &doLedOn, LEDon }, /**/ -{ COMMAND_OFF, IR_COMMAND_FLAG_NON_BLOCKING, &doLedOff, LEDoff }, /**/ -{ COMMAND_START, IR_COMMAND_FLAG_NON_BLOCKING, &doLedBlinkStart, blinkStart }, /**/ -{ COMMAND_RESET, IR_COMMAND_FLAG_NON_BLOCKING, &doResetBlinkFrequency, reset }, +{ COMMAND_TONE1, IR_COMMAND_FLAG_NON_BLOCKING, &doTone1800, COMMAND_STRING(tone1800) }, /* Lasts 200 ms and blocks receiving of repeats. tone() requires interrupts enabled */ +{ COMMAND_TONE3, IR_COMMAND_FLAG_NON_BLOCKING, &doPrintMenu, COMMAND_STRING(printMenu) }, /**/ +{ COMMAND_RESET, IR_COMMAND_FLAG_NON_BLOCKING, &doResetBlinkFrequency, COMMAND_STRING(reset) }, /* * Repeatable short commands */ -{ COMMAND_TONE2, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doTone2200, tone2200 }, /**/ -{ COMMAND_INCREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doIncreaseBlinkFrequency, increaseBlink }, /**/ -{ COMMAND_DECREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doDecreaseBlinkFrequency, decreaseBlink } }; +{ COMMAND_TONE2, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doTone2200, COMMAND_STRING(tone2200) }, /* Lasts 50 ms and allows receiving of repeats */ +{ COMMAND_INCREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doIncreaseBlinkFrequency, COMMAND_STRING(increaseBlink) }, /**/ +{ COMMAND_DECREASE_BLINK, IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING, &doDecreaseBlinkFrequency, COMMAND_STRING(decreaseBlink) } }; #endif // _IR_COMMAND_MAPPING_H diff --git a/examples/IRDispatcherDemo/IRCommandDispatcher.h b/examples/IRDispatcherDemo/IRCommandDispatcher.h deleted file mode 100644 index e3f46127b..000000000 --- a/examples/IRDispatcherDemo/IRCommandDispatcher.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * IRCommandDispatcher.h - * - * Library to process IR commands by calling functions specified in a mapping array. - * - * To run this example you need to install the "IRremote" or "IRMP" library under "Tools -> Manage Libraries..." or "Ctrl+Shift+I" - * - * Copyright (C) 2019-2021 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com - * - * This file is part of ServoEasing https://github.com/ArminJo/ServoEasing. - * This file is part of IRMP https://github.com/IRMP-org/IRMP. - * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. - * - * ServoEasing is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef _IR_COMMAND_DISPATCHER_H -#define _IR_COMMAND_DISPATCHER_H - -#include - -/* - * For command mapping file - */ -#define IR_COMMAND_FLAG_BLOCKING 0x00 // default - blocking command, repeat not accepted, only one command at a time. Stops an already running command. -#define IR_COMMAND_FLAG_REPEATABLE 0x01 // repeat accepted -#define IR_COMMAND_FLAG_NON_BLOCKING 0x02 // Non blocking (short) command that can be processed any time and may interrupt other IR commands - used for stop, set direction etc. -#define IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING (IR_COMMAND_FLAG_REPEATABLE | IR_COMMAND_FLAG_NON_BLOCKING) - -// Basic mapping structure -struct IRToCommandMappingStruct { -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) - uint16_t IRCode; -#else - uint8_t IRCode; -#endif - uint8_t Flags; - void (*CommandToCall)(); - const char *CommandString; -}; - -struct IRDataForCommandDispatcherStruct { - uint16_t address; // to distinguish between multiple senders -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) - uint16_t command; -#else - uint8_t command; -#endif - bool isRepeat; - uint32_t MillisOfLastCode; // millis() of last IR command -including repeats!- received - for timeouts etc. - volatile bool isAvailable; // flag for a polling interpreting function, that a new command has arrived. Is set true by library and set false by main loop. -}; - -/* - * Special codes (hopefully) not sent by the remote - otherwise please redefine it here - */ -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) -#define COMMAND_EMPTY 0xFFFF // code no command -#else -#define COMMAND_EMPTY 0xFF // code no command -#endif - -#define RETURN_IF_STOP if (IRDispatcher.requestToStopReceived) return -#define BREAK_IF_STOP if (IRDispatcher.requestToStopReceived) break -#define DELAY_AND_RETURN_IF_STOP(aDurationMillis) if (IRDispatcher.delayAndCheckForStop(aDurationMillis)) return - -class IRCommandDispatcher { -public: - void init(); - - bool checkAndRunNonBlockingCommands(); - bool checkAndRunSuspendedBlockingCommands(); -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) - void setNextBlockingCommand(uint16_t aBlockingCommandToRunNext); -#else - void setNextBlockingCommand(uint8_t aBlockingCommandToRunNext); -#endif - bool delayAndCheckForStop(uint16_t aDelayMillis); - - // The main dispatcher function - void checkAndCallCommand(bool aCallBlockingCommandImmediately); - - void printIRCommandString(Print *aSerial); - void setRequestToStopReceived(bool aRequestToStopReceived = true); - -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) - uint16_t currentBlockingCommandCalled = COMMAND_EMPTY; // The code for the current called command - uint16_t lastBlockingCommandCalled = COMMAND_EMPTY; // The code for the last called command. Can be evaluated by main loop - uint16_t BlockingCommandToRunNext = COMMAND_EMPTY; // Storage for command currently suspended to allow the current command to end, before it is called by main loop -#else - uint8_t currentBlockingCommandCalled = COMMAND_EMPTY; // The code for the current called command - uint8_t lastBlockingCommandCalled = COMMAND_EMPTY; // The code for the last called command. Can be evaluated by main loop - uint8_t BlockingCommandToRunNext = COMMAND_EMPTY; // Storage for command currently suspended to allow the current command to end, before it is called by main loop -#endif - bool justCalledBlockingCommand = false; // Flag that a blocking command was received and called - is set before call of command - /* - * Flag for running blocking commands to terminate. To check, you can use "if (IRDispatcher.requestToStopReceived) return;" (available as macro RETURN_IF_STOP). - * Is reset by next IR command received. Can be reset by main loop, if command has stopped. - */ - volatile bool requestToStopReceived; - /* - * This flag must be true, if we have a function, which want to interpret the IR codes by itself e.g. the calibrate function of QuadrupedControl - */ - bool doNotUseDispatcher = false; - - struct IRDataForCommandDispatcherStruct IRReceivedData; - -}; - -extern IRCommandDispatcher IRDispatcher; - -#endif // _IR_COMMAND_DISPATCHER_H diff --git a/examples/IRDispatcherDemo/IRCommandDispatcher.hpp b/examples/IRDispatcherDemo/IRCommandDispatcher.hpp deleted file mode 100644 index f2bc25982..000000000 --- a/examples/IRDispatcherDemo/IRCommandDispatcher.hpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - * IRCommandDispatcher.hpp - * - * Library to process IR commands by calling functions specified in a mapping array. - * Commands can be tagged as blocking or non blocking. - * - * To run this example you need to install the "IRremote" or "IRMP" library. - * Install it under "Tools -> Manage Libraries..." or "Ctrl+Shift+I" - * - * The IR library calls a callback function, which executes a non blocking command directly in ISR (Interrupt Service Routine) context! - * A blocking command is stored and sets a stop flag for an already running blocking function to terminate. - * The blocking command can in turn be executed by main loop by calling IRDispatcher.checkAndRunSuspendedBlockingCommands(). - * - * Copyright (C) 2019-2022 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com - * - * This file is part of ServoEasing https://github.com/ArminJo/ServoEasing. - * This file is part of IRMP https://github.com/IRMP-org/IRMP. - * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. - * - * ServoEasing is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef _IR_COMMAND_DISPATCHER_HPP -#define _IR_COMMAND_DISPATCHER_HPP - -#include - -#include "IRCommandDispatcher.h" - -/* - * Enable this to see information on each call. - * Since there should be no library which uses Serial, it should only be enabled for development purposes. - */ -#if defined(INFO) && !defined(LOCAL_INFO) -#define LOCAL_INFO -#else -//#define LOCAL_INFO // This enables info output only for this file -#endif -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -// Propagate debug level -#define LOCAL_INFO -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif - -IRCommandDispatcher IRDispatcher; - -#if defined(USE_TINY_IR_RECEIVER) -#include "TinyIRReceiver.hpp" // included in "IRremote" library - -#if defined(LOCAL_INFO) -#define CD_INFO_PRINT(...) Serial.print(__VA_ARGS__); -#define CD_INFO_PRINTLN(...) Serial.println(__VA_ARGS__); -#else -#define CD_INFO_PRINT(...) void(); -#define CD_INFO_PRINTLN(...) void(); -#endif - -void IRCommandDispatcher::init() { - initPCIInterruptForTinyReceiver(); -} - -/* - * This is the TinyReceiver callback function, which is called if a complete command was received - * It checks for right address and then call the dispatcher - */ -#if defined(ESP8266) || defined(ESP32) -IRAM_ATTR -#endif -void handleReceivedTinyIRData(uint8_t aAddress, uint8_t aCommand, uint8_t aFlags) { - IRDispatcher.IRReceivedData.address = aAddress; - IRDispatcher.IRReceivedData.command = aCommand; - IRDispatcher.IRReceivedData.isRepeat = aFlags & IRDATA_FLAGS_IS_REPEAT; - IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); - - CD_INFO_PRINT(F("A=0x")); - CD_INFO_PRINT(aAddress, HEX); - CD_INFO_PRINT(F(" C=0x")); - CD_INFO_PRINT(aCommand, HEX); - if (IRDispatcher.IRReceivedData.isRepeat) { - CD_INFO_PRINT(F("R")); - } - CD_INFO_PRINTLN(); - - if (aAddress == IR_ADDRESS) { // IR_ADDRESS is defined in *IRCommandMapping.h - IRDispatcher.IRReceivedData.isAvailable = true; - if(!IRDispatcher.doNotUseDispatcher) { - /* - * Only short (non blocking) commands are executed directly in ISR (Interrupt Service Routine) context, - * others are stored for main loop which calls checkAndRunSuspendedBlockingCommands() - */ - IRDispatcher.checkAndCallCommand(false); - } - - } else { - CD_INFO_PRINT(F("Wrong address. Expected 0x")); - CD_INFO_PRINTLN(IR_ADDRESS, HEX); - } -} - -#elif defined(USE_IRMP_LIBRARY) -# if !defined(IRMP_USE_COMPLETE_CALLBACK) -# error IRMP_USE_COMPLETE_CALLBACK must be activated for IRMP library -# endif - -void IRCommandDispatcher::init() { - irmp_init(); -} - -/* - * This is the callback function, which is called if a complete command was received - */ -#if defined(ESP8266) || defined(ESP32) -IRAM_ATTR -#endif -void handleReceivedIRData() { - IRMP_DATA tTeporaryData; - irmp_get_data(&tTeporaryData); - IRDispatcher.IRReceivedData.address = tTeporaryData.address; - IRDispatcher.IRReceivedData.command = tTeporaryData.command; - IRDispatcher.IRReceivedData.isRepeat = tTeporaryData.flags & IRMP_FLAG_REPETITION; - IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); - - CD_INFO_PRINT(F("A=0x")); - CD_INFO_PRINT(IRDispatcher.IRReceivedData.address, HEX); - CD_INFO_PRINT(F(" C=0x")); - CD_INFO_PRINT(IRDispatcher.IRReceivedData.command, HEX); - if (IRDispatcher.IRReceivedData.isRepeat) { - CD_INFO_PRINT(F("R")); - } - CD_INFO_PRINTLN(); - - // To enable delay() for commands -# if !defined(ARDUINO_ARCH_MBED) - interrupts(); // be careful with always executable commands which lasts longer than the IR repeat duration. -# endif - - if (IRDispatcher.IRReceivedData.address == IR_ADDRESS) { - IRDispatcher.checkAndCallCommand(true); - } else { - CD_INFO_PRINT(F("Wrong address. Expected 0x")); - CD_INFO_PRINTLN(IR_ADDRESS, HEX); - } -} -#endif // elif defined(USE_IRMP_LIBRARY) - -/* - * The main dispatcher function - * Sets flags justCalledRegularIRCommand, executingBlockingCommand - * @param aCallBlockingCommandImmediately Run blocking command directly, otherwise set request to stop to true - * and store command for main loop to execute by checkAndRunSuspendedBlockingCommands(). - * Should be false if called by ISR. - */ -void IRCommandDispatcher::checkAndCallCommand(bool aCallBlockingCommandImmediately) { - if (IRReceivedData.command == COMMAND_EMPTY) { - return; - } - - /* - * Search for command in Array of IRToCommandMappingStruct - */ - for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) { - if (IRReceivedData.command == IRMapping[i].IRCode) { - /* - * Command found - */ -#if defined(LOCAL_INFO) - const __FlashStringHelper *tCommandName = reinterpret_cast(IRMapping[i].CommandString); -#endif - /* - * Check for repeat and if repeat is allowed for the current command - */ - if (IRReceivedData.isRepeat && !(IRMapping[i].Flags & IR_COMMAND_FLAG_REPEATABLE)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Repeats of command \"")); - Serial.print(tCommandName); - Serial.println("\" not accepted"); -#endif - return; - } - - /* - * Do not accept recursive call of the same command - */ - if (currentBlockingCommandCalled == IRReceivedData.command) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Recursive command \"")); - Serial.print(tCommandName); - Serial.println("\" not accepted"); -#endif - return; - } - - /* - * lets start a new turn - */ - requestToStopReceived = false; - - bool tIsNonBlockingCommand = (IRMapping[i].Flags & IR_COMMAND_FLAG_NON_BLOCKING); - if (tIsNonBlockingCommand) { - // short command here, just call - CD_INFO_PRINT(F("Run non blocking command: ")); - CD_INFO_PRINTLN (tCommandName); - IRMapping[i].CommandToCall(); - } else { - if (aCallBlockingCommandImmediately && currentBlockingCommandCalled == COMMAND_EMPTY) { - /* - * here we are called from main loop to execute a command - */ - justCalledBlockingCommand = true; - currentBlockingCommandCalled = IRReceivedData.command; // set lock for recursive calls - lastBlockingCommandCalled = IRReceivedData.command; // set history, can be evaluated by main loop - /* - * This call is blocking!!! - */ - CD_INFO_PRINT(F("Run blocking command: ")); - CD_INFO_PRINTLN (tCommandName); - - IRMapping[i].CommandToCall(); -#if defined(TRACE) - Serial.println(F("End of blocking command")); -#endif - currentBlockingCommandCalled = COMMAND_EMPTY; - } else { - /* - * Do not run command directly, but set request to stop to true and store command for main loop to execute - */ - BlockingCommandToRunNext = IRReceivedData.command; - requestToStopReceived = true; // to stop running command - CD_INFO_PRINT(F("Requested stop and stored blocking command ")); - CD_INFO_PRINT (tCommandName); - CD_INFO_PRINTLN(F(" as next command to run.")); - } - } - break; // command found - } // if (IRReceivedData.command == IRMapping[i].IRCode) - } // for loop - return; -} - -/* - * Intended to be called from main loop - * @return true, if command was called - */ -bool IRCommandDispatcher::checkAndRunSuspendedBlockingCommands() { - /* - * Take last rejected command and call associated function - */ - if (BlockingCommandToRunNext != COMMAND_EMPTY) { - - CD_INFO_PRINT(F("Take stored command = 0x")); - CD_INFO_PRINTLN(BlockingCommandToRunNext, HEX); - - IRReceivedData.command = BlockingCommandToRunNext; - BlockingCommandToRunNext = COMMAND_EMPTY; - IRReceivedData.isRepeat = false; - checkAndCallCommand(true); - return true; - } - return false; -} - -#if defined(IR_COMMAND_HAS_MORE_THAN_8_BIT) -void IRCommandDispatcher::setNextBlockingCommand(uint16_t aBlockingCommandToRunNext) -#else -void IRCommandDispatcher::setNextBlockingCommand(uint8_t aBlockingCommandToRunNext) -#endif - { - CD_INFO_PRINT(F("Set next command to 0x")); - CD_INFO_PRINTLN(aBlockingCommandToRunNext, HEX); - BlockingCommandToRunNext = aBlockingCommandToRunNext; - requestToStopReceived = true; -} - -/* - * Special delay function for the IRCommandDispatcher. Returns prematurely if requestToStopReceived is set. - * To be used in blocking functions as delay - * @return true - as soon as stop received - */ -bool IRCommandDispatcher::delayAndCheckForStop(uint16_t aDelayMillis) { - uint32_t tStartMillis = millis(); - do { - if (requestToStopReceived) { - return true; - } - } while (millis() - tStartMillis < aDelayMillis); - return false; -} - -void IRCommandDispatcher::printIRCommandString(Print *aSerial) { - aSerial->print(F("IRCommand=")); - for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) { - if (IRReceivedData.command == IRMapping[i].IRCode) { - aSerial->println(reinterpret_cast(IRMapping[i].CommandString)); - return; - } - } - aSerial->println(reinterpret_cast(unknown)); -} - -void IRCommandDispatcher::setRequestToStopReceived(bool aRequestToStopReceived) { - requestToStopReceived = aRequestToStopReceived; -} - -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif -#if defined(LOCAL_INFO) -#undef LOCAL_INFO -#endif -#endif // _IR_COMMAND_DISPATCHER_HPP diff --git a/examples/IRDispatcherDemo/IRDispatcherDemo.ino b/examples/IRDispatcherDemo/IRDispatcherDemo.ino index 8a66d4fc8..3ec5d8b81 100644 --- a/examples/IRDispatcherDemo/IRDispatcherDemo.ino +++ b/examples/IRDispatcherDemo/IRDispatcherDemo.ino @@ -1,10 +1,9 @@ /* * IRDispatcherDemo.cpp * - * Receives NEC IR commands and maps them to different actions by means of a mapping array. + * Example how to use IRCommandDispatcher to receive IR commands and map them to different actions / functions by means of a mapping array. * - * Copyright (C) 2020-2021 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2020-2026 Armin Joachimsmeyer * * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. @@ -29,83 +28,37 @@ /* * Choose the library to be used for IR receiving */ -#define USE_TINY_IR_RECEIVER // Recommended, but only for NEC protocol!!! If disabled and IRMP_INPUT_PIN is defined, the IRMP library is used for decoding -//#define TINY_RECEIVER_USE_ARDUINO_ATTACH_INTERRUPT // Requires additional 112 bytes program memory + 4 bytes RAM - -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. -// Some kind of auto detect library if USE_TINY_IR_RECEIVER is deactivated -#if !defined(USE_TINY_IR_RECEIVER) -# if defined(IR_RECEIVE_PIN) -#define USE_TINY_IR_RECEIVER -# elif !defined(USE_IRMP_LIBRARY) && defined(IRMP_INPUT_PIN) -#define USE_IRMP_LIBRARY -# else -#error No IR library selected -# endif +//#define USE_TINY_IR_RECEIVER // Recommended and default, but only for NEC protocol!!! If disabled and IRMP_INPUT_PIN is defined, the IRMP library is used for decoding +//#define USE_IRREMOTE_LIBRARY // The IRremote library is used for decoding +//#define USE_IRMP_LIBRARY // The IRMP library is used for decoding +//#define DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT // Enables mapping and dispatching of IR commands consisting of more than 8 bits. Saves up to 160 bytes program memory and 5 bytes RAM + 1 byte RAM per mapping entry. +#define NO_LED_FEEDBACK_CODE // We use LED_BUILTIN for command feedback and therefore cannot use is as IR receiving feedback +#define INFO // To see some informative output of the IRCommandDispatcher library +//#define DEBUG // To see some additional debug output of the IRCommandDispatcher library + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. + +#if defined(INFO) || defined(DEBUG) +#define USE_DISPATCHER_COMMAND_STRINGS // Enables the printing of command strings. Requires additional 2 bytes RAM for each command mapping. Requires program memory for strings, but saves snprintf() code (1.5k) if INFO or DEBUG is activated, which has no effect if snprintf() is also used in other parts of your program / libraries. #endif - -//#define NO_LED_FEEDBACK_CODE // You can set it here, before the include of IRCommandDispatcher below - -#if defined(USE_TINY_IR_RECEIVER) -//#define NO_LED_FEEDBACK_CODE // Activate this if you want to suppress LED feedback or if you do not have a LED. This saves 14 bytes code and 2 clock cycles per interrupt. - -/* - * Set sensible receive pin for different CPU's - */ -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) -#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" -# if defined(ARDUINO_AVR_DIGISPARKPRO) -#define IR_INPUT_PIN 9 // PA3 - on Digispark board labeled as pin 9 -# else -#define IR_INPUT_PIN 0 // PCINT0 -# endif -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) -#define IR_INPUT_PIN 10 -# elif (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)) -#define IR_INPUT_PIN 21 // INT0 -# elif defined(ESP8266) -#define IR_INPUT_PIN 14 // D5 -# elif defined(ESP32) -#define IR_INPUT_PIN 15 -# elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) -#define IR_INPUT_PIN 3 // GPIO15 Use pin 3 since pin 2|GPIO25 is connected to LED on Pi pico -# elif defined(ARDUINO_ARCH_RP2040) // Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico -#define IR_INPUT_PIN 15 // to be compatible with the Arduino Nano RP2040 Connect (pin3) -# else -#define IR_INPUT_PIN 2 // INT0 -# endif - -#elif defined(USE_IRMP_LIBRARY) -/* - * IRMP version - */ -#define IR_INPUT_PIN 2 -#define IRMP_USE_COMPLETE_CALLBACK 1 // Enable callback functionality. It is required if IRMP library is used. -#if defined(ALTERNATIVE_IR_FEEDBACK_LED_PIN) -#define FEEDBACK_LED_PIN ALTERNATIVE_IR_FEEDBACK_LED_PIN +#if defined(TONE_PIN) +#define DISPATCHER_BUZZER_FEEDBACK_PIN TONE_PIN // The pin to be used for the optional 50 ms buzzer feedback before executing a command. Only available for TinyIR. #endif -//#define IRMP_ENABLE_PIN_CHANGE_INTERRUPT // Enable interrupt functionality (not for all protocols) - requires around 376 additional bytes of program memory - -#define IRMP_PROTOCOL_NAMES 1 // Enable protocol number mapping to protocol strings - requires some program memory. Must before #include - +#if defined(USE_IRMP_LIBRARY) +//Enable protocols for IRMP #define IRMP_SUPPORT_NEC_PROTOCOL 1 // this enables only one protocol //#define IRMP_SUPPORT_KASEIKYO_PROTOCOL 1 - -# if defined(ALTERNATIVE_IR_FEEDBACK_LED_PIN) -#define IRMP_FEEDBACK_LED_PIN ALTERNATIVE_IR_FEEDBACK_LED_PIN -# endif -/* - * After setting the definitions we can include the code and compile it. - */ -#include -void handleReceivedIRData(); -void irmp_tone(uint8_t _pin, unsigned int frequency, unsigned long duration); -#endif // #if defined(USE_IRMP_LIBRARY) +//#define IRMP_ENABLE_PIN_CHANGE_INTERRUPT // Enable interrupt functionality (not for all protocols) - requires around 376 additional bytes of program memory +#endif // defined(USE_IRMP_LIBRARY) bool doBlink = false; uint16_t sBlinkDelay = 200; +/* + * The functions which are called by the IR commands. + * They must be declared before including DemoIRCommandMapping.h, where the mapping to IR keys is defined. + */ void doPrintMenu(); void doLedOn(); void doLedOff(); @@ -119,23 +72,20 @@ void doTone1800(); void doTone2200(); /* - * Set definitions and include IRCommandDispatcher library after the declaration of all commands to map + * Set definitions and include IRCommandDispatcher library after the declaration of all commands required for mapping */ -#define INFO // to see some informative output -#include "IRCommandDispatcher.h" // Only for required declarations, the library itself is included below after the definitions of the commands -#include "DemoIRCommandMapping.h" // must be included before IRCommandDispatcher.hpp to define IR_ADDRESS and IRMapping and string "unknown". -#include "IRCommandDispatcher.hpp" +#include "DemoIRCommandMapping.h" // must be included before IRCommandDispatcher.hpp to define IRMapping array, IR_ADDRESS etc. +#include "IRCommandDispatcher.hpp" // This can optionally set USE_TINY_IR_RECEIVER -/* - * Helper macro for getting a macro definition as string - */ -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +void IRremoteTone(uint8_t aTonePin, unsigned int aFrequency, unsigned long aDuration); -void setup() { +void setup() +{ pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif #if defined(ESP8266) @@ -144,45 +94,36 @@ void setup() { // Just to know which program is running on my Arduino #if defined(USE_TINY_IR_RECEIVER) - Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing TinyIRReceiver")); + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing TinyIRReceiver library version " VERSION_TINYIR)); #elif defined(USE_IRREMOTE_LIBRARY) Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing IRremote library version " VERSION_IRREMOTE)); #elif defined(USE_IRMP_LIBRARY) Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing IRMP library version " VERSION_IRMP)); #endif -#if !defined(ESP8266) && !defined(NRF5) - // play feedback tone before setup, since it kills the IR timer settings +#if !defined(ESP8266) && !defined(NRF5) && defined(TONE_PIN) + // play feedback tone before IRDispatcher.init(), because it kills the IR timer settings, which are made by init() tone(TONE_PIN, 1000, 50); delay(50); #endif - IRDispatcher.init(); // This just calls irmp_init() -#if defined(USE_TINY_IR_RECEIVER) - Serial.println(F("Ready to receive NEC IR signals at pin " STR(IR_INPUT_PIN))); -#else - irmp_register_complete_callback_function(&handleReceivedIRData); // fixed function in IRCommandDispatcher.hpp - - Serial.print(F("Ready to receive IR signals of protocols: ")); - irmp_print_active_protocols(&Serial); - Serial.println(F("at pin " STR(IRMP_INPUT_PIN))); - -# if defined(ALTERNATIVE_IR_FEEDBACK_LED_PIN) - irmp_irsnd_LEDFeedback(true); // Enable receive signal feedback at ALTERNATIVE_IR_FEEDBACK_LED_PIN - Serial.println(F("IR feedback pin is " STR(ALTERNATIVE_IR_FEEDBACK_LED_PIN))); -# endif -#endif + IRDispatcher.init(); // This calls the init function of the chosen library + IRDispatcher.printIRInfo(&Serial); - Serial.print(F("Listening to commands of IR remote of type ")); - Serial.println(IR_REMOTE_NAME); doPrintMenu(); +#if defined(DEBUG) && defined(SP) + Serial.print(F("SP=0x")); + Serial.println(SP, HEX); +#endif } -void loop() { +void loop() +{ IRDispatcher.checkAndRunSuspendedBlockingCommands(); - if (doBlink) { + if (doBlink) + { digitalWrite(LED_BUILTIN, HIGH); DELAY_AND_RETURN_IF_STOP(sBlinkDelay); digitalWrite(LED_BUILTIN, LOW); @@ -191,15 +132,22 @@ void loop() { if (millis() - IRDispatcher.IRReceivedData.MillisOfLastCode > 120000) { - //Short beep as remainder, if we did not receive any command in the last 2 minutes - IRDispatcher.IRReceivedData.MillisOfLastCode += 120000; + // Short beep as remainder, if we did not receive any command in the last 2 minutes + IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); doTone1800(); +#if defined(INFO) + Serial.println(F("2 minutes timeout")); +#endif } // delay(10); } -void doPrintMenu(){ +/* + * Menu for simple China Keyes or Keyes clone IR controls with number pad and direction control pad + */ +void doPrintMenu() +{ Serial.println(); Serial.println(F("Press 1 for tone 1800 Hz")); Serial.println(F("Press 2 for tone 2200 Hz")); @@ -217,39 +165,50 @@ void doPrintMenu(){ /* * Here the actions that are matched to IR keys */ -void doLedOn() { +void doLedOn() +{ digitalWrite(LED_BUILTIN, HIGH); doBlink = false; } -void doLedOff() { +void doLedOff() +{ digitalWrite(LED_BUILTIN, LOW); doBlink = false; } -void doIncreaseBlinkFrequency() { +void doIncreaseBlinkFrequency() +{ doBlink = true; - if (sBlinkDelay > 5) { + if (sBlinkDelay > 5) + { sBlinkDelay -= sBlinkDelay / 4; } } -void doDecreaseBlinkFrequency() { +void doDecreaseBlinkFrequency() +{ doBlink = true; sBlinkDelay += sBlinkDelay / 4; } -void doStop() { +void doStop() +{ doBlink = false; + digitalWrite(LED_BUILTIN, LOW); } -void doResetBlinkFrequency() { +void doResetBlinkFrequency() +{ sBlinkDelay = 200; digitalWrite(LED_BUILTIN, LOW); } -void doLedBlinkStart() { +void doLedBlinkStart() +{ doBlink = true; } /* - * This is a blocking function and checks periodically for stop + * This is a blocking function which checks for stop */ -void doLedBlink20times() { - for (int i = 0; i < 20; ++i) { +void doLedBlink20times() +{ + for (int i = 0; i < 20; ++i) + { digitalWrite(LED_BUILTIN, HIGH); DELAY_AND_RETURN_IF_STOP(200); digitalWrite(LED_BUILTIN, LOW); @@ -257,50 +216,63 @@ void doLedBlink20times() { } } - -void doTone1800() { -#if defined(USE_IRMP_LIBRARY) && !defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT) - irmp_tone(TONE_PIN, 1800, 200); -#else -# if !defined(ESP8266) && !defined(NRF5) // tone() stops timer 1 for ESP8266 - tone(TONE_PIN, 1800, 200); -# endif +/* + * Lasts 200 ms and blocks receiving of repeats. tone() requires interrupts enabled + */ +void doTone1800() +{ +#if defined(TONE_PIN) + IRremoteTone(TONE_PIN, 1800, 200); #endif } -void doTone2200() { -#if defined(USE_IRMP_LIBRARY) && !defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT) - // use IRMP compatible function for tone() - irmp_tone(TONE_PIN, 2200, 50); -#else -# if !defined(ESP8266) && !defined(NRF5) // tone() stops timer 1 for ESP8266 - tone(TONE_PIN, 2200, 50); -# endif +/* + * Lasts 50 ms and allows receiving of repeats + */ +void doTone2200() +{ +#if defined(TONE_PIN) + IRremoteTone(TONE_PIN, 2200, 50); #endif } -#if defined(USE_IRMP_LIBRARY) /* - * Convenience IRMP compatible wrapper function for Arduino tone() if IRMP_ENABLE_PIN_CHANGE_INTERRUPT is NOT activated + * Convenience IR library wrapper function for Arduino tone() * It currently disables the receiving of repeats + * It is not part of the library because it statically allocates the tone interrupt vector 7. */ -void irmp_tone(uint8_t _pin, unsigned int frequency, unsigned long duration) { -# if defined(__AVR__) && !defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT) +void IRremoteTone(uint8_t aTonePin, unsigned int aFrequency, unsigned long aDuration) +{ + // IRMP_ENABLE_PIN_CHANGE_INTERRUPT currently disables the receiving of repeats +#if defined(ESP8266) || defined(NRF5) || defined(IRMP_ENABLE_PIN_CHANGE_INTERRUPT) // tone on esp8266 works only once, then it disables IrReceiver.restartTimer() / timerConfigForReceive(). + (void) aTonePin; + (void) aFrequency; + (void) aDuration; + return; +#else + /* + * Stop receiver, generate a single beep and start receiver again + */ +# if defined(ESP32) || defined(USE_TINY_IR_RECEIVER )// ESP32 uses another timer for tone(), maybe other platforms (not tested yet) too. + tone(aTonePin, aFrequency, aDuration); +# else +# if defined(USE_IRREMOTE_LIBRARY) + IrReceiver.stopTimer(); // Stop timer consistently before calling tone() or other functions using the timer resource. +# else storeIRTimer(); - tone(_pin, frequency, 0); - if (duration == 0) { - duration = 100; +# endif + tone(aTonePin, aFrequency, 0); + if (aDuration == 0) + { + aDuration = 100; } - delay(duration); - noTone(_pin); + delay(aDuration); + noTone(aTonePin); +# if defined(USE_IRREMOTE_LIBRARY) + IrReceiver.restartTimer(); // Restart IR timer after timer resource is no longer blocked. +# else restoreIRTimer(); -#elif defined(ESP8266) - // tone() stops timer 1 - (void) _pin; - (void) frequency; - (void) duration; -#else - tone(_pin, frequency, duration); +# endif +# endif #endif } -#endif // #if defined(USE_IRMP_LIBRARY) diff --git a/examples/IRDispatcherDemo/PinDefinitionsAndMore.h b/examples/IRDispatcherDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/IRDispatcherDemo/PinDefinitionsAndMore.h +++ b/examples/IRDispatcherDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/IRremoteExtensionTest/IRremoteExtensionClass.cpp b/examples/IRremoteExtensionTest/IRremoteExtensionClass.cpp index 328db5b8d..a110d8fb5 100644 --- a/examples/IRremoteExtensionTest/IRremoteExtensionClass.cpp +++ b/examples/IRremoteExtensionTest/IRremoteExtensionClass.cpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2021 Armin Joachimsmeyer + * Copyright (c) 2021-2025 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 @@ -31,11 +31,36 @@ */ #include +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. + +/* + * !!! The value of RAW_BUFFER_LENGTH (and some other macros) must be the same in all compile units !!! + * Otherwise you may get warnings like "type 'struct IRData' itself violates the C++ One Definition Rule" + */ +#if !defined(RAW_BUFFER_LENGTH) +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 +# else +// Here we most likely have 2 k RAM or more +#define RAW_BUFFER_LENGTH 750 +# endif +#endif + #include "IRremoteExtensionClass.h" IRExtensionClass::IRExtensionClass(IRrecv *aIrReceiver) { MyIrReceiver = aIrReceiver; } +bool IRExtensionClass::decode() { + return MyIrReceiver->decode(); +} + +bool IRExtensionClass::printIRResultShort(Print *aSerial, bool aCheckForRecordGapsMicros) { + return MyIrReceiver->printIRResultShort(aSerial, aCheckForRecordGapsMicros); +} + void IRExtensionClass::resume() { Serial.println(F("Call resume()")); MyIrReceiver->resume(); diff --git a/examples/IRremoteExtensionTest/IRremoteExtensionClass.h b/examples/IRremoteExtensionTest/IRremoteExtensionClass.h index 5c50fd5e4..07c858802 100644 --- a/examples/IRremoteExtensionTest/IRremoteExtensionClass.h +++ b/examples/IRremoteExtensionTest/IRremoteExtensionClass.h @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2021 Armin Joachimsmeyer + * Copyright (c) 2021-2025 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 @@ -39,6 +39,8 @@ class IRExtensionClass public: IRrecv * MyIrReceiver; IRExtensionClass(IRrecv * aIrReceiver); + bool decode(); + bool printIRResultShort(Print *aSerial, bool aCheckForRecordGapsMicros = true); void resume(); }; diff --git a/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino b/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino index 65b42c03c..9ee1e437b 100644 --- a/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino +++ b/examples/IRremoteExtensionTest/IRremoteExtensionTest.ino @@ -30,15 +30,16 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 180 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 500 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else -#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Here we most likely have 2 k RAM or more +#define RAW_BUFFER_LENGTH 750 # endif #endif @@ -53,8 +54,15 @@ IRExtensionClass IRExtension(&IrReceiver); void setup() { Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -62,7 +70,6 @@ void setup() { // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); - Serial.print(F("Ready to receive IR signals of protocols: ")); printActiveIRProtocols(&Serial); Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); @@ -70,8 +77,8 @@ void setup() { } void loop() { - if (IrReceiver.decode()) { - IrReceiver.printIRResultShort(&Serial); + if (IRExtension.decode()) { + IRExtension.printIRResultShort(&Serial); IrReceiver.printIRSendUsage(&Serial); IRExtension.resume(); // Use the extended function provided by IRExtension class } diff --git a/examples/IRremoteExtensionTest/PinDefinitionsAndMore.h b/examples/IRremoteExtensionTest/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/IRremoteExtensionTest/PinDefinitionsAndMore.h +++ b/examples/IRremoteExtensionTest/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/IRremoteInfo/IRremoteInfo.ino b/examples/IRremoteInfo/IRremoteInfo.ino index 22ae75fbb..7f8ef9e32 100644 --- a/examples/IRremoteInfo/IRremoteInfo.ino +++ b/examples/IRremoteInfo/IRremoteInfo.ino @@ -11,6 +11,8 @@ */ #include +//#define DEBUG + //#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 240 bytes program memory if IrSender.write is used //#define SEND_PWM_BY_TIMER //#define USE_NO_SEND_PWM @@ -34,9 +36,17 @@ void dumpFooter(); void setup() { Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -193,7 +203,7 @@ void dumpPulseParams() { ; Serial.println(F(" uSecs")); Serial.print(F("Measurement tolerance: ")); - Serial.print(TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING); + Serial.print(TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT); Serial.println(F("%")); } @@ -205,7 +215,7 @@ void dumpSignalParams() { void dumpDebugMode() { Serial.print(F("Debug Mode: ")); -#if DEBUG +#if defined(DEBUG) Serial.println(F("ON")); #else Serial.println(F("OFF (Normal)")); @@ -259,13 +269,6 @@ void dumpProtocols() { Serial.println(F("Disabled")); #endif - Serial.print(F("PANASONIC: ")); -#if defined(DECODE_PANASONIC) - Serial.println(F("Enabled")); -#else - Serial.println(F("Disabled")); -#endif - Serial.print(F("JVC: ")); #if defined(DECODE_JVC) Serial.println(F("Enabled")); diff --git a/examples/MicroGirs/MicroGirs.ino b/examples/MicroGirs/MicroGirs.ino index a840bf240..7af892c10 100644 --- a/examples/MicroGirs/MicroGirs.ino +++ b/examples/MicroGirs/MicroGirs.ino @@ -64,15 +64,16 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 180 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 500 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else -#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Here we most likely have 2 k RAM or more +#define RAW_BUFFER_LENGTH 750 # endif #endif @@ -83,6 +84,8 @@ #define BAUDRATE 115200 #define NO_DECODER +//#define NO_LED_FEEDBACK_CODE // Saves 346 bytes program memory + #include "IRremote.hpp" #include @@ -190,8 +193,7 @@ String Tokenizer::getRest() { } String Tokenizer::getLine() { - if (index == invalidIndex) - return String(""); + if (index == invalidIndex) return String(""); int i = payload.indexOf('\n', index); String s = (i > 0) ? payload.substring(index, i) : payload.substring(index); @@ -200,16 +202,13 @@ String Tokenizer::getLine() { } String Tokenizer::getToken() { - if (index < 0) - return String(""); + if (index < 0) return String(""); int i = payload.indexOf(' ', index); String s = (i > 0) ? payload.substring(index, i) : payload.substring(index); index = (i > 0) ? i : invalidIndex; - if (index != invalidIndex) - if (index != invalidIndex) - while (payload.charAt(index) == ' ') - index++; + if (index != invalidIndex) if (index != invalidIndex) while (payload.charAt(index) == ' ') + index++; return s; } @@ -253,26 +252,23 @@ static inline unsigned hz2khz(frequency_t hz) { */ static void sendRaw(const microseconds_t intro[], unsigned lengthIntro, const microseconds_t repeat[], unsigned lengthRepeat, const microseconds_t ending[], unsigned lengthEnding, frequency_t frequency, unsigned times) { - if (lengthIntro > 0U) - IrSender.sendRaw(intro, lengthIntro, hz2khz(frequency)); - if (lengthRepeat > 0U) - for (unsigned i = 0U; i < times - (lengthIntro > 0U); i++) - IrSender.sendRaw(repeat, lengthRepeat, hz2khz(frequency)); - if (lengthEnding > 0U) - IrSender.sendRaw(ending, lengthEnding, hz2khz(frequency)); + if (lengthIntro > 0U) IrSender.sendRaw(intro, lengthIntro, hz2khz(frequency)); + if (lengthRepeat > 0U) for (unsigned i = 0U; i < times - (lengthIntro > 0U); i++) + IrSender.sendRaw(repeat, lengthRepeat, hz2khz(frequency)); + if (lengthEnding > 0U) IrSender.sendRaw(ending, lengthEnding, hz2khz(frequency)); } #endif // TRANSMIT #if defined(RECEIVE) static void dump(Stream &stream) { - unsigned int count = IrReceiver.decodedIRData.rawDataPtr->rawlen; + unsigned int count = IrReceiver.irparams.rawlen; // If buffer gets full, count = RAW_BUFFER_LENGTH, which is odd, // and IrScrutinizer does not like that. count &= ~1; for (unsigned int i = 1; i < count; i++) { stream.write(i & 1 ? '+' : '-'); - stream.print(IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK, DEC); + stream.print(IrReceiver.irparams.rawbuf[i] * MICROS_PER_TICK, DEC); stream.print(" "); } stream.print('-'); @@ -300,8 +296,6 @@ static void receive(Stream &stream) { */ void setup() { Serial.begin(BAUDRATE); - while (!Serial) - ; // wait for serial port to connect. Serial.println(F(PROGNAME " " VERSION)); // Just to know which program is running on my Arduino @@ -317,9 +311,13 @@ void setup() { #endif #if defined(IR_SEND_PIN) - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ #else - IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin + IrSender.begin(3); // Specify send pin and enable feedback LED at default feedback LED pin #endif } diff --git a/examples/MicroGirs/PinDefinitionsAndMore.h b/examples/MicroGirs/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/MicroGirs/PinDefinitionsAndMore.h +++ b/examples/MicroGirs/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/MultipleReceivers/MultipleReceivers.ino b/examples/MultipleReceivers/MultipleReceivers.ino new file mode 100644 index 000000000..c60b990c3 --- /dev/null +++ b/examples/MultipleReceivers/MultipleReceivers.ino @@ -0,0 +1,152 @@ +/* + * MultipleReceivers.cpp + * + * Demonstrates receiving from multiple receivers at different pins using multiple IRreceiver instances + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + ************************************************************************************ + * MIT License + * + * Copyright (c) 2025-2026 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. + * + ************************************************************************************ + */ + +#include + +#define IR_RECEIVE_PIN_OF_SECOND_RECEIVER 5 + +/* + * Specify which protocol(s) should be used for decoding. + * If no protocol is defined, all protocols (except Bang&Olufsen) are active. + * This must be done before the #include + */ +//#define DECODE_DENON // Includes Sharp +//#define DECODE_JVC +//#define DECODE_KASEIKYO // Includes Panasonic ~ 640 bytes +//#define DECODE_LG +//#define DECODE_NEC // Includes Apple and Onkyo. To enable all protocols , just comment/disable this line. +//#define DECODE_SAMSUNG +//#define DECODE_SONY +//#define DECODE_RC5 +//#define DECODE_RC6 +//#define DECODE_BOSEWAVE +//#define DECODE_LEGO_PF +//#define DECODE_MAGIQUEST +//#define DECODE_WHYNTER +//#define DECODE_FAST +//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols +//#define DECODE_HASH // special decoder for all protocols +//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY! +//#define DEBUG // Activate this for lots of lovely debug output from the decoders. +//#define RAW_BUFFER_LENGTH 750 // For air condition remotes it may require up to 750. Default is 200. +#define SUPPORT_MULTIPLE_RECEIVER_INSTANCES +void UserIRReceiveTimerInterruptHandler(); // Is defined below and must be declared before line #include + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. +#include // include the library + +IRrecv MySecondIrReceiver(IR_RECEIVE_PIN_OF_SECOND_RECEIVER); // This sets the pin for the second instance + +void handleSuccessfulDecoding(IRrecv *aIRReceiverInstance); + +void setup() { + Serial.begin(115200); + + // Just to know which program is running on my Arduino + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); + + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // This sets the pin for the default / first instance and enables the global LED feedback + + Serial.print(F("Ready to receive IR signals of protocols: ")); + printActiveIRProtocols(&Serial); + Serial.println(F("at pin " STR(IR_RECEIVE_PIN) " and pin " STR(IR_RECEIVE_PIN_OF_SECOND_RECEIVER))); +} + +void loop() { + /* + * Check if received data is available and if yes, try to decode it. + * Decoded result is in the IrReceiver.decodedIRData structure. + * + * E.g. command is in IrReceiver.decodedIRData.command + * address is in command is in IrReceiver.decodedIRData.address + * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData + */ + if (IrReceiver.decode()) { + handleSuccessfulDecoding(&IrReceiver); + } + if (MySecondIrReceiver.decode()) { + handleSuccessfulDecoding(&MySecondIrReceiver); + } +} + +void handleSuccessfulDecoding(IRrecv *aIRReceiverInstance) { + + Serial.print(F("Receiver at pin ")); + Serial.print(aIRReceiverInstance->irparams.IRReceivePin); + Serial.print(F(": ")); + + /* + * Print a summary of received data + */ + if (aIRReceiverInstance->decodedIRData.protocol == UNKNOWN) { + Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); + // We have an unknown protocol here, print extended info + aIRReceiverInstance->printIRResultRawFormatted(&Serial, true); + + aIRReceiverInstance->resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted() + } else { + aIRReceiverInstance->resume(); // Early enable receiving of the next IR frame + + aIRReceiverInstance->printIRResultShort(&Serial); + aIRReceiverInstance->printIRSendUsage(&Serial); + } + Serial.println(); + + /* + * Finally, check the received data and perform actions according to the received command + */ + if (aIRReceiverInstance->decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { + Serial.println(F("Repeat received. Here you can repeat the same action as before.")); + } else { + if (aIRReceiverInstance->decodedIRData.command == 0x10) { + Serial.println(F("Received command 0x10.")); + // do something + } else if (aIRReceiverInstance->decodedIRData.command == 0x11) { + Serial.println(F("Received command 0x11.")); + // do something else + } + } + +} + +/* + * If SUPPORT_MULTIPLE_RECEIVER_INSTANCES is active, this handler is called in ISR context after IrReceiver.ReceiveInterruptHandler(). + * Here we just call the standard ReceiveInterruptHandler for the second receiver. + * Doing it this way, we are able to modify the body of this function to support more than 2 IRrecv instances for receiving. + */ +#if defined(ESP8266) || defined(ESP32) +IRAM_ATTR +#endif +void UserIRReceiveTimerInterruptHandler() { + MySecondIrReceiver.ReceiveInterruptHandler(); +} diff --git a/examples/MultipleReceivers/PinDefinitionsAndMore.h b/examples/MultipleReceivers/PinDefinitionsAndMore.h new file mode 100644 index 000000000..d3dd74992 --- /dev/null +++ b/examples/MultipleReceivers/PinDefinitionsAndMore.h @@ -0,0 +1,366 @@ +/* + * PinDefinitionsAndMore.h + * + * Contains pin definitions for IRremote examples for various platforms + * as well as definitions for feedback LED and tone() and includes + * + * Copyright (C) 2021-2026 Armin Joachimsmeyer + * + * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * Arduino-IRremote is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Pin mapping table for different platforms + * + * Platform IR input IR output Tone Core/Pin schema + * -------------------------------------------------------------- + * DEFAULT/AVR 2 3 4 Arduino + * ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore + * ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore + * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core + * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore + * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore + * ATtiny1604 2 3|PA5 % + * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore + * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore + * MKR* 1 3 4 + * SAMD 2 3 4 + * ESP8266 14|D5 12|D6 % + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 + * APOLLO3 11 12 5 + * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 + */ +//#define _IR_MEASURE_TIMING // For debugging purposes. + +#if defined(__AVR__) +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. +#define IR_RECEIVE_PIN PIN_PB0 +#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. +#define TONE_PIN PIN_PB3 +#define _IR_TIMING_TEST_PIN PIN_PB3 + +# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" +// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. +# if defined(ARDUINO_AVR_DIGISPARKPRO) +// For use with Digispark original core +#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 +//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 +#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 +#define _IR_TIMING_TEST_PIN 10 // PA4 +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else +// For use with ATTinyCore +#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 +#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 +# endif + +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +#define IR_RECEIVE_PIN PIN_PB2 // INT0 +#define IR_SEND_PIN PIN_PA4 +#define TONE_PIN PIN_PA3 +#define _IR_TIMING_TEST_PIN PIN_PA5 + +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +// Pin 6 is TX, pin 7 is RX +#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 +#define IR_SEND_PIN PIN_PD4 // 4 +#define TONE_PIN PIN_PB1 // 9 +#define _IR_TIMING_TEST_PIN PIN_PB0 // 8 + +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore +// Tiny Core Dev board +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET +#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 + +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 14 +#define IR_SEND_PIN PIN_PA3 // 16 +#define TONE_PIN PIN_PA5 // 1 +#define APPLICATION_PIN PIN_PA4 // 0 +#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output +#define LED_BUILTIN PIN_PB5 // 4 + +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB2 // 5 + +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 + +# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ +|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ +|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ +|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ +|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ +|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \ +|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \ +|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \ +|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__) +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 13 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc. +#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here. +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit +// We have no built in LED at pin 13 -> reuse RX LED +#undef LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN_RX +# endif +# endif // defined(__AVR_ATtiny25__)... + +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ESP8266) +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW +#define IR_RECEIVE_PIN 14 // D5 +#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED +#define _IR_TIMING_TEST_PIN 2 // D4 +#define APPLICATION_PIN 13 // D7 + +#define tone(...) void() // tone() inhibits receive timer +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 + +#elif defined(ESP32) +#include + +// tone() is included in ESP32 core since 2.0.2 +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif +#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) +#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. +void tone(uint8_t aPinNumber, unsigned int aFrequency){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); +} +void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); + delay(aDuration); + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +void noTone(uint8_t aPinNumber){ + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) + +#define IR_RECEIVE_PIN 15 // D15 +#define IR_SEND_PIN 4 // D4 +#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 +#define APPLICATION_PIN 16 // RX2 pin + +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill +// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() +#define IR_RECEIVE_PIN PA6 +#define IR_RECEIVE_PIN_STRING "PA6" +#define IR_SEND_PIN PA7 +#define IR_SEND_PIN_STRING "PA7" +#define TONE_PIN PA3 +#define _IR_TIMING_TEST_PIN PA5 +#define APPLICATION_PIN PA2 +#define APPLICATION_PIN_STRING "PA2" +# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8) +// BluePill LED is active low +#define FEEDBACK_LED_IS_ACTIVE_LOW +# endif + +#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards +#define IR_RECEIVE_PIN 11 +#define IR_SEND_PIN 12 +#define TONE_PIN 5 + +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect +#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico +#define IR_SEND_PIN 4 // GPIO16 +#define TONE_PIN 5 +#define APPLICATION_PIN 6 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 8 + +#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico +#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3) +#define IR_SEND_PIN 16 // GPIO16 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 20 + +// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN +// and use the external reset with 1 kOhm to ground to enter UF2 mode +#undef LED_BUILTIN +#define LED_BUILTIN 6 + +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! +#define IR_RECEIVE_PIN A4 +#define IR_SEND_PIN A5 // Particle supports multiple pins + +#define LED_BUILTIN D7 + +/* + * 4 times the same (default) layout for easy adaption in the future + */ +#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else +#define IR_RECEIVE_PIN 2 +# endif +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0) +// On the Zero and others we switch explicitly to SerialUSB +#define Serial SerialUSB +#endif + +// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17. +// Attention!!! D2 and D4 are swapped on these boards!!! +// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 24 // PB11 +// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 25 // PB03 +//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW + +#elif defined (NRF51) // BBC micro:bit +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define APPLICATION_PIN 1 +#define _IR_TIMING_TEST_PIN 4 + +#define tone(...) void() // no tone() available +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it + +#else +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. +// Default valued for unidentified boards +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 +#endif // defined(ESP8266) + +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp +#endif + +#if !defined (FLASHEND) +#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined +#endif + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // +#endif +#if !defined (RAMSIZE) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined +#endif diff --git a/examples/MultipleSendPins/MultipleSendPins.ino b/examples/MultipleSendPins/MultipleSendPins.ino new file mode 100644 index 000000000..ce7b7827a --- /dev/null +++ b/examples/MultipleSendPins/MultipleSendPins.ino @@ -0,0 +1,95 @@ +/* + * MultipleSendPins.cpp + * + * Demonstrates sending IR codes toggling between 2 different send pins. + * Based on SimpleSender. + * + * Copyright (C) 2025 Armin Joachimsmeyer + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * MIT License + */ +#include + +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif + +//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define NO_LED_FEEDBACK_CODE // Saves 52 bytes program memory + +#include // include the library + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + + Serial.begin(115200); + + // Just to know which program is running on my Arduino + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); + Serial.print(F("Send IR signals alternating at pin 3 and 4")); + + /* + * The IR library setup. That's all! + */ + IrSender.begin(3); // Start with pin3 as send pin and enable feedback LED at default feedback LED pin + disableLEDFeedback(); // Disable feedback LED at default feedback LED pin +} + +/* + * Set up the data to be sent. + * For most protocols, the data is build up with a constant 8 (or 16 byte) address + * and a variable 8 bit command. + * There are exceptions like Sony and Denon, which have 5 bit address. + */ +uint8_t sCommand = 0x34; +uint8_t sRepeats = 0; + +void loop() { + /* + * Print current send values + */ + Serial.println(); + Serial.print(F("Send now: address=0x00, command=0x")); + Serial.print(sCommand, HEX); + Serial.print(F(", repeats=")); + Serial.print(sRepeats); + Serial.println(); + + Serial.println(F("Send standard NEC with 8 bit address")); + Serial.flush(); + + // Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits) + IrSender.sendNEC(0x00, sCommand, sRepeats); + + /* + * If you want to send a raw HEX value directly like e.g. 0xCB340102 you must use sendNECRaw() + */ +// Serial.println(F("Send 32 bit LSB 0xCB340102 with NECRaw()")); +// IrSender.sendNECRaw(0xCB340102, sRepeats); + /* + * If you want to send an "old" MSB HEX value used by IRremote versions before 3.0 like e.g. 0x40802CD3 you must use sendNECMSB() + */ +// Serial.println(F("Send old 32 bit MSB 0x40802CD3 with sendNECMSB()")); +// IrSender.sendNECMSB(0x40802CD3, 32, sRepeats); + /* + * Increment send values + */ + sCommand += 0x11; + sRepeats++; + // clip repeats at 4 + if (sRepeats > 4) { + sRepeats = 4; + } + + /* + * Toggle between send pin 3 and 4 + */ + if (IrSender.sendPin == 3) { + IrSender.setSendPin(4); + } else { + IrSender.setSendPin(3); + } + delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal +} diff --git a/examples/ReceiveAndSend/PinDefinitionsAndMore.h b/examples/ReceiveAndSend/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ReceiveAndSend/PinDefinitionsAndMore.h +++ b/examples/ReceiveAndSend/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ReceiveAndSend/ReceiveAndSend.ino b/examples/ReceiveAndSend/ReceiveAndSend.ino index fdd4eaf36..faae9a06e 100644 --- a/examples/ReceiveAndSend/ReceiveAndSend.ino +++ b/examples/ReceiveAndSend/ReceiveAndSend.ino @@ -14,6 +14,7 @@ * A button must be connected between the input SEND_BUTTON_PIN and ground. * A visible LED can be connected to STATUS_PIN to provide status. * + * See also https://dronebotworkshop.com/ir-remotes/#ReceiveAndSend_Code * * Initially coded 2009 Ken Shirriff http://www.righto.com * @@ -22,7 +23,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2009-2023 Ken Shirriff, Armin Joachimsmeyer + * Copyright (c) 2009-2026 Ken Shirriff, 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 @@ -45,8 +46,6 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. - /* * Specify which protocol(s) should be used for decoding. * If no protocol is defined, all protocols (except Bang&Olufsen) are active. @@ -54,10 +53,9 @@ */ //#define DECODE_DENON // Includes Sharp //#define DECODE_JVC -//#define DECODE_KASEIKYO -//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO +//#define DECODE_KASEIKYO // Includes Panasonic ~ 640 bytes //#define DECODE_LG -#define DECODE_NEC // Includes Apple and Onkyo +//#define DECODE_NEC // Includes Apple and Onkyo //#define DECODE_SAMSUNG //#define DECODE_SONY //#define DECODE_RC5 @@ -69,29 +67,39 @@ //#define DECODE_WHYNTER //#define DECODE_FAST // + #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 120 -# elif RAMEND <= 0xAFF || RAMSIZE < 0xAFF // 0xAFF for LEONARDO -#define RAW_BUFFER_LENGTH 400 // 600 is too much here, because we have additional uint8_t rawCode[RAW_BUFFER_LENGTH]; +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else +// Here we most likely have 2 k RAM or more #define RAW_BUFFER_LENGTH 750 # endif #endif +#if RAMSIZE >= 0x1000 +// Here we most likely have 4 k RAM or more +#define USE_16_BIT_TIMING_BUFFER // Use a 16-bit buffer to preserve timing values above 12750 us +#endif + //#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. -//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active +#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active //#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define NO_LED_FEEDBACK_CODE // Saves 202 bytes program memory // MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, -// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142. -#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules. +// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 135. +// 20 is taken as default if not otherwise specified / defined. +//#define MARK_EXCESS_MICROS 40 // Adapt it to your IR receiver module. 40 is recommended for the cheap VS1838 modules at high intensity. //#define DEBUG // Activate this for lots of lovely debug output from the decoders. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include int SEND_BUTTON_PIN = APPLICATION_PIN; @@ -103,7 +111,7 @@ struct storedIRDataStruct { IRData receivedIRData; // extensions for sendRaw uint8_t rawCode[RAW_BUFFER_LENGTH]; // The durations if raw - uint8_t rawCodeLength; // The length of the code + uint16_t rawCodeLength; // The length of the code } sStoredIRData; bool sSendButtonWasActive; @@ -115,7 +123,9 @@ void setup() { pinMode(SEND_BUTTON_PIN, INPUT_PULLUP); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino @@ -127,9 +137,14 @@ void setup() { printActiveIRProtocols(&Serial); Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin - Serial.print(F("Ready to send IR signals at pin " STR(IR_SEND_PIN) " on press of button at pin ")); - Serial.println(SEND_BUTTON_PIN); + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ + Serial.print(F("Ready to send IR signal (with repeats) at pin " STR(IR_SEND_PIN) " as long as button at pin ")); + Serial.print(SEND_BUTTON_PIN); + Serial.println(F(" is pressed.")); } void loop() { @@ -166,6 +181,7 @@ void loop() { // Restart receiver Serial.println(F("Button released -> start receiving")); IrReceiver.start(); + delay(100); // Button debouncing } else if (IrReceiver.decode()) { /* @@ -176,15 +192,14 @@ void loop() { } sSendButtonWasActive = tSendButtonIsActive; - delay(100); } // Stores the code for later playback in sStoredIRData // Most of this code is just logging void storeCode() { - if (IrReceiver.decodedIRData.rawDataPtr->rawlen < 4) { + if (IrReceiver.irparams.rawlen < 4) { Serial.print(F("Ignore data with rawlen=")); - Serial.println(IrReceiver.decodedIRData.rawDataPtr->rawlen); + Serial.println(IrReceiver.irparams.rawlen); return; } if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { @@ -199,21 +214,31 @@ void storeCode() { Serial.println(F("Ignore parity error")); return; } + if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) { + Serial.println(F("Overflow occurred, raw data did not fit into " STR(RAW_BUFFER_LENGTH) " byte raw buffer")); + return; + } /* * Copy decoded data */ sStoredIRData.receivedIRData = IrReceiver.decodedIRData; - if (sStoredIRData.receivedIRData.protocol == UNKNOWN) { - Serial.print(F("Received unknown code and store ")); - Serial.print(IrReceiver.decodedIRData.rawDataPtr->rawlen - 1); - Serial.println(F(" timing entries as raw ")); - IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format - sStoredIRData.rawCodeLength = IrReceiver.decodedIRData.rawDataPtr->rawlen - 1; + auto tProtocol = sStoredIRData.receivedIRData.protocol; + if (tProtocol == UNKNOWN || tProtocol == PULSE_WIDTH || tProtocol == PULSE_DISTANCE) { + // TODO: support PULSE_WIDTH and PULSE_DISTANCE with IrSender.write + sStoredIRData.rawCodeLength = IrReceiver.irparams.rawlen - 1; /* * Store the current raw data in a dedicated array for later usage */ IrReceiver.compensateAndStoreIRResultInArray(sStoredIRData.rawCode); + /* + * Print info + */ + Serial.print(F("Received unknown or pulse width/distance code and store ")); + Serial.print(IrReceiver.irparams.rawlen - 1); + Serial.println(F(" timing entries as raw in buffer of size " STR(RAW_BUFFER_LENGTH))); + IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format + } else { IrReceiver.printIRResultShort(&Serial); IrReceiver.printIRSendUsage(&Serial); @@ -223,7 +248,8 @@ void storeCode() { } void sendCode(storedIRDataStruct *aIRDataToSend) { - if (aIRDataToSend->receivedIRData.protocol == UNKNOWN /* i.e. raw */) { + auto tProtocol = aIRDataToSend->receivedIRData.protocol; + if (tProtocol == UNKNOWN || tProtocol == PULSE_WIDTH || tProtocol == PULSE_DISTANCE /* i.e. raw */) { // Assume 38 KHz IrSender.sendRaw(aIRDataToSend->rawCode, aIRDataToSend->rawCodeLength, 38); @@ -231,12 +257,11 @@ void sendCode(storedIRDataStruct *aIRDataToSend) { Serial.print(aIRDataToSend->rawCodeLength); Serial.println(F(" marks or spaces")); } else { - /* * Use the write function, which does the switch for different protocols */ IrSender.write(&aIRDataToSend->receivedIRData); - printIRResultShort(&Serial, &aIRDataToSend->receivedIRData, false); + printIRDataShort(&Serial, &aIRDataToSend->receivedIRData); } } diff --git a/examples/ReceiveAndSendDistanceWidth/PinDefinitionsAndMore.h b/examples/ReceiveAndSendDistanceWidth/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ReceiveAndSendDistanceWidth/PinDefinitionsAndMore.h +++ b/examples/ReceiveAndSendDistanceWidth/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino b/examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino index 5c2e73556..9f79eac29 100644 --- a/examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino +++ b/examples/ReceiveAndSendDistanceWidth/ReceiveAndSendDistanceWidth.ino @@ -16,13 +16,14 @@ * A button must be connected between the input SEND_BUTTON_PIN and ground. * A visible LED can be connected to STATUS_PIN to provide status. * + * See also https://dronebotworkshop.com/ir-remotes/#ReceiveAndSendDistanceWidth_Code * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2023 Armin Joachimsmeyer + * Copyright (c) 2023-2025 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 @@ -45,33 +46,33 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. -#if !defined(IR_SEND_PIN) -#define IR_SEND_PIN 3 -#endif - /* * Specify DistanceWidthProtocol for decoding. This must be done before the #include */ #define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols // #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 120 -# elif RAMEND <= 0xAFF || RAMSIZE < 0xAFF // 0xAFF for LEONARDO -#define RAW_BUFFER_LENGTH 400 // 600 is too much here, because we have additional uint8_t rawCode[RAW_BUFFER_LENGTH]; +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else +// Here we most likely have 2 k RAM or more #define RAW_BUFFER_LENGTH 750 # endif #endif //#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define NO_LED_FEEDBACK_CODE // Saves 218 bytes program memory +//#define NO_LED_RECEIVE_FEEDBACK_CODE // Saves 82 bytes program memory +//#define NO_LED_SEND_FEEDBACK_CODE // Saves 58 bytes program memory //#define DEBUG // Activate this for lots of lovely debug output from the decoders. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include #define SEND_BUTTON_PIN APPLICATION_PIN @@ -79,8 +80,8 @@ #define DELAY_BETWEEN_REPEATS_MILLIS 70 // Storage for the recorded code, pre-filled with NEC data -IRRawDataType sDecodedRawDataArray[RAW_DATA_ARRAY_SIZE] = { 0x7B34ED12 }; // address 0x12 command 0x34 -DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = { 9000, 4500, 560, 1690, 560, 560 }; // NEC timing +IRDecodedRawDataType sDecodedRawDataArray[DECODED_RAW_DATA_ARRAY_SIZE] = { 0x7B34ED12 }; // Initialize with NEC address 0x12 and command 0x34 +DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = { 9000, 4500, 560, 1690, 560, 560 }; // Initialize with NEC timing uint8_t sNumberOfBits = 32; bool sSendButtonWasActive; @@ -89,7 +90,9 @@ void setup() { pinMode(SEND_BUTTON_PIN, INPUT_PULLUP); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino @@ -99,7 +102,11 @@ void setup() { IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); Serial.println(F("Ready to receive pulse distance/width coded IR signals at pin " STR(IR_RECEIVE_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR send setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ Serial.print(F("Ready to send IR signals at pin " STR(IR_SEND_PIN) " on press of button at pin ")); Serial.println(SEND_BUTTON_PIN); } @@ -173,7 +180,12 @@ void loop() { if (sDecodedRawDataArray[0] != IrReceiver.decodedIRData.decodedRawDataArray[0]) { *sDecodedRawDataArray = *IrReceiver.decodedIRData.decodedRawDataArray; // copy content here Serial.print(F("Store new sDecodedRawDataArray[0]=0x")); +# if (__INT_WIDTH__ < 32) Serial.println(IrReceiver.decodedIRData.decodedRawDataArray[0], HEX); +# else + PrintULL::print(&Serial, IrReceiver.decodedIRData.decodedRawDataArray[0], HEX); +# endif + } } IrReceiver.resume(); // resume receiver diff --git a/examples/ReceiveAndSendHob2Hood/PinDefinitionsAndMore.h b/examples/ReceiveAndSendHob2Hood/PinDefinitionsAndMore.h new file mode 100644 index 000000000..d3dd74992 --- /dev/null +++ b/examples/ReceiveAndSendHob2Hood/PinDefinitionsAndMore.h @@ -0,0 +1,366 @@ +/* + * PinDefinitionsAndMore.h + * + * Contains pin definitions for IRremote examples for various platforms + * as well as definitions for feedback LED and tone() and includes + * + * Copyright (C) 2021-2026 Armin Joachimsmeyer + * + * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * Arduino-IRremote is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Pin mapping table for different platforms + * + * Platform IR input IR output Tone Core/Pin schema + * -------------------------------------------------------------- + * DEFAULT/AVR 2 3 4 Arduino + * ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore + * ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore + * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core + * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore + * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore + * ATtiny1604 2 3|PA5 % + * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore + * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore + * MKR* 1 3 4 + * SAMD 2 3 4 + * ESP8266 14|D5 12|D6 % + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 + * APOLLO3 11 12 5 + * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 + */ +//#define _IR_MEASURE_TIMING // For debugging purposes. + +#if defined(__AVR__) +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. +#define IR_RECEIVE_PIN PIN_PB0 +#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. +#define TONE_PIN PIN_PB3 +#define _IR_TIMING_TEST_PIN PIN_PB3 + +# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" +// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. +# if defined(ARDUINO_AVR_DIGISPARKPRO) +// For use with Digispark original core +#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 +//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 +#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 +#define _IR_TIMING_TEST_PIN 10 // PA4 +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else +// For use with ATTinyCore +#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 +#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 +# endif + +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +#define IR_RECEIVE_PIN PIN_PB2 // INT0 +#define IR_SEND_PIN PIN_PA4 +#define TONE_PIN PIN_PA3 +#define _IR_TIMING_TEST_PIN PIN_PA5 + +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +// Pin 6 is TX, pin 7 is RX +#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 +#define IR_SEND_PIN PIN_PD4 // 4 +#define TONE_PIN PIN_PB1 // 9 +#define _IR_TIMING_TEST_PIN PIN_PB0 // 8 + +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore +// Tiny Core Dev board +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET +#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 + +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 14 +#define IR_SEND_PIN PIN_PA3 // 16 +#define TONE_PIN PIN_PA5 // 1 +#define APPLICATION_PIN PIN_PA4 // 0 +#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output +#define LED_BUILTIN PIN_PB5 // 4 + +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB2 // 5 + +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 + +# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ +|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ +|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ +|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ +|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ +|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \ +|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \ +|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \ +|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__) +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 13 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc. +#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here. +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit +// We have no built in LED at pin 13 -> reuse RX LED +#undef LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN_RX +# endif +# endif // defined(__AVR_ATtiny25__)... + +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ESP8266) +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW +#define IR_RECEIVE_PIN 14 // D5 +#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED +#define _IR_TIMING_TEST_PIN 2 // D4 +#define APPLICATION_PIN 13 // D7 + +#define tone(...) void() // tone() inhibits receive timer +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 + +#elif defined(ESP32) +#include + +// tone() is included in ESP32 core since 2.0.2 +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif +#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) +#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. +void tone(uint8_t aPinNumber, unsigned int aFrequency){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); +} +void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); + delay(aDuration); + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +void noTone(uint8_t aPinNumber){ + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) + +#define IR_RECEIVE_PIN 15 // D15 +#define IR_SEND_PIN 4 // D4 +#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 +#define APPLICATION_PIN 16 // RX2 pin + +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill +// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() +#define IR_RECEIVE_PIN PA6 +#define IR_RECEIVE_PIN_STRING "PA6" +#define IR_SEND_PIN PA7 +#define IR_SEND_PIN_STRING "PA7" +#define TONE_PIN PA3 +#define _IR_TIMING_TEST_PIN PA5 +#define APPLICATION_PIN PA2 +#define APPLICATION_PIN_STRING "PA2" +# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8) +// BluePill LED is active low +#define FEEDBACK_LED_IS_ACTIVE_LOW +# endif + +#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards +#define IR_RECEIVE_PIN 11 +#define IR_SEND_PIN 12 +#define TONE_PIN 5 + +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect +#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico +#define IR_SEND_PIN 4 // GPIO16 +#define TONE_PIN 5 +#define APPLICATION_PIN 6 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 8 + +#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico +#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3) +#define IR_SEND_PIN 16 // GPIO16 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 20 + +// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN +// and use the external reset with 1 kOhm to ground to enter UF2 mode +#undef LED_BUILTIN +#define LED_BUILTIN 6 + +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! +#define IR_RECEIVE_PIN A4 +#define IR_SEND_PIN A5 // Particle supports multiple pins + +#define LED_BUILTIN D7 + +/* + * 4 times the same (default) layout for easy adaption in the future + */ +#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else +#define IR_RECEIVE_PIN 2 +# endif +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0) +// On the Zero and others we switch explicitly to SerialUSB +#define Serial SerialUSB +#endif + +// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17. +// Attention!!! D2 and D4 are swapped on these boards!!! +// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 24 // PB11 +// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 25 // PB03 +//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW + +#elif defined (NRF51) // BBC micro:bit +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define APPLICATION_PIN 1 +#define _IR_TIMING_TEST_PIN 4 + +#define tone(...) void() // no tone() available +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it + +#else +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. +// Default valued for unidentified boards +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 +#endif // defined(ESP8266) + +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp +#endif + +#if !defined (FLASHEND) +#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined +#endif + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // +#endif +#if !defined (RAMSIZE) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined +#endif diff --git a/examples/ReceiveAndSendHob2Hood/ReceiveAndSendHob2Hood.ino b/examples/ReceiveAndSendHob2Hood/ReceiveAndSendHob2Hood.ino new file mode 100644 index 000000000..7a598f25d --- /dev/null +++ b/examples/ReceiveAndSendHob2Hood/ReceiveAndSendHob2Hood.ino @@ -0,0 +1,152 @@ +/* + * ReceiveAndSendHob2Hood.cpp + * + * Demonstrates receiving and sending of IR codes for AEG / Elektrolux Hob2Hood protocol + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + ************************************************************************************ + * MIT License + * + * Copyright (c) 2024 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. + * + ************************************************************************************ + */ + +#include + +#define DECODE_HASH // Only decoder, which works for Hob2Hood. protocol is UNKNOWN and only raw data is set. + +//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory +//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. +//#define NO_LED_FEEDBACK_CODE // Saves 310 bytes program memory +//#define NO_LED_RECEIVE_FEEDBACK_CODE // Saves 44 bytes program memory +//#define NO_LED_SEND_FEEDBACK_CODE // Saves 34 bytes program memory + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. +#include + +// IR commands from AEG hob2hood device +#define NUMBER_OF_HOB_TO_HOOD_COMMANDS 7 +#define HOB_TO_HOOD_HASH_CODE_FAN_1 0xE3C01BE2 +#define HOB_TO_HOOD_HASH_CODE_FAN_2 0xD051C301 +#define HOB_TO_HOOD_HASH_CODE_FAN_3 0xC22FFFD7 +#define HOB_TO_HOOD_HASH_CODE_FAN_4 0xB9121B29 +#define HOB_TO_HOOD_HASH_CODE_FAN_OFF 0x55303A3 +#define HOB_TO_HOOD_HASH_CODE_LIGHT_ON 0xE208293C +#define HOB_TO_HOOD_HASH_CODE_LIGHT_OFF 0x24ACF947 + +// based on https://pastebin.com/N6kG7Wu5 +#define HOB_TO_HOOD_UNIT_MICROS 725 +#define H2H_1 HOB_TO_HOOD_UNIT_MICROS +#define H2H_2 (HOB_TO_HOOD_UNIT_MICROS*2) // 1450 +#define H2H_3 (HOB_TO_HOOD_UNIT_MICROS*3) // 2175 +#define H2H_4 (HOB_TO_HOOD_UNIT_MICROS*4) // 2900 +#define H2H_5 (HOB_TO_HOOD_UNIT_MICROS*5) // 3625 + +// First entry is the length of the raw command +const uint16_t Fan1[] PROGMEM { 15, H2H_2, H2H_2, H2H_1, H2H_2, H2H_3, H2H_2, H2H_1, H2H_2, H2H_1, H2H_1, H2H_1, H2H_2, H2H_1, +H2H_3, H2H_1 }; +const uint16_t Fan2[] PROGMEM { 9, H2H_2, H2H_2, H2H_1, H2H_4, H2H_1, H2H_3, H2H_5, H2H_3, H2H_3 }; +const uint16_t Fan3[] PROGMEM { 9, H2H_1, H2H_3, H2H_4, H2H_4, H2H_3, H2H_1, H2H_1, H2H_3, H2H_3 }; +const uint16_t Fan4[] PROGMEM { 13, H2H_2, H2H_3, H2H_2, H2H_1, H2H_2, H2H_3, H2H_2, H2H_2, H2H_1, H2H_3, H2H_1, H2H_1, H2H_2 }; +const uint16_t FanOff[] PROGMEM { 15, H2H_1, H2H_2, H2H_1, H2H_2, H2H_3, H2H_2, H2H_1, H2H_2, H2H_2, H2H_3, H2H_1, H2H_2, H2H_1, +H2H_1, H2H_1 }; +const uint16_t LightOn[] PROGMEM { 17, H2H_1, H2H_2, H2H_1, H2H_1, H2H_2, H2H_1, H2H_1, H2H_2, H2H_1, H2H_1, H2H_2, H2H_4, H2H_1, +H2H_1, H2H_1, H2H_1, H2H_2 }; +const uint16_t LightOff[] PROGMEM { 17, H2H_1, H2H_2, H2H_1, H2H_1, H2H_1, H2H_1, H2H_1, H2H_3, H2H_1, H2H_1, H2H_1, H2H_2, H2H_1, +H2H_2, H2H_1, H2H_1, H2H_1 }; +const uint16_t *const Hob2HoodSendCommands[NUMBER_OF_HOB_TO_HOOD_COMMANDS] = { Fan1, Fan2, Fan3, Fan4, FanOff, LightOn, LightOff }; // Constant array in RAM + +void setup() { + Serial.begin(115200); + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! +#endif + // Just to know which program is running on my Arduino + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); + + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); + + Serial.print(F("Ready to receive Hob2Hood IR signals at pin " STR(IR_RECEIVE_PIN))); + /* + * No IR send setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ + Serial.println(F("Send Hob2Hood IR signals at pin " STR(IR_SEND_PIN))); +} + +/* + * Receive and send Hob2Hood protocol + */ +void loop() { + static long sLastMillisOfSend = 0; + static uint8_t sSendCommandIndex = 0; + + if (IrReceiver.decode()) { + IrReceiver.resume(); // Early enable receiving of the next IR frame + IrReceiver.printIRResultShort(&Serial); + + /* + * Finally, check the received data and perform actions according to the received command + */ + switch (IrReceiver.decodedIRData.decodedRawData) { + case HOB_TO_HOOD_HASH_CODE_FAN_OFF: + Serial.print(F("FAN off")); + break; + case HOB_TO_HOOD_HASH_CODE_FAN_1: + Serial.print(F("FAN 1")); + break; + case HOB_TO_HOOD_HASH_CODE_FAN_2: + Serial.print(F("FAN 2")); + break; + default: + Serial.print(F("unknown Hob2Hood IR command")); + break; + } + } + + /* + * Send next command every 5 seconds + */ + if (millis() - sLastMillisOfSend > 2000) { + sLastMillisOfSend = millis(); + +#if defined(__AVR__) + uint16_t tLengthOfRawCommand = pgm_read_word(Hob2HoodSendCommands[sSendCommandIndex]); // length is the 1. word in array +#else + uint16_t tLengthOfRawCommand = *Hob2HoodSendCommands[sSendCommandIndex]; // length is the 1. word in array +#endif + const uint16_t *tAddressOfRawCommandSequence = Hob2HoodSendCommands[sSendCommandIndex] + 1; // Raw sequence starts at the 2. word of array + Serial.print(F("Send Hob2Hood command index=")); + Serial.println(sSendCommandIndex); + IrSender.sendRaw_P(tAddressOfRawCommandSequence, tLengthOfRawCommand, 38); + + // Prepare for next command + sSendCommandIndex++; + if (sSendCommandIndex >= NUMBER_OF_HOB_TO_HOOD_COMMANDS) { + sSendCommandIndex = 0; + } + } +} diff --git a/examples/ReceiveDemo/PinDefinitionsAndMore.h b/examples/ReceiveDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ReceiveDemo/PinDefinitionsAndMore.h +++ b/examples/ReceiveDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ReceiveDemo/ReceiveDemo.ino b/examples/ReceiveDemo/ReceiveDemo.ino index e2659dec5..6de9fb7f0 100644 --- a/examples/ReceiveDemo/ReceiveDemo.ino +++ b/examples/ReceiveDemo/ReceiveDemo.ino @@ -3,14 +3,14 @@ * * Demonstrates receiving IR codes with the IRremote library and the use of the Arduino tone() function with this library. * Long press of one IR button (receiving of multiple repeats for one command) is detected. - * If debug button is pressed (pin connected to ground) a long output is generated. + * If debug button is pressed (pin connected to ground) a long output is generated, which may disturb detecting of repeats. * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -34,91 +34,133 @@ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. //#define LOCAL_DEBUG // If defined, print timing for each received data set (the same as if DEBUG_BUTTON_PIN was connected to low) /* * Specify which protocol(s) should be used for decoding. - * If no protocol is defined, all protocols (except Bang&Olufsen) are active. + * If no protocol is defined, all protocols (except BEO / Bang&Olufsen) are active. * This must be done before the #include + * In alphabetic order */ -//#define DECODE_DENON // Includes Sharp -//#define DECODE_JVC -//#define DECODE_KASEIKYO -//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO -//#define DECODE_LG -//#define DECODE_ONKYO // Decodes only Onkyo and not NEC or Apple -//#define DECODE_NEC // Includes Apple and Onkyo -//#define DECODE_SAMSUNG -//#define DECODE_SONY -//#define DECODE_RC5 -//#define DECODE_RC6 - -//#define DECODE_BOSEWAVE -//#define DECODE_LEGO_PF -//#define DECODE_MAGIQUEST -//#define DECODE_WHYNTER -//#define DECODE_FAST - -//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols -//#define DECODE_HASH // special decoder for all protocols - -//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY! - -#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. +//#define DECODE_DENON // Includes Sharp - requires around 250 bytes of program memory on ATmega328 +//#define DECODE_JVC // ~ 200 bytes +//#define DECODE_KASEIKYO // Includes Panasonic ~ 300 bytes +//#define DECODE_LG // ~ 400 bytes +//#define DECODE_NEC // Includes Apple and Onkyo ~ 250 bytes +//#define DECODE_SAMSUNG // ~ 300 bytes +//#define DECODE_SONY // ~ 175 bytes +//#define DECODE_RC5 // RC5 + MARANTZ: ~ 425 bytes +//#define DECODE_RC6 // ~ 375 bytes + +// Universal protocol decoder +//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols ~ 2275 bytes +//#define DECODE_HASH // special decoder for all protocols ~ 250 bytes + +// Exotic protocol decoder +//#define DECODE_BOSEWAVE // ~ 140 bytes +//#define DECODE_FAST // ~ 135 bytes +//#define DECODE_LEGO_PF // ~ 300 bytes +//#define DECODE_MAGIQUEST // ~ 270 bytes +//#define DECODE_MARANTZ // RC5 + MARANTZ: ~ 425 bytes +//#define DECODE_OPENLASIR // Modified NEC with 8-bit validated address + 16-bit command. ~ 175 bytes +//#define DECODE_WHYNTER // ~ 90 bytes + +//#define DECODE_ONKYO // Decodes NEC and Apple as Onkyo - saves around 90 bytes of program memory, if activated +//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY! ~ 430 bytes +#if FLASHEND >= 0x7FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. +// Do not enable any protocol explicitly => all protocols are enabled automatically. // !!! Enabling B&O disables detection of Sony, because the repeat gap for SONY is smaller than the B&O frame gap :-( !!! -//#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It has an IR transmit frequency of 455 kHz! It prevents decoding of SONY! -#endif -#if defined(DECODE_BEO) -#define RECORD_GAP_MICROS 16000 // always get the complete frame in the receive buffer, but this prevents decoding of SONY! +//#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It has an IR transmit frequency of 455 kHz! It prevents decoding of SONY! ~ 430 bytes +#else +// for 8k flash +//#define DECODE_DENON // Includes Sharp - requires around 250 bytes of program memory on ATmega328 +//#define DECODE_JVC // ~ 200 bytes +#define DECODE_KASEIKYO // Includes Panasonic ~ 300 bytes +#define DECODE_LG // ~ 400 bytes +#define DECODE_NEC // Includes Apple and Onkyo ~ 250 bytes +#define DECODE_SAMSUNG // ~ 300 bytes +//#define DECODE_SONY // ~ 175 bytes +//#define DECODE_RC5 // RC5 + MARANTZ: ~ 425 bytes +//#define DECODE_RC6 // ~ 375 bytes +#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols ~ 2275 bytes +#define DECODE_HASH // special decoder for all protocols ~ 250 bytes + +#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 90 bytes of program memory, if activated #endif // etc. see IRremote.hpp // #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 130 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active -#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 600 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# else -#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 +# elif RAMSIZE <= 0x800 +// Here we have 2 k RAM or less, otherwise use default of 750 +#define RAW_BUFFER_LENGTH 600 // 400 is OK with Pronto and 1000 is OK without Pronto. 1200 is too much here, because then variables are overwritten. # endif #endif -//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory +//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory //#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. -//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active +//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active +//#define USE_THRESHOLD_DECODER // May give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses. Requires additional 1 bytes program memory. +//#define IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK // saves 32 bytes program memory +//#define USE_16_BIT_TIMING_BUFFER // Use a 16-bit buffer to preserve values above 12750 us +#define SHOW_DISTANCE_WIDTH_DECODER_ERRORS // Prints the reason which prevents data to be decoded as distance width data // MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, -// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142. -//#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 40 is taken for the cheap VS1838 module her, since we have high intensity. +// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 135. +// 20 is taken as default if not otherwise specified / defined. +//#define MARK_EXCESS_MICROS 40 // Adapt it to your IR receiver module. 40 is recommended for the cheap VS1838 modules at high intensity. -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols +#if defined(DECODE_BEO) +#define RECORD_GAP_MICROS 16000 // always get the complete frame in the receive buffer, but this prevents decoding of SONY! +#endif +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols //#define DEBUG // Activate this for lots of lovely debug output from the decoders. #include -#if defined(APPLICATION_PIN) -#define DEBUG_BUTTON_PIN APPLICATION_PIN // if low, print timing for each received data set +#if defined(APPLICATION_PIN) && !defined(DEBUG_BUTTON_PIN) +#define DEBUG_BUTTON_PIN APPLICATION_PIN // if held low, print timing for each received data #else #define DEBUG_BUTTON_PIN 6 #endif +#if defined(ESP32) && defined(DEBUG_BUTTON_PIN) +# if !digitalPinIsValid(DEBUG_BUTTON_PIN) +#undef DEBUG_BUTTON_PIN // DEBUG_BUTTON_PIN number is not valid, so delete definition to disable further usage +# endif +#endif + +/* + * Using the function printActiveIRProtocols() requires additional 314 bytes program memory + * Using the function printIRResultShort() requires additional 1450 bytes program memory + * Using the function printIRSendUsage() requires additional 2736 bytes program memory + * Because these 3 functions all share common code, using all 3 functions requires only additional 3016 bytes program memory + */ +void generateTone(); +void handleOverflow(); bool detectLongPress(uint16_t aLongPressDurationMillis); void setup() { #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. +# if defined(DEBUG_BUTTON_PIN) pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP); +# endif #endif Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) || (defined(ESP32) && defined(ARDUINO_USB_MODE)) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -137,23 +179,33 @@ void setup() { Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); #endif +#if defined(LED_BUILTIN) && !defined(NO_LED_FEEDBACK_CODE) +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + Serial.print(F("Active low ")); +# endif + Serial.print(F("FeedbackLED at pin ")); + Serial.println(LED_BUILTIN); // Works also for ESP32: static const uint8_t LED_BUILTIN = 8; #define LED_BUILTIN LED_BUILTIN +#endif + #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. Serial.println(); +# if defined(DEBUG_BUTTON_PIN) Serial.print(F("If you connect debug pin ")); -# if defined(APPLICATION_PIN_STRING) - Serial.print(APPLICATION_PIN_STRING); -# else Serial.print(DEBUG_BUTTON_PIN); + Serial.println(F(" to ground, raw data is always printed and tone is disabled")); # endif - Serial.println(F(" to ground, raw data is always printed")); // infos for receive Serial.print(RECORD_GAP_MICROS); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); + +# if defined(USE_THRESHOLD_DECODER) + Serial.println(F("Threshold decoding is active and thus MARK_EXCESS_MICROS is set to 0")); +# else Serial.print(MARK_EXCESS_MICROS); Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); -#endif - +# endif +#endif // FLASHEND >= 0x3FFF } void loop() { @@ -164,114 +216,95 @@ void loop() { * E.g. command is in IrReceiver.decodedIRData.command * address is in command is in IrReceiver.decodedIRData.address * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData - * - * At 115200 baud, printing takes 40 ms for NEC protocol and 10 ms for NEC repeat */ if (IrReceiver.decode()) { Serial.println(); -#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 +#if FLASHEND < 0x3FFF // For less than 16k flash, only print a minimal summary of received data + IrReceiver.printIRResultMinimal(&Serial); +#else + + /* + * + */ if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) { - Serial.println(F("Overflow detected")); - Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__)); - // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library -# if !defined(ESP8266) && !defined(NRF5) + handleOverflow(); + } else { /* - * do double beep + * No overflow here. + * Stop receiver, generate a single beep, print short info and send usage and start receiver again */ -# if !defined(ESP32) - IrReceiver.stop(); // ESP32 uses another timer for tone() -# endif - tone(TONE_PIN, 1100, 10); - delay(50); - tone(TONE_PIN, 1100, 10); - delay(50); -# if !defined(ESP32) - IrReceiver.start(100000); // to compensate for 100 ms stop of receiver. This enables a correct gap measurement. -# endif -# endif - - } else { - auto tStartMillis = millis(); -# if !defined(ESP32) - IrReceiver.stop(); // ESP32 uses another timer for tone() -# endif - tone(TONE_PIN, 2200); - - // No overflow, print a short summary of received data -# if defined(LOCAL_DEBUG) - IrReceiver.printIRResultShort(&Serial, true); -# else - IrReceiver.printIRResultShort(&Serial, true, digitalRead(DEBUG_BUTTON_PIN) == LOW); -# endif - // Guarantee at least 5 millis for tone. decode starts 5 millis (RECORD_GAP_MICROS) after end of frame - // so here we are 10 millis after end of frame. Sony20 has only a 12 ms repeat gap. - while ((millis() - tStartMillis) < 5) - ; - noTone(TONE_PIN); - -# if !defined(ESP32) - // Restore IR timer. millis() - tStartMillis to compensate for stop of receiver. This enables a correct gap measurement. - IrReceiver.startWithTicksToAdd((millis() - tStartMillis) * (MICROS_IN_ONE_MILLI / MICROS_PER_TICK)); -# endif + if ((IrReceiver.decodedIRData.protocol != SONY) && (IrReceiver.decodedIRData.protocol != PULSE_WIDTH) + && (IrReceiver.decodedIRData.protocol != PULSE_DISTANCE) && (IrReceiver.decodedIRData.protocol != UNKNOWN) +#if defined(DEBUG_BUTTON_PIN) + && digitalRead(DEBUG_BUTTON_PIN) != LOW +#endif + ) { + /* + * For SONY the tone prevents the detection of a repeat after the 15 ms SONY gap. + * In debug mode and for unknown protocols, we need the time for extended output. + * Skipping tone will get exact gap time between transmissions and not running into repeat frames while wait for tone to end. + * This in turn enables the next CheckForRecordGapsMicros() call a chance to eventually propose a change of the current RECORD_GAP_MICROS value. + */ + generateTone(); + } - IrReceiver.printIRSendUsage(&Serial); -# if defined(LOCAL_DEBUG) - IrReceiver.printIRResultRawFormatted(&Serial, true); -# else - if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) { - // We have an unknown protocol, print more info + /* + * Print info + */ + if (IrReceiver.decodedIRData.protocol == UNKNOWN +#if defined(DEBUG_BUTTON_PIN) + || digitalRead(DEBUG_BUTTON_PIN) == LOW +#endif + ) { + // We have debug enabled or an unknown protocol, print extended info if (IrReceiver.decodedIRData.protocol == UNKNOWN) { Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); } IrReceiver.printIRResultRawFormatted(&Serial, true); } -# endif - } - - // tone on esp8266 works once, then it disables the successful IrReceiver.start() / timerConfigForReceive(). -# if !defined(ESP8266) && !defined(NRF5) && !defined(LOCAL_DEBUG) - if ((IrReceiver.decodedIRData.protocol != SONY) && (IrReceiver.decodedIRData.protocol != PULSE_WIDTH) - && (IrReceiver.decodedIRData.protocol != PULSE_DISTANCE) && (IrReceiver.decodedIRData.protocol != UNKNOWN) - && digitalRead(DEBUG_BUTTON_PIN) != LOW) { - /* - * If no debug mode or a valid protocol was received, play tone, wait and restore IR timer. - * For SONY the tone prevents the detection of a repeat - * Otherwise do not play a tone to get exact gap time between transmissions and not running into repeat frames while wait for tone to end. - * This will give the next CheckForRecordGapsMicros() call a chance to eventually propose a change of the current RECORD_GAP_MICROS value. - */ -# if !defined(ESP32) - IrReceiver.stop(); // ESP32 uses another timer for tone() -# endif - tone(TONE_PIN, 2200, 8); -# if !defined(ESP32) - delay(8); - IrReceiver.start(8000); // Restore IR timer. 8000 to compensate for 8 ms stop of receiver. This enables a correct gap measurement. + if (IrReceiver.decodedIRData.protocol == UNKNOWN) { + auto tDecodedRawData = IrReceiver.decodedIRData.decodedRawData; // uint32_t on 8 and 16 bit CPUs and uint64_t on 32 and 64 bit CPUs + Serial.print(F("Raw data from hash decoder is 0x")); +# if (__INT_WIDTH__ < 32) + Serial.println(tDecodedRawData); +# else + PrintULL::println(&Serial, tDecodedRawData, BIN); # endif + + } else { + /* + * The info output for a successful receive + */ + IrReceiver.printIRResultShort(&Serial); + IrReceiver.printIRSendUsage(&Serial); // Calls printIRResultShort() and other functions, if protocol is UNKNOWN + } } -# endif -#else // #if FLASHEND >= 0x3FFF - // Print a minimal summary of received data - IrReceiver.printIRResultMinimal(&Serial); #endif // #if FLASHEND >= 0x3FFF /* - * !!!Important!!! Enable receiving of the next value, - * since receiving has stopped after the end of the current received data packet. + * !!!Important!!! Enable receiving of the next value, because receiving + * has stopped after the end of the current received data packet. + * Do it here, to preserve raw data for printing with printIRResultRawFormatted() */ IrReceiver.resume(); /* * Finally check the received data and perform actions according to the received address and commands */ - if (IrReceiver.decodedIRData.address == 0) { - if (IrReceiver.decodedIRData.command == 0x10) { - // do something - } else if (IrReceiver.decodedIRData.command == 0x11) { - // do something else + + if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { + Serial.println(F("Repeat received. Here you can repeat the same action as before.")); + } else { + if (IrReceiver.decodedIRData.address == 0) { + if (IrReceiver.decodedIRData.command == 0x10) { + // do something + } else if (IrReceiver.decodedIRData.command == 0x11) { + // do something else + } } } - // Check if the command was repeated for more than 1000 ms + // Check if repeats of the IR command was sent for more than 1000 ms if (detectLongPress(1000)) { Serial.print(F("Command 0x")); Serial.print(IrReceiver.decodedIRData.command, HEX); @@ -289,10 +322,54 @@ void loop() { } +#if FLASHEND >= 0x3FFF // No tone() available when using ATTinyCore +/* + * Stop receiver, generate a single beep and start receiver again + */ +void generateTone() { +# if !defined(ESP8266) && !defined(NRF5) && defined(TONE_PIN) // tone on esp8266 works only once, then it disables IrReceiver.restartTimer() / timerConfigForReceive(). +# if defined(ESP32) // ESP32 uses another timer for tone(), maybe other platforms (not tested yet) too. + tone(TONE_PIN, 2200, 8); +# else + IrReceiver.stopTimer(); // Stop timer consistently before calling tone() or other functions using the timer resource. + tone(TONE_PIN, 2200, 8); + delay(8); + IrReceiver.restartTimer(); // Restart IR timer after timer resource is no longer blocked. +# endif +# endif +} +#endif // FLASHEND >= 0x3FFF + +void handleOverflow() { + Serial.println(F("Overflow detected")); + Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__)); + // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library + +#if !defined(ESP8266) && !defined(NRF5) && FLASHEND >= 0x3FFF && defined(TONE_PIN) // tone on esp8266 works once, then it disables IrReceiver.restartTimer() / timerConfigForReceive(). + /* + * Stop timer, generate a double beep and start timer again + */ +# if defined(ESP32) // ESP32 uses another timer for tone() + tone(TONE_PIN, 1100, 10); + delay(50); + tone(TONE_PIN, 1100, 10); +# else + IrReceiver.stopTimer(); + tone(TONE_PIN, 1100, 10); + delay(50); + tone(TONE_PIN, 1100, 10); + delay(50); + IrReceiver.restartTimer(); +# endif +#endif +} + unsigned long sMillisOfFirstReceive; bool sLongPressJustDetected; /** - * @return true once after the repeated command was received for longer than aLongPressDurationMillis milliseconds, false otherwise. + * True once we received the consecutive repeats for more than aLongPressDurationMillis milliseconds. + * The first frame, which is no repeat, is NOT counted for the duration! + * @return true once after the repeated IR command was received for longer than aLongPressDurationMillis milliseconds, false otherwise. */ bool detectLongPress(uint16_t aLongPressDurationMillis) { if (!sLongPressJustDetected && (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) { diff --git a/examples/ReceiveDump/PinDefinitionsAndMore.h b/examples/ReceiveDump/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ReceiveDump/PinDefinitionsAndMore.h +++ b/examples/ReceiveDump/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ReceiveDump/ReceiveDump.ino b/examples/ReceiveDump/ReceiveDump.ino index 0f3297788..84b570061 100644 --- a/examples/ReceiveDump/ReceiveDump.ino +++ b/examples/ReceiveDump/ReceiveDump.ino @@ -10,7 +10,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2022 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -33,32 +33,32 @@ */ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. - #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -#define RAW_BUFFER_LENGTH 180 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 600 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 # else -#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Here we most likely have 2 k RAM or more +#define RAW_BUFFER_LENGTH 750 // this allows usage of 16 bit raw buffer, for RECORD_GAP_MICROS > 20000 # endif #endif /* * MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, - * to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142. + * to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 135. + * 20 is taken as default if not otherwise specified / defined. * * You can change this value accordingly to the receiver module you use. * The required value can be derived from the timings printed here. * Keep in mind that the timings may change with the distance * between sender and receiver as well as with the ambient light intensity. */ -#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules. - -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols +//#define MARK_EXCESS_MICROS 40 // Adapt it to your IR receiver module. 40 is recommended for the cheap VS1838 modules at high intensity. +//#define USE_16_BIT_TIMING_BUFFER // Use a 16-bit buffer to preserve values above 12750 us +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols //#define DEBUG // Activate this for lots of lovely debug output from the decoders. - +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include //+============================================================================= @@ -68,9 +68,17 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); // Status message will be sent to PC at 9600 baud -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -84,10 +92,22 @@ void setup() { // infos for receive Serial.print(RECORD_GAP_MICROS); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); + +# if defined(USE_THRESHOLD_DECODER) + Serial.println(F("Threshold decoding is active and thus MARK_EXCESS_MICROS is set to 0")); +# else Serial.print(MARK_EXCESS_MICROS); + Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); +# endif + + Serial.println(); + Serial.println(F("Because of the verbose output (>200 ms at 115200 baud), repeats are not dumped correctly!")); Serial.println(); - Serial.println(F("Because of the verbose output (>200 ms at 115200), repeats are probably not dumped correctly!")); + Serial.println( + F( + "If you receive protocol NEC, Samsung or LG, run also ReceiveDemo to check if your actual protocol is eventually NEC2 or SamsungLG, which is determined by the repeats")); Serial.println(); + } //+============================================================================= @@ -118,10 +138,14 @@ void loop() { Serial.print(F("Result as internal 8bit ticks (50 us) array - compensated with MARK_EXCESS_MICROS=")); Serial.println(MARK_EXCESS_MICROS); IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false); // Output the results as uint8_t source code array of ticks + Serial.println(); // blank line between entries Serial.print(F("Result as microseconds array - compensated with MARK_EXCESS_MICROS=")); Serial.println(MARK_EXCESS_MICROS); IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, true); // Output the results as uint16_t source code array of micros + Serial.println(); // blank line between entries IrReceiver.printIRResultAsCVariables(&Serial); // Output address and data as source code variables + Serial.println(); // blank line between entries + Serial.println(); // blank line between entries IrReceiver.compensateAndPrintIRResultAsPronto(&Serial); @@ -129,7 +153,7 @@ void loop() { * Example for using the compensateAndStorePronto() function. * Creating this String requires 2210 bytes program memory and 10 bytes RAM for the String class. * The String object itself requires additional 440 bytes RAM from the heap. - * This values are for an Arduino UNO. + * This values are for an Arduino Uno. */ // Serial.println(); // blank line between entries // String ProntoHEX = F("Pronto HEX contains: "); // Assign string to ProtoHex string object @@ -144,6 +168,6 @@ void loop() { // Serial.println(); // blank line between entries // } } - IrReceiver.resume(); // Prepare for the next value + IrReceiver.resume(); // Prepare for the next IR frame } } diff --git a/examples/ReceiveOneAndSendMultiple/PinDefinitionsAndMore.h b/examples/ReceiveOneAndSendMultiple/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/ReceiveOneAndSendMultiple/PinDefinitionsAndMore.h +++ b/examples/ReceiveOneAndSendMultiple/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/ReceiveOneAndSendMultiple/ReceiveOneAndSendMultiple.ino b/examples/ReceiveOneAndSendMultiple/ReceiveOneAndSendMultiple.ino index 34baa144e..f7277fa6b 100644 --- a/examples/ReceiveOneAndSendMultiple/ReceiveOneAndSendMultiple.ino +++ b/examples/ReceiveOneAndSendMultiple/ReceiveOneAndSendMultiple.ino @@ -13,7 +13,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2022 Armin Joachimsmeyer + * Copyright (c) 2020-2025 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 @@ -44,7 +44,7 @@ // USB- 3.6V Z-Diode IR Output (4) PB4 3| |6 PB1 (1) Feedback LED // GND 4| |5 PB0 (0) IR Input // +----+ -/* SAUMSUMG REMOTE CODES (Model: BN59-01180A) +/* SAUMSUMG REMOTE CODES (Model: BN59-01180A) - Address is 0x07 * Power Button - 0x2 * Power Off - 0x98 * 1 - 0x4 @@ -90,11 +90,13 @@ #include +//#define NO_LED_FEEDBACK_CODE // Saves 104 bytes program memory + // select only Samsung protocol for sending and receiving #define DECODE_SAMSUNG -#define ADDRESS_OF_SAMSUNG_REMOTE 0x0707 // The value you see as address in printIRResultShort() +#define ADDRESS_OF_SAMSUNG_REMOTE 0x07 // The value you see as address in printIRResultShort() -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include void sendSamsungSmartHubMacro(bool aDoSelect); @@ -104,14 +106,18 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); // tone before IR setup, since it kills the IR timer settings +#if defined(TONE_PIN) tone(TONE_PIN, 2200, 400); +#endif digitalWrite(LED_BUILTIN, HIGH); delay(400); digitalWrite(LED_BUILTIN, LOW); @@ -123,7 +129,11 @@ void setup() { printActiveIRProtocols(&Serial); Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR send setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ Serial.println(F("Ready to send IR signals at pin " STR(IR_SEND_PIN))); } @@ -189,9 +199,9 @@ void sendSamsungSmartHubMacro(bool aDoSelect) { tWaitTimeAfterBoot = INITIAL_WAIT_TIME_SMARTHUB_READY_MILLIS; } -# if !defined(ESP32) - IrReceiver.stop(); // ESP32 uses another timer for tone() -# endif +#if !defined(ESP32) // ESP32 uses another timer for tone(), so the receiver must not be stopped and restarted for it + IrReceiver.stopTimer(); +#endif if (millis() < tWaitTimeAfterBoot) { // division by 1000 and printing requires much (8%) program memory Serial.print(F("It is ")); @@ -200,10 +210,12 @@ void sendSamsungSmartHubMacro(bool aDoSelect) { Serial.print(tWaitTimeAfterBoot / 1000); Serial.println(F(" seconds after boot to be ready for the command")); +#if defined(TONE_PIN) tone(TONE_PIN, 2200, 100); delay(200); tone(TONE_PIN, 2200, 100); delay(100); +#endif if (millis() < tWaitTimeAfterBoot) { Serial.print(F("Now do a blocking wait for ")); @@ -214,12 +226,14 @@ void sendSamsungSmartHubMacro(bool aDoSelect) { } // Do beep feedback for special key to be received +#if defined(TONE_PIN) tone(TONE_PIN, 2200, 200); delay(200); +#endif -# if !defined(ESP32) - IrReceiver.start(200000); // to compensate for 200 ms stop of receiver. This enables a correct gap measurement. -# endif +#if !defined(ESP32) + IrReceiver.restartTimer(); // Restart IR timer. +#endif Serial.println(F("Wait for \"not supported\" to disappear")); delay(2000); diff --git a/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino b/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino index 1ee2bf92b..99e67014e 100644 --- a/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino +++ b/examples/ReceiverTimingAnalysis/ReceiverTimingAnalysis.ino @@ -11,7 +11,6 @@ * * * Copyright (C) 2019-2020 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com * * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. @@ -33,48 +32,59 @@ #include -#define IR_INPUT_PIN 2 -//#define IR_INPUT_PIN 3 +#define IR_RECEIVE_PIN 2 +//#define IR_RECEIVE_PIN 3 -/* - * Helper macro for getting a macro definition as string - */ +// Helper macro for getting a macro definition as string +#if !defined(STR_HELPER) && !defined(STR) #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) +#endif +#if !(defined(EICRA) && defined(EIFR) && defined(EIMSK)) void measureTimingISR(void); +#endif -void setup() -{ +void setup() { pinMode(LED_BUILTIN, OUTPUT); + Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__)); #if defined(EICRA) && defined(EIFR) && defined(EIMSK) -# if (IR_INPUT_PIN == 2) +# if (IR_RECEIVE_PIN == 2) EICRA |= _BV(ISC00); // interrupt on any logical change EIFR |= _BV(INTF0); // clear interrupt bit EIMSK |= _BV(INT0); // enable interrupt on next change -# elif (IR_INPUT_PIN == 3) +# elif (IR_RECEIVE_PIN == 3) EICRA |= _BV(ISC10); // enable interrupt on pin3 on both edges for ATmega328 EIFR |= _BV(INTF1); // clear interrupt bit EIMSK |= _BV(INT1); // enable interrupt on next change # endif #else - attachInterrupt(digitalPinToInterrupt(IR_INPUT_PIN), measureTimingISR, CHANGE); +# if defined(ARDUINO_ARCH_SAMD) // see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ paragraph: Syntax + attachInterrupt(IR_RECEIVE_PIN, measureTimingISR, CHANGE); +# else + attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), measureTimingISR, CHANGE); // CHANGE can also be an enum :-( +# endif #endif - Serial.println(F("Ready to analyze NEC IR signal at pin " STR(IR_INPUT_PIN))); + Serial.println(F("Ready to analyze NEC IR signal at pin " STR(IR_RECEIVE_PIN))); Serial.println(); } uint8_t ISREdgeCounter = 0; volatile uint32_t LastMicros; -struct timingStruct -{ +struct timingStruct { uint16_t minimum; uint8_t indexOfMinimum; uint16_t maximum; @@ -93,23 +103,19 @@ struct timingStruct LongSpace; /* * Compute minimum, maximum and average */ -void processTmingValue(struct timingStruct *aTimingStruct, uint16_t aValue) -{ - if (aTimingStruct->SampleCount == 0) - { +void processTmingValue(struct timingStruct *aTimingStruct, uint16_t aValue) { + if (aTimingStruct->SampleCount == 0) { // initialize values aTimingStruct->minimum = UINT16_MAX; aTimingStruct->maximum = 0; aTimingStruct->SumForAverage = 0; } - if (aTimingStruct->minimum > aValue) - { + if (aTimingStruct->minimum > aValue) { aTimingStruct->minimum = aValue; aTimingStruct->indexOfMinimum = aTimingStruct->SampleCount; } - if (aTimingStruct->maximum < aValue) - { + if (aTimingStruct->maximum < aValue) { aTimingStruct->maximum = aValue; aTimingStruct->indexOfMaximum = aTimingStruct->SampleCount; } @@ -120,8 +126,7 @@ void processTmingValue(struct timingStruct *aTimingStruct, uint16_t aValue) } -void printTimingValues(struct timingStruct *aTimingStruct, const char *aCaption) -{ +void printTimingValues(struct timingStruct *aTimingStruct, const char *aCaption) { // if (aTimingStruct->LastPrintedCount != aTimingStruct->SampleCount) // { // aTimingStruct->LastPrintedCount = aTimingStruct->SampleCount; @@ -145,10 +150,8 @@ void printTimingValues(struct timingStruct *aTimingStruct, const char *aCaption) // } } -void loop() -{ - if (Mark.SampleCount >= 32) - { +void loop() { + if (Mark.SampleCount >= 32) { /* * This check enables statistics for longer protocols like Kaseikyo/Panasonics */ @@ -161,8 +164,7 @@ void loop() #endif uint32_t tMicrosDelta = micros() - tLastMicros; - if (tMicrosDelta > 10000) - { + if (tMicrosDelta > 10000) { // NEC signal ended just now Serial.println(); printTimingValues(&Mark, "Mark "); @@ -197,9 +199,9 @@ void loop() void IRAM_ATTR measureTimingISR() #else # if defined(EICRA) && defined(EIFR) && defined(EIMSK) -# if (IR_INPUT_PIN == 2) +# if (IR_RECEIVE_PIN == 2) ISR(INT0_vect) -# elif (IR_INPUT_PIN == 3) +# elif (IR_RECEIVE_PIN == 3) ISR(INT1_vect) # endif # else @@ -213,44 +215,34 @@ void measureTimingISR() /* * read level and give feedback */ - uint8_t tInputLevel = digitalRead(IR_INPUT_PIN); + uint8_t tInputLevel = digitalRead(IR_RECEIVE_PIN); digitalWrite(LED_BUILTIN, !tInputLevel); - if (tMicrosDelta > 10000) - { + if (tMicrosDelta > 10000) { // gap > 10 ms detected, reset counter to first detected edge and initialize timing structures ISREdgeCounter = 1; LongSpace.SampleCount = 0; ShortSpace.SampleCount = 0; Mark.SampleCount = 0; - } - else - { + } else { ISREdgeCounter++; } /* * Skip header mark and space and first bit mark and space */ - if (ISREdgeCounter > 4) - { - if (tInputLevel != LOW) - { + if (ISREdgeCounter > 4) { + if (tInputLevel != LOW) { // Mark ended processTmingValue(&Mark, tMicrosDelta); // Serial.print('M'); - } - else - { + } else { // Space ended - if (tMicrosDelta > 1000) - { + if (tMicrosDelta > 1000) { // long space - logical 1 processTmingValue(&LongSpace, tMicrosDelta); Serial.print('1'); - } - else - { + } else { // short space - logical 0 processTmingValue(&ShortSpace, tMicrosDelta); Serial.print('0'); diff --git a/examples/SendAndReceive/PinDefinitionsAndMore.h b/examples/SendAndReceive/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendAndReceive/PinDefinitionsAndMore.h +++ b/examples/SendAndReceive/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendAndReceive/SendAndReceive.ino b/examples/SendAndReceive/SendAndReceive.ino index 7303c1afc..7aaabf8c5 100644 --- a/examples/SendAndReceive/SendAndReceive.ino +++ b/examples/SendAndReceive/SendAndReceive.ino @@ -38,14 +38,17 @@ //#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. //#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active -//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory -//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define NO_LED_FEEDBACK_CODE // saves 318 bytes program memory +//#define NO_LED_RECEIVE_FEEDBACK_CODE // Saves 44 bytes program memory +//#define NO_LED_SEND_FEEDBACK_CODE // Saves 36 bytes program memory +//#define USE_16_BIT_TIMING_BUFFER // Use a 16-bit buffer to preserve values above 12750 us //#define DEBUG // Activate this for lots of lovely debug output from the decoders. -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include #define DELAY_AFTER_SEND 2000 @@ -53,7 +56,9 @@ void setup() { Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino @@ -65,7 +70,11 @@ void setup() { Serial.print(F("Ready to receive IR signals of protocols: ")); printActiveIRProtocols(&Serial); Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR send setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 @@ -87,8 +96,13 @@ void setup() { // infos for receive Serial.print(RECORD_GAP_MICROS); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); + +# if defined(USE_THRESHOLD_DECODER) + Serial.println(F("Threshold decoding is active and thus MARK_EXCESS_MICROS is set to 0")); +# else Serial.print(MARK_EXCESS_MICROS); Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); +# endif #endif } diff --git a/examples/SendBoseWaveDemo/PinDefinitionsAndMore.h b/examples/SendBoseWaveDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendBoseWaveDemo/PinDefinitionsAndMore.h +++ b/examples/SendBoseWaveDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendBoseWaveDemo/SendBoseWaveDemo.ino b/examples/SendBoseWaveDemo/SendBoseWaveDemo.ino index 054c083c1..d6b44faa3 100644 --- a/examples/SendBoseWaveDemo/SendBoseWaveDemo.ino +++ b/examples/SendBoseWaveDemo/SendBoseWaveDemo.ino @@ -33,9 +33,13 @@ */ #include -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif + +//#define NO_LED_FEEDBACK_CODE // Saves 216 bytes program memory -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include //...................................................................... @@ -96,6 +100,10 @@ //#define BOSE_CMD_ALARM_ON_OFF 0x22 //#define BOSE_CMD_ALARM_WAKE_TO 0x70 //#define BOSE_CMD_ALARM_TIME 0x23 +// Different last 3 codes for Wave Sound Touch IV +//#define BOSE_CMD_ALARM_1 0x22 +//#define BOSE_CMD_ALARM_2 0x62 +//#define BOSE_CMD_ALARM_SETUP 0xA2 bool sPrintMenu; void printMenu(); @@ -104,18 +112,28 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); #if defined(IR_SEND_PIN) - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); #else - IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin - Serial.println(F("Send IR signals at pin 3")); + uint8_t tSendPin = 3; + IrSender.begin(tSendPin); // Specify send pin and enable feedback LED at default feedback LED pin + // You can change send pin later with IrSender.setSendPin(); + + Serial.print(F("Send IR signals at pin ")); + Serial.println(tSendPin); #endif sPrintMenu = true; diff --git a/examples/SendDemo/PinDefinitionsAndMore.h b/examples/SendDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendDemo/PinDefinitionsAndMore.h +++ b/examples/SendDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendDemo/SendDemo.ino b/examples/SendDemo/SendDemo.ino index 97e7fa29a..d11622003 100644 --- a/examples/SendDemo/SendDemo.ino +++ b/examples/SendDemo/SendDemo.ino @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -32,40 +32,80 @@ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. - -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. - +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif +//#define IR_USE_AVR_TIMER1 //#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 240 bytes program memory if IrSender.write is used +//#define USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN // Reverses the polarity at the send pin. +//#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition -//#define NO_LED_FEEDBACK_CODE // Saves 566 bytes program memory -//#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! +//#define USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM // Simulate an active high receiver signal instead of an active low signal. +//#define NO_LED_FEEDBACK_CODE // Saves 322 bytes program memory + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. +#if FLASHEND <= 0x1FFF // For 8k flash or less like ATtiny85 +#define NO_LED_FEEDBACK_CODE +#endif +//#undef IR_SEND_PIN // enable this, if you need to set send pin programmatically using uint8_t tSendPin below #include #define DELAY_AFTER_SEND 2000 #define DELAY_AFTER_LOOP 5000 +#if __INT_WIDTH__ < 32 +IRDecodedRawDataType const tRawDataPGM[] PROGMEM = { 0xB02002, 0xA010 }; // LSB of tRawData[0] is sent first +/* + * Alternative definition of tRawDataPGM as byte array of same size with same content as { 0xB02002, 0xA010} + * But be aware, that this requires a cast when using tRawDataPGM as parameter. + * Like sendPulseDistanceWidthFromPGMArray_P(..., (IRDecodedRawDataType*) &tRawDataPGM[0], ...); + */ +//uint8_t const tRawDataPGM[] PROGMEM = { 0x02, 0x20, 0xB0, 0x00, /*0xB02002*/ +//0x10, 0xA0, 0x0, 0x0, /*0xA010*/}; +#endif + +const uint16_t rawIRTimingsNEC[] +#if defined(__AVR__) +PROGMEM // this crashes on ESP8266 +#endif += { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, + 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, + 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560, 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, + 560/*0000 0x00*/, 560, 1690, 560, 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, + 560, 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing + void setup() { Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); #if defined(IR_SEND_PIN) - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ # if defined(IR_SEND_PIN_STRING) Serial.println(F("Send IR signals at pin " IR_SEND_PIN_STRING)); # else Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); # endif #else - IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin - Serial.println(F("Send IR signals at pin 3")); + // Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN + uint8_t tSendPin = 3; + IrSender.begin(tSendPin); // Specify send pin and use feedback LED at default feedback LED pin + // You can change send pin later with IrSender.setSendPin(); + + Serial.print(F("Send IR signals at pin ")); + Serial.println(tSendPin); #endif #if !defined(SEND_PWM_BY_TIMER) @@ -81,16 +121,27 @@ void setup() { Serial.print(IrSender.periodTimeMicros); Serial.println(F(" us")); #endif + +#if defined(LED_BUILTIN) && !defined(NO_LED_FEEDBACK_CODE) && !defined(NO_LED_SEND_FEEDBACK_CODE) +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + Serial.print(F("Active low ")); +# endif + Serial.print(F("FeedbackLED at pin ")); + Serial.println(LED_BUILTIN); // Works also for ESP32: static const uint8_t LED_BUILTIN = 8; #define LED_BUILTIN LED_BUILTIN +#endif + } /* * Set up the data to be sent. * For most protocols, the data is build up with a constant 8 (or 16 byte) address * and a variable 8 bit command. - * There are exceptions like Sony and Denon, which have 5 bit address. + * There are exceptions like Sony, Denon or Marantz, which have 5 bit address. + * Furthermore, the extended protocol from Marantz has a 6 bit command extension. */ uint16_t sAddress = 0x0102; uint8_t sCommand = 0x34; +uint8_t sCommandExtension = 0x0B; // Only used for Marantz extended protocol uint16_t s16BitCommand = 0x5634; uint8_t sRepeats = 0; @@ -125,11 +176,23 @@ void loop() { delay(DELAY_AFTER_SEND); if (sRepeats == 0) { -#if FLASHEND >= 0x3FFF && (RAMEND >= 0x4FF || RAMSIZE >= 0x4FF) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. +#if FLASHEND >= 0x3FFF && RAMSIZE >= 0x600 /* + * For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. * Send constant values only once in this demo */ - Serial.println(F("Sending NEC Pronto data with 8 bit address 0x80 and command 0x45 and no repeats")); + + /* + * Test send usage for UNKNOWN protocol + */ + const uint16_t rawIRTimings[] = { 9000, 4500/*Start bit*/, 500, 1000, 1000, 500, 500, 2000, 2000, 500, 500, 3000, 3000, 500, + 500, 250, 250, 500 }; + Serial.println(F("Send arbitrary raw data with exact timing (16 bit array format) with sendRaw()")); + Serial.flush(); + IrSender.sendRaw(rawIRTimings, sizeof(rawIRTimings) / sizeof(rawIRTimings[0]), NEC_KHZ, 80, 1); // Note the approach used to automatically calculate the size of the array. + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send NEC data with 8 bit address 0x80 and command 0x45 and no repeats with sendPronto()")); Serial.flush(); IrSender.sendPronto(F("0000 006D 0022 0000 015E 00AB " /* Pronto header + start bit */ "0017 0015 0017 0015 0017 0017 0015 0017 0017 0015 0017 0015 0017 0015 0017 003F " /* Lower address byte */ @@ -140,18 +203,13 @@ void loop() { delay(DELAY_AFTER_SEND); /* - * !!! The next data occupies 136 bytes RAM !!! + * Test sending NEC protocol using sendRaw_P */ Serial.println( - F("Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format)")); + F( + "Send NEC data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format) with sendRaw_P()")); Serial.flush(); - const uint16_t irSignal[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, - 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, - 560, 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, - 560, 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, - 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, - 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing - IrSender.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array. + IrSender.sendRaw_P(rawIRTimingsNEC, sizeof(rawIRTimingsNEC) / sizeof(rawIRTimingsNEC[0]), NEC_KHZ, 110, 1); // Note the approach used to automatically calculate the size of the array. delay(DELAY_AFTER_SEND); /* @@ -165,6 +223,7 @@ void loop() { /* * With Send sendNECMSB() you can send your old 32 bit codes. * To convert one into the other, you must reverse the byte positions and then reverse all positions of each byte. + * Use bitreverse32Bit(). * Example: * 0xCB340102 byte reverse -> 0x020134CB bit reverse-> 40802CD3 */ @@ -172,74 +231,100 @@ void loop() { Serial.flush(); IrSender.sendNECMSB(0x40802CD3, 32, false); delay(DELAY_AFTER_SEND); -#endif - Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance using ProtocolConstants")); + Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM using ProtocolConstants 1=432|1296, 0=432|432")); Serial.flush(); -#if __INT_WIDTH__ < 32 - IRRawDataType tRawData[] = { 0xB02002, 0xA010 }; // LSB of tRawData[0] is sent first - IrSender.sendPulseDistanceWidthFromArray(&KaseikyoProtocolConstants, &tRawData[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant -#else - IrSender.sendPulseDistanceWidth(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant -#endif +# if __INT_WIDTH__ < 32 + IrSender.sendPulseDistanceWidthFromPGMArray_P(&KaseikyoProtocolConstants, (IRDecodedRawDataType*) &tRawDataPGM[0], 48, + NO_REPEATS); // Panasonic is a Kaseikyo variant +# else + IrSender.sendPulseDistanceWidth_P(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant +# endif delay(DELAY_AFTER_SEND); /* - * Send 2 Panasonic 48 bit codes as generic Pulse Distance data, once with LSB and once with MSB first + * Send 2 Panasonic 48 bit codes as Pulse Distance data, once with LSB and once with MSB first */ - Serial.println(F("Send Panasonic 0xB, 0x10 as generic 48 bit PulseDistance")); + Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM 1=450|1250, 0=450|400")); Serial.println(F(" LSB first")); Serial.flush(); -#if __INT_WIDTH__ < 32 - IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, +# if __INT_WIDTH__ < 32 + IrSender.sendPulseDistanceWidthFromPGMArray(38, 3450, 1700, 450, 1250, 450, 400, (IRDecodedRawDataType*) tRawDataPGM, 48, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS); -#else - IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, - 0, NO_REPEATS); -#endif +# else + IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, 0, + NO_REPEATS); +# endif delay(DELAY_AFTER_SEND); // The same with MSB first. Use bit reversed raw data of LSB first part Serial.println(F(" MSB first")); -#if __INT_WIDTH__ < 32 + IRDecodedRawDataType tRawData[4]; +# if __INT_WIDTH__ < 32 tRawData[0] = 0x40040D00; // MSB of tRawData[0] is sent first tRawData[1] = 0x805; IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, PROTOCOL_IS_MSB_FIRST, 0, NO_REPEATS); -#else - IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, - 0, NO_REPEATS); -#endif +# else + IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, 0, + NO_REPEATS); +# endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first")); + Serial.println(F("Send 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first 1=550|1700, 0=550|600")); Serial.flush(); -# if __INT_WIDTH__ < 32 +# if __INT_WIDTH__ < 32 tRawData[0] = 0x87654321; // LSB of tRawData[0] is sent first tRawData[1] = 0xAFEDCBA9; tRawData[2] = 0x5A; IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS); -# else - IRRawDataType tRawData[] = { 0xAFEDCBA987654321, 0x5A }; // LSB of tRawData[0] is sent first - IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS); -# endif +# else + tRawData[0] = 0xAFEDCBA987654321; + tRawData[1] = 0x5A; // LSB of tRawData[0] is sent first + IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, + NO_REPEATS); +# endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first")); + Serial.println(F("Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first 1=300|600, 0=600|300")); Serial.flush(); // Real PulseDistanceWidth (constant bit length) does not require a stop bit -#if __INT_WIDTH__ < 32 +# if __INT_WIDTH__ < 32 IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, 0, 0); -#else - IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, - 0, 0); -#endif +# else + IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0); +# endif + delay(DELAY_AFTER_SEND); + + Serial.println( + F("Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first with inverse timing and data 1=600|300, 0=300|600")); + Serial.flush(); +# if __INT_WIDTH__ < 32 + tRawData[2] = ~tRawData[0]; + tRawData[3] = ~tRawData[1]; + IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[2], 52, PROTOCOL_IS_LSB_FIRST, 0, 0); +# else + IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, ~0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0); +# endif + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send 7 bit ASCII character with PulseDistanceWidth LSB first 1=500|1500, 0=1500|500")); + Serial.flush(); + // Real PulseDistanceWidth (constant bit length) does theoretically not require a stop bit, but we know the stop bit from serial transmission + IrSender.sendPulseDistanceWidth(38, 6000, 500, 500, 1500, 1500, 500, sCommand, 7, PROTOCOL_IS_LSB_FIRST, 0, 0); delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 32 bit PulseWidth 0x87654321 LSB first")); + Serial.println(F("Send Sony12 as PulseWidth LSB first 1=1200|300, 0=600|600")); + Serial.flush(); + uint32_t tData = (uint32_t) sAddress << 7 | (sCommand & 0x7F); + IrSender.sendPulseDistanceWidth(38, 2400, 600, 1200, 600, 600, 600, tData, SIRCS_12_PROTOCOL, PROTOCOL_IS_LSB_FIRST, 0, 0); + delay(DELAY_AFTER_SEND); +#endif // FLASHEND >= 0x3FFF ... + + Serial.println(F("Send 32 bit PulseWidth 0x87654321 LSB first 1=600|300, 0=300|300")); Serial.flush(); // Real PulseDistanceWidth (constant bit length) does not require a stop bit IrSender.sendPulseDistanceWidth(38, 1000, 500, 600, 300, 300, 300, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, 0, 0); @@ -296,14 +381,19 @@ void loop() { IrSender.sendSony(sAddress & 0x1FFF, sCommand & 0x7F, sRepeats, SIRCS_20_PROTOCOL); delay(DELAY_AFTER_SEND); - Serial.println(F("Send Samsung 8 bit command")); + Serial.println(F("Send Samsung 8 bit command and 8 bit address")); Serial.flush(); - IrSender.sendSamsung(sAddress, sCommand, sRepeats); + IrSender.sendSamsung(sAddress & 0xFF, sCommand, sRepeats); delay(DELAY_AFTER_SEND); - Serial.println(F("Send Samsung 16 bit command")); + Serial.println(F("Send Samsung 8 bit command and 16 bit address")); Serial.flush(); - IrSender.sendSamsung(sAddress, s16BitCommand, sRepeats); + IrSender.sendSamsung16BitAddressAnd8BitCommand(sAddress, sCommand, sRepeats); + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send Samsung 16 bit command and address")); + Serial.flush(); + IrSender.sendSamsung16BitAddressAndCommand(sAddress, s16BitCommand, sRepeats); delay(DELAY_AFTER_SEND); Serial.println(F("Send Samsung48 16 bit command")); @@ -321,12 +411,44 @@ void loop() { IrSender.sendRC5(sAddress & 0x1F, (sCommand & 0x3F) + 0x40, sRepeats, true); // 5 address, 7 command bits delay(DELAY_AFTER_SEND); + Serial.println(F("Send Marantz variant of RC5x with 6 command bits and additional command extension")); + Serial.flush(); + IrSender.sendRC5Marantz(sAddress & 0x1F, sCommand & 0x3F, sRepeats, sCommandExtension); + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send Marantz variant of RC5x with 7 command bits and additional command extension")); + Serial.flush(); + IrSender.sendRC5Marantz(sAddress & 0x1F, sCommand & 0x7F, sRepeats, sCommandExtension); + delay(DELAY_AFTER_SEND); + Serial.println(F("Send RC6")); Serial.flush(); IrSender.sendRC6(sAddress, sCommand, sRepeats, true); delay(DELAY_AFTER_SEND); -#if FLASHEND >= 0x3FFF && (RAMEND >= 0x4FF || RAMSIZE >= 0x4FF) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. + Serial.println(F("Send RC6A with 14 bit 0x2711 as extra")); + Serial.flush(); + IrSender.sendRC6A(sAddress & 0xFF, sCommand, sRepeats, 0x2711, true); + delay(DELAY_AFTER_SEND); + +#if FLASHEND >= 0x3FFF && RAMSIZE >= 0x400 // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. + + Serial.println(F("Send MagiQuest")); + Serial.flush(); + IrSender.sendMagiQuest(0x6BCD0000 | (uint32_t) sAddress, s16BitCommand); // we have 31 bit address + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send OpenLASIR")); + Serial.flush(); + IrSender.sendOpenLASIR(sAddress & 0xFF, sCommand, OPENLASIR_MODE_LASER_TAG_FIRE, OPENLASIR_COLOR_ORANGE, sRepeats); + delay(DELAY_AFTER_SEND); + + // Bang&Olufsen must be sent with 455 kHz +// Serial.println(F("Send Bang&Olufsen")); +// Serial.flush(); +// IrSender.sendBangOlufsen(sAddress, sCommand, sRepeats); +// delay(DELAY_AFTER_SEND); + /* * Next example how to use the IrSender.write function */ @@ -336,12 +458,8 @@ void loop() { IRSendData.command = sCommand; IRSendData.flags = IRDATA_FLAGS_EMPTY; - IRSendData.protocol = SAMSUNG; - Serial.print(F("Send ")); - Serial.println(getProtocolString(IRSendData.protocol)); + Serial.println(F("Send next protocols with IrSender.write")); Serial.flush(); - IrSender.write(&IRSendData, sRepeats); - delay(DELAY_AFTER_SEND); IRSendData.protocol = JVC; // switch protocol Serial.print(F("Send ")); @@ -350,7 +468,7 @@ void loop() { IrSender.write(&IRSendData, sRepeats); delay(DELAY_AFTER_SEND); - IRSendData.command = s16BitCommand; // LG support more than 8 bit command + IRSendData.command = s16BitCommand; // LG support more than 8 bit command IRSendData.protocol = SAMSUNG; Serial.print(F("Send ")); @@ -366,17 +484,6 @@ void loop() { IrSender.write(&IRSendData, sRepeats); delay(DELAY_AFTER_SEND); - Serial.println(F("Send MagiQuest")); - Serial.flush(); - IrSender.sendMagiQuest(0x6BCD0000 | (uint32_t) sAddress, s16BitCommand); // we have 31 bit address - delay(DELAY_AFTER_SEND); - - // Bang&Olufsen must be sent with 455 kHz -// Serial.println(F("Send Bang&Olufsen")); -// Serial.flush(); -// IrSender.sendBangOlufsen(sAddress, sCommand, sRepeats); -// delay(DELAY_AFTER_SEND); - IRSendData.protocol = BOSEWAVE; Serial.println(F("Send Bosewave with no address and 8 command bits")); Serial.flush(); diff --git a/examples/SendLGAirConditionerDemo/PinDefinitionsAndMore.h b/examples/SendLGAirConditionerDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendLGAirConditionerDemo/PinDefinitionsAndMore.h +++ b/examples/SendLGAirConditionerDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendLGAirConditionerDemo/Readme.md b/examples/SendLGAirConditionerDemo/Readme.md deleted file mode 100644 index ad16367c0..000000000 --- a/examples/SendLGAirConditionerDemo/Readme.md +++ /dev/null @@ -1,93 +0,0 @@ -=== decoding for LG A/C ==== -- 1) remote of LG AC has two type of HDR mark/space, 8000/4000 and 3100/10000 -- 2) HDR 8000/4000 is decoded using decodeLG(IRrecvDumpV2) without problem -- 3) for HDR 3100/10000, use AnalysIR's code : http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/ -- 4) for bin output based on AnalysIR's code : https://gist.github.com/chaeplin/a3a4b4b6b887c663bfe8 -- 5) remove first two byte(11) -- 6) sample rawcode with bin output : https://gist.github.com/chaeplin/134d232e0b8cfb898860 - - -=== *** === -- 1) Sample raw code : https://gist.github.com/chaeplin/ab2a7ad1533c41260f0d -- 2) send raw code : https://gist.github.com/chaeplin/7c800d3166463bb51be4 - - -=== *** === -- (0) : Cooling or Heating -- (1) : fixed address -- (2) : fixed address -- (3) : special(power, swing, air clean) -- (4) : change air flow, temperature, cooling(0)/heating(4) -- (5) : temperature ( 15 + (5) = ) -- (6) : air flow -- (7) : checksum ( 3 + 4 + 5 + 6 ) & B00001111 - - -°F = °C × 1.8 + 32
-°C = (°F - 32) / 1.8 - - -=== *** === -* remote / Korea / without heating - -| status |(0)| (1)| (2)| (3)| (4)| (5)| (6)| (7) -|----------------|---|----|----|----|----|----|----|---- -| on / 25 / mid | C |1000|1000|0000|0000|1010|0010|1100 -| on / 26 / mid | C |1000|1000|0000|0000|1011|0010|1101 -| on / 27 / mid | C |1000|1000|0000|0000|1100|0010|1110 -| on / 28 / mid | C |1000|1000|0000|0000|1101|0010|1111 -| on / 25 / high | C |1000|1000|0000|0000|1010|0100|1110 -| on / 26 / high | C |1000|1000|0000|0000|1011|0100|1111 -| on / 27 / high | C |1000|1000|0000|0000|1100|0100|0000 -| on / 28 / high | C |1000|1000|0000|0000|1101|0100|0001 -|----------------|---|----|----|----|----|----|----|---- -| 1 up | C |1000|1000|0000|1000|1101|0100|1001 -|----------------|---|----|----|----|----|----|----|---- -| Cool power | C |1000|1000|0001|0000|0000|1100|1101 -| energy saving | C |1000|1000|0001|0000|0000|0100|0101 -| power | C |1000|1000|0001|0000|0000|1000|1001 -| flow/up/down | C |1000|1000|0001|0011|0001|0100|1001 -| up/down off | C |1000|1000|0001|0011|0001|0101|1010 -| flow/left/right| C |1000|1000|0001|0011|0001|0110|1011 -| left/right off | C |1000|1000|0001|0011|0001|0111|1100 -|----------------|---|----|----|----|----|----|----|---- -| Air clean | C |1000|1000|1100|0000|0000|0000|1100 -|----------------|---|----|----|----|----|----|----|---- -| off | C |1000|1000|1100|0000|0000|0101|0001 - - - -* remote / with heating -* converted using raw code at https://github.com/chaeplin/RaspAC/blob/master/lircd.conf - -| status |(0)| (1)| (2)| (3)| (4)| (5)| (6)| (7) -|----------------|---|----|----|----|----|----|----|---- -| on | C |1000|1000|0000|0000|1011|0010|1101 -|----------------|---|----|----|----|----|----|----|---- -| off | C |1000|1000|1100|0000|0000|0101|0001 -|----------------|---|----|----|----|----|----|----|---- -| 64 / 18 | C |1000|1000|0000|0000|0011|0100|0111 -| 66 / 19 | C |1000|1000|0000|0000|0100|0100|1000 -| 68 / 20 | C |1000|1000|0000|0000|0101|0100|1001 -| 70 / 21 | C |1000|1000|0000|0000|0110|0100|1010 -| 72 / 22 | C |1000|1000|0000|0000|0111|0100|1011 -| 74 / 23 | C |1000|1000|0000|0000|1000|0100|1100 -| 76 / 25 | C |1000|1000|0000|0000|1010|0100|1110 -| 78 / 26 | C |1000|1000|0000|0000|1011|0100|1111 -| 80 / 27 | C |1000|1000|0000|0000|1100|0100|0000 -| 82 / 28 | C |1000|1000|0000|0000|1101|0100|0001 -| 84 / 29 | C |1000|1000|0000|0000|1110|0100|0010 -| 86 / 30 | C |1000|1000|0000|0000|1111|0100|0011 -|----------------|---|----|----|----|----|----|----|---- -| heat64 | H |1000|1000|0000|0100|0011|0100|1011 -| heat66 | H |1000|1000|0000|0100|0100|0100|1100 -| heat68 | H |1000|1000|0000|0100|0101|0100|1101 -| heat70 | H |1000|1000|0000|0100|0110|0100|1110 -| heat72 | H |1000|1000|0000|0100|0111|0100|1111 -| heat74 | H |1000|1000|0000|0100|1000|0100|0000 -| heat76 | H |1000|1000|0000|0100|1001|0100|0001 -| heat78 | H |1000|1000|0000|0100|1011|0100|0011 -| heat80 | H |1000|1000|0000|0100|1100|0100|0100 -| heat82 | H |1000|1000|0000|0100|1101|0100|0101 -| heat84 | H |1000|1000|0000|0100|1110|0100|0110 -| heat86 | H |1000|1000|0000|0100|1111|0100|0111 diff --git a/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino b/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino index 9697745e1..d5282f348 100644 --- a/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino +++ b/examples/SendLGAirConditionerDemo/SendLGAirConditionerDemo.ino @@ -32,22 +32,27 @@ */ #include +//#define NO_LED_FEEDBACK_CODE // Saves 276 bytes program memory + /* - * LG2 has different header timing and a shorter bit time - * Known LG remote controls, which uses LG2 protocol are: + * LG has different header timing and a shorter bit time + * Known LG remote controls, which uses LG protocol are: * AKB75215403 * AKB74955603 * AKB73757604: */ -//#define USE_LG2_PROTOCOL // Try it if you do not have success with the default LG protocol #define NUMBER_OF_COMMANDS_BETWEEN_PRINT_OF_MENU 5 -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif + +//#define NO_LED_FEEDBACK_CODE // Saves 214 bytes program memory #define INFO // Deactivate this to save program memory and suppress info output from the LG-AC driver. //#define DEBUG // Activate this for more output from the LG-AC driver. -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) @@ -65,18 +70,21 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) -delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); /* - * The IR library setup. That's all! + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE */ - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin - Serial.println(); MyLG_Aircondition.setType(LG_IS_WALL_TYPE); diff --git a/examples/SendProntoDemo/PinDefinitionsAndMore.h b/examples/SendProntoDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendProntoDemo/PinDefinitionsAndMore.h +++ b/examples/SendProntoDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendProntoDemo/SendProntoDemo.ino b/examples/SendProntoDemo/SendProntoDemo.ino index ba92eff21..963a22693 100644 --- a/examples/SendProntoDemo/SendProntoDemo.ino +++ b/examples/SendProntoDemo/SendProntoDemo.ino @@ -32,9 +32,13 @@ */ #include -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif + +//#define NO_LED_FEEDBACK_CODE // Saves 266 bytes program memory -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include #define NUMBER_OF_REPEATS 3U @@ -57,14 +61,21 @@ IRsend irsend; void setup() { Serial.begin(115200); - while (!Serial) - ; + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! +#endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ } void loop() { diff --git a/examples/SendRawDemo/PinDefinitionsAndMore.h b/examples/SendRawDemo/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SendRawDemo/PinDefinitionsAndMore.h +++ b/examples/SendRawDemo/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SendRawDemo/SendRawDemo.ino b/examples/SendRawDemo/SendRawDemo.ino index 351148ada..5a1e59915 100644 --- a/examples/SendRawDemo/SendRawDemo.ino +++ b/examples/SendRawDemo/SendRawDemo.ino @@ -3,8 +3,7 @@ * * This example shows how to send a RAW signal using the IRremote library. * The example signal is actually a 32 bit NEC signal. - * Remote Control button: LGTV Power On/Off. - * Hex Value: 0x20DF10EF, 32 bits + * Protocol=NEC Address=0x4 Command=0x18 Raw-Data=0xE718FB04 32 bits LSB first * * If it is a supported protocol, it is more efficient to use the protocol send function * (here sendNEC) to send the signal. @@ -14,7 +13,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2022 Armin Joachimsmeyer + * Copyright (c) 2020-2024 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 @@ -37,34 +36,42 @@ */ #include -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition -//#define NO_LED_FEEDBACK_CODE // Saves 566 bytes program memory +//#define NO_LED_FEEDBACK_CODE // Saves 220 bytes program memory //#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ } /* - * NEC address=0xFB0C, command=0x18 + * NEC address=0x04 (0xFB04), command=0x18 (0xE718) * - * This is data in byte format. + * This is the raw data array in byte format. * The uint8_t/byte elements contain the number of ticks in 50 us. * The uint16_t format contains the (number of ticks * 50) if generated by IRremote, * so the uint16_t format has exact the same resolution but requires double space. @@ -72,49 +79,52 @@ void setup() { * e.g. use 560 (instead of 11 * 50) for NEC or use 432 for Panasonic. But in this cases, * you better use the timing generation functions e.g. sendNEC() directly. */ -const uint8_t rawDataP[] -#if defined(__AVR__) -PROGMEM -#endif -= { 180, 90 /*Start bit*/, 11, 11, 11, 11, 11, 34, 11, 34/*0011 0xC of 16 bit address LSB first*/, 11, 11, 11, 11, 11, 11, 11, +const uint8_t rawDataP[] PROGMEM += { 180, 90 /*Start bit*/, 11, 11, 11, 11, 11, 34, 11, 11/*0010 0x4 of 8 bit address LSB first*/, 11, 11, 11, 11, 11, 11, 11, 11/*0000*/, 11, 34, 11, 34, 11, 11, 11, 34/*1101 0xB*/, 11, 34, 11, 34, 11, 34, 11, 34/*1111*/, 11, 11, 11, 11, 11, 11, 11, 34/*0001 0x08 of command LSB first*/, 11, 34, 11, 11, 11, 11, 11, 11/*1000 0x01*/, 11, 34, 11, 34, 11, 34, 11, 11/*1110 Inverted 8 of command*/, 11, 11, 11, 34, 11, 34, 11, 34/*0111 inverted 1 of command*/, 11 /*stop bit*/}; +/* + * The same frame as above. Values are NOT multiple of 50, but are taken from the NEC timing definitions + */ +const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, + 560/*0010 0x4 of 8 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, 560, + 560, 1690/*1101 0xB - inverted 0x04*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 - inverted 0*/, 560, 560, 560, 560, + 560, 560, 560, 1690/*0001 0x08 of command LSB first*/, 560, 1690, 560, 560, 560, 560, 560, 560/*1000 0x01*/, 560, 1690, 560, + 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 560, 560, 1690, 560, 1690, 560, + 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing + void loop() { -#if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) +#if FLASHEND > 0x1FFF // For more than 8k flash => not for ATtiny85 etc. /* * Send hand crafted data from RAM - * The values are NOT multiple of 50, but are taken from the NEC timing definitions */ - Serial.println(F("Send NEC 16 bit address=0xFB04 and command 0x08 with exact timing (16 bit array format)")); + Serial.println(F("Send NEC 8 bit address=0x04 (0xFB04) and command 0x18 (0xE718) with exact timing (16 bit array format)")); Serial.flush(); - - const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, - 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, - 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560, - 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, 1690, 560, - 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 inverted 0 of command*/, - 560 /*stop bit*/}; // Using exact NEC timing IrSender.sendRaw(rawData, sizeof(rawData) / sizeof(rawData[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array. - delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal + delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal + #endif /* * Send byte data direct from FLASH * Note the approach used to automatically calculate the size of the array. */ - Serial.println(F("Send NEC 16 bit address 0xFB0C and data 0x18 with (50 us) tick resolution timing (8 bit array format) ")); + Serial.println(F("Send NEC 8 bit address 0x04 and command 0x18 with (50 us) tick resolution timing (8 bit array format) ")); Serial.flush(); IrSender.sendRaw_P(rawDataP, sizeof(rawDataP) / sizeof(rawDataP[0]), NEC_KHZ); - delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal + delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal - Serial.println(F("Send NEC 16 bit address 0x0102, 8 bit data 0x34 with generated timing")); + /* + * Send the same frame using NEC encoder + */ + Serial.println(F("Send NEC 16 bit address 0x04, 8 bit command 0x18 with NEC encoder")); Serial.flush(); - IrSender.sendNEC(0x0102, 0x34, 0); + IrSender.sendNEC(0x04, 0x18, 0); delay(3000); } diff --git a/examples/SimpleReceiver/PinDefinitionsAndMore.h b/examples/SimpleReceiver/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SimpleReceiver/PinDefinitionsAndMore.h +++ b/examples/SimpleReceiver/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SimpleReceiver/SimpleReceiver.ino b/examples/SimpleReceiver/SimpleReceiver.ino index 12b950b2c..4c0aeaea1 100644 --- a/examples/SimpleReceiver/SimpleReceiver.ino +++ b/examples/SimpleReceiver/SimpleReceiver.ino @@ -1,14 +1,15 @@ /* * SimpleReceiver.cpp * - * Demonstrates receiving NEC IR codes with IRremote + * Demonstrates receiving ONLY NEC protocol IR codes with IRremote + * If no protocol is defined, all protocols (except Bang&Olufsen) are active. * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2025 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 @@ -30,47 +31,55 @@ ************************************************************************************ */ +#include + /* * Specify which protocol(s) should be used for decoding. - * If no protocol is defined, all protocols (except Bang&Olufsen) are active. + * If no protocol is defined, all protocols (except BEO / Bang&Olufsen) are active. * This must be done before the #include + * In alphabetic order */ -//#define DECODE_DENON // Includes Sharp -//#define DECODE_JVC -//#define DECODE_KASEIKYO -//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO -//#define DECODE_LG -#define DECODE_NEC // Includes Apple and Onkyo -//#define DECODE_SAMSUNG -//#define DECODE_SONY -//#define DECODE_RC5 -//#define DECODE_RC6 - -//#define DECODE_BOSEWAVE -//#define DECODE_LEGO_PF -//#define DECODE_MAGIQUEST -//#define DECODE_WHYNTER -//#define DECODE_FAST - -//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols -//#define DECODE_HASH // special decoder for all protocols - -//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY! +//#define DECODE_DENON // Includes Sharp - requires around 250 bytes of program memory on ATmega328 +//#define DECODE_JVC // ~ 200 bytes +//#define DECODE_KASEIKYO // Includes Panasonic ~ 300 bytes +//#define DECODE_LG // ~ 400 bytes +//#define DECODE_NEC // Includes Apple and Onkyo ~ 250 bytes +//#define DECODE_SAMSUNG // ~ 300 bytes +//#define DECODE_SONY // ~ 175 bytes +//#define DECODE_RC5 // RC5 + MARANTZ: ~ 425 bytes +//#define DECODE_RC6 // ~ 375 bytes + +// Universal protocol decoder +//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols ~ 2275 bytes +//#define DECODE_HASH // special decoder for all protocols ~ 250 bytes + +// Exotic protocol decoder +//#define DECODE_BOSEWAVE // ~ 140 bytes +//#define DECODE_FAST // ~ 135 bytes +//#define DECODE_LEGO_PF // ~ 300 bytes +//#define DECODE_MAGIQUEST // ~ 270 bytes +//#define DECODE_MARANTZ // RC5 + MARANTZ: ~ 425 bytes +//#define DECODE_OPENLASIR // Modified NEC with 8-bit validated address + 16-bit command. ~ 175 bytes +//#define DECODE_WHYNTER // ~ 90 bytes + +//#define DECODE_BEO // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY! ~ 430 bytes //#define DEBUG // Activate this for lots of lovely debug output from the decoders. -//#define RAW_BUFFER_LENGTH 180 // Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +//#define RAW_BUFFER_LENGTH 750 // For air condition remotes it may require up to 750. Default is 200. -#include +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. +#include // include the library /* - * This include defines the actual pin number for pins like IR_RECEIVE_PIN, IR_SEND_PIN for many different boards and architectures + * Using the function printActiveIRProtocols() requires additional 318 bytes program memory + * Using the function printIRResultShort() requires additional 1436 bytes program memory + * Using the function printIRSendUsage() requires additional 2568 bytes program memory + * Because these 3 functions all share common code, using all 3 functions requires only additional 2884 bytes program memory */ -#include "PinDefinitionsAndMore.h" -#include // include the library - void setup() { Serial.begin(115200); + // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -78,7 +87,7 @@ void setup() { IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); Serial.print(F("Ready to receive IR signals of protocols: ")); - printActiveIRProtocols(&Serial); + printActiveIRProtocols(&Serial); // Requires additional 318 bytes program memory Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); } @@ -94,30 +103,35 @@ void loop() { if (IrReceiver.decode()) { /* - * Print a short summary of received data + * Print a summary of received data */ - IrReceiver.printIRResultShort(&Serial); - IrReceiver.printIRSendUsage(&Serial); if (IrReceiver.decodedIRData.protocol == UNKNOWN) { Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); - // We have an unknown protocol here, print more info + // We have an unknown protocol here, print extended info IrReceiver.printIRResultRawFormatted(&Serial, true); + + IrReceiver.resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted() + } else { + IrReceiver.resume(); // Early enable receiving of the next IR frame + + IrReceiver.printIRResultShort(&Serial); // Requires additional 1436 bytes program memory + IrReceiver.printIRSendUsage(&Serial); // Calls printIRResultShort() and other functions, if protocol is UNKNOWN } Serial.println(); - /* - * !!!Important!!! Enable receiving of the next value, - * since receiving has stopped after the end of the current received data packet. - */ - IrReceiver.resume(); // Enable receiving of the next value - /* * Finally, check the received data and perform actions according to the received command */ - if (IrReceiver.decodedIRData.command == 0x10) { - // do something - } else if (IrReceiver.decodedIRData.command == 0x11) { - // do something else + if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { + Serial.println(F("Repeat received. Here you can repeat the same action as before.")); + } else { + if (IrReceiver.decodedIRData.command == 0x10) { + Serial.println(F("Received command 0x10.")); + // do something + } else if (IrReceiver.decodedIRData.command == 0x11) { + Serial.println(F("Received command 0x11.")); + // do something else + } } } } diff --git a/examples/SimpleReceiverForHashCodes/PinDefinitionsAndMore.h b/examples/SimpleReceiverForHashCodes/PinDefinitionsAndMore.h new file mode 100644 index 000000000..d3dd74992 --- /dev/null +++ b/examples/SimpleReceiverForHashCodes/PinDefinitionsAndMore.h @@ -0,0 +1,366 @@ +/* + * PinDefinitionsAndMore.h + * + * Contains pin definitions for IRremote examples for various platforms + * as well as definitions for feedback LED and tone() and includes + * + * Copyright (C) 2021-2026 Armin Joachimsmeyer + * + * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * Arduino-IRremote is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Pin mapping table for different platforms + * + * Platform IR input IR output Tone Core/Pin schema + * -------------------------------------------------------------- + * DEFAULT/AVR 2 3 4 Arduino + * ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore + * ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore + * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core + * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore + * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore + * ATtiny1604 2 3|PA5 % + * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore + * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore + * MKR* 1 3 4 + * SAMD 2 3 4 + * ESP8266 14|D5 12|D6 % + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 + * APOLLO3 11 12 5 + * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 + */ +//#define _IR_MEASURE_TIMING // For debugging purposes. + +#if defined(__AVR__) +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. +#define IR_RECEIVE_PIN PIN_PB0 +#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. +#define TONE_PIN PIN_PB3 +#define _IR_TIMING_TEST_PIN PIN_PB3 + +# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" +// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. +# if defined(ARDUINO_AVR_DIGISPARKPRO) +// For use with Digispark original core +#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 +//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 +#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 +#define _IR_TIMING_TEST_PIN 10 // PA4 +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else +// For use with ATTinyCore +#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 +#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 +# endif + +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +#define IR_RECEIVE_PIN PIN_PB2 // INT0 +#define IR_SEND_PIN PIN_PA4 +#define TONE_PIN PIN_PA3 +#define _IR_TIMING_TEST_PIN PIN_PA5 + +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +// Pin 6 is TX, pin 7 is RX +#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 +#define IR_SEND_PIN PIN_PD4 // 4 +#define TONE_PIN PIN_PB1 // 9 +#define _IR_TIMING_TEST_PIN PIN_PB0 // 8 + +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore +// Tiny Core Dev board +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET +#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 + +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 14 +#define IR_SEND_PIN PIN_PA3 // 16 +#define TONE_PIN PIN_PA5 // 1 +#define APPLICATION_PIN PIN_PA4 // 0 +#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output +#define LED_BUILTIN PIN_PB5 // 4 + +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB2 // 5 + +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 + +# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ +|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ +|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ +|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ +|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ +|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \ +|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \ +|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \ +|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__) +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 13 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc. +#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here. +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit +// We have no built in LED at pin 13 -> reuse RX LED +#undef LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN_RX +# endif +# endif // defined(__AVR_ATtiny25__)... + +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ESP8266) +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW +#define IR_RECEIVE_PIN 14 // D5 +#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED +#define _IR_TIMING_TEST_PIN 2 // D4 +#define APPLICATION_PIN 13 // D7 + +#define tone(...) void() // tone() inhibits receive timer +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 + +#elif defined(ESP32) +#include + +// tone() is included in ESP32 core since 2.0.2 +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif +#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) +#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. +void tone(uint8_t aPinNumber, unsigned int aFrequency){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); +} +void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); + delay(aDuration); + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +void noTone(uint8_t aPinNumber){ + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) + +#define IR_RECEIVE_PIN 15 // D15 +#define IR_SEND_PIN 4 // D4 +#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 +#define APPLICATION_PIN 16 // RX2 pin + +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill +// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() +#define IR_RECEIVE_PIN PA6 +#define IR_RECEIVE_PIN_STRING "PA6" +#define IR_SEND_PIN PA7 +#define IR_SEND_PIN_STRING "PA7" +#define TONE_PIN PA3 +#define _IR_TIMING_TEST_PIN PA5 +#define APPLICATION_PIN PA2 +#define APPLICATION_PIN_STRING "PA2" +# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8) +// BluePill LED is active low +#define FEEDBACK_LED_IS_ACTIVE_LOW +# endif + +#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards +#define IR_RECEIVE_PIN 11 +#define IR_SEND_PIN 12 +#define TONE_PIN 5 + +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect +#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico +#define IR_SEND_PIN 4 // GPIO16 +#define TONE_PIN 5 +#define APPLICATION_PIN 6 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 8 + +#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico +#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3) +#define IR_SEND_PIN 16 // GPIO16 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 20 + +// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN +// and use the external reset with 1 kOhm to ground to enter UF2 mode +#undef LED_BUILTIN +#define LED_BUILTIN 6 + +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! +#define IR_RECEIVE_PIN A4 +#define IR_SEND_PIN A5 // Particle supports multiple pins + +#define LED_BUILTIN D7 + +/* + * 4 times the same (default) layout for easy adaption in the future + */ +#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else +#define IR_RECEIVE_PIN 2 +# endif +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0) +// On the Zero and others we switch explicitly to SerialUSB +#define Serial SerialUSB +#endif + +// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17. +// Attention!!! D2 and D4 are swapped on these boards!!! +// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 24 // PB11 +// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 25 // PB03 +//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW + +#elif defined (NRF51) // BBC micro:bit +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define APPLICATION_PIN 1 +#define _IR_TIMING_TEST_PIN 4 + +#define tone(...) void() // no tone() available +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it + +#else +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. +// Default valued for unidentified boards +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 +#endif // defined(ESP8266) + +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp +#endif + +#if !defined (FLASHEND) +#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined +#endif + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // +#endif +#if !defined (RAMSIZE) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined +#endif diff --git a/examples/SimpleReceiverForHashCodes/SimpleReceiverForHashCodes.ino b/examples/SimpleReceiverForHashCodes/SimpleReceiverForHashCodes.ino new file mode 100644 index 000000000..27c0be7f9 --- /dev/null +++ b/examples/SimpleReceiverForHashCodes/SimpleReceiverForHashCodes.ino @@ -0,0 +1,102 @@ +/* + * SimpleReceiverForHashCodes.cpp + * + * Demonstrates receiving hash codes of unknown protocols with IRremote + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + ************************************************************************************ + * MIT License + * + * Copyright (c) 2024 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. + * + ************************************************************************************ + */ + +#include + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. + +/* + * Specify which protocol(s) should be used for decoding. + * This must be done before the #include + */ +#define DECODE_HASH // special decoder for all protocols +#if !defined(RAW_BUFFER_LENGTH) +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE >= 0x400 +// Here we have 1 k RAM or more +#define RAW_BUFFER_LENGTH 750 +# elif RAMSIZE >= 0x800 +// Here we have 2 k RAM or more +#define RAW_BUFFER_LENGTH 1000 // Especially useful for unknown and probably long protocols +# endif +#endif +//#define DEBUG // Activate this for lots of lovely debug output from the decoders. + +#include // include the library + +void setup() { + Serial.begin(115200); + + // Just to know which program is running on my Arduino + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); + + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); + + Serial.println(F("Ready to receive unknown IR signals at pin " STR(IR_RECEIVE_PIN) " and decode it with hash decoder.")); +} + +void loop() { + /* + * Check if received data is available and if yes, try to decode it. + * Decoded hash result is in IrReceiver.decodedIRData.decodedRawData + */ + if (IrReceiver.available()) { + IrReceiver.initDecodedIRData(); // is required, if we do not call decode(); + IrReceiver.decodeHash(); + IrReceiver.resume(); // Early enable receiving of the next IR frame + /* + * Print a summary and then timing of received data + */ + IrReceiver.printIRResultShort(&Serial); + IrReceiver.printIRResultRawFormatted(&Serial, true); + + Serial.println(); + + /* + * Finally, check the received data and perform actions according to the received command + */ + auto tDecodedRawData = IrReceiver.decodedIRData.decodedRawData; // uint32_t on 8 and 16 bit CPUs and uint64_t on 32 and 64 bit CPUs + if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { + Serial.println(F("Repeat received. Here you can repeat the same action as before.")); + } else { + Serial.print(F("Raw data received are 0x")); + Serial.println(tDecodedRawData); + + if (IrReceiver.decodedIRData.command == 0x10) { + // do something + } else if (IrReceiver.decodedIRData.command == 0x11) { + // do something else + } + } + } +} diff --git a/examples/SimpleSender/PinDefinitionsAndMore.h b/examples/SimpleSender/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/SimpleSender/PinDefinitionsAndMore.h +++ b/examples/SimpleSender/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/SimpleSender/SimpleSender.ino b/examples/SimpleSender/SimpleSender.ino index 0ea7ece3c..ac372582e 100644 --- a/examples/SimpleSender/SimpleSender.ino +++ b/examples/SimpleSender/SimpleSender.ino @@ -3,9 +3,9 @@ * * Demonstrates sending IR codes in standard format with address and command * An extended example for sending can be found as SendDemo. + * Sending IR codes using several pins for sending is implements in the MultipleSendPins example. * - * Copyright (C) 2020-2022 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2020-2026 Armin Joachimsmeyer * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -13,14 +13,14 @@ */ #include -#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used. +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. +#endif //#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. //#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define NO_LED_FEEDBACK_CODE // Saves 216 bytes program memory -/* - * This include defines the actual pin number for pins like IR_RECEIVE_PIN, IR_SEND_PIN for many different boards and architectures - */ -#include "PinDefinitionsAndMore.h" +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include // include the library void setup() { @@ -34,10 +34,10 @@ void setup() { Serial.println(IR_SEND_PIN); /* - * The IR library setup. That's all! + * No IR library setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE */ -// IrSender.begin(); // Start with IR_SEND_PIN as send pin and if NO_LED_FEEDBACK_CODE is NOT defined, enable feedback LED at default feedback LED pin - IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin and disable feedback LED at default feedback LED pin } /* @@ -66,6 +66,18 @@ void loop() { // Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits) IrSender.sendNEC(0x00, sCommand, sRepeats); + /* + * If you want to send a raw HEX value directly like e.g. 0xCB340102 you must use sendNECRaw() + */ +// Serial.println(F("Send 32 bit LSB 0xCB340102 with NECRaw()")); +// IrSender.sendNECRaw(0xCB340102, sRepeats); + + /* + * If you want to send an "old" MSB HEX value used by IRremote versions before 3.0 like e.g. 0x40802CD3 you must use sendNECMSB() + */ +// Serial.println(F("Send old 32 bit MSB 0x40802CD3 with sendNECMSB()")); +// IrSender.sendNECMSB(0x40802CD3, 32, sRepeats); + /* * Increment send values */ diff --git a/examples/TinyReceiver/PinDefinitionsAndMore.h b/examples/TinyReceiver/PinDefinitionsAndMore.h new file mode 100644 index 000000000..d3dd74992 --- /dev/null +++ b/examples/TinyReceiver/PinDefinitionsAndMore.h @@ -0,0 +1,366 @@ +/* + * PinDefinitionsAndMore.h + * + * Contains pin definitions for IRremote examples for various platforms + * as well as definitions for feedback LED and tone() and includes + * + * Copyright (C) 2021-2026 Armin Joachimsmeyer + * + * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * Arduino-IRremote is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Pin mapping table for different platforms + * + * Platform IR input IR output Tone Core/Pin schema + * -------------------------------------------------------------- + * DEFAULT/AVR 2 3 4 Arduino + * ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore + * ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore + * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core + * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore + * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore + * ATtiny1604 2 3|PA5 % + * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore + * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore + * MKR* 1 3 4 + * SAMD 2 3 4 + * ESP8266 14|D5 12|D6 % + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 + * APOLLO3 11 12 5 + * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 + */ +//#define _IR_MEASURE_TIMING // For debugging purposes. + +#if defined(__AVR__) +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. +#define IR_RECEIVE_PIN PIN_PB0 +#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. +#define TONE_PIN PIN_PB3 +#define _IR_TIMING_TEST_PIN PIN_PB3 + +# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" +// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. +# if defined(ARDUINO_AVR_DIGISPARKPRO) +// For use with Digispark original core +#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 +//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 +#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 +#define _IR_TIMING_TEST_PIN 10 // PA4 +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else +// For use with ATTinyCore +#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 +#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 +# endif + +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +#define IR_RECEIVE_PIN PIN_PB2 // INT0 +#define IR_SEND_PIN PIN_PA4 +#define TONE_PIN PIN_PA3 +#define _IR_TIMING_TEST_PIN PIN_PA5 + +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +// Pin 6 is TX, pin 7 is RX +#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 +#define IR_SEND_PIN PIN_PD4 // 4 +#define TONE_PIN PIN_PB1 // 9 +#define _IR_TIMING_TEST_PIN PIN_PB0 // 8 + +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore +// Tiny Core Dev board +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET +#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 + +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 14 +#define IR_SEND_PIN PIN_PA3 // 16 +#define TONE_PIN PIN_PA5 // 1 +#define APPLICATION_PIN PIN_PA4 // 0 +#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output +#define LED_BUILTIN PIN_PB5 // 4 + +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB2 // 5 + +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 + +# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ +|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ +|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ +|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ +|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ +|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \ +|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \ +|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \ +|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__) +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 13 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc. +#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here. +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit +// We have no built in LED at pin 13 -> reuse RX LED +#undef LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN_RX +# endif +# endif // defined(__AVR_ATtiny25__)... + +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ESP8266) +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW +#define IR_RECEIVE_PIN 14 // D5 +#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED +#define _IR_TIMING_TEST_PIN 2 // D4 +#define APPLICATION_PIN 13 // D7 + +#define tone(...) void() // tone() inhibits receive timer +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 + +#elif defined(ESP32) +#include + +// tone() is included in ESP32 core since 2.0.2 +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif +#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) +#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. +void tone(uint8_t aPinNumber, unsigned int aFrequency){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); +} +void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); + delay(aDuration); + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +void noTone(uint8_t aPinNumber){ + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) + +#define IR_RECEIVE_PIN 15 // D15 +#define IR_SEND_PIN 4 // D4 +#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 +#define APPLICATION_PIN 16 // RX2 pin + +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill +// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() +#define IR_RECEIVE_PIN PA6 +#define IR_RECEIVE_PIN_STRING "PA6" +#define IR_SEND_PIN PA7 +#define IR_SEND_PIN_STRING "PA7" +#define TONE_PIN PA3 +#define _IR_TIMING_TEST_PIN PA5 +#define APPLICATION_PIN PA2 +#define APPLICATION_PIN_STRING "PA2" +# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8) +// BluePill LED is active low +#define FEEDBACK_LED_IS_ACTIVE_LOW +# endif + +#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards +#define IR_RECEIVE_PIN 11 +#define IR_SEND_PIN 12 +#define TONE_PIN 5 + +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect +#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico +#define IR_SEND_PIN 4 // GPIO16 +#define TONE_PIN 5 +#define APPLICATION_PIN 6 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 8 + +#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico +#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3) +#define IR_SEND_PIN 16 // GPIO16 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 20 + +// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN +// and use the external reset with 1 kOhm to ground to enter UF2 mode +#undef LED_BUILTIN +#define LED_BUILTIN 6 + +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! +#define IR_RECEIVE_PIN A4 +#define IR_SEND_PIN A5 // Particle supports multiple pins + +#define LED_BUILTIN D7 + +/* + * 4 times the same (default) layout for easy adaption in the future + */ +#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else +#define IR_RECEIVE_PIN 2 +# endif +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0) +// On the Zero and others we switch explicitly to SerialUSB +#define Serial SerialUSB +#endif + +// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17. +// Attention!!! D2 and D4 are swapped on these boards!!! +// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 24 // PB11 +// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 25 // PB03 +//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW + +#elif defined (NRF51) // BBC micro:bit +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define APPLICATION_PIN 1 +#define _IR_TIMING_TEST_PIN 4 + +#define tone(...) void() // no tone() available +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it + +#else +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. +// Default valued for unidentified boards +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 +#endif // defined(ESP8266) + +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp +#endif + +#if !defined (FLASHEND) +#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined +#endif + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // +#endif +#if !defined (RAMSIZE) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined +#endif diff --git a/examples/TinyReceiver/TinyReceiver.ino b/examples/TinyReceiver/TinyReceiver.ino index cbf6188f3..f3465d5aa 100644 --- a/examples/TinyReceiver/TinyReceiver.ino +++ b/examples/TinyReceiver/TinyReceiver.ino @@ -4,29 +4,29 @@ * Small memory footprint and no timer usage! * * Receives IR protocol data of NEC protocol using pin change interrupts. - * On complete received IR command the function handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, uint8_t aFlags) - * is called in Interrupt context but with interrupts being enabled to enable use of delay() etc. + * For each complete IR frame/command received, the decoded data is copied to the TinyIRReceiverData structure + * and the handleReceivedTinyIRData() function is called in an interrupt context. + * However, interrupts are explicitly enabled here to allow the use of delay() and millis() etc. * !!!!!!!!!!!!!!!!!!!!!! * Functions called in interrupt context should be running as short as possible, - * so if you require longer action, save the data (address + command) and handle it in the main loop. * !!!!!!!!!!!!!!!!!!!!! * * The FAST protocol is a proprietary modified JVC protocol without address, with parity and with a shorter header. * FAST Protocol characteristics: * - Bit timing is like NEC or JVC * - The header is shorter, 3156 vs. 12500 - * - No address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command, - * leading to a fixed protocol length of (6 + (16 * 3) + 1) * 526 = 55 * 526 = 28930 microseconds or 29 ms. + * - No address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command. + * This results in a fixed protocol length of (6 + (16 * 3) + 1) * 526 = 55 * 526 = 28930 microseconds or 29 ms. * - Repeats are sent as complete frames but in a 50 ms period / with a 21 ms distance. * * - * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. * ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -50,65 +50,37 @@ #include -/* - * Set sensible receive pin for different CPU's - */ -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) -/* - * This program runs on 1 MHz CPU clock :-) and is requires only 1550 bytes program memory using ATTiny core - */ -#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut" - Saves up to 700 bytes program memory and 70 bytes RAM for ATtinyCore -# if defined(ARDUINO_AVR_DIGISPARKPRO) -#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 -# else -#define IR_RECEIVE_PIN 0 // PCINT0 -# endif -#elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) -#define IR_RECEIVE_PIN 10 -#elif (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)) -#define IR_RECEIVE_PIN 21 // INT0 -#elif defined(ESP8266) -#define IR_RECEIVE_PIN 14 // D5 -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_RECEIVE_PIN 8 -#elif defined(ESP32) -#define IR_RECEIVE_PIN 15 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) -#define IR_RECEIVE_PIN 3 // GPIO15 Use pin 3 since pin 2|GPIO25 is connected to LED on Pi pico -#elif defined(ARDUINO_ARCH_RP2040) // Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico -#define IR_RECEIVE_PIN 15 // to be compatible with the Arduino Nano RP2040 Connect (pin3) -#else -#define IR_RECEIVE_PIN 2 // INT0 -//#define NO_LED_FEEDBACK_CODE // Activate this if you want to suppress LED feedback or if you do not have a LED. This saves 14 bytes code and 2 clock cycles per interrupt. -#endif - //#define DEBUG // to see if attachInterrupt is used //#define TRACE // to see the state of the ISR state machine /* - * Second: include the code and compile it. + * Protocol selection */ -//#define DISABLE_PARITY_CHECKS // Disable parity checks. Saves 48 bytes of program memory. +//#define USE_EXTENDED_NEC_PROTOCOL // Like NEC, but take the 16 bit address as one 16 bit value and not as 8 bit normal and 8 bit inverted value. //#define USE_ONKYO_PROTOCOL // Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. -//#define USE_FAST_PROTOCOL // Use FAST protocol (no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command) instead of NEC / ONKYO. -//#define ENABLE_NEC2_REPEATS // Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. -#include "TinyIRReceiver.hpp" - +//#define USE_FAST_PROTOCOL // Use FAST protocol instead of NEC / ONKYO. +//#define ENABLE_NEC2_REPEATS // Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. /* - * Helper macro for getting a macro definition as string + * Set compile options to modify the generated code. */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) -#endif - -volatile struct TinyIRReceiverCallbackDataStruct sCallbackData; +//#define DISABLE_PARITY_CHECKS // Disable parity checks. Saves 48 bytes of program memory. +//#define USE_CALLBACK_FOR_TINY_RECEIVER // Call the user provided function "void handleReceivedTinyIRData()" each time a frame or repeat is received. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. +#include "TinyIRReceiver.hpp" // include the code void setup() { Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif + // Just to know which program is running on my Arduino #if defined(ESP8266) || defined(ESP32) Serial.println(); @@ -116,7 +88,7 @@ void setup() { Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_TINYIR)); // Enables the interrupt generation on change of IR input signal - if (!initPCIInterruptForTinyReceiver()) { + if (!initPCIInterruptForTinyIRReceiver()) { Serial.println(F("No interrupt available for pin " STR(IR_RECEIVE_PIN))); // optimized out by the compiler, if not required :-) } #if defined(USE_FAST_PROTOCOL) @@ -127,64 +99,70 @@ void setup() { } void loop() { - if (sCallbackData.justWritten) { - sCallbackData.justWritten = false; -#if defined(USE_FAST_PROTOCOL) - Serial.print(F("Command=0x")); -#else + if (TinyIRReceiverDecode()) { + /* + * The library has already copied the data used for this output, + * so there is no need to do this in the callback function. + */ +#if !defined(USE_FAST_PROTOCOL) + // We have no address at FAST protocol Serial.print(F("Address=0x")); - Serial.print(sCallbackData.Address, HEX); - Serial.print(F(" Command=0x")); + Serial.print(TinyIRReceiverData.Address, HEX); + Serial.print(' '); #endif - Serial.print(sCallbackData.Command, HEX); - if (sCallbackData.Flags == IRDATA_FLAGS_IS_REPEAT) { + + Serial.print(F("Command=0x")); + Serial.print(TinyIRReceiverData.Command, HEX); + if (TinyIRReceiverData.Flags == IRDATA_FLAGS_IS_REPEAT) { Serial.print(F(" Repeat")); } - if (sCallbackData.Flags == IRDATA_FLAGS_PARITY_FAILED) { + if (TinyIRReceiverData.Flags == IRDATA_FLAGS_PARITY_FAILED) { Serial.print(F(" Parity failed")); + +#if !defined(USE_EXTENDED_NEC_PROTOCOL) && !defined(USE_ONKYO_PROTOCOL) + Serial.print(F(", try USE_EXTENDED_NEC_PROTOCOL or USE_ONKYO_PROTOCOL")); +#endif + } Serial.println(); } /* * Put your code here */ + + /* + * No resume() required :-) + */ } /* - * This is the function, which is called if a complete command was received - * It runs in an ISR context with interrupts enabled, so functions like delay() etc. should work here + * Optional code, if you require a callback */ -#if defined(ESP8266) || defined(ESP32) +#if defined(USE_CALLBACK_FOR_TINY_RECEIVER) +/* + * This is the function, which is called if a complete frame was received + * This function is executed in an ISR (Interrupt Service Routine) context but with interrupts enabled! + * However, it is always best to keep this callback function short and fast! + */ +# if defined(ESP8266) || defined(ESP32) IRAM_ATTR -#endif - -#if defined(USE_FAST_PROTOCOL) -void handleReceivedTinyIRData(uint8_t aCommand, uint8_t aFlags) -#elif defined(USE_ONKYO_PROTOCOL) -void handleReceivedTinyIRData(uint16_t aAddress, uint16_t aCommand, uint8_t aFlags) -#else -void handleReceivedTinyIRData(uint8_t aAddress, uint8_t aCommand, uint8_t aFlags) -#endif - { -#if defined(ARDUINO_ARCH_MBED) || defined(ESP32) - // Copy data for main loop, this is the recommended way for handling a callback :-) -# if !defined(USE_FAST_PROTOCOL) - sCallbackData.Address = aAddress; # endif - sCallbackData.Command = aCommand; - sCallbackData.Flags = aFlags; - sCallbackData.justWritten = true; -#else +void handleReceivedTinyIRData() { +# if defined(ARDUINO_ARCH_MBED) || defined(ESP32) /* - * Printing is not allowed in ISR context for any kind of RTOS + * Printing is not allowed in ISR context for RTOS based cores like ESP, even when interrupts are enabled. * For Mbed we get a kernel panic and "Error Message: Semaphore: 0x0, Not allowed in ISR context" for Serial.print() * for ESP32 we get a "Guru Meditation Error: Core 1 panic'ed" (we also have an RTOS running!) */ - // Print only very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon -# if defined(USE_FAST_PROTOCOL) - printTinyReceiverResultMinimal(&Serial, aCommand, aFlags); # else - printTinyReceiverResultMinimal(&Serial, aAddress, aCommand, aFlags); + // As an example, print very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon + printTinyIRReceiverResultMinimal(&Serial); # endif -#endif + if (TinyIRReceiverData.Command == 0x10) { + // do something SHORT here + } else if (TinyIRReceiverData.Command == 0x11) { + // do something SHORT here too + } } +#endif + diff --git a/examples/TinySender/PinDefinitionsAndMore.h b/examples/TinySender/PinDefinitionsAndMore.h new file mode 100644 index 000000000..d3dd74992 --- /dev/null +++ b/examples/TinySender/PinDefinitionsAndMore.h @@ -0,0 +1,366 @@ +/* + * PinDefinitionsAndMore.h + * + * Contains pin definitions for IRremote examples for various platforms + * as well as definitions for feedback LED and tone() and includes + * + * Copyright (C) 2021-2026 Armin Joachimsmeyer + * + * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * Arduino-IRremote is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Pin mapping table for different platforms + * + * Platform IR input IR output Tone Core/Pin schema + * -------------------------------------------------------------- + * DEFAULT/AVR 2 3 4 Arduino + * ATtinyX5 0|PB0 4|PB4 3|PB3 ATTinyCore + * ATtiny167 3|PA3 2|PA2 7|PA7 ATTinyCore + * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core + * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore + * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore + * ATtiny1604 2 3|PA5 % + * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore + * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore + * MKR* 1 3 4 + * SAMD 2 3 4 + * ESP8266 14|D5 12|D6 % + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 + * APOLLO3 11 12 5 + * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 + */ +//#define _IR_MEASURE_TIMING // For debugging purposes. + +#if defined(__AVR__) +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. +#define IR_RECEIVE_PIN PIN_PB0 +#define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. +#define TONE_PIN PIN_PB3 +#define _IR_TIMING_TEST_PIN PIN_PB3 + +# elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" +// For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. +# if defined(ARDUINO_AVR_DIGISPARKPRO) +// For use with Digispark original core +#define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 +//#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 +#define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 +#define _IR_TIMING_TEST_PIN 10 // PA4 +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else +// For use with ATTinyCore +#define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards +#define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 +#define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 +# endif + +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +#define IR_RECEIVE_PIN PIN_PB2 // INT0 +#define IR_SEND_PIN PIN_PA4 +#define TONE_PIN PIN_PA3 +#define _IR_TIMING_TEST_PIN PIN_PA5 + +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. +#include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. +// Pin 6 is TX, pin 7 is RX +#define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 +#define IR_SEND_PIN PIN_PD4 // 4 +#define TONE_PIN PIN_PB1 // 9 +#define _IR_TIMING_TEST_PIN PIN_PB0 // 8 + +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore +// Tiny Core Dev board +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET +#undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 + +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 14 +#define IR_SEND_PIN PIN_PA3 // 16 +#define TONE_PIN PIN_PA5 // 1 +#define APPLICATION_PIN PIN_PA4 // 0 +#undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output +#define LED_BUILTIN PIN_PB5 // 4 + +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB2 // 5 + +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 + +# elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ +|| defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ +|| defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) \ +|| defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega164A__) \ +|| defined(__AVR_ATmega164P__) || defined(__AVR_ATmega32__) \ +|| defined(__AVR_ATmega16__) || defined(__AVR_ATmega8535__) \ +|| defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) \ +|| defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) \ +|| defined(__AVR_ATmega8515__) || defined(__AVR_ATmega162__) +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 13 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# else // Default as for ATmega328 like on Uno, Nano, Leonardo, Teensy 2.0 etc. +#define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here. +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +# if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro is __AVR_ATmega32U4__ but has different external circuit +// We have no built in LED at pin 13 -> reuse RX LED +#undef LED_BUILTIN +#define LED_BUILTIN LED_BUILTIN_RX +# endif +# endif // defined(__AVR_ATtiny25__)... + +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ESP8266) +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW +#define IR_RECEIVE_PIN 14 // D5 +#define IR_SEND_PIN 12 // D6 - D4/pin 2 is internal LED +#define _IR_TIMING_TEST_PIN 2 // D4 +#define APPLICATION_PIN 13 // D7 + +#define tone(...) void() // tone() inhibits receive timer +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 + +#elif defined(ESP32) +#include + +// tone() is included in ESP32 core since 2.0.2 +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif +#if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) +#define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. +void tone(uint8_t aPinNumber, unsigned int aFrequency){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); +} +void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ + ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); + ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); + delay(aDuration); + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +void noTone(uint8_t aPinNumber){ + ledcWriteTone(TONE_LEDC_CHANNEL, 0); +} +#endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) + +#define IR_RECEIVE_PIN 15 // D15 +#define IR_SEND_PIN 4 // D4 +#define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 +#define APPLICATION_PIN 16 // RX2 pin + +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill +// Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() +#define IR_RECEIVE_PIN PA6 +#define IR_RECEIVE_PIN_STRING "PA6" +#define IR_SEND_PIN PA7 +#define IR_SEND_PIN_STRING "PA7" +#define TONE_PIN PA3 +#define _IR_TIMING_TEST_PIN PA5 +#define APPLICATION_PIN PA2 +#define APPLICATION_PIN_STRING "PA2" +# if defined(ARDUINO_GENERIC_STM32F103C) || defined(ARDUINO_BLUEPILL_F103C8) +// BluePill LED is active low +#define FEEDBACK_LED_IS_ACTIVE_LOW +# endif + +#elif defined(ARDUINO_ARCH_APOLLO3) // Sparkfun Apollo boards +#define IR_RECEIVE_PIN 11 +#define IR_SEND_PIN 12 +#define TONE_PIN 5 + +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect +#define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico +#define IR_SEND_PIN 4 // GPIO16 +#define TONE_PIN 5 +#define APPLICATION_PIN 6 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 7 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 8 + +#elif defined(ARDUINO_ARCH_RP2040) // Arduino Nano Connect, Pi Pico with arduino-pico core https://github.com/earlephilhower/arduino-pico +#define IR_RECEIVE_PIN 15 // GPIO15 to be compatible with the Arduino Nano RP2040 Connect (pin3) +#define IR_SEND_PIN 16 // GPIO16 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 19 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 20 + +// If you program the Nano RP2040 Connect with this core, then you must redefine LED_BUILTIN +// and use the external reset with 1 kOhm to ground to enter UF2 mode +#undef LED_BUILTIN +#define LED_BUILTIN 6 + +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! +#define IR_RECEIVE_PIN A4 +#define IR_SEND_PIN A5 // Particle supports multiple pins + +#define LED_BUILTIN D7 + +/* + * 4 times the same (default) layout for easy adaption in the future + */ +#elif defined(TEENSYDUINO) // Teensy 2.0 is handled at default for ATmega328 like on Uno, Nano, Leonardo etc. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_MBED) // Arduino Nano 33 BLE +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else +#define IR_RECEIVE_PIN 2 +# endif +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + +#if !defined(ARDUINO_SAMD_ADAFRUIT) && !defined(ARDUINO_SEEED_XIAO_M0) +// On the Zero and others we switch explicitly to SerialUSB +#define Serial SerialUSB +#endif + +// Definitions for the Chinese SAMD21 M0-Mini clone, which has no led connected to D13/PA17. +// Attention!!! D2 and D4 are swapped on these boards!!! +// If you connect the LED, it is on pin 24/PB11. In this case activate the next two lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 24 // PB11 +// As an alternative you can choose pin 25, it is the RX-LED pin (PB03), but active low.In this case activate the next 3 lines. +//#undef LED_BUILTIN +//#define LED_BUILTIN 25 // PB03 +//#define FEEDBACK_LED_IS_ACTIVE_LOW // The RX LED on the M0-Mini is active LOW + +#elif defined (NRF51) // BBC micro:bit +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define APPLICATION_PIN 1 +#define _IR_TIMING_TEST_PIN 4 + +#define tone(...) void() // no tone() available +#define noTone(a) void() +#define TONE_PIN 42 // Dummy for examples using it + +#else +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. +// Default valued for unidentified boards +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 +#endif // defined(ESP8266) + +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp +#endif + +#if !defined (FLASHEND) +#define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined +#endif + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // +#endif +#if !defined (RAMSIZE) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined +#endif diff --git a/examples/TinySender/TinySender.ino b/examples/TinySender/TinySender.ino index 39ff3c4d7..45d79af76 100644 --- a/examples/TinySender/TinySender.ino +++ b/examples/TinySender/TinySender.ino @@ -1,10 +1,12 @@ /* * TinySender.cpp * - * Example for sending FAST or NEC protocol using TinyIR. + * Example for sending using TinyIR. By default sends simultaneously using all supported protocols + * To use a single protocol, simply delete or comment out all unneeded protocols in the main loop + * Program size is significantly reduced when using a single protocol + * For example, sending only 8 bit address and command NEC codes saves 780 bytes program memory and 26 bytes RAM compared to SimpleSender, + * which does the same, but uses the IRRemote library (and is therefore much more flexible). * - * NEC protocol codes are sent in standard format with 8bit address and 8 bit command as in SimpleSender example. - * Saves 780 bytes program memory and 26 bytes RAM compared to SimpleSender, which does the same, but uses the IRRemote library (and is therefore much more flexible). * * The FAST protocol is a proprietary modified JVC protocol without address, with parity and with a shorter header. * FAST Protocol characteristics: @@ -15,13 +17,13 @@ * - Repeats are sent as complete frames but in a 50 ms period / with a 21 ms distance. * * - * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. * ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2024 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 @@ -44,16 +46,10 @@ */ #include -//#define USE_FAST_PROTOCOL // Use FAST protocol. No address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command -//#define DISABLE_PARITY_CHECKS // Disable parity checks. Saves 48 bytes of program memory. -//#define USE_ONKYO_PROTOCOL // Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. -//#define USE_FAST_PROTOCOL // Use FAST protocol (no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command) instead of NEC. -//#define ENABLE_NEC2_REPEATS // Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #include "TinyIRSender.hpp" -#define IR_SEND_PIN 3 - void setup() { pinMode(LED_BUILTIN, OUTPUT); @@ -82,29 +78,47 @@ void loop() { */ Serial.println(); Serial.print(F("Send now:")); -#if defined(USE_FAST_PROTOCOL) Serial.print(F(" address=0x")); Serial.print(sAddress, HEX); -#endif Serial.print(F(" command=0x")); Serial.print(sCommand, HEX); Serial.print(F(" repeats=")); Serial.print(sRepeats); Serial.println(); -#if defined(USE_FAST_PROTOCOL) - Serial.println(F("Send FAST with 8 bit address")); + // Send with FAST + // No address and only 16 bits of data, interpreted as 8 bit command and 8 bit inverted command for parity checking + Serial.println(F("Send FAST with 8 bit command")); Serial.flush(); sendFAST(IR_SEND_PIN, sCommand, sRepeats); -#elif defined(USE_ONKYO_PROTOCOL) + + // Send with NEC + // NEC uses 8 bit address and 8 bit command each with 8 bit inverted parity checks + // However, sendNEC will accept 16 bit address and commands too (but remove the parity checks) + Serial.println(F("Send NEC with 8 bit address and command")); + Serial.flush(); + sendNEC(IR_SEND_PIN, sAddress, sCommand, sRepeats); + + // Send with Extended NEC + // Like NEC, but the address is forced 16 bits with no parity check + Serial.println(F("Send ExtendedNEC with 16 bit address and 8 bit command")); + Serial.flush(); + sendExtendedNEC(IR_SEND_PIN, sAddress, sCommand, sRepeats); + + // Send with ONKYO + // Like NEC, but both the address and command are forced 16 bits with no parity check Serial.println(F("Send ONKYO with 16 bit address and command")); Serial.flush(); sendONKYO(IR_SEND_PIN, sAddress, sCommand, sRepeats); -#else - Serial.println(F("Send NEC with 8 bit address")); + + // Send with NEC2 + // Instead of sending the NEC special repeat code, sends the full original frame for repeats + // Sending NEC2 is done by setting the optional bool NEC2Repeats argument to true (defaults to false) + // sendExtendedNEC and sendONKYO also support the NEC2Repeats argument for full frame repeats (not demonstrated here) + Serial.println(F("Send NEC2 with 8 bit address and command and original frame repeats")); Serial.flush(); - sendNEC(IR_SEND_PIN, sAddress, sCommand, sRepeats); -#endif + sendNEC(IR_SEND_PIN, sAddress, sCommand, sRepeats, true); + /* * Increment send values * Also increment address just for demonstration, which normally makes no sense diff --git a/examples/UnitTest/PinDefinitionsAndMore.h b/examples/UnitTest/PinDefinitionsAndMore.h index ce84aa482..d3dd74992 100644 --- a/examples/UnitTest/PinDefinitionsAndMore.h +++ b/examples/UnitTest/PinDefinitionsAndMore.h @@ -4,8 +4,7 @@ * Contains pin definitions for IRremote examples for various platforms * as well as definitions for feedback LED and tone() and includes * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2026 Armin Joachimsmeyer * * This file is part of IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * @@ -35,21 +34,24 @@ * ATtiny167 9|PA3 8|PA2 5|PA7 Digispark original core * ATtiny84 |PB2 |PA4 |PA3 ATTinyCore * ATtiny88 3|PD3 4|PD4 9|PB1 ATTinyCore - * ATtiny3217 18|PA1 19|PA2 20|PA3 MegaTinyCore + * ATtiny3216 14|PA1 15|PA2 16|PA3 MegaTinyCore * ATtiny1604 2 3|PA5 % * ATtiny816 14|PA1 16|PA3 1|PA5 MegaTinyCore * ATtiny1614 8|PA1 10|PA3 1|PA5 MegaTinyCore - * SAMD21 3 4 5 + * MKR* 1 3 4 + * SAMD 2 3 4 * ESP8266 14|D5 12|D6 % - * ESP32 15 4 27 - * BluePill PA6 PA7 PA3 + * ESP32 15 4 27 + * ESP32-C3 2 3 4 + * ESP32-S3 2 3 4 + * BluePill PA6 PA7 PA3 * APOLLO3 11 12 5 * RP2040 3|GPIO15 4|GPIO16 5|GPIO17 */ //#define _IR_MEASURE_TIMING // For debugging purposes. #if defined(__AVR__) -#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) // Digispark board. For use with ATTinyCore. +#if (defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) && defined(PIN_PB0) // Digispark board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // TX is at pin 2 - Available as Arduino library "ATtinySerialOut". Saves 700 bytes program memory and 70 bytes RAM for ATtinyCore. #define IR_RECEIVE_PIN PIN_PB0 #define IR_SEND_PIN PIN_PB4 // Pin 2 is serial output with ATtinySerialOut. Pin 1 is internal LED and Pin3 is USB+ with pullup on Digispark board. @@ -59,28 +61,30 @@ # elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark pro board #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut" // For ATtiny167 Pins PB6 and PA3 are usable as interrupt source. -# if defined(ARDUINO_AVR_DIGISPARKPRO) +# if defined(ARDUINO_AVR_DIGISPARKPRO) // For use with Digispark original core #define IR_RECEIVE_PIN 9 // PA3 - on Digispark board labeled as pin 9 //#define IR_RECEIVE_PIN 14 // PB6 / INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN 8 // PA2 - on Digispark board labeled as pin 8 #define TONE_PIN 5 // PA7 - on Digispark board labeled as pin 5 #define _IR_TIMING_TEST_PIN 10 // PA4 -# else +# elif !defined(PIN_PA3) +#error ATtiny87 or ATtiny167 is not supported for the selected core. Please extend PinDefinitionsAndMore.h. +# else // For use with ATTinyCore #define IR_RECEIVE_PIN PIN_PA3 // On Digispark board labeled as pin 9 - INT0 is connected to USB+ on DigisparkPro boards #define IR_SEND_PIN PIN_PA2 // On Digispark board labeled as pin 8 #define TONE_PIN PIN_PA7 // On Digispark board labeled as pin 5 -# endif +# endif -# elif defined(__AVR_ATtiny84__) // For use with ATTinyCore +# elif defined(__AVR_ATtiny84__) && defined(PIN_PB2) // For use with ATTinyCore #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. #define IR_RECEIVE_PIN PIN_PB2 // INT0 #define IR_SEND_PIN PIN_PA4 #define TONE_PIN PIN_PA3 #define _IR_TIMING_TEST_PIN PIN_PA5 -# elif defined(__AVR_ATtiny88__) // MH-ET Tiny88 board. For use with ATTinyCore. +# elif defined(__AVR_ATtiny88__) && defined(PIN_PD3) // MH-ET Tiny88 board. For use with ATTinyCore. #include "ATtinySerialOut.hpp" // Available as Arduino library "ATtinySerialOut". Saves 128 bytes program memory. // Pin 6 is TX, pin 7 is RX #define IR_RECEIVE_PIN PIN_PD3 // 3 - INT1 @@ -88,39 +92,42 @@ #define TONE_PIN PIN_PB1 // 9 #define _IR_TIMING_TEST_PIN PIN_PB0 // 8 -# elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // For use with megaTinyCore +# elif (defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__)) && defined(PIN_PA1) // For use with megaTinyCore // Tiny Core Dev board -// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ -// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ -#define IR_RECEIVE_PIN PIN_PA1 // use 18 for TinyCore32 -#define IR_SEND_PIN PIN_PA2 // 19 -#define TONE_PIN PIN_PA3 // 20 -#define APPLICATION_PIN PIN_PA0 // 0 +// https://www.tindie.com/products/xkimi/tiny-core-16-dev-board-attiny1616/ - Out of Stock +// https://www.tindie.com/products/xkimi/tiny-core-32-dev-board-attiny3217/ - Out of Stock +#define IR_RECEIVE_PIN PIN_PA1 // 14 use 18 instead of PIN_PA1 for TinyCore32 +#define IR_SEND_PIN PIN_PA2 // 15, 19 for TinyCore32 +#define TONE_PIN PIN_PA3 // 16, 20 for TinyCore32 +#define APPLICATION_PIN PIN_PC3 // 13, PIN_PA0 is RESET #undef LED_BUILTIN // No LED available on the TinyCore 32 board, take the one on the programming board which is connected to the DAC output -#define LED_BUILTIN PIN_PA6 // use 2 for TinyCore32 +#define LED_BUILTIN PIN_PA6 // use 2 instead of PIN_PA6 for TinyCore32 -# elif defined(__AVR_ATtiny816__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny816__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 14 -#define IR_SEND_PIN PIN_PA1 // 16 +#define IR_SEND_PIN PIN_PA3 // 16 #define TONE_PIN PIN_PA5 // 1 #define APPLICATION_PIN PIN_PA4 // 0 #undef LED_BUILTIN // No LED available, take the one which is connected to the DAC output #define LED_BUILTIN PIN_PB5 // 4 -# elif defined(__AVR_ATtiny1614__) // For use with megaTinyCore +# elif defined(__AVR_ATtiny1604__) && defined(PIN_PA1) // For use with megaTinyCore #define IR_RECEIVE_PIN PIN_PA1 // 8 -#define IR_SEND_PIN PIN_PA3 // 10 -#define TONE_PIN PIN_PA5 // 1 -#define APPLICATION_PIN PIN_PA4 // 0 - -# elif defined(__AVR_ATtiny1604__) // For use with megaTinyCore -#define IR_RECEIVE_PIN PIN_PA6 // 2 - To be compatible with interrupt example, pin 2 is chosen here. #define IR_SEND_PIN PIN_PA7 // 3 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 #define APPLICATION_PIN PIN_PB2 // 5 -#define tone(...) void() // Define as void, since TCB0_INT_vect is also used by tone() -#define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it +# elif defined(__AVR_ATtiny1614__) && defined(PIN_PA1) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 10 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PA4 // 0 + +# elif defined(__AVR_ATtiny1624__) && defined(PIN_PA6) // For use with megaTinyCore +#define IR_RECEIVE_PIN PIN_PA1 // 8 +#define IR_SEND_PIN PIN_PA5 // 3 TCA0-WO5 +#define TONE_PIN PIN_PA3 // 1 TCA0-WO3 +#define APPLICATION_PIN PIN_PB1 // 6 # elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \ || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) \ @@ -153,6 +160,15 @@ # endif # endif // defined(__AVR_ATtiny25__)... +#elif defined(ARDUINO_ARCH_RENESAS_UNO) // Uno R4 +// To be compatible with Uno R3. +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 5 +#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output. +#define _IR_TIMING_TEST_PIN 7 + #elif defined(ESP8266) #define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D4) is active LOW #define IR_RECEIVE_PIN 14 // D5 @@ -162,21 +178,41 @@ #define tone(...) void() // tone() inhibits receive timer #define noTone(a) void() -#define TONE_PIN 42 // Dummy for examples using it - -#elif defined(CONFIG_IDF_TARGET_ESP32C3) -#define IR_INPUT_PIN 8 -#define IR_SEND_PIN 9 -#define TONE_PIN 10 // ADC2_0 -#define APPLICATION_PIN 11 +#define TONE_PIN 42 // Dummy for examples using it# + +#elif defined(ARDUINO_NOLOGO_ESP32C3_SUPER_MINI) +// ESP32 - C3 super mini +#define FEEDBACK_LED_IS_ACTIVE_LOW // The LED on my board (D8) is active LOW +#define IR_RECEIVE_PIN 2 +#define IR_SEND_PIN 3 +#define TONE_PIN 4 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(ARDUINO_ESP32C3_DEV) +// ESP32 - C3 other +#define NO_LED_FEEDBACK_CODE // The WS2812 on pin 8 of AI-C3 board crashes if used as receive feedback LED, other I/O pins are working... +#define IR_RECEIVE_PIN 6 +#define IR_SEND_PIN 7 +#define TONE_PIN 9 +#define APPLICATION_PIN 10 + +#elif defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARDUINO_ESP32S3_DEV) +// ESP32 - S3 - !!! NOT tested !!! +#define IR_RECEIVE_PIN 15 // alternatively 13 +#define IR_SEND_PIN 16 // alternatively 14 +#define TONE_PIN 17 +#define APPLICATION_PIN 18 #elif defined(ESP32) #include // tone() is included in ESP32 core since 2.0.2 -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 12345678 -#endif +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif +# if !defined(ESP_ARDUINO_VERSION_VAL) +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +# endif #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. void tone(uint8_t aPinNumber, unsigned int aFrequency){ @@ -199,7 +235,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 27 // D27 25 & 26 are DAC0 and 1 #define APPLICATION_PIN 16 // RX2 pin -#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1) // BluePill +#elif (defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32F1)) && defined(PA6) // BluePill // Timer 3 blocks PA6, PA7, PB0, PB1 for use by Servo or tone() #define IR_RECEIVE_PIN PA6 #define IR_RECEIVE_PIN_STRING "PA6" @@ -219,7 +255,8 @@ void noTone(uint8_t aPinNumber){ #define IR_SEND_PIN 12 #define TONE_PIN 5 -#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE +#elif defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_MBED_NANO) // Arduino Nano 33 BLE and Arduino Nano Connect layout for MBED +// Must be before ARDUINO_ARCH_RP2040, since it is the layout for the MBED core of Arduino Nano Connect #define IR_RECEIVE_PIN 3 // GPIO15 Start with pin 3 since pin 2|GPIO25 is connected to LED on Pi pico #define IR_SEND_PIN 4 // GPIO16 #define TONE_PIN 5 @@ -240,7 +277,7 @@ void noTone(uint8_t aPinNumber){ #undef LED_BUILTIN #define LED_BUILTIN 6 -#elif defined(PARTICLE) // !!!UNTESTED!!! +#elif defined(PARTICLE) && defined(A4) // !!!UNTESTED!!! #define IR_RECEIVE_PIN A4 #define IR_SEND_PIN A5 // Particle supports multiple pins @@ -266,7 +303,11 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM) +# if defined(USE_ARDUINO_MKR_PIN_LAYOUT) +#define IR_RECEIVE_PIN 1 // Pin 2 on MKR is not interrupt capable, see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ +# else #define IR_RECEIVE_PIN 2 +# endif #define IR_SEND_PIN 3 #define TONE_PIN 4 #define APPLICATION_PIN 5 @@ -299,7 +340,7 @@ void noTone(uint8_t aPinNumber){ #define TONE_PIN 42 // Dummy for examples using it #else -#warning Board / CPU is not detected using pre-processor symbols -> using default values, which may not fit. Please extend PinDefinitionsAndMore.h. +#warning Board and Core / CPU is not detected using pre-processor symbols -> using default values for IR_RECEIVE_PIN etc., which may not fit. Please extend PinDefinitionsAndMore.h. // Default valued for unidentified boards #define IR_RECEIVE_PIN 2 #define IR_SEND_PIN 3 @@ -309,28 +350,17 @@ void noTone(uint8_t aPinNumber){ #define _IR_TIMING_TEST_PIN 7 #endif // defined(ESP8266) -#if defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED) -#define SEND_PWM_BY_TIMER // We do not have pin restrictions for this CPU's, so lets use the hardware PWM for send carrier signal generation -#else -# if defined(SEND_PWM_BY_TIMER) -#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warning in IRTimer.hpp -# endif +#if !(defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE) || defined(ARDUINO_ARCH_MBED)) && defined(SEND_PWM_BY_TIMER) +#undef IR_SEND_PIN // SendPin is determined by timer! This avoids warnings in IRremote.hpp and IRTimer.hpp #endif #if !defined (FLASHEND) #define FLASHEND 0xFFFF // Dummy value for platforms where FLASHEND is not defined #endif -#if !defined (RAMEND) -#define RAMEND 0xFFFF // Dummy value for platforms where RAMEND is not defined + +#if !defined (RAMSIZE) && defined(RAMEND) && defined(RAMSTART) +#define RAMSIZE (RAMEND - RAMSTART + 1) // #endif #if !defined (RAMSIZE) -#define RAMSIZE 0xFFFF // Dummy value for platforms where RAMSIZE is not defined -#endif - -/* - * Helper macro for getting a macro definition as string - */ -#if !defined(STR_HELPER) -#define STR_HELPER(x) #x -#define STR(x) STR_HELPER(x) +#define RAMSIZE 0x1000 // 4k Dummy value for platforms where RAMSIZE is not defined #endif diff --git a/examples/UnitTest/UnitTest.ino b/examples/UnitTest/UnitTest.ino index b9a88d11b..f88f26227 100644 --- a/examples/UnitTest/UnitTest.ino +++ b/examples/UnitTest/UnitTest.ino @@ -9,7 +9,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -33,44 +33,58 @@ #include -#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. +//#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. +//#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 240 bytes program memory if IrSender.write is used +//#define USE_THRESHOLD_DECODER // May give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses. Requires additional 24 bytes program memory. +//#define USE_STRICT_DECODER // Check for additional required characteristics of protocol timing. Requires 300 additional bytes program memory. +//#define USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN // Reverses the polarity at the send pin. +//#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! +//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. +//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition +//#define USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM // Simulate an active high receiver signal instead of an active low signal. +#define NO_LED_FEEDBACK_CODE // Saves 270 bytes program memory +//#define NO_LED_RECEIVE_FEEDBACK_CODE // Saves 176 bytes program memory +//#define NO_LED_SEND_FEEDBACK_CODE // Saves 38 bytes program memory +//#define USE_16_BIT_TIMING_BUFFER // Use a 16-bit buffer to preserve values above 12750 us + +#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc. Sets FLASHEND and RAMSIZE and evaluates value of SEND_PWM_BY_TIMER. #if !defined(RAW_BUFFER_LENGTH) -# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF -//#define RAW_BUFFER_LENGTH 180 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# elif RAMEND <= 0x8FF || RAMSIZE < 0x8FF -#define RAW_BUFFER_LENGTH 150 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. -# else -#define RAW_BUFFER_LENGTH 200 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100. +// Use more than the default values of 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM +# if RAMSIZE <= 0x400 +// Here we have 1 k RAM or less +#define RAW_BUFFER_LENGTH 360 +# elif RAMSIZE <= 0x800 +// Here we have 2 k RAM or less, otherwise use default of 750 +#define RAW_BUFFER_LENGTH 400 // 400 is OK with Pronto and 1000 is OK without Pronto. 1200 is too much here, because then variables are overwritten. # endif #endif -//#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory. -//#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 240 bytes program memory if IrSender.write is used -//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. -//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition -#define NO_LED_FEEDBACK_CODE // Saves 344 bytes program memory -// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, //#define USE_MSB_DECODING_FOR_DISTANCE_DECODER -// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142. -//#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 40 is taken for the cheap VS1838 module her, since we have high intensity. + +// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, +// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 135. +// 20 is taken as default if not otherwise specified / defined. +//#define MARK_EXCESS_MICROS 40 // 40 inhibits the decoding of the short B&O marks of 250 us. + +//#define RECORD_GAP_MICROS 12000 // Default is 8000. Activate it for some LG air conditioner protocols. //#define TRACE // For internal usage //#define DEBUG // Activate this for lots of lovely debug output from the decoders. #if FLASHEND >= 0x1FFF // For 8k flash or more, like ATtiny85 #define DECODE_DENON // Includes Sharp -#define DECODE_KASEIKYO -#define DECODE_PANASONIC // alias for DECODE_KASEIKYO -#define DECODE_NEC // Includes Apple and Onkyo +#define DECODE_KASEIKYO // Includes Panasonic ~ 640 bytes +#define DECODE_NEC // Includes Apple and Onkyo ~ 1050 bytes #endif #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 #define DECODE_JVC -#define DECODE_RC5 -#define DECODE_RC6 +#define DECODE_RC5 // with DECODE_MARANTZ ~ 1270 +#define DECODE_MARANTZ +#define DECODE_RC6 // ~ 940 bytes -#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols +#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols ~ 2430 bytes #define DECODE_HASH // special decoder for all protocols #endif @@ -78,31 +92,44 @@ #define DECODE_SONY #define DECODE_SAMSUNG #define DECODE_LG - -#define DECODE_BEO // It prevents decoding of SONY (default repeats), which we are not using here. -//#define ENABLE_BEO_WITHOUT_FRAME_GAP // For successful unit testing we must see the warning at ir_BangOlufsen.hpp:88:2 -#if defined(DECODE_BEO) -#define RECORD_GAP_MICROS 16000 // always get the complete frame in the receive buffer -#define BEO_KHZ 38 // We send and receive Bang&Olufsen with 38 kHz here (instead of 455 kHz). +#define DECODE_LEGO_PF // LEGO is skipped, since it is difficult to receive because of its short marks and spaces + +#define DECODE_BEO // It prevents decoding of SONY (default repeats), which we are not using here. ~ 1340 bytes +//#define ENABLE_BEO_WITHOUT_FRAME_GAP // !!!For successful unit testing we must see the warning at ir_BangOlufsen.hpp:100:2!!! +# if defined(DECODE_BEO) +#define RECORD_GAP_MICROS 16000 // Force to get the complete frame including the 3. space of 15 ms in the receive buffer +#define SUPPRESS_BEO_RECORD_GAP_MICROS_WARNING // We know, what we do here :-) +#define BEO_KHZ 38 // We send and receive Bang&Olufsen with 38 kHz instead of 455 kHz in order to be able to test it +# endif #endif -#define DECODE_BOSEWAVE -//#define DECODE_LEGO_PF -#define DECODE_MAGIQUEST +#define DECODE_BOSEWAVE // ~ 250 bytes +#define DECODE_MAGIQUEST // ~ 460 bytes +#define DECODE_OPENLASIR // ~ 330 bytes +#define DECODE_FAST // ~ 210 bytes + //#define DECODE_WHYNTER -#define DECODE_FAST -#endif +//#undef IR_SEND_PIN // enable this, if you need to set send pin programmatically using uint8_t tSendPin below + +#define SHOW_DISTANCE_WIDTH_DECODER_ERRORS // Prints the reason which prevents data to be decoded as distance width data #include -#if defined(APPLICATION_PIN) +#include "TinyIRSender.hpp" + +#if defined(APPLICATION_PIN) && !defined(DEBUG_BUTTON_PIN) #define DEBUG_BUTTON_PIN APPLICATION_PIN // if held low, print timing for each received data #else #define DEBUG_BUTTON_PIN 6 #endif +#if defined(ESP32) && defined(DEBUG_BUTTON_PIN) +# if !digitalPinIsValid(DEBUG_BUTTON_PIN) +#undef DEBUG_BUTTON_PIN // DEBUG_BUTTON_PIN number is not valid, so delete definition to disable further usage +# endif +#endif -#define DELAY_AFTER_SEND 1000 -#define DELAY_AFTER_LOOP 5000 +#define DELAY_AFTER_SEND 700 +#define DELAY_AFTER_LOOP 3000 #if defined(SEND_PWM_BY_TIMER) && !defined(SEND_PWM_DOES_NOT_USE_RECEIVE_TIMER) #error Unit test cannot run if SEND_PWM_BY_TIMER is enabled i.e. receive timer us also used by send @@ -114,12 +141,38 @@ volatile bool sDataJustReceived = false; void ReceiveCompleteCallbackHandler(); +#if __INT_WIDTH__ < 32 +//IRDecodedRawDataType const tRawDataPGM[] PROGMEM = { 0xB02002, 0xA010 }; // LSB of tRawData[0] is sent first +uint8_t const tRawDataPGM[] PROGMEM = { 0x02, 0x20, 0xB0, 0x00, /*0xB02002*/ +0x10, 0xA0, 0x0, 0x0, /*0xA010*/}; // Define tRawDataPGM as byte array of same size with same content as { 0xB02002, 0xA010} +#endif + +// if this definition is contained in a function, the address, the compiler uses is wrong :-( +const uint16_t rawIRTimingsNEC[] +#if defined(__AVR__) +PROGMEM // this crashes on ESP8266 +#endif += { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, + 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, + 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560, 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, + 560/*0000 0x00*/, 560, 1690, 560, 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, + 560, 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing + void setup() { +#if defined(DEBUG_BUTTON_PIN) pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP); +#endif Serial.begin(115200); -#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217) - delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! + +#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ + || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) + // Wait until Serial Monitor is attached. + // Required for boards using USB code for Serial like Leonardo. + // Is void for USB Serial implementations using external chips e.g. a CH340. + while (!Serial) + ; + // !!! Program will not proceed if no Serial Monitor is attached !!! #endif // Just to know which program is running on my Arduino Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); @@ -136,26 +189,44 @@ void setup() { Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); #endif +#if defined(LED_BUILTIN) && !defined(NO_LED_FEEDBACK_CODE) +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + Serial.print(F("Active low ")); +# endif + Serial.print(F("FeedbackLED at pin ")); + Serial.println(LED_BUILTIN); // Works also for ESP32: static const uint8_t LED_BUILTIN = 8; #define LED_BUILTIN LED_BUILTIN +#endif + + Serial.println(F("Use ReceiveCompleteCallback")); + Serial.println(F("Receive buffer length is " STR(RAW_BUFFER_LENGTH))); + #if defined(IR_SEND_PIN) - IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin + /* + * No IR send setup required :-) + * Default is to use IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin + * and use feedback LED at default feedback LED pin if not disabled by #define NO_LED_SEND_FEEDBACK_CODE + */ # if defined(IR_SEND_PIN_STRING) - Serial.println(F("at pin " IR_SEND_PIN_STRING)); + Serial.println(F("Send IR signals at pin " IR_SEND_PIN_STRING)); # else Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN))); # endif #else - IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin - Serial.println(F("Send IR signals at pin 3")); + // Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN + uint8_t tSendPin = 3; + IrSender.begin(tSendPin);// Specify send pin and use feedback LED at default feedback LED pin + // You can change send pin later with IrSender.setSendPin(); + + Serial.print(F("Send IR signals at pin ")); + Serial.println(tSendPin); #endif #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 +# if defined(DEBUG_BUTTON_PIN) Serial.print(F("If you connect debug pin ")); -# if defined(APPLICATION_PIN_STRING) - Serial.print(APPLICATION_PIN_STRING); -# else Serial.print(DEBUG_BUTTON_PIN); -# endif Serial.println(F(" to ground, raw data is always printed")); +# endif // For esp32 we use PWM generation by ledcWrite() for each pin. # if !defined(SEND_PWM_BY_TIMER) @@ -175,14 +246,19 @@ void setup() { // infos for receive Serial.print(RECORD_GAP_MICROS); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); + +# if defined(USE_THRESHOLD_DECODER) + Serial.println(F("Threshold decoding is active and thus MARK_EXCESS_MICROS is set to 0")); +# else Serial.print(MARK_EXCESS_MICROS); Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); +# endif #endif delay(DELAY_AFTER_SEND); } -void checkReceivedRawData(IRRawDataType aRawData) { +void checkReceivedRawData(IRDecodedRawDataType aRawData) { // wait until signal has received while (!sDataJustReceived) { }; @@ -197,11 +273,16 @@ void checkReceivedRawData(IRRawDataType aRawData) { IrReceiver.printIRResultMinimal(&Serial); #endif #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 - if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) { - // We have an unknown protocol, print more info + if (IrReceiver.decodedIRData.protocol == UNKNOWN +# if defined(DEBUG_BUTTON_PIN) + || digitalRead(DEBUG_BUTTON_PIN) == LOW +# endif + ) { + // We have an unknown protocol or debug button is held low, print more info IrReceiver.printIRResultRawFormatted(&Serial, true); } -#endif +#endif // FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 + if (IrReceiver.decodedIRData.protocol == PULSE_DISTANCE || IrReceiver.decodedIRData.protocol == PULSE_WIDTH) { if (IrReceiver.decodedIRData.decodedRawData != aRawData) { Serial.print(F("ERROR: Received data=0x")); @@ -217,6 +298,8 @@ void checkReceivedRawData(IRRawDataType aRawData) { PrintULL::print(&Serial, aRawData, HEX); #endif Serial.println(); + IrReceiver.printIRResultAsCArray(&Serial, false, false); // To be able to easily compare received with sent data + Serial.println(); } } IrReceiver.resume(); @@ -227,7 +310,7 @@ void checkReceivedRawData(IRRawDataType aRawData) { } #if defined(DECODE_DISTANCE_WIDTH) -void checkReceivedArray(IRRawDataType *aRawDataArrayPointer, uint8_t aArraySize) { +void checkReceivedArray(IRDecodedRawDataType *aRawDataArrayPointer, uint8_t aArraySize) { // wait until signal has received while (!sDataJustReceived) { }; @@ -242,8 +325,12 @@ void checkReceivedArray(IRRawDataType *aRawDataArrayPointer, uint8_t aArraySize) IrReceiver.printIRResultMinimal(&Serial); #endif #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 - if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) { - // We have an unknown protocol, print more info + if (IrReceiver.decodedIRData.protocol == UNKNOWN +# if defined(DEBUG_BUTTON_PIN) + || digitalRead(DEBUG_BUTTON_PIN) == LOW +# endif + ) { + // We have an unknown protocol or debug button is held low, print more info IrReceiver.printIRResultRawFormatted(&Serial, true); } #endif @@ -259,6 +346,7 @@ void checkReceivedArray(IRRawDataType *aRawDataArrayPointer, uint8_t aArraySize) # endif Serial.print(F(" != sent data=0x")); Serial.println(*aRawDataArrayPointer, HEX); + IrReceiver.printIRResultAsCArray(&Serial, false, false); } aRawDataArrayPointer++; } @@ -273,17 +361,45 @@ void checkReceivedArray(IRRawDataType *aRawDataArrayPointer, uint8_t aArraySize) /* * Test callback function - * Has the same functionality as available() + * Has the same functionality as a check with available() */ void ReceiveCompleteCallbackHandler() { sDataJustReceived = true; } -void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { +/* + * Must be called after checkReceive, because it does not wait for signal to be received and does not call decode() + */ +void checkReceivedExtra(uint16_t aSentExtra) { + if (IrReceiver.decodedIRData.extra != aSentExtra) { + Serial.print(F("ERROR: Received extra=0x")); + Serial.print(IrReceiver.decodedIRData.extra, HEX); + Serial.print(F(" != sent extra=0x")); + Serial.println(aSentExtra, HEX); + } +} + +void waitForReceived() { // wait until signal has received + uint16_t tTimeoutCounter = 500; // gives 5 seconds timeout while (!sDataJustReceived) { - }; + delay(10); + if (tTimeoutCounter == 0) { + Serial.println(F("Receive timeout happened")); + break; + } + tTimeoutCounter--; + } sDataJustReceived = false; +} + +/* + * @return true if NO error, false if error + */ +bool checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { + bool tReturnValueIsSuccess = true; + + waitForReceived(); if (IrReceiver.decode()) { // Print a short summary of received data @@ -300,13 +416,20 @@ void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { } #if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604 - if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) { + if (IrReceiver.decodedIRData.protocol == UNKNOWN +# if defined(DEBUG_BUTTON_PIN) + || digitalRead(DEBUG_BUTTON_PIN) == LOW +# endif + ) { // We have an unknown protocol, print more info IrReceiver.printIRResultRawFormatted(&Serial, true); } #endif + IrReceiver.resume(); // Early resume + if (IrReceiver.decodedIRData.protocol == UNKNOWN) { Serial.println(F("ERROR: Unknown protocol")); + tReturnValueIsSuccess = false; } else { /* * Check address @@ -316,6 +439,7 @@ void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { Serial.print(IrReceiver.decodedIRData.address, HEX); Serial.print(F(" != sent address=0x")); Serial.println(aSentAddress, HEX); + tReturnValueIsSuccess = false; } /* * Check command @@ -325,14 +449,17 @@ void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { Serial.print(IrReceiver.decodedIRData.command, HEX); Serial.print(F(" != sent command=0x")); Serial.println(aSentCommand, HEX); + tReturnValueIsSuccess = false; } } - IrReceiver.resume(); } else { Serial.println(F("No data received")); + tReturnValueIsSuccess = false; + IrReceiver.resume(); } Serial.println(); + return tReturnValueIsSuccess; } /* @@ -344,7 +471,12 @@ void checkReceive(uint16_t aSentAddress, uint16_t aSentCommand) { uint16_t sAddress = 0xFFF1; uint8_t sCommand = 0x76; uint16_t s16BitCommand = 0x9876; -#define sRepeats 0 // no unit test for repeats +/* + * Repeats cannot be automatically checked, because just the first frame is stored in receive buffer and all repeat frames are skipped. + * We cannot issue a resume() before sending of an repeat, because we use the blocking send*() functions. + * But an independent receiver could check it + */ +uint8_t sRepeats = 0; void loop() { /* @@ -355,36 +487,131 @@ void loop() { Serial.print(sAddress, HEX); Serial.print(F(" command=0x")); Serial.print(sCommand, HEX); + if (sRepeats > 0) { + Serial.print(F(" repeats=")); + Serial.print(sRepeats); + } + Serial.println(); Serial.println(); - Serial.println(F("Send NEC with 8 bit address")); +#if defined(DECODE_NEC) + /* + * Sending complete NEC frames as repeats to force decoding as NEC2 are tested here + */ + Serial.print(F("Send NEC with 8 bit address")); + if (sRepeats > 0) { + Serial.print(F(" and complete NEC frames as repeats to force decoding as NEC2")); + } + Serial.println(); Serial.flush(); - IrSender.sendNEC(sAddress & 0xFF, sCommand, sRepeats); + IrSender.sendNEC(sAddress & 0xFF, sCommand, 0); // sending first frame -> decodes as NEC checkReceive(sAddress & 0xFF, sCommand); + + for (int8_t i = 0; i < sRepeats; i++) { +# if defined(DEBUG_BUTTON_PIN) + if (digitalRead(DEBUG_BUTTON_PIN) != LOW) { + // If debug is enabled, printing time (50 ms) is sufficient as delay + delayMicroseconds(NEC_REPEAT_DISTANCE - 20000); // 20000 is just a guess + } +# endif + IrSender.sendNEC(sAddress & 0xFF, sCommand, 0); // sending repeat frames -> decodes as NEC2 + checkReceive(sAddress & 0xFF, sCommand); + } + delay(DELAY_AFTER_SEND); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal Serial.println(F("Send NEC with 16 bit address")); Serial.flush(); - IrSender.sendNEC(sAddress, sCommand, sRepeats); + IrSender.sendNEC(sAddress, sCommand, sRepeats); // no repeats checkReceive(sAddress, sCommand); delay(DELAY_AFTER_SEND); - Serial.println(F("Send NEC2 with 16 bit address")); + Serial.println(F("Send NEC2 with 16 bit address")); // The only difference is the repeat Serial.flush(); IrSender.sendNEC2(sAddress, sCommand, sRepeats); checkReceive(sAddress, sCommand); delay(DELAY_AFTER_SEND); +#endif // defined(DECODE_NEC) + +#if FLASHEND >= 0x7FFF && RAMSIZE >= 0x600 // For 32k flash or more, like Uno. Code does not fit in program memory of ATtiny1604 etc. + if (sCommand == 0x76) { + /* + * Do this only once at the first loop + */ + +#if defined(DECODE_RC5) + /* + * Test minimal RC5X and maximal RC5 length + */ + Serial.println(F("Send RC5 minimal length")); // 14 + Serial.flush(); + IrSender.setNextToggleBitValueForRC5AndRC6(1); // To get minimal length + IrSender.sendRC5(0x0A, 0x6A, sRepeats, true); // use RC5X + checkReceive(0x0A, 0x6A); + delay(DELAY_AFTER_SEND / 2); + + Serial.println(F("Send RC5 maximal length")); // 28 + Serial.flush(); + IrSender.setNextToggleBitValueForRC5AndRC6(1); // To get maximal length + IrSender.sendRC5(0x1F, 0x3F, sRepeats, true); + checkReceive(0x1F, 0x3F); + delay(DELAY_AFTER_SEND / 2); + + Serial.println(F("Send Marantz maximal length")); // 34 + Serial.flush(); + IrSender.setNextToggleBitValueForRC5AndRC6(1); // To get maximal length + IrSender.sendRC5Marantz(0x1F, 0x3F, sRepeats, 0x3F, true); + if (checkReceive(0x1F, 0x3F)) { + checkReceivedExtra(0x3F); + } + + delay(DELAY_AFTER_SEND); +#endif // defined(DECODE_RC5) + +#if defined(DECODE_RC6) + /* + * Test minimal RC6 and maximal RC6A length + * Toggle bit does not make any difference for RC6A, because it is located between a 0 and a 1 bit + */ + Serial.println(F("Send RC6 minimal length")); // 26 + Serial.flush(); + IrSender.setNextToggleBitValueForRC5AndRC6(1); // To get minimal length + IrSender.sendRC6(0x55, 0x55, 0, true); + checkReceive(0x55, 0x55); + delay(DELAY_AFTER_SEND / 2); + + Serial.println(F("Send RC6A maximal length")); // 72 + Serial.flush(); + IrSender.sendRC6A(0xFF, 0xFF, 0, 0x3FFF, true); + if (checkReceive(0xFF, 0xFF)) { + checkReceivedExtra(0x3FFF); + } + delay(DELAY_AFTER_SEND); +#endif // defined(DECODE_RC6) + + IRDecodedRawDataType tRawData[4]; -#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. + /* + * Test send usage for UNKNOWN protocol + */ + const uint16_t rawIRTimings[] = { 9000, 4500/*Start bit*/, 500, 1000, 1000, 500, 500, 2000, 2000, 500, 500, 3000, 3000, 500, + 500, 250, 250, 500 }; + Serial.println(F("Send arbitrary raw data with 1 repeat and exact timing (16 bit array format) with sendRaw()")); + Serial.flush(); + IrSender.sendRaw(rawIRTimings, sizeof(rawIRTimings) / sizeof(rawIRTimings[0]), NEC_KHZ, 80, 1); // Note the approach used to automatically calculate the size of the array. + waitForReceived(); + IrReceiver.printIRResultRawFormatted(&Serial, true); + IrReceiver.resume(); + delay(DELAY_AFTER_SEND); - if (sAddress == 0xFFF1) { -# if FLASHEND >= 0x7FFF // For 32k flash or more, like UNO. Code does not fit in program memory of ATtiny1604 etc. +# if defined(DECODE_NEC) /* * Send constant values only once in this demo */ - Serial.println(F("Send NEC Pronto data with 8 bit address 0x80 and command 0x45 and no repeats")); + Serial.println(F("Send NEC data with 8 bit address 0x80 and command 0x45 and no repeats with sendPronto()")); Serial.flush(); + // This is copied to stack/ram internally IrSender.sendPronto(F("0000 006D 0022 0000 015E 00AB " /* Pronto header + start bit */ "0017 0015 0017 0015 0017 0017 0015 0017 0017 0015 0017 0015 0017 0015 0017 003F " /* Lower address byte */ "0017 003F 0017 003E 0017 003F 0015 003F 0017 003E 0017 003F 0017 003E 0017 0015 " /* Upper address byte (inverted at 8 bit mode) */ @@ -394,16 +621,14 @@ void loop() { checkReceive(0x80, 0x45); delay(DELAY_AFTER_SEND); + /* + * Test sending NEC protocol using sendRaw_P + */ Serial.println( - F("Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format)")); + F( + "Send NEC data with 8 bit address=0xFB04, command 0x08, 1 repeat and exact timing (16 bit array format) with sendRaw_P()")); Serial.flush(); - const uint16_t irSignal[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, - 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, - 560, 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, - 560, 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, - 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, - 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing - IrSender.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array. + IrSender.sendRaw_P(rawIRTimingsNEC, sizeof(rawIRTimingsNEC) / sizeof(rawIRTimingsNEC[0]), NEC_KHZ, 110, 1); // Note the approach used to automatically calculate the size of the array. checkReceive(0xFB04 & 0xFF, 0x08); delay(DELAY_AFTER_SEND); @@ -412,13 +637,14 @@ void loop() { */ Serial.println(F("Send ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102)")); Serial.flush(); - IrSender.sendNECRaw(0x03040102, sRepeats); + IrSender.sendNECRaw(0x03040102, 0); checkReceive(0x0102, 0x304); delay(DELAY_AFTER_SEND); /* * With Send sendNECMSB() you can send your old 32 bit codes. * To convert one into the other, you must reverse the byte positions and then reverse all positions of each byte. + * Use bitreverse32Bit(). * Example: * 0xCB340102 byte reverse -> 0x020134CB bit reverse-> 40802CD3 */ @@ -427,40 +653,40 @@ void loop() { IrSender.sendNECMSB(0x40802CD3, 32, false); checkReceive(0x0102, 0x34); delay(DELAY_AFTER_SEND); -# endif +# endif // defined(DECODE_NEC) -# if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) - Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit generic PulseDistance using ProtocolConstants")); +# if defined(DECODE_KASEIKYO) + Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM using ProtocolConstants 1=432|1296, 0=432|432")); Serial.flush(); # if __INT_WIDTH__ < 32 - IRRawDataType tRawData[] = { 0xB02002, 0xA010, 0x0 }; // LSB of tRawData[0] is sent first - IrSender.sendPulseDistanceWidthFromArray(&KaseikyoProtocolConstants, &tRawData[0], 48, NO_REPEATS); // Panasonic is a Kaseikyo variant + IrSender.sendPulseDistanceWidthFromPGMArray_P(&KaseikyoProtocolConstants, (IRDecodedRawDataType*) &tRawDataPGM[0], 48, + NO_REPEATS); // Panasonic is a Kaseikyo variant checkReceive(0x0B, 0x10); # else - IrSender.sendPulseDistanceWidth(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant + IrSender.sendPulseDistanceWidth_P(&KaseikyoProtocolConstants, 0xA010B02002, 48, NO_REPEATS); // Panasonic is a Kaseikyo variant checkReceivedRawData(0xA010B02002); # endif delay(DELAY_AFTER_SEND); /* - * Send 2 Panasonic 48 bit codes as generic Pulse Distance data, once with LSB and once with MSB first + * Send 2 Panasonic 48 bit codes as Pulse Distance data, once with LSB and once with MSB first */ - Serial.println(F("Send Panasonic 0xB, 0x10 as generic 48 bit PulseDistance")); - Serial.println(F(" LSB first")); + Serial.println(F("Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM 1=450|1250, 0=450|400")); + Serial.println(F("-LSB first")); Serial.flush(); # if __INT_WIDTH__ < 32 - IrSender.sendPulseDistanceWidthFromArray(38, 3450, 1700, 450, 1250, 450, 400, &tRawData[0], 48, PROTOCOL_IS_LSB_FIRST, 0, - NO_REPEATS); + IrSender.sendPulseDistanceWidthFromPGMArray(38, 3450, 1700, 450, 1250, 450, 400, (IRDecodedRawDataType*) tRawDataPGM, 48, + PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS); checkReceive(0x0B, 0x10); # else - IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, - 0, NO_REPEATS); + IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0xA010B02002, 48, PROTOCOL_IS_LSB_FIRST, 0, + NO_REPEATS); checkReceivedRawData(0xA010B02002); # endif delay(DELAY_AFTER_SEND); // The same with MSB first. Use bit reversed raw data of LSB first part - Serial.println(F(" MSB first")); + Serial.println(F("-MSB first")); # if __INT_WIDTH__ < 32 tRawData[0] = 0x40040D00; // MSB of tRawData[0] is sent first tRawData[1] = 0x805; @@ -468,22 +694,23 @@ void loop() { NO_REPEATS); checkReceive(0x0B, 0x10); # else - IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, 0, NO_REPEATS); + IrSender.sendPulseDistanceWidth(38, 3450, 1700, 450, 1250, 450, 400, 0x40040D000805, 48, PROTOCOL_IS_MSB_FIRST, 0, + NO_REPEATS); checkReceivedRawData(0x40040D000805); # endif delay(DELAY_AFTER_SEND); -# endif // defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) +# endif // defined(DECODE_KASEIKYO) # if defined(DECODE_DISTANCE_WIDTH) # if defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER) - Serial.println(F("Send generic 52 bit PulseDistance 0x43D8613C and 0x3BC3B MSB first")); + Serial.println(F("Send 52 bit PulseDistance 0x43D8613C and 0x3BC3B MSB first 1=550|1700, 0=550|600")); Serial.flush(); # if __INT_WIDTH__ < 32 tRawData[0] = 0x43D8613C; // MSB of tRawData[0] is sent first tRawData[1] = 0x3BC3B; IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 52, PROTOCOL_IS_MSB_FIRST, 0, - NO_REPEATS); + NO_REPEATS); checkReceivedArray(tRawData, 2); # else IrSender.sendPulseDistanceWidth(38, 8900, 4450, 550, 1700, 550, 600, 0x43D8613CBC3B, 52, PROTOCOL_IS_MSB_FIRST, 0, NO_REPEATS); @@ -491,7 +718,7 @@ void loop() { # endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 52 bit PulseDistanceWidth 0x43D8613C and 0x3BC3B MSB first")); + Serial.println(F("Send 52 bit PulseDistanceWidth 0x43D8613C and 0x3BC3B MSB first 1=600|300, 0=300|600")); Serial.flush(); // Real PulseDistanceWidth (constant bit length) does not require a stop bit # if __INT_WIDTH__ < 32 @@ -502,7 +729,7 @@ void loop() { checkReceivedRawData(0x123456789ABC); # endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 32 bit PulseWidth 0x43D8613C MSB first")); + Serial.println(F("Send 32 bit PulseWidth 0x43D8613C MSB first 1=600|300, 0=300|300")); Serial.flush(); // Real PulseDistanceWidth (constant bit length) does not require a stop bit IrSender.sendPulseDistanceWidth(38, 1000, 500, 600, 300, 300, 300, 0x43D8613C, 32, PROTOCOL_IS_MSB_FIRST, 0, 0); @@ -510,7 +737,7 @@ void loop() { delay(DELAY_AFTER_SEND); # else // defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER) - Serial.println(F("Send generic 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first")); + Serial.println(F("Send 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first 1=550|1700, 0=550|600")); Serial.flush(); # if __INT_WIDTH__ < 32 tRawData[0] = 0x87654321; // LSB of tRawData[0] is sent first @@ -520,28 +747,105 @@ void loop() { NO_REPEATS); checkReceivedArray(tRawData, 3); # else - IRRawDataType tRawData[] = { 0xAFEDCBA987654321, 0x5A }; // LSB of tRawData[0] is sent first - IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, NO_REPEATS); + tRawData[0] = 0xAFEDCBA987654321; + tRawData[1] = 0x5A; // LSB of tRawData[0] is sent first + IrSender.sendPulseDistanceWidthFromArray(38, 8900, 4450, 550, 1700, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, 0, + NO_REPEATS); checkReceivedArray(tRawData, 2); # endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first")); + /* + * This one can be interpreted as 52 bit PulseDistance or 53 bit PulseWidth with inverted bits and bit timing. + Protocol=PulseWidth, Raw-Data=0x123456, 53 bits, LSB first, Gap=789450us, Duration=49100us + Send on a 8 bit platform with: + uint32_t tRawData[]={0x789ABCDE, 0x123456}; + IrSender.sendPulseDistanceWidthFromArray(38, 300, 650, 600, 450, 300, 450, &tRawData[0], 53, PROTOCOL_IS_LSB_FIRST, , ); + rawIRTimings[108]: + -789450 + + 300,- 650 + + 300,- 600 + 600,- 300 + 650,- 450 + 500,- 250 + + 600,- 300 + 300,- 650 + 650,- 250 + 600,- 350 + + 250,- 650 + 300,- 600 + 650,- 250 + 650,- 300 + + 600,- 350 + 550,- 300 + 350,- 550 + 650,- 300 + + 300,- 650 + 550,- 300 + 350,- 550 + 650,- 300 + + 600,- 300 + 350,- 550 + 300,- 600 + 650,- 350 + + 300,- 600 + 250,- 600 + 350,- 600 + 600,- 300 + + 650,- 300 + 600,- 250 + 600,- 300 + 350,- 600 + + 300,- 650 + 600,- 300 + 650,- 250 + 350,- 550 + + 550,- 350 + 300,- 650 + 600,- 300 + 300,- 600 + + 300,- 600 + 350,- 600 + 650,- 250 + 350,- 550 + + 650,- 300 + 650,- 250 + 300,- 600 + 350,- 550 + + 350,- 600 + 650,- 250 + 350,- 550 + 350,- 550 + + 650 + Duration=49100us + */ + Serial.println(F("Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first 1=300|600, 0=600|300")); Serial.flush(); - // Real PulseDistanceWidth (constant bit length) does not require a stop bit + // Real PulseDistanceWidth (constant bit length) does theoretically not require a stop bit, but we know the stop bit from serial transmission # if __INT_WIDTH__ < 32 tRawData[1] = 0xDCBA9; - IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, 0, 0); + IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 300, 600, 600, 300, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, 0, 0); checkReceivedArray(tRawData, 2); # else - IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0); + IrSender.sendPulseDistanceWidth(38, 300, 600, 300, 600, 600, 300, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0); checkReceivedRawData(0xDCBA987654321); # endif delay(DELAY_AFTER_SEND); - Serial.println(F("Send generic 32 bit PulseWidth 0x87654321 LSB first")); + Serial.println( + F( + "Send the same 52 bit PulseDistanceWidth but with inverse of 0xDCBA9 87654321 and with inverse timing 1=600|300, 0=300|600")); + Serial.flush(); +# if __INT_WIDTH__ < 32 + tRawData[2] = ~tRawData[0]; + tRawData[3] = ~tRawData[1]; + IrSender.sendPulseDistanceWidthFromArray(38, 300, 600, 600, 300, 300, 600, &tRawData[2], 52, PROTOCOL_IS_LSB_FIRST, 0, 0); + checkReceivedArray(tRawData, 2); +# else + IrSender.sendPulseDistanceWidth(38, 300, 600, 600, 300, 300, 600, ~0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, 0, 0); + checkReceivedRawData(0xDCBA987654321); +# endif + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send 7 bit ASCII character with PulseDistanceWidth LSB first 1=500|1500, 0=1500|500")); + Serial.flush(); + // Real PulseDistanceWidth (constant bit length) does theoretically not require a stop bit, but we know the stop bit from serial transmission + IrSender.sendPulseDistanceWidth(38, 6000, 500, 500, 1500, 1500, 500, sCommand, 7, PROTOCOL_IS_LSB_FIRST, 0, 0); + checkReceivedRawData(sCommand); + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send Velux 0x654321 decoded as PulseDistanceWidth 0x3D9EAC LSB first 1=1275|475, 0=475|1275")); + Serial.flush(); + IrSender.sendPulseDistanceWidth_P(&VeluxProtocolConstants, 0x654321, VELUX_BITS, 0); + /* + * We send 24 bit MSB first so bitreverse32Bit() >> 8 + * We send without header, so >> 1. + * We send as pulse width so we must invert result, which is decoded as pulse distance + */ + checkReceivedRawData((~(((bitreverse32Bit(0x654321)) >> 8) >> 1)) & 0x7FFFFF); +#if false + Serial.print(F("bitreverse32Bit(0x654321) >> 8 =0x")); + Serial.print(bitreverse32Bit(0x654321) >> 8, HEX); + Serial.print(F(" >> 1 =0x")); + Serial.print((bitreverse32Bit(0x654321) >> 8) >> 1, HEX); + Serial.print(F(" ~ =0x")); + Serial.println((~((bitreverse32Bit(0x654321) >> 8) >> 1)) & 0x7FFFFF, HEX); +#endif + + delay(DELAY_AFTER_SEND); + +# if defined(DECODE_SONY) + Serial.println(F("Send Sony12 as PulseWidth LSB first 1=1200|300, 0=600|600")); + Serial.flush(); + IrSender.sendPulseDistanceWidth(38, 2400, 600, 1200, 600, 600, 600, (sAddress << 7 | (sCommand & 0x7F)), SIRCS_12_PROTOCOL, + PROTOCOL_IS_LSB_FIRST, 0, 0); + checkReceive(sAddress & 0x1F, sCommand & 0x7F); + delay(DELAY_AFTER_SEND); +# endif + + Serial.println(F("Send 32 bit PulseWidth 0x87654321 LSB first 1=600|300, 0=300|300 - timing ratio is 1:2")); Serial.flush(); - // Real PulseDistanceWidth (constant bit length) does not require a stop bit IrSender.sendPulseDistanceWidth(38, 1000, 500, 600, 300, 300, 300, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, 0, 0); checkReceivedRawData(0x87654321); delay(DELAY_AFTER_SEND); @@ -549,33 +853,52 @@ void loop() { # endif // defined(DECODE_DISTANCE_WIDTH) # if defined(DECODE_MAGIQUEST) - Serial.println(F("Send MagiQuest 0x6BCDFF00, 0x176 as generic 55 bit PulseDistanceWidth MSB first")); + Serial.println(F("Send MagiQuest 0x6BCDFF00, 0x176 as 55 bit PulseDistanceWidth MSB first 1=576|576, 0=287|864")); Serial.flush(); # if __INT_WIDTH__ < 32 - tRawData[0] = 0x01AF37FC; // We have 1 header (start) bit and 7 start bits and 31 address bits for MagiQuest, so 0x6BCDFF00 is shifted 2 left - tRawData[1] = 0x017619; // We send only 23 instead of 24 bite here! 19 is the checksum - IrSender.sendPulseDistanceWidthFromArray(38, 287, 864, 576, 576, 287, 864, &tRawData[0], 55, PROTOCOL_IS_MSB_FIRST, 0, 0); + IRDecodedRawDataType tRawData1[2]; + tRawData1[0] = 0x01AF37FC; // We have 1 header (start) bit and 7 start bits and 31 address bits for MagiQuest, so 0x6BCDFF00 is shifted 2 left + tRawData1[1] = 0x017619; // We send only 23 bits here! 0x19 is the checksum + IrSender.sendPulseDistanceWidthFromArray(38, 287, 864, 576, 576, 287, 864, &tRawData1[0], 55, + PROTOCOL_IS_MSB_FIRST | SUPPRESS_STOP_BIT, 0, 0); # else // 0xD79BFE00 is 0x6BCDFF00 is shifted 1 left - IrSender.sendPulseDistanceWidth(38, 287, 864, 576, 576, 287, 864, 0xD79BFE017619, 55, PROTOCOL_IS_MSB_FIRST, 0, 0); + IrSender.sendPulseDistanceWidth(38, 287, 864, 576, 576, 287, 864, 0xD79BFE017619, 55, PROTOCOL_IS_MSB_FIRST | SUPPRESS_STOP_BIT, 0, 0); # endif checkReceive(0xFF00, 0x176); if (IrReceiver.decodedIRData.decodedRawData != 0x6BCDFF00) { Serial.print(F("ERROR: Received address=0x")); -#if (__INT_WIDTH__ < 32) +# if (__INT_WIDTH__ < 32) Serial.print(IrReceiver.decodedIRData.decodedRawData, HEX); -#else +# else PrintULL::print(&Serial, IrReceiver.decodedIRData.decodedRawData, HEX); -#endif +# endif Serial.println(F(" != sent address=0x6BCDFF00")); Serial.println(); } delay(DELAY_AFTER_SEND); # endif // defined(DECODE_MAGIQUEST) + } // end of once at first loop - } -#endif // if FLASHEND >= 0x3FFF +# if defined(DECODE_NEC) + Serial.println(F("Send NEC with TinyIRSender")); + Serial.flush(); + sendNEC(IR_SEND_PIN, (uint8_t) sAddress, sCommand, sRepeats); // Casting saves 18 bytes + checkReceive(sAddress & 0xFF, sCommand); + delay(DELAY_AFTER_SEND); +# endif + +# if defined(DECODE_FAST) + Serial.println(F("Send FAST with TinyIRSender")); + Serial.flush(); + sendFAST(IR_SEND_PIN, sCommand, sRepeats); + checkReceive(0, sCommand); + delay(DELAY_AFTER_SEND); +# endif + +#endif // if FLASHEND >= 0x7FFF +#if defined(DECODE_NEC) Serial.println(F("Send Onkyo (NEC with 16 bit command)")); Serial.flush(); IrSender.sendOnkyo(sAddress, (sCommand + 1) << 8 | sCommand, sRepeats); @@ -587,18 +910,21 @@ void loop() { IrSender.sendApple(sAddress & 0xFF, sCommand, sRepeats); checkReceive(sAddress & 0xFF, sCommand); delay(DELAY_AFTER_SEND); +#endif -#if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) +#if defined(DECODE_KASEIKYO) Serial.println(F("Send Panasonic")); Serial.flush(); IrSender.sendPanasonic(sAddress & 0xFFF, sCommand, sRepeats); checkReceive(sAddress & 0xFFF, sCommand); delay(DELAY_AFTER_SEND); - Serial.println(F("Send Kaseikyo with 0x4711 as Vendor ID")); + Serial.println(F("Send Kaseikyo with extra=0x4711 as Vendor ID")); Serial.flush(); IrSender.sendKaseikyo(sAddress & 0xFFF, sCommand, sRepeats, 0x4711); - checkReceive(sAddress & 0xFFF, sCommand); + if (checkReceive(sAddress & 0xFFF, sCommand)) { + checkReceivedExtra(0x4711); + } delay(DELAY_AFTER_SEND); Serial.println(F("Send Kaseikyo_Denon variant")); @@ -609,13 +935,13 @@ void loop() { #endif #if defined(DECODE_DENON) - Serial.println(F("Send Denon")); + Serial.println(F("Send Denon with 2 autorepeats after 45 ms")); // Only first frame is received! Serial.flush(); IrSender.sendDenon(sAddress & 0x1F, sCommand, sRepeats); checkReceive(sAddress & 0x1F, sCommand); delay(DELAY_AFTER_SEND); - Serial.println(F("Send Denon/Sharp variant")); + Serial.println(F("Send Denon/Sharp variant with 2 autorepeats after 45 ms")); Serial.flush(); IrSender.sendSharp(sAddress & 0x1F, sCommand, sRepeats); checkReceive(sAddress & 0x1F, sCommand); @@ -625,7 +951,7 @@ void loop() { #if defined(DECODE_SONY) Serial.println(F("Send Sony/SIRCS with 7 command and 5 address bits")); Serial.flush(); - IrSender.sendSony(sAddress & 0x1F, sCommand, sRepeats); + IrSender.sendSony(sAddress & 0x1F, sCommand, sRepeats); // SIRCS_12_PROTOCOL is default checkReceive(sAddress & 0x1F, sCommand & 0x7F); delay(DELAY_AFTER_SEND); @@ -635,23 +961,36 @@ void loop() { checkReceive(sAddress & 0xFF, sCommand & 0x7F); delay(DELAY_AFTER_SEND); +# if defined(DECODE_BEO) + // BEO sets RECORD_GAP_MICROS 16000 which leads to concatenating the Sony repeats + Serial.println(F("Send Sony/SIRCS with 7 command and 13 address bits and no repeats")); + Serial.flush(); + IrSender.sendSony(sAddress & 0x1FFF, sCommand, 0, SIRCS_20_PROTOCOL); +# else Serial.println(F("Send Sony/SIRCS with 7 command and 13 address bits")); Serial.flush(); IrSender.sendSony(sAddress & 0x1FFF, sCommand, sRepeats, SIRCS_20_PROTOCOL); +# endif checkReceive(sAddress & 0x1FFF, sCommand & 0x7F); delay(DELAY_AFTER_SEND); #endif #if defined(DECODE_SAMSUNG) - Serial.println(F("Send Samsung 8 bit command")); + Serial.println(F("Send Samsung 8 bit command and 8 bit address")); + Serial.flush(); + IrSender.sendSamsung(sAddress & 0xFF, sCommand, sRepeats); + checkReceive(sAddress & 0xFF, sCommand); + delay(DELAY_AFTER_SEND); + + Serial.println(F("Send Samsung 8 bit command and 16 bit address")); Serial.flush(); - IrSender.sendSamsung(sAddress, sCommand, sRepeats); + IrSender.sendSamsung16BitAddressAnd8BitCommand(sAddress, sCommand, sRepeats); checkReceive(sAddress, sCommand); delay(DELAY_AFTER_SEND); - Serial.println(F("Send Samsung 16 bit command")); + Serial.println(F("Send Samsung 16 bit command and address")); Serial.flush(); - IrSender.sendSamsung(sAddress, s16BitCommand, sRepeats); + IrSender.sendSamsung16BitAddressAndCommand(sAddress, s16BitCommand, sRepeats); checkReceive(sAddress, s16BitCommand); delay(DELAY_AFTER_SEND); @@ -662,6 +1001,10 @@ void loop() { delay(DELAY_AFTER_SEND); #endif +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) || defined(DECODE_RC6) + IrSender.setNextToggleBitValueForRC5AndRC6(sCommand); // To modify start value of toggling for each loop. Only LSB is taken :-). +#endif + #if defined(DECODE_RC5) Serial.println(F("Send RC5")); Serial.flush(); @@ -676,13 +1019,106 @@ void loop() { delay(DELAY_AFTER_SEND); #endif +#if defined(DECODE_MARANTZ) + Serial.print(F("Send Marantz with RC5 and extra=0x")); + Serial.println(~sCommand & 0x3F, HEX); + Serial.flush(); + IrSender.sendRC5Marantz(sAddress & 0x1F, sCommand & 0x3F, sRepeats, ~sCommand & 0x3F, true); // 5 address, 6 command bits + if (checkReceive(sAddress & 0x1F, sCommand & 0x3F)) { + checkReceivedExtra(~sCommand & 0x3F); + } + delay(DELAY_AFTER_SEND); + + Serial.print(F("Send Marantz with RC5A and extra=0x")); + Serial.println(~sCommand & 0x3F, HEX); + Serial.flush(); + IrSender.sendRC5Marantz(sAddress & 0x1F, (sCommand & 0x3F) + 0x40, sRepeats, ~sCommand & 0x3F, true); // 5 address, 7 command bits + if (checkReceive(sAddress & 0x1F, (sCommand & 0x3F) + 0x40)) { + checkReceivedExtra(~sCommand & 0x3F); + } + delay(DELAY_AFTER_SEND); +#endif + #if defined(DECODE_RC6) Serial.println(F("Send RC6")); - // RC6 check does not work stable without the flush Serial.flush(); + IrSender.sendRC6(sAddress & 0xFF, sCommand, sRepeats, true); checkReceive(sAddress & 0xFF, sCommand); delay(DELAY_AFTER_SEND); + + Serial.println(F("Send RC6A with 14 bit and extra=0x2711")); + Serial.flush(); + IrSender.sendRC6A(sAddress & 0xFF, sCommand, sRepeats, 0x2711, true); + if (checkReceive(sAddress & 0xFF, sCommand)) { + checkReceivedExtra(0x2711); + } + delay(DELAY_AFTER_SEND); +#endif + +#if defined(DECODE_MAGIQUEST) + uint32_t tWandId = 0x6BCD0000 | (uint32_t) sAddress; + Serial.print(F("Send MagiQuest, WandId=0x")); + Serial.println(tWandId, HEX); + Serial.flush(); + IrSender.sendMagiQuest(tWandId, s16BitCommand); // we have 31 bit address + if (checkReceive(sAddress, s16BitCommand & 0x1FF)) { // we have 9 bit command + checkReceivedExtra(0x6BCD); + } + delay(DELAY_AFTER_SEND); +#endif + +#if defined(DECODE_OPENLASIR) + Serial.println(F("Send OpenLASIR mode fire and color orange, detected as ONKYO")); + Serial.flush(); + IrSender.sendOpenLASIR(sAddress & 0xFF, sCommand, OPENLASIR_MODE_LASER_TAG_FIRE, OPENLASIR_COLOR_ORANGE, sRepeats); + checkReceive(sAddress & 0xFF, + IrSender.computeOpenLASIRRawCommand(sCommand, OPENLASIR_MODE_LASER_TAG_FIRE, OPENLASIR_COLOR_ORANGE)); + delay(DELAY_AFTER_SEND); +#endif + +#if defined(DECODE_LEGO_PF) + Serial.println(F("Send Lego with 2 channel and with 4 command bits")); + Serial.flush(); + IrSender.sendLegoPowerFunctions(sAddress, sCommand, LEGO_MODE_COMBO, false); + checkReceive(sAddress & 0x0F, (sCommand | (LEGO_MODE_COMBO << LEGO_COMMAND_BITS)) & 0x1F); + delay(DELAY_AFTER_SEND); +#endif + +#if defined(DECODE_BEO) + Serial.println(F("Send 16 bit Bang&Olufsen - requires originally 455 kHz")); + Serial.flush(); + IrSender.sendBangOlufsen(sAddress, sCommand, sRepeats, 8); // send 8 bit command and 8 bit address / header +# if defined(ENABLE_BEO_WITHOUT_FRAME_GAP) + delay((RECORD_GAP_MICROS / 1000) + 1); + Serial.println(F("- ENABLE_BEO_WITHOUT_FRAME_GAP is enabled")); + IrReceiver.printIRResultRawFormatted(&Serial, true); + Serial.println(F("- Now try to decode the first 6 entries, which results in rawData 0x0")); + uint8_t tOriginalRawlen = IrReceiver.irparams.rawlen; + IrReceiver.decodedIRData.rawlen = 6; + IrReceiver.irparams.rawlen = 6; + /* + * decode first part / AGC part of frame + */ + IrReceiver.decode(); + IrReceiver.printIRResultShort(&Serial); // -> Protocol=Bang&Olufsen Address=0x0 Command=0x0 Raw-Data=0x0 0 bits MSB first + + if (tOriginalRawlen > 30) { + // Remove trailing 6 entries for second decode try + Serial.println(); + Serial.println( + F( + "- Remove trailing 6 entries, which is equivalent to define RECORD_GAP_MICROS < 15000, to enable successful B&O decode")); + IrReceiver.decodedIRData.rawlen = tOriginalRawlen - 6; + IrReceiver.irparams.rawlen = tOriginalRawlen - 6; + for (uint_fast8_t i = 0; i < IrReceiver.decodedIRData.rawlen; ++i) { + IrReceiver.irparams.rawbuf[i] = IrReceiver.irparams.rawbuf[i + 6]; + } + IrReceiver.decodedIRData.initialGapTicks = IrReceiver.irparams.rawbuf[0]; + checkReceive(sAddress & 0xFF, sCommand); // only 8 bit of address is sent + } +# endif + delay(DELAY_AFTER_SEND); #endif /* @@ -694,6 +1130,10 @@ void loop() { IRSendData.command = sCommand; IRSendData.flags = IRDATA_FLAGS_EMPTY; + Serial.println(F("Send next protocols with IrSender.write")); + Serial.println(); + Serial.flush(); + #if defined(DECODE_JVC) IRSendData.protocol = JVC; // switch protocol Serial.print(F("Send ")); @@ -708,57 +1148,16 @@ void loop() { IRSendData.command = s16BitCommand; // LG support more than 8 bit command #endif -#if defined(DECODE_SAMSUNG) - IRSendData.protocol = SAMSUNG; - Serial.print(F("Send ")); - Serial.println(getProtocolString(IRSendData.protocol)); - Serial.flush(); - IrSender.write(&IRSendData, sRepeats); - checkReceive(IRSendData.address, IRSendData.command); - delay(DELAY_AFTER_SEND); -#endif - #if defined(DECODE_LG) IRSendData.protocol = LG; Serial.print(F("Send ")); Serial.println(getProtocolString(IRSendData.protocol)); Serial.flush(); - IrSender.write(&IRSendData, sRepeats); + IrSender.write(&IRSendData, 0); checkReceive(IRSendData.address & 0xFF, IRSendData.command); delay(DELAY_AFTER_SEND); #endif -#if defined(DECODE_MAGIQUEST) - Serial.println(F("Send MagiQuest")); - Serial.flush(); - IrSender.sendMagiQuest(0x6BCD0000 | (uint32_t) sAddress, s16BitCommand); // we have 31 bit address - checkReceive(sAddress, s16BitCommand & 0x1FF); // we have 9 bit command - delay(DELAY_AFTER_SEND); -#endif - -#if defined(DECODE_BEO) - Serial.println(F("Send Bang&Olufsen")); - Serial.flush(); - IrSender.sendBangOlufsen(sAddress & 0x0FF, sCommand, sRepeats); -# if defined(ENABLE_BEO_WITHOUT_FRAME_GAP) - delay((RECORD_GAP_MICROS / 1000) + 1); - IrReceiver.printIRResultRawFormatted(&Serial, true); - uint8_t tOriginalRawlen = IrReceiver.decodedIRData.rawDataPtr->rawlen; - IrReceiver.decodedIRData.rawDataPtr->rawlen = 6; - // decode first part of frame - IrReceiver.decode(); - IrReceiver.printIRResultShort(&Serial); - - // Remove trailing 6 entries for next decode - IrReceiver.decodedIRData.rawDataPtr->rawlen = tOriginalRawlen - 6; - for (uint_fast8_t i = 0; i < IrReceiver.decodedIRData.rawDataPtr->rawlen; ++i) { - IrReceiver.decodedIRData.rawDataPtr->rawbuf[i] = IrReceiver.decodedIRData.rawDataPtr->rawbuf[i + 6]; - } -# endif - checkReceive(sAddress & 0x0FF, sCommand); - delay(DELAY_AFTER_SEND); -#endif - #if defined(DECODE_BOSEWAVE) IRSendData.protocol = BOSEWAVE; Serial.println(F("Send Bosewave with no address and 8 command bits")); @@ -778,25 +1177,19 @@ void loop() { delay(DELAY_AFTER_SEND); #endif - /* - * LEGO is skipped, since it is difficult to receive because of its short marks and spaces - */ -// Serial.println(F("Send Lego with 2 channel and with 4 command bits")); -// Serial.flush(); -// IrSender.sendLegoPowerFunctions(sAddress, sCommand, LEGO_MODE_COMBO, true); -// checkReceive(sAddress, sCommand); // never has success for Lego protocol :-( -// delay(DELAY_AFTER_SEND); /* * Force buffer overflow */ - Serial.println(F("Force buffer overflow by sending 280 marks and spaces")); - for (unsigned int i = 0; i < 140; ++i) { - // 400 + 400 should be received as 8/8 and sometimes as 9/7 or 7/9 if compensation by MARK_EXCESS_MICROS is optimal. + Serial.println(F("Force buffer overflow by sending 450 marks and spaces")); + for (unsigned int i = 0; i < 225; ++i) { // 225 because we send 2 entries per loop // 210 + 540 = 750 should be received as 5/10 or 4/11 if compensation by MARK_EXCESS_MICROS is optimal. + // 400 + 400 should be received as 8/8 and sometimes as 9/7 or 7/9 if compensation by MARK_EXCESS_MICROS is optimal. IrSender.mark(210); // 8 pulses at 38 kHz IrSender.space(540); // to fill up to 750 us } - checkReceive(sAddress, sCommand); + waitForReceived(); + IrReceiver.printIRResultRawFormatted(&Serial, true); + IrReceiver.resume(); delay(DELAY_AFTER_SEND); /* @@ -806,7 +1199,22 @@ void loop() { sAddress += 0x0101; sCommand += 0x11; s16BitCommand += 0x1111; + sRepeats++; + // clip repeats at 4 + if (sRepeats > 4) { + sRepeats = 4; + } + Serial.println(F("Invert toggle value for next loop")); + sLastSendToggleValue = !sLastSendToggleValue; + + /* + * Test stop and start of 50 us receiver timer + */ + Serial.println(F("Stop receiver")); + IrReceiver.stop(); delay(DELAY_AFTER_LOOP); // additional delay at the end of each loop + Serial.println(F("Start receiver")); + IrReceiver.start(); // For ESP32 timerEnableReceiveInterrupt() is sufficient here, since timer is not reconfigured by another task } diff --git a/examples/UnitTest/UnitTest.log b/examples/UnitTest/UnitTest.log index da30c2188..4582eee2e 100644 --- a/examples/UnitTest/UnitTest.log +++ b/examples/UnitTest/UnitTest.log @@ -1,751 +1,1690 @@ -START ../src/UnitTest.cpp from Feb 22 2023 -Using library version 4.1.0 -Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, Bang & Olufsen, FAST, Bosewave , MagiQuest, Universal Pulse Distance Width, Hash at pin 2 +START ../src/UnitTest.cpp from Feb 20 2026 +Using library version 4.6.0 +Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, Bang & Olufsen, FAST, Lego Power Functions, Bosewave, MagiQuest, OpenLASIR, Universal Pulse Distance Width, Hash at pin 2 +Use ReceiveCompleteCallback +Receive buffer length is 400 Send IR signals at pin 3 If you connect debug pin 5 to ground, raw data is always printed Send signal mark duration for 38kHz is 8 us, pulse narrowing correction is 3000 ns, total period is 26 us 16000 us is the (minimum) gap, after which the start of a new IR packet is assumed -20 us are subtracted from all marks and added to all spaces for decoding +40 us are subtracted from all marks and added to all spaces for decoding address=0xFFF1 command=0x76 Send NEC with 8 bit address -Protocol=NEC Address=0xF1 Command=0x76 Raw-Data=0x89760EF1 32 bits LSB first +Protocol=NEC Address=0xF1, Command=0x76, Raw-Data=0x89760EF1, 32 bits, LSB first, Gap=754900us, Duration=68000us Send with: IrSender.sendNEC(0xF1, 0x76, ); -rawData[68]: - -1044300 - +8950,-4400 - + 600,-1650 + 600,- 500 + 600,- 550 + 600,- 500 +rawIRTimings[68]: + -754900 + +8900,-4450 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + 600,-1600 + 600,-1650 + 600,-1650 - + 550,- 550 + 600,-1650 + 600,-1650 + 550,-1650 - + 600,- 550 + 550,- 550 + 600,- 550 + 550,- 600 - + 550,- 550 + 550,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 550,- 600 + 550,- 550 + 600,-1800 - + 450,- 500 + 600,- 550 + 550,- 550 + 600,-1650 - + 550 -Sum: 67650 + + 600,- 550 + 600,-1650 + 650,-1600 + 600,-1600 + + 600,- 550 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,- 550 + 650,-1600 + 600,-1600 + 650,- 500 + + 650,-1600 + 650,-1600 + 650,-1600 + 600,- 500 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,- 500 + 600,- 550 + 600,-1650 + + 650 +Duration=68000us + Send NEC with 16 bit address -Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first +Protocol=NEC Address=0xFFF1, Command=0x76, Raw-Data=0x8976FFF1, 32 bits, LSB first, Gap=764800us, Duration=73450us Send with: IrSender.sendNEC(0xFFF1, 0x76, ); -rawData[68]: - -1055100 - +8850,-4450 - + 600,-1650 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,-1650 - + 550,-1650 + 600,-1650 + 550,-1700 + 550,-1650 - + 550,- 600 + 550,-1650 + 600,-1650 + 600,- 550 - + 550,-1650 + 600,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,- 550 + 550,- 550 + 600,-1650 - + 600,- 500 + 550,- 600 + 600,- 500 + 600,-1650 - + 550 -Sum: 73150 +rawIRTimings[68]: + -764800 + +8900,-4450 + + 600,-1600 + 600,- 550 + 600,- 550 + 600,- 500 + + 650,-1600 + 650,-1600 + 600,-1650 + 650,-1550 + + 650,-1600 + 650,-1600 + 600,-1650 + 650,-1600 + + 600,-1600 + 650,-1600 + 650,-1600 + 650,-1600 + + 650,- 450 + 650,-1600 + 650,-1600 + 650,- 500 + + 600,-1600 + 650,-1600 + 650,-1600 + 600,- 550 + + 600,-1650 + 600,- 500 + 600,- 550 + 650,-1600 + + 650,- 450 + 650,- 500 + 650,- 500 + 650,-1600 + + 600 +Duration=73450us + Send NEC2 with 16 bit address -Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first +Protocol=NEC Address=0xFFF1, Command=0x76, Raw-Data=0x8976FFF1, 32 bits, LSB first, Gap=765250us, Duration=73450us Send with: IrSender.sendNEC(0xFFF1, 0x76, ); -rawData[68]: - -1055500 - +8950,-4400 - + 650,-1600 + 600,- 500 + 650,- 500 + 600,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 600,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 600,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 650,-1600 - + 600,- 500 + 650,-1600 + 650,-1600 + 600,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 650,- 450 - + 650,-1600 + 650,- 500 + 600,- 500 + 600,-1650 - + 650,- 500 + 600,- 500 + 650,- 500 + 600,-1600 +rawIRTimings[68]: + -765250 + +8900,-4450 + + 600,-1650 + 650,- 450 + 650,- 500 + 650,- 450 + + 650,-1600 + 600,-1650 + 650,-1600 + 650,-1550 + + 650,-1600 + 600,-1650 + 650,-1600 + 650,-1600 + + 600,-1600 + 650,-1600 + 650,-1600 + 600,-1650 + + 600,- 500 + 650,-1600 + 600,-1650 + 650,- 450 + + 650,-1600 + 650,-1600 + 600,-1650 + 650,- 450 + + 650,-1600 + 650,- 500 + 650,- 500 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1600 + 650 -Sum: 73400 +Duration=73450us + + +Send RC5 minimal length +Protocol=RC5 Address=0xA, Command=0x6A, Toggle=1, Raw-Data=0xAAA, 13 bits, MSB first, Gap=765600us, Duration=23100us +Send with: IrSender.sendRC5(0xA, 0x6A, ); +rawIRTimings[14]: + -765600 + +1850,-1700 + +1850,-1700 +1850,-1700 +1850,-1700 +1850,-1700 + +1800,-1750 +1800 +Duration=23100us + -Send NEC Pronto data with 8 bit address 0x80 and command 0x45 and no repeats -Protocol=NEC Address=0x80 Command=0x45 Raw-Data=0xBA457F80 32 bits LSB first +Send RC5 maximal length +Protocol=RC5 Address=0x1F, Command=0x3F, Toggle=1, Raw-Data=0x1FFF, 13 bits, MSB first, Gap=391600us, Duration=24200us +Send with: IrSender.sendRC5(0x1F, 0x3F, ); +rawIRTimings[28]: + -391600 + + 900,- 900 + + 950,- 800 +1000,- 800 + 900,- 900 + 950,- 850 + + 900,- 850 + 950,- 850 + 900,- 900 + 900,- 900 + + 900,- 900 + 900,- 900 + 900,- 900 + 950,- 850 + + 900 +Duration=24200us + + +Send Marantz maximal length +Protocol=Marantz Address=0x1F, Command=0x3F, Extra=0x3F, Toggle=1, Raw-Data=0x7FFFF, 19 bits, MSB first, Gap=398900us, Duration=38350us +Send with: IrSender.sendMarantz(0x1F, 0x3F, , 0x3F); +rawIRTimings[40]: + -398900 + + 950,- 850 + + 850,- 950 + 900,- 900 + 950,- 850 + 950,- 800 + +1000,- 800 + 900,- 900 + 950,-4350 + 950,- 850 + + 950,- 800 +1000,- 800 + 850,- 950 + 950,- 850 + + 900,- 850 + 950,- 850 + 950,- 850 + 950,- 800 + +1000,- 800 + 950,- 850 + 850 +Duration=38350us + + +Send RC6 minimal length +Protocol=RC6 Address=0x55, Command=0x55, Toggle=1, Raw-Data=0x15555, 20 bits, MSB first, Gap=744250us, Duration=23100us +Send with: IrSender.sendRC6(0x55, 0x55, ); +rawIRTimings[26]: + -744250 + +2750,- 800 + + 550,- 800 + 500,- 400 + 500,- 450 +1400,-1250 + +1000,- 800 + 950,- 900 + 950,- 850 +1000,- 800 + + 950,- 850 + 950,- 900 +1000,- 800 +1000 +Duration=23100us + + +Send RC6A maximal length +Protocol=RC6A Address=0xFF, Command=0xFF, Extra=0x3FFF, Raw-Data=0x7FFFFFFF, 35 bits, MSB first, Gap=397100us, Duration=36850us +Send with: IrSender.sendRC6A(0xFF, 0xFF, , 0x3FFF); +rawIRTimings[72]: + -397100 + +2650,- 900 + + 550,- 400 + 400,- 500 + 500,- 850 + 500,- 850 + +1450,- 350 + 550,- 400 + 400,- 500 + 450,- 450 + + 500,- 400 + 550,- 400 + 400,- 500 + 450,- 450 + + 550,- 350 + 550,- 400 + 500,- 400 + 450,- 450 + + 500,- 400 + 500,- 450 + 400,- 500 + 450,- 450 + + 500,- 400 + 500,- 400 + 450,- 500 + 450,- 450 + + 500,- 400 + 550,- 350 + 450,- 500 + 450,- 450 + + 500,- 400 + 500,- 450 + 400,- 500 + 450,- 450 + + 450,- 450 + 550,- 350 + 500 +Duration=36850us + + +Send arbitrary raw data with 1 repeat and exact timing (16 bit array format) with sendRaw() +rawIRTimings[18]: + -770450 + +8950,-4400 + + 600,- 950 +1050,- 450 + 550,-1950 +2050,- 450 + + 600,-2900 +3000,- 450 + 600,- 100 + 400 +Duration=29450us + +Send NEC data with 8 bit address 0x80 and command 0x45 and no repeats with sendPronto() +Protocol=NEC Address=0x80, Command=0x45, Raw-Data=0xBA457F80, 32 bits, LSB first, Gap=713750us, Duration=68500us Send with: IrSender.sendNEC(0x80, 0x45, ); -rawData[68]: - -1064450 - +9050,-4450 - + 550,- 550 + 600,- 550 + 600,- 600 + 550,- 600 - + 600,- 550 + 600,- 550 + 600,- 550 + 600,-1600 - + 650,-1600 + 600,-1600 + 600,-1650 + 550,-1600 - + 600,-1600 + 600,-1600 + 600,-1600 + 650,- 500 - + 650,-1550 + 600,- 550 + 600,-1600 + 600,- 550 - + 600,- 550 + 600,- 550 + 600,-1600 + 600,- 550 - + 650,- 500 + 650,-1550 + 600,- 550 + 600,-1600 - + 600,-1600 + 600,-1650 + 600,- 550 + 600,-1650 - + 550 -Sum: 67800 +rawIRTimings[68]: + -713750 + +9100,-4350 + + 700,- 500 + 650,- 500 + 650,- 550 + 600,- 550 + + 650,- 550 + 700,- 450 + 650,- 500 + 650,-1600 + + 650,-1600 + 650,-1550 + 700,-1550 + 650,-1550 + + 700,-1500 + 700,-1550 + 700,-1550 + 650,- 500 + + 700,-1500 + 700,- 500 + 650,-1600 + 650,- 500 + + 650,- 500 + 700,- 450 + 650,-1600 + 650,- 550 + + 700,- 450 + 750,-1450 + 700,- 450 + 700,-1550 + + 650,-1600 + 700,-1550 + 650,- 500 + 700,-1500 + + 700 +Duration=68500us + -Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format) -Protocol=NEC Address=0x4 Command=0x8 Raw-Data=0xF708FB04 32 bits LSB first +Send NEC data with 8 bit address=0xFB04, command 0x08, 1 repeat and exact timing (16 bit array format) with sendRaw_P() +Protocol=NEC Address=0x4, Command=0x8, Raw-Data=0xF708FB04, 32 bits, LSB first, Gap=772450us, Duration=68100us Send with: IrSender.sendNEC(0x4, 0x8, ); -rawData[68]: - -1061400 - +9000,-4400 - + 600,- 500 + 650,- 500 + 600,-1650 + 600,- 500 - + 650,- 500 + 600,- 550 + 600,- 500 + 600,- 550 - + 600,-1650 + 600,-1650 + 600,- 500 + 600,-1650 - + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 - + 600,- 500 + 600,- 550 + 600,- 500 + 600,-1650 - + 600,- 500 + 600,- 550 + 600,- 500 + 600,- 550 +rawIRTimings[68]: + -772450 + +8950,-4450 + + 650,- 450 + 600,- 550 + 650,-1600 + 600,- 500 + + 650,- 500 + 600,- 550 + 650,- 450 + 600,- 550 + + 650,-1600 + 650,-1600 + 600,- 500 + 600,-1650 + + 650,-1600 + 650,-1600 + 650,-1600 + 650,-1600 + + 650,- 500 + 650,- 500 + 600,- 500 + 600,-1650 + + 600,- 550 + 650,- 500 + 600,- 500 + 600,- 550 + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,-1650 + 600,-1650 + 550,-1650 + + 650,-1600 + 650,-1600 + 650,-1600 + 650,-1650 + 600 -Sum: 67900 +Duration=68100us + Send ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102) -Protocol=Onkyo Address=0x102 Command=0x304 Raw-Data=0x3040102 32 bits LSB first +Protocol=Onkyo Address=0x102, Command=0x304, Raw-Data=0x3040102, 32 bits, LSB first, Gap=749650us, Duration=55650us Send with: IrSender.sendOnkyo(0x102, 0x304, ); -rawData[68]: - -1059700 - +8900,-4400 - + 600,- 550 + 600,-1600 + 600,- 550 + 600,- 500 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,-1650 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,- 550 - + 550,- 550 + 600,- 500 + 600,-1650 + 600,- 500 - + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 500 - + 600,-1650 + 600,-1600 + 600,- 550 + 600,- 500 - + 650,- 500 + 600,- 550 + 550,- 550 + 600,- 500 +rawIRTimings[68]: + -749650 + +8950,-4400 + + 650,- 500 + 600,-1650 + 600,- 500 + 600,- 550 + + 650,- 450 + 650,- 500 + 650,- 450 + 650,- 500 + + 600,-1650 + 600,- 500 + 650,- 500 + 650,- 450 + + 650,- 500 + 600,- 500 + 600,- 550 + 600,- 500 + + 650,- 500 + 600,- 500 + 650,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,- 500 + + 650,-1600 + 600,-1600 + 650,- 500 + 600,- 550 + + 600,- 500 + 600,- 550 + 650,- 500 + 600,- 500 + 650 -Sum: 55450 +Duration=55650us + Send ONKYO with 16 bit address 0x0102 and command 0x34 with old 32 bit format MSB first (0x40802CD3) -Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first +Protocol=NEC Address=0x102, Command=0x34, Raw-Data=0xCB340102, 32 bits, LSB first, Gap=771400us, Duration=61300us Send with: IrSender.sendNEC(0x102, 0x34, ); -rawData[68]: - -1061500 +rawIRTimings[68]: + -771400 +8950,-4400 - + 600,- 500 + 550,-1700 + 600,- 500 + 650,- 500 - + 600,- 500 + 650,- 500 + 550,- 550 + 650,- 500 - + 600,-1650 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,- 550 + 600,- 500 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,-1650 + 600,- 500 + 600,- 550 - + 600,-1600 + 550,-1700 + 600,- 550 + 600,-1600 - + 600,- 550 + 600,- 500 + 650,-1600 + 600,-1650 - + 550 -Sum: 61000 + + 600,- 550 + 600,-1600 + 650,- 500 + 650,- 500 + + 650,- 450 + 600,- 550 + 600,- 550 + 650,- 450 + + 600,-1650 + 650,- 500 + 600,- 500 + 600,- 550 + + 600,- 500 + 600,- 550 + 650,- 500 + 650,- 450 + + 600,- 550 + 600,- 500 + 700,-1550 + 650,- 500 + + 600,-1650 + 600,-1600 + 650,- 500 + 600,- 550 + + 600,-1600 + 600,-1650 + 600,- 550 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,-1650 + 600,-1650 + + 650 +Duration=61300us + -Send Panasonic 0xB, 0x10 as 48 bit generic PulseDistance using ProtocolConstants -Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first +Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM using ProtocolConstants 1=432|1296, 0=432|432 +Protocol=Panasonic Address=0xB, Command=0x10, Raw-Data=0xA01000B0, 48 bits, LSB first, Gap=770800us, Duration=55050us Send with: IrSender.sendPanasonic(0xB, 0x10, ); -rawData[100]: - -1059500 - +3450,-1700 - + 450,- 450 + 450,-1250 + 450,- 400 + 450,- 450 - + 450,- 400 + 450,- 400 + 450,- 450 + 400,- 450 - + 450,- 400 + 450,- 450 + 400,- 450 + 450,- 400 - + 450,- 450 + 400,-1300 + 450,- 400 + 450,- 450 - + 400,- 450 + 450,- 400 + 450,- 450 + 400,- 450 - + 450,-1300 + 400,-1300 + 450,- 400 + 450,-1300 - + 450,- 400 + 450,- 450 + 450,- 400 + 450,- 400 - + 450,- 450 + 400,- 450 + 450,- 400 + 450,- 450 - + 450,- 400 + 450,- 450 + 400,- 450 + 450,- 400 - + 450,-1300 + 400,- 450 + 450,- 450 + 400,- 450 - + 450,- 400 + 450,- 450 + 400,- 450 + 450,- 400 - + 450,- 450 + 400,-1300 + 450,- 400 + 450,-1300 - + 450 -Sum: 54100 - -Send Panasonic 0xB, 0x10 as generic 48 bit PulseDistance - LSB first -Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first +rawIRTimings[100]: + -770800 + +3550,-1650 + + 450,- 450 + 500,-1200 + 500,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 500,- 350 + 450,- 450 + + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 400 + + 500,- 400 + 500,-1200 + 450,- 450 + 500,- 400 + + 500,- 350 + 500,- 400 + 450,- 400 + 500,- 400 + + 500,-1250 + 450,-1300 + 450,- 450 + 400,-1300 + + 450,- 450 + 500,- 400 + 500,- 400 + 400,- 450 + + 500,- 400 + 450,- 450 + 500,- 350 + 500,- 450 + + 450,- 400 + 500,- 400 + 450,- 400 + 500,- 400 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 400 + + 500,- 400 + 450,- 400 + 550,- 350 + 500,- 400 + + 500,- 400 + 400,-1300 + 500,- 400 + 450,-1300 + + 500 +Duration=55050us + + +Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM 1=450|1250, 0=450|400 +-LSB first +Protocol=Panasonic Address=0xB, Command=0x10, Raw-Data=0xA01000B0, 48 bits, LSB first, Gap=787500us, Duration=54050us Send with: IrSender.sendPanasonic(0xB, 0x10, ); -rawData[100]: - -1076450 +rawIRTimings[100]: + -787500 +3450,-1700 - + 450,- 400 + 450,-1250 + 450,- 400 + 450,- 400 - + 450,- 400 + 400,- 450 + 400,- 450 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,-1250 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,-1250 + 450,-1250 + 450,- 400 + 450,-1250 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 350 - + 500,- 400 + 400,- 450 + 450,- 350 + 500,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,-1250 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,-1200 + 500,- 400 + 450,-1300 - + 400 -Sum: 53200 + + 550,- 350 + 450,-1200 + 550,- 350 + 500,- 350 + + 500,- 400 + 500,- 350 + 550,- 300 + 500,- 400 + + 500,- 350 + 550,- 350 + 500,- 350 + 500,- 350 + + 500,- 400 + 450,-1200 + 550,- 350 + 500,- 350 + + 550,- 350 + 500,- 350 + 500,- 350 + 500,- 350 + + 500,-1250 + 550,-1150 + 500,- 400 + 500,-1200 + + 550,- 300 + 500,- 400 + 500,- 350 + 500,- 350 + + 550,- 300 + 550,- 350 + 500,- 350 + 550,- 350 + + 500,- 350 + 550,- 350 + 500,- 350 + 550,- 300 + + 500,-1200 + 500,- 400 + 500,- 350 + 550,- 350 + + 450,- 400 + 550,- 300 + 500,- 350 + 550,- 350 + + 500,- 350 + 500,-1200 + 500,- 400 + 500,-1200 + + 500 +Duration=54050us + - MSB first -Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B0 48 bits LSB first +-MSB first +Protocol=Panasonic Address=0xB, Command=0x10, Raw-Data=0xA01000B0, 48 bits, LSB first, Gap=780200us, Duration=54050us Send with: IrSender.sendPanasonic(0xB, 0x10, ); -rawData[100]: - -1070700 - +3400,-1700 - + 450,- 400 + 450,-1250 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,-1250 + 450,- 400 + 450,- 400 - + 400,- 450 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,-1250 + 400,-1300 + 450,- 400 + 450,-1300 - + 400,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 400 - + 450,- 400 + 450,- 400 + 450,- 400 + 450,- 550 - + 250,-1300 + 450,- 450 + 400,- 400 + 450,- 400 - + 450,- 400 + 400,- 450 + 400,- 450 + 450,- 400 - + 450,- 400 + 450,-1250 + 450,- 400 + 450,-1250 - + 450 -Sum: 53150 - -Send generic 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first -Protocol=PulseDistance Raw-Data=0x5A 72 bits LSB first -Send with: - uint32_t tRawData[]={0x87654321, 0xAFEDCBA9, 0x5A}; - IrSender.sendPulseDistanceWidthFromArray(38, 8850, 4400, 550, 1650, 550, 600, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, , ); -rawData[148]: - -1076300 +rawIRTimings[100]: + -780200 + +3500,-1650 + + 550,- 350 + 500,-1200 + 500,- 350 + 550,- 350 + + 500,- 350 + 550,- 350 + 500,- 350 + 500,- 350 + + 550,- 350 + 550,- 300 + 500,- 350 + 550,- 350 + + 550,- 300 + 500,-1200 + 550,- 350 + 450,- 400 + + 500,- 350 + 550,- 300 + 550,- 350 + 500,- 350 + + 550,-1150 + 550,-1150 + 550,- 350 + 450,-1250 + + 500,- 350 + 500,- 400 + 550,- 300 + 500,- 350 + + 550,- 300 + 550,- 350 + 500,- 350 + 500,- 400 + + 500,- 350 + 550,- 350 + 500,- 350 + 500,- 350 + + 550,-1150 + 600,- 300 + 500,- 350 + 500,- 400 + + 450,- 400 + 500,- 350 + 500,- 400 + 500,- 350 + + 500,- 350 + 500,-1200 + 550,- 300 + 550,-1200 + + 500 +Duration=54050us + + +Send 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first 1=550|1700, 0=550|600 +Protocol=PulseDistance, Raw-Data=0x5A, 72 bits, LSB first, Gap=787050us, Duration=139000us +Send on a 8 bit platform with: + uint32_t tRawData[]={0x87654321, 0xAFEDCBA9, 0x5A}; + IrSender.sendPulseDistanceWidthFromArray(38, 8850, 4400, 650, 1600, 650, 500, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[148]: + -787050 +8850,-4400 - + 600,-1650 + 550,- 600 + 550,- 600 + 550,- 600 - + 550,- 600 + 550,-1650 + 550,- 650 + 550,- 600 - + 550,-1700 + 550,-1650 + 600,- 600 + 550,- 600 - + 550,- 600 + 500,- 650 + 550,-1650 + 600,- 600 - + 550,-1650 + 600,- 600 + 550,-1650 + 550,- 650 - + 550,- 600 + 550,-1650 + 550,-1700 + 550,- 600 - + 550,-1700 + 550,-1700 + 550,-1650 + 550,- 650 - + 550,- 600 + 550,- 600 + 550,- 600 + 550,-1700 - + 550,-1700 + 550,- 600 + 550,- 600 + 550,-1650 - + 500,- 700 + 550,-1650 + 600,- 600 + 550,-1650 - + 600,-1650 + 600,-1650 + 550,- 650 + 550,-1650 - + 550,- 600 + 550,- 600 + 550,-1700 + 550,-1700 - + 550,-1650 + 600,- 600 + 550,-1650 + 600,-1650 - + 600,- 600 + 550,-1650 + 550,-1700 + 550,-1700 - + 550,-1700 + 550,-1700 + 550,-1700 + 550,-1650 - + 550,- 650 + 550,-1650 + 550,- 650 + 550,-1700 - + 550,- 600 + 550,-1650 + 600,- 550 + 600,-1650 - + 550,-1700 + 550,- 600 + 550,-1700 + 550,- 600 - + 550 -Sum: 138200 - -Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first -Protocol=PulseWidth Raw-Data=0xDCBA9 52 bits LSB first -Send with: - uint32_t tRawData[]={0x87654321, 0xDCBA9}; - IrSender.sendPulseDistanceWidthFromArray(38, 350, 600, 600, 300, 300, 600, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, , ); -rawData[106]: - -1115100 + + 600,-1650 + 600,- 550 + 650,- 500 + 650,- 550 + + 650,- 500 + 650,-1600 + 600,- 550 + 650,- 500 + + 650,-1600 + 650,-1600 + 650,- 500 + 650,- 550 + + 600,- 550 + 650,- 500 + 650,-1600 + 650,- 550 + + 600,-1650 + 600,- 550 + 650,-1600 + 650,- 500 + + 650,- 550 + 600,-1650 + 600,-1650 + 650,- 500 + + 650,-1600 + 650,-1600 + 650,-1600 + 600,- 550 + + 650,- 550 + 650,- 500 + 600,- 550 + 650,-1650 + + 600,-1650 + 650,- 500 + 650,- 500 + 650,-1650 + + 600,- 550 + 650,-1600 + 650,- 500 + 650,-1600 + + 600,-1650 + 650,-1600 + 650,- 500 + 700,-1550 + + 650,- 550 + 600,- 550 + 650,-1600 + 600,-1650 + + 650,-1600 + 650,- 500 + 600,-1650 + 650,-1600 + + 700,- 450 + 650,-1600 + 650,-1650 + 600,-1650 + + 650,-1600 + 600,-1650 + 600,-1650 + 600,-1650 + + 650,- 500 + 600,-1650 + 600,- 550 + 650,-1650 + + 600,- 550 + 600,-1650 + 600,- 550 + 650,-1600 + + 650,-1600 + 650,- 500 + 600,-1650 + 650,- 550 + + 600 +Duration=139000us + + +Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first 1=300|600, 0=600|300 +Protocol=PulseDistance, Raw-Data=0xDCBA9, 52 bits, LSB first, Gap=822600us, Duration=48950us +Send on a 8 bit platform with: + uint32_t tRawData[]={0x87654321, 0xDCBA9}; + IrSender.sendPulseDistanceWidthFromArray(38, 350, 600, 350, 550, 650, 250, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[108]: + -822600 + 350,- 600 - + 650,- 250 + 350,- 550 + 350,- 550 + 300,- 600 - + 350,- 550 + 600,- 300 + 350,- 550 + 350,- 550 - + 600,- 300 + 600,- 300 + 350,- 550 + 350,- 550 - + 350,- 600 + 300,- 600 + 600,- 300 + 300,- 600 - + 600,- 300 + 300,- 600 + 600,- 300 + 300,- 600 - + 300,- 600 + 600,- 300 + 600,- 300 + 350,- 550 - + 600,- 300 + 600,- 300 + 600,- 300 + 300,- 600 - + 350,- 550 + 350,- 550 + 350,- 550 + 600,- 350 - + 600,- 300 + 300,- 600 + 300,- 600 + 600,- 300 - + 300,- 600 + 600,- 300 + 300,- 600 + 600,- 300 - + 600,- 300 + 600,- 300 + 300,- 600 + 600,- 300 - + 300,- 600 + 350,- 550 + 600,- 300 + 600,- 300 - + 600,- 300 + 300,- 600 + 600,- 300 + 600 -Sum: 47550 - -Send generic 32 bit PulseWidth 0x87654321 LSB first -Protocol=PulseWidth Raw-Data=0x87654321 32 bits LSB first -Send with: IrSender.sendPulseDistanceWidth(38, 950, 550, 600, 300, 300, 300, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, , ); -rawData[66]: - -1088600 - + 950,- 550 - + 600,- 300 + 300,- 300 + 350,- 250 + 350,- 250 - + 350,- 300 + 600,- 300 + 300,- 300 + 300,- 300 - + 650,- 250 + 650,- 250 + 300,- 300 + 350,- 250 - + 350,- 300 + 300,- 300 + 600,- 300 + 300,- 300 - + 600,- 300 + 350,- 250 + 600,- 300 + 350,- 250 - + 350,- 300 + 600,- 300 + 600,- 300 + 300,- 300 - + 600,- 300 + 600,- 300 + 600,- 300 + 300,- 300 - + 300,- 300 + 300,- 300 + 350,- 250 + 650 -Sum: 24500 - -Send MagiQuest 0x6BCDFF00, 0x176 as generic 55 bit PulseDistanceWidth MSB first -Protocol=MagiQuest Address=0xFF00 Command=0x176 Raw-Data=0x6BCDFF00 56 bits MSB first + + 400,- 500 + 650,- 300 + 700,- 200 + 650,- 300 + + 650,- 200 + 400,- 550 + 700,- 250 + 700,- 150 + + 400,- 550 + 350,- 600 + 650,- 200 + 700,- 300 + + 600,- 300 + 650,- 250 + 400,- 500 + 650,- 300 + + 350,- 550 + 700,- 200 + 350,- 600 + 650,- 200 + + 750,- 200 + 400,- 550 + 350,- 550 + 650,- 300 + + 350,- 500 + 400,- 550 + 350,- 550 + 650,- 250 + + 650,- 300 + 700,- 250 + 650,- 200 + 400,- 550 + + 350,- 550 + 700,- 250 + 650,- 250 + 350,- 550 + + 650,- 300 + 350,- 550 + 650,- 250 + 400,- 500 + + 350,- 600 + 400,- 500 + 650,- 250 + 350,- 550 + + 700,- 250 + 700,- 200 + 400,- 500 + 400,- 550 + + 350,- 550 + 650,- 250 + 350,- 550 + 350,- 600 + + 350 +Duration=48950us + + +Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first with inverse timing and data 1=600|300, 0=300|600 +Protocol=PulseDistance, Raw-Data=0xDCBA9, 52 bits, LSB first, Gap=802900us, Duration=49250us +Send on a 8 bit platform with: + uint32_t tRawData[]={0x87654321, 0xDCBA9}; + IrSender.sendPulseDistanceWidthFromArray(38, 400, 550, 550, 550, 550, 250, &tRawData[0], 52, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[108]: + -802900 + + 400,- 550 + + 350,- 550 + 700,- 250 + 650,- 250 + 650,- 300 + + 650,- 250 + 400,- 500 + 650,- 300 + 600,- 300 + + 350,- 550 + 350,- 550 + 650,- 300 + 650,- 200 + + 750,- 200 + 750,- 100 + 500,- 500 + 650,- 250 + + 400,- 500 + 700,- 200 + 450,- 500 + 700,- 200 + + 700,- 200 + 400,- 550 + 400,- 500 + 700,- 200 + + 400,- 550 + 350,- 550 + 350,- 550 + 700,- 250 + + 650,- 200 + 700,- 250 + 700,- 200 + 400,- 550 + + 400,- 500 + 700,- 200 + 750,- 200 + 400,- 500 + + 700,- 200 + 400,- 550 + 650,- 250 + 350,- 550 + + 350,- 600 + 350,- 550 + 650,- 200 + 400,- 550 + + 650,- 300 + 650,- 250 + 400,- 500 + 400,- 550 + + 400,- 500 + 650,- 300 + 300,- 550 + 400,- 550 + + 700 +Duration=49250us + + +Send 7 bit ASCII character with PulseDistanceWidth LSB first 1=500|1500, 0=1500|500 +Protocol=PulseDistance, Raw-Data=0x76, 7 bits, LSB first, Gap=800900us, Duration=21050us +Send on a 8 bit platform with: IrSender.sendPulseDistanceWidth(38, 5950, 500, 550, 1450, 1600, 450, 0x76, 7, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[18]: + -800900 + +5950,- 500 + +1550,- 450 + 550,-1450 + 600,-1400 +1600,- 400 + + 550,-1450 + 550,-1450 + 550,-1450 + 600 +Duration=21050us + + +Send Velux 0x654321 decoded as PulseDistanceWidth 0x3D9EAC LSB first 1=1275|475, 0=475|1275 +Protocol=PulseDistance, Raw-Data=0x3D9EAC, 23 bits, LSB first, Gap=747800us, Duration=42450us +Send on a 8 bit platform with: IrSender.sendPulseDistanceWidth(38, 550, 1250, 450, 1250, 1300, 400, 0x3D9EAC, 23, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[50]: + -747800 + + 550,-1250 + +1300,- 400 +1300,- 400 + 500,-1200 + 450,-1250 + +1350,- 400 + 450,-1250 +1300,- 400 + 450,-1250 + +1300,- 400 + 450,-1250 + 500,-1200 + 500,-1250 + + 450,-1250 +1300,- 400 +1350,- 350 + 500,-1200 + + 450,-1300 +1300,- 400 + 450,-1250 + 450,-1250 + + 500,-1200 + 450,-1250 +1350,- 400 +1350 +Duration=42450us + + +Send Sony12 as PulseWidth LSB first 1=1200|300, 0=600|600 +Protocol=Sony Address=0x11, Command=0x76, Raw-Data=0x8F6, 12 bits, LSB first, Gap=762850us, Duration=21150us +Send with: IrSender.sendSony(0x11, 0x76, , 12); +rawIRTimings[26]: + -762850 + +2450,- 550 + + 700,- 500 +1300,- 500 +1250,- 550 + 700,- 500 + +1300,- 550 +1250,- 550 +1250,- 550 +1250,- 550 + + 700,- 550 + 650,- 550 + 700,- 500 +1250 +Duration=21150us + + +Send 32 bit PulseWidth 0x87654321 LSB first 1=600|300, 0=300|300 - timing ratio is 1:2 +Protocol=PulseWidth, Raw-Data=0x87654321, 32 bits, LSB first, Gap=748050us, Duration=24950us +Send on a 8 bit platform with: IrSender.sendPulseDistanceWidth(38, 1050, 500, 700, 250, 400, 250, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, , ); +rawIRTimings[66]: + -748050 + +1050,- 500 + + 650,- 250 + 400,- 200 + 400,- 200 + 450,- 200 + + 350,- 300 + 650,- 200 + 400,- 250 + 400,- 200 + + 700,- 250 + 700,- 200 + 400,- 250 + 350,- 250 + + 350,- 300 + 300,- 300 + 650,- 250 + 400,- 200 + + 700,- 250 + 350,- 250 + 700,- 250 + 350,- 250 + + 400,- 150 + 750,- 150 + 750,- 250 + 350,- 250 + + 700,- 200 + 700,- 250 + 700,- 150 + 400,- 300 + + 350,- 250 + 400,- 150 + 400,- 250 + 700 +Duration=24950us + + +Send MagiQuest 0x6BCDFF00, 0x176 as 55 bit PulseDistanceWidth MSB first 1=576|576, 0=287|864 +Protocol=MagiQuest Address=0xFF00, Command=0x176, Raw-Data=0x6BCDFF00, 56 bits, MSB first, Gap=774150us, Duration=64900us Send with: IrSender.sendMagiQuest(0x6BCDFF00, 0x176, ); -rawData[112]: - -1089000 - + 350,- 800 + 350,- 800 + 350,- 800 + 300,- 850 - + 300,- 850 + 300,- 850 + 300,- 850 + 350,- 800 - + 600,- 550 + 600,- 550 + 350,- 800 + 600,- 550 - + 300,- 850 + 600,- 550 + 600,- 550 + 600,- 550 - + 600,- 550 + 350,- 800 + 300,- 850 + 550,- 600 - + 600,- 550 + 300,- 850 + 600,- 550 + 600,- 550 - + 600,- 550 + 600,- 600 + 550,- 550 + 600,- 550 - + 600,- 550 + 600,- 550 + 600,- 550 + 300,- 850 - + 300,- 850 + 350,- 800 + 300,- 850 + 300,- 850 - + 300,- 850 + 300,- 850 + 300,- 850 + 600,- 550 - + 300,- 850 + 600,- 550 + 600,- 550 + 600,- 550 - + 350,- 800 + 600,- 550 + 600,- 550 + 350,- 800 - + 300,- 850 + 300,- 850 + 300,- 850 + 600,- 600 - + 550,- 600 + 250,- 900 + 250,- 850 + 600 -Sum: 63850 +rawIRTimings[112]: + -774150 + + 350,- 850 + 350,- 800 + 400,- 800 + 350,- 800 + + 450,- 700 + 400,- 800 + 400,- 750 + 400,- 800 + + 650,- 500 + 600,- 550 + 400,- 750 + 600,- 600 + + 350,- 800 + 600,- 600 + 650,- 500 + 650,- 500 + + 650,- 550 + 350,- 800 + 400,- 800 + 600,- 550 + + 650,- 500 + 400,- 800 + 650,- 500 + 600,- 550 + + 600,- 550 + 700,- 500 + 600,- 550 + 650,- 550 + + 550,- 600 + 600,- 550 + 650,- 550 + 350,- 800 + + 350,- 850 + 400,- 750 + 400,- 800 + 350,- 800 + + 350,- 800 + 350,- 850 + 350,- 800 + 600,- 550 + + 350,- 850 + 600,- 550 + 650,- 550 + 600,- 550 + + 350,- 800 + 600,- 600 + 600,- 550 + 350,- 800 + + 350,- 850 + 350,- 800 + 350,- 800 + 600,- 600 + + 650,- 500 + 400,- 750 + 400,- 800 + 600 +Duration=64900us + + +Send NEC with TinyIRSender +Protocol=NEC Address=0xF1, Command=0x76, Raw-Data=0x89760EF1, 32 bits, LSB first, Gap=790250us, Duration=75050us +Send with: IrSender.sendNEC(0xF1, 0x76, ); +rawIRTimings[68]: + -790250 + +8900,-5250 + + 600,-1950 + 600,- 650 + 600,- 600 + 600,- 650 + + 500,-2000 + 650,-1900 + 600,-1950 + 600,-1950 + + 650,- 600 + 550,-1950 + 650,-1900 + 650,-1900 + + 650,- 600 + 650,- 550 + 600,- 650 + 600,- 600 + + 650,- 550 + 650,-1900 + 600,-1950 + 600,- 650 + + 600,-1950 + 650,-1900 + 650,-1900 + 550,- 650 + + 600,-1950 + 650,- 550 + 650,- 600 + 600,-1900 + + 650,- 600 + 600,- 600 + 600,- 650 + 600,-1950 + + 600 +Duration=75050us + + +Send FAST with TinyIRSender +Protocol=FAST Address=0x0, Command=0x76, Raw-Data=0x8976, 16 bits, LSB first, Gap=764700us, Duration=32050us +Send with: IrSender.sendFAST(0x76, ); +rawIRTimings[36]: + -764700 + +2100,-1200 + + 550,- 600 + 550,-1850 + 600,-1750 + 600,- 550 + + 500,-1900 + 600,-1800 + 550,-1800 + 550,- 600 + + 600,-1800 + 550,- 600 + 600,- 550 + 550,-1800 + + 600,- 550 + 550,- 600 + 600,- 550 + 550,-1800 + + 550 +Duration=32050us + Send Onkyo (NEC with 16 bit command) -Protocol=Onkyo Address=0xFFF1 Command=0x7776 Raw-Data=0x7776FFF1 32 bits LSB first +Protocol=Onkyo Address=0xFFF1, Command=0x7776, Raw-Data=0x7776FFF1, 32 bits, LSB first, Gap=791150us, Duration=76750us Send with: IrSender.sendOnkyo(0xFFF1, 0x7776, ); -rawData[68]: - -1070700 - +8900,-4550 - + 500,-1600 + 650,- 500 + 600,- 500 + 600,- 550 - + 600,-1600 + 600,-1650 + 600,-1650 + 550,-1650 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 550,-1700 - + 550,- 550 + 600,-1650 + 550,-1650 + 600,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,-1650 + 600,-1600 + 600,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 550,- 550 +rawIRTimings[68]: + -791150 + +8900,-4450 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1600 + 650,-1600 + 650,-1600 + 650,-1600 + + 600,-1650 + 650,-1550 + 650,-1600 + 600,-1650 + + 650,-1600 + 600,-1600 + 650,-1600 + 600,-1650 + + 650,- 500 + 600,-1650 + 600,-1600 + 650,- 500 + + 650,-1600 + 600,-1650 + 600,-1600 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 700,- 450 + + 600,-1650 + 600,-1600 + 700,-1550 + 600,- 550 + 600 -Sum: 76500 +Duration=76750us + Send Apple -Protocol=Apple Address=0xF1 Command=0x76 Raw-Data=0xF17687EE 32 bits LSB first +Protocol=Apple Address=0xF1, Command=0x76, Raw-Data=0xF17687EE, 32 bits, LSB first, Gap=764350us, Duration=72350us Send with: IrSender.sendApple(0xF1, 0x76, ); -rawData[68]: - -1054650 - +8950,-4400 - + 600,- 550 + 550,-1650 + 650,-1600 + 600,-1600 - + 600,- 550 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,- 550 - + 550,- 550 + 600,- 550 + 600,- 500 + 600,-1650 - + 600,- 550 + 550,-1650 + 600,-1650 + 600,- 500 - + 550,-1700 + 600,-1650 + 550,-1650 + 600,- 550 - + 550,-1650 + 600,- 550 + 600,- 550 + 550,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,-1650 - + 550 -Sum: 72100 +rawIRTimings[68]: + -764350 + +8900,-4450 + + 600,- 500 + 600,-1650 + 650,-1600 + 650,-1600 + + 600,- 500 + 650,-1600 + 600,-1650 + 650,-1600 + + 600,-1650 + 650,-1600 + 600,-1650 + 600,- 500 + + 650,- 500 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,- 500 + 650,-1600 + 600,-1600 + 600,- 550 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,- 500 + + 650,-1600 + 600,- 550 + 600,- 500 + 650,- 500 + + 650,-1600 + 600,-1650 + 600,-1600 + 600,-1650 + + 600 +Duration=72350us + Send Panasonic -Protocol=Panasonic Address=0xFF1 Command=0x76 Raw-Data=0x9976FF10 48 bits LSB first +Protocol=Panasonic Address=0xFF1, Command=0x76, Raw-Data=0x9976FF10, 48 bits, LSB first, Gap=764050us, Duration=65300us Send with: IrSender.sendPanasonic(0xFF1, 0x76, ); -rawData[100]: - -1054300 - +3450,-1700 - + 450,- 450 + 400,-1300 + 450,- 400 + 450,- 450 - + 450,- 400 + 450,- 450 + 400,- 450 + 450,- 400 - + 450,- 450 + 450,- 400 + 450,- 400 + 450,- 450 - + 450,- 400 + 450,-1300 + 400,- 450 + 450,- 400 - + 450,- 450 + 400,- 450 + 450,- 400 + 450,- 450 - + 450,-1250 + 450,- 400 + 450,- 450 + 450,- 400 - + 450,-1300 + 400,-1300 + 450,-1300 + 400,-1300 - + 450,-1300 + 400,-1300 + 450,-1300 + 400,-1300 - + 450,- 450 + 450,-1250 + 500,-1250 + 450,- 400 - + 450,-1300 + 400,-1300 + 450,-1300 + 400,- 450 - + 450,-1250 + 450,- 450 + 450,- 400 + 450,-1300 - + 400,-1300 + 450,- 400 + 450,- 450 + 450,-1250 - + 450 -Sum: 64400 - -Send Kaseikyo with 0x4711 as Vendor ID -Protocol=Kaseikyo Address=0xFF1 Command=0x76 Extra=0x4711 Raw-Data=0x9A76FF13 48 bits LSB first +rawIRTimings[100]: + -764050 + +3500,-1700 + + 450,- 400 + 500,-1250 + 500,- 400 + 500,- 400 + + 450,- 450 + 500,- 350 + 500,- 400 + 500,- 350 + + 550,- 350 + 500,- 400 + 500,- 400 + 500,- 350 + + 450,- 450 + 500,-1250 + 450,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 400,- 450 + 500,- 400 + + 400,-1350 + 500,- 400 + 500,- 400 + 500,- 350 + + 550,-1200 + 500,-1250 + 450,-1250 + 500,-1250 + + 500,-1250 + 500,-1250 + 450,-1250 + 500,-1250 + + 500,- 400 + 500,-1250 + 500,-1250 + 500,- 350 + + 550,-1200 + 500,-1250 + 500,-1250 + 500,- 400 + + 450,-1250 + 500,- 400 + 500,- 400 + 450,-1300 + + 450,-1250 + 550,- 350 + 500,- 400 + 500,-1250 + + 500 +Duration=65300us + + +Send Kaseikyo with extra=0x4711 as Vendor ID +Protocol=Kaseikyo Address=0xFF1, Command=0x76, Extra=0x4711, Raw-Data=0x9A76FF13, 48 bits, LSB first, Gap=784400us, Duration=70450us Send with: IrSender.sendKaseikyo(0xFF1, 0x76, , 0x4711); -rawData[100]: - -1074550 - +3400,-1750 - + 450,-1250 + 450,- 450 + 450,- 400 + 450,- 450 - + 400,-1300 + 450,- 400 + 450,- 450 + 450,- 400 - + 450,-1300 + 400,-1300 + 450,-1300 + 400,- 450 - + 450,- 400 + 450,- 450 + 450,-1250 + 450,- 450 - + 400,-1300 + 450,-1300 + 400,- 450 + 450,- 400 - + 450,-1300 + 450,- 400 + 450,- 450 + 400,- 450 - + 450,-1250 + 400,-1350 + 450,-1300 + 400,-1350 - + 400,-1300 + 400,-1300 + 450,-1300 + 450,-1250 - + 450,- 450 + 400,-1300 + 450,-1300 + 400,- 450 - + 450,-1250 + 450,-1300 + 400,-1300 + 450,- 400 - + 450,- 450 + 450,-1250 + 450,- 400 + 450,-1300 - + 450,-1250 + 450,- 400 + 450,- 450 + 450,-1250 - + 450 -Sum: 69500 +rawIRTimings[100]: + -784400 + +3450,-1700 + + 550,-1200 + 500,- 400 + 450,- 450 + 500,- 350 + + 500,-1250 + 450,- 450 + 450,- 450 + 500,- 400 + + 500,-1200 + 500,-1250 + 500,-1250 + 500,- 400 + + 450,- 400 + 550,- 350 + 500,-1250 + 500,- 400 + + 500,-1200 + 450,-1300 + 500,- 400 + 500,- 400 + + 450,-1250 + 500,- 400 + 500,- 400 + 450,- 450 + + 450,-1250 + 500,-1250 + 500,-1250 + 500,-1250 + + 450,-1300 + 500,-1200 + 500,-1250 + 500,-1250 + + 500,- 400 + 500,-1250 + 450,-1250 + 500,- 400 + + 500,-1250 + 500,-1250 + 450,-1250 + 500,- 400 + + 550,- 350 + 450,-1300 + 500,- 400 + 500,-1250 + + 450,-1250 + 550,- 350 + 500,- 400 + 500,-1250 + + 500 +Duration=70450us + Send Kaseikyo_Denon variant -Protocol=Kaseikyo_Denon Address=0xFF1 Command=0x76 Raw-Data=0x9976FF10 48 bits LSB first +Protocol=Kaseikyo_Denon Address=0xFF1, Command=0x76, Raw-Data=0x9976FF10, 48 bits, LSB first, Gap=784650us, Duration=68700us Send with: IrSender.sendKaseikyo_Denon(0xFF1, 0x76, ); -rawData[100]: - -1067700 - +3400,-1750 - + 450,- 400 + 450,- 450 + 450,-1250 + 450,- 400 - + 450,-1300 + 450,- 400 + 450,-1300 + 400,- 450 - + 450,- 400 + 450,-1300 + 450,- 400 + 450,- 400 - + 450,-1300 + 450,-1250 + 450,- 400 + 450,- 450 - + 400,- 450 + 450,- 400 + 450,- 450 + 400,- 450 - + 450,-1250 + 450,- 450 + 450,- 400 + 450,- 400 - + 450,-1300 + 450,-1250 + 450,-1300 + 400,-1300 - + 450,-1300 + 400,-1300 + 450,-1250 + 450,-1300 - + 450,- 400 + 450,-1300 + 400,-1300 + 450,- 400 - + 450,-1300 + 400,-1300 + 450,-1300 + 400,- 450 - + 450,-1250 + 450,- 450 + 400,- 450 + 450,-1300 - + 400,-1300 + 450,- 400 + 450,- 450 + 450,-1250 - + 450 -Sum: 67700 - -Send Denon -Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0xED1 15 bits LSB first +rawIRTimings[100]: + -784650 + +3550,-1650 + + 500,- 400 + 500,- 400 + 450,-1250 + 500,- 400 + + 450,-1300 + 450,- 450 + 500,-1200 + 500,- 400 + + 450,- 450 + 450,-1250 + 500,- 400 + 450,- 450 + + 500,-1250 + 500,-1250 + 500,- 400 + 500,- 350 + + 500,- 400 + 500,- 400 + 500,- 400 + 500,- 350 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 400 + + 500,-1250 + 450,-1250 + 450,-1300 + 500,-1250 + + 500,-1250 + 500,-1250 + 450,-1250 + 550,-1200 + + 500,- 400 + 500,-1250 + 500,-1250 + 500,- 400 + + 450,-1250 + 500,-1250 + 450,-1300 + 450,- 400 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,-1250 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,-1250 + + 500 +Duration=68700us + + +Send Denon with 2 autorepeats after 45 ms +Protocol=Denon Address=0x11, Command=0x76, Raw-Data=0xED1, 15 bits, LSB first, Gap=784950us, Duration=23450us Send with: IrSender.sendDenon(0x11, 0x76, ); -rawData[32]: - -1073050 - + 250,-1850 + 250,- 750 + 250,- 800 + 250,- 800 - + 250,-1800 + 250,- 800 + 250,-1800 + 250,-1850 - + 250,- 750 + 300,-1800 + 250,-1800 + 300,-1800 - + 250,- 750 + 300,- 750 + 300,- 750 + 250 -Sum: 23050 - -Send Denon/Sharp variant -Protocol=Sharp Address=0x11 Command=0x76 Raw-Data=0x4ED1 15 bits LSB first +rawIRTimings[32]: + -784950 + + 350,-1750 + 350,- 700 + 300,- 800 + 300,- 750 + + 300,-1750 + 350,- 750 + 300,-1750 + 350,-1750 + + 300,- 750 + 350,-1750 + 350,-1750 + 300,-1800 + + 300,- 750 + 300,- 750 + 300,- 750 + 350 +Duration=23450us + + +Send Denon/Sharp variant with 2 autorepeat5 after 45 ms +Protocol=Sharp Address=0x11, Command=0x76, Raw-Data=0x2ED1, 15 bits, LSB first, Gap=728000us, Duration=24400us Send with: IrSender.sendSharp(0x11, 0x76, ); -rawData[32]: - -1018750 - + 300,-1750 + 300,- 750 + 250,- 800 + 250,- 800 - + 250,-1800 + 250,- 800 + 250,-1800 + 300,-1800 - + 250,- 800 + 250,-1800 + 300,-1750 + 300,-1800 - + 250,- 800 + 250,- 750 + 300,-1800 + 250 -Sum: 24100 +rawIRTimings[32]: + -728000 + + 350,-1750 + 300,- 750 + 300,- 750 + 300,- 750 + + 350,-1750 + 300,- 750 + 300,-1800 + 350,-1700 + + 300,- 750 + 350,-1750 + 350,-1750 + 300,-1800 + + 350,- 700 + 350,-1700 + 300,- 800 + 300 +Duration=24400us + Send Sony/SIRCS with 7 command and 5 address bits -Protocol=Sony Address=0x11 Command=0x76 Raw-Data=0x8F6 12 bits LSB first -Send with: IrSender.sendSony(0x11, 0x76, 2, 12); -rawData[26]: - -1020950 - +2400,- 650 - + 550,- 600 +1200,- 550 +1250,- 550 + 650,- 550 - +1250,- 550 +1250,- 600 +1200,- 550 +1200,- 600 - + 650,- 550 + 650,- 550 + 650,- 550 +1200 -Sum: 20950 +Protocol=Sony Address=0x11, Command=0x76, Raw-Data=0x8F6, 12 bits, LSB first, Gap=727550us, Duration=21250us +Send with: IrSender.sendSony(0x11, 0x76, , 12); +rawIRTimings[26]: + -727550 + +2500,- 550 + + 650,- 550 +1250,- 550 +1250,- 550 + 700,- 500 + +1250,- 600 +1250,- 550 +1250,- 550 +1300,- 500 + + 650,- 550 + 700,- 550 + 650,- 550 +1300 +Duration=21250us + Send Sony/SIRCS with 7 command and 8 address bits -Protocol=Sony Address=0xF1 Command=0x76 Raw-Data=0x78F6 15 bits LSB first -Send with: IrSender.sendSony(0xF1, 0x76, 2, 15); -rawData[32]: - -1032550 +Protocol=Sony Address=0xF1, Command=0x76, Raw-Data=0x78F6, 15 bits, LSB first, Gap=744950us, Duration=26650us +Send with: IrSender.sendSony(0xF1, 0x76, , 15); +rawIRTimings[32]: + -744950 +2400,- 600 - + 600,- 600 +1200,- 600 +1200,- 550 + 650,- 550 - +1200,- 600 +1200,- 650 +1200,- 550 +1200,- 600 - + 650,- 550 + 650,- 550 + 650,- 550 +1200,- 600 - +1200,- 600 +1250,- 600 +1200 -Sum: 26400 - -Send Sony/SIRCS with 7 command and 13 address bits -Protocol=Sony Address=0x1FF1 Command=0x76 Raw-Data=0xFF8F6 20 bits LSB first -Send with: IrSender.sendSony(0x1FF1, 0x76, 2, 20); -rawData[42]: - -1036350 - +2300,- 650 - + 600,- 600 +1200,- 550 +1250,- 550 + 650,- 600 - +1200,- 550 +1250,- 550 +1200,- 600 +1250,- 600 - + 600,- 600 + 600,- 600 + 600,- 550 +1200,- 600 - +1250,- 550 +1250,- 550 +1250,- 550 +1250,- 600 - +1200,- 550 +1200,- 600 +1250,- 600 +1200 -Sum: 35350 - -Send Samsung 8 bit command -Protocol=Samsung Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first + + 700,- 500 +1250,- 600 +1300,- 500 + 700,- 500 + +1250,- 550 +1300,- 550 +1250,- 550 +1250,- 550 + + 700,- 550 + 600,- 600 + 650,- 550 +1250,- 600 + +1250,- 550 +1250,- 550 +1250 +Duration=26650us + + +Send Sony/SIRCS with 7 command and 13 address bits and no repeats +Protocol=Sony Address=0x1FF1, Command=0x76, Raw-Data=0xFF8F6, 20 bits, LSB first, Gap=749650us, Duration=35650us +Send with: IrSender.sendSony(0x1FF1, 0x76, , 20); +rawIRTimings[42]: + -749650 + +2450,- 550 + + 650,- 550 +1250,- 550 +1250,- 550 + 700,- 550 + +1300,- 500 +1250,- 550 +1300,- 500 +1250,- 550 + + 700,- 550 + 650,- 550 + 700,- 500 +1250,- 550 + +1250,- 550 +1250,- 550 +1250,- 600 +1250,- 550 + +1250,- 550 +1250,- 550 +1250,- 550 +1300 +Duration=35650us + + +Send Samsung 8 bit command and 8 bit address +Protocol=Samsung Address=0xF1, Command=0x76, Raw-Data=0x8976F1F1, 32 bits, LSB first, Gap=753500us, Duration=65700us +Send with: IrSender.sendSamsung(0xF1, 0x76, ); +rawIRTimings[68]: + -753500 + +4500,-4400 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,- 500 + + 650,-1600 + 600,-1650 + 600,-1600 + 650,-1600 + + 650,-1600 + 600,- 550 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,-1600 + + 650,- 500 + 600,-1650 + 600,-1600 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 + + 600,-1650 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 500 + 600,- 550 + 600,- 550 + 600,-1600 + + 650 +Duration=65700us + + +Send Samsung 8 bit command and 16 bit address +Protocol=Samsung Address=0xFFF1, Command=0x76, Raw-Data=0x8976FFF1, 32 bits, LSB first, Gap=766950us, Duration=68950us Send with: IrSender.sendSamsung(0xFFF1, 0x76, ); -rawData[68]: - -1039650 - +4400,-4450 - + 550,-1700 + 550,- 550 + 600,- 550 + 550,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 550,-1650 - + 600,-1650 + 600,-1650 + 600,-1650 + 550,-1650 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,- 550 + 550,-1650 + 600,-1650 + 600,- 550 - + 550,-1650 + 600,-1650 + 550,-1700 + 550,- 550 - + 600,-1650 + 550,- 550 + 600,- 550 + 600,-1600 - + 600,- 550 + 600,- 550 + 550,- 550 + 600,-1650 +rawIRTimings[68]: + -766950 + +4450,-4450 + + 650,-1600 + 650,- 500 + 600,- 500 + 600,- 500 + + 650,-1600 + 600,-1650 + 600,-1650 + 650,-1600 + + 600,-1600 + 650,-1600 + 650,-1600 + 600,-1650 + + 650,-1600 + 600,-1600 + 650,-1600 + 650,-1600 + + 650,- 500 + 650,-1600 + 600,-1600 + 650,- 500 + + 600,-1650 + 600,-1650 + 650,-1550 + 650,- 500 + + 600,-1650 + 600,- 500 + 650,- 500 + 650,-1600 + + 600,- 500 + 650,- 500 + 650,- 450 + 650,-1600 + 600 -Sum: 68750 +Duration=68950us + -Send Samsung 16 bit command -Protocol=Samsung Address=0xFFF1 Command=0x9876 Raw-Data=0x9876FFF1 32 bits LSB first +Send Samsung 16 bit command and address +Protocol=Samsung Address=0xFFF1, Command=0x9876, Raw-Data=0x9876FFF1, 32 bits, LSB first, Gap=766800us, Duration=69050us Send with: IrSender.sendSamsung(0xFFF1, 0x9876, ); -rawData[68]: - -1056350 - +4400,-4400 - + 600,-1650 + 550,- 550 + 600,- 550 + 550,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,-1600 - + 600,-1650 + 600,-1650 + 600,-1650 + 550,-1650 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,- 500 + 550,-1700 + 600,-1650 + 550,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,- 550 - + 550,- 550 + 600,- 550 + 550,- 550 + 600,-1650 - + 550,-1650 + 600,- 550 + 600,- 550 + 550,-1650 +rawIRTimings[68]: + -766800 + +4500,-4400 + + 600,-1650 + 600,- 550 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,-1600 + + 650,-1600 + 600,-1650 + 600,-1650 + 600,-1600 + + 600,-1650 + 650,-1600 + 650,-1600 + 600,-1650 + + 600,- 500 + 650,-1600 + 650,-1600 + 600,- 550 + + 600,-1650 + 600,-1600 + 650,-1600 + 700,- 450 + + 600,- 550 + 600,- 500 + 700,- 450 + 650,-1600 + + 600,-1650 + 600,- 500 + 600,- 550 + 600,-1650 + 600 -Sum: 68650 +Duration=69050us + Send Samsung48 16 bit command -Protocol=Samsung48 Address=0xFFF1 Command=0x9876 Raw-Data=0x6798 48 bits LSB first +Protocol=Samsung48 Address=0xFFF1, Command=0x9876, Raw-Data=0x6798, 48 bits, LSB first, Gap=766300us, Duration=96000us Send with: IrSender.sendSamsung48(0xFFF1, 0x9876, ); -rawData[100]: - -1056750 - +4450,-4450 - + 600,-1650 + 600,- 500 + 600,- 550 + 550,- 550 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,-1650 - + 550,-1650 + 550,-1700 + 550,-1700 + 550,-1650 - + 600,- 550 + 550,-1700 + 550,-1650 + 600,- 550 - + 550,-1650 + 600,-1650 + 600,-1650 + 600,- 500 - + 600,-1650 + 600,- 500 + 600,- 550 + 600,-1650 - + 550,- 550 + 600,- 550 + 550,- 550 + 550,-1700 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 - + 550,-1650 + 600,- 550 + 550,- 550 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,- 550 - + 550,- 550 + 600,-1650 + 550,-1650 + 600,- 550 - + 550 -Sum: 95650 +rawIRTimings[100]: + -766300 + +4500,-4400 + + 650,-1600 + 600,- 500 + 650,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,-1600 + + 650,-1600 + 650,-1600 + 600,-1600 + 650,-1600 + + 600,-1650 + 600,-1650 + 650,-1600 + 600,-1600 + + 650,- 500 + 600,-1650 + 650,-1600 + 600,- 500 + + 600,-1650 + 650,-1600 + 650,-1600 + 600,- 500 + + 650,-1600 + 650,- 500 + 650,- 450 + 650,-1600 + + 650,- 500 + 650,- 450 + 650,- 500 + 600,-1650 + + 650,- 500 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,-1600 + 600,- 500 + 600,- 550 + 650,-1600 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,- 500 + + 600,- 500 + 650,-1600 + 650,-1600 + 650,- 500 + + 600 +Duration=96000us + Send RC5 -Protocol=RC5 Address=0x11 Command=0x36 Raw-Data=0x1476 13 bits MSB first +Protocol=RC5 Address=0x11, Command=0x36, Raw-Data=0x1476, 13 bits, MSB first, Gap=782400us, Duration=23300us Send with: IrSender.sendRC5(0x11, 0x36, ); -rawData[20]: - -1073300 - + 900,- 900 - +1750,-1800 +1750,- 900 + 900,- 850 + 900,-1750 - + 900,- 900 + 900,- 850 +1800,-1800 + 900,- 850 - +1800 -Sum: 23100 +rawIRTimings[20]: + -782400 + + 950,- 850 + +1850,-1700 +1850,- 850 + 900,- 850 +1000,-1700 + + 950,- 850 + 900,- 850 +1850,-1750 + 900,- 850 + +1900 +Duration=23300us + Send RC5X with 7.th MSB of command set -Protocol=RC5 Address=0x11 Command=0x76 Toggle=1 Raw-Data=0xC76 13 bits MSB first +Protocol=RC5 Address=0x11, Command=0x76, Toggle=1, Raw-Data=0xC76, 13 bits, MSB first, Gap=742050us, Duration=23250us Send with: IrSender.sendRC5(0x11, 0x76, ); -rawData[20]: - -1031250 +rawIRTimings[20]: + -742050 +1800,-1750 - + 850,- 900 +1800,- 850 + 900,- 900 + 900,-1750 - + 900,- 900 + 850,- 900 +1750,-1800 + 900,- 850 - +1800 -Sum: 23050 + + 950,- 800 +1900,- 800 + 900,- 850 +1000,-1700 + +1000,- 800 + 900,- 850 +1900,-1650 +1000,- 800 + +1900 +Duration=23250us + + +Send Marantz with RC5 and extra=0x9 +Protocol=Marantz Address=0x11, Command=0x36, Extra=0x9, Raw-Data=0x51D89, 19 bits, MSB first, Gap=742600us, Duration=38400us +Send with: IrSender.sendMarantz(0x11, 0x36, , 0x9); +rawIRTimings[30]: + -742600 + + 900,- 850 + +1850,-1750 +1800,- 850 + 900,- 850 +1000,-1700 + +1000,-4350 + 950,- 850 +1800,-1750 + 950,- 800 + +1850,- 850 + 900,- 900 + 900,-1750 +1850,- 800 + +1000,-1700 +1000 +Duration=38400us + + +Send Marantz with RC5A and extra=0x9 +Protocol=Marantz Address=0x11, Command=0x76, Extra=0x9, Toggle=1, Raw-Data=0x31D89, 19 bits, MSB first, Gap=748550us, Duration=38400us +Send with: IrSender.sendMarantz(0x11, 0x76, , 0x9); +rawIRTimings[30]: + -748550 + +1800,-1800 + + 950,- 850 +1800,- 800 +1000,- 800 +1000,-1700 + + 950,-4400 + 900,- 850 +1850,-1750 + 950,- 850 + +1800,- 850 + 950,- 850 + 950,-1700 +1800,- 850 + +1000,-1750 + 900 +Duration=38400us + Send RC6 -Protocol=RC6 Address=0xF1 Command=0x76 Raw-Data=0xF176 20 bits MSB first +Protocol=RC6 Address=0xF1, Command=0x76, Raw-Data=0xF176, 20 bits, MSB first, Gap=746200us, Duration=23600us Send with: IrSender.sendRC6(0xF1, 0x76, ); -rawData[36]: - -1028550 - +2650,- 900 - + 450,- 900 + 450,- 450 + 450,- 450 + 450,- 850 - +1350,- 450 + 450,- 450 + 450,- 450 + 450,- 900 - + 450,- 450 + 450,- 450 + 900,- 900 + 900,- 450 - + 450,- 450 + 450,- 900 + 850,- 450 + 450,- 900 - + 450 -Sum: 23250 +rawIRTimings[36]: + -746200 + +2700,- 800 + + 600,- 750 + 550,- 400 + 550,- 350 + 500,- 850 + +1400,- 400 + 550,- 350 + 550,- 400 + 500,- 850 + + 500,- 400 + 550,- 350 + 950,- 900 + 950,- 400 + + 550,- 400 + 500,- 850 +1000,- 350 + 550,- 800 + + 550 +Duration=23600us + + +Send RC6A with 14 bit and extra=0x2711 +Protocol=RC6A Address=0xF1, Command=0x76, Extra=0x2711, Toggle=1, Raw-Data=0xA711F176, 35 bits, MSB first, Gap=749050us, Duration=37450us +Send with: IrSender.sendRC6A(0xF1, 0x76, , 0x2711); +rawIRTimings[58]: + -749050 + +2700,- 850 + + 500,- 400 + 550,- 350 + 500,- 850 +1450,-1300 + +1000,- 850 + 500,- 400 +1000,- 400 + 500,- 450 + + 500,- 800 + 500,- 400 + 500,- 450 + 950,- 850 + + 500,- 450 + 500,- 400 +1000,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 550,- 850 + 500,- 400 + + 500,- 400 +1050,- 800 +1000,- 400 + 500,- 400 + + 500,- 850 +1000,- 400 + 500,- 850 + 550 +Duration=37450us + + +Send MagiQuest, WandId=0x6BCDFFF1 +Protocol=MagiQuest Address=0xFFF1, Command=0x76, Raw-Data=0x6BCDFFF1, 56 bits, MSB first, Gap=763750us, Duration=65050us +Send with: IrSender.sendMagiQuest(0x6BCDFFF1, 0x76, ); +rawIRTimings[112]: + -763750 + + 350,- 800 + 400,- 800 + 350,- 800 + 400,- 750 + + 400,- 800 + 350,- 800 + 350,- 850 + 350,- 850 + + 600,- 600 + 650,- 500 + 350,- 800 + 600,- 600 + + 350,- 800 + 650,- 500 + 650,- 550 + 650,- 500 + + 650,- 550 + 350,- 800 + 400,- 750 + 650,- 550 + + 600,- 550 + 400,- 800 + 600,- 550 + 650,- 500 + + 600,- 600 + 650,- 500 + 650,- 500 + 650,- 550 + + 600,- 550 + 650,- 550 + 600,- 550 + 600,- 550 + + 650,- 500 + 600,- 600 + 600,- 550 + 350,- 800 + + 400,- 800 + 400,- 750 + 650,- 550 + 350,- 800 + + 350,- 850 + 650,- 500 + 650,- 550 + 600,- 550 + + 350,- 800 + 650,- 550 + 600,- 550 + 350,- 850 + + 350,- 800 + 350,- 850 + 650,- 500 + 650,- 550 + + 350,- 800 + 650,- 500 + 650,- 550 + 650 +Duration=65050us + + +Send OpenLASIR mode fire and color orange, detected as ONKYO +Protocol=Onkyo Address=0xF1, Command=0xC076, Raw-Data=0xC0760EF1, 32 bits, LSB first, Gap=792950us, Duration=66750us +Send with: IrSender.sendOnkyo(0xF1, 0xC076, ); +rawIRTimings[68]: + -792950 + +8950,-4400 + + 600,-1650 + 600,- 500 + 600,- 550 + 650,- 500 + + 600,-1600 + 650,-1600 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,-1600 + 650,-1600 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,- 500 + + 600,- 550 + 600,-1600 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 650,- 500 + 600,- 500 + + 650,- 500 + 650,- 500 + 600,-1600 + 600,-1650 + + 600 +Duration=66750us + + +Send Lego with 2 channel and with 4 command bits +Protocol=Lego Address=0x1, Command=0x16, Raw-Data=0x1169, 16 bits, MSB first, Gap=767200us, Duration=10250us +Send with: IrSender.sendLego(0x1, 0x16, ); +rawIRTimings[36]: + -767200 + + 250,- 950 + + 250,- 500 + 250,- 150 + 200,- 300 + 200,- 500 + + 250,- 150 + 200,- 600 + 250,- 500 + 200,- 150 + + 300,- 500 + 200,- 200 + 250,- 200 + 200,- 300 + + 250,- 450 + 250,- 150 + 200,- 300 + 250,- 150 + + 250 +Duration=10250us + + +Send 16 bit Bang&Olufsen - requires originally 455 kHz +- ENABLE_BEO_WITHOUT_FRAME_GAP is enabled +rawIRTimings[44]: + -749450 + + 250,-2850 + + 300,-2850 + 250,-12750 + 250,-2850 + 250,-9050 + + 250,-5950 + 250,-5950 + 300,-5950 + 250,-2850 + + 250,-5950 + 300,-5900 + 300,-9000 + 250,-2900 + + 250,-9050 + 250,-5950 + 300,-5900 + 300,-2850 + + 300,-9000 + 250,-5950 + 250,-2850 + 300,-12100 + + 300 +Duration=134400us + +- Now try to decode the first 6 entries, which results in rawData 0x0 +Protocol=Bang&Olufsen Address=0x0, Command=0x0, Raw-Data=0x0, 0 bits, MSB first, Gap=749450us, Duration=6500us + +- Remove trailing 6 entries, which is equivalent to define RECORD_GAP_MICROS < 15000, to enable successful B&O decode +Protocol=Bang&Olufsen Address=0xF1, Command=0x76, Raw-Data=0xF176, 16 bits, MSB first, Gap=12750us, Duration=115150us +Send with: IrSender.sendBang&Olufsen(0xF1, 0x76, ); +rawIRTimings[38]: + -12750 + + 250,-2850 + + 250,-9050 + 250,-5950 + 250,-5950 + 300,-5950 + + 250,-2850 + 250,-5950 + 300,-5900 + 300,-9000 + + 250,-2900 + 250,-9050 + 250,-5950 + 300,-5900 + + 300,-2850 + 300,-9000 + 250,-5950 + 250,-2850 + + 300,-12100 + 300 +Duration=115150us + + +Send next protocols with IrSender.write Send JVC -Protocol=JVC Address=0xF1 Command=0x76 Raw-Data=0x76F1 16 bits LSB first +Protocol=JVC Address=0xF1, Command=0x76, Raw-Data=0x76F1, 16 bits, LSB first, Gap=805500us, Duration=40700us Send with: IrSender.sendJVC(0xF1, 0x76, ); -rawData[36]: - -1037050 - +8400,-4150 - + 500,-1600 + 550,- 500 + 500,- 550 + 550,- 500 - + 550,-1550 + 550,-1550 + 500,-1600 + 550,-1550 - + 550,- 500 + 550,-1550 + 550,-1550 + 500,- 550 - + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500 - + 550 -Sum: 40400 +rawIRTimings[36]: + -805500 + +8450,-4100 + + 650,-1500 + 600,- 450 + 600,- 450 + 600,- 500 + + 550,-1550 + 600,-1500 + 600,-1500 + 550,-1600 + + 550,- 500 + 600,-1500 + 600,-1500 + 600,- 500 + + 550,-1550 + 600,-1500 + 600,-1500 + 600,- 500 + + 600 +Duration=40700us -Send Samsung -Protocol=Samsung Address=0xFFF1 Command=0x9876 Raw-Data=0x9876FFF1 32 bits LSB first -Send with: IrSender.sendSamsung(0xFFF1, 0x9876, ); -rawData[68]: - -1036350 - +4450,-4400 - + 550,-1700 + 600,- 550 + 550,- 550 + 600,- 550 - + 550,-1650 + 600,-1650 + 600,-1650 + 550,-1650 - + 550,-1700 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,-1650 - + 550,- 550 + 600,-1650 + 550,-1700 + 550,- 550 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,- 550 - + 550,- 550 + 600,- 550 + 550,- 550 + 600,-1650 - + 550,-1650 + 600,- 550 + 600,- 500 + 600,-1700 - + 550 -Sum: 68750 Send LG -Protocol=LG Address=0xF1 Command=0x9876 Raw-Data=0xF19876E 28 bits MSB first +Protocol=LG Address=0xF1, Command=0x9876, Raw-Data=0xF19876E, 28 bits, MSB first, Gap=745900us, Duration=59900us Send with: IrSender.sendLG(0xF1, 0x9876, ); -rawData[60]: - -1054900 - +9000,-4150 - + 450,-1600 + 500,-1550 + 500,-1550 + 500,-1600 - + 500,- 550 + 500,- 550 + 500,- 550 + 500,-1550 - + 500,-1600 + 500,- 550 + 500,- 550 + 450,-1600 - + 500,-1600 + 500,- 550 + 500,- 550 + 500,- 550 - + 500,- 550 + 500,-1550 + 500,-1550 + 550,-1550 - + 500,- 550 + 500,-1550 + 500,-1600 + 500,- 550 - + 500,-1550 + 500,-1550 + 500,-1600 + 500,- 550 - + 500 -Sum: 59350 +rawIRTimings[60]: + -745900 + +8350,-4150 + + 550,-1550 + 600,-1550 + 550,-1550 + 550,-1550 + + 600,- 550 + 500,- 550 + 550,- 550 + 550,-1550 + + 550,-1550 + 550,- 550 + 550,- 550 + 550,-1550 + + 550,-1550 + 550,- 550 + 550,- 550 + 550,- 550 + + 550,- 550 + 550,-1550 + 550,-1550 + 550,-1550 + + 550,- 550 + 550,-1550 + 550,-1550 + 550,- 550 + + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 550 + + 550 +Duration=59900us -Send MagiQuest -Protocol=MagiQuest Address=0xFFF1 Command=0x76 Raw-Data=0x6BCDFFF1 56 bits MSB first -Send with: IrSender.sendMagiQuest(0x6BCDFFF1, 0x76, ); -rawData[112]: - -1049950 - + 250,- 850 + 250,- 900 + 250,- 900 + 250,- 900 - + 250,- 900 + 300,- 850 + 250,- 900 + 250,- 900 - + 600,- 550 + 600,- 550 + 300,- 850 + 550,- 600 - + 250,- 900 + 550,- 600 + 550,- 600 + 550,- 600 - + 550,- 600 + 300,- 850 + 250,- 900 + 550,- 600 - + 550,- 600 + 300,- 850 + 550,- 600 + 550,- 600 - + 550,- 600 + 550,- 600 + 550,- 600 + 550,- 600 - + 550,- 600 + 550,- 600 + 550,- 600 + 550,- 600 - + 550,- 600 + 550,- 600 + 600,- 550 + 300,- 900 - + 250,- 900 + 250,- 900 + 550,- 550 + 300,- 850 - + 250,- 900 + 550,- 600 + 550,- 600 + 550,- 600 - + 300,- 850 + 550,- 600 + 550,- 600 + 250,- 900 - + 300,- 850 + 300,- 850 + 600,- 550 + 550,- 600 - + 300,- 850 + 550,- 600 + 550,- 600 + 550 -Sum: 63750 - -Send Bang&Olufsen -Protocol=Bang&Olufsen Address=0xF1 Command=0x76 Raw-Data=0xF176 16 bits MSB first -Send with: IrSender.sendBang&Olufsen(0xF1, 0x76, ); -rawData[44]: - -1078450 - + 150,-2850 - + 200,-2900 + 200,-15300 + 200,-2900 + 200,-9100 - + 250,-5950 + 250,-5950 + 250,-5950 + 200,-2900 - + 200,-6000 + 200,-6000 + 200,-9100 + 200,-2900 - + 200,-9100 + 250,-5950 + 250,-5950 + 250,-2850 - + 200,-9100 + 250,-5950 + 250,-2850 + 200,-12200 - + 200 -Sum: 136500 Send Bosewave with no address and 8 command bits -Protocol=BoseWave Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first +Protocol=BoseWave Address=0x0, Command=0x76, Raw-Data=0x8976, 16 bits, LSB first, Gap=762400us, Duration=27150us Send with: IrSender.sendBoseWave(0x0, 0x76, ); -rawData[36]: - -1044750 - +1050,-1450 - + 550,- 450 + 550,-1400 + 550,-1450 + 550,- 450 - + 500,-1450 + 550,-1450 + 500,-1450 + 550,- 450 - + 550,-1400 + 550,- 450 + 550,- 450 + 550,-1450 - + 500,- 500 + 500,- 450 + 550,- 450 + 550,-1450 - + 500 -Sum: 26750 +rawIRTimings[36]: + -762400 + +1100,-1400 + + 600,- 450 + 550,-1400 + 600,-1400 + 600,- 450 + + 550,-1400 + 600,-1400 + 600,-1400 + 600,- 450 + + 550,-1400 + 600,- 450 + 550,- 400 + 650,-1350 + + 600,- 450 + 550,- 450 + 550,- 450 + 600,-1400 + + 600 +Duration=27150us + Send FAST -Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first -Send with: IrSender.sendFAST(0x0, 0x76, ); -rawData[36]: - -1036750 - +2100,-1050 - + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500 - + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500 - + 550,-1550 + 550,- 500 + 550,- 500 + 550,-1550 - + 550,- 500 + 550,- 500 + 550,- 500 + 550,-1550 - + 550 -Sum: 28900 - -Force buffer overflow by sending 280 marks and spaces -Overflow -Try to increase the "RAW_BUFFER_LENGTH" value of 150 in ../src/UnitTest.cpp -rawData[150]: - -1040000 - + 250,- 500 - + 200,- 600 + 200,- 550 + 200,- 500 + 200,- 550 - + 200,- 550 + 250,- 500 + 250,- 550 + 200,- 550 - + 250,- 500 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,-1300 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 250,- 500 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 500 + 250,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 500 + 250,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 550 + 200,- 550 + 200,- 550 - + 200,- 550 + 250,- 500 + 200,- 550 + 200,- 550 - + 200,- 550 + 200,- 500 + 250,- 550 + 200,- 500 - + 250,- 550 + 200,- 550 + 250,- 500 + 200,- 550 - + 200,- 550 + 200 -Sum: 56500 -ERROR: Unknown protocol - - -address=0xF2 command=0x87 +Protocol=FAST Address=0x0, Command=0x76, Raw-Data=0x8976, 16 bits, LSB first, Gap=746700us, Duration=29250us +Send with: IrSender.sendFAST(0x76, ); +rawIRTimings[36]: + -746700 + +2200,-1000 + + 600,- 450 + 600,-1550 + 550,-1550 + 600,- 450 + + 600,-1500 + 600,-1550 + 550,-1550 + 550,- 500 + + 600,-1500 + 600,- 500 + 550,- 500 + 600,-1550 + + 550,- 500 + 600,- 450 + 600,- 500 + 550,-1550 + + 600 +Duration=29250us -Send NEC with 8 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first + +Force buffer overflow by sending 450 marks and spaces +rawIRTimings[400]: + -745550 + + 250,- 550 + + 250,- 500 + 300,- 500 + 300,- 450 + 300,- 450 + + 300,- 500 + 250,- 500 + 200,- 550 + 300,- 500 + + 300,- 450 + 250,- 500 + 300,- 500 + 250,- 500 + + 250,- 550 + 200,- 550 + 250,- 500 + 250,- 550 + + 200,- 550 + 200,- 550 + 200,- 550 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 300,- 450 + + 300,- 450 + 300,- 500 + 200,- 550 + 200,- 550 + + 300,- 500 + 200,- 550 + 300,- 500 + 250,- 500 + + 300,- 500 + 200,- 550 + 200,- 550 + 250,- 500 + + 300,- 500 + 250,- 500 + 300,- 450 + 300,- 500 + + 300,- 450 + 250,- 500 + 300,- 500 + 250,- 500 + + 200,- 550 + 300,- 500 + 250,- 500 + 250,- 500 + + 300,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 200,- 550 + 250,- 500 + 300,- 500 + 250,- 500 + + 200,- 550 + 200,- 550 + 300,- 500 + 250,- 500 + + 200,- 600 + 250,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 500 + 300,- 500 + 200,- 550 + + 200,- 550 + 250,- 550 + 250,- 500 + 200,- 550 + + 300,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 200,- 550 + 250,- 500 + 300,- 500 + 250,- 500 + + 250,- 500 + 250,- 550 + 200,- 550 + 200,- 550 + + 250,- 550 + 250,- 500 + 250,- 500 + 200,- 600 + + 250,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 200,- 550 + 250,- 500 + 300,- 500 + 250,- 500 + + 300,- 500 + 250,- 500 + 300,- 450 + 250,- 500 + + 300,- 500 + 250,- 500 + 200,- 550 + 300,- 500 + + 200,- 550 + 300,- 500 + 200,- 550 + 250,- 500 + + 300,- 500 + 300,- 450 + 300,- 450 + 300,- 500 + + 300,- 450 + 200,- 550 + 300,- 500 + 250,- 500 + + 250,- 500 + 250,- 550 + 250,- 500 + 300,- 450 + + 300,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 300,- 450 + + 250,- 500 + 300,- 500 + 250,- 500 + 250,- 500 + + 300,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 500 + 250,- 550 + 250,- 500 + 300,- 500 + + 250,- 500 + 250,- 500 + 250,- 550 + 200,- 550 + + 250,- 500 + 250,- 550 + 250,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 550 + 200,- 550 + + 250,- 500 + 250,- 550 + 200,- 550 + 250,- 500 + + 250,- 550 + 200,- 550 + 250,- 500 + 250,- 550 + + 200,- 600 + 200,- 500 + 250,- 550 + 200,- 550 + + 250,- 550 + 200,- 550 + 250,- 550 + 200,- 550 + + 200,- 550 + 250,- 500 + 250,- 550 + 200,- 600 + + 200,- 550 + 200,- 550 + 250,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 550 + 200,- 600 + + 200,- 550 + 200,- 550 + 200,- 550 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 550 + 200,- 550 + + 250,- 550 + 200,- 550 + 200 +Duration=152950us + +Invert toggle value for next loop +Stop receiver +Start receiver + +address=0xF2 command=0x87 repeats=1 + +Send NEC with 8 bit address and complete NEC frames as repeats to force decoding as NEC2 +Protocol=NEC Address=0xF2, Command=0x87, Raw-Data=0x78870DF2, 32 bits, LSB first, Gap=915400us, Duration=67850us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -3276750 - +8850,-4500 - + 550,- 500 + 600,-1650 + 600,- 500 + 600,- 550 - + 600,-1600 + 600,-1650 + 600,-1650 + 600,-1650 - + 600,-1600 + 600,- 550 + 600,-1650 + 550,-1650 - + 600,- 550 + 550,- 550 + 600,- 550 + 550,- 550 - + 600,-1650 + 600,-1600 + 600,-1650 + 600,- 550 - + 550,- 550 + 600,- 550 + 550,- 550 + 600,-1650 - + 600,- 500 + 550,- 600 + 550,- 550 + 600,-1650 - + 550,-1700 + 550,-1650 + 600,-1650 + 600,- 500 +rawIRTimings[68]: + -915400 + +8900,-4450 + + 600,- 500 + 600,-1650 + 700,- 450 + 600,- 500 + + 650,-1600 + 650,-1600 + 650,-1600 + 600,-1600 + + 600,-1650 + 650,- 500 + 600,-1650 + 600,-1600 + + 650,- 500 + 600,- 550 + 650,- 450 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 650,-1600 + + 650,- 450 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,-1600 + 650,-1600 + 600,-1600 + 650,- 500 + 600 -Sum: 67600 +Duration=67850us + + +Protocol=NEC2 Address=0xF2, Command=0x87, Raw-Data=0x78870DF2, 32 bits, LSB first, Repeat, Gap=69250us, Duration=67900us +Send with: IrSender.sendNEC2(0xF2, 0x87, ); +rawIRTimings[68]: + -69250 + +8900,-4450 + + 600,- 500 + 650,-1600 + 700,- 450 + 600,- 500 + + 600,-1650 + 600,-1650 + 650,-1600 + 650,-1600 + + 600,-1600 + 650,- 500 + 600,-1650 + 600,-1650 + + 650,- 450 + 600,- 550 + 650,- 450 + 600,- 550 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,- 500 + + 650,- 500 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1600 + + 650,-1600 + 600,-1650 + 600,-1600 + 650,- 500 + + 650 +Duration=67900us + Send NEC with 16 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first +Protocol=NEC Address=0xF2, Command=0x87, Raw-Data=0x78870DF2, 32 bits, LSB first, Gap=765500us, Duration=67850us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -998700 - +8900,-4400 - + 600,- 500 + 600,-1650 + 600,- 550 + 600,- 500 - + 600,-1650 + 600,-1600 + 600,-1650 + 600,-1650 - + 600,-1600 + 650,- 500 + 600,-1650 + 600,-1600 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,- 500 - + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 - + 600,- 500 + 600,- 550 + 600,- 500 + 600,-1650 +rawIRTimings[68]: + -765500 + +8950,-4350 + + 600,- 550 + 700,-1550 + 650,- 450 + 650,- 500 + + 650,-1600 + 600,-1650 + 600,-1600 + 650,-1600 + + 600,-1650 + 650,- 500 + 600,-1650 + 650,-1600 + + 600,- 500 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1650 + 650,-1550 + 650,-1600 + 650,- 500 + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1600 - + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 + + 650,- 500 + 600,- 500 + 650,- 500 + 650,-1600 + + 650,-1600 + 600,-1600 + 650,-1600 + 650,- 500 + 600 -Sum: 67650 +Duration=67850us + Send NEC2 with 16 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first +Protocol=NEC Address=0xF2, Command=0x87, Raw-Data=0x78870DF2, 32 bits, LSB first, Gap=745150us, Duration=67900us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -1055100 - +8950,-4400 - + 600,- 500 + 650,-1600 + 650,- 500 + 600,- 500 +rawIRTimings[68]: + -745150 + +8900,-4450 + + 600,- 500 + 650,-1600 + 600,- 550 + 600,- 500 + 650,-1600 + 650,-1600 + 650,-1600 + 600,-1600 - + 650,-1600 + 650,- 500 + 650,-1600 + 600,-1600 - + 650,- 500 + 600,- 500 + 650,- 500 + 600,- 500 - + 650,-1600 + 600,-1650 + 600,-1650 + 600,- 500 - + 650,- 500 + 600,- 500 + 650,- 500 + 600,-1650 - + 600,- 500 + 600,- 550 + 600,- 500 + 600,-1650 - + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,-1600 + 650,- 500 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,- 500 + 650,- 500 + 600,- 500 + + 650,-1600 + 600,-1650 + 600,-1650 + 650,- 450 + + 600,- 550 + 650,- 500 + 600,- 500 + 600,-1650 + + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 + + 600,-1650 + 650,-1550 + 600,-1650 + 650,- 500 + + 600 + + +Send NEC with TinyIRSender +Protocol=NEC Address=0xF2, Command=0x87, Raw-Data=0x78870DF2, 32 bits, LSB first, Gap=744800us, Duration=75100us +Send with: IrSender.sendNEC(0xF2, 0x87, ); +rawIRTimings[68]: + -744800 + +8950,-5250 + + 550,- 650 + 650,-1900 + 650,- 550 + 550,- 700 + + 650,-1900 + 650,-1900 + 600,-1950 + 600,-1950 + + 650,-1900 + 600,- 600 + 550,-2000 + 650,-1900 + + 600,- 600 + 650,- 600 + 600,- 600 + 650,- 600 + + 600,-1950 + 600,-1950 + 650,-1900 + 600,- 600 + + 550,- 700 + 650,- 550 + 650,- 600 + 600,-1950 + + 650,- 550 + 650,- 550 + 650,- 600 + 600,-1950 + + 600,-1950 + 600,-1950 + 600,-1950 + 600,- 600 + + 600 +Duration=75100us + + +Send FAST with TinyIRSender +Protocol=FAST Address=0x0, Command=0x87, Raw-Data=0x7887, 16 bits, LSB first, Gap=745000us, Duration=32150us +Send with: IrSender.sendFAST(0x87, ); +rawIRTimings[36]: + -745000 + +2050,-1250 + + 600,-1800 + 600,-1800 + 550,-1800 + 600,- 550 + + 500,- 650 + 550,- 600 + 550,- 600 + 600,-1800 + + 550,- 600 + 550,- 600 + 550,- 550 + 550,-1850 + + 600,-1800 + 600,-1750 + 600,-1800 + 550,- 600 + 600 -Sum: 67800 +Duration=32150usDuration=67900us + Send Onkyo (NEC with 16 bit command) -Protocol=Onkyo Address=0xF2 Command=0x8887 Raw-Data=0x888700F2 32 bits LSB first +Protocol=Onkyo Address=0xF2, Command=0x8887, Raw-Data=0x888700F2, 32 bits, LSB first, Gap=745700us, Duration=62350us Send with: IrSender.sendOnkyo(0xF2, 0x8887, ); -rawData[68]: - -1053400 - +8850,-4400 - + 600,- 550 + 600,-1650 + 600,- 500 + 600,- 550 - + 600,-1600 + 600,-1650 + 600,-1650 + 550,-1650 - + 600,- 550 + 550,- 550 + 650,- 500 + 550,- 550 - + 600,- 550 + 600,- 500 + 600,- 550 + 550,- 550 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,- 550 - + 550,- 550 + 600,- 550 + 550,- 550 + 600,-1650 - + 600,- 500 + 600,- 550 + 550,- 550 + 600,-1650 - + 600,- 500 + 600,- 550 + 600,- 500 + 600,-1650 +rawIRTimings[68]: + -745700 + +8950,-4400 + + 650,- 500 + 600,-1650 + 650,- 450 + 600,- 550 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,-1600 + + 650,- 500 + 600,- 500 + 600,- 550 + 650,- 500 + + 600,- 500 + 600,- 550 + 650,- 500 + 600,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,- 500 + 650,- 500 + 650,-1600 + + 650,- 450 + 650,- 500 + 650,- 500 + 600,-1650 + 600 -Sum: 62050 +Duration=62350us + Send Apple -Protocol=Apple Address=0xF2 Command=0x87 Raw-Data=0xF28787EE 32 bits LSB first +Protocol=Apple Address=0xF2, Command=0x87, Raw-Data=0xF28787EE, 32 bits, LSB first, Gap=744200us, Duration=71250us Send with: IrSender.sendApple(0xF2, 0x87, ); -rawData[68]: - -1054100 +rawIRTimings[68]: + -744200 + +8950,-4400 + + 650,- 500 + 600,-1600 + 650,-1600 + 650,-1600 + + 600,- 550 + 600,-1600 + 650,-1600 + 650,-1600 + + 600,-1650 + 600,-1600 + 650,-1600 + 600,- 550 + + 600,- 500 + 600,- 550 + 650,- 500 + 600,-1600 + + 650,-1600 + 600,-1650 + 650,-1600 + 650,- 450 + + 600,- 550 + 600,- 550 + 600,- 500 + 700,-1550 + + 600,- 550 + 650,-1600 + 650,- 450 + 650,- 500 + + 650,-1600 + 600,-1650 + 600,-1600 + 600,-1650 + + 650 +Duration=71250us + + +Send Panasonic +Protocol=Panasonic Address=0xF2, Command=0x87, Raw-Data=0xA8870F20, 48 bits, LSB first, Gap=744250us, Duration=60100us +Send with: IrSender.sendPanasonic(0xF2, 0x87, ); +rawIRTimings[100]: + -744250 + +3400,-1750 + + 500,- 400 + 450,-1300 + 500,- 400 + 450,- 400 + + 450,- 450 + 500,- 400 + 500,- 400 + 500,- 350 + + 450,- 450 + 500,- 400 + 500,- 350 + 550,- 350 + + 500,- 400 + 500,-1250 + 450,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 450,- 400 + 500,- 400 + + 500,- 400 + 450,-1250 + 550,- 350 + 550,- 350 + + 500,-1250 + 500,-1250 + 450,-1250 + 500,-1250 + + 500,- 400 + 500,- 400 + 500,- 350 + 450,- 450 + + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 400 + + 450,- 400 + 550,- 350 + 500,- 400 + 450,-1250 + + 550,- 350 + 500,- 400 + 500,- 350 + 500,-1250 + + 450,- 450 + 500,-1250 + 500,- 400 + 450,-1300 + + 400 +Duration=60100us + + +Send Kaseikyo with extra=0x4711 as Vendor ID +Protocol=Kaseikyo Address=0xF2, Command=0x87, Extra=0x4711, Raw-Data=0xAB870F23, 48 bits, LSB first, Gap=764450us, Duration=67100us +Send with: IrSender.sendKaseikyo(0xF2, 0x87, , 0x4711); +rawIRTimings[100]: + -764450 + +3500,-1700 + + 500,-1250 + 500,- 400 + 400,- 450 + 550,- 350 + + 500,-1250 + 500,- 400 + 450,- 450 + 450,- 400 + + 500,-1250 + 500,-1250 + 450,-1300 + 500,- 400 + + 500,- 400 + 450,- 400 + 500,-1250 + 500,- 350 + + 500,-1250 + 550,-1200 + 500,- 400 + 500,- 350 + + 500,- 400 + 500,-1250 + 500,- 400 + 400,- 500 + + 450,-1250 + 500,-1250 + 500,-1250 + 500,-1250 + + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 400 + + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 350 + + 500,- 400 + 500,- 400 + 500,- 350 + 550,-1200 + + 500,-1250 + 500,-1250 + 500,- 400 + 450,-1250 + + 550,- 350 + 500,-1250 + 500,- 400 + 450,-1300 + + 500 +Duration=67100us + + +Send Kaseikyo_Denon variant +Protocol=Kaseikyo_Denon Address=0xF2, Command=0x87, Raw-Data=0xA8870F20, 48 bits, LSB first, Gap=764750us, Duration=63650us +Send with: IrSender.sendKaseikyo_Denon(0xF2, 0x87, ); +rawIRTimings[100]: + -764750 + +3550,-1650 + + 500,- 400 + 500,- 400 + 500,-1200 + 550,- 350 + + 450,-1300 + 450,- 400 + 550,-1200 + 450,- 450 + + 500,- 400 + 400,-1300 + 550,- 350 + 500,- 400 + + 450,-1300 + 500,-1250 + 450,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 400,- 450 + 500,- 400 + + 450,- 450 + 400,-1300 + 500,- 450 + 450,- 400 + + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1200 + + 500,- 400 + 450,- 450 + 500,- 400 + 500,- 350 + + 500,-1250 + 450,-1300 + 500,-1250 + 500,- 400 + + 450,- 400 + 500,- 400 + 500,- 400 + 500,-1250 + + 400,- 500 + 450,- 400 + 500,- 400 + 500,-1250 + + 500,- 350 + 450,-1300 + 500,- 400 + 500,-1250 + + 500 +Duration=63650us + + +Send Denon with 2 autorepeats after 45 ms +Protocol=Denon Address=0x12, Command=0x87, Raw-Data=0x10F2, 15 bits, LSB first, Gap=765050us, Duration=22400us +Send with: IrSender.sendDenon(0x12, 0x87, ); +rawIRTimings[32]: + -765050 + + 350,- 700 + 350,-1750 + 350,- 700 + 350,- 700 + + 350,-1750 + 350,-1750 + 350,-1750 + 350,-1700 + + 300,- 800 + 300,- 750 + 300,- 750 + 300,- 750 + + 300,-1750 + 350,- 750 + 300,- 750 + 350 +Duration=22400us + + +Send Denon/Sharp variant with 2 autorepeat5 after 45 ms +Protocol=Sharp Address=0x12, Command=0x87, Raw-Data=0x30F2, 15 bits, LSB first, Gap=728100us, Duration=23400us +Send with: IrSender.sendSharp(0x12, 0x87, ); +rawIRTimings[32]: + -728100 + + 350,- 700 + 300,-1800 + 350,- 700 + 300,- 750 + + 350,-1750 + 300,-1800 + 300,-1750 + 350,-1750 + + 350,- 700 + 350,- 750 + 300,- 750 + 300,- 750 + + 300,-1800 + 300,-1750 + 350,- 700 + 350 +Duration=23400us + + +Send Sony/SIRCS with 7 command and 5 address bits +Protocol=Sony Address=0x12, Command=0x7, Raw-Data=0x907, 12 bits, LSB first, Gap=727550us, Duration=20000us +Send with: IrSender.sendSony(0x12, 0x7, , 12); +rawIRTimings[26]: + -727550 + +2450,- 550 + +1300,- 500 +1250,- 600 +1250,- 550 + 650,- 550 + + 650,- 550 + 700,- 550 + 650,- 550 + 650,- 550 + +1250,- 600 + 700,- 500 + 700,- 500 +1250 +Duration=20000us + + +Send Sony/SIRCS with 7 command and 8 address bits +Protocol=Sony Address=0xF2, Command=0x7, Raw-Data=0x7907, 15 bits, LSB first, Gap=725050us, Duration=25400us +Send with: IrSender.sendSony(0xF2, 0x7, , 15); +rawIRTimings[32]: + -725050 + +2450,- 550 + +1300,- 500 +1250,- 550 +1300,- 500 + 700,- 550 + + 700,- 500 + 700,- 500 + 700,- 550 + 700,- 500 + +1250,- 550 + 650,- 550 + 650,- 600 +1300,- 500 + +1250,- 550 +1250,- 550 +1250 +Duration=25400us + + +Send Sony/SIRCS with 7 command and 13 address bits and no repeats +Protocol=Sony Address=0xF2, Command=0x7, Raw-Data=0x7907, 20 bits, LSB first, Gap=729700us, Duration=31500us +Send with: IrSender.sendSony(0xF2, 0x7, , 20); +rawIRTimings[42]: + -729700 + +2400,- 600 + +1250,- 550 +1300,- 500 +1250,- 550 + 700,- 550 + + 650,- 550 + 700,- 500 + 700,- 550 + 650,- 550 + +1300,- 500 + 650,- 550 + 700,- 550 +1250,- 550 + +1250,- 550 +1300,- 500 +1250,- 550 + 650,- 600 + + 650,- 550 + 650,- 550 + 700,- 550 + 650 +Duration=31500us + + +Send Samsung 8 bit command and 8 bit address +Protocol=Samsung Address=0xF2, Command=0x87, Raw-Data=0x7887F2F2, 32 bits, LSB first, Gap=752900us, Duration=65650us +Send with: IrSender.sendSamsung(0xF2, 0x87, ); +rawIRTimings[68]: + -752900 + +4500,-4450 + + 600,- 500 + 650,-1600 + 650,- 500 + 600,- 500 + + 650,-1600 + 650,-1600 + 600,-1650 + 600,-1600 + + 650,- 500 + 650,-1600 + 650,- 450 + 650,- 500 + + 600,-1650 + 650,-1550 + 650,-1600 + 600,-1650 + + 600,-1650 + 650,-1600 + 600,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 600,- 550 + 650,-1550 + + 650,- 500 + 600,- 550 + 650,- 450 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 600 +Duration=65650us + + +Send Samsung 8 bit command and 16 bit address +Protocol=Samsung Address=0xF2, Command=0x87, Raw-Data=0x788700F2, 32 bits, LSB first, Gap=747150us, Duration=60150us +Send with: IrSender.sendSamsung(0xF2, 0x87, ); +rawIRTimings[68]: + -747150 + +4500,-4400 + + 650,- 500 + 650,-1600 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,-1600 + + 600,- 550 + 600,- 500 + 600,- 550 + 650,- 500 + + 600,- 500 + 650,- 500 + 600,- 500 + 700,- 450 + + 650,-1600 + 650,-1600 + 600,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 650,- 500 + 650,-1600 + + 650,- 450 + 650,- 500 + 650,- 500 + 600,-1600 + + 650,-1600 + 650,-1600 + 600,-1600 + 650,- 500 + + 650 +Duration=60150us + + +Send Samsung 16 bit command and address +Protocol=Samsung Address=0xF2, Command=0xA987, Raw-Data=0xA98700F2, 32 bits, LSB first, Gap=746700us, Duration=60200us +Send with: IrSender.sendSamsung(0xF2, 0xA987, ); +rawIRTimings[68]: + -746700 + +4450,-4450 + + 650,- 500 + 600,-1650 + 600,- 500 + 600,- 550 + + 650,-1600 + 600,-1650 + 600,-1600 + 600,-1650 + + 600,- 550 + 650,- 500 + 600,- 500 + 600,- 550 + + 600,- 550 + 600,- 500 + 700,- 450 + 600,- 500 + + 650,-1600 + 650,-1600 + 600,-1650 + 600,- 500 + + 600,- 550 + 600,- 550 + 600,- 500 + 600,-1650 + + 650,-1600 + 650,- 500 + 650,- 500 + 600,-1600 + + 600,- 550 + 600,-1650 + 600,- 500 + 650,-1600 + + 650 +Duration=60200us + + +Send Samsung48 16 bit command +Protocol=Samsung48 Address=0xF2, Command=0xA987, Raw-Data=0x56A9, 48 bits, LSB first, Gap=746150us, Duration=87100us +Send with: IrSender.sendSamsung48(0xF2, 0xA987, ); +rawIRTimings[100]: + -746150 + +4550,-4350 + + 650,- 500 + 650,-1600 + 600,- 550 + 600,- 500 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,-1600 + + 600,- 500 + 650,- 500 + 650,- 500 + 600,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 550 + + 650,-1550 + 650,-1600 + 650,-1600 + 650,- 500 + + 600,- 500 + 650,- 500 + 650,- 500 + 600,-1600 + + 600,- 550 + 650,- 500 + 600,- 500 + 650,-1600 + + 650,-1600 + 600,-1600 + 600,-1650 + 650,- 500 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,-1650 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,-1600 + 650,-1600 + 600,- 550 + + 600,-1650 + 600,- 500 + 650,-1600 + 650,- 500 + + 600 +Duration=87100us + + +Send RC5 +Protocol=RC5 Address=0x12, Command=0x7, Toggle=1, Raw-Data=0x1C87, 13 bits, MSB first, Gap=762250us, Duration=24200us +Send with: IrSender.sendRC5(0x12, 0x7, ); +rawIRTimings[24]: + -762250 + + 950,- 850 + + 950,- 800 +1000,- 850 +1850,- 800 + 950,-1750 + +1800,- 850 + 950,- 850 + 950,- 800 +1000,-1700 + + 900,- 850 +1000,- 800 +1000 +Duration=24200us + + +Send RC5X with 7.th MSB of command set +Protocol=RC5 Address=0x12, Command=0x47, Raw-Data=0x487, 13 bits, MSB first, Gap=724200us, Duration=24150us +Send with: IrSender.sendRC5(0x12, 0x47, ); +rawIRTimings[22]: + -724200 + +1850,- 800 + + 950,-1750 +1800,- 850 + 950,-1750 +1850,- 800 + + 950,- 800 +1000,- 800 + 950,-1750 + 950,- 800 + +1000,- 800 +1000 +Duration=24150us + + +Send Marantz with RC5 and extra=0x38 +Protocol=Marantz Address=0x12, Command=0x7, Extra=0x38, Toggle=1, Raw-Data=0x721F8, 19 bits, MSB first, Gap=722250us, Duration=37500us +Send with: IrSender.sendMarantz(0x12, 0x7, , 0x38); +rawIRTimings[34]: + -722250 + + 950,- 850 + + 950,- 850 + 900,- 850 +1900,- 800 + 900,-1800 + +1800,-4350 +1000,- 800 + 950,- 850 + 950,-1750 + + 900,- 850 +1000,- 750 +1000,- 850 + 950,- 850 + + 900,- 850 +1850,- 800 +1000,- 850 + 900 +Duration=37500us + + +Send Marantz with RC5A and extra=0x38 +Protocol=Marantz Address=0x12, Command=0x47, Extra=0x38, Raw-Data=0x121F8, 19 bits, MSB first, Gap=732750us, Duration=37550us +Send with: IrSender.sendMarantz(0x12, 0x47, , 0x38); +rawIRTimings[32]: + -732750 + +1850,- 800 + + 950,-1700 +1850,- 850 + 900,-1800 +1800,-4400 + +1000,- 800 + 950,- 800 +1000,-1700 + 950,- 850 + + 950,- 850 + 900,- 900 + 950,- 800 + 950,- 850 + +1850,- 850 + 900,- 850 +1000 +Duration=37550us + + +Send RC6 +Protocol=RC6 Address=0xF2, Command=0x87, Toggle=1, Raw-Data=0x1F287, 20 bits, MSB first, Gap=727650us, Duration=23200us +Send with: IrSender.sendRC6(0xF2, 0x87, ); +rawIRTimings[36]: + -727650 + +2750,- 750 + + 550,- 800 + 600,- 350 + 550,- 400 +1400,- 850 + + 500,- 400 + 550,- 350 + 550,- 350 + 550,- 850 + + 550,- 350 +1000,- 850 + 950,- 850 + 550,- 350 + + 500,- 400 + 550,- 350 +1000,- 400 + 550,- 350 + + 550 +Duration=23200us + + +Send RC6A with 14 bit and extra=0x2711 +Protocol=RC6A Address=0xF2, Command=0x87, Extra=0x2711, Raw-Data=0x2711F287, 35 bits, MSB first, Gap=730650us, Duration=37000us +Send with: IrSender.sendRC6A(0xF2, 0x87, , 0x2711); +rawIRTimings[60]: + -730650 + +2750,- 800 + + 500,- 400 + 500,- 400 + 550,- 850 + 500,- 850 + + 950,- 400 +1000,- 850 + 500,- 400 +1000,- 400 + + 500,- 450 + 450,- 850 + 500,- 450 + 500,- 400 + + 950,- 900 + 500,- 400 + 500,- 400 +1050,- 350 + + 500,- 400 + 500,- 400 + 500,- 450 + 500,- 800 + + 600,- 350 +1000,- 850 +1000,- 800 + 550,- 400 + + 500,- 450 + 500,- 400 +1000,- 400 + 550,- 350 + + 500 +Duration=37000us + + +Send MagiQuest, WandId=0x6BCD00F2 +Protocol=MagiQuest Address=0xF2, Command=0x187, Raw-Data=0x6BCD00F2, 56 bits, MSB first, Gap=744850us, Duration=64800us +Send with: IrSender.sendMagiQuest(0x6BCD00F2, 0x187, ); +rawIRTimings[112]: + -744850 + + 400,- 750 + 400,- 800 + 350,- 800 + 400,- 800 + + 350,- 800 + 400,- 800 + 350,- 800 + 350,- 850 + + 650,- 550 + 600,- 550 + 350,- 800 + 600,- 600 + + 350,- 800 + 600,- 550 + 650,- 550 + 650,- 500 + + 650,- 500 + 400,- 800 + 350,- 800 + 650,- 550 + + 600,- 550 + 350,- 800 + 650,- 550 + 350,- 800 + + 400,- 800 + 350,- 800 + 400,- 800 + 350,- 800 + + 350,- 800 + 400,- 800 + 400,- 750 + 650,- 550 + + 600,- 550 + 650,- 500 + 700,- 500 + 350,- 800 + + 400,- 750 + 650,- 550 + 350,- 850 + 600,- 550 + + 650,- 550 + 350,- 800 + 350,- 800 + 350,- 850 + + 350,- 800 + 650,- 500 + 650,- 550 + 650,- 550 + + 400,- 750 + 400,- 800 + 600,- 550 + 350,- 800 + + 400,- 800 + 350,- 800 + 650,- 500 + 400 +Duration=64800us + + +Send OpenLASIR mode fire and color orange, detected as ONKYO +Protocol=Onkyo Address=0xF2, Command=0xC087, Raw-Data=0xC0870DF2, 32 bits, LSB first, Gap=793250us, Duration=65650us +Send with: IrSender.sendOnkyo(0xF2, 0xC087, ); +rawIRTimings[68]: + -793250 +8900,-4450 - + 550,- 550 + 600,-1650 + 600,-1650 + 600,-1650 - + 550,- 550 + 600,-1650 + 550,-1650 + 600,-1650 - + 600,-1650 + 600,-1650 + 550,-1650 + 600,- 550 - + 600,- 500 + 600,- 600 + 550,- 500 + 600,-1650 - + 600,-1650 + 550,-1650 + 600,-1650 + 600,- 500 - + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 - + 550,- 550 + 600,-1650 + 550,- 550 + 600,- 550 - + 550,-1650 + 600,-1650 + 600,-1650 + 550,-1650 + + 600,- 500 + 650,-1600 + 650,- 500 + 600,- 500 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,-1600 + + 650,-1600 + 650,- 450 + 600,-1650 + 650,-1600 + + 650,- 500 + 600,- 500 + 600,- 550 + 600,- 500 + + 650,-1600 + 650,-1600 + 600,-1650 + 650,- 450 + + 650,- 500 + 700,- 450 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,- 500 + 650,- 500 + 650,- 500 + + 600,- 500 + 600,- 550 + 600,-1650 + 600,-1650 + + 600 +Duration=65650us + + +Send Lego with 2 channel and with 4 command bits +Protocol=Lego Address=0x2, Command=0x17, Raw-Data=0x217B, 16 bits, MSB first, Gap=747400us, Duration=10850us +Send with: IrSender.sendLego(0x2, 0x17, ); +rawIRTimings[36]: + -747400 + + 250,- 950 + + 200,- 550 + 250,- 500 + 200,- 150 + 300,- 500 + + 200,- 500 + 250,- 500 + 250,- 500 + 250,- 200 + + 200,- 500 + 250,- 150 + 300,- 150 + 250,- 250 + + 200,- 250 + 250,- 450 + 250,- 200 + 250,- 150 + + 300 +Duration=10850us + + +Send 16 bit Bang&Olufsen - requires originally 455 kHz +- ENABLE_BEO_WITHOUT_FRAME_GAP is enabled +rawIRTimings[86]: + -749450 + + 250,-2850 + + 300,-2800 + 300,-12750 + 300,-2850 + 250,-9050 + + 300,-5900 + 300,-5900 + 250,-5950 + 300,-2850 + + 250,-5950 + 250,-9050 + 250,-2850 + 300,-9000 + + 300,-2800 + 250,-6000 + 250,-5950 + 300,-5900 + + 300,-9000 + 300,-5950 + 250,-5950 + 300,-12100 + + 300,-2850 + 300,-2800 + 250,-12750 + 250,-2850 + + 300,-9000 + 300,-5900 + 300,-5950 + 250,-5950 + + 250,-2850 + 300,-5900 + 300,-9000 + 300,-2850 + + 250,-9050 + 250,-2850 + 300,-5950 + 250,-5950 + + 250,-5950 + 300,-9000 + 300,-5900 + 250,-6000 + + 250,-12150 + 250 +Duration=274750us + +- Now try to decode the first 6 entries, which results in rawData 0x0 +Protocol=Bang&Olufsen Address=0x0, Command=0x0, Raw-Data=0x0, 0 bits, MSB first, Gap=749450us, Duration=6500us + +- Remove trailing 6 entries, which is equivalent to define RECORD_GAP_MICROS < 15000, to enable successful B&O decode +Protocol=Bang&Olufsen Address=0xF2, Command=0x87, Raw-Data=0xF287, 16 bits, MSB first, Gap=12750us, Duration=255500us +Send with: IrSender.sendBang&Olufsen(0xF2, 0x87, ); +rawIRTimings[80]: + -12750 + + 300,-2850 + + 250,-9050 + 300,-5900 + 300,-5900 + 250,-5950 + + 300,-2850 + 250,-5950 + 250,-9050 + 250,-2850 + + 300,-9000 + 300,-2800 + 250,-6000 + 250,-5950 + + 300,-5900 + 300,-9000 + 300,-5950 + 250,-5950 + + 300,-12100 + 300,-2850 + 300,-2800 + 250,-12750 + + 250,-2850 + 300,-9000 + 300,-5900 + 300,-5950 + + 250,-5950 + 250,-2850 + 300,-5900 + 300,-9000 + + 300,-2850 + 250,-9050 + 250,-2850 + 300,-5950 + + 250,-5950 + 250,-5950 + 300,-9000 + 300,-5900 + + 250,-6000 + 250,-12150 + 250 +Duration=255500us + + +Send next protocols with IrSender.write + +Send JVC +Protocol=JVC Address=0xF2, Command=0x87, Raw-Data=0x87F2, 16 bits, LSB first, Gap=850000us, Duration=39600us +Send with: IrSender.sendJVC(0xF2, 0x87, ); +rawIRTimings[36]: + -850000 + +8400,-4150 + + 650,- 400 + 600,-1500 + 650,- 450 + 600,- 500 + + 550,-1500 + 550,-1600 + 600,-1500 + 550,-1550 + + 600,-1500 + 600,-1500 + 600,-1550 + 550,- 500 + + 600,- 450 + 550,- 550 + 550,- 500 + 600,-1500 + + 600 +Duration=39600us + + +Send LG +Protocol=LG Address=0xF2, Command=0xA987, Raw-Data=0xF2A9872, 28 bits, MSB first, Gap=726100us, Duration=57800us +Send with: IrSender.sendLG(0xF2, 0xA987, ); +rawIRTimings[60]: + -726100 + +8950,-4150 + + 550,-1550 + 550,-1500 + 600,-1500 + 600,-1500 + + 550,- 500 + 650,- 450 + 550,-1500 + 550,- 500 + + 600,-1500 + 550,- 500 + 550,-1550 + 600,- 450 + + 600,-1500 + 600,- 450 + 600,- 450 + 600,-1500 + + 600,-1500 + 550,- 500 + 600,- 450 + 600,- 500 + + 550,- 500 + 600,-1500 + 550,-1500 + 600,-1500 + + 600,- 450 + 550,- 550 + 550,-1500 + 600,- 500 + + 600 +Duration=57800us + + +Send Bosewave with no address and 8 command bits +Protocol=BoseWave Address=0x0, Command=0x87, Raw-Data=0x7887, 16 bits, LSB first, Gap=762350us, Duration=27150us +Send with: IrSender.sendBoseWave(0x0, 0x87, ); +rawIRTimings[36]: + -762350 + +1100,-1400 + + 600,-1400 + 600,-1400 + 600,-1400 + 600,- 400 + + 600,- 450 + 600,- 400 + 550,- 450 + 550,-1450 + + 550,- 450 + 600,- 400 + 600,- 400 + 550,-1450 + + 600,-1400 + 600,-1400 + 550,-1450 + 600,- 450 + + 550 +Duration=27150us + + +Send FAST +Protocol=FAST Address=0x0, Command=0x87, Raw-Data=0x7887, 16 bits, LSB first, Gap=726950us, Duration=29200us +Send with: IrSender.sendFAST(0x87, ); +rawIRTimings[36]: + -726950 + +2200,-1000 + + 600,-1500 + 600,-1500 + 550,-1550 + 600,- 500 + + 600,- 500 + 550,- 500 + 550,- 500 + 600,-1500 + + 600,- 450 + 600,- 500 + 550,- 500 + 600,-1500 + + 600,-1550 + 600,-1500 + 550,-1550 + 600,- 500 + + 550 +Duration=29200us + + +Force buffer overflow by sending 450 marks and spaces +rawIRTimings[400]: + -725800 + + 300,- 450 + + 300,- 500 + 200,- 550 + 300,- 450 + 250,- 550 + + 300,- 450 + 300,- 450 + 300,- 500 + 250,- 500 + + 200,- 550 + 300,- 500 + 200,- 550 + 300,- 500 + + 250,- 500 + 200,- 600 + 250,- 500 + 250,- 500 + + 200,- 550 + 250,- 550 + 250,- 500 + 250,- 500 + + 200,- 550 + 300,- 500 + 200,- 550 + 250,- 500 + + 300,- 500 + 200,- 550 + 200,- 550 + 300,- 450 + + 300,- 500 + 200,- 550 + 200,- 550 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 250,- 500 + + 300,- 450 + 300,- 500 + 300,- 450 + 250,- 500 + + 300,- 500 + 250,- 500 + 300,- 450 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 250,- 500 + + 300,- 450 + 300,- 500 + 250,- 500 + 300,- 450 + + 300,- 500 + 250,- 500 + 250,- 500 + 300,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 250,- 500 + + 250,- 500 + 300,- 500 + 250,- 500 + 250,- 500 + + 300,- 500 + 250,- 500 + 200,- 550 + 300,- 500 + + 200,- 550 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 500 + 250,- 500 + 300,- 500 + 200,- 550 + + 200,- 550 + 300,- 500 + 250,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 500 + 300,- 500 + + 250,- 500 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 500 + 250,- 550 + 250,- 500 + 250,- 550 + + 250,- 500 + 300,- 450 + 300,- 500 + 250,- 500 + + 250,- 500 + 300,- 500 + 250,- 500 + 250,- 500 + + 250,- 500 + 300,- 500 + 250,- 500 + 300,- 500 + + 200,- 550 + 250,- 500 + 300,- 500 + 250,- 500 + + 300,- 450 + 200,- 600 + 250,- 500 + 300,- 450 + + 250,- 500 + 250,- 550 + 300,- 450 + 250,- 500 + + 250,- 550 + 200,- 550 + 250,- 500 + 250,- 550 + + 250,- 500 + 300,- 450 + 250,- 550 + 300,- 450 + + 200,- 550 + 300,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 500 + 250,- 550 + 250,- 500 + + 300,- 500 + 300,- 450 + 250,- 500 + 250,- 500 + + 300,- 500 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 500 + 300,- 450 + 300,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 500 + 200,- 550 + + 300,- 500 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 500 + 250,- 550 + 200,- 550 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 500 + 250,- 550 + 200,- 550 + + 250,- 550 + 250,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 500 + 250,- 550 + 250,- 500 + + 250,- 550 + 200,- 550 + 250,- 500 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 550 + 200,- 550 + 250,- 500 + + 250,- 550 + 250,- 500 + 250,- 500 + 250,- 550 + + 250,- 500 + 250,- 550 + 200,- 600 + 200,- 500 + + 250,- 500 + 250,- 550 + 200,- 550 + 250,- 500 + + 250,- 600 + 200,- 550 + 200 +Duration=152850us + +Invert toggle value for next loop +Stop receiver +Start receiver + +address=0x1F3 command=0x98 repeats=2 + +Send NEC with 8 bit address and complete NEC frames as repeats to force decoding as NEC2 +Protocol=NEC Address=0xF3, Command=0x98, Raw-Data=0x67980CF3, 32 bits, LSB first, Gap=915450us, Duration=67850us +Send with: IrSender.sendNEC(0xF3, 0x98, ); +rawIRTimings[68]: + -915450 + +8900,-4450 + + 600,-1600 + 650,-1600 + 600,- 550 + 600,- 500 + + 700,-1550 + 600,-1650 + 650,-1600 + 600,-1600 + + 600,- 550 + 600,- 550 + 650,-1600 + 600,-1600 + + 650,- 500 + 650,- 500 + 600,- 500 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1600 + + 650,-1600 + 650,- 500 + 650,- 450 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1600 + 650,- 500 + + 650,- 450 + 650,-1600 + 650,-1600 + 600,- 550 + 600 -Sum: 71000 +Duration=67850us + +Protocol=NEC2 Address=0xF3, Command=0x98, Raw-Data=0x67980CF3, 32 bits, LSB first, Repeat, Gap=69250us, Duration=67900us +Send with: IrSender.sendNEC2(0xF3, 0x98, ); +rawIRTimings[68]: + -69250 + +8900,-4400 + + 650,-1600 + 650,-1600 + 650,- 500 + 600,- 500 + + 650,-1600 + 650,-1600 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,- 500 + 650,-1600 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 550 + 600,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 650,-1600 + + 600,-1600 + 650,- 500 + 650,- 500 + 600,-1600 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,- 500 + + 600,- 550 + 600,-1650 + 600,-1600 + 650,- 500 + + 650 +Duration=67900us + + +Protocol=NEC2 Address=0xF3, Command=0x98, Raw-Data=0x67980CF3, 32 bits, LSB first, Repeat, Gap=69850us, Duration=67900us +Send with: IrSender.sendNEC2(0xF3, 0x98, ); +rawIRTimings[68]: + -69850 + +8950,-4400 + + 650,-1600 + 600,-1650 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1600 + 650,-1600 + 650,-1600 + + 600,- 550 + 600,- 500 + 650,-1600 + 650,-1600 + + 650,- 450 + 650,- 500 + 650,- 500 + 650,- 450 + + 600,- 550 + 650,- 450 + 650,- 500 + 650,-1600 + + 600,-1650 + 600,- 500 + 650,- 500 + 600,-1650 + + 650,-1550 + 650,-1600 + 650,-1600 + 650,- 500 + + 600,- 500 + 650,-1600 + 650,-1600 + 650,- 450 + + 650 +Duration=67900us diff --git a/examples/UnitTest/UnitTest_64bit.log b/examples/UnitTest/UnitTest_64bit.log index e69f1c73b..82e257d33 100644 --- a/examples/UnitTest/UnitTest_64bit.log +++ b/examples/UnitTest/UnitTest_64bit.log @@ -1,640 +1,740 @@ -START UnitTest.cpp from Feb 24 2023 -Using library version 4.1.0 -Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, Bang & Olufsen, FAST, Bosewave , MagiQuest, Universal Pulse Distance Width, Hash at pin 14 -Send IR signals at pin 12 -If you connect debug pin 13 to ground, raw data is always printed -Send signal mark duration for 38kHz is 8 us, pulse narrowing correction is 600 ns, total period is 26 us +START C:\Users\armin\AppData\Local\Temp\.arduinoIDE-unsaved2025614-8520-1rntouk.pt81h\UnitTest\UnitTest.ino from Jul 14 2025 +Using library version 4.4.2 +Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, Panasonic/Kaseikyo, Denon/Sharp, Sony, RC5, RC6, LG, JVC, Samsung, Bang & Olufsen, FAST, Bosewave, MagiQuest, Universal Pulse Distance Width, Hash at pin 15 +Use ReceiveCompleteCallback +Receive buffer length is 750 +Send IR signals at pin 4 +If you connect debug pin 16 to ground, raw data is always printed 16000 us is the (minimum) gap, after which the start of a new IR packet is assumed -100 us are subtracted from all marks and added to all spaces for decoding +20 us are subtracted from all marks and added to all spaces for decoding address=0xFFF1 command=0x76 Send NEC with 8 bit address -Protocol=NEC Address=0xF1 Command=0x76 Raw-Data=0x89760EF1 32 bits LSB first +Protocol=NEC Address=0xF1 Command=0x76 Raw-Data=0x89760EF1 32 bits LSB first Gap=1047000us Duration=68250us Send with: IrSender.sendNEC(0xF1, 0x76, ); -rawData[68]: - -1050650 +rawData[68]: + -1047000 +9050,-4450 - + 650,-1600 + 700,- 450 + 650,- 500 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,-1600 - + 700,- 450 + 650,-1600 + 650,-1650 + 650,-1600 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,- 450 - + 700,- 450 + 650,-1600 + 650,-1600 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,- 450 + 700,- 450 + 650,-1600 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,-1600 - + 700 -Sum: 68500 + + 600,-1650 + 600,- 550 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 550 + 600,- 500 + + 650,- 500 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 600,-1650 + 650,- 500 + 600,- 500 + 650,-1650 + + 600,- 500 + 600,- 550 + 600,- 550 + 600,-1650 + + 600 +Duration=68250us + Send NEC with 16 bit address -Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first +Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first Gap=1067700us Duration=73800us Send with: IrSender.sendNEC(0xFFF1, 0x76, ); -rawData[68]: - -1060200 - +9050,-4400 - + 650,-1600 + 650,- 500 + 650,- 450 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,- 500 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1650 + 650,- 450 - + 650,-1600 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 450 + 650,- 500 + 650,-1600 - + 650 -Sum: 74050 +rawData[68]: + -1067700 + +9050,-4450 + + 550,-1650 + 650,- 500 + 600,- 550 + 600,- 500 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,-1650 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,-1650 + + 650,-1600 + 650,-1600 + 650,-1600 + 650,-1600 + + 650,- 500 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,-1650 + 550,- 550 + 600,- 550 + 600,-1650 + + 600,- 500 + 600,- 550 + 600,- 500 + 650,-1650 + + 600 +Duration=73800us + Send NEC2 with 16 bit address -Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first +Protocol=NEC Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first Gap=1067300us Duration=73750us Send with: IrSender.sendNEC(0xFFF1, 0x76, ); -rawData[68]: - -1060450 - +9050,-4450 - + 650,-1600 + 650,- 500 + 650,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,- 500 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 500 - + 650,-1600 + 650,- 500 + 650,- 500 + 650,-1600 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650 -Sum: 74150 +rawData[68]: + -1067300 + +9000,-4450 + + 600,-1650 + 650,- 500 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 650,-1600 + 600,-1650 + 600,-1650 + + 600,- 550 + 650,-1600 + 600,-1650 + 600,- 500 + + 650,-1650 + 550,-1650 + 650,-1650 + 550,- 550 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,-1600 + + 650,- 500 + 600,- 550 + 650,- 450 + 650,-1650 + + 550 +Duration=73750us + Send NEC Pronto data with 8 bit address 0x80 and command 0x45 and no repeats -Protocol=NEC Address=0x80 Command=0x45 Raw-Data=0xBA457F80 32 bits LSB first +Protocol=NEC Address=0x80 Command=0x45 Raw-Data=0xBA457F80 32 bits LSB first Gap=1071500us Duration=68500us Send with: IrSender.sendNEC(0x80, 0x45, ); -rawData[68]: - -1065600 - +9200,-4400 - + 700,- 450 + 700,- 450 + 700,- 500 + 650,- 500 - + 700,- 500 + 650,- 500 + 650,- 550 + 700,-1550 - + 700,-1550 + 700,-1550 + 700,-1550 + 650,-1550 - + 700,-1550 + 700,-1550 + 700,-1550 + 700,- 450 - + 700,-1550 + 650,- 500 + 650,-1600 + 700,- 450 - + 700,- 450 + 700,- 450 + 700,-1550 + 700,- 450 - + 750,- 450 + 700,-1500 + 700,- 450 + 700,-1550 - + 700,-1550 + 700,-1550 + 700,- 450 + 700,-1550 +rawData[68]: + -1071500 + +9100,-4450 + + 600,- 550 + 650,- 500 + 650,- 550 + 600,- 550 + + 650,- 500 + 650,- 550 + 600,- 550 + 600,-1600 + + 650,-1600 + 700,-1550 + 650,-1600 + 550,-1600 + + 700,-1550 + 650,-1600 + 650,-1600 + 600,- 550 + + 650,-1550 + 650,- 500 + 650,-1600 + 650,- 500 + + 700,- 450 + 650,- 500 + 650,-1600 + 650,- 550 + + 650,- 450 + 700,-1550 + 650,- 500 + 650,-1600 + + 650,-1600 + 650,-1550 + 650,- 500 + 700,-1550 + 700 -Sum: 68800 +Duration=68500us + Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format) -Protocol=NEC Address=0x4 Command=0x8 Raw-Data=0xF708FB04 32 bits LSB first +Protocol=NEC Address=0x4 Command=0x8 Raw-Data=0xF708FB04 32 bits LSB first Gap=1073650us Duration=68450us Send with: IrSender.sendNEC(0x4, 0x8, ); -rawData[68]: - -1066550 - +9150,-4400 - + 650,- 500 + 650,- 450 + 700,-1600 + 650,- 450 - + 700,- 450 + 650,- 500 + 650,- 450 + 650,- 500 - + 650,-1600 + 700,-1600 + 650,- 450 + 700,-1600 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,-1650 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 700 -Sum: 68700 +rawData[68]: + -1073650 + +9050,-4450 + + 600,- 550 + 600,- 500 + 650,-1600 + 650,- 500 + + 600,- 550 + 600,- 550 + 600,- 550 + 550,- 550 + + 600,-1650 + 600,-1700 + 600,- 500 + 600,-1650 + + 600,-1650 + 650,-1650 + 600,-1650 + 600,-1650 + + 600,- 550 + 600,- 550 + 600,- 500 + 600,-1700 + + 600,- 500 + 600,- 550 + 600,- 550 + 600,- 500 + + 650,-1650 + 600,-1650 + 600,-1650 + 650,- 500 + + 600,-1650 + 600,-1650 + 650,-1600 + 650,-1650 + + 600 +Duration=68450us + Send ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102) -Protocol=Onkyo Address=0x102 Command=0x304 Raw-Data=0x3040102 32 bits LSB first +Protocol=Onkyo Address=0x102 Command=0x304 Raw-Data=0x3040102 32 bits LSB first Gap=1072150us Duration=55900us Send with: IrSender.sendOnkyo(0x102, 0x304, ); -rawData[68]: - -1064800 - +9050,-4450 - + 650,- 450 + 650,-1600 + 700,- 450 + 650,- 500 - + 650,- 450 + 650,- 500 + 650,- 500 + 650,- 450 - + 650,-1600 + 700,- 450 + 700,- 450 + 650,- 500 - + 650,- 450 + 650,- 500 + 650,- 450 + 700,- 450 - + 650,- 500 + 650,- 450 + 700,-1600 + 650,- 450 - + 650,- 500 + 650,- 450 + 650,- 500 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,- 500 + 650,- 450 - + 650,- 550 + 650,- 500 + 600,- 500 + 650,- 500 - + 650 -Sum: 56050 +rawData[68]: + -1072150 + +9050,-4400 + + 600,- 550 + 600,-1650 + 650,- 450 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 500 + + 650,-1650 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,- 500 + + 600,- 550 + 600,- 550 + 600,-1650 + 600,- 500 + + 650,- 500 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,- 550 + 600,- 550 + + 550,- 550 + 600,- 550 + 600,- 500 + 600,- 550 + + 600 +Duration=55900us + Send ONKYO with 16 bit address 0x0102 and command 0x34 with old 32 bit format MSB first (0x40802CD3) -Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first +Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 32 bits LSB first Gap=1074200us Duration=61500us Send with: IrSender.sendNEC(0x102, 0x34, ); -rawData[68]: - -1066900 - +9050,-4400 - + 650,- 500 + 650,-1600 + 650,- 500 + 650,- 450 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,- 500 - + 650,-1600 + 650,- 500 + 650,- 450 + 650,- 550 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,- 450 - + 650,- 500 + 650,- 450 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,- 500 + 650,- 450 - + 650,-1600 + 700,-1600 + 600,- 500 + 650,-1650 - + 650,- 450 + 700,- 450 + 650,-1600 + 650,-1600 - + 700 -Sum: 61700 +rawData[68]: + -1074200 + +9050,-4450 + + 600,- 500 + 600,-1650 + 600,- 550 + 600,- 500 + + 600,- 550 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,- 550 + 600,-1650 + + 600,- 500 + 600,- 550 + 600,-1650 + 650,-1600 + + 600 +Duration=61500us + -Send Panasonic 0xB, 0x10 as 48 bit generic PulseDistance using ProtocolConstants -Protocol=Panasonic Address=0x10B Command=0xA0 Raw-Data=0xA010B02002 48 bits LSB first +Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM using ProtocolConstants 1=432|1296, 0=432|432 +Protocol=Panasonic Address=0x10B Command=0xA0 Raw-Data=0xA010B02002 48 bits LSB first Gap=1073350us Duration=54650us Send with: IrSender.sendPanasonic(0x10B, 0xA0, ); -rawData[100]: - -1064700 +rawData[100]: + -1073350 +3550,-1650 - + 550,- 350 + 500,-1250 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,- 400 + 450,-1300 + 500,- 350 + 500,- 400 - + 500,- 350 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,-1250 + 500,-1250 + 500,- 350 + 500,-1250 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,-1250 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,- 350 + 550,- 350 + 500,- 350 + 550,- 350 - + 500,- 350 + 500,-1250 + 500,- 400 + 500,-1250 - + 500,- 350 + 550,- 350 + 500,- 350 + 550,- 350 - + 500,- 350 + 550,- 350 + 500,- 400 + 500,- 350 - + 500 -Sum: 54750 + + 500,- 400 + 450,-1250 + 500,- 400 + 450,- 450 + + 450,- 400 + 500,- 400 + 450,- 400 + 450,- 450 + + 450,- 400 + 500,- 400 + 500,- 350 + 500,- 400 + + 450,- 400 + 500,-1250 + 500,- 350 + 500,- 400 + + 500,- 400 + 500,- 350 + 500,- 400 + 450,- 400 + + 500,-1250 + 500,-1250 + 500,- 400 + 450,-1250 + + 500,- 400 + 500,- 350 + 500,- 400 + 450,- 400 + + 500,-1250 + 450,- 450 + 450,- 400 + 500,- 350 + + 500,- 400 + 450,- 450 + 450,- 400 + 500,- 400 + + 450,- 400 + 450,-1300 + 450,- 400 + 500,-1250 + + 500,- 400 + 450,- 400 + 500,- 400 + 450,- 450 + + 450,- 400 + 500,- 400 + 450,- 400 + 450,- 450 + + 450 +Duration=54650us + -Send Panasonic 0xB, 0x10 as generic 48 bit PulseDistance - LSB first -Protocol=Panasonic Address=0x10B Command=0xA0 Raw-Data=0xA010B02002 48 bits LSB first +Send Panasonic 0xB, 0x10 as 48 bit PulseDistance PGM 1=450|1250, 0=450|400 +-LSB first +Protocol=Panasonic Address=0x10B Command=0xA0 Raw-Data=0xA010B02002 48 bits LSB first Gap=1092300us Duration=53850us Send with: IrSender.sendPanasonic(0x10B, 0xA0, ); -rawData[100]: - -1082450 - +3550,-1600 - + 550,- 350 + 550,-1150 + 550,- 300 + 600,- 300 - + 550,- 300 + 550,- 300 + 600,- 300 + 550,- 300 - + 550,- 300 + 550,- 350 + 550,- 300 + 550,- 350 - + 550,- 300 + 550,-1200 + 550,- 300 + 550,- 300 - + 550,- 350 + 550,- 300 + 550,- 300 + 550,- 350 - + 550,-1150 + 550,-1200 + 550,- 300 + 550,-1200 - + 550,- 300 + 550,- 300 + 550,- 300 + 600,- 300 - + 550,-1150 + 600,- 300 + 550,- 300 + 550,- 300 - + 550,- 350 + 550,- 300 + 550,- 350 + 550,- 300 - + 550,- 300 + 550,-1200 + 550,- 300 + 550,-1200 - + 550,- 300 + 550,- 300 + 600,- 300 + 550,- 300 - + 550,- 300 + 600,- 300 + 550,- 300 + 550,- 300 - + 550 -Sum: 54200 +rawData[100]: + -1092300 + +3500,-1700 + + 500,- 350 + 500,-1200 + 500,- 350 + 500,- 400 + + 450,- 350 + 550,- 350 + 500,- 350 + 500,- 400 + + 450,- 400 + 500,- 350 + 500,- 350 + 500,- 400 + + 450,- 350 + 550,-1200 + 500,- 350 + 500,- 350 + + 500,- 400 + 450,- 400 + 500,- 250 + 600,- 350 + + 500,-1200 + 550,-1200 + 450,- 350 + 550,-1200 + + 500,- 400 + 450,- 400 + 500,- 350 + 500,- 350 + + 500,-1200 + 500,- 400 + 450,- 400 + 500,- 350 + + 500,- 350 + 500,- 400 + 450,- 400 + 500,- 350 + + 500,- 350 + 500,-1200 + 500,- 400 + 500,-1200 + + 500,- 350 + 500,- 350 + 550,- 350 + 450,- 400 + + 500,- 350 + 500,- 350 + 500,- 400 + 450,- 400 + + 500 +Duration=53850us + - MSB first -Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B02002 48 bits LSB first +-MSB first +Protocol=Panasonic Address=0xB Command=0x10 Raw-Data=0xA01000B02002 48 bits LSB first Gap=1084600us Duration=53850us Send with: IrSender.sendPanasonic(0xB, 0x10, ); -rawData[100]: - -1076300 - +3550,-1600 - + 550,- 350 + 550,-1150 + 550,- 300 + 600,- 300 - + 550,- 300 + 600,- 300 + 550,- 300 + 550,- 300 - + 600,- 300 + 550,- 300 + 550,- 300 + 600,- 300 - + 550,- 300 + 550,-1200 + 550,- 300 + 550,- 300 - + 550,- 350 + 550,- 300 + 550,- 300 + 550,- 350 - + 550,-1150 + 550,-1200 + 550,- 300 + 550,-1200 - + 550,- 300 + 550,- 300 + 550,- 350 + 550,- 300 - + 550,- 350 + 550,- 350 + 550,- 300 + 550,- 300 - + 550,- 350 + 550,- 300 + 550,- 300 + 550,- 350 - + 550,-1150 + 550,- 300 + 600,- 300 + 550,- 300 - + 550,- 300 + 600,- 300 + 550,- 300 + 550,- 300 - + 600,- 300 + 550,-1150 + 550,- 350 + 550,-1150 - + 550 -Sum: 54250 +rawData[100]: + -1084600 + +3500,-1650 + + 500,- 350 + 550,-1200 + 450,- 400 + 500,- 350 + + 500,- 350 + 550,- 350 + 450,- 400 + 500,- 350 + + 500,- 350 + 500,- 400 + 450,- 400 + 500,- 350 + + 500,- 350 + 500,-1200 + 550,- 350 + 450,- 400 + + 500,- 350 + 500,- 350 + 550,- 350 + 450,- 400 + + 500,-1200 + 500,-1200 + 500,- 400 + 500,-1200 + + 500,- 350 + 500,- 350 + 500,- 400 + 450,- 400 + + 500,- 350 + 500,- 350 + 500,- 350 + 500,- 400 + + 500,- 350 + 500,- 350 + 500,- 350 + 550,- 350 + + 500,-1200 + 500,- 350 + 500,- 350 + 500,- 400 + + 450,- 400 + 500,- 350 + 550,- 300 + 500,- 400 + + 450,- 400 + 500,-1200 + 500,- 350 + 500,-1250 + + 500 +Duration=53850us -Send generic 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first -Protocol=PulseDistance Raw-Data=0x5A 72 bits LSB first -Send with: + +Send 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first 1=550|1700, 0=550|600 +Protocol=PulseDistance Raw-Data=0x5A 72 bits LSB first Gap=1091200us Duration=139400us +Send on a 32 bit platform with: uint64_t tRawData[]={0xAFEDCBA987654321, 0x5A}; - IrSender.sendPulseDistanceWidthFromArray(38, 9000, 4350, 650, 1600, 650, 500, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, , ); -rawData[148]: - -1082050 - +9000,-4350 - + 700,-1600 + 650,- 500 + 700,- 500 + 650,- 500 - + 650,- 550 + 650,-1600 + 650,- 550 + 650,- 500 - + 700,-1600 + 650,-1650 + 650,- 500 + 650,- 500 - + 700,- 500 + 650,- 500 + 650,-1650 + 650,- 500 - + 650,-1650 + 650,- 500 + 650,-1650 + 650,- 500 - + 650,- 550 + 650,-1600 + 650,-1650 + 650,- 500 - + 650,-1650 + 650,-1600 + 700,-1600 + 650,- 500 - + 700,- 500 + 650,- 500 + 700,- 500 + 650,-1600 - + 700,-1600 + 650,- 500 + 700,- 500 + 650,-1600 - + 700,- 500 + 650,-1650 + 600,- 550 + 700,-1600 - + 650,-1650 + 650,-1600 + 650,- 550 + 650,-1600 - + 700,- 500 + 650,- 500 + 650,-1650 + 650,-1600 - + 650,-1650 + 650,- 500 + 700,-1600 + 650,-1650 - + 650,- 500 + 650,-1650 + 650,-1600 + 700,-1600 - + 650,-1650 + 650,-1600 + 700,-1600 + 650,-1650 - + 650,- 500 + 650,-1650 + 650,- 500 + 700,-1600 - + 650,- 500 + 700,-1600 + 650,- 550 + 650,-1600 - + 650,-1650 + 650,- 500 + 650,-1650 + 650,- 500 + IrSender.sendPulseDistanceWidthFromArray(38, 8950, 4450, 600, 1650, 600, 550, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, , ); +rawData[148]: + -1091200 + +8950,-4450 + + 550,-1700 + 600,- 550 + 600,- 550 + 600,- 550 + + 600,- 600 + 600,-1650 + 600,- 550 + 600,- 600 + + 550,-1650 + 650,-1650 + 550,- 600 + 600,- 550 + + 600,- 600 + 550,- 600 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,- 600 + 550,-1700 + 600,- 550 + + 600,- 600 + 600,-1600 + 650,-1650 + 600,- 550 + + 600,-1700 + 550,-1650 + 650,-1650 + 550,- 600 + + 650,- 500 + 600,- 600 + 550,- 600 + 600,-1650 + + 600,-1650 + 650,- 500 + 600,- 600 + 600,-1650 + + 600,- 550 + 600,-1650 + 600,- 550 + 650,-1650 + + 600,-1650 + 650,-1600 + 600,- 600 + 600,-1650 + + 550,- 600 + 600,- 550 + 600,-1700 + 550,-1700 + + 600,-1650 + 600,- 550 + 600,-1700 + 550,-1700 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,-1700 + + 600,-1650 + 600,-1650 + 600,-1700 + 550,-1700 + + 600,- 550 + 600,-1650 + 600,- 550 + 600,-1700 + + 550,- 600 + 600,-1650 + 600,- 550 + 600,-1650 + + 600,-1700 + 550,- 600 + 600,-1650 + 600,- 550 + + 600 +Duration=139400us + + +Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first 1=300|600, 0=600|300 +Protocol=PulseDistance Raw-Data=0xDCBA987654321 52 bits LSB first Gap=1134450us Duration=48650us +Send on a 32 bit platform with: IrSender.sendPulseDistanceWidth(38, 350, 550, 350, 550, 650, 200, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, , ); +rawData[108]: + -1134450 + + 350,- 550 + + 350,- 550 + 650,- 200 + 700,- 250 + 700,- 200 + + 700,- 250 + 350,- 550 + 650,- 200 + 700,- 250 + + 400,- 550 + 350,- 550 + 650,- 250 + 650,- 250 + + 700,- 200 + 700,- 250 + 350,- 600 + 650,- 150 + + 450,- 550 + 650,- 250 + 350,- 550 + 650,- 250 + + 700,- 150 + 450,- 550 + 350,- 550 + 650,- 250 + + 350,- 600 + 350,- 550 + 350,- 600 + 600,- 200 + + 700,- 250 + 700,- 200 + 700,- 200 + 400,- 600 + + 300,- 550 + 650,- 250 + 700,- 250 + 350,- 550 + + 650,- 250 + 400,- 550 + 650,- 200 + 450,- 500 + + 350,- 600 + 300,- 600 + 650,- 200 + 400,- 600 + + 600,- 200 + 700,- 250 + 350,- 600 + 350,- 550 + + 350,- 600 + 600,- 200 + 450,- 550 + 350,- 550 + + 350 +Duration=48650us + + +Send 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first with inverse timing and data 1=600|300, 0=300|600 +Protocol=PulseDistance Raw-Data=0xDCBA987654321 52 bits LSB first Gap=1104850us Duration=48950us +Send on a 32 bit platform with: IrSender.sendPulseDistanceWidth(38, 300, 600, 350, 550, 650, 200, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, , ); +rawData[108]: + -1104850 + + 300,- 600 + + 350,- 550 + 650,- 250 + 650,- 200 + 750,- 200 + + 700,- 250 + 350,- 550 + 650,- 250 + 700,- 150 + + 450,- 550 + 350,- 550 + 650,- 200 + 700,- 250 + + 700,- 250 + 650,- 200 + 400,- 550 + 650,- 250 + + 400,- 550 + 650,- 250 + 350,- 600 + 600,- 200 + + 750,- 200 + 400,- 550 + 350,- 550 + 650,- 250 + + 350,- 550 + 400,- 550 + 350,- 550 + 700,- 150 + + 700,- 250 + 700,- 250 + 650,- 200 + 400,- 550 + + 350,- 600 + 650,- 200 + 700,- 250 + 350,- 600 + + 600,- 200 + 400,- 600 + 650,- 250 + 350,- 550 + + 350,- 600 + 300,- 550 + 650,- 250 + 400,- 550 + + 650,- 200 + 700,- 250 + 400,- 550 + 350,- 550 + + 350,- 550 + 650,- 250 + 350,- 600 + 350,- 550 + 650 -Sum: 140550 - -Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first -Protocol=PulseWidth Raw-Data=0xDCBA987654321 52 bits LSB first -Send with: IrSender.sendPulseDistanceWidth(38, 400, 550, 750, 150, 400, 500, 0xDCBA987654321, 52, PROTOCOL_IS_LSB_FIRST, , ); -rawData[106]: - -1120100 - + 400,- 550 - + 700,- 150 + 450,- 500 + 400,- 550 + 400,- 500 - + 400,- 500 + 700,- 150 + 450,- 550 + 400,- 500 - + 700,- 150 + 800,- 150 + 450,- 500 + 400,- 500 - + 400,- 550 + 350,- 550 + 700,- 200 + 400,- 550 - + 700,- 200 + 400,- 500 + 750,- 200 + 400,- 500 - + 400,- 550 + 700,- 150 + 750,- 200 + 450,- 500 - + 700,- 150 + 750,- 200 + 750,- 150 + 450,- 500 - + 400,- 550 + 400,- 500 + 400,- 500 + 700,- 150 - + 800,- 150 + 450,- 500 + 400,- 500 + 750,- 150 - + 450,- 500 + 700,- 200 + 450,- 500 + 700,- 250 - + 700,- 150 + 800,- 150 + 450,- 500 + 700,- 200 - + 450,- 500 + 400,- 500 + 700,- 200 + 750,- 150 - + 750,- 150 + 450,- 550 + 700,- 200 + 700 -Sum: 48450 - -Send generic 32 bit PulseWidth 0x87654321 LSB first -Protocol=PulseWidth Raw-Data=0x87654321 32 bits LSB first -Send with: IrSender.sendPulseDistanceWidth(38, 1100, 400, 750, 200, 450, 200, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, , ); -rawData[66]: - -1090450 - +1100,- 400 - + 700,- 150 + 450,- 200 + 450,- 150 + 450,- 200 - + 400,- 200 + 750,- 150 + 450,- 150 + 450,- 200 - + 700,- 200 + 750,- 200 + 400,- 200 + 400,- 200 - + 450,- 150 + 450,- 150 + 750,- 150 + 450,- 200 - + 750,- 200 + 400,- 200 + 750,- 150 + 450,- 150 - + 450,- 200 + 700,- 200 + 750,- 200 + 400,- 200 - + 750,- 150 + 750,- 200 + 700,- 200 + 450,- 150 - + 450,- 200 + 400,- 200 + 450,- 150 + 750 -Sum: 24900 - -Send MagiQuest 0x6BCDFF00, 0x176 as generic 55 bit PulseDistanceWidth MSB first -Protocol=MagiQuest Address=0xFF00 Command=0x176 Raw-Data=0x6BCDFF00 56 bits MSB first +Duration=48950us + + +Send 7 bit ASCII character with PulseDistanceWidth LSB first 1=500|1500, 0=1500|500 +Protocol=PulseDistance Raw-Data=0x76 7 bits LSB first Gap=1102950us Duration=21150us +Send on a 32 bit platform with: IrSender.sendPulseDistanceWidth(38, 6050, 500, 500, 1500, 1550, 500, 0x76, 7, PROTOCOL_IS_LSB_FIRST, , ); +rawData[18]: + -1102950 + +6050,- 500 + +1500,- 500 + 500,-1500 + 550,-1450 +1550,- 500 + + 500,-1500 + 500,-1500 + 550,-1450 + 550 +Duration=21150us + + +Send Sony12 as PulseWidth LSB first 1=1200|300, 0=600|600 +Protocol=Sony Address=0x11 Command=0x76 Raw-Data=0x8F6 12 bits LSB first Gap=1053600us Duration=21200us +Send with: IrSender.sendSony(0x11, 0x76, 2, 12); +rawData[26]: + -1053600 + +2450,- 600 + + 650,- 550 +1250,- 550 +1250,- 600 + 600,- 600 + +1200,- 600 +1250,- 550 +1250,- 550 +1300,- 500 + + 650,- 600 + 650,- 550 + 650,- 550 +1250 +Duration=21200us + + +Send 32 bit PulseWidth 0x87654321 LSB first 1=600|300, 0=300|300 +Protocol=PulseWidth Raw-Data=0x87654321 32 bits LSB first Gap=1048400us Duration=24750us +Send on a 32 bit platform with: IrSender.sendPulseDistanceWidth(38, 1100, 450, 700, 200, 400, 200, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, , ); +rawData[66]: + -1048400 + +1100,- 450 + + 650,- 200 + 400,- 250 + 350,- 250 + 400,- 150 + + 450,- 200 + 700,- 200 + 400,- 200 + 450,- 200 + + 700,- 150 + 750,- 250 + 350,- 200 + 400,- 200 + + 400,- 250 + 400,- 200 + 700,- 200 + 450,- 200 + + 650,- 200 + 450,- 250 + 650,- 200 + 400,- 250 + + 400,- 200 + 700,- 150 + 750,- 200 + 400,- 250 + + 700,- 150 + 700,- 250 + 700,- 250 + 350,- 250 + + 400,- 200 + 400,- 200 + 400,- 250 + 650 +Duration=24750us + + +Send MagiQuest 0x6BCDFF00, 0x176 as 55 bit PulseDistanceWidth MSB first 1=576|576, 0=287|864 +Protocol=MagiQuest Address=0xFF00 Command=0x176 Raw-Data=0x6BCDFF00 56 bits MSB first Gap=1090700us Duration=64700us Send with: IrSender.sendMagiQuest(0x6BCDFF00, 0x176, ); -rawData[112]: - -1070250 - + 400,- 800 + 400,- 750 + 450,- 800 + 400,- 750 - + 400,- 800 + 400,- 750 + 400,- 800 + 400,- 750 - + 700,- 500 + 650,- 500 + 400,- 800 + 650,- 500 - + 400,- 800 + 650,- 500 + 700,- 500 + 650,- 500 - + 700,- 450 + 450,- 750 + 400,- 750 + 700,- 500 - + 700,- 450 + 400,- 800 + 700,- 450 + 700,- 500 - + 700,- 500 + 650,- 500 + 700,- 450 + 700,- 500 - + 700,- 450 + 700,- 500 + 700,- 450 + 400,- 800 - + 350,- 800 + 400,- 800 + 400,- 750 + 400,- 800 - + 400,- 750 + 400,- 800 + 400,- 750 + 700,- 450 - + 450,- 750 + 700,- 450 + 700,- 500 + 700,- 450 - + 400,- 800 + 650,- 500 + 700,- 500 + 400,- 750 - + 400,- 800 + 400,- 750 + 450,- 750 + 700,- 450 - + 700,- 500 + 400,- 750 + 400,- 800 + 700 -Sum: 65350 +rawData[112]: + -1090700 + + 300,- 850 + 350,- 800 + 350,- 800 + 350,- 850 + + 350,- 800 + 350,- 800 + 350,- 850 + 350,- 800 + + 650,- 500 + 650,- 550 + 300,- 850 + 650,- 500 + + 300,- 900 + 600,- 550 + 600,- 550 + 650,- 550 + + 600,- 550 + 300,- 850 + 350,- 850 + 600,- 550 + + 600,- 550 + 350,- 800 + 650,- 550 + 600,- 550 + + 650,- 500 + 650,- 550 + 600,- 550 + 600,- 550 + + 650,- 550 + 600,- 550 + 600,- 550 + 350,- 850 + + 300,- 850 + 300,- 850 + 350,- 850 + 300,- 850 + + 300,- 850 + 300,- 850 + 350,- 800 + 650,- 550 + + 300,- 850 + 600,- 550 + 650,- 550 + 600,- 550 + + 350,- 800 + 650,- 550 + 600,- 550 + 350,- 800 + + 350,- 850 + 300,- 850 + 350,- 800 + 650,- 500 + + 650,- 550 + 300,- 850 + 350,- 800 + 650 +Duration=64700us + Send Onkyo (NEC with 16 bit command) -Protocol=Onkyo Address=0xFFF1 Command=0x7776 Raw-Data=0x7776FFF1 32 bits LSB first +Protocol=Onkyo Address=0xFFF1 Command=0x7776 Raw-Data=0x7776FFF1 32 bits LSB first Gap=1113450us Duration=77150us Send with: IrSender.sendOnkyo(0xFFF1, 0x7776, ); -rawData[68]: - -1086400 - +9050,-4400 - + 700,-1600 + 650,- 450 + 700,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,- 450 + 700,-1600 + 650,-1600 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,- 500 +rawData[68]: + -1113450 + +9000,-4450 + + 650,-1600 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 650,-1600 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,-1600 + 600,-1650 + 650,-1600 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + 650 -Sum: 77500 +Duration=77150us + Send Apple -Protocol=Apple Address=0xF1 Command=0x76 Raw-Data=0xF17687EE 32 bits LSB first +Protocol=Apple Address=0xF1 Command=0x76 Raw-Data=0xF17687EE 32 bits LSB first Gap=1065600us Duration=72650us Send with: IrSender.sendApple(0xF1, 0x76, ); -rawData[68]: - -1059500 - +9050,-4400 - + 700,- 500 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,- 500 + 650,-1600 + 650,-1600 + 650,-1600 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,- 450 + 700,- 450 + 700,- 450 + 650,-1600 - + 650,- 500 + 650,-1600 + 650,-1600 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,- 450 + 650,- 500 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 +rawData[68]: + -1065600 + +9000,-4450 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,-1650 + + 650,- 450 + 600,-1650 + 650,-1600 + 600,-1700 + + 550,-1650 + 600,-1700 + 600,-1600 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,-1650 + 550,-1650 + 650,-1650 + 550,- 550 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + 600 -Sum: 73000 +Duration=72650us + Send Panasonic -Protocol=Panasonic Address=0xFF1 Command=0x76 Raw-Data=0x9976FF102002 48 bits LSB first +Protocol=Panasonic Address=0xFF1 Command=0x76 Raw-Data=0x9976FF102002 48 bits LSB first Gap=1065700us Duration=65000us Send with: IrSender.sendPanasonic(0xFF1, 0x76, ); -rawData[100]: - -1059200 +rawData[100]: + -1065700 +3500,-1700 - + 500,- 350 + 500,-1250 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,-1250 + 500,- 350 + 500,- 400 - + 500,- 350 + 500,- 400 + 450,- 400 + 500,- 400 - + 500,-1250 + 500,- 350 + 500,- 400 + 450,- 400 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,- 400 + 500,-1250 + 500,-1250 + 500,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 400 - + 500,-1250 + 500,- 350 + 500,- 400 + 500,-1250 - + 500,-1250 + 500,- 400 + 500,- 350 + 500,-1250 - + 500 -Sum: 65200 + + 500,- 400 + 450,-1250 + 500,- 400 + 500,- 400 + + 450,- 400 + 500,- 400 + 450,- 400 + 500,- 400 + + 450,- 400 + 500,- 400 + 450,- 400 + 550,- 350 + + 450,- 400 + 500,-1250 + 450,- 450 + 450,- 400 + + 500,- 350 + 500,- 400 + 500,- 400 + 450,- 400 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 350 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,-1300 + + 450,-1300 + 450,-1250 + 500,-1250 + 500,-1250 + + 450,- 450 + 450,-1250 + 500,-1250 + 500,- 350 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,- 450 + + 450,-1250 + 500,- 400 + 450,- 400 + 500,-1250 + + 500,-1250 + 500,- 350 + 500,- 400 + 450,-1300 + + 450 +Duration=65000us + Send Kaseikyo with 0x4711 as Vendor ID -Protocol=Kaseikyo Address=0xFF1 Command=0x76 Extra=0x4711 Raw-Data=0x9A76FF134711 48 bits LSB first +Protocol=Kaseikyo Address=0xFF1 Command=0x76 Extra=0x4711 Raw-Data=0x9A76FF134711 48 bits LSB first Gap=1091050us Duration=70250us Send with: IrSender.sendKaseikyo(0xFF1, 0x76, , 0x4711); -rawData[100]: - -1079950 +rawData[100]: + -1091050 +3550,-1650 - + 500,-1250 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,-1250 + 500,- 350 + 550,- 350 + 500,- 400 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,-1250 + 500,- 400 - + 500,-1250 + 500,-1250 + 500,- 350 + 500,- 400 - + 500,-1250 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,-1250 + 500,-1250 + 500,-1250 + 550,-1200 - + 550,- 350 + 500,-1250 + 500,-1250 + 500,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 550,- 350 - + 500,- 350 + 500,-1250 + 550,- 350 + 500,-1250 - + 500,-1250 + 500,- 350 + 500,- 400 + 500,-1250 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 400 + + 450,-1300 + 450,- 400 + 500,- 350 + 500,- 400 + + 500,-1250 + 450,-1300 + 450,-1300 + 450,- 400 + + 500,- 400 + 450,- 400 + 450,-1300 + 450,- 400 + + 500,-1250 + 500,-1250 + 500,- 400 + 450,- 400 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 350 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,-1300 + + 450,-1300 + 450,-1250 + 500,-1250 + 500,-1250 + + 450,- 450 + 450,-1250 + 500,-1250 + 500,- 350 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,- 450 + + 450,- 400 + 500,-1250 + 450,- 450 + 450,-1250 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,-1250 + 500 -Sum: 70500 +Duration=70250us + Send Kaseikyo_Denon variant -Protocol=Kaseikyo_Denon Address=0xFF1 Command=0x76 Raw-Data=0x9976FF103254 48 bits LSB first +Protocol=Kaseikyo_Denon Address=0xFF1 Command=0x76 Raw-Data=0x9976FF103254 48 bits LSB first Gap=1089850us Duration=68450us Send with: IrSender.sendKaseikyo_Denon(0xFF1, 0x76, ); -rawData[100]: - -1080650 - +3550,-1650 - + 550,- 350 + 500,- 350 + 550,-1200 + 550,- 350 - + 500,-1250 + 500,- 350 + 550,-1200 + 500,- 400 - + 500,- 350 + 500,-1250 + 550,- 350 + 500,- 350 - + 550,-1200 + 550,-1200 + 550,- 350 + 500,- 350 - + 550,- 350 + 500,- 350 + 550,- 350 + 500,- 350 - + 550,-1200 + 550,- 350 + 500,- 350 + 550,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,- 350 + 500,-1250 + 500,-1250 + 500,- 400 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 350 - + 500,-1250 + 550,- 350 + 500,- 350 + 550,-1250 - + 450,-1300 + 500,- 350 + 500,- 400 + 500,-1250 +rawData[100]: + -1089850 + +3500,-1650 + + 500,- 400 + 500,- 400 + 450,-1250 + 500,- 400 + + 500,-1250 + 450,- 400 + 500,-1250 + 450,- 450 + + 450,- 400 + 500,-1250 + 450,- 450 + 450,- 400 + + 450,-1300 + 500,-1200 + 500,- 400 + 450,- 400 + + 500,- 400 + 450,- 400 + 500,- 400 + 450,- 400 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,- 400 + + 450,-1300 + 450,-1250 + 500,-1250 + 500,-1250 + + 500,-1250 + 450,-1300 + 450,-1300 + 450,-1250 + + 550,- 350 + 450,-1250 + 500,-1250 + 500,- 400 + + 450,-1300 + 450,-1300 + 450,-1250 + 450,- 450 + + 450,-1250 + 500,- 400 + 450,- 450 + 450,-1250 + + 500,-1250 + 500,- 400 + 450,- 400 + 500,-1250 + 500 -Sum: 68750 +Duration=68450us + Send Denon -Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0xED1 15 bits LSB first +Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0xED1 15 bits LSB first Gap=1089050us Duration=23400us Send with: IrSender.sendDenon(0x11, 0x76, ); -rawData[32]: - -1078400 - + 350,-1750 + 350,- 700 + 350,- 700 + 350,- 700 - + 350,-1750 + 350,- 700 + 300,-1800 + 350,-1750 - + 350,- 700 + 350,-1750 + 350,-1750 + 350,-1750 - + 350,- 700 + 350,- 700 + 350,- 700 + 350 -Sum: 23450 +rawData[32]: + -1089050 + + 350,-1750 + 300,- 750 + 300,- 750 + 300,- 750 + + 300,-1800 + 300,- 750 + 300,-1800 + 300,-1800 + + 300,- 750 + 300,-1800 + 300,-1750 + 350,-1750 + + 300,- 750 + 350,- 750 + 300,- 750 + 300 +Duration=23400us + Send Denon/Sharp variant -Protocol=Sharp Address=0x11 Command=0x76 Raw-Data=0x4ED1 15 bits LSB first -Send with: IrSender.sendSharp(0x11, 0x76, ); -rawData[32]: - -1023500 - + 350,-1750 + 350,- 700 + 350,- 700 + 350,- 700 - + 350,-1750 + 350,- 700 + 350,-1750 + 350,-1750 - + 350,- 700 + 350,-1750 + 350,-1750 + 350,-1750 - + 350,- 700 + 300,- 750 + 350,-1750 + 350 -Sum: 24500 +Protocol=Denon Address=0x11 Command=0x76 Raw-Data=0x2ED1 15 bits LSB first Gap=1034900us Duration=24450us +Send with: IrSender.sendDenon(0x11, 0x76, ); +rawData[32]: + -1034900 + + 300,-1800 + 300,- 750 + 300,- 750 + 300,- 750 + + 300,-1800 + 300,- 750 + 300,-1800 + 300,-1800 + + 300,- 750 + 300,-1800 + 300,-1800 + 300,-1750 + + 350,- 700 + 300,-1800 + 300,- 750 + 350 +Duration=24450us + Send Sony/SIRCS with 7 command and 5 address bits -Protocol=Sony Address=0x11 Command=0x76 Raw-Data=0x8F6 12 bits LSB first +Protocol=Sony Address=0x11 Command=0x76 Raw-Data=0x8F6 12 bits LSB first Gap=1037050us Duration=21150us Send with: IrSender.sendSony(0x11, 0x76, 2, 12); -rawData[26]: - -1025750 - +2500,- 500 - + 700,- 500 +1300,- 650 +1250,- 550 + 700,- 500 - +1300,- 500 +1300,- 500 +1300,- 550 +1300,- 500 - + 700,- 500 + 700,- 500 + 700,- 550 +1250 -Sum: 21300 +rawData[26]: + -1037050 + +2400,- 600 + + 650,- 550 +1250,- 550 +1300,- 550 + 600,- 600 + +1250,- 550 +1250,- 550 +1250,- 550 +1250,- 550 + + 650,- 600 + 650,- 550 + 650,- 550 +1250 +Duration=21150us + Send Sony/SIRCS with 7 command and 8 address bits -Protocol=Sony Address=0xF1 Command=0x76 Raw-Data=0x78F6 15 bits LSB first +Protocol=Sony Address=0xF1 Command=0x76 Raw-Data=0x78F6 15 bits LSB first Gap=1046850us Duration=26600us Send with: IrSender.sendSony(0xF1, 0x76, 2, 15); -rawData[32]: - -1037600 - +2500,- 550 - + 650,- 550 +1300,- 500 +1300,- 500 + 700,- 500 - +1300,- 550 +1250,- 550 +1300,- 500 +1300,- 500 - + 700,- 500 + 700,- 550 + 650,- 550 +1300,- 500 - +1300,- 550 +1300,- 500 +1300 -Sum: 26700 +rawData[32]: + -1046850 + +2450,- 550 + + 650,- 550 +1250,- 550 +1250,- 600 + 600,- 600 + +1250,- 550 +1250,- 550 +1250,- 600 +1200,- 550 + + 650,- 600 + 650,- 550 + 650,- 600 +1200,- 550 + +1250,- 600 +1250,- 550 +1250 +Duration=26600us + Send Sony/SIRCS with 7 command and 13 address bits -Protocol=Sony Address=0x1FF1 Command=0x76 Raw-Data=0xFF8F6 20 bits LSB first +Protocol=Sony Address=0x1FF1 Command=0x76 Raw-Data=0xFF8F6 20 bits LSB first Gap=1057450us Duration=35700us Send with: IrSender.sendSony(0x1FF1, 0x76, 2, 20); -rawData[42]: - -1041100 - +2500,- 500 - + 700,- 550 +1300,- 500 +1300,- 500 + 700,- 550 - +1250,- 550 +1300,- 500 +1300,- 550 +1300,- 500 - + 700,- 500 + 700,- 500 + 700,- 500 +1300,- 550 - +1300,- 500 +1300,- 500 +1300,- 500 +1300,- 550 - +1300,- 500 +1300,- 500 +1300,- 550 +1250 -Sum: 35750 - -Send Samsung 8 bit command -Protocol=Samsung Address=0xFFF1 Command=0x76 Raw-Data=0x8976FFF1 32 bits LSB first -Send with: IrSender.sendSamsung(0xFFF1, 0x76, ); -rawData[68]: - -1044850 - +4550,-4400 - + 700,-1600 + 650,- 450 + 700,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,- 450 + 700,-1600 + 650,-1600 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,-1600 - + 650 -Sum: 69600 +rawData[42]: + -1057450 + +2450,- 600 + + 650,- 550 +1200,- 600 +1250,- 550 + 650,- 550 + +1250,- 600 +1250,- 550 +1250,- 550 +1250,- 550 + + 650,- 600 + 650,- 550 + 650,- 550 +1250,- 550 + +1250,- 600 +1250,- 550 +1250,- 550 +1250,- 550 + +1250,- 550 +1250,- 600 +1200,- 600 +1250 +Duration=35700us + + +Send Samsung 8 bit command and 8 bit address +Protocol=Samsung Address=0xF1 Command=0x76 Raw-Data=0x8976F1F1 32 bits LSB first Gap=1056800us Duration=65950us +Send with: IrSender.sendSamsung(0xF1, 0x76, ); +rawData[68]: + -1056800 + +4550,-4450 + + 550,-1700 + 600,- 500 + 600,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,- 550 + 550,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 500 + 600,-1650 + 650,-1600 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,-1650 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 + + 600 +Duration=65950us + -Send Samsung 16 bit command -Protocol=Samsung Address=0xFFF1 Command=0x9876 Raw-Data=0x9876FFF1 32 bits LSB first +Send Samsung 16 bit command and address +Protocol=Samsung Address=0xFFF1 Command=0x9876 Raw-Data=0x9876FFF1 32 bits LSB first Gap=1068600us Duration=69300us Send with: IrSender.sendSamsung(0xFFF1, 0x9876, ); -rawData[68]: - -1061000 - +4600,-4400 - + 650,-1600 + 700,- 450 + 650,- 500 + 650,- 450 - + 700,-1550 + 700,-1600 + 650,-1600 + 650,-1600 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,-1600 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,-1600 - + 650,- 500 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,-1600 + 650,- 500 + 650,- 450 + 700,-1600 - + 650 -Sum: 69650 +rawData[68]: + -1068600 + +4550,-4450 + + 600,-1650 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 550 + 550,-1650 + 650,-1650 + 550,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,-1650 + + 600,-1650 + 600,- 550 + 600,- 500 + 600,-1650 + + 600 +Duration=69300us + Send Samsung48 16 bit command -Protocol=Samsung48 Address=0xFFF1 Command=0x9876 Raw-Data=0xFFFFFFFF8976FFF1 48 bits LSB first +Protocol=Samsung48 Address=0xFFF1 Command=0x9876 Raw-Data=0xFFFFFFFF8976FFF1 48 bits LSB first Gap=1066850us Duration=96400us Send with: IrSender.sendSamsung48(0xFFF1, 0x9876, ); -rawData[100]: - -1066350 +rawData[100]: + -1066850 +4550,-4400 - + 650,-1650 + 600,- 500 + 700,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,-1600 - + 600,-1650 + 650,-1600 + 650,-1600 + 700,-1600 - + 600,-1650 + 650,-1600 + 650,-1600 + 700,-1550 - + 700,- 450 + 650,-1600 + 700,-1600 + 600,- 500 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,- 500 - + 650,-1600 + 650,- 500 + 650,- 500 + 650,-1600 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 450 + 650,- 500 + 650,-1600 - + 650,-1600 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,-1600 + 650,-1600 + 650,-1650 + 650,- 450 - + 650,- 500 + 650,-1600 + 650,-1600 + 650,- 500 + + 650,-1650 + 550,- 550 + 600,- 550 + 600,- 500 + + 600,-1650 + 650,-1600 + 600,-1650 + 650,-1600 + + 600,-1650 + 650,-1600 + 600,-1650 + 650,-1600 + + 600,-1650 + 650,-1600 + 600,-1650 + 650,-1600 + + 600,- 550 + 600,-1650 + 650,-1600 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 550,-1650 + 650,- 500 + 600,- 550 + 600,-1650 + + 600,- 500 + 600,- 550 + 600,- 550 + 600,-1650 + + 600,- 550 + 550,- 550 + 600,- 550 + 600,-1650 + + 600,-1650 + 600,- 500 + 600,- 550 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,- 500 + 650,-1650 + 550,-1650 + 650,- 500 + 650 -Sum: 96750 +Duration=96400us + Send RC5 -Protocol=RC5 Address=0x11 Command=0x36 Raw-Data=0x1476 13 bits MSB first +Protocol=RC5 Address=0x11 Command=0x36 Raw-Data=0x1476 13 bits MSB first Gap=1089700us Duration=23300us Send with: IrSender.sendRC5(0x11, 0x36, ); -rawData[20]: - -1079150 - +1000,- 800 - +1900,-1650 +1900,- 800 +1000,- 800 +1000,-1700 - +1000,- 800 +1000,- 750 +1900,-1700 +1000,- 800 - +1900 -Sum: 23400 +rawData[20]: + -1089700 + + 900,- 850 + +1850,-1750 +1850,- 850 + 900,- 850 + 950,-1750 + + 950,- 850 + 950,- 850 +1800,-1750 + 950,- 850 + +1850 +Duration=23300us + Send RC5X with 7.th MSB of command set -Protocol=RC5 Address=0x11 Command=0x76 Toggle=1 Raw-Data=0xC76 13 bits MSB first +Protocol=RC5 Address=0x11 Command=0x76 Toggle=1 Raw-Data=0xC76 13 bits MSB first Gap=1047250us Duration=23350us Send with: IrSender.sendRC5(0x11, 0x76, ); -rawData[20]: - -1035450 - +1900,-1700 - +1000,- 800 +1900,- 750 +1000,- 800 +1000,-1700 - +1000,- 800 +1000,- 800 +1900,-1650 +1000,- 800 - +1900 -Sum: 23400 +rawData[20]: + -1047250 + +1850,-1750 + + 950,- 850 +1850,- 850 + 900,- 900 + 900,-1750 + + 950,- 850 + 950,- 850 +1800,-1750 +1000,- 800 + +1850 +Duration=23350us + Send RC6 -Protocol=RC6 Address=0xF1 Command=0x76 Raw-Data=0xF176 20 bits MSB first +Protocol=RC6 Address=0xF1 Command=0x76 Raw-Data=0xF176 20 bits MSB first Gap=1043200us Duration=23400us Send with: IrSender.sendRC6(0xF1, 0x76, ); -rawData[36]: - -1032650 +rawData[36]: + -1043200 + +2700,- 850 + + 500,- 850 + 500,- 400 + 500,- 400 + 500,- 850 + +1400,- 400 + 500,- 400 + 500,- 400 + 500,- 850 + + 500,- 400 + 500,- 400 + 950,- 850 + 950,- 400 + + 500,- 400 + 500,- 850 + 950,- 400 + 500,- 850 + + 500 +Duration=23400us + + +Send RC6A with 14 bit 0x2711 as extra +Protocol=RC6A Address=0xF1 Command=0x76 Extra=0x2711 Toggle=1 Raw-Data=0xA711F176 35 bits MSB first Gap=1067100us Duration=36900us +Send with: IrSender.sendRC6A(0xF1, 0x76, , 0x2711); +rawData[58]: + -1067100 +2750,- 800 - + 550,- 800 + 550,- 350 + 550,- 350 + 550,- 800 - +1450,- 350 + 550,- 350 + 550,- 350 + 550,- 800 - + 550,- 350 + 550,- 350 +1000,- 800 +1000,- 350 - + 550,- 350 + 550,- 800 +1000,- 350 + 550,- 800 - + 550 -Sum: 23450 + + 500,- 400 + 500,- 350 + 600,- 800 +1400,-1300 + + 950,- 850 + 500,- 400 + 950,- 400 + 500,- 400 + + 500,- 850 + 500,- 400 + 500,- 400 + 950,- 850 + + 500,- 400 + 500,- 400 + 950,- 400 + 500,- 400 + + 500,- 400 + 500,- 400 + 500,- 850 + 500,- 400 + + 500,- 400 + 950,- 850 + 950,- 400 + 500,- 400 + + 500,- 850 + 950,- 400 + 500,- 850 + 500 +Duration=36900us + + +Send Bang&Olufsen +- ENABLE_BEO_WITHOUT_FRAME_GAP is enabled +rawData[44]: + -1066350 + + 250,-2900 + + 250,-2900 + 250,-12750 + 250,-2850 + 250,-9150 + + 250,-6000 + 250,-6050 + 250,-6000 + 250,-2850 + + 250,-6050 + 250,-6000 + 250,-9150 + 250,-2850 + + 250,-9150 + 250,-6000 + 250,-6000 + 250,-2900 + + 250,-9150 + 250,-6000 + 250,-2900 + 250,-12250 + + 250 +Duration=135350us + +- Now try to decode the first 6 entries, which results in rawData 0x0 +Protocol=Bang&Olufsen Address=0x0 Command=0x0 Raw-Data=0x0 0 bits MSB first Gap=1066350us Duration=6550us + +- Remove trailing 6 entries, which is equivalent to define RECORD_GAP_MICROS < 15000, to enable successful B&O decode +Protocol=Bang&Olufsen Address=0xF1 Command=0x76 Raw-Data=0xF176 16 bits MSB first Gap=12750us Duration=116050us +Send with: IrSender.sendBang&Olufsen(0xF1, 0x76, ); +rawData[38]: + -12750 + + 250,-2850 + + 250,-9150 + 250,-6000 + 250,-6050 + 250,-6000 + + 250,-2850 + 250,-6050 + 250,-6000 + 250,-9150 + + 250,-2850 + 250,-9150 + 250,-6000 + 250,-6000 + + 250,-2900 + 250,-9150 + 250,-6000 + 250,-2900 + + 250,-12250 + 250 +Duration=116050us + + +Send MagiQuest +Protocol=MagiQuest Address=0xFFF1 Command=0x76 Raw-Data=0x6BCDFFF1 56 bits MSB first Gap=1104750us Duration=64450us +Send with: IrSender.sendMagiQuest(0x6BCDFFF1, 0x76, ); +rawData[112]: + -1104750 + + 350,- 850 + 300,- 850 + 300,- 850 + 300,- 850 + + 350,- 800 + 350,- 800 + 350,- 850 + 300,- 850 + + 600,- 550 + 600,- 550 + 350,- 800 + 650,- 550 + + 350,- 800 + 600,- 550 + 600,- 550 + 650,- 500 + + 650,- 550 + 300,- 850 + 300,- 850 + 600,- 550 + + 600,- 550 + 350,- 800 + 650,- 550 + 600,- 550 + + 650,- 500 + 650,- 550 + 600,- 550 + 600,- 550 + + 600,- 550 + 600,- 550 + 600,- 550 + 650,- 500 + + 650,- 550 + 600,- 550 + 650,- 500 + 350,- 850 + + 300,- 850 + 300,- 850 + 600,- 550 + 350,- 800 + + 350,- 800 + 650,- 550 + 600,- 550 + 600,- 550 + + 350,- 850 + 600,- 550 + 600,- 550 + 300,- 850 + + 350,- 800 + 350,- 800 + 650,- 500 + 650,- 550 + + 350,- 800 + 650,- 500 + 650,- 550 + 600 +Duration=64450us + + +Send next protocols with IrSender.write Send JVC -Protocol=JVC Address=0xF1 Command=0x76 Raw-Data=0x76F1 16 bits LSB first +Protocol=JVC Address=0xF1 Command=0x76 Raw-Data=0x76F1 16 bits LSB first Gap=1114750us Duration=40800us Send with: IrSender.sendJVC(0xF1, 0x76, ); -rawData[36]: - -1040750 +rawData[36]: + -1114750 +8500,-4150 - + 650,-1500 + 650,- 400 + 650,- 450 + 600,- 450 - + 650,-1500 + 600,-1500 + 650,-1500 + 600,-1550 - + 600,- 450 + 650,-1500 + 650,-1450 + 650,- 450 - + 650,-1450 + 650,-1500 + 650,-1500 + 600,- 450 - + 650 -Sum: 41050 + + 550,-1550 + 600,- 500 + 550,- 500 + 600,- 450 + + 600,-1500 + 600,-1550 + 550,-1550 + 600,-1550 + + 550,- 500 + 600,-1550 + 550,-1550 + 550,- 500 + + 550,-1550 + 600,-1550 + 550,-1550 + 550,- 500 + + 600 +Duration=40800us -Send Samsung -Protocol=Samsung Address=0xFFF1 Command=0x9876 Raw-Data=0x9876FFF1 32 bits LSB first -Send with: IrSender.sendSamsung(0xFFF1, 0x9876, ); -rawData[68]: - -1040900 - +4600,-4400 - + 650,-1600 + 700,- 450 + 650,- 500 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,-1600 - + 650,-1650 + 650,-1600 + 650,-1600 + 650,-1600 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,-1600 - + 650,- 500 + 650,-1600 + 650,-1600 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,- 450 + 650,- 500 + 650,- 450 + 650,-1600 - + 700,-1600 + 650,- 500 + 650,- 450 + 650,-1600 - + 700 -Sum: 69650 Send LG -Protocol=LG Address=0xF1 Command=0x9876 Raw-Data=0xF19876E 28 bits MSB first +Protocol=LG Address=0xF1 Command=0x9876 Raw-Data=0xF19876E 28 bits MSB first Gap=1053400us Duration=60000us Send with: IrSender.sendLG(0xF1, 0x9876, ); -rawData[60]: - -1059650 - +9100,-4100 - + 650,-1500 + 600,-1500 + 600,-1500 + 600,-1500 - + 600,- 500 + 600,- 450 + 600,- 450 + 650,-1500 - + 600,-1500 + 600,- 450 + 600,- 500 + 600,-1500 - + 600,-1500 + 600,- 500 + 600,- 450 + 600,- 450 - + 650,- 450 + 600,-1500 + 600,-1500 + 600,-1500 - + 650,- 450 + 600,-1500 + 600,-1500 + 600,- 500 - + 600,-1500 + 600,-1500 + 600,-1500 + 600,- 500 - + 600 -Sum: 60450 - -Send MagiQuest -Protocol=MagiQuest Address=0xFFF1 Command=0x76 Raw-Data=0x6BCDFFF1 56 bits MSB first -Send with: IrSender.sendMagiQuest(0x6BCDFFF1, 0x76, ); -rawData[112]: - -1054600 - + 400,- 750 + 400,- 800 + 400,- 750 + 400,- 750 - + 400,- 800 + 400,- 750 + 400,- 800 + 400,- 750 - + 700,- 500 + 650,- 500 + 400,- 800 + 650,- 500 - + 400,- 750 + 700,- 500 + 700,- 450 + 700,- 500 - + 650,- 500 + 400,- 800 + 400,- 750 + 700,- 500 - + 650,- 500 + 400,- 800 + 650,- 500 + 700,- 450 - + 700,- 500 + 650,- 500 + 700,- 500 + 650,- 500 - + 700,- 450 + 700,- 500 + 700,- 450 + 700,- 500 - + 650,- 500 + 700,- 450 + 700,- 500 + 400,- 750 - + 400,- 800 + 400,- 750 + 700,- 500 + 400,- 800 - + 400,- 750 + 700,- 450 + 700,- 500 + 650,- 500 - + 400,- 800 + 650,- 500 + 700,- 450 + 400,- 800 - + 400,- 750 + 400,- 800 + 650,- 500 + 700,- 500 - + 350,- 800 + 700,- 450 + 700,- 500 + 650 -Sum: 65100 +rawData[60]: + -1053400 + +9050,-4150 + + 550,-1550 + 550,-1550 + 550,-1550 + 550,-1550 + + 550,- 500 + 550,- 500 + 550,- 550 + 550,-1500 + + 600,-1500 + 550,- 500 + 550,- 550 + 550,-1500 + + 550,-1550 + 550,- 500 + 600,- 450 + 600,- 500 + + 550,- 500 + 550,-1550 + 550,-1550 + 550,-1550 + + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500 + + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500 + + 550 +Duration=60000us -Send Bang&Olufsen -Protocol=Bang&Olufsen Address=0xF1 Command=0x76 Raw-Data=0xF176 16 bits MSB first -Send with: IrSender.sendBang&Olufsen(0xF1, 0x76, ); -rawData[44]: - -1084600 - + 300,-2850 - + 250,-2900 + 250,-15400 + 300,-2850 + 300,-9100 - + 250,-6050 + 250,-6000 + 250,-6000 + 300,-2850 - + 300,-6000 + 250,-6000 + 300,-9100 + 300,-2850 - + 300,-9100 + 300,-6000 + 250,-6000 + 300,-2850 - + 300,-9100 + 250,-6000 + 300,-2900 + 250,-12250 - + 300 -Sum: 138300 Send Bosewave with no address and 8 command bits -Protocol=BoseWave Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first +Protocol=BoseWave Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first Gap=1068550us Duration=27050us Send with: IrSender.sendBoseWave(0x0, 0x76, ); -rawData[36]: - -1050250 - +1100,-1400 - + 600,- 400 + 600,-1400 + 600,-1400 + 600,- 400 - + 600,-1400 + 600,-1400 + 650,-1400 + 600,- 400 +rawData[36]: + -1068550 + +1050,-1450 + + 600,- 400 + 550,-1450 + 550,-1450 + 600,- 400 + + 550,-1450 + 550,-1400 + 600,-1400 + 600,- 400 + 600,-1400 + 600,- 400 + 600,- 400 + 600,-1400 + 600,- 400 + 600,- 400 + 600,- 400 + 600,-1400 + 600 -Sum: 27150 +Duration=27050us + Send FAST -Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first +Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first Gap=1053550us Duration=29200us Send with: IrSender.sendFAST(0x0, 0x76, ); -rawData[36]: - -1041350 - +2200,-1000 - + 650,- 400 + 650,-1500 + 650,-1500 + 600,- 450 - + 650,-1500 + 650,-1500 + 600,-1500 + 650,- 450 - + 600,-1500 + 650,- 450 + 600,- 450 + 650,-1500 - + 600,- 450 + 650,- 450 + 600,- 450 + 650,-1500 - + 600 -Sum: 29450 +rawData[36]: + -1053550 + +2150,-1050 + + 550,- 500 + 550,-1550 + 600,-1550 + 550,- 500 + + 550,-1600 + 550,-1550 + 550,-1550 + 600,- 450 + + 600,-1500 + 600,- 500 + 550,- 500 + 600,-1550 + + 550,- 500 + 600,- 450 + 600,- 500 + 550,-1550 + + 550 +Duration=29200us + Force buffer overflow by sending 280 marks and spaces Overflow Try to increase the "RAW_BUFFER_LENGTH" value of 200 in UnitTest.cpp -rawData[200]: +rawData[200]: -1039850 + 300,- 450 + 300,- 450 + 350,- 450 + 300,- 450 + 350,- 450 @@ -665,132 +765,338 @@ rawData[200]: Sum: 77050 ERROR: Unknown protocol +Stop receiver +Start receiver address=0xF2 command=0x87 -Send NEC with 8 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first +Send NEC with 8 bit address and complete NEC frames as repeats to force decoding as NEC2 +Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first Gap=1275750us Duration=68200us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -3276750 - +9050,-4400 - + 650,- 500 + 650,-1600 + 650,- 500 + 650,- 450 - + 650,-1600 + 700,-1600 + 650,-1600 + 650,-1600 - + 650,-1600 + 650,- 500 + 650,-1600 + 700,-1550 - + 650,- 500 + 650,- 500 + 600,- 500 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,- 450 + 650,- 500 + 650,- 450 + 700,-1550 - + 700,- 450 + 650,- 500 + 650,- 500 + 650,-1600 - + 650,-1650 + 650,-1600 + 650,-1600 + 650,- 500 +rawData[68]: + -1275750 + +9000,-4450 + + 650,- 500 + 600,-1650 + 600,- 550 + 600,- 550 + + 550,-1650 + 650,-1650 + 550,-1650 + 650,-1650 + + 550,-1650 + 650,- 500 + 600,-1650 + 600,-1650 + + 650,- 450 + 650,- 500 + 600,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,- 500 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,- 550 + 600,- 500 + 650,-1650 + + 550,-1650 + 650,-1650 + 550,-1650 + 650,- 500 + + 600 +Duration=68200us + + +Protocol=NEC2 Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first Repeat Gap=65700us Duration=68200us +Send with: IrSender.sendNEC2(0xF2, 0x87, ); +rawData[68]: + -65700 + +9000,-4450 + + 600,- 550 + 600,-1650 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,- 500 + 650,-1650 + 600,-1650 + + 600,- 550 + 550,- 550 + 600,- 550 + 600,- 500 + + 600,-1650 + 650,-1600 + 600,-1650 + 600,- 550 + + 600,- 500 + 650,- 550 + 550,- 550 + 600,-1650 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + 650 -Sum: 68450 +Duration=68200us + Send NEC with 16 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first +Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first Gap=1067650us Duration=68200us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -1060000 - +9100,-4400 - + 650,- 450 + 700,-1600 + 650,- 450 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,- 500 + 650,-1600 + 650,-1600 - + 650,- 500 + 650,- 500 + 600,- 500 + 650,- 500 - + 650,-1600 + 650,-1600 + 650,-1600 + 700,- 450 - + 650,- 500 + 600,- 500 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,-1600 - + 700,-1550 + 700,-1600 + 650,-1600 + 650,- 500 - + 650 -Sum: 68450 +rawData[68]: + -1067650 + +9000,-4450 + + 600,- 550 + 600,-1650 + 600,- 550 + 600,- 500 + + 650,-1650 + 550,-1650 + 650,-1600 + 600,-1650 + + 650,-1600 + 600,- 550 + 600,-1650 + 600,-1650 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 550,- 550 + 600,- 550 + 600,- 500 + 600,-1650 + + 600,- 550 + 600,- 550 + 600,- 550 + 550,-1650 + + 650,-1650 + 550,-1650 + 650,-1650 + 550,- 550 + + 600 +Duration=68200us + Send NEC2 with 16 bit address -Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first +Protocol=NEC Address=0xF2 Command=0x87 Raw-Data=0x78870DF2 32 bits LSB first Gap=1066900us Duration=68200us Send with: IrSender.sendNEC(0xF2, 0x87, ); -rawData[68]: - -1060100 - +9050,-4400 - + 700,- 450 + 650,-1600 + 650,- 500 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,-1600 - + 700,-1600 + 650,- 450 + 700,-1600 + 650,-1600 - + 650,- 500 + 600,- 500 + 650,- 500 + 650,- 450 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 650,- 500 + 650,- 450 + 650,-1600 - + 700,-1600 + 600,-1650 + 650,-1600 + 650,- 500 - + 650 -Sum: 68450 +rawData[68]: + -1066900 + +9000,-4450 + + 650,- 500 + 600,-1650 + 600,- 550 + 550,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,- 500 + 650,-1650 + 600,-1650 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 600,- 550 + 600,- 550 + 600,- 500 + 650,-1650 + + 550,- 550 + 600,- 550 + 600,- 500 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600 +Duration=68200us + Send Onkyo (NEC with 16 bit command) -Protocol=Onkyo Address=0xF2 Command=0x8887 Raw-Data=0x888700F2 32 bits LSB first +Protocol=Onkyo Address=0xF2 Command=0x8887 Raw-Data=0x888700F2 32 bits LSB first Gap=1068400us Duration=62600us Send with: IrSender.sendOnkyo(0xF2, 0x8887, ); -rawData[68]: - -1060700 - +9100,-4400 - + 650,- 450 + 700,-1600 + 650,- 450 + 700,- 450 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,- 450 - + 700,- 450 + 650,- 500 + 650,- 450 + 650,- 500 - + 650,-1600 + 650,-1600 + 700,-1550 + 700,- 450 - + 650,- 500 + 650,- 500 + 650,- 450 + 650,-1600 - + 700,- 450 + 650,- 500 + 650,- 450 + 650,-1650 - + 650,- 500 + 650,- 450 + 700,- 450 + 650,-1600 - + 650 -Sum: 62800 +rawData[68]: + -1068400 + +9000,-4450 + + 600,- 550 + 600,-1650 + 600,- 500 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,- 550 + + 550,-1650 + 650,-1650 + 550,-1650 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 + + 600 +Duration=62600us + Send Apple -Protocol=Apple Address=0xF2 Command=0x87 Raw-Data=0xF28787EE 32 bits LSB first +Protocol=Apple Address=0xF2 Command=0x87 Raw-Data=0xF28787EE 32 bits LSB first Gap=1067150us Duration=71550us Send with: IrSender.sendApple(0xF2, 0x87, ); -rawData[68]: - -1059150 - +9050,-4400 - + 650,- 500 + 650,-1600 + 650,-1600 + 700,-1600 - + 650,- 450 + 650,-1600 + 700,-1600 + 650,-1600 - + 650,-1600 + 650,-1600 + 700,-1600 + 650,- 450 - + 700,- 450 + 650,- 500 + 650,- 450 + 650,-1600 - + 700,-1600 + 650,-1600 + 650,-1600 + 650,- 500 - + 650,- 450 + 700,- 450 + 650,- 500 + 650,-1600 - + 650,- 500 + 600,-1650 + 650,- 500 + 650,- 450 - + 650,-1600 + 650,-1650 + 650,-1600 + 650,-1600 - + 650 -Sum: 71800 +rawData[68]: + -1067150 + +9000,-4450 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 550,- 550 + 600,- 550 + 600,- 500 + 600,-1650 + + 650,-1600 + 650,-1650 + 600,-1600 + 650,- 500 + + 600,- 550 + 600,- 500 + 650,- 500 + 600,-1650 + + 650,- 500 + 600,-1650 + 600,- 500 + 650,- 500 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600 +Duration=71550us + Send Panasonic -Protocol=Panasonic Address=0xF2 Command=0x87 Raw-Data=0xA8870F202002 48 bits LSB first +Protocol=Panasonic Address=0xF2 Command=0x87 Raw-Data=0xA8870F202002 48 bits LSB first Gap=1065800us Duration=59800us Send with: IrSender.sendPanasonic(0xF2, 0x87, ); -rawData[100]: - -1069050 - +3550,-1650 - + 500,- 400 + 500,-1250 + 500,- 350 + 500,- 400 - + 500,- 350 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,- 350 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,- 350 + 500,-1250 + 500,- 400 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,- 350 - + 500,- 400 + 450,-1300 + 500,- 350 + 550,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,- 350 + 500,- 400 + 500,- 350 + 500,- 400 - + 500,-1250 + 500,-1250 + 450,-1300 + 500,- 350 - + 500,- 400 + 450,- 400 + 500,- 400 + 450,-1300 - + 500,- 350 + 550,- 350 + 500,- 350 + 500,-1250 - + 550,- 350 + 500,-1250 + 450,- 400 + 550,-1200 - + 550 -Sum: 60000 +rawData[100]: + -1065800 + +3500,-1700 + + 500,- 400 + 450,-1250 + 500,- 400 + 500,- 350 + + 500,- 350 + 500,- 400 + 500,- 400 + 450,- 400 + + 500,- 400 + 450,- 400 + 500,- 400 + 500,- 350 + + 500,- 400 + 450,-1250 + 550,- 350 + 450,- 400 + + 500,- 400 + 500,- 350 + 500,- 400 + 450,- 450 + + 450,- 400 + 500,-1250 + 450,- 450 + 450,- 400 + + 500,-1250 + 450,-1250 + 500,-1250 + 500,-1250 + + 500,- 400 + 450,- 400 + 500,- 400 + 450,- 400 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,- 400 + + 500,- 400 + 500,- 350 + 500,- 400 + 450,-1300 + + 450,- 400 + 500,- 400 + 450,- 400 + 500,-1250 + + 450,- 450 + 450,-1250 + 500,- 400 + 450,-1250 + + 500 +Duration=59800us + Send Kaseikyo with 0x4711 as Vendor ID -Protocol=Kaseikyo Address=0xF2 Command=0x87 Extra=0x4711 Raw-Data=0xAB870F234711 48 bits LSB first +Protocol=Kaseikyo Address=0xF2 Command=0x87 Extra=0x4711 Raw-Data=0xAB870F234711 48 bits LSB first Gap=1091300us Duration=66700us Send with: IrSender.sendKaseikyo(0xF2, 0x87, , 0x4711); -rawData[100]: - -1079750 - +3550,-1650 - + 550,-1200 + 550,- 350 + 500,- 350 + 550,- 350 - + 500,-1250 + 500,- 350 + 550,- 350 + 500,- 350 - + 550,-1200 + 550,-1200 + 550,-1200 + 550,- 350 - + 500,- 350 + 550,- 350 + 500,-1250 + 500,- 350 - + 550,-1200 + 550,-1200 + 550,- 350 + 500,- 350 - + 550,- 350 + 500,-1250 + 500,- 350 + 550,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,-1250 - + 500,- 300 + 550,- 400 + 500,- 350 + 550,- 350 - + 500,-1250 + 500,-1250 + 500,-1250 + 500,- 350 - + 500,- 400 + 500,- 350 + 500,- 400 + 500,-1250 - + 500,-1250 + 500,-1250 + 500,- 350 + 500,-1250 - + 500,- 400 + 500,-1250 + 500,- 350 + 500,-1250 - + 550 -Sum: 67000 \ No newline at end of file +rawData[100]: + -1091300 + +3500,-1650 + + 500,-1250 + 500,- 400 + 500,- 350 + 500,- 400 + + 450,-1300 + 450,- 400 + 450,- 450 + 450,- 400 + + 500,-1250 + 450,-1250 + 500,-1250 + 500,- 400 + + 450,- 400 + 500,- 400 + 450,-1250 + 500,- 400 + + 500,-1250 + 450,-1300 + 450,- 400 + 500,- 400 + + 450,- 400 + 500,-1250 + 450,- 450 + 450,- 400 + + 500,-1250 + 450,-1300 + 450,-1300 + 450,-1250 + + 500,- 400 + 450,- 450 + 450,- 400 + 500,- 350 + + 500,-1250 + 500,-1250 + 500,-1250 + 450,- 400 + + 500,- 400 + 500,- 400 + 450,- 400 + 500,-1250 + + 450,-1300 + 450,-1250 + 500,- 400 + 450,-1300 + + 450,- 400 + 500,-1250 + 500,- 350 + 500,-1250 + + 500 +Duration=66700us + + +Send Kaseikyo_Denon variant +Protocol=Kaseikyo_Denon Address=0xF2 Command=0x87 Raw-Data=0xA8870F203254 48 bits LSB first Gap=1090350us Duration=63250us +Send with: IrSender.sendKaseikyo_Denon(0xF2, 0x87, ); +rawData[100]: + -1090350 + +3500,-1700 + + 500,- 200 + 650,- 400 + 450,-1300 + 450,- 400 + + 450,-1300 + 450,- 350 + 550,-1250 + 450,- 450 + + 450,- 400 + 500,-1250 + 450,- 400 + 500,- 400 + + 450,-1300 + 450,-1250 + 500,- 400 + 500,- 400 + + 450,- 400 + 500,- 350 + 500,- 400 + 500,- 400 + + 450,- 400 + 500,-1250 + 500,- 350 + 500,- 400 + + 500,-1250 + 450,-1250 + 500,-1250 + 500,-1250 + + 500,- 350 + 500,- 400 + 450,- 450 + 450,- 400 + + 500,-1250 + 450,-1250 + 500,-1250 + 500,- 400 + + 500,- 350 + 500,- 400 + 450,- 400 + 500,-1250 + + 500,- 400 + 450,- 400 + 500,- 400 + 450,-1300 + + 450,- 400 + 450,-1300 + 500,- 350 + 500,-1250 + + 500 +Duration=63250us + + +Send Denon +Protocol=Denon Address=0x12 Command=0x87 Raw-Data=0x10F2 15 bits LSB first Gap=1088250us Duration=22350us +Send with: IrSender.sendDenon(0x12, 0x87, ); +rawData[32]: + -1088250 + + 300,- 750 + 300,-1800 + 300,- 750 + 300,- 750 + + 300,-1800 + 300,-1800 + 300,-1800 + 300,-1800 + + 300,- 700 + 350,- 700 + 300,- 750 + 300,- 750 + + 300,-1850 + 300,- 750 + 300,- 700 + 350 +Duration=22350us + + +Send Denon/Sharp variant +Protocol=Denon Address=0x12 Command=0x87 Raw-Data=0x30F2 15 bits LSB first Gap=1035000us Duration=23350us +Send with: IrSender.sendDenon(0x12, 0x87, ); +rawData[32]: + -1035000 + + 300,- 750 + 300,-1750 + 300,- 750 + 300,- 750 + + 300,-1800 + 300,-1800 + 300,-1800 + 300,-1800 + + 300,- 750 + 300,- 750 + 300,- 750 + 300,- 750 + + 300,-1750 + 350,-1750 + 350,- 750 + 300 +Duration=23350us + + +Send Sony/SIRCS with 7 command and 5 address bits +Protocol=Sony Address=0x12 Command=0x7 Raw-Data=0x907 12 bits LSB first Gap=1037100us Duration=20000us +Send with: IrSender.sendSony(0x12, 0x7, 2, 12); +rawData[26]: + -1037100 + +2450,- 550 + +1250,- 550 +1250,- 550 +1250,- 600 + 650,- 550 + + 650,- 550 + 650,- 550 + 650,- 600 + 600,- 600 + +1250,- 550 + 650,- 550 + 650,- 600 +1250 +Duration=20000us + + +Send Sony/SIRCS with 7 command and 8 address bits +Protocol=Sony Address=0xF2 Command=0x7 Raw-Data=0x7907 15 bits LSB first Gap=1047000us Duration=25400us +Send with: IrSender.sendSony(0xF2, 0x7, 2, 15); +rawData[32]: + -1047000 + +2450,- 550 + +1250,- 550 +1300,- 500 +1250,- 600 + 650,- 550 + + 650,- 550 + 650,- 550 + 650,- 600 + 600,- 600 + +1250,- 550 + 650,- 550 + 650,- 600 +1250,- 550 + +1200,- 600 +1250,- 550 +1250 +Duration=25400us + + +Send Sony/SIRCS with 7 command and 13 address bits +Protocol=Sony Address=0xF2 Command=0x7 Raw-Data=0x7907 20 bits LSB first Gap=1057650us Duration=31500us +Send with: IrSender.sendSony(0xF2, 0x7, 2, 20); +rawData[42]: + -1057650 + +2450,- 550 + +1250,- 600 +1250,- 550 +1250,- 550 + 650,- 550 + + 650,- 600 + 650,- 550 + 650,- 550 + 650,- 550 + +1250,- 600 + 600,- 600 + 650,- 550 +1250,- 550 + +1250,- 600 +1250,- 550 +1200,- 600 + 650,- 550 + + 650,- 600 + 600,- 600 + 650,- 550 + 650 +Duration=31500us + + +Send Samsung 8 bit command and 8 bit address +Protocol=Samsung Address=0xF2 Command=0x87 Raw-Data=0x7887F2F2 32 bits LSB first Gap=1058000us Duration=65950us +Send with: IrSender.sendSamsung(0xF2, 0x87, ); +rawData[68]: + -1058000 + +4550,-4450 + + 600,- 500 + 650,-1650 + 550,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 500 + 600,-1650 + 600,- 550 + 600,- 500 + + 650,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 650,- 500 + 600,- 550 + 600,- 550 + 600,-1600 + + 650,- 500 + 600,- 550 + 600,- 500 + 650,-1650 + + 550,-1650 + 650,-1650 + 550,-1650 + 650,- 500 + + 600 +Duration=65950us + + +Send Samsung 16 bit command and address +Protocol=Samsung Address=0xF2 Command=0xA987 Raw-Data=0xA98700F2 32 bits LSB first Gap=1068650us Duration=60350us +Send with: IrSender.sendSamsung(0xF2, 0xA987, ); +rawData[68]: + -1068650 + +4500,-4450 + + 600,- 500 + 650,-1600 + 600,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 550 + 600,- 500 + 600,- 550 + 600,- 550 + + 600,- 500 + 650,- 500 + 600,- 550 + 600,- 500 + + 650,-1600 + 600,-1650 + 650,-1600 + 600,- 550 + + 600,- 550 + 600,- 500 + 600,- 550 + 600,-1650 + + 600,-1650 + 600,- 550 + 600,- 500 + 650,-1600 + + 600,- 550 + 600,-1650 + 600,- 500 + 650,-1650 + + 600 +Duration=60350us + + +Send Samsung48 16 bit command +Protocol=Samsung48 Address=0xF2 Command=0xA987 Raw-Data=0x56A9788700F2 48 bits LSB first Gap=1067750us Duration=87450us +Send with: IrSender.sendSamsung48(0xF2, 0xA987, ); +rawData[100]: + -1067750 + +4550,-4400 + + 650,- 500 + 650,-1600 + 600,- 550 + 600,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 500 + 650,- 500 + + 600,- 550 + 600,- 550 + 600,- 550 + 550,- 550 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 550 + + 600,- 500 + 600,- 550 + 600,- 550 + 600,-1650 + + 600,- 500 + 650,- 500 + 600,- 550 + 600,-1650 + + 600,-1650 + 600,-1650 + 600,-1650 + 600,- 500 + + 600,-1650 + 600,- 550 + 600,- 550 + 600,-1650 + + 600,- 550 + 550,-1650 + 650,- 500 + 600,-1650 + + 600,- 550 + 600,-1650 + 600,-1650 + 600,- 500 + + 600,-1650 + 600,- 550 + 600,-1650 + 600,- 550 + + 600 +Duration=87450us + + +Send RC5 +Protocol=RC5 Address=0x12 Command=0x7 Raw-Data=0x1487 13 bits MSB first Gap=1089650us Duration=24200us +Send with: IrSender.sendRC5(0x12, 0x7, ); +rawData[22]: + -1089650 + + 950,- 850 + +1800,-1750 +1800,- 850 + 950,-1750 +1850,- 850 + + 900,- 850 + 950,- 850 + 950,-1750 + 950,- 850 + + 900,- 900 + 950 +Duration=24200us + + +Send RC5X with 7.th MSB of command set +Protocol=RC5 Address=0x12 Command=0x47 Toggle=1 Raw-Data=0xC87 13 bits MSB first Gap=1046350us Duration=24250us +Send with: IrSender.sendRC5(0x12, 0x47, ); +rawData[22]: + -1046350 + +1850,-1750 + + 950,- 850 +1800,- 850 + 950,-1750 +1850,- 850 + + 900,- 900 + 900,- 850 + 950,-1750 + 950,- 850 + + 900,- 900 + 950 +Duration=24250us + + +Send RC6 +Protocol=RC6 Address=0xF2 Command=0x87 Toggle=1 Raw-Data=0x1F287 20 bits MSB first Gap=1042300us Duration=22950us +Send with: IrSender.sendRC6(0xF2, 0x87, ); +rawData[36]: + -1042300 + +2700,- 850 + + 500,- 850 + 500,- 400 + 500,- 400 +1400,- 850 + + 500,- 400 + 500,- 400 + 500,- 400 + 500,- 850 + + 500,- 400 + 950,- 850 + 950,- 850 + 500,- 400 + + 500,- 400 + 500,- 400 + 950,- 400 + 500,- 400 + + 500 +Duration=22950us diff --git a/keywords.txt b/keywords.txt index 935f913e1..ab15edd97 100644 --- a/keywords.txt +++ b/keywords.txt @@ -16,69 +16,101 @@ decodedIRData KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### - -setFeedbackLED KEYWORD2 -enableLEDFeedback KEYWORD2 -enableLEDFeedbackForSend KEYWORD2 -disableLEDFeedback KEYWORD2 -disableLEDFeedbackForSend KEYWORD2 -printIRResultShort KEYWORD2 +# IRReceive +available KEYWORD2 begin KEYWORD2 +decode KEYWORD2 +disableIRIn KEYWORD2 +enableIRIn KEYWORD2 +isIdle KEYWORD2 +printActiveIRProtocols KEYWORD2 +printIRResultMinimal KEYWORD2 +printIRResultRawFormatted KEYWORD2 +printIRResultShort KEYWORD2 +printIRSendUsage KEYWORD2 +registerReceiveCompleteCallback KEYWORD2 +restartAfterSend KEYWORD2 +restartTimer KEYWORD2 +restartTimerWithTicksToAdd KEYWORD2 +resume KEYWORD2 +setReceivePin KEYWORD2 start KEYWORD2 -available KEYWORD2 read KEYWORD2 stop KEYWORD2 end KEYWORD2 -enableLEDFeedback KEYWORD2 -decode KEYWORD2 -resume KEYWORD2 -enableIRIn KEYWORD2 -disableIRIn KEYWORD2 -sendNEC KEYWORD2 + +# IRSend setSendPin KEYWORD2 write KEYWORD2 -enableIROut KEYWORD2 -IRLedOff KEYWORD2 -sendRaw KEYWORD2 +sendApple KEYWORD2 +sendFAST KEYWORD2 sendJVC KEYWORD2 +sendLegoPowerFunctions KEYWORD2 sendLG KEYWORD2 +sendLGSpecialRepeat KEYWORD2 sendLGRepeat KEYWORD2 sendLGRaw KEYWORD2 +sendMaranz KEYWORD2 +sendMagiQuest KEYWORD2 sendNEC KEYWORD2 +sendNEC2 KEYWORD2 +sendNECSpecialRepeat KEYWORD2 sendNECRepeat KEYWORD2 sendNECRaw KEYWORD2 sendOnkyo KEYWORD2 -sendApple KEYWORD2 sendPanasonic KEYWORD2 +sendPronto KEYWORD2 sendKaseikyo KEYWORD2 sendKaseikyo_Denon KEYWORD2 sendKaseikyo_Sharp KEYWORD2 sendKaseikyo_JVC KEYWORD2 sendKaseikyo_Mitsubishi KEYWORD2 +sendRaw KEYWORD2 +sendRaw_P KEYWORD2 sendRC5 KEYWORD2 +sendRC5Marantz KEYWORD2 sendRC6 KEYWORD2 sendSamsungRepeat KEYWORD2 sendSamsung KEYWORD2 sendSharp KEYWORD2 sendSony KEYWORD2 sendSharpRaw KEYWORD2 -sendLegoPowerFunctions KEYWORD2 -sendMagiQuest KEYWORD2 -sendPronto KEYWORD2 -sendMagiQuest KEYWORD2 +sendVelux KEYWORD2 +sendOpenLASIR KEYWORD2 + +# IRFeedbackLED +disableLEDFeedback KEYWORD2 +disableLEDFeedbackForSend KEYWORD2 +enableLEDFeedback KEYWORD2 +enableLEDFeedbackForSend KEYWORD2 +setFeedbackLED KEYWORD2 +setLEDFeedback KEYWORD2 + +# TinyIRReceiver +disablePCIInterruptForTinyReceiver KEYWORD2 +enablePCIInterruptForTinyReceiver KEYWORD2 +initPCIInterruptForTinyReceiver KEYWORD2 +isIRReceiverAttachedForTinyReceiver KEYWORD2 +printTinyReceiverResultMinimal KEYWORD2 +TinyReceiverDecode KEYWORD2 +# TinyIRSender +sendExtendedNEC KEYWORD2 sendFAST KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### +UNKNOWN LITERAL1 PULSE_DISTANCE LITERAL1 PULSE_WIDTH LITERAL1 +APPLE LITERAL1 DENON LITERAL1 -DISH LITERAL1 JVC LITERAL1 LG LITERAL1 -LG2 LITERAL1 NEC LITERAL1 +NEC2 LITERAL1 +ONKYO LITERAL1 PANASONIC LITERAL1 KASEIKYO LITERAL1 KASEIKYO_JVC LITERAL1 @@ -87,18 +119,57 @@ KASEIKYO_SHARP LITERAL1 KASEIKYO_MITSUBISHI LITERAL1 RC5 LITERAL1 RC6 LITERAL1 +RC6A LITERAL1 SAMSUNG LITERAL1 +SAMSUNGLG LITERAL1 +SAMSUNG48 LITERAL1 SHARP LITERAL1 SONY LITERAL1 -ONKYO LITERAL1 -APPLE LITERAL1 BANG_OLUFSEN LITERAL1 BOSEWAVE LITERAL1 LEGO_PF LITERAL1 MAGIQUEST LITERAL1 WHYNTER LITERAL1 FAST LITERAL1 -UNKNOWN LITERAL1 -IR_RECEIVE_PIN LITERAL1 + +IRDATA_FLAGS_IS_REPEAT LITERAL1 +IRDATA_FLAGS_IS_AUTO_REPEAT LITERAL1 +IRDATA_FLAGS_PARITY_FAILED LITERAL1 +IRDATA_FLAGS_TOGGLE_BIT LITERAL1 +IRDATA_FLAGS_EXTRA_INFO LITERAL1 +IRDATA_FLAGS_WAS_OVERFLOW LITERAL1 +IRDATA_FLAGS_IS_MSB_FIRST LITERAL1 + + +RAW_BUFFER_LENGTH LITERAL1 +EXCLUDE_UNIVERSAL_PROTOCOLS LITERAL1 +EXCLUDE_EXOTIC_PROTOCOLS LITERAL1 +IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK LITERAL1 +MARK_EXCESS_MICROS LITERAL1 +RECORD_GAP_MICROS LITERAL1 +DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE LITERAL1 +IR_INPUT_IS_ACTIVE_HIGH LITERAL1 IR_SEND_PIN LITERAL1 -FEEDBACK_LED_IS_ACTIVE_LOW LITERAL1 +SEND_PWM_BY_TIMER LITERAL1 +IR_SEND_DUTY_CYCLE_PERCENT LITERAL1 +USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN LITERAL1 +USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN LITERAL1 +USE_NO_SEND_PWM LITERAL1 +USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM LITERAL1 +DISABLE_CODE_FOR_RECEIVER LITERAL1 +FEEDBACK_LED_IS_ACTIVE_LOW LITERAL1 +NO_LED_FEEDBACK_CODE LITERAL1 +NO_LED_RECEIVE_FEEDBACK_CODE LITERAL1 +NO_LED_SEND_FEEDBACK_CODE LITERAL1 +MICROS_PER_TICK LITERAL1 +TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT LITERAL1 + +# Constants for TinyIRReceiver +IR_RECEIVE_PIN LITERAL1 +IR_FEEDBACK_LED_PIN LITERAL1 +DISABLE_PARITY_CHECKS LITERAL1 +USE_EXTENDED_NEC_PROTOCOL LITERAL1 +USE_ONKYO_PROTOCOL LITERAL1 +USE_FAST_PROTOCOL LITERAL1 +ENABLE_NEC2_REPEATS LITERAL1 +USE_CALLBACK_FOR_TINY_RECEIVER LITERAL1 diff --git a/library.json b/library.json index 9bfa9873f..e621f7c06 100644 --- a/library.json +++ b/library.json @@ -1,15 +1,14 @@ { "name": "IRremote", - "keywords": "communication, infrared, ir, remote", + "version": "4.7.1", "description": "Send and receive infrared signals with multiple protocols", + "keywords": "communication, infrared, ir, remote", + "homepage": "https://github.com/Arduino-IRremote/Arduino-IRremote", "repository": { "type": "git", - "url": "https://github.com/z3t0/Arduino-IRremote.git" + "url": "https://github.com/Arduino-IRremote/Arduino-IRremote.git" }, - "version": "4.1.2", - "frameworks": "arduino", - "platforms": ["atmelavr", "atmelmegaavr", "atmelsam", "espressif8266", "espressif32", "ststm32"], "authors" : [ { @@ -26,5 +25,10 @@ "email":"ken.shirriff@gmail.com" } ], - "headers": "IRRemote.hpp" + "license": "MIT", + "frameworks": "arduino", + "platforms": ["atmelavr", "atmelmegaavr", "atmelsam", "espressif8266", "espressif32", "ststm32", "raspberrypi"], + "headers": "IRRemote.hpp", + "examples": "examples/*/*.ino", + "export": {"exclude": [".github", "pictures"]} } diff --git a/library.properties b/library.properties index ad2bdd36b..f0beef631 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=IRremote -version=4.1.2 +version=4.7.1 author=shirriff, z3t0, ArminJo maintainer=Armin Joachimsmeyer sentence=Send and receive infrared signals with multiple protocols -paragraph=Currently included protocols: Denon / Sharp, JVC, LG / LG2, NEC / Onkyo / Apple, Panasonic / Kaseikyo, RC5, RC6, Samsung, Sony, (Pronto), BangOlufsen, BoseWave, Lego, Whynter, FAST, MagiQuest.

New: Added FAST Protocol. Changed some function signatures. Improved handling of PULSE_DISTANCE + PULSE_WIDTH protocols.
Release notes
+paragraph=Currently included protocols: Denon / Sharp, JVC, LG, NEC / Onkyo / Apple, Panasonic / Kaseikyo, RC5, RC6, Samsung, Sony, (Pronto), BangOlufsen, BoseWave, Lego, Whynter, FAST, MagiQuest, Velux, Universal Pulse Distance and Pulse Width. category=Communication url=https://github.com/Arduino-IRremote/Arduino-IRremote -architectures=avr,megaavr,samd,esp8266,esp32,stm32,STM32F1,mbed,mbed_nano,rp2040,mbed_rp2040 +architectures=avr,megaavr,samd,esp8266,esp32,stm32,STM32F1,mbed,mbed_nano,rp2040,mbed_rp2040,renesas_uno,riscv,nRF5 includes=IRremote.hpp diff --git a/pictures/BoseWaveSoundTouch_IV.jpg b/pictures/BoseWaveSoundTouch_IV.jpg new file mode 100644 index 000000000..17d535d90 Binary files /dev/null and b/pictures/BoseWaveSoundTouch_IV.jpg differ diff --git a/pictures/IRReceiverPinout.jpg b/pictures/IRReceiverPinout.jpg new file mode 100644 index 000000000..5e232d157 Binary files /dev/null and b/pictures/IRReceiverPinout.jpg differ diff --git a/pictures/IR_RobotCar.jpg b/pictures/IR_RobotCar.jpg new file mode 100644 index 000000000..6258d0136 Binary files /dev/null and b/pictures/IR_RobotCar.jpg differ diff --git a/pictures/IR_UnitTest_delay.bmp b/pictures/IR_UnitTest_delay.bmp new file mode 100644 index 000000000..00e17dd49 Binary files /dev/null and b/pictures/IR_UnitTest_delay.bmp differ diff --git a/src/IRCommandDispatcher.h b/src/IRCommandDispatcher.h new file mode 100644 index 000000000..f4f89d26d --- /dev/null +++ b/src/IRCommandDispatcher.h @@ -0,0 +1,130 @@ +/* + * IRCommandDispatcher.h + * + * Library to process IR commands by calling functions specified in a mapping array. + * + * To run this example you need to install the "IRremote" or "IRMP" library under "Tools -> Manage Libraries..." or "Ctrl+Shift+I" + * + * Copyright (C) 2019-2026 Armin Joachimsmeyer + * + * This file is part of ServoEasing https://github.com/ArminJo/ServoEasing. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * IRCommandDispatcher is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _IR_COMMAND_DISPATCHER_H +#define _IR_COMMAND_DISPATCHER_H + +#include + +//#define DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT // Enables mapping and dispatching of IR commands consisting of more than 8 bits. Saves up to 160 bytes program memory and 5 bytes RAM + 1 byte RAM per mapping entry. +//#define USE_DISPATCHER_COMMAND_STRINGS // Enables the printing of command strings. Requires additional 2 bytes RAM for each command mapping. Requires program memory for strings, but saves snprintf() code (1.5k) if INFO or DEBUG is activated, which has no effect if snprintf() is also used in other parts of your program / libraries. +#if defined(USE_DISPATCHER_COMMAND_STRINGS) +#define COMMAND_STRING(anyString) anyString +#else +#define COMMAND_STRING(anyString) +#endif +/* + * For command mapping file + */ +#define IR_COMMAND_FLAG_BLOCKING 0x00 // default - blocking command, repeat not accepted, only one command at a time. Stops an already running command. +#define IR_COMMAND_FLAG_REPEATABLE 0x01 // repeat accepted +#define IR_COMMAND_FLAG_NON_BLOCKING 0x02 // Non blocking (short) command that can be processed any time and may interrupt other IR commands - used for stop, set direction etc. +#define IR_COMMAND_FLAG_REPEATABLE_NON_BLOCKING (IR_COMMAND_FLAG_REPEATABLE | IR_COMMAND_FLAG_NON_BLOCKING) +#define IR_COMMAND_FLAG_BEEP 0x04 // Do a single short beep before executing command. May not be useful for short or repeating commands. +#define IR_COMMAND_FLAG_BLOCKING_BEEP (IR_COMMAND_FLAG_BLOCKING | IR_COMMAND_FLAG_BEEP) + +#if !defined(IS_STOP_REQUESTED) +#define IS_STOP_REQUESTED IRDispatcher.requestToStopReceived +#endif +#if !defined(RETURN_IF_STOP) +#define RETURN_IF_STOP if (IRDispatcher.requestToStopReceived) return +#endif +#if !defined(BREAK_IF_STOP) +#define BREAK_IF_STOP if (IRDispatcher.requestToStopReceived) break +#endif +#if !defined(DELAY_AND_RETURN_IF_STOP) +#define DELAY_AND_RETURN_IF_STOP(aDurationMillis) if (IRDispatcher.delayAndCheckForStop(aDurationMillis)) return +#endif + +/* + * Define as COMMAND_EMPTY a code which is not sent by the remote - otherwise please redefine it here + */ +#if defined(DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT) +#define COMMAND_EMPTY __UINT_FAST16_MAX__ // 0xFFFF code no command +typedef uint_fast16_t IRCommandType; +#else +typedef uint_fast8_t IRCommandType; +#define COMMAND_EMPTY __UINT_FAST8_MAX__ // 0xFF code no command +#endif + +// Basic mapping structure +struct IRToCommandMappingStruct { + IRCommandType IRCode; + uint8_t Flags; + void (*CommandToCall)(); +#if defined(USE_DISPATCHER_COMMAND_STRINGS) + const char *CommandString; +#endif +}; + +struct IRDataForCommandDispatcherStruct { + uint16_t address; // to distinguish between multiple senders + IRCommandType command; + bool isRepeat; + volatile uint32_t MillisOfLastCode; // millis() of last IR command -including repeats!- received - for timeouts etc. + volatile bool isAvailable; // flag for a polling interpreting function, that a new command has arrived. Is set true by library and set false by main loop. +}; + +class IRCommandDispatcher { +public: + void init(); + void printIRInfo(Print *aSerial); + + bool checkAndRunNonBlockingCommands(); + bool checkAndRunSuspendedBlockingCommands(); + void setNextBlockingCommand(IRCommandType aBlockingCommandToRunNext); + bool delayAndCheckForStop(uint16_t aDelayMillis); + + // The main dispatcher function + void checkAndCallCommand(bool aCallBlockingCommandImmediately); + + void printIRCommandString(Print *aSerial, IRCommandType aCommand); + void printIRCommandStringForArrayIndex(Print *aSerial, uint_fast8_t aMappingArrayIndex); + void setRequestToStopReceived(bool aRequestToStopReceived = true); + + IRCommandType currentBlockingCommandCalled = COMMAND_EMPTY; // The code for the current called command + IRCommandType lastBlockingCommandCalled = COMMAND_EMPTY; // The code for the last called command. Can be evaluated by main loop + IRCommandType BlockingCommandToRunNext = COMMAND_EMPTY; // Storage for command currently suspended to allow the current command to end, before it is called by main loop + bool justCalledBlockingCommand = false; // Flag that a blocking command was received and called - is set before call of command + /* + * Flag for running blocking commands to terminate. To check, you can use "if (IRDispatcher.requestToStopReceived) return;" (available as macro RETURN_IF_STOP). + * It is set if a blocking IR command received, which cannot be executed directly. Can be reset by main loop, if command has stopped. + * It is reset before executing a blocking command. + */ + volatile bool requestToStopReceived; + /* + * This flag must be true, if we have a function, which want to interpret the IR codes by itself e.g. the calibrate function of QuadrupedControl + */ + bool doNotUseDispatcher = false; + + struct IRDataForCommandDispatcherStruct IRReceivedData; + +}; + +extern IRCommandDispatcher IRDispatcher; + +#endif // _IR_COMMAND_DISPATCHER_H diff --git a/src/IRCommandDispatcher.hpp b/src/IRCommandDispatcher.hpp new file mode 100644 index 000000000..0a65efd3e --- /dev/null +++ b/src/IRCommandDispatcher.hpp @@ -0,0 +1,512 @@ +/* + * IRCommandDispatcher.hpp + * + * Library to process IR commands by calling functions specified in a mapping array. + * Commands can be tagged as blocking or non blocking. + * + * To run this example you need to install the "IRremote" or "IRMP" library. + * Install it under "Tools -> Manage Libraries..." or "Ctrl+Shift+I" + * + * The IR library calls a callback function, which executes a non blocking command directly in ISR (Interrupt Service Routine) context! + * A blocking command is stored and sets a stop flag for an already running blocking function to terminate. + * The blocking command can in turn be executed by main loop by calling IRDispatcher.checkAndRunSuspendedBlockingCommands(). + * + * Copyright (C) 2019-2026 Armin Joachimsmeyer + * + * This file is part of ServoEasing https://github.com/ArminJo/ServoEasing. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + * IRCommandDispatcher is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * Program behavior is modified by the following macros + * USE_TINY_IR_RECEIVER + * USE_IRMP_LIBRARY + * DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT + */ + +#ifndef _IR_COMMAND_DISPATCHER_HPP +#define _IR_COMMAND_DISPATCHER_HPP + +#include + +#include "IRCommandDispatcher.h" + +//#define NO_LED_FEEDBACK_CODE // Activate this if you want to suppress LED feedback or if you do not have a LED. This saves 14 bytes code and 2 clock cycles per interrupt. + +//#define USE_TINY_IR_RECEIVER // Recommended and default, but only for NEC protocol!!! If disabled and IRMP_INPUT_PIN is defined, the IRMP library is used for decoding +//#define USE_IRREMOTE_LIBRARY // The IRremote library is used for decoding +//#define USE_IRMP_LIBRARY // The IRMP library is used for decoding +#if !defined(USE_TINY_IR_RECEIVER) && !defined(USE_IRREMOTE_LIBRARY) && !defined(USE_IRMP_LIBRARY) +#define USE_TINY_IR_RECEIVER // Set TiniIR as default library +#endif + +IRCommandDispatcher IRDispatcher; + +#if defined(USE_TINY_IR_RECEIVER) +/****************************** + * Code for the TinyIR library + ******************************/ +#if defined(USE_ONKYO_PROTOCOL) && ! defined(DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT) +#warning ONKYO protocol has 16 bit commands so activating of DISPATCHER_IR_COMMAND_HAS_MORE_THAN_8_BIT is recommended +#endif +#define USE_CALLBACK_FOR_TINY_RECEIVER // Call the function "handleReceivedTinyIRData()" below each time a frame or repeat is received. +#include "TinyIRReceiver.hpp" // included in "IRremote" and "IRMP" library + +// This block must be located after the includes of other *.hpp files +//#define LOCAL_INFO // This enables info output only for this file +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" + +void IRCommandDispatcher::init() { + initPCIInterruptForTinyIRReceiver(); +} +/* + * This is the TinyIRReceiver callback function, which is called if a complete command was received. + * Interrupts are enabled here to allow e.g. delay() in commands. + * Copy the (volatile) IR data in order not to be overwritten on receiving of next frame. + * Next, check for right address if IR_ADDRESS is defined. + * At last call the dispatcher. + */ +# if defined(ESP8266) || defined(ESP32) +IRAM_ATTR +# endif +void handleReceivedTinyIRData() { + IRDispatcher.IRReceivedData.address = TinyIRReceiverData.Address; + IRDispatcher.IRReceivedData.command = TinyIRReceiverData.Command; + IRDispatcher.IRReceivedData.isRepeat = TinyIRReceiverData.Flags & IRDATA_FLAGS_IS_REPEAT; + IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); + +# if defined(LOCAL_INFO) + printTinyIRReceiverResultMinimal(&Serial); +# endif + +# if defined(IR_ADDRESS) + // if available, compare address. TinyIRReceiverData.Address saves 6 bytes + if (TinyIRReceiverData.Address != IR_ADDRESS) { // IR_ADDRESS is defined in *IRCommandMapping.h + INFO_PRINT(F("Wrong address. Expected 0x")); + INFO_PRINTLN(IR_ADDRESS, HEX); + } else +# endif + { + IRDispatcher.IRReceivedData.isAvailable = true; + // check if dispatcher enabled + if (!IRDispatcher.doNotUseDispatcher) { + /* + * Only short (non blocking) commands are executed directly in ISR (Interrupt Service Routine) context, + * others are stored for main loop which calls checkAndRunSuspendedBlockingCommands() + */ + IRDispatcher.checkAndCallCommand(false); + } + } +} + +#elif defined(USE_IRREMOTE_LIBRARY) +/********************************* + * Code for the IRremote library + *********************************/ +#define DECODE_NEC // Includes Apple and Onkyo +#include "IRremote.hpp" + +// This block must be located after the includes of other *.hpp files +//#define LOCAL_INFO // This enables info output only for this file +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" + +void ReceiveCompleteCallbackHandler(); + +void IRCommandDispatcher::init() { + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); + /* + * Tell the ISR to call this function, when a complete frame has been received + */ + IrReceiver.registerReceiveCompleteCallback(ReceiveCompleteCallbackHandler); +} + +/* + * Callback function + * Here we know, that data is available. + * This function is executed in an ISR (Interrupt Service Routine) context. + * This means that interrupts are blocked here, so delay(), millis() and Serial prints of data longer than the print buffer size etc. will block forever. + * This is because they require their internal interrupt routines to run in order to return. + * Therefore it is best to make this callback function short and fast! + * A dirty hack is to enable interrupts again by calling sei() (enable interrupt again), but you should know what you are doing, + */ +#if defined(ESP32) || defined(ESP8266) +IRAM_ATTR +# endif +void ReceiveCompleteCallbackHandler() { + /* + * Fill IrReceiver.decodedIRData + */ + IrReceiver.decode(); + + IRDispatcher.IRReceivedData.address = IrReceiver.decodedIRData.address; + IRDispatcher.IRReceivedData.command = IrReceiver.decodedIRData.command; + IRDispatcher.IRReceivedData.isRepeat = IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT; + IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); + + // Interrupts are already enabled for SUPPORT_MULTIPLE_RECEIVER_INSTANCES +#if !defined(SUPPORT_MULTIPLE_RECEIVER_INSTANCES) && !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled + interrupts(); // To enable tone(), delay() etc. for commands. Be careful with non-blocking and repeatable commands which lasts longer than the IR repeat duration. +# endif + +# if defined(LOCAL_INFO) + IrReceiver.printIRResultMinimal(&Serial); + Serial.println(); +# endif + /* + * Enable receiving of the next frame. + */ + IrReceiver.resume(); + +# if defined(IR_ADDRESS) + // if available, compare address + if (IRDispatcher.IRReceivedData.address != IR_ADDRESS) { // IR_ADDRESS is defined in *IRCommandMapping.h + INFO_PRINT(F("Wrong address. Expected 0x")); + INFO_PRINTLN(IR_ADDRESS, HEX); + } else +# endif + { + IRDispatcher.IRReceivedData.isAvailable = true; + // check if dispatcher enabled + if (!IRDispatcher.doNotUseDispatcher) { + /* + * Only short (non blocking) commands are executed directly in ISR (Interrupt Service Routine) context, + * others are stored for main loop which calls checkAndRunSuspendedBlockingCommands() + */ + IRDispatcher.checkAndCallCommand(false); + } + } +} + +#elif defined(USE_IRMP_LIBRARY) +/****************************** + * Code for the IRMP library + ******************************/ +#define IRMP_USE_COMPLETE_CALLBACK 1 // Enable callback functionality. It is required if IRMP library is used. +#define IRMP_PROTOCOL_NAMES 1 // Enable protocol number mapping to protocol strings for printIRInfo() +#include "irmp.hpp" +#include "LocalDebugLevelStart.h" + +IRMP_DATA irmp_data; + +void handleReceivedIRData(); + +void IRCommandDispatcher::init() +{ + irmp_init(); + irmp_register_complete_callback_function(&handleReceivedIRData); // fixed function in IRCommandDispatcher.hpp +} + +/* + * This is the callback function, which is called if a complete command was received. + * Interrupts are NOT enabled here so we must do it manually to allow e.g. delay() in commands. + * Copy the (volatile) IR data in order not to be overwritten on receiving of next frame. + * Next, check for right address if IR_ADDRESS is defined. + * At last call the dispatcher. + */ +#if defined(ESP8266) || defined(ESP32) +IRAM_ATTR +#endif +void handleReceivedIRData() +{ + irmp_get_data(&irmp_data); + + IRDispatcher.IRReceivedData.address = irmp_data.address; + IRDispatcher.IRReceivedData.command = irmp_data.command; + IRDispatcher.IRReceivedData.isRepeat = irmp_data.flags & IRMP_FLAG_REPETITION; + IRDispatcher.IRReceivedData.MillisOfLastCode = millis(); + +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled + interrupts(); // To enable tone(), delay() etc. for commands. Be careful with non-blocking and repeatable commands which lasts longer than the IR repeat duration. +# endif + +# if defined(LOCAL_INFO) + irmp_result_print(&Serial, &irmp_data); +# endif + +# if defined(IR_ADDRESS) + // if available, compare address + if (IRDispatcher.IRReceivedData.address != IR_ADDRESS) { + INFO_PRINT(F("Wrong address. Expected 0x")); + INFO_PRINTLN(IR_ADDRESS, HEX); + } else +# endif + { + IRDispatcher.IRReceivedData.isAvailable = true; + // check if dispatcher enabled + if (!IRDispatcher.doNotUseDispatcher) + { + /* + * Only short (non blocking) commands are executed directly in ISR (Interrupt Service Routine) context, + * others are stored for main loop which calls checkAndRunSuspendedBlockingCommands() + */ + IRDispatcher.checkAndCallCommand(false); + } + } +} +#endif // elif defined(USE_IRMP_LIBRARY) + +/******************************************* + * Start of the IR library independent code + *******************************************/ +void IRCommandDispatcher::printIRInfo(Print *aSerial) { + aSerial->println(); + // For available IR commands see IRCommandMapping.h https://github.com/ArminJo/PWMMotorControl/blob/master/examples/SmartCarFollower/IRCommandMapping.h +#if defined(USE_IRMP_LIBRARY) +# if defined(IR_REMOTE_NAME) + aSerial->println(F("Listening to IR remote of type " STR(IR_REMOTE_NAME) " at pin " STR(IRMP_INPUT_PIN))); +# else + aSerial->println(F("Listening to IR remote at pin " STR(IRMP_INPUT_PIN))); +# endif + aSerial->print(F("Accepted protocols are: ")); + irmp_print_active_protocols(aSerial); + aSerial->println(); +#else +# if defined(IR_REMOTE_NAME) + aSerial->println(F("Listening to IR remote of type " STR(IR_REMOTE_NAME) " at pin " STR(IR_RECEIVE_PIN))); +# else + aSerial->println(F("Listening to IR remote at pin " STR(IR_RECEIVE_PIN))); +# endif +#endif +} + +/* + * The main dispatcher function called by IR-ISR, main loop and checkAndRunSuspendedBlockingCommands() + * Non blocking commands are executed immediately, blocking commands are executed if no other command is just running. + * If another blocking command is currently running, the request to stop is set + * and the command is stored for main loop to be later execute by checkAndRunSuspendedBlockingCommands(). + * This function sets flags justCalledRegularIRCommand, executingBlockingCommand, requestToStopReceived + * @param aCallBlockingCommandImmediately Run blocking command directly, if no other command is just running. + * Should be false if called by ISR in order not to block ISR. Is true when called from checkAndRunSuspendedBlockingCommands(). + */ +void IRCommandDispatcher::checkAndCallCommand(bool aCallBlockingCommandImmediately) { + if (IRReceivedData.command == COMMAND_EMPTY) { + return; + } + + /* + * Search for command in Array of IRToCommandMappingStruct + */ + for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) { + if (IRReceivedData.command == IRMapping[i].IRCode) { + /* + * Command found + */ +#if defined(LOCAL_INFO) +# if defined(__AVR__) +# if defined(USE_DISPATCHER_COMMAND_STRINGS) + const __FlashStringHelper *tCommandName = reinterpret_cast(IRMapping[i].CommandString); +# else + char tCommandName[7]; + snprintf_P(tCommandName, sizeof(tCommandName), PSTR("0x%x"), IRMapping[i].IRCode); +# endif +# else +# if defined(USE_DISPATCHER_COMMAND_STRINGS) + const char *tCommandName = IRMapping[i].CommandString; +# else + char tCommandName[7]; + snprintf(tCommandName, sizeof(tCommandName), "0x%x", IRMapping[i].IRCode); +# endif +# endif +#endif + /* + * Check for repeat and if repeat is allowed for the current command + */ + if (IRReceivedData.isRepeat && !(IRMapping[i].Flags & IR_COMMAND_FLAG_REPEATABLE)) { + + DEBUG_PRINT(F("Repeats of command \"")); + DEBUG_PRINT(tCommandName); + DEBUG_PRINTLN("\" not accepted"); + + return; + } + + /* + * Do not accept recursive call of the same command + */ + if (currentBlockingCommandCalled == IRReceivedData.command) { + + DEBUG_PRINT(F("Recursive command \"")); + DEBUG_PRINT(tCommandName); + DEBUG_PRINTLN("\" not accepted"); + + return; + } + + /* + * Execute commands + */ + bool tIsNonBlockingCommand = (IRMapping[i].Flags & IR_COMMAND_FLAG_NON_BLOCKING); + if (tIsNonBlockingCommand) { + // short command here, just call + INFO_PRINT(F("Run non blocking command: ")); + INFO_PRINTLN(tCommandName); +#if defined(DISPATCHER_BUZZER_FEEDBACK_PIN) && defined(USE_TINY_IR_RECEIVER) + /* + * Do (non blocking) buzzer feedback before command is executed + */ + if(IRMapping[i].Flags & IR_COMMAND_FLAG_BEEP) { + tone(DISPATCHER_BUZZER_FEEDBACK_PIN, 2200, 50); + } +#endif + IRMapping[i].CommandToCall(); + } else { + /* + * Blocking command here + */ + if (aCallBlockingCommandImmediately && currentBlockingCommandCalled == COMMAND_EMPTY) { + /* + * Here no blocking command was running and we are called from main loop + */ + requestToStopReceived = false; // Do not stop the command executed now + justCalledBlockingCommand = true; + currentBlockingCommandCalled = IRReceivedData.command; // set lock for recursive calls + lastBlockingCommandCalled = IRReceivedData.command; // set history, can be evaluated by main loop + + /* + * This call is blocking!!! + */ + INFO_PRINT(F("Run blocking command: ")); + INFO_PRINTLN(tCommandName); + +#if defined(DISPATCHER_BUZZER_FEEDBACK_PIN) && defined(USE_TINY_IR_RECEIVER) + /* + * Do (non blocking) buzzer feedback before command is executed + */ + if(IRMapping[i].Flags & IR_COMMAND_FLAG_BEEP) { + tone(DISPATCHER_BUZZER_FEEDBACK_PIN, 2200, 50); + } +#endif + + IRMapping[i].CommandToCall(); + TRACE_PRINTLN(F("End of blocking command")); + + currentBlockingCommandCalled = COMMAND_EMPTY; + } else { + /* + * Called by ISR or another command still running. + * Do not run command directly, but set request to stop to true and store command + * for main loop to execute by checkAndRunSuspendedBlockingCommands() + */ + BlockingCommandToRunNext = IRReceivedData.command; + requestToStopReceived = true; // to stop running command + INFO_PRINT(F("Requested stop and stored blocking command ")); + INFO_PRINT(tCommandName); + INFO_PRINTLN(F(" as next command to run.")); + } + } + break; // command found + } // if (IRReceivedData.command == IRMapping[i].IRCode) + } // for loop + return; +} + +/* + * Intended to be called from main loop + * @return true, if command was called + */ +bool IRCommandDispatcher::checkAndRunSuspendedBlockingCommands() { + /* + * Take last rejected command and call associated function + */ + if (BlockingCommandToRunNext != COMMAND_EMPTY) { + + INFO_PRINT(F("Run stored command=0x")); + INFO_PRINTLN(BlockingCommandToRunNext, HEX); + + IRReceivedData.command = BlockingCommandToRunNext; + BlockingCommandToRunNext = COMMAND_EMPTY; + IRReceivedData.isRepeat = false; + requestToStopReceived = false; // Signal to main loop to stop the command currently executed + checkAndCallCommand(true); + return true; + } + return false; +} + +/* + * Not used internally + */ +void IRCommandDispatcher::setNextBlockingCommand(IRCommandType aBlockingCommandToRunNext) { +#if defined(LOCAL_INFO) + Serial.print(F("Set next command to run to 0x")); + Serial.print(aBlockingCommandToRunNext, HEX); +# if defined(USE_DISPATCHER_COMMAND_STRINGS) + Serial.print('|'); + printIRCommandString(&Serial, aBlockingCommandToRunNext); +# endif + Serial.println(); +#endif + + BlockingCommandToRunNext = aBlockingCommandToRunNext; + requestToStopReceived = true; +} + +/* + * Special delay function for the IRCommandDispatcher. Returns prematurely if requestToStopReceived is set. + * To be used in blocking functions as delay + * @return true - as soon as stop received + */ +bool IRCommandDispatcher::delayAndCheckForStop(uint16_t aDelayMillis) { + uint32_t tStartMillis = millis(); + do { + if (requestToStopReceived) { + return true; + } + } while (millis() - tStartMillis < aDelayMillis); + return false; +} + +void IRCommandDispatcher::printIRCommandStringForArrayIndex(Print *aSerial, uint_fast8_t aMappingArrayIndex) { +#if defined(__AVR__) +# if defined(USE_DISPATCHER_COMMAND_STRINGS) + aSerial->println(reinterpret_cast(IRMapping[aMappingArrayIndex].CommandString)); +# else + aSerial->print(F("0x")); + aSerial->println(IRMapping[aMappingArrayIndex].IRCode, HEX); +# endif +#else +# if defined(USE_DISPATCHER_COMMAND_STRINGS) + aSerial->println(IRMapping[aMappingArrayIndex].CommandString); +# else + aSerial->print("0x"); + aSerial->println(IRMapping[aMappingArrayIndex].IRCode, HEX); +# endif +#endif +} + +void IRCommandDispatcher::printIRCommandString(Print *aSerial, IRCommandType aCommand) { + for (uint_fast8_t i = 0; i < sizeof(IRMapping) / sizeof(struct IRToCommandMappingStruct); ++i) { + if (aCommand == IRMapping[i].IRCode) { + printIRCommandStringForArrayIndex(aSerial, i); + return; + } + } + aSerial->println(F("unknown")); +} + +void IRCommandDispatcher::setRequestToStopReceived(bool aRequestToStopReceived) { + requestToStopReceived = aRequestToStopReceived; +} + +#include "LocalDebugLevelEnd.h" + +#endif // _IR_COMMAND_DISPATCHER_HPP diff --git a/src/IRFeedbackLED.hpp b/src/IRFeedbackLED.hpp index 97611b083..058c7285c 100644 --- a/src/IRFeedbackLED.hpp +++ b/src/IRFeedbackLED.hpp @@ -8,7 +8,7 @@ ************************************************************************************* * MIT License * - * Copyright (c) 2021-2022 Armin Joachimsmeyer + * Copyright (c) 2021-2026 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 @@ -40,33 +40,30 @@ * Contains pin number and enable status of the feedback LED */ struct FeedbackLEDControlStruct { - uint8_t FeedbackLEDPin; ///< if 0, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions - uint8_t LedFeedbackEnabled; ///< LED_FEEDBACK_ENABLED_FOR_RECEIVE or LED_FEEDBACK_ENABLED_FOR_SEND -> enable blinking of pin on IR processing + uint8_t FeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN; ///< if USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF, then use digitalWriteFast(LED_BUILTIN,..) otherwise use digitalWrite(FeedbackLEDPin,..) + bool LedFeedbackEnabled; ///< Disabled for receive at default. Feedback for send is always enabled and can be disabled by NO_LED_SEND_FEEDBACK_CODE or #define NO_LED_FEEDBACK_CODE macros }; struct FeedbackLEDControlStruct FeedbackLEDControl; ///< The feedback LED control instance /** - * Enable blinking of feedback LED (LED_BUILTIN is taken as default) on IR sending and receiving - * Cannot disable it here!!! Use disableLEDFeedbackForReceive() or disableLEDFeedbackForSend() - * @param aFeedbackLEDPin If aFeedbackLEDPin == 0, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions - * If FeedbackLEDPin == 0 and no LED_BUILTIN defined, disable LED feedback - * @param aEnableLEDFeedback If LED_FEEDBACK_ENABLED_FOR_RECEIVE or LED_FEEDBACK_ENABLED_FOR_SEND -> enable blinking of Feedback LED + * @param aFeedbackLEDPin If FeedbackLEDPin != USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF, then use digitalWrite / digitalWriteFast(FeedbackLEDPin,..) + * If FeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF and LED_BUILTIN defined, then use digitalWriteFast(LED_BUILTIN,..) + * If FeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF and no LED_BUILTIN defined, disable LED feedback */ -void setLEDFeedback(uint8_t aFeedbackLEDPin, uint8_t aEnableLEDFeedback) { +void setLEDFeedbackPin(uint8_t aFeedbackLEDPin) { + FeedbackLEDControl.FeedbackLEDPin = aFeedbackLEDPin; - FeedbackLEDControl.FeedbackLEDPin = aFeedbackLEDPin; // default is 0 -> use LED_BUILTIN if available, else disable feedback - - if (aEnableLEDFeedback != DO_NOT_ENABLE_LED_FEEDBACK) { - FeedbackLEDControl.LedFeedbackEnabled |= aEnableLEDFeedback; - if (aFeedbackLEDPin != USE_DEFAULT_FEEDBACK_LED_PIN) { - pinModeFast(aFeedbackLEDPin, OUTPUT); + // use fast macros here + if (aFeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN) { #if defined(LED_BUILTIN) - } else { - pinModeFast(LED_BUILTIN, OUTPUT); -#else - FeedbackLEDControl.LedFeedbackEnabled = LED_FEEDBACK_DISABLED_COMPLETELY; // we have no LED_BUILTIN available + pinModeFast(LED_BUILTIN, OUTPUT); #endif + } else { + if (__builtin_constant_p(aFeedbackLEDPin)) { + pinModeFast(aFeedbackLEDPin, OUTPUT); + } else { + pinMode(aFeedbackLEDPin, OUTPUT); } } } @@ -75,67 +72,78 @@ void setLEDFeedback(uint8_t aFeedbackLEDPin, uint8_t aEnableLEDFeedback) { * Direct replacement for blink13() */ void setLEDFeedback(bool aEnableLEDFeedback) { - bool tEnableLEDFeedback = LED_FEEDBACK_DISABLED_COMPLETELY; - if (aEnableLEDFeedback) { - tEnableLEDFeedback = LED_FEEDBACK_ENABLED_FOR_SEND | LED_FEEDBACK_ENABLED_FOR_RECEIVE; - } - setLEDFeedback(FeedbackLEDControl.FeedbackLEDPin, tEnableLEDFeedback); + FeedbackLEDControl.LedFeedbackEnabled = aEnableLEDFeedback; } +/* + * Historically this only affects receive LED + */ void enableLEDFeedback() { - FeedbackLEDControl.LedFeedbackEnabled |= LED_FEEDBACK_ENABLED_FOR_RECEIVE; + FeedbackLEDControl.LedFeedbackEnabled = ENABLE_LED_FEEDBACK; } - void disableLEDFeedback() { - FeedbackLEDControl.LedFeedbackEnabled &= ~(LED_FEEDBACK_ENABLED_FOR_RECEIVE); -} - -void enableLEDFeedbackForSend() { - FeedbackLEDControl.LedFeedbackEnabled |= LED_FEEDBACK_ENABLED_FOR_SEND; -} - -void disableLEDFeedbackForSend() { - FeedbackLEDControl.LedFeedbackEnabled &= ~(LED_FEEDBACK_ENABLED_FOR_SEND); + FeedbackLEDControl.LedFeedbackEnabled = DISABLE_LED_FEEDBACK; } /** * Flash LED while receiving or sending IR data. Does not check if enabled, this must be done by the caller. - * Handles the 0 value of FeedbackLEDPin and the macro FEEDBACK_LED_IS_ACTIVE_LOW. + * Handles the USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF value of FeedbackLEDPin and the macro FEEDBACK_LED_IS_ACTIVE_LOW. + * If FeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN and LED_BUILTIN is NOT defined no action is done */ #if defined(ESP32) || defined(ESP8266) IRAM_ATTR #endif void setFeedbackLED(bool aSwitchLedOn) { if (aSwitchLedOn) { - if (FeedbackLEDControl.FeedbackLEDPin != USE_DEFAULT_FEEDBACK_LED_PIN) { -#if defined(FEEDBACK_LED_IS_ACTIVE_LOW) - digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, LOW); // Turn user defined pin LED on -#else - digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, HIGH); // Turn user defined pin LED on -#endif + // Turn user defined pin LED on + if (FeedbackLEDControl.FeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN) { #if defined(LED_BUILTIN) // use fast macros here - } else { # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) - digitalWriteFast(LED_BUILTIN, LOW); // For AVR, this generates a single cbi command + digitalWriteFast(LED_BUILTIN, LOW); // For AVR, this generates a single cbi command # else - digitalWriteFast(LED_BUILTIN, HIGH); // For AVR, this generates a single sbi command + digitalWriteFast(LED_BUILTIN, HIGH); // For AVR, this generates a single sbi command # endif #endif - } - } else { - if (FeedbackLEDControl.FeedbackLEDPin != USE_DEFAULT_FEEDBACK_LED_PIN) { + + } else { #if defined(FEEDBACK_LED_IS_ACTIVE_LOW) - digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, HIGH); // Turn user defined pin LED off + if (__builtin_constant_p(FeedbackLEDControl.FeedbackLEDPin) ) { + digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, LOW); + } else { + digitalWrite(FeedbackLEDControl.FeedbackLEDPin, LOW); + } #else - digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, LOW); // Turn user defined pin LED off + if (__builtin_constant_p(FeedbackLEDControl.FeedbackLEDPin)) { + digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, HIGH); + } else { + digitalWrite(FeedbackLEDControl.FeedbackLEDPin, HIGH); + } #endif + } + + } else { + // Turn user defined pin LED off + if (FeedbackLEDControl.FeedbackLEDPin == USE_DEFAULT_FEEDBACK_LED_PIN) { #if defined(LED_BUILTIN) - } else { # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) - digitalWriteFast(LED_BUILTIN, HIGH); // For AVR, this generates a single sbi command + digitalWriteFast(LED_BUILTIN, HIGH); // For AVR, this generates a single sbi command # else - digitalWriteFast(LED_BUILTIN, LOW); // For AVR, this generates a single cbi command + digitalWriteFast(LED_BUILTIN, LOW); // For AVR, this generates a single cbi command # endif +#endif + } else { +#if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + if (__builtin_constant_p(FeedbackLEDControl.FeedbackLEDPin) ) { + digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, HIGH); + } else { + digitalWrite(FeedbackLEDControl.FeedbackLEDPin, HIGH); + } +#else + if (__builtin_constant_p(FeedbackLEDControl.FeedbackLEDPin)) { + digitalWriteFast(FeedbackLEDControl.FeedbackLEDPin, LOW); + } else { + digitalWrite(FeedbackLEDControl.FeedbackLEDPin, LOW); + } #endif } } @@ -145,13 +153,13 @@ void setFeedbackLED(bool aSwitchLedOn) { * Old deprecated function name for setLEDFeedback() or enableLEDFeedback() / disableLEDFeedback() */ void IRrecv::blink13(uint8_t aEnableLEDFeedback) { - setLEDFeedback(FeedbackLEDControl.FeedbackLEDPin, aEnableLEDFeedback); + setLEDFeedback(aEnableLEDFeedback); } /** * Old deprecated function name for setLEDFeedback() */ void setBlinkPin(uint8_t aBlinkPin) { - setLEDFeedback(aBlinkPin, FeedbackLEDControl.LedFeedbackEnabled); + setLEDFeedbackPin(aBlinkPin); } /** @}*/ diff --git a/src/IRProtocol.h b/src/IRProtocol.h index 42d3e2cb2..6b11044b6 100644 --- a/src/IRProtocol.h +++ b/src/IRProtocol.h @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -32,45 +32,83 @@ #ifndef _IR_PROTOCOL_H #define _IR_PROTOCOL_H +#include + +/* + * If activated, BANG_OLUFSEN, BOSEWAVE, MAGIQUEST, WHYNTER, FAST and LEGO_PF are excluded in decoding and in sending with IrSender.write + */ +//#define EXCLUDE_EXOTIC_PROTOCOLS +/* + * Supported IR protocols + * Each protocol you include costs memory and, during decode, costs time + * Copy the lines with the protocols you need in your program before the #include line + * See also SimpleReceiver example + */ + +// For backward compatibility +#if defined(DECODE_PANASONIC) +#define DECODE_KASEIKYO +#endif + +#if !defined(NO_DECODER) // for sending raw only +# if (!(defined(DECODE_DENON) || defined(DECODE_JVC) || defined(DECODE_KASEIKYO) \ +|| defined(DECODE_PANASONIC) || defined(DECODE_LG) || defined(DECODE_NEC) || defined(DECODE_ONKYO) || defined(DECODE_SAMSUNG) \ +|| defined(DECODE_SONY) || defined(DECODE_RC5) || defined(DECODE_RC6) \ +|| defined(DECODE_DISTANCE_WIDTH) || defined(DECODE_HASH) || defined(DECODE_BOSEWAVE) \ +|| defined(DECODE_LEGO_PF) || defined(DECODE_MAGIQUEST) || defined(DECODE_WHYNTER) || defined(DECODE_MARANTZ) || defined(DECODE_FAST) \ +|| defined(DECODE_OPENLASIR))) +/* + * If no protocol is explicitly enabled, we enable all protocols + * In alphabetic order: + */ +#define DECODE_DENON // Includes Sharp - requires around 250 bytes of program memory on ATmega328 +#define DECODE_JVC // ~ 200 bytes +#define DECODE_KASEIKYO // Includes Panasonic ~ 300 bytes +#define DECODE_LG // ~ 400 bytes +#define DECODE_NEC // Includes Apple and Onkyo ~ 250 bytes +#define DECODE_SAMSUNG // ~ 300 bytes +#define DECODE_SONY // ~ 175 bytes +#define DECODE_RC5 // RC5 + MARANTZ: ~ 425 bytes +#define DECODE_RC6 // ~ 375 bytes + +# if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program memory +#define DECODE_BOSEWAVE // ~ 140 bytes +#define DECODE_FAST // ~ 135 bytes +#define DECODE_LEGO_PF // ~ 300 bytes +#define DECODE_MAGIQUEST // ~ 270 bytes +#define DECODE_MARANTZ // RC5 + MARANTZ: ~ 425 bytes +#define DECODE_OPENLASIR // Modified NEC with 8-bit validated address + 16-bit command. ~ 175 bytes +#define DECODE_WHYNTER // ~ 90 bytes +# endif + +# if !defined(EXCLUDE_UNIVERSAL_PROTOCOLS) +#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols ~ 2275 bytes +#define DECODE_HASH // special decoder for all protocols ~ 250 bytes +# endif +# endif +#endif // !defined(NO_DECODER) + +//#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It prevents decoding of SONY! + +#if defined(DECODE_NEC) && !(~(~DECODE_NEC + 0) == 0 && ~(~DECODE_NEC + 1) == 1) +#warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro." +#endif + /** * An enum consisting of all supported formats. * You do NOT need to remove entries from this list when disabling protocols! - * !!!Must be the same order as ProtocolNames in IRReceive.hpp!!! + * !!!Must be the same order as ProtocolNames in IRProtocol.hpp!!! */ typedef enum { - UNKNOWN = 0, - PULSE_WIDTH, - PULSE_DISTANCE, - APPLE, - DENON, - JVC, - LG, - LG2, - NEC, - NEC2, /* NEC with full frame as repeat */ - ONKYO, - PANASONIC, - KASEIKYO, - KASEIKYO_DENON, - KASEIKYO_SHARP, - KASEIKYO_JVC, - KASEIKYO_MITSUBISHI, - RC5, - RC6, - SAMSUNG, - SAMSUNG48, - SAMSUNG_LG, - SHARP, - SONY, + UNKNOWN = 0, PULSE_WIDTH, PULSE_DISTANCE, APPLE, DENON, JVC, LG, NEC, NEC2, ONKYO, /* 10 entries */ + PANASONIC, KASEIKYO, KASEIKYO_DENON, KASEIKYO_SHARP, KASEIKYO_JVC, KASEIKYO_MITSUBISHI, RC5, RC6, RC6A, /*31 bit + 3 fixed 0b110 mode bits*/ + SAMSUNG, /* 10 entries */ + SAMSUNGLG, SAMSUNG48, SHARP, SONY, /* Now the exotic protocols */ - BANG_OLUFSEN, - BOSEWAVE, - LEGO_PF, - MAGIQUEST, - WHYNTER, - FAST + BANG_OLUFSEN, BOSEWAVE, LEGO_PF, MAGIQUEST, WHYNTER, MARANTZ,/* 10 entries */ + FAST, OPENLASIR, OTHER } decode_type_t; - +extern const char *const ProtocolNames[]; // The array of name strings for the decode_type_t enum #define SIRCS_12_PROTOCOL 12 #define SIRCS_15_PROTOCOL 15 @@ -95,49 +133,34 @@ struct DistanceWidthTimingInfoStruct { #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). +#define IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT 0x20 ///< Here we have a repeat of type NEC2 or SamsungLG #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. #define IRDATA_FLAGS_IS_LSB_FIRST 0x00 +#define IRDATA_FLAGS_LSB_MSB_FIRST_MASK IRDATA_FLAGS_IS_MSB_FIRST -#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. -/** - * 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. - IRRawDataType decodedRawData; ///< Up to 32/64 bit decoded raw data, to be used for send functions. -#if defined(DECODE_DISTANCE_WIDTH) - // This replaces the address, command, extra and decodedRawData in case of protocol == PULSE_DISTANCE or -rather seldom- protocol == PULSE_WIDTH. - DistanceWidthTimingInfoStruct DistanceWidthTimingInfo; // 12 bytes - IRRawDataType decodedRawDataArray[RAW_DATA_ARRAY_SIZE]; ///< 32/64 bit decoded raw data, to be used for send function. -#endif - uint16_t numberOfBits; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible. - uint8_t flags; ///< IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above - irparams_struct *rawDataPtr; ///< Pointer of the raw timing data to be decoded. Mainly the OverflowFlag and the data buffer filled by receiving ISR. -}; +extern uint8_t sLastSendToggleValue; // Currently used by RC5 + RC6 struct PulseDistanceWidthProtocolConstants { decode_type_t ProtocolIndex; uint_fast8_t FrequencyKHz; DistanceWidthTimingInfoStruct DistanceWidthTimingInfo; uint8_t Flags; - unsigned int RepeatPeriodMillis; + unsigned int RepeatPeriodMillis; // Time between start of two frames. Thus independent from frame length. void (*SpecialSendRepeatFunction)(); // using non member functions here saves up to 250 bytes for send demo // void (IRsend::*SpecialSendRepeatFunction)(); }; /* * Definitions for member PulseDistanceWidthProtocolConstants.Flags */ -#define SUPPRESS_STOP_BIT_FOR_THIS_DATA 0x20 +#define PROTOCOL_IS_PULSE_DISTANCE 0x00 +#define PROTOCOL_IS_PULSE_DISTANCE_WIDTH 0x00 // Can often be decoded successfully as pulse distance +#define PROTOCOL_IS_PULSE_WIDTH 0x10 // Currently only Sony protocol +#define PROTOCOL_IS_PULSE_WIDTH_MASK PROTOCOL_IS_PULSE_WIDTH +#define SUPPRESS_STOP_BIT 0x20 // Stop bit is otherwise sent for all pulse distance protocols, i.e. aOneSpaceMicros != aZeroSpaceMicros. #define PROTOCOL_IS_MSB_FIRST IRDATA_FLAGS_IS_MSB_FIRST #define PROTOCOL_IS_LSB_FIRST IRDATA_FLAGS_IS_LSB_FIRST -// 2 definitions for deprecated parameter bool aSendStopBit -#define SEND_STOP_BIT true -#define SEND_NO_STOP_BIT false +#define PROTOCOL_IS_MSB_MASK IRDATA_FLAGS_IS_MSB_FIRST /* * Carrier frequencies for various protocols @@ -151,6 +174,7 @@ struct PulseDistanceWidthProtocolConstants { #define JVC_KHZ 38 #define LG_KHZ 38 #define NEC_KHZ 38 +#define OPENLASIR_KHZ 38 #define SAMSUNG_KHZ 38 #define KASEIKYO_KHZ 37 #define RC5_RC6_KHZ 36 @@ -160,7 +184,6 @@ 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 diff --git a/src/IRProtocol.hpp b/src/IRProtocol.hpp index 093d2a8f4..18f145666 100644 --- a/src/IRProtocol.hpp +++ b/src/IRProtocol.hpp @@ -9,7 +9,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2009-2023 Ken Shirriff, Rafi Khan, Armin Joachimsmeyer + * Copyright (c) 2009-2026 Ken Shirriff, 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 @@ -33,17 +33,6 @@ #ifndef _IR_PROTOCOL_HPP #define _IR_PROTOCOL_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif - -/* - * Check for additional characteristics of timing like length of mark for a constant mark protocol, - * where space length determines the bit value. Requires up to 194 additional bytes of program memory. - */ -//#define DECODE_STRICT_CHECKS /** \addtogroup Receiving Receiving IR data for multiple protocols * @{ */ @@ -55,7 +44,6 @@ const char string_Apple[] PROGMEM = "Apple"; const char string_Denon[] PROGMEM = "Denon"; const char string_JVC[] PROGMEM = "JVC"; const char string_LG[] PROGMEM = "LG"; -const char string_LG2[] PROGMEM = "LG2"; const char string_NEC[] PROGMEM = "NEC"; const char string_NEC2[] PROGMEM = "NEC2"; const char string_Onkyo[] PROGMEM = "Onkyo"; @@ -67,9 +55,10 @@ const char string_Kaseikyo_JVC[] PROGMEM = "Kaseikyo_JVC"; const char string_Kaseikyo_Mitsubishi[] PROGMEM = "Kaseikyo_Mitsubishi"; const char string_RC5[] PROGMEM = "RC5"; const char string_RC6[] PROGMEM = "RC6"; +const char string_RC6A[] PROGMEM = "RC6A"; const char string_Samsung[] PROGMEM = "Samsung"; -const char string_Samsung48[] PROGMEM = "Samsung48"; const char string_SamsungLG[] PROGMEM = "SamsungLG"; +const char string_Samsung48[] PROGMEM = "Samsung48"; const char string_Sharp[] PROGMEM = "Sharp"; const char string_Sony[] PROGMEM = "Sony"; const char string_BangOlufsen[] PROGMEM = "Bang&Olufsen"; @@ -77,18 +66,22 @@ const char string_BoseWave[] PROGMEM = "BoseWave"; const char string_Lego[] PROGMEM = "Lego"; const char string_MagiQuest[] PROGMEM = "MagiQuest"; const char string_Whynter[] PROGMEM = "Whynter"; +const char string_Marantz[] PROGMEM = "Marantz"; const char string_FAST[] PROGMEM = "FAST"; +const char string_OpenLASIR[] PROGMEM = "OpenLASIR"; +const char string_Other[] PROGMEM = "OTHER"; /* * !!Must be the same order as in decode_type_t in IRProtocol.h!!! */ const char *const ProtocolNames[] -PROGMEM = { string_Unknown, string_PulseWidth, string_PulseDistance, string_Apple, string_Denon, string_JVC, string_LG, string_LG2, +PROGMEM = { string_Unknown, string_PulseWidth, string_PulseDistance, string_Apple, string_Denon, string_JVC, string_LG, string_NEC, string_NEC2, string_Onkyo, string_Panasonic, string_Kaseikyo, string_Kaseikyo_Denon, string_Kaseikyo_Sharp, - string_Kaseikyo_JVC, string_Kaseikyo_Mitsubishi, string_RC5, string_RC6, string_Samsung, string_Samsung48, string_SamsungLG, - string_Sharp, string_Sony + string_Kaseikyo_JVC, string_Kaseikyo_Mitsubishi, string_RC5, string_RC6, string_RC6A, string_Samsung, string_SamsungLG, + string_Samsung48, string_Sharp, string_Sony #if !defined(EXCLUDE_EXOTIC_PROTOCOLS) - , string_BangOlufsen, string_BoseWave, string_Lego, string_MagiQuest, string_Whynter, string_FAST + , string_BangOlufsen, string_BoseWave, string_Lego, string_MagiQuest, string_Whynter, string_Marantz, string_FAST, + string_OpenLASIR, string_Other #endif }; @@ -138,11 +131,21 @@ size_t print(PrintImplType *p, unsigned long long value, int base) { tLength += p->print(static_cast(value), base); return tLength; } +template::value, bool>::type = true> +size_t println(PrintImplType *p, unsigned long long value, int base) { + size_t tLength = p->print(static_cast(value >> 32), base); + tLength += p->println(static_cast(value), base); + return tLength; +} template::value, bool>::type = true> size_t print(PrintImplType *p, unsigned long long value, int base) { return p->print(value, base); } +template::value, bool>::type = true> +size_t println(PrintImplType *p, unsigned long long value, int base) { + return p->println(value, base); +} } ; # else @@ -150,116 +153,17 @@ namespace PrintULL { size_t print(Print *aSerial, unsigned long long n, int base) { return aSerial->print(n, base); } + size_t println(Print *aSerial, unsigned long long n, int base) { + return aSerial->println(n, base); + } }; # endif #endif -/** - * Function to print decoded result and flags in one line. - * A static function to be able to print data to send or copied received data. - * Ends with println(). - * - * @param aSerial The Print object on which to write, for Arduino you can use &Serial. - * @param aIRDataPtr Pointer to the data to be printed. - * @param aPrintRepeatGap If true also print the gap before repeats. - * +/** @} + * \addtogroup Utils Utility functions + * @{ */ -void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintRepeatGap) { - if (aIRDataPtr->flags & IRDATA_FLAGS_WAS_OVERFLOW) { - aSerial->println(F("Overflow")); - return; - } - aSerial->print(F("Protocol=")); - aSerial->print(getProtocolString(aIRDataPtr->protocol)); - if (aIRDataPtr->protocol == UNKNOWN) { -#if defined(DECODE_HASH) - aSerial->print(F(" Hash=0x")); -#if (__INT_WIDTH__ < 32) - aSerial->print(aIRDataPtr->decodedRawData, HEX); -#else - PrintULL::print(aSerial,aIRDataPtr->decodedRawData, HEX); -#endif - -#endif -#if !defined(DISABLE_CODE_FOR_RECEIVER) - aSerial->print(' '); - aSerial->print((aIRDataPtr->rawDataPtr->rawlen + 1) / 2, DEC); - aSerial->println(F(" bits (incl. gap and start) received")); -#endif - } else { -#if defined(DECODE_DISTANCE_WIDTH) - if (aIRDataPtr->protocol != PULSE_DISTANCE && aIRDataPtr->protocol != PULSE_WIDTH) { -#endif - /* - * New decoders have address and command - */ - aSerial->print(F(" Address=0x")); - aSerial->print(aIRDataPtr->address, HEX); - - aSerial->print(F(" Command=0x")); - aSerial->print(aIRDataPtr->command, HEX); - - if (aIRDataPtr->flags & IRDATA_FLAGS_EXTRA_INFO) { - aSerial->print(F(" Extra=0x")); - aSerial->print(aIRDataPtr->extra, HEX); - } - - if (aIRDataPtr->flags & IRDATA_FLAGS_PARITY_FAILED) { - aSerial->print(F(" Parity fail")); - } - - if (aIRDataPtr->flags & IRDATA_FLAGS_TOGGLE_BIT) { - aSerial->print(F(" Toggle=1")); - } -#if defined(DECODE_DISTANCE_WIDTH) - } -#endif - if (aIRDataPtr->flags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) { - aSerial->print(' '); - if (aIRDataPtr->flags & IRDATA_FLAGS_IS_AUTO_REPEAT) { - aSerial->print(F("Auto-")); - } - aSerial->print(F("Repeat")); -#if !defined(DISABLE_CODE_FOR_RECEIVER) - if (aPrintRepeatGap) { - aSerial->print(F(" gap=")); - aSerial->print((uint32_t) aIRDataPtr->rawDataPtr->rawbuf[0] * MICROS_PER_TICK); - aSerial->print(F("us")); - } -#else - (void)aPrintRepeatGap; -#endif - } - - /* - * Print raw data - */ - if (!(aIRDataPtr->flags & IRDATA_FLAGS_IS_REPEAT) || aIRDataPtr->decodedRawData != 0) { - aSerial->print(F(" Raw-Data=0x")); -#if (__INT_WIDTH__ < 32) - aSerial->print(aIRDataPtr->decodedRawData, HEX); -#else - PrintULL::print(aSerial, aIRDataPtr->decodedRawData, HEX); -#endif - /* - * Print number of bits processed - */ - aSerial->print(' '); - aSerial->print(aIRDataPtr->numberOfBits, DEC); - aSerial->print(F(" bits")); - - if (aIRDataPtr->flags & IRDATA_FLAGS_IS_MSB_FIRST) { - aSerial->println(F(" MSB first")); - } else { - aSerial->println(F(" LSB first")); - } - - } else { - aSerial->println(); - } - } -} - /********************************************************************************************************************** * Function to bit reverse OLD MSB values of e.g. NEC. **********************************************************************************************************************/ @@ -288,7 +192,4 @@ uint32_t bitreverse32Bit(uint32_t aInput) { /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif #endif // _IR_PROTOCOL_HPP diff --git a/src/IRReceive.hpp b/src/IRReceive.hpp index a1bf0b488..f2b2bf4a6 100644 --- a/src/IRReceive.hpp +++ b/src/IRReceive.hpp @@ -9,7 +9,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2009-2023 Ken Shirriff, Rafi Khan, Armin Joachimsmeyer + * Copyright (c) 2009-2026 Ken Shirriff, 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 @@ -33,28 +33,22 @@ #ifndef _IR_RECEIVE_HPP #define _IR_RECEIVE_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -//#define LOCAL_DEBUG // -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif - -#if defined(TRACE) && !defined(LOCAL_TRACE) -#define LOCAL_TRACE -#else -//#define LOCAL_TRACE // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" /* * Low level hardware timing measurement */ //#define _IR_MEASURE_TIMING // for ISR //#define _IR_TIMING_TEST_PIN 7 // "pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT);" is executed at start() // -/* - * Check for additional characteristics of timing like length of mark for a constant mark protocol, - * where space length determines the bit value. Requires up to 194 additional bytes of program memory. - */ -//#define DECODE_STRICT_CHECKS +#if !defined(NO_LED_RECEIVE_FEEDBACK_CODE) +#define LED_RECEIVE_FEEDBACK_CODE // Resolve the double negative +#endif + +unsigned long sMicrosAtLastStopTimer = 0; // Used to adjust TickCounterForISR with uncounted ticks between stopTimer() and restartTimer() + /** \addtogroup Receiving Receiving IR data for multiple protocols * @{ */ @@ -63,41 +57,29 @@ */ IRrecv IrReceiver; -/* - * The control structure instance - */ -struct irparams_struct irparams; // the irparams instance - /** - * Instantiate the IRrecv class. Multiple instantiation is not supported. + * Instantiate the IRrecv class. Multiple instantiation is supported by activating SUPPORT_MULTIPLE_RECEIVER_INSTANCES and providing + * the simple function UserIRReceiveTimerInterruptHandler(). This function is required, because we have only one timer resource. + * See the MultipleReceivers example. * @param IRReceivePin Arduino pin to use. No sanity check is made. */ IRrecv::IRrecv() { - decodedIRData.rawDataPtr = &irparams; // for decodePulseDistanceData() etc. setReceivePin(0); -#if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(0, DO_NOT_ENABLE_LED_FEEDBACK); -#endif } IRrecv::IRrecv(uint_fast8_t aReceivePin) { - decodedIRData.rawDataPtr = &irparams; // for decodePulseDistanceData() etc. setReceivePin(aReceivePin); -#if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(0, DO_NOT_ENABLE_LED_FEEDBACK); -#endif } /** - * Instantiate the IRrecv class. Multiple instantiation is not supported. + * Instantiate the IRrecv class. * @param aReceivePin Arduino pin to use, where a demodulating IR receiver is connected. - * @param aFeedbackLEDPin if 0, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions + * @param aFeedbackLEDPin if 0xFF, then take board specific LED_BUILTIN pin if it is defined as macro */ IRrecv::IRrecv(uint_fast8_t aReceivePin, uint_fast8_t aFeedbackLEDPin) { - decodedIRData.rawDataPtr = &irparams; // for decodePulseDistanceData() etc. setReceivePin(aReceivePin); -#if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(aFeedbackLEDPin, DO_NOT_ENABLE_LED_FEEDBACK); +#if defined(LED_RECEIVE_FEEDBACK_CODE) + setLEDFeedbackPin(aFeedbackLEDPin); #else (void) aFeedbackLEDPin; #endif @@ -122,9 +104,12 @@ IRrecv::IRrecv(uint_fast8_t aReceivePin, uint_fast8_t aFeedbackLEDPin) { * **********************************************************************************************************************/ #if defined(ESP8266) || defined(ESP32) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvolatile" IRAM_ATTR #endif -void IRReceiveTimerInterruptHandler(){ + +void IRrecv::ReceiveInterruptHandler() { #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles #endif @@ -141,11 +126,13 @@ void IRReceiveTimerInterruptHandler(){ uint_fast8_t tIRInputLevel = (uint_fast8_t) digitalReadFast(irparams.IRReceivePin); #endif + uint_fast16_t tTickCounterForISR = irparams.TickCounterForISR; /* * Increase TickCounter and clip it at maximum 0xFFFF / 3.2 seconds at 50 us ticks */ if (irparams.TickCounterForISR < UINT16_MAX) { - irparams.TickCounterForISR++; // One more 50uS tick + tTickCounterForISR++; // One more 50uS tick + irparams.TickCounterForISR = tTickCounterForISR; } /* @@ -154,29 +141,34 @@ void IRReceiveTimerInterruptHandler(){ */ // switch (irparams.StateForISR) { // - if (irparams.StateForISR == IR_REC_STATE_IDLE) { + uint_fast8_t tStateForISR = irparams.StateForISR; + if (tStateForISR == IR_REC_STATE_IDLE) { /* - * Here we are just resumed and maybe in the middle of a transmission + * Here we are just resumed and wait for start bit. But in real time we may be in the middle of an ongoing transmission! */ if (tIRInputLevel == INPUT_MARK) { - // check if we did not start in the middle of a transmission by checking the minimum length of leading space - if (irparams.TickCounterForISR > RECORD_GAP_TICKS) { + // Check if we are not in the middle of an ongoing transmission by checking the minimum length of leading space + if (tTickCounterForISR > RECORD_GAP_TICKS) { #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) // digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles #endif /* - * Gap between two transmissions just ended; Record gap duration + start recording transmission + * Big gap between two transmissions just ended; Record gap duration + start recording transmission * Initialize all state machine variables */ irparams.OverflowFlag = false; - irparams.rawbuf[0] = irparams.TickCounterForISR; + // irparams.rawbuf[0] = irparams.TickCounterForISR; + // Usage of initialGapTicks enables usage of 8 bit buffer instead of 16 bit since 4.4, + // because the big gap value is not stored in this buffer any more + irparams.initialGapTicks = tTickCounterForISR; irparams.rawlen = 1; irparams.StateForISR = IR_REC_STATE_MARK; } // otherwise stay in idle state - irparams.TickCounterForISR = 0;// reset counter in both cases + irparams.TickCounterForISR = 0; // reset counter in both cases } - } else if (irparams.StateForISR == IR_REC_STATE_MARK) { // Timing mark + } else if (tStateForISR == IR_REC_STATE_MARK) { + // Timing mark here, rawlen is even if (tIRInputLevel != INPUT_MARK) { /* * Mark ended here. Record mark time in rawbuf array @@ -184,56 +176,75 @@ void IRReceiveTimerInterruptHandler(){ #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) // digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles #endif - irparams.rawbuf[irparams.rawlen++] = irparams.TickCounterForISR; // record mark +#if !defined(USE_16_BIT_TIMING_BUFFER) + // Clip timings > 12750 us (255 * 50) to 12750 + if (tTickCounterForISR > UINT8_MAX) { + tTickCounterForISR = UINT8_MAX; + } +#endif + irparams.rawbuf[irparams.rawlen++] = tTickCounterForISR; // record mark irparams.StateForISR = IR_REC_STATE_SPACE; - irparams.TickCounterForISR = 0;// This resets the tick counter also at end of frame :-) + irparams.TickCounterForISR = 0; // This resets the tick counter also at end of frame :-) } - } else if (irparams.StateForISR == IR_REC_STATE_SPACE) { // Timing space - if (tIRInputLevel == INPUT_MARK) { - /* - * Space ended here. Check for overflow and record space time in rawbuf array - */ + } else if (tStateForISR == IR_REC_STATE_SPACE) { + /* + * Timing space here, rawlen is odd + * Check for timeout or overflow + */ + if (tTickCounterForISR > RECORD_GAP_TICKS || irparams.rawlen >= RAW_BUFFER_LENGTH - 1) { if (irparams.rawlen >= RAW_BUFFER_LENGTH) { // Flag up a read OverflowFlag; Stop the state machine irparams.OverflowFlag = true; - irparams.StateForISR = IR_REC_STATE_STOP; -#if !IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK - /* - * Call callback if registered (not NULL) - */ - if (irparams.ReceiveCompleteCallbackFunction != NULL) { - irparams.ReceiveCompleteCallbackFunction(); - } -#endif - } else { -#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) -// digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles -#endif - irparams.rawbuf[irparams.rawlen++] = irparams.TickCounterForISR; // record space - irparams.StateForISR = IR_REC_STATE_MARK; } - irparams.TickCounterForISR = 0; - - } else if (irparams.TickCounterForISR > RECORD_GAP_TICKS) { /* - * Maximum space duration reached here. + * Overflow or maximum space duration reached here. * Current code is ready for processing! * We received a long space, which indicates gap between codes. * Switch to IR_REC_STATE_STOP * Don't reset TickCounterForISR; keep counting width of next leading space */ - irparams.StateForISR = IR_REC_STATE_STOP; -#if !IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK /* - * Call callback if registered (not NULL) + * These 2 variables allow to call resume() directly after decode. + * After resume(), irparams.initialGapTicks and irparams.rawlen are + * the first variables, which are overwritten by the next received frame. + * since 4.3.0. + * For backward compatibility, there are the same 2 statements in decode() if IrReceiver is not used. */ - if (irparams.ReceiveCompleteCallbackFunction != NULL) { + IrReceiver.decodedIRData.initialGapTicks = irparams.initialGapTicks; + IrReceiver.decodedIRData.rawlen = irparams.rawlen; + + irparams.StateForISR = IR_REC_STATE_STOP; // This signals the decode(), that a complete frame was received +#if !defined(IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK) + /* + * Call callback if registered (not nullptr) + */ + if (irparams.ReceiveCompleteCallbackFunction != nullptr) { +#if defined(SUPPORT_MULTIPLE_RECEIVER_INSTANCES) && !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled + interrupts(); // To enable the receiving for the other instances while in callback +#endif irparams.ReceiveCompleteCallbackFunction(); } #endif + } else if (tIRInputLevel == INPUT_MARK) { + /* + * Space ended here. + */ + +#if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) +// digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles +#endif +#if !defined(USE_16_BIT_TIMING_BUFFER) + // Clip timings > 12750 us (255 * 50) to 12750 + if (tTickCounterForISR > UINT8_MAX) { + tTickCounterForISR = UINT8_MAX; + } +#endif + irparams.rawbuf[irparams.rawlen++] = tTickCounterForISR; // record space + irparams.StateForISR = IR_REC_STATE_MARK; + irparams.TickCounterForISR = 0; } - } else if (irparams.StateForISR == IR_REC_STATE_STOP) { + } else if (tStateForISR == IR_REC_STATE_STOP) { /* * Complete command received * stay here until resume() is called, which switches state to IR_REC_STATE_IDLE @@ -247,8 +258,8 @@ void IRReceiveTimerInterruptHandler(){ } } -#if !defined(NO_LED_FEEDBACK_CODE) - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_RECEIVE) { +#if defined(LED_RECEIVE_FEEDBACK_CODE) + if (FeedbackLEDControl.LedFeedbackEnabled) { setFeedbackLED(tIRInputLevel == INPUT_MARK); } #endif @@ -258,9 +269,25 @@ void IRReceiveTimerInterruptHandler(){ #endif } - /* - * The ISR, which calls the interrupt handler + * The handler which directly calls the interrupt handler function of the IRrecv object. + * This must be a separate function, because we need this static function in IRTimer.hpp. + * Doing it this way, we are able to modify the body of this function to support more than 2 IRrecv instances for receiving + */ +#if defined(ESP8266) || defined(ESP32) +IRAM_ATTR +#endif +void IRReceiveTimerInterruptHandler() { + IrReceiver.ReceiveInterruptHandler(); +#if defined(SUPPORT_MULTIPLE_RECEIVER_INSTANCES) + // Quick and dirty solution by used defined extension + UserIRReceiveTimerInterruptHandler(); +#endif +} + +/********************************************************************************************************************** + * Interrupt Service Routine - Called every 50 us + * This in turn calls calls the static interrupt handler function, which in turn calls the interrupt handler function of the IRrecv object */ #if defined(TIMER_INTR_NAME) || defined(ISR) # if defined(TIMER_INTR_NAME) @@ -277,21 +304,19 @@ ISR() /********************************************************************************************************************** * Stream like API **********************************************************************************************************************/ + /** * Initializes the receive and feedback pin * @param aReceivePin The Arduino pin number, where a demodulating IR receiver is connected. * @param aEnableLEDFeedback if true / ENABLE_LED_FEEDBACK, then let the feedback led blink on receiving IR signal - * @param aFeedbackLEDPin if 0 / USE_DEFAULT_FEEDBACK_LED_PIN, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions + * @param aFeedbackLEDPin if 0xFF, then take board specific LED_BUILTIN pin if it is defined as macro */ void IRrecv::begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) { setReceivePin(aReceivePin); -#if !defined(NO_LED_FEEDBACK_CODE) - bool tEnableLEDFeedback = DO_NOT_ENABLE_LED_FEEDBACK; - if (aEnableLEDFeedback) { - tEnableLEDFeedback = LED_FEEDBACK_ENABLED_FOR_RECEIVE; - } - setLEDFeedback(aFeedbackLEDPin, tEnableLEDFeedback); +#if defined(LED_RECEIVE_FEEDBACK_CODE) + setLEDFeedback(aEnableLEDFeedback); + setLEDFeedbackPin(aFeedbackLEDPin); #else (void) aEnableLEDFeedback; (void) aFeedbackLEDPin; @@ -309,19 +334,45 @@ void IRrecv::begin(uint_fast8_t aReceivePin, bool aEnableLEDFeedback, uint_fast8 void IRrecv::setReceivePin(uint_fast8_t aReceivePinNumber) { irparams.IRReceivePin = aReceivePinNumber; #if defined(__AVR__) - irparams.IRReceivePinMask = digitalPinToBitMask(aReceivePinNumber); - irparams.IRReceivePinPortInputRegister = portInputRegister(digitalPinToPort(aReceivePinNumber)); +# if defined(__digitalPinToBit) + if (__builtin_constant_p(aReceivePinNumber)) { + irparams.IRReceivePinMask = 1UL << (__digitalPinToBit(aReceivePinNumber)); + } else { + irparams.IRReceivePinMask = digitalPinToBitMask(aReceivePinNumber); // requires 10 bytes PGM, even if not referenced (?because it is assembler code?) + } +# else + irparams.IRReceivePinMask = digitalPinToBitMask(aReceivePinNumber); // requires 10 bytes PGM, even if not referenced (?because it is assembler code?) +# endif +# if defined(__digitalPinToPINReg) + /* + * This code is 54 bytes smaller, if aReceivePinNumber is a constant :-), but 38 byte longer if it is not constant (,which is not likely). + */ + if (__builtin_constant_p(aReceivePinNumber)) { + irparams.IRReceivePinPortInputRegister = __digitalPinToPINReg(aReceivePinNumber); + } else { + irparams.IRReceivePinPortInputRegister = portInputRegister(digitalPinToPort(aReceivePinNumber)); // requires 44 bytes PGM, even if not referenced + } +# else + irparams.IRReceivePinPortInputRegister = portInputRegister(digitalPinToPort(aReceivePinNumber)); // requires 44 bytes PGM, even if not referenced +# endif #endif - // Set pin mode once. pinModeFast makes no difference here :-( - pinMode(aReceivePinNumber, INPUT); // Seems to be at least required by ESP32 + // Seems to be at least required by ESP32 + // Set pin mode once. pinModeFast makes no difference if used, but saves 224 if not referenced :-( + if (__builtin_constant_p(aReceivePinNumber)) { + pinModeFast(aReceivePinNumber, INPUT); + } else { + pinModeFast(aReceivePinNumber, INPUT); + } } +#if !defined(IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK) /** - * Sets the function to call if a protocol message has arrived + * Sets the function to call if a complete protocol frame has arrived */ void IRrecv::registerReceiveCompleteCallback(void (*aReceiveCompleteCallbackFunction)(void)) { irparams.ReceiveCompleteCallbackFunction = aReceiveCompleteCallbackFunction; } +#endif /** * Start the receiving process. @@ -342,6 +393,23 @@ void IRrecv::start() { pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); #endif } + +/* + * Restarts timer interrupts, adjusts TickCounterForISR for correct gap value after stopTimer(). Does not call resume()! + */ +void IRrecv::restartTimer() { + // Setup for cyclic 50 us interrupt + timerConfigForReceive(); // no interrupts enabled here! + // Timer interrupt is enabled after state machine reset + if (sMicrosAtLastStopTimer != 0) { + irparams.TickCounterForISR += (micros() - sMicrosAtLastStopTimer) / MICROS_PER_TICK; // adjust TickCounterForISR for correct gap value, which is used for repeat detection + sMicrosAtLastStopTimer = 0; + } + timerEnableReceiveInterrupt(); // Enables the receive sample timer interrupt which consumes a small amount of CPU every 50 us. +#ifdef _IR_MEASURE_TIMING + pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); +#endif +} /** * Alias for start(). */ @@ -350,26 +418,39 @@ void IRrecv::enableIRIn() { } /** - * Configures the timer and the state machine for IR reception. + * Configures the timer and the state machine for IR reception. Does not call resume()! + * We assume, that timer interrupts are disabled here, otherwise it makes no sense to use this functions. + * Therefore we do not need to guard the change of the volatile TickCounterForISR here :-). * The tick counter value is already at 100 when decode() gets true, because of the 5000 us minimal gap defined in RECORD_GAP_MICROS. + * If TickCounterForISR is not adjusted with the value of the microseconds, the timer was stopped, + * it can happen, that a new IR frame is recognized as a repeat, because the value of RECORD_GAP_MICROS + * was not reached by TickCounterForISR counter before receiving the new IR frame. * @param aMicrosecondsToAddToGapCounter To compensate for the amount of microseconds the timer was stopped / disabled. */ -void IRrecv::start(uint32_t aMicrosecondsToAddToGapCounter) { +void IRrecv::restartTimer(uint32_t aMicrosecondsToAddToGapCounter) { irparams.TickCounterForISR += aMicrosecondsToAddToGapCounter / MICROS_PER_TICK; - start(); + timerConfigForReceive(); // no interrupts enabled here! + timerEnableReceiveInterrupt(); // Enables the receive sample timer interrupt which consumes a small amount of CPU every 50 us. +#ifdef _IR_MEASURE_TIMING + pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); +#endif } -void IRrecv::startWithTicksToAdd(uint16_t aTicksToAddToGapCounter) { +/** + * Configures the timer and the state machine for IR reception. Does not call resume()! + * @param aTicksToAddToGapCounter To compensate for the amount of ticks the timer was stopped / disabled. + */ +void IRrecv::restartTimerWithTicksToAdd(uint16_t aTicksToAddToGapCounter) { irparams.TickCounterForISR += aTicksToAddToGapCounter; - start(); -} - -void IRrecv::addTicksToInternalTickCounter(uint16_t aTicksToAddToInternalTickCounter) { - irparams.TickCounterForISR += aTicksToAddToInternalTickCounter; + timerConfigForReceive(); // no interrupts enabled here! + timerEnableReceiveInterrupt(); // Enables the receive sample timer interrupt which consumes a small amount of CPU every 50 us. +#ifdef _IR_MEASURE_TIMING + pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); +#endif } +#if defined(ESP8266) || defined(ESP32) +#pragma GCC diagnostic push +#endif -void IRrecv::addMicrosToInternalTickCounter(uint16_t aMicrosecondsToAddToInternalTickCounter) { - irparams.TickCounterForISR += aMicrosecondsToAddToInternalTickCounter / MICROS_PER_TICK; -} /** * Restarts receiver after send. Is a NOP if sending does not require a timer. */ @@ -385,6 +466,14 @@ void IRrecv::restartAfterSend() { void IRrecv::stop() { timerDisableReceiveInterrupt(); } + +/* + * Stores microseconds of stop, to adjust TickCounterForISR in restartTimer() + */ +void IRrecv::stopTimer() { + timerDisableReceiveInterrupt(); + sMicrosAtLastStopTimer = micros(); +} /** * Alias for stop(). */ @@ -399,18 +488,11 @@ void IRrecv::end() { } /** - * Returns status of reception - * @return true if no reception is on-going. - */ -bool IRrecv::isIdle() { - return (irparams.StateForISR == IR_REC_STATE_IDLE || irparams.StateForISR == IR_REC_STATE_STOP) ? true : false; -} - -/** - * Restart the ISR (Interrupt Service Routine) state machine, to enable receiving of the next IR frame + * Restart the ISR (Interrupt Service Routine) state machine, to enable receiving of the next IR frame. + * Internal counting of gap timing is independent of StateForISR and therefore independent of call time of resume(). */ void IRrecv::resume() { - // check allows to call resume at arbitrary places or more than once + // This check allows to call resume at arbitrary places or more than once if (irparams.StateForISR == IR_REC_STATE_STOP) { irparams.StateForISR = IR_REC_STATE_IDLE; } @@ -424,16 +506,15 @@ void IRrecv::initDecodedIRData() { if (irparams.OverflowFlag) { decodedIRData.flags = IRDATA_FLAGS_WAS_OVERFLOW; -#if defined(LOCAL_DEBUG) - Serial.print(F("Overflow happened, try to increase the \"RAW_BUFFER_LENGTH\" value of ")); - Serial.print(RAW_BUFFER_LENGTH); - Serial.println(F(" with #define RAW_BUFFER_LENGTH=")); -#endif + + DEBUG_PRINT(F("Overflow happened, try to increase the \"RAW_BUFFER_LENGTH\" value of ")); + DEBUG_PRINT(RAW_BUFFER_LENGTH); + DEBUG_PRINTLN(F(" with #define RAW_BUFFER_LENGTH=")); } else { decodedIRData.flags = IRDATA_FLAGS_EMPTY; // save last protocol, command and address for repeat handling (where they are compared or copied back :-)) - lastDecodedProtocol = decodedIRData.protocol; // repeat patterns can be equal between protocols (e.g. NEC and LG), so we must keep the original one + lastDecodedProtocol = decodedIRData.protocol; // repeat patterns can be equal between protocols (e.g. NEC, Samsung and LG), so we must keep the original one lastDecodedCommand = decodedIRData.command; lastDecodedAddress = decodedIRData.address; @@ -446,23 +527,30 @@ void IRrecv::initDecodedIRData() { } /** - * Returns true if IR receiver data is available. + * @return true if available() is true or IR receiver has not received a mark/signal since last resume(). + */ +bool IRrecv::isIdle() { + return (irparams.StateForISR == IR_REC_STATE_IDLE || available()); +} + +/** + * Returns true if IR receiver has received a complete IR frame (detected by timeout after last mark). */ bool IRrecv::available() { return (irparams.StateForISR == IR_REC_STATE_STOP); } /** - * If IR receiver data is available, returns pointer to IrReceiver.decodedIRData, else NULL. + * Returns pointer to IrReceiver.decodedIRData if IR receiver data is available, else nullptr. */ IRData* IRrecv::read() { if (irparams.StateForISR != IR_REC_STATE_STOP) { - return NULL; + return nullptr; } if (decode()) { return &decodedIRData; } else { - return NULL; + return nullptr; } } @@ -477,6 +565,14 @@ bool IRrecv::decode() { return false; } + /* + * Support for old examples, which do not use the default IrReceiver instance + */ + if (this != &IrReceiver) { + decodedIRData.initialGapTicks = irparams.initialGapTicks; + decodedIRData.rawlen = irparams.rawlen; + } + initDecodedIRData(); // sets IRDATA_FLAGS_WAS_OVERFLOW if (decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) { @@ -488,63 +584,69 @@ bool IRrecv::decode() { } #if defined(DECODE_NEC) || defined(DECODE_ONKYO) - IR_TRACE_PRINTLN(F("Attempting NEC/Onkyo decode")); + TRACE_PRINTLN(F("Attempting NEC/Onkyo decode")); if (decodeNEC()) { return true; } #endif -#if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) - IR_TRACE_PRINTLN(F("Attempting Panasonic/Kaseikyo decode")); +#if defined(DECODE_KASEIKYO) + TRACE_PRINTLN(F("Attempting Panasonic/Kaseikyo decode")); if (decodeKaseikyo()) { return true; } #endif #if defined(DECODE_DENON) - IR_TRACE_PRINTLN(F("Attempting Denon/Sharp decode")); + TRACE_PRINTLN(F("Attempting Denon/Sharp decode")); if (decodeDenon()) { return true; } #endif #if defined(DECODE_SONY) - IR_TRACE_PRINTLN(F("Attempting Sony decode")); + TRACE_PRINTLN(F("Attempting Sony decode")); if (decodeSony()) { return true; } #endif -#if defined(DECODE_RC5) - IR_TRACE_PRINTLN(F("Attempting RC5 decode")); +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) +# if defined(DECODE_RC5) && !defined(DECODE_MARANTZ) + TRACE_PRINTLN(F("Attempting RC5 decode")); +# elif !defined(DECODE_RC5) && defined(DECODE_MARANTZ) + TRACE_PRINTLN(F("Attempting Marantz decode")); +# else + TRACE_PRINTLN(F("Attempting RC5 and Marantz decode")); +# endif if (decodeRC5()) { return true; } #endif #if defined(DECODE_RC6) - IR_TRACE_PRINTLN(F("Attempting RC6 decode")); + TRACE_PRINTLN(F("Attempting RC6 decode")); if (decodeRC6()) { return true; } #endif #if defined(DECODE_LG) - IR_TRACE_PRINTLN(F("Attempting LG decode")); + TRACE_PRINTLN(F("Attempting LG decode")); if (decodeLG()) { return true; } #endif #if defined(DECODE_JVC) - IR_TRACE_PRINTLN(F("Attempting JVC decode")); + TRACE_PRINTLN(F("Attempting JVC decode")); if (decodeJVC()) { return true; } #endif #if defined(DECODE_SAMSUNG) - IR_TRACE_PRINTLN(F("Attempting Samsung decode")); + TRACE_PRINTLN(F("Attempting Samsung decode")); if (decodeSamsung()) { return true; } @@ -554,52 +656,59 @@ bool IRrecv::decode() { */ #if defined(DECODE_BEO) - IR_TRACE_PRINTLN(F("Attempting Bang & Olufsen decode")); + TRACE_PRINTLN(F("Attempting Bang & Olufsen decode")); if (decodeBangOlufsen()) { return true; } #endif #if defined(DECODE_FAST) - IR_TRACE_PRINTLN(F("Attempting FAST decode")); + TRACE_PRINTLN(F("Attempting FAST decode")); if (decodeFAST()) { return true; } #endif #if defined(DECODE_WHYNTER) - IR_TRACE_PRINTLN(F("Attempting Whynter decode")); + TRACE_PRINTLN(F("Attempting Whynter decode")); if (decodeWhynter()) { return true; } #endif #if defined(DECODE_LEGO_PF) - IR_TRACE_PRINTLN(F("Attempting Lego Power Functions")); + TRACE_PRINTLN(F("Attempting Lego Power Functions")); if (decodeLegoPowerFunctions()) { return true; } #endif #if defined(DECODE_BOSEWAVE) - IR_TRACE_PRINTLN(F("Attempting Bosewave decode")); + TRACE_PRINTLN(F("Attempting Bosewave decode")); if (decodeBoseWave()) { return true; } #endif #if defined(DECODE_MAGIQUEST) - IR_TRACE_PRINTLN(F("Attempting MagiQuest decode")); + TRACE_PRINTLN(F("Attempting MagiQuest decode")); if (decodeMagiQuest()) { return true; } #endif +#if defined(DECODE_OPENLASIR) + TRACE_PRINTLN(F("Attempting OpenLASIR decode")); + if (decodeOpenLASIR()) { + return true; + } +#endif + /* * Try the universal decoder for pulse distance protocols */ #if defined(DECODE_DISTANCE_WIDTH) - IR_TRACE_PRINTLN(F("Attempting universal Distance Width decode")); + TRACE_PRINTLN(F("Attempting universal Distance Width decode")); if (decodeDistanceWidth()) { return true; } @@ -609,7 +718,7 @@ bool IRrecv::decode() { * Last resort is the universal hash decode which always return true */ #if defined(DECODE_HASH) - IR_TRACE_PRINTLN(F("Hash decode")); + TRACE_PRINTLN(F("Hash decode")); // decodeHash returns a hash on any input. // Thus, it needs to be last in the list. // If you add any decodes, add them before this. @@ -628,99 +737,65 @@ bool IRrecv::decode() { * Common decode functions **********************************************************************************************************************/ /** - * Decode pulse distance width protocols. + * Decode pulse distance width protocols. We only check the mark or space length of a 1 against a threshold value, otherwise we always assume a 0! + * We do not check the length of the constant pulse for the widely used PulseDistance width and the constant pause for PulseWidth (currently only sony protocol). + * using matchMark() and matchSpace(), which includes MARK_EXCESS_MICROS in comparison. * * We can have the following protocol timings - * Pulse distance: Pulses/marks are constant, pause/spaces have different length, like NEC. - * Pulse width: Pulses/marks have different length, pause/spaces are constant, like Sony. - * Pulse distance width: Pulses/marks and pause/spaces have different length, often the bit length is constant, like MagiQuest. - * Pulse distance width can be decoded like pulse width decoder, if this decoder does not check the length of pause/spaces. + * PULSE_DISTANCE: Pause/spaces have different length and determine the bit value, longer space is 1. Pulses/marks can be constant, like NEC. + * PULSE_WIDTH: Pulses/marks have different length and determine the bit value, longer mark is 1. Pause/spaces can be constant, like Sony. + * PULSE_DISTANCE_WIDTH: Pulses/marks and pause/spaces have different length, often the bit length is constant, like MagiQuest. Can be decoded using the PULSE_DISTANCE decoding. * - * Input is IrReceiver.decodedIRData.rawDataPtr->rawbuf[] + * Input is IrReceiver.irparams.rawbuf[] * Output is IrReceiver.decodedIRData.decodedRawData * - * Assume pulse distance if aOneMarkMicros == aZeroMarkMicros - * - * @param aNumberOfBits Number of bits to decode from decodedIRData.rawDataPtr->rawbuf[] array. - * @param aStartOffset Offset in decodedIRData.rawDataPtr->rawbuf[] to start decoding. Must point to a mark. - * @param aOneMarkMicros Taken as constant BitMarkMicros for pulse distance. - * @param aZeroMarkMicros Not required if DECODE_STRICT_CHECKS is not defined. - * @param aOneSpaceMicros Taken as (constant) BitSpaceMicros for pulse width. - * @param aZeroSpaceMicros Not required if DECODE_STRICT_CHECKS is not defined. - * @param aMSBfirst If true send Most Significant Bit first, else send Least Significant Bit (lowest bit) first. - * @return true If decoding was successful + * @param aNumberOfBits Number of bits to decode from irparams.rawbuf[] array. + * @param aStartOffset Offset in irparams.rawbuf[] to start decoding. Must point to a mark. + * @param aOneMicros Timing value for 1 + * @param aIsPulseWidthProtocol If true the aOneThresholdMicros id the mark threshold for 1, otherwise the space threshold + * @param aMSBfirst If true send Most Significant Bit first, else send Least Significant Bit (lowest bit) first. */ -bool IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset, uint16_t aOneMarkMicros, - uint16_t aZeroMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst) { +void IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMicros, + bool aIsPulseWidthProtocol, bool aMSBfirst) { - auto *tRawBufPointer = &decodedIRData.rawDataPtr->rawbuf[aStartOffset]; + DEBUG_PRINT(F("aOneMicros=")); + DEBUG_PRINT(aOneMicros); + DEBUG_PRINT(F(", 0.75*aOneMicros=")); + DEBUG_PRINT((aOneMicros * 3) / 4); + DEBUG_PRINT(F(", MARK_EXCESS_MICROS=" STR(MARK_EXCESS_MICROS) " isPulseWidthProtocol=")); + DEBUG_PRINT(aIsPulseWidthProtocol); + DEBUG_PRINTLN(); - bool isPulseDistanceProtocol = (aOneMarkMicros == aZeroMarkMicros); // If true, we have a constant mark -> pulse distance protocol - - IRRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop - IRRawDataType tMask = 1UL; // Mask is only used for LSB first + IRDecodedRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop + IRDecodedRawDataType tMask = 1UL; // Mask is only used for LSB first + auto *tRawBufPointer = &irparams.rawbuf[aStartOffset]; for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { - // get one mark and space pair - unsigned int tMarkTicks; - unsigned int tSpaceTicks; - if (isPulseDistanceProtocol) { + bool tBitValue; + uint16_t tCurrentTicks; + if (aIsPulseWidthProtocol) { /* - * Pulse distance here, it is not required to check constant mark duration (aOneMarkMicros) and zero space duration. + * PULSE_WIDTH here. + * !!!We only check variable length mark indicating a 1 or 0!!! */ -#if defined DECODE_STRICT_CHECKS - tMarkTicks = *tRawBufPointer++; -#else - (void) aZeroSpaceMicros; + tCurrentTicks = *tRawBufPointer++; + tBitValue = matchMark(tCurrentTicks, aOneMicros); // Check for variable length mark indicating a 1 or 0 tRawBufPointer++; -#endif - tSpaceTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) - -#if defined DECODE_STRICT_CHECKS - // Check for constant length mark - if (!matchMark(tMarkTicks, aOneMarkMicros)) { -# if defined(LOCAL_DEBUG) - Serial.print(F("Mark=")); - Serial.print(tMarkTicks * MICROS_PER_TICK); - Serial.print(F(" is not ")); - Serial.print(aOneMarkMicros); - Serial.print(F(". Index=")); - Serial.print(aNumberOfBits - i); - Serial.print(' '); -# endif - return false; - } -#endif - } else { /* - * Pulse width here, it is not required to check (constant) space duration and zero mark duration. + * PULSE_DISTANCE -including PULSE_DISTANCE_WIDTH- here. + * !!!We only check variable length space indicating a 1 or 0!!! */ - tMarkTicks = *tRawBufPointer++; -#if defined DECODE_STRICT_CHECKS - tSpaceTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) -#else - (void) aZeroMarkMicros; - (void) aZeroSpaceMicros; tRawBufPointer++; -#endif + tCurrentTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) + tBitValue = matchSpace(tCurrentTicks, aOneMicros); // Check for variable length space indicating a 1 or 0 } if (aMSBfirst) { tDecodedData <<= 1; } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" - bool tBitValue; - if (isPulseDistanceProtocol) { - // Check for variable length space indicating a 1 or 0 - tBitValue = matchSpace(tSpaceTicks, aOneSpaceMicros); // tSpaceTicks is initialized here, even if some compiler are complaining! - } else { - // Check for variable length mark indicating a 1 or 0 - tBitValue = matchMark(tMarkTicks, aOneMarkMicros); // tMarkTicks is initialized here, even if some compiler are complaining! - } -#pragma GCC diagnostic pop + if (tBitValue) { // It's a 1 -> set the bit if (aMSBfirst) { @@ -728,163 +803,334 @@ bool IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, uint_fast8 } else { tDecodedData |= tMask; } - IR_TRACE_PRINTLN('1'); + TRACE_PRINT(tCurrentTicks); + TRACE_PRINTLN(F(" => 1")); } else { -#if defined DECODE_STRICT_CHECKS - /* - * Additionally check length of length parameter which determine a zero - */ - if (isPulseDistanceProtocol) { - if (!matchSpace(tSpaceTicks, aZeroSpaceMicros)) { -# if defined(LOCAL_DEBUG) - Serial.print(F("Space=")); - Serial.print(tSpaceTicks * MICROS_PER_TICK); - Serial.print(F(" is not ")); - Serial.print(aOneSpaceMicros); - Serial.print(F(" or ")); - Serial.print(aZeroSpaceMicros); - Serial.print(F(". Index=")); - Serial.print(aNumberOfBits - i); - Serial.print(' '); -# endif - return false; - } - } else { - if (!matchMark(tMarkTicks, aZeroMarkMicros)) { -# if defined(LOCAL_DEBUG) - Serial.print(F("Mark=")); - Serial.print(tMarkTicks * MICROS_PER_TICK); - Serial.print(F(" is not ")); - Serial.print(aOneMarkMicros); - Serial.print(F(" or ")); - Serial.print(aZeroMarkMicros); - Serial.print(F(". Index=")); - Serial.print(aNumberOfBits - i); - Serial.print(' '); -# endif - return false; - } - } -#endif // do not set the bit - IR_TRACE_PRINTLN('0'); - } -#if defined DECODE_STRICT_CHECKS - // If we have no stop bit, assume that last space, which is not recorded, is correct, since we can not check it - if (aZeroSpaceMicros == aOneSpaceMicros - && tRawBufPointer < &decodedIRData.rawDataPtr->rawbuf[decodedIRData.rawDataPtr->rawlen]) { - // Check for constant length space (of pulse width protocol) here - if (!matchSpace(tSpaceTicks, aOneSpaceMicros)) { -# if defined(LOCAL_DEBUG) - Serial.print(F("Space=")); - Serial.print(tSpaceTicks * MICROS_PER_TICK); - Serial.print(F(" is not ")); - Serial.print(aOneSpaceMicros); - Serial.print(F(". Index=")); - Serial.print(aNumberOfBits - i); - Serial.print(' '); -# endif - return false; - } + TRACE_PRINT(tCurrentTicks); + TRACE_PRINTLN(F(" => 0")); } -#endif tMask <<= 1; } decodedIRData.decodedRawData = tDecodedData; - return true; } /** - * Decode pulse distance protocols for PulseDistanceWidthProtocolConstants. - * @return true if decoding was successful + * New threshold decoder to be activated by USE_THRESHOLD_DECODER + * Assumes a 0 for shorter and a 1 for longer timing. Thus the value must be eventually inverted by the calling protocol decoder (MagiQuest). + * In normal decoder, we check whether there is a timing for a 1 (usually the longer timing) within a range of 75 % to 125 % of the nominal timing. See TICKS_LOW. + * Many protocols have a ratio of 1 to 3 between short and long timing. In this case this decoder extends the range to 66% and the upper bound does not matter anyway. + * I hope that this will give slightly better results especially for + * - jittering signals + * - protocols with a smaller timing ratio than 1 to 2 + * - protocols with short 1 pulses / pauses like MagiQuest. + * Requires up to 458 bytes more program space, if more than 1 protocol is involved. + * but saves 90 bytes if only e.g. NEC is selected. + * + * @param aNumberOfBits Number of bits to decode from irparams.rawbuf[] array. + * @param aStartOffset Offset in irparams.rawbuf[] to start decoding. Must point to a mark. + * @param aOneThresholdMicros Threshold value for 1 + * @param aIsPulseWidthProtocol If true the aOneThresholdMicros id the mark threshold for 1, otherwise the space threshold + * @param aMSBfirst If true send Most Significant Bit first, else send Least Significant Bit (lowest bit) first. */ -bool IRrecv::decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, - uint_fast8_t aStartOffset) { +void IRrecv::decodeWithThresholdPulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, + uint16_t aOneThresholdMicros, bool aIsPulseWidthProtocol, bool aMSBfirst) { - return decodePulseDistanceWidthData(aNumberOfBits, aStartOffset, aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, - aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, - aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aProtocolConstants->Flags); -} + DEBUG_PRINT(F("OneThresholdMicros=")); + DEBUG_PRINT(aOneThresholdMicros); + DEBUG_PRINT(F(" isPulseWidthProtocol=")); + DEBUG_PRINT(aIsPulseWidthProtocol); + DEBUG_PRINTLN(); -/* - * Static variables for the getBiphaselevel function - */ -uint_fast8_t sBiphaseDecodeRawbuffOffset; // Index into raw timing array -uint16_t sBiphaseCurrentTimingIntervals; // 1, 2 or 3. Number of aBiphaseTimeUnit intervals of the current rawbuf[sBiphaseDecodeRawbuffOffset] timing. -uint_fast8_t sBiphaseUsedTimingIntervals; // Number of already used intervals of sCurrentTimingIntervals. -uint16_t sBiphaseTimeUnit; + IRDecodedRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop + IRDecodedRawDataType tMask = 1UL; // Mask is only used for LSB first + auto *tRawBufPointer = &irparams.rawbuf[aStartOffset]; + + for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { + + if (!aIsPulseWidthProtocol) { + tRawBufPointer++; + } + uint16_t tCurrentMicros = *tRawBufPointer * MICROS_PER_TICK; + bool tBitValue = tCurrentMicros > aOneThresholdMicros; // Check for variable length timing indicating a 1 or 0 + tRawBufPointer++; + + if (aIsPulseWidthProtocol) { + tRawBufPointer++; + } + + if (aMSBfirst) { + tDecodedData <<= 1; + } -void IRrecv::initBiphaselevel(uint_fast8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit) { - sBiphaseDecodeRawbuffOffset = aRCDecodeRawbuffOffset; - sBiphaseTimeUnit = aBiphaseTimeUnit; - sBiphaseUsedTimingIntervals = 0; + if (tBitValue) { + // It's a 1 -> set the bit + if (aMSBfirst) { + tDecodedData |= 1; + } else { + tDecodedData |= tMask; + } + TRACE_PRINT(tCurrentMicros); + TRACE_PRINTLN(F(" => 1")); + } else { + // do not set the bit + TRACE_PRINT(tCurrentMicros); + TRACE_PRINTLN(F(" => 0")); + } + tMask <<= 1; + } + decodedIRData.decodedRawData = tDecodedData; } /** - * Gets the level of one time interval (aBiphaseTimeUnit) at a time from the raw buffer. - * The RC5/6 decoding is easier if the data is broken into time intervals. - * E.g. if the buffer has mark for 2 time intervals and space for 1, - * successive calls to getBiphaselevel will return 1, 1, 0. - * - * _ _ _ _ _ _ _ _ _ _ _ _ _ - * _____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | - * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Significant clock edge - * _ _ _ ___ _ ___ ___ _ - Mark - * Data _____| |___| |_| |_| |_| |___| |___| |_| | - Data starts with a mark->space bit - * 1 0 0 0 1 1 0 1 0 1 1 - Space - * A mark to space at a significant clock edge results in a 1 - * A space to mark at a significant clock edge results in a 0 (for RC6) - * Returns current level [MARK or SPACE] or -1 for error (measured time interval is not a multiple of sBiphaseTimeUnit). + * Old deprecated version with 3 timing parameters instead of one and a aIsPulseWidthProtocol flag */ -uint_fast8_t IRrecv::getBiphaselevel() { - uint_fast8_t tLevelOfCurrentInterval; // 0 (SPACE) or 1 (MARK) +void IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, bool aMSBfirst) { - if (sBiphaseDecodeRawbuffOffset >= decodedIRData.rawDataPtr->rawlen) { - return SPACE; // After end of recorded buffer, assume space. - } + auto *tRawBufPointer = &irparams.rawbuf[aStartOffset]; - tLevelOfCurrentInterval = (sBiphaseDecodeRawbuffOffset) & 1; // on odd rawbuf offsets we have mark timings + bool isPulseDistanceProtocol = (aOneMarkMicros == aZeroMarkMicros); // If true, we check aOneSpaceMicros -> pulse distance protocol + + IRDecodedRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop + IRDecodedRawDataType tMask = 1UL; // Mask is only used for LSB first + + for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { + // get one mark and space pair + unsigned int tMarkTicks; + unsigned int tSpaceTicks; + bool tBitValue; + + if (isPulseDistanceProtocol) { + /* + * PULSE_DISTANCE -including PULSE_DISTANCE_WIDTH- here. + * !!!We only check variable length space indicating a 1 or 0!!! + */ + tRawBufPointer++; + tSpaceTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) + tBitValue = matchSpace(tSpaceTicks, aOneSpaceMicros); // Check for variable length space indicating a 1 or 0 - /* - * Setup data if sUsedTimingIntervals is 0 - */ - if (sBiphaseUsedTimingIntervals == 0) { - uint16_t tCurrentTimingWith = decodedIRData.rawDataPtr->rawbuf[sBiphaseDecodeRawbuffOffset]; - uint16_t tMarkExcessCorrection = (tLevelOfCurrentInterval == MARK) ? MARK_EXCESS_MICROS : -MARK_EXCESS_MICROS; - - if (matchTicks(tCurrentTimingWith, sBiphaseTimeUnit + tMarkExcessCorrection)) { - sBiphaseCurrentTimingIntervals = 1; - } else if (matchTicks(tCurrentTimingWith, (2 * sBiphaseTimeUnit) + tMarkExcessCorrection)) { - sBiphaseCurrentTimingIntervals = 2; - } else if (matchTicks(tCurrentTimingWith, (3 * sBiphaseTimeUnit) + tMarkExcessCorrection)) { - sBiphaseCurrentTimingIntervals = 3; } else { - return -1; + /* + * PULSE_WIDTH here. + * !!!We only check variable length mark indicating a 1 or 0!!! + */ + tMarkTicks = *tRawBufPointer++; + tBitValue = matchMark(tMarkTicks, aOneMarkMicros); // Check for variable length mark indicating a 1 or 0 + tRawBufPointer++; } - } -// We use another interval from tCurrentTimingIntervals - sBiphaseUsedTimingIntervals++; + if (aMSBfirst) { + tDecodedData <<= 1; + } -// keep track of current timing offset - if (sBiphaseUsedTimingIntervals >= sBiphaseCurrentTimingIntervals) { - // we have used all intervals of current timing, switch to next timing value - sBiphaseUsedTimingIntervals = 0; - sBiphaseDecodeRawbuffOffset++; + if (tBitValue) { + // It's a 1 -> set the bit + if (aMSBfirst) { + tDecodedData |= 1; + } else { + tDecodedData |= tMask; + } + TRACE_PRINTLN(F("=> 1")); + } else { + // do not set the bit + TRACE_PRINTLN(F("=> 0")); + } + tMask <<= 1; } + decodedIRData.decodedRawData = tDecodedData; +} - IR_TRACE_PRINTLN(tLevelOfCurrentInterval); +/* + * Old deprecated version with 7 parameters and unused aZeroSpaceMicros parameter + */ +void IRrecv::decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aZeroMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst) { - return tLevelOfCurrentInterval; + (void) aZeroSpaceMicros; + decodePulseDistanceWidthData(aNumberOfBits, aStartOffset, aOneMarkMicros, aZeroMarkMicros, aOneSpaceMicros, aMSBfirst); } -#if defined(DECODE_HASH) -/********************************************************************************************************************** - * Internal Hash decode function - **********************************************************************************************************************/ -/** +/* + * Only sensible for development or very exotic requirements. - Not used yet + * Check for additional required characteristics of timing like length of mark for a constant mark protocol, + * where space length determines the bit value. Requires up to 194 additional bytes of program memory. + * + * @param aZeroMarkMicros For strict checks + * @param aZeroSpaceMicros For strict checks + * @return true if decoding successful + * + */ +bool IRrecv::decodeStrictPulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst) { + + auto *tRawBufPointer = &irparams.rawbuf[aStartOffset]; + + bool isPulseDistanceProtocol = (aOneMarkMicros == aZeroMarkMicros); // If true, we have a constant mark -> pulse distance protocol + + IRDecodedRawDataType tDecodedData = 0; // For MSB first tDecodedData is shifted left each loop + IRDecodedRawDataType tMask = 1UL; // Mask is only used for LSB first + + for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { + // get one mark and space pair + unsigned int tMarkTicks; + unsigned int tSpaceTicks; + bool tBitValue; + + if (isPulseDistanceProtocol) { + /* + * PULSE_DISTANCE here (aOneMarkMicros == aZeroMarkMicros) + * We additionally check constant mark duration and in case of zero the zero space duration. + */ + tMarkTicks = *tRawBufPointer++; + tSpaceTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) + tBitValue = matchSpace(tSpaceTicks, aOneSpaceMicros); // Check for variable length space indicating a 1 or 0 + + // Check for constant mark duration + if (!matchMark(tMarkTicks, aOneMarkMicros)) { + DEBUG_PRINT(F("Mark=")); + DEBUG_PRINT(tMarkTicks * MICROS_PER_TICK); + DEBUG_PRINT(F(" is not ")); + DEBUG_PRINT(aOneMarkMicros); + DEBUG_PRINT(F(". Index=")); + DEBUG_PRINT(aNumberOfBits - i); + DEBUG_PRINT(' '); + return false; + } + + // in case of 0, check for zero space duration + if (!tBitValue && !matchSpace(tSpaceTicks, aZeroSpaceMicros)) { + DEBUG_PRINT(F("Space=")); + DEBUG_PRINT(tSpaceTicks * MICROS_PER_TICK); + DEBUG_PRINT(F(" is not ")); + DEBUG_PRINT(aZeroSpaceMicros); + DEBUG_PRINT(F(". Index=")); + DEBUG_PRINT(aNumberOfBits - i); + DEBUG_PRINT(' '); + return false; + } + + } else { + /* + * PULSE_WIDTH -including PULSE_DISTANCE_WIDTH- here. + * We additionally check two space durations and in case of zero the zero mark duration. + */ + tMarkTicks = *tRawBufPointer++; + tBitValue = matchMark(tMarkTicks, aOneMarkMicros); // Check for variable length mark indicating a 1 or 0 + tSpaceTicks = *tRawBufPointer++; // maybe buffer overflow for last bit, but we do not evaluate this value :-) + + // Check for space length, which is not constant in case of PULSE_DISTANCE_WIDTH + if ((tBitValue && !matchSpace(tSpaceTicks, aOneSpaceMicros)) + || ((!tBitValue && !matchSpace(tSpaceTicks, aZeroSpaceMicros)))) { + DEBUG_PRINT(F("Space=")); + DEBUG_PRINT(tSpaceTicks * MICROS_PER_TICK); + DEBUG_PRINT(F(" is not ")); + DEBUG_PRINT(aOneSpaceMicros); + DEBUG_PRINT(F(" or ")); + DEBUG_PRINT(aZeroSpaceMicros); + DEBUG_PRINT(F(". Index=")); + DEBUG_PRINT(aNumberOfBits - i); + DEBUG_PRINT(' '); + return false; + } + if (!tBitValue && !matchMark(tMarkTicks, aZeroMarkMicros)) { + DEBUG_PRINT(F("Mark=")); + DEBUG_PRINT(tMarkTicks * MICROS_PER_TICK); + DEBUG_PRINT(F(" is not ")); + DEBUG_PRINT(aZeroMarkMicros); + DEBUG_PRINT(F(". Index=")); + DEBUG_PRINT(aNumberOfBits - i); + DEBUG_PRINT(' '); + return false; + } + } + + if (aMSBfirst) { + tDecodedData <<= 1; + } + + if (tBitValue) { + // It's a 1 -> set the bit + if (aMSBfirst) { + tDecodedData |= 1; + } else { + tDecodedData |= tMask; + } + TRACE_PRINTLN(F("=> 1")); + } else { + // do not set the bit + TRACE_PRINTLN(F("=> 0")); + } + tMask <<= 1; + } + decodedIRData.decodedRawData = tDecodedData; + return true; +} + +/** + * Decode pulse distance protocols for PulseDistanceWidthProtocolConstants. + * @return true if decoding was successful + */ +#if defined(USE_STRICT_DECODER) +bool +#else +void +#endif +IRrecv::decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, + IRRawlenType aStartOffset) { + +#if defined(USE_STRICT_DECODER) + return decodeStrictPulseDistanceWidthData(aNumberOfBits, aStartOffset, aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, (aProtocolConstants->Flags & PROTOCOL_IS_MSB_MASK)); + +#else + bool tIsPulseWidthProtocol = aProtocolConstants->Flags & PROTOCOL_IS_PULSE_WIDTH_MASK; + uint16_t tThresholdMicros; + +# if defined(USE_THRESHOLD_DECODER) + if (tIsPulseWidthProtocol) { + // we check the length of marks here + tThresholdMicros = ((aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros + + aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros) / 2) - MARK_EXCESS_MICROS;// MARK_EXCESS_MICROS is 0 here if not explicitly specified by user + } else { + // we check the length of spaces here + tThresholdMicros = ((aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros + + aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros) / 2) + MARK_EXCESS_MICROS;// MARK_EXCESS_MICROS is 0 here if not explicitly specified by user + } + return decodeWithThresholdPulseDistanceWidthData(aNumberOfBits, aStartOffset, tThresholdMicros, + aProtocolConstants->Flags & PROTOCOL_IS_PULSE_WIDTH_MASK, (aProtocolConstants->Flags & PROTOCOL_IS_MSB_MASK)); +# else + if (tIsPulseWidthProtocol) { + tThresholdMicros = aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros; + } else { + tThresholdMicros = aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros; + } + decodePulseDistanceWidthData(aNumberOfBits, aStartOffset, tThresholdMicros, + aProtocolConstants->Flags & PROTOCOL_IS_PULSE_WIDTH_MASK, (aProtocolConstants->Flags & PROTOCOL_IS_MSB_MASK)); +# endif +#endif +} + +void IRrecv::decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset) { + + PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants; + memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM, + sizeof(tTemporaryPulseDistanceWidthProtocolConstants)); + + decodePulseDistanceWidthData(&tTemporaryPulseDistanceWidthProtocolConstants, aNumberOfBits, aStartOffset); +} + +/********************************************************************************************************************** + * Internal Hash decode function + **********************************************************************************************************************/ +#define FNV_PRIME_32 16777619 ///< used for decodeHash() +#define FNV_BASIS_32 2166136261 ///< used for decodeHash() + +/** * Compare two (tick) values for Hash decoder - * Use a tolerance of 20% to enable e.g. 500 and 600 (NEC timing) to be equal + * Use a tolerance of 20% to enable e.g. 500 and 600 (NEC timing) and at least 200 and 250 to be equal * @return 0 if newval is shorter, 1 if newval is equal, and 2 if newval is longer */ uint_fast8_t IRrecv::compare(uint16_t oldval, uint16_t newval) { @@ -897,21 +1143,17 @@ uint_fast8_t IRrecv::compare(uint16_t oldval, uint16_t newval) { return 1; } -#define FNV_PRIME_32 16777619 ///< used for decodeHash() -#define FNV_BASIS_32 2166136261 ///< used for decodeHash() - /** - * decodeHash - decode an arbitrary IR code. + * 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: look at the sequence of MARK signals, and see if each one - * is shorter (0), the same length (1), or longer (2) than the previous. - * Do the same with the SPACE signals. Hash the resulting sequence of 0's, - * 1's, and 2's to a 32-bit value. This will give a unique value for each - * different code (probably), for most code systems. + * 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 resulting sequence of 0's, 1's, and 2's to a 32-bit value. + * This will give a unique value for each different code (probably), for most code systems. * - * Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param + * Uses FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param * Converts the raw code values into a 32-bit hash code. * Hopefully this code is unique for each button. * This isn't a "real" decoding, just an arbitrary value. @@ -922,17 +1164,16 @@ bool IRrecv::decodeHash() { unsigned long hash = FNV_BASIS_32; // the result is the same no matter if we use a long or unsigned long variable // Require at least 6 samples to prevent triggering on noise - if (decodedIRData.rawDataPtr->rawlen < 6) { + if (decodedIRData.rawlen < 6) { + DEBUG_PRINT(F("HASH: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is less than 6")); return false; } -#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR - uint_fast8_t i; -#else - unsigned int i; -#endif - for (i = 1; (i + 2) < decodedIRData.rawDataPtr->rawlen; i++) { - uint_fast8_t value = compare(decodedIRData.rawDataPtr->rawbuf[i], decodedIRData.rawDataPtr->rawbuf[i + 2]); - // Add value into the hash + for (IRRawlenType i = 1; (i + 2) < decodedIRData.rawlen; i++) { + // Compare mark with mark and space with space + uint_fast8_t value = compare(irparams.rawbuf[i], irparams.rawbuf[i + 2]); + // 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]) hash = (hash * FNV_PRIME_32) ^ value; } @@ -964,7 +1205,6 @@ bool IRrecv::decodeHashOld(decode_results *aResults) { return true; } -#endif // DECODE_HASH /********************************************************************************************************************** * Match functions @@ -975,32 +1215,44 @@ bool IRrecv::decodeHashOld(decode_results *aResults) { */ bool IRrecv::checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants) { // Check header "mark" and "space" - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros)) { -#if defined(LOCAL_TRACE) - Serial.print(::getProtocolString(aProtocolConstants->ProtocolIndex)); - Serial.println(F(": Header mark length is wrong")); -#endif + if (!matchMark(irparams.rawbuf[1], aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros)) { + TRACE_PRINT(::getProtocolString(aProtocolConstants->ProtocolIndex)); + TRACE_PRINTLN(F(": Header mark length is wrong")); return false; } - if (!matchSpace(decodedIRData.rawDataPtr->rawbuf[2], aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros)) { -#if defined(LOCAL_TRACE) - Serial.print(::getProtocolString(aProtocolConstants->ProtocolIndex)); - Serial.println(F(": Header space length is wrong")); -#endif + if (!matchSpace(irparams.rawbuf[2], aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros)) { + TRACE_PRINT(::getProtocolString(aProtocolConstants->ProtocolIndex)); + TRACE_PRINTLN(F(": Header space length is wrong")); + return false; + } + return true; +} + +bool IRrecv::checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM) { +// Check header "mark" and "space" + if (!matchMark(irparams.rawbuf[1], pgm_read_word(&aProtocolConstantsPGM->DistanceWidthTimingInfo.HeaderMarkMicros))) { + TRACE_PRINT(::getProtocolString((decode_type_t ) pgm_read_byte(&aProtocolConstantsPGM->ProtocolIndex))); + TRACE_PRINTLN(F(": Header mark length is wrong")); + return false; + } + if (!matchSpace(irparams.rawbuf[2], pgm_read_word(&aProtocolConstantsPGM->DistanceWidthTimingInfo.HeaderSpaceMicros))) { + TRACE_PRINT(::getProtocolString((decode_type_t ) pgm_read_byte(&aProtocolConstantsPGM->ProtocolIndex))); + TRACE_PRINTLN(F(": Header space length is wrong")); return false; } return true; } /* - * Do not check for same address and command, because it is almost not possible to press 2 different buttons on the remote within around 100 ms. + * Does not check for same address and command, because it is almost not possible to press 2 different buttons on the remote within around 100 ms. * And if really required, it can be enabled here, or done manually in user program. * And we have still no RC6 toggle bit check for detecting a second press on the same button. */ void IRrecv::checkForRepeatSpaceTicksAndSetFlag(uint16_t aMaximumRepeatSpaceTicks) { - if (decodedIRData.rawDataPtr->rawbuf[0] < aMaximumRepeatSpaceTicks -#if defined(ENABLE_FULL_REPEAT_CHECK) - && decodedIRData.address == lastDecodedAddress && decodedIRData.command == lastDecodedCommand /* requires around 85 bytes program space */ + if (decodedIRData.initialGapTicks < aMaximumRepeatSpaceTicks +#if defined(ENABLE_COMPLETE_REPEAT_CHECK) +// Check also for same command and address values to detect a repeat. Not sensible for standard protocols, because it is almost not possible to press 2 different buttons on the remote within around 100 ms + && decodedIRData.address == lastDecodedAddress && decodedIRData.command == lastDecodedCommand /* requires around 44 bytes program space */ #endif ) { decodedIRData.flags |= IRDATA_FLAGS_IS_REPEAT; @@ -1008,19 +1260,26 @@ void IRrecv::checkForRepeatSpaceTicksAndSetFlag(uint16_t aMaximumRepeatSpaceTick } /** - * Match function without compensating for marks exceeded or spaces shortened by demodulator hardware - * Currently not used + * Match function WITHOUT compensating for marks exceeded or spaces shortened by demodulator hardware + * Match is true, if signal value is bigger/equal 75% and less/equal 125% of aMatchValueMicros. + * @return true, if values match */ bool matchTicks(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { -#if defined(LOCAL_TRACE) - Serial.print(F("Testing: ")); - Serial.print(TICKS_LOW(aMatchValueMicros), DEC); - Serial.print(F(" <= ")); - Serial.print(aMeasuredTicks, DEC); - Serial.print(F(" <= ")); - Serial.print(TICKS_HIGH(aMatchValueMicros), DEC); -#endif - bool passed = ((aMeasuredTicks >= TICKS_LOW(aMatchValueMicros)) && (aMeasuredTicks <= TICKS_HIGH(aMatchValueMicros))); + uint16_t tMeasuredMicros = (aMeasuredTicks * MICROS_PER_TICK); + uint16_t tMatchValueMicrosQuarter = aMatchValueMicros / 4; + + TRACE_PRINT(F("Testing (actual vs desired): ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 3); // rounded value because we divide first + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 5); + + bool passed = (tMeasuredMicros >= (tMatchValueMicrosQuarter * 3) && tMeasuredMicros <= (tMatchValueMicrosQuarter * 5)); #if defined(LOCAL_TRACE) if (passed) { Serial.println(F(" => passed")); @@ -1031,29 +1290,78 @@ bool matchTicks(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { return passed; } -bool MATCH(uint16_t measured_ticks, uint16_t desired_us) { - return matchTicks(measured_ticks, desired_us); +bool matchTicksWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { + uint16_t tMeasuredMicros = (aMeasuredTicks * MICROS_PER_TICK); + uint16_t tMatchValueMicrosQuarter = aMatchValueMicros / 4; + + TRACE_PRINT(F("Testing with greater range (actual vs desired): ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 2); // rounded value because we divide first + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 6); + + bool passed = (tMeasuredMicros >= (tMatchValueMicrosQuarter * 2) && tMeasuredMicros <= (tMatchValueMicrosQuarter * 6)); +#if defined(LOCAL_TRACE) + if (passed) { + Serial.println(F(" => passed")); + } else { + Serial.println(F(" => FAILED")); + } +#endif + return passed; } - /** - * Compensate for marks exceeded by demodulator hardware + * Match function WITH compensating for marks exceeded or spaces shortened by demodulator hardware + * With MARK_EXCESS_MICROS default value of 20 we cannot match 200 to 250, because we have 186 < 180 <= 310 + * @return true, if values match */ -bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { +bool matchTicks(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros, int16_t aCompensationMicrosForTicks) { + uint16_t tMeasuredMicros = (aMeasuredTicks * MICROS_PER_TICK) + aCompensationMicrosForTicks; + uint16_t tMatchValueMicrosQuarter = aMatchValueMicros / 4; + + TRACE_PRINT(F("Testing (actual vs desired): ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 3); // rounded value because we divide first + TRACE_PRINT(F(" < ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 5); + + bool passed = (tMeasuredMicros > (tMatchValueMicrosQuarter * 3) && tMeasuredMicros <= (tMatchValueMicrosQuarter * 5)); #if defined(LOCAL_TRACE) - Serial.print(F("Testing mark (actual vs desired): ")); - Serial.print(aMeasuredTicks * MICROS_PER_TICK, DEC); - Serial.print(F("us vs ")); - Serial.print(aMatchValueMicros, DEC); - Serial.print(F("us: ")); - Serial.print(TICKS_LOW(aMatchValueMicros + MARK_EXCESS_MICROS) * MICROS_PER_TICK, DEC); - Serial.print(F(" <= ")); - Serial.print(aMeasuredTicks * MICROS_PER_TICK, DEC); - Serial.print(F(" <= ")); - Serial.print(TICKS_HIGH(aMatchValueMicros + MARK_EXCESS_MICROS) * MICROS_PER_TICK, DEC); -#endif - // compensate for marks exceeded by demodulator hardware - bool passed = ((aMeasuredTicks >= TICKS_LOW(aMatchValueMicros + MARK_EXCESS_MICROS)) - && (aMeasuredTicks <= TICKS_HIGH(aMatchValueMicros + MARK_EXCESS_MICROS))); + if (passed) { + Serial.println(F(" => passed")); + } else { + Serial.println(F(" => FAILED")); + } +#endif + return passed; +} + +bool matchTicksWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros, int16_t aCompensationMicrosForTicks) { + uint16_t tMeasuredMicros = (aMeasuredTicks * MICROS_PER_TICK) + aCompensationMicrosForTicks; + uint16_t tMatchValueMicrosQuarter = aMatchValueMicros / 4; + + TRACE_PRINT(F("Testing with greater range (actual vs desired): ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 2); // rounded value because we divide first + TRACE_PRINT(F(" < ")); + TRACE_PRINT(tMeasuredMicros); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(tMatchValueMicrosQuarter * 6); + + bool passed = (tMeasuredMicros > (tMatchValueMicrosQuarter * 2) && tMeasuredMicros <= (tMatchValueMicrosQuarter * 6)); #if defined(LOCAL_TRACE) if (passed) { Serial.println(F(" => passed")); @@ -1064,37 +1372,114 @@ bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { return passed; } +bool MATCH(uint16_t measured_ticks, uint16_t desired_us) { + return matchTicks(measured_ticks, desired_us); +} + +/** + * Compensate for marks exceeded by demodulator hardware + * @return true, if values match + */ +bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { +#if (MARK_EXCESS_MICROS == 0) + return matchTicks(aMeasuredTicks, aMatchValueMicros); +#else + +# if !defined(USE_OLD_MATCH_FUNCTIONS) + return matchTicks(aMeasuredTicks, aMatchValueMicros, -MARK_EXCESS_MICROS); // New handling of MARK_EXCESS_MICROS without strange rounding errors +# endif + + // old version here + aMatchValueMicros += MARK_EXCESS_MICROS; + + TRACE_PRINT(F("Testing mark (actual vs desired): ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); +// TRACE_PRINT(F("TICKS_LOW=")); +// TRACE_PRINT(TICKS_LOW(aMatchValueMicros)); +// TRACE_PRINT(F(" ")); + TRACE_PRINT(TICKS_LOW(aMatchValueMicros) * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(TICKS_HIGH(aMatchValueMicros) * MICROS_PER_TICK); + + // compensate for marks exceeded by demodulator hardware + bool passed = ((aMeasuredTicks >= TICKS_LOW(aMatchValueMicros)) + && (aMeasuredTicks <= TICKS_HIGH(aMatchValueMicros))); +# if defined(LOCAL_TRACE) + if (passed) { + Serial.println(F(" => passed")); + } else { + Serial.println(F(" => FAILED")); + } +# endif + return passed; +#endif +} + +bool matchMarkWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { +#if (MARK_EXCESS_MICROS == 0) + return matchTicksWithGreaterRange(aMeasuredTicks, aMatchValueMicros); +#else + return matchTicksWithGreaterRange(aMeasuredTicks, aMatchValueMicros, -MARK_EXCESS_MICROS); // New handling of MARK_EXCESS_MICROS without strange rounding errors +#endif +} + bool MATCH_MARK(uint16_t measured_ticks, uint16_t desired_us) { return matchMark(measured_ticks, desired_us); } /** * Compensate for spaces shortened by demodulator hardware + * @return true, if values match */ bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { -#if defined(LOCAL_TRACE) - Serial.print(F("Testing space (actual vs desired): ")); - Serial.print(aMeasuredTicks * MICROS_PER_TICK, DEC); - Serial.print(F("us vs ")); - Serial.print(aMatchValueMicros, DEC); - Serial.print(F("us: ")); - Serial.print(TICKS_LOW(aMatchValueMicros - MARK_EXCESS_MICROS) * MICROS_PER_TICK, DEC); - Serial.print(F(" <= ")); - Serial.print(aMeasuredTicks * MICROS_PER_TICK, DEC); - Serial.print(F(" <= ")); - Serial.print(TICKS_HIGH(aMatchValueMicros - MARK_EXCESS_MICROS) * MICROS_PER_TICK, DEC); -#endif - // compensate for spaces shortened by demodulator hardware - bool passed = ((aMeasuredTicks >= TICKS_LOW(aMatchValueMicros - MARK_EXCESS_MICROS)) - && (aMeasuredTicks <= TICKS_HIGH(aMatchValueMicros - MARK_EXCESS_MICROS))); -#if defined(LOCAL_TRACE) - if (passed) { - Serial.println(F(" => passed")); - } else { - Serial.println(F(" => FAILED")); - } +#if (MARK_EXCESS_MICROS == 0) + return matchTicks(aMeasuredTicks, aMatchValueMicros); +#else +# if !defined(USE_OLD_MATCH_FUNCTIONS) + return matchTicks(aMeasuredTicks, aMatchValueMicros, MARK_EXCESS_MICROS); // New handling of MARK_EXCESS_MICROS without strange rounding errors +# endif + // old version here + aMatchValueMicros -= MARK_EXCESS_MICROS; + + TRACE_PRINT(F("Testing space (actual vs desired): ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F("us vs ")); + TRACE_PRINT(aMatchValueMicros); + TRACE_PRINT(F("us: ")); + TRACE_PRINT(F("LOW=")); + TRACE_PRINT(TICKS_LOW(aMatchValueMicros)); + TRACE_PRINT(F(" ")); + TRACE_PRINT(TICKS_LOW(aMatchValueMicros) * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(aMeasuredTicks * MICROS_PER_TICK); + TRACE_PRINT(F(" <= ")); + TRACE_PRINT(TICKS_HIGH(aMatchValueMicros) * MICROS_PER_TICK); + + // compensate for spaces shortened by demodulator hardware + bool passed = ((aMeasuredTicks >= TICKS_LOW(aMatchValueMicros)) + && (aMeasuredTicks <= TICKS_HIGH(aMatchValueMicros))); +# if defined(LOCAL_TRACE) + if (passed) { + Serial.println(F(" => passed")); + } else { + Serial.println(F(" => FAILED")); + } +# endif + return passed; +#endif +} + +bool matchSpaceWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { +#if (MARK_EXCESS_MICROS == 0) + return matchTicksWithGreaterRange(aMeasuredTicks, aMatchValueMicros); +#else + return matchTicksWithGreaterRange(aMeasuredTicks, aMatchValueMicros, MARK_EXCESS_MICROS); // New handling of MARK_EXCESS_MICROS without strange rounding errors #endif - return passed; } bool MATCH_SPACE(uint16_t measured_ticks, uint16_t desired_us) { @@ -1108,8 +1493,8 @@ int getMarkExcessMicros() { return MARK_EXCESS_MICROS; } -/* - * Check if protocol is not detected and detected space between two transmissions +/** + * Checks if protocol is not detected and detected space between two transmissions * is smaller than known value for protocols (Sony with around 24 ms) * @return true, if CheckForRecordGapsMicros() has printed a message, i.e. gap < 15ms (RECORD_GAP_MICROS_WARNING_THRESHOLD) */ @@ -1119,13 +1504,13 @@ bool IRrecv::checkForRecordGapsMicros(Print *aSerial) { * is smaller than known value for protocols (Sony with around 24 ms) */ if (decodedIRData.protocol <= PULSE_DISTANCE - && decodedIRData.rawDataPtr->rawbuf[0] < (RECORD_GAP_MICROS_WARNING_THRESHOLD / MICROS_PER_TICK)) { + && decodedIRData.initialGapTicks < (RECORD_GAP_MICROS_WARNING_THRESHOLD / MICROS_PER_TICK)) { aSerial->println(); aSerial->print(F("Space of ")); - aSerial->print(decodedIRData.rawDataPtr->rawbuf[0] * MICROS_PER_TICK); + aSerial->print(decodedIRData.initialGapTicks * MICROS_PER_TICK); aSerial->print(F(" us between two detected transmission is smaller than the minimal gap of ")); aSerial->print(RECORD_GAP_MICROS_WARNING_THRESHOLD); - aSerial->println(F(" us known for implemented protocols like NEC, Sony, RC% etc..")); + aSerial->println(F(" us known for implemented protocols like NEC, Sony, RC5 etc..")); aSerial->println(F("But it can be OK for some yet unsupported protocols, and especially for repeats.")); aSerial->println(F("If you get unexpected results, try to increase the RECORD_GAP_MICROS in IRremote.h.")); aSerial->println(); @@ -1142,87 +1527,370 @@ void IRrecv::printActiveIRProtocols(Print *aSerial) { // call no class function with same name ::printActiveIRProtocols(aSerial); } +/* + * Prints a list of enabled protocols for this application. + * @param aSerial pointer to serial used for printing. Use "&Serial". + */ void printActiveIRProtocols(Print *aSerial) { #if defined(DECODE_ONKYO) - aSerial->print(F("Onkyo, ")); + aSerial->print(F("Onkyo, ")); #elif defined(DECODE_NEC) - aSerial->print(F("NEC/NEC2/Onkyo/Apple, ")); + aSerial->print(F("NEC/NEC2/Onkyo/Apple, ")); #endif -#if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) - aSerial->print(F("Panasonic/Kaseikyo, ")); +#if defined(DECODE_KASEIKYO) + aSerial->print(F("Panasonic/Kaseikyo, ")); #endif #if defined(DECODE_DENON) - aSerial->print(F("Denon/Sharp, ")); + aSerial->print(F("Denon/Sharp, ")); #endif #if defined(DECODE_SONY) - aSerial->print(F("Sony, ")); + aSerial->print(F("Sony, ")); #endif #if defined(DECODE_RC5) - aSerial->print(F("RC5, ")); + aSerial->print(F("RC5, ")); #endif #if defined(DECODE_RC6) - aSerial->print(F("RC6, ")); + aSerial->print(F("RC6, ")); #endif #if defined(DECODE_LG) - aSerial->print(F("LG, ")); + aSerial->print(F("LG, ")); #endif #if defined(DECODE_JVC) - aSerial->print(F("JVC, ")); + aSerial->print(F("JVC, ")); #endif #if defined(DECODE_SAMSUNG) - aSerial->print(F("Samsung, ")); + aSerial->print(F("Samsung, ")); #endif /* * Start of the exotic protocols */ #if defined(DECODE_BEO) - aSerial->print(F("Bang & Olufsen, ")); + aSerial->print(F("Bang & Olufsen, ")); #endif #if defined(DECODE_FAST) - aSerial->print(F("FAST, ")); + aSerial->print(F("FAST, ")); #endif #if defined(DECODE_WHYNTER) - aSerial->print(F("Whynter, ")); + aSerial->print(F("Whynter, ")); #endif #if defined(DECODE_LEGO_PF) - aSerial->print(F("Lego Power Functions, ")); + aSerial->print(F("Lego Power Functions, ")); #endif #if defined(DECODE_BOSEWAVE) - aSerial->print(F("Bosewave , ")); + aSerial->print(F("Bosewave, ")); #endif #if defined(DECODE_MAGIQUEST) - aSerial->print(F("MagiQuest, ")); + aSerial->print(F("MagiQuest, ")); +#endif +#if defined(DECODE_OPENLASIR) + aSerial->print(F("OpenLASIR, ")); #endif #if defined(DECODE_DISTANCE_WIDTH) - aSerial->print(F("Universal Pulse Distance Width, ")); + aSerial->print(F("Universal Pulse Distance Width, ")); #endif #if defined(DECODE_HASH) - aSerial->print(F("Hash ")); + aSerial->print(F("Hash ")); #endif #if defined(NO_DECODER) // for sending raw only - (void)aSerial; // to avoid compiler warnings + (void)aSerial; // to avoid compiler warnings #endif } +/** @} + * \addtogroup Print Print functions + * @{ + */ + /** * Function to print values and flags of IrReceiver.decodedIRData in one line. * Ends with println(). * * @param aSerial The Print object on which to write, for Arduino you can use &Serial. - * @param aPrintRepeatGap If true also print the gap before repeats. * @param aCheckForRecordGapsMicros If true, call CheckForRecordGapsMicros() which may do a long printout, * which in turn may block the proper detection of repeats.* * @return true, if CheckForRecordGapsMicros() has printed a message, i.e. gap < 15ms (RECORD_GAP_MICROS_WARNING_THRESHOLD). */ bool IRrecv::printIRResultShort(Print *aSerial, bool aPrintRepeatGap, bool aCheckForRecordGapsMicros) { + // DEPRECATED + (void) aPrintRepeatGap; + return printIRResultShort(aSerial, aCheckForRecordGapsMicros); +} +bool IRrecv::printIRResultShort(Print *aSerial, bool aCheckForRecordGapsMicros) { + + uint8_t tFlags = decodedIRData.flags; + if (tFlags & IRDATA_FLAGS_WAS_OVERFLOW) { + aSerial->println(F("Overflow")); + } else { + aSerial->print(F("Protocol=")); + aSerial->print(getProtocolString()); + if (decodedIRData.protocol == UNKNOWN) { +#if defined(DECODE_HASH) + aSerial->print(F(" Hash=0x")); +#if (__INT_WIDTH__ < 32) + aSerial->print(decodedIRData.decodedRawData, HEX); +#else + PrintULL::print(aSerial,decodedIRData.decodedRawData, HEX); +#endif + +#endif +#if !defined(DISABLE_CODE_FOR_RECEIVER) + aSerial->print(' '); + aSerial->print((decodedIRData.rawlen + 1) / 2); + aSerial->println(F(" bits (incl. gap and start) received")); +#endif + } else { +#if defined(DECODE_DISTANCE_WIDTH) + if (decodedIRData.protocol != PULSE_DISTANCE && decodedIRData.protocol != PULSE_WIDTH) { +#endif + /* + * New decoders have address and command + */ + aSerial->print(F(" Address=0x")); + aSerial->print(decodedIRData.address, HEX); + + aSerial->print(F(", Command=0x")); + aSerial->print(decodedIRData.command, HEX); + + if (tFlags & IRDATA_FLAGS_EXTRA_INFO) { + aSerial->print(F(", Extra=0x")); + aSerial->print(decodedIRData.extra, HEX); + } + + if (tFlags & IRDATA_FLAGS_PARITY_FAILED) { + aSerial->print(F(", Parity fail")); + } + + if (tFlags & IRDATA_FLAGS_TOGGLE_BIT) { + aSerial->print(F(", Toggle=1")); + } +#if defined(DECODE_DISTANCE_WIDTH) + } +#endif + + /* + * Print raw data, numberOfBits and MSB or LSB + */ + if (!(tFlags & IRDATA_FLAGS_IS_REPEAT) || decodedIRData.decodedRawData != 0) { + aSerial->print(F(", Raw-Data=0x")); +#if (__INT_WIDTH__ < 32) + aSerial->print(decodedIRData.decodedRawData, HEX); +#else + PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); +#endif + aSerial->print(F(", ")); + + /* + * Print number of bits processed + */ + aSerial->print(decodedIRData.numberOfBits); + aSerial->print(F(" bits,")); + + if (tFlags & IRDATA_FLAGS_IS_MSB_FIRST) { + aSerial->print(F(" MSB first")); + } else { + aSerial->print(F(" LSB first")); + } + } + + /* + * Print gap and duration, in order to be able to compute the repeat period of the protocol by adding the next gap time + */ + if (tFlags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) { + aSerial->print(F(", ")); + if (tFlags & IRDATA_FLAGS_IS_AUTO_REPEAT) { + aSerial->print(F("Auto-")); + } + aSerial->print(F("Repeat")); + } +#if !defined(DISABLE_CODE_FOR_RECEIVER) + aSerial->print(F(", Gap=")); + aSerial->print((uint32_t) decodedIRData.initialGapTicks * MICROS_PER_TICK); + aSerial->print(F("us")); + + /* + * Print complete duration of IR frame + */ + uint16_t tSumOfDurationTicks = 0; + for (IRRawlenType i = 1; i < decodedIRData.rawlen; i++) { + tSumOfDurationTicks += irparams.rawbuf[i]; + } + aSerial->print(F(", Duration=")); + aSerial->print((uint32_t) tSumOfDurationTicks * MICROS_PER_TICK); + aSerial->println(F("us")); +#else + aSerial->println(); +#endif + } + } + // call no class function with same name - ::printIRResultShort(aSerial, &decodedIRData, aPrintRepeatGap); if (aCheckForRecordGapsMicros && decodedIRData.protocol != UNKNOWN) { return checkForRecordGapsMicros(aSerial); } return false; } +/* + * Only used in example ReceiveAndSend.cpp + */ +void printIRDataShort(Print *aSerial, IRData *aIRDataPtr) { + + aSerial->print(F("Protocol=")); + aSerial->print(getProtocolString(aIRDataPtr->protocol)); +#if defined(DECODE_DISTANCE_WIDTH) + if (aIRDataPtr->protocol != PULSE_DISTANCE && aIRDataPtr->protocol != PULSE_WIDTH) { +#endif + /* + * New decoders have address and command + */ + aSerial->print(F(" Address=0x")); + aSerial->print(aIRDataPtr->address, HEX); + + aSerial->print(F(" Command=0x")); + aSerial->print(aIRDataPtr->command, HEX); + +#if defined(DECODE_DISTANCE_WIDTH) + } +#endif + + /* + * Print number of bits + */ + aSerial->print(' '); + aSerial->print(aIRDataPtr->numberOfBits, DEC); + aSerial->print(F(" bits")); + + if (aIRDataPtr->flags & IRDATA_FLAGS_IS_MSB_FIRST) { + aSerial->print(F(" MSB first")); + } else { + aSerial->print(F(" LSB first")); + } + + /* + * Print gap and duration, in order to be able to compute the repeat period of the protocol by adding the next gap time + */ + if (aIRDataPtr->flags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) { + aSerial->print(' '); + if (aIRDataPtr->flags & IRDATA_FLAGS_IS_AUTO_REPEAT) { + aSerial->print(F("Auto-")); + } + aSerial->print(F("Repeat")); + } + aSerial->println(); +} + +/** + * Deprecated static function to be able to print data to send or copied received data. + * Ends with println(). + * + * @param aSerial The Print object on which to write, for Arduino you can use &Serial. + * @param aIRDataPtr Pointer to the data to be printed. + * @param aPrintRepeatGap If true also print the gap before repeats. + * + */ +void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintRepeatGap) { + // DEPRECATED + + (void) aPrintRepeatGap; + printIRDataShort(aSerial, aIRDataPtr); +} +void printIRResultShort(Print *aSerial, IRData *aIRDataPtr) { + // DEPRECATED + + if (aIRDataPtr->flags & IRDATA_FLAGS_WAS_OVERFLOW) { + aSerial->println(F("Overflow")); + return; + } + aSerial->print(F("Protocol=")); + aSerial->print(getProtocolString(aIRDataPtr->protocol)); + if (aIRDataPtr->protocol == UNKNOWN) { +#if defined(DECODE_HASH) + aSerial->print(F(" Hash=0x")); +#if (__INT_WIDTH__ < 32) + aSerial->print(aIRDataPtr->decodedRawData, HEX); +#else + PrintULL::print(aSerial,aIRDataPtr->decodedRawData, HEX); +#endif + +#endif +#if !defined(DISABLE_CODE_FOR_RECEIVER) + aSerial->print(' '); + aSerial->print((aIRDataPtr->rawlen + 1) / 2, DEC); + aSerial->println(F(" bits (incl. gap and start) received")); +#endif + } else { +#if defined(DECODE_DISTANCE_WIDTH) + if (aIRDataPtr->protocol != PULSE_DISTANCE && aIRDataPtr->protocol != PULSE_WIDTH) { +#endif + /* + * New decoders have address and command + */ + aSerial->print(F(" Address=0x")); + aSerial->print(aIRDataPtr->address, HEX); + + aSerial->print(F(" Command=0x")); + aSerial->print(aIRDataPtr->command, HEX); + + if (aIRDataPtr->flags & IRDATA_FLAGS_EXTRA_INFO) { + aSerial->print(F(" Extra=0x")); + aSerial->print(aIRDataPtr->extra, HEX); + } + + if (aIRDataPtr->flags & IRDATA_FLAGS_PARITY_FAILED) { + aSerial->print(F(" Parity fail")); + } + + if (aIRDataPtr->flags & IRDATA_FLAGS_TOGGLE_BIT) { + aSerial->print(F(" Toggle=1")); + } +#if defined(DECODE_DISTANCE_WIDTH) + } +#endif + + /* + * Print raw data + */ + if (!(aIRDataPtr->flags & IRDATA_FLAGS_IS_REPEAT) || aIRDataPtr->decodedRawData != 0) { + aSerial->print(F(" Raw-Data=0x")); +#if (__INT_WIDTH__ < 32) + aSerial->print(aIRDataPtr->decodedRawData, HEX); +#else + PrintULL::print(aSerial, aIRDataPtr->decodedRawData, HEX); +#endif + /* + * Print number of bits processed + */ + aSerial->print(' '); + aSerial->print(aIRDataPtr->numberOfBits, DEC); + aSerial->print(F(" bits")); + + if (aIRDataPtr->flags & IRDATA_FLAGS_IS_MSB_FIRST) { + aSerial->print(F(" MSB first")); + } else { + aSerial->print(F(" LSB first")); + } + } + + /* + * Print gap and duration, in order to be able to compute the repeat period of the protocol by adding the next gap time + */ + if (aIRDataPtr->flags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) { + aSerial->print(' '); + if (aIRDataPtr->flags & IRDATA_FLAGS_IS_AUTO_REPEAT) { + aSerial->print(F("Auto-")); + } + aSerial->print(F("Repeat")); + } +#if !defined(DISABLE_CODE_FOR_RECEIVER) + aSerial->print(F(" Gap=")); + aSerial->print((uint32_t) aIRDataPtr->initialGapTicks * MICROS_PER_TICK); + aSerial->println(F("us")); +#else + aSerial->println(); +#endif + } +} + void IRrecv::printDistanceWidthTimingInfo(Print *aSerial, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo) { aSerial->print(aDistanceWidthTimingInfo->HeaderMarkMicros); aSerial->print(F(", ")); @@ -1237,42 +1905,106 @@ void IRrecv::printDistanceWidthTimingInfo(Print *aSerial, DistanceWidthTimingInf aSerial->print(aDistanceWidthTimingInfo->ZeroSpaceMicros); } +/* + * Get maximum of mark ticks in rawDataPtr. + * Skip leading start and trailing stop bit. + */ +uint8_t IRrecv::getMaximumMarkTicksFromRawData() { + uint8_t tMaximumTick = 0; + for (IRRawlenType i = 3; i < decodedIRData.rawlen - 2; i += 2) { // Skip leading start and trailing stop bit. + auto tTick = irparams.rawbuf[i]; + if (tMaximumTick < tTick) { + tMaximumTick = tTick; + } + } + return tMaximumTick; +} +uint8_t IRrecv::getMaximumSpaceTicksFromRawData() { + uint8_t tMaximumTick = 0; + for (IRRawlenType i = 4; i < decodedIRData.rawlen - 2; i += 2) { // Skip leading start and trailing stop bit. + auto tTick = irparams.rawbuf[i]; + if (tMaximumTick < tTick) { + tMaximumTick = tTick; + } + } + return tMaximumTick; +} + +/* + * The optimizing compiler internally generates this function, if getMaximumMarkTicksFromRawData() and getMaximumSpaceTicksFromRawData() is used. + */ +uint8_t IRrecv::getMaximumTicksFromRawData(bool aSearchSpaceInsteadOfMark) { + uint8_t tMaximumTick = 0; + IRRawlenType i; + if (aSearchSpaceInsteadOfMark) { + i = 4; + } else { + i = 3; + } + for (; i < decodedIRData.rawlen - 2; i += 2) { // Skip leading start and trailing stop bit. + auto tTick = irparams.rawbuf[i]; + if (tMaximumTick < tTick) { + tMaximumTick = tTick; + } + } + return tMaximumTick; +} + uint32_t IRrecv::getTotalDurationOfRawData() { uint16_t tSumOfDurationTicks = 0; - for (uint_fast8_t i = 1; i < decodedIRData.rawDataPtr->rawlen; i++) { - tSumOfDurationTicks += decodedIRData.rawDataPtr->rawbuf[i]; + + for (IRRawlenType i = 1; i < decodedIRData.rawlen; i++) { + tSumOfDurationTicks += irparams.rawbuf[i]; } - return tSumOfDurationTicks * (uint32_t) MICROS_PER_TICK; + return (uint32_t) tSumOfDurationTicks * MICROS_PER_TICK; +} + +// @formatter:off + +void printNumberOfRepeats(Print *aSerial) { + aSerial->print(F(", ")); } /** * Function to print values and flags of IrReceiver.decodedIRData in one line. + * do not print for repeats except IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT. * Ends with println(). + * !!!Attention: The result differs on a 8 bit or 32 bit platform!!! * * @param aSerial The Print object on which to write, for Arduino you can use &Serial. */ void IRrecv::printIRSendUsage(Print *aSerial) { - if (decodedIRData.protocol != UNKNOWN - && (decodedIRData.flags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) == 0x00) { + if (((decodedIRData.flags & (IRDATA_FLAGS_IS_AUTO_REPEAT | IRDATA_FLAGS_IS_REPEAT)) == 0x00 + || (decodedIRData.flags & IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT))) { + + /* + * Generating the string: + * Send on a 8 bit platform with: + * uint32_t tRawData[]={0x87654321, 0xAFEDCBA9, 0x5A}; + * IrSender.send + * or + * Send on a 8 bit platform with: IrSender.send + * or + * Send with: IrSender.send + */ #if defined(DECODE_DISTANCE_WIDTH) - aSerial->print(F("Send with:")); uint_fast8_t tNumberOfArrayData = 0; if (decodedIRData.protocol == PULSE_DISTANCE || decodedIRData.protocol == PULSE_WIDTH) { # if __INT_WIDTH__ < 32 + aSerial->print(F("Send on a 8 bit platform with: ")); tNumberOfArrayData = ((decodedIRData.numberOfBits - 1) / 32) + 1; if(tNumberOfArrayData > 1) { aSerial->println(); - aSerial->print(F(" uint32_t tRawData[]={0x")); + aSerial->print(F(" uint32_t tRawData[]={0x")); + for (uint_fast8_t i = 0; i < tNumberOfArrayData; ++i) { + aSerial->print(decodedIRData.decodedRawDataArray[i], HEX); # else + aSerial->print(F("Send on a 32 bit platform with: ")); tNumberOfArrayData = ((decodedIRData.numberOfBits - 1) / 64) + 1; if(tNumberOfArrayData > 1) { aSerial->println(); - aSerial->print(F(" uint64_t tRawData[]={0x")); -# endif + aSerial->print(F(" uint64_t tRawData[]={0x")); for (uint_fast8_t i = 0; i < tNumberOfArrayData; ++i) { -# if (__INT_WIDTH__ < 32) - aSerial->print(decodedIRData.decodedRawDataArray[i], HEX); -# else PrintULL::print(aSerial, decodedIRData.decodedRawDataArray[i], HEX); # endif if (i != tNumberOfArrayData - 1) { @@ -1280,55 +2012,49 @@ void IRrecv::printIRSendUsage(Print *aSerial) { } } aSerial->println(F("};")); - aSerial->print(F(" ")); + aSerial->print(F(" ")); } + } else { // if (decodedIRData.protocol == PULSE_DISTANCE || decodedIRData.protocol == PULSE_WIDTH) + aSerial->print(F("Send with: ")); + } + if (decodedIRData.protocol == UNKNOWN){ + aSerial->println(); + aSerial->print(F(" ")); + printIRResultAsCArray(aSerial); + aSerial->print(F(" ")); } - aSerial->print(F(" IrSender.send")); + aSerial->print(F("IrSender.send")); + #else aSerial->print(F("Send with: IrSender.send")); -#endif +#endif // #if defined(DECODE_DISTANCE_WIDTH) -#if defined(DECODE_DISTANCE_WIDTH) - if (decodedIRData.protocol != PULSE_DISTANCE && decodedIRData.protocol != PULSE_WIDTH) { -#endif - aSerial->print(getProtocolString()); - aSerial->print(F("(0x")); -#if defined(DECODE_MAGIQUEST) - if (decodedIRData.protocol == MAGIQUEST) { -# if (__INT_WIDTH__ < 32) - aSerial->print(decodedIRData.decodedRawData, HEX); -# else - PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); -# endif - } else { - aSerial->print(decodedIRData.address, HEX); - } -#else /* - * New decoders have address and command + * Generating the string: + * Raw(rawIRTimings, sizeof(rawIRTimings) / sizeof(rawIRTimings[0]), 38, , + * or + * PulseDistanceWidth(38, 550, 1250, 500, 1250, 1300, 400, 0x3D9EAC, 23, PROTOCOL_IS_LSB_FIRST, , ); + * or + * PulseDistanceWidthFromArray(38, 8900, 4350, 600, 1650, 600, 550, &tRawData[0], 72, PROTOCOL_IS_LSB_FIRST, , ); + * or + * (0x
, 0x, ); + * or + * FAST(0x, ); */ - aSerial->print(decodedIRData.address, HEX); -#endif - - aSerial->print(F(", 0x")); - aSerial->print(decodedIRData.command, HEX); - if (decodedIRData.protocol == SONY) { - aSerial->print(F(", 2, ")); - aSerial->print(decodedIRData.numberOfBits); - } else { - aSerial->print(F(", ")); + if (decodedIRData.protocol == UNKNOWN){ + aSerial->print(F("Raw(rawIRTimings, sizeof(rawIRTimings) / sizeof(rawIRTimings[0]), 38, ")); + printNumberOfRepeats(aSerial); } - #if defined(DECODE_DISTANCE_WIDTH) - } else { + else if (decodedIRData.protocol == PULSE_DISTANCE || decodedIRData.protocol == PULSE_WIDTH) { /* * Pulse distance or pulse width here */ - aSerial->print("PulseDistanceWidth"); + aSerial->print(F("PulseDistanceWidth")); if(tNumberOfArrayData > 1) { - aSerial->print("FromArray(38, "); + aSerial->print(F("FromArray(38, ")); } else { - aSerial->print("(38, "); + aSerial->print(F("(38, ")); } printDistanceWidthTimingInfo(aSerial, &decodedIRData.DistanceWidthTimingInfo); @@ -1343,7 +2069,7 @@ void IRrecv::printIRSendUsage(Print *aSerial) { # endif aSerial->print(F(", ")); } - aSerial->print(decodedIRData.numberOfBits);// aNumberOfBits + aSerial->print(decodedIRData.numberOfBits); // aNumberOfBits aSerial->print(F(", PROTOCOL_IS_")); if (decodedIRData.flags & IRDATA_FLAGS_IS_MSB_FIRST) { @@ -1351,11 +2077,57 @@ void IRrecv::printIRSendUsage(Print *aSerial) { } else { aSerial->print('L'); } - aSerial->print(F("SB_FIRST, , ")); + aSerial->print(F("SB_FIRST, ")); + printNumberOfRepeats(aSerial); + } +#endif // defined(DECODE_DISTANCE_WIDTH) + else { + /* + * Regular protocols here + */ + aSerial->print(getProtocolString()); + aSerial->print(F("(0x")); +#if defined(DECODE_MAGIQUEST) + if (decodedIRData.protocol == MAGIQUEST) { +# if (__INT_WIDTH__ < 32) + aSerial->print(decodedIRData.decodedRawData, HEX); + aSerial->print(F(", 0x")); +# else + PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); + aSerial->print(F(", 0x")); +# endif + } else { +# if defined(DECODE_FAST) + // do not print address parameter for FAST protocol + if (decodedIRData.protocol != FAST) { + aSerial->print(decodedIRData.address, HEX); + aSerial->print(F(", 0x")); + } +# else + aSerial->print(decodedIRData.address, HEX); + aSerial->print(F(", 0x")); +# endif + } +#else + aSerial->print(decodedIRData.address, HEX); + aSerial->print(F(", 0x")); #endif -#if defined(DECODE_PANASONIC) || defined(DECODE_KASEIKYO) - if ((decodedIRData.flags & IRDATA_FLAGS_EXTRA_INFO) && decodedIRData.protocol == KASEIKYO) { + + aSerial->print(decodedIRData.command, HEX); + if (decodedIRData.protocol == SONY) { + printNumberOfRepeats(aSerial); + aSerial->print(F(", ")); + aSerial->print(decodedIRData.numberOfBits); + } else { + printNumberOfRepeats(aSerial); + + } + } + +#if defined(DECODE_KASEIKYO) || defined(DECODE_RC6) || defined(DECODE_MARANTZ) + if ((decodedIRData.flags & IRDATA_FLAGS_EXTRA_INFO) && (decodedIRData.protocol == KASEIKYO || decodedIRData.protocol == RC6A || decodedIRData.protocol == MARANTZ)) { + // Vendor code, Customer or MarantzExtension parameter, which is after numberOfRepeats parameter aSerial->print(F(", 0x")); aSerial->print(decodedIRData.extra, HEX); } @@ -1365,6 +2137,7 @@ void IRrecv::printIRSendUsage(Print *aSerial) { } } +// @formatter:on /** * Function to print protocol number, address, command, raw data and repeat flag of IrReceiver.decodedIRData in one short line. * Does not print a Newline / does not end with println(). @@ -1376,15 +2149,15 @@ void IRrecv::printIRResultMinimal(Print *aSerial) { aSerial->print(decodedIRData.protocol); if (decodedIRData.protocol == UNKNOWN) { #if defined(DECODE_HASH) - aSerial->print(F(" #=0x")); + aSerial->print(F(" #=0x")); # if (__INT_WIDTH__ < 32) - aSerial->print(decodedIRData.decodedRawData, HEX); + aSerial->print(decodedIRData.decodedRawData, HEX); # else - PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); + PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); # endif #endif aSerial->print(' '); - aSerial->print((decodedIRData.rawDataPtr->rawlen + 1) / 2, DEC); + aSerial->print((decodedIRData.rawlen + 1) / 2); aSerial->println(F(" bits received")); } else { /* @@ -1409,18 +2182,36 @@ void IRrecv::printIRResultMinimal(Print *aSerial) { } } +/* + * Not used yet + */ +void IRrecv::printIRDuration(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks) { + uint16_t tSumOfDurationTicks = 0; + for (IRRawlenType i = 1; i < decodedIRData.rawlen; i++) { + tSumOfDurationTicks += irparams.rawbuf[i]; + } + aSerial->print(F("Duration=")); + if (aOutputMicrosecondsInsteadOfTicks) { + aSerial->print((uint32_t) tSumOfDurationTicks * MICROS_PER_TICK); + aSerial->println(F("us")); + + } else { + aSerial->print(tSumOfDurationTicks); + aSerial->println(F(" ticks")); + } +} + /** - * Dump out the timings in IrReceiver.decodedIRData.rawDataPtr->rawbuf[] array 8 values per line. + * Dump out the timings in IrReceiver.irparams.rawbuf[] array 8 values per line. * * @param aSerial The Print object on which to write, for Arduino you can use &Serial. * @param aOutputMicrosecondsInsteadOfTicks Output the (rawbuf_values * MICROS_PER_TICK) for better readability. */ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks) { - uint8_t tRawlen = decodedIRData.rawDataPtr->rawlen; // Get it once here in order to print quite consistent data, even if ISR is running // Print Raw data - aSerial->print(F("rawData[")); - aSerial->print(tRawlen, DEC); + aSerial->print(F("rawIRTimings[")); + aSerial->print(decodedIRData.rawlen); aSerial->println(F("]: ")); /* @@ -1428,37 +2219,32 @@ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsI */ aSerial->print(F(" -")); if (aOutputMicrosecondsInsteadOfTicks) { - aSerial->println((uint32_t) decodedIRData.rawDataPtr->rawbuf[0] * MICROS_PER_TICK, DEC); + aSerial->println((uint32_t) decodedIRData.initialGapTicks * MICROS_PER_TICK); } else { - aSerial->println(decodedIRData.rawDataPtr->rawbuf[0], DEC); + aSerial->println(decodedIRData.initialGapTicks); } -#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR - uint_fast8_t i; -#else - unsigned int i; -#endif // Newline is printed every 8. value, if tCounterForNewline % 8 == 0 uint_fast8_t tCounterForNewline = 6; // first newline is after the 2 values of the start bit // check if we have a protocol with no or 8 start bits #if defined(DECODE_DENON) || defined(DECODE_MAGIQUEST) - if ( + if ( # if defined(DECODE_DENON) - decodedIRData.protocol == DENON || decodedIRData.protocol == SHARP || + decodedIRData.protocol == DENON || decodedIRData.protocol == SHARP || # endif # if defined(DECODE_MAGIQUEST) - decodedIRData.protocol == MAGIQUEST || + decodedIRData.protocol == MAGIQUEST || # endif - false) { - tCounterForNewline = 0; // no or 8 start bits - } + false) { + tCounterForNewline = 0; // no or 8 start bits + } #endif uint32_t tDuration; uint16_t tSumOfDurationTicks = 0; - for (i = 1; i < tRawlen; i++) { - auto tCurrentTicks = decodedIRData.rawDataPtr->rawbuf[i]; + for (IRRawlenType i = 1; i < decodedIRData.rawlen; i++) { + auto tCurrentTicks = irparams.rawbuf[i]; if (aOutputMicrosecondsInsteadOfTicks) { tDuration = tCurrentTicks * MICROS_PER_TICK; } else { @@ -1482,9 +2268,9 @@ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsI if (tDuration < 10) { aSerial->print(' '); } - aSerial->print(tDuration, DEC); + aSerial->print(tDuration); - if ((i & 1) && (i + 1) < tRawlen) { + if ((i & 1) && (i + 1) < decodedIRData.rawlen) { aSerial->print(','); //',' not required for last one } @@ -1495,50 +2281,55 @@ void IRrecv::printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsI } aSerial->println(); - aSerial->print("Sum: "); + aSerial->print(F("Duration=")); if (aOutputMicrosecondsInsteadOfTicks) { - aSerial->println((uint32_t) tSumOfDurationTicks * MICROS_PER_TICK, DEC); + aSerial->print((uint32_t) tSumOfDurationTicks * MICROS_PER_TICK); + aSerial->println(F("us")); + } else { - aSerial->println(tSumOfDurationTicks, DEC); + aSerial->print(tSumOfDurationTicks); + aSerial->println(F(" ticks")); } + aSerial->println(); } /** - * Dump out the IrReceiver.decodedIRData.rawDataPtr->rawbuf[] to be used as C definition for sendRaw(). + * Dump out the IrReceiver.irparams.rawbuf[] to be used as C definition for sendRaw(). + * * - * Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding! * Print ticks in 8 bit format to save space. * Maximum is 255*50 microseconds = 12750 microseconds = 12.75 ms, which hardly ever occurs inside an IR sequence. * Recording of IRremote anyway stops at a gap of RECORD_GAP_MICROS (5 ms). * - * @param aSerial The Print object on which to write, for Arduino you can use &Serial. - * @param aOutputMicrosecondsInsteadOfTicks Output the (rawbuf_values * MICROS_PER_TICK) for better readability. + * @param aSerial The Print object on which to write, for Arduino you can use &Serial. + * @param aOutputMicrosecondsInsteadOfTicks Output the (rawbuf_values * MICROS_PER_TICK) for better readability. + * @param aDoCompensate Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding! */ void IRrecv::compensateAndPrintIRResultAsCArray(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks) { + printIRResultAsCArray(aSerial, aOutputMicrosecondsInsteadOfTicks, true); +} +void IRrecv::printIRResultAsCArray(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks, bool aDoCompensate) { // Start declaration if (aOutputMicrosecondsInsteadOfTicks) { - aSerial->print(F("uint16_t rawData[")); // variable type, array name + aSerial->print(F("uint16_t rawIRTimings[")); // variable type, array name } else { aSerial->print(F("uint8_t rawTicks[")); // variable type, array name } - aSerial->print(decodedIRData.rawDataPtr->rawlen - 1, DEC); // array size + aSerial->print(decodedIRData.rawlen - 1); // array size aSerial->print(F("] = {")); // Start declaration // Dump data -#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR - uint_fast8_t i; -#else - unsigned int i; -#endif - for (i = 1; i < decodedIRData.rawDataPtr->rawlen; i++) { - uint32_t tDuration = decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK; + for (IRRawlenType i = 1; i < decodedIRData.rawlen; i++) { + uint32_t tDuration = irparams.rawbuf[i] * MICROS_PER_TICK; // no problem to use 50 instead of 50L here! - if (i & 1) { - // Mark - tDuration -= MARK_EXCESS_MICROS; - } else { - tDuration += MARK_EXCESS_MICROS; + if (aDoCompensate) { + if (i & 1) { + // Mark + tDuration -= MARK_EXCESS_MICROS; + } else { + tDuration += MARK_EXCESS_MICROS; + } } if (aOutputMicrosecondsInsteadOfTicks) { @@ -1551,10 +2342,8 @@ void IRrecv::compensateAndPrintIRResultAsCArray(Print *aSerial, bool aOutputMicr tTicks = (tTicks > UINT8_MAX) ? UINT8_MAX : tTicks; aSerial->print(tTicks); } - if (i + 1 < decodedIRData.rawDataPtr->rawlen) - aSerial->print(','); // ',' not required on last one - if (!(i & 1)) - aSerial->print(' '); + if (i + 1 < decodedIRData.rawlen) aSerial->print(','); // ',' not required on last one + if (!(i & 1)) aSerial->print(' '); } // End declaration @@ -1563,30 +2352,22 @@ void IRrecv::compensateAndPrintIRResultAsCArray(Print *aSerial, bool aOutputMicr // Comment aSerial->print(F(" // ")); printIRResultShort(aSerial); - -// Newline - aSerial->println(""); } /** * Store the decodedIRData to be used for sendRaw(). * - * Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding and store it in an array provided. + * Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding and store it in an array. * - * Maximum for uint8_t is 255*50 microseconds = 12750 microseconds = 12.75 ms, which hardly ever occurs inside an IR sequence. - * Recording of IRremote anyway stops at a gap of RECORD_GAP_MICROS (5 ms). + * Maximum for uint8_t is 255*50 microseconds = 12750 microseconds = 12.75 ms, which hardly ever occurs inside an IR frame. * @param aArrayPtr Address of an array provided by the caller. */ void IRrecv::compensateAndStoreIRResultInArray(uint8_t *aArrayPtr) { // Store data, skip leading space# -#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR - uint_fast8_t i; -#else - unsigned int i; -#endif - for (i = 1; i < decodedIRData.rawDataPtr->rawlen; i++) { - uint32_t tDuration = decodedIRData.rawDataPtr->rawbuf[i] * MICROS_PER_TICK; + IRRawlenType i; + for (i = 1; i < decodedIRData.rawlen; i++) { + uint32_t tDuration = irparams.rawbuf[i] * MICROS_PER_TICK; // no problem to use 50 instead of 50L here! if (i & 1) { // Mark tDuration -= MARK_EXCESS_MICROS; @@ -1602,6 +2383,9 @@ void IRrecv::compensateAndStoreIRResultInArray(uint8_t *aArrayPtr) { /** * Print results as C variables to be used for sendXXX() + * uint16_t address = 0x44; + * uint16_t command = 0x11; + * uint32_t rawData = 0x44BB11EE; * @param aSerial The Print object on which to write, for Arduino you can use &Serial. */ void IRrecv::printIRResultAsCVariables(Print *aSerial) { @@ -1623,9 +2407,9 @@ void IRrecv::printIRResultAsCVariables(Print *aSerial) { // All protocols have raw data #if __INT_WIDTH__ < 32 - aSerial->print(F("uint32_t rawData = 0x")); + aSerial->print(F("uint32_t rawIRTimings = 0x")); #else - aSerial->print(F("uint64_t rawData = 0x")); + aSerial->print(F("uint64_t rawIRTimings = 0x")); #endif #if (__INT_WIDTH__ < 32) aSerial->print(decodedIRData.decodedRawData, HEX); @@ -1633,7 +2417,6 @@ void IRrecv::printIRResultAsCVariables(Print *aSerial) { PrintULL::print(aSerial, decodedIRData.decodedRawData, HEX); #endif aSerial->println(';'); - aSerial->println(); } } @@ -1657,28 +2440,22 @@ const char* IRrecv::getProtocolString() { * aResults->decode_type **********************************************************************************************************************/ bool IRrecv::decode_old(decode_results *aResults) { - static bool sDeprecationMessageSent = false; if (irparams.StateForISR != IR_REC_STATE_STOP) { return false; } - if (!sDeprecationMessageSent) { -#if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)) -// Serial.println( -// "The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData. ."); -#endif - sDeprecationMessageSent = true; - } - // copy for usage by legacy programs - aResults->rawbuf = irparams.rawbuf; + aResults->rawbuf[0] = irparams.initialGapTicks; + for (int i = 1; i < RAW_BUFFER_LENGTH; ++i) { + aResults->rawbuf[i] = irparams.rawbuf[i]; // copy 8 bit array into a 16 bit array + } aResults->rawlen = irparams.rawlen; if (irparams.OverflowFlag) { // Copy overflow flag to decodedIRData.flags irparams.OverflowFlag = false; irparams.rawlen = 0; // otherwise we have OverflowFlag again at next ISR call - IR_DEBUG_PRINTLN(F("Overflow happened")); + DEBUG_PRINTLN(F("Overflow happened")); } aResults->overflow = irparams.OverflowFlag; aResults->value = 0; @@ -1686,66 +2463,66 @@ bool IRrecv::decode_old(decode_results *aResults) { decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; // for print #if defined(DECODE_NEC) - IR_DEBUG_PRINTLN(F("Attempting old NEC decode")); - if (decodeNECMSB(aResults)) { - return true; - } + DEBUG_PRINTLN(F("Attempting old NEC decode")); + if (decodeNECMSB(aResults)) { + return true; + } #endif #if defined(DECODE_SONY) - IR_DEBUG_PRINTLN(F("Attempting old Sony decode")); - if (decodeSonyMSB(aResults)) { - return true; - } + DEBUG_PRINTLN(F("Attempting old Sony decode")); + if (decodeSonyMSB(aResults)) { + return true; + } #endif #if defined(DECODE_RC5) - IR_DEBUG_PRINTLN(F("Attempting RC5 decode")); - if (decodeRC5()) { - aResults->bits = decodedIRData.numberOfBits; - aResults->value = decodedIRData.decodedRawData; - aResults->decode_type = RC5; + DEBUG_PRINTLN(F("Attempting RC5 decode")); + if (decodeRC5()) { + aResults->bits = decodedIRData.numberOfBits; + aResults->value = decodedIRData.decodedRawData; + aResults->decode_type = RC5; - return true; - } + return true; + } #endif #if defined(DECODE_RC6) - IR_DEBUG_PRINTLN(F("Attempting RC6 decode")); - if (decodeRC6()) { - aResults->bits = decodedIRData.numberOfBits; - aResults->value = decodedIRData.decodedRawData; - aResults->decode_type = RC6; - return true; - } + DEBUG_PRINTLN(F("Attempting RC6 decode")); + if (decodeRC6()) { + aResults->bits = decodedIRData.numberOfBits; + aResults->value = decodedIRData.decodedRawData; + aResults->decode_type = RC6; + return true; + } #endif // Removed bool IRrecv::decodePanasonicMSB(decode_results *aResults) since implementations was wrong (wrong length), and nobody recognized it #if defined(DECODE_LG) - IR_DEBUG_PRINTLN(F("Attempting old LG decode")); - if (decodeLGMSB(aResults)) {return true;} + DEBUG_PRINTLN(F("Attempting old LG decode")); + if (decodeLGMSB(aResults)) {return true;} #endif #if defined(DECODE_JVC) - IR_DEBUG_PRINTLN(F("Attempting old JVC decode")); - if (decodeJVCMSB(aResults)) { - return true; - } + DEBUG_PRINTLN(F("Attempting old JVC decode")); + if (decodeJVCMSB(aResults)) { + return true; + } #endif #if defined(DECODE_SAMSUNG) - IR_DEBUG_PRINTLN(F("Attempting old SAMSUNG decode")); - if (decodeSAMSUNG(aResults)) { - return true; - } + DEBUG_PRINTLN(F("Attempting old SAMSUNG decode")); + if (decodeSAMSUNG(aResults)) { + return true; + } #endif #if defined(DECODE_DENON) - IR_DEBUG_PRINTLN(F("Attempting old Denon decode")); - if (decodeDenonOld(aResults)) { - return true; - } + DEBUG_PRINTLN(F("Attempting old Denon decode")); + if (decodeDenonOld(aResults)) { + return true; + } #endif // decodeHash returns a hash on any input. @@ -1763,10 +2540,6 @@ bool IRrecv::decode_old(decode_results *aResults) { #if defined(_IR_MEASURE_TIMING) #undef _IR_MEASURE_TIMING #endif -#if defined(LOCAL_TRACE) -#undef LOCAL_TRACE -#endif -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_RECEIVE_HPP diff --git a/src/IRSend.hpp b/src/IRSend.hpp index 195a47fa1..82ae85550 100644 --- a/src/IRSend.hpp +++ b/src/IRSend.hpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2009-2023 Ken Shirriff, Rafi Khan, Armin Joachimsmeyer + * Copyright (c) 2009-2026 Ken Shirriff, 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 @@ -32,17 +32,10 @@ #ifndef _IR_SEND_HPP #define _IR_SEND_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif - -#if defined(TRACE) && !defined(LOCAL_TRACE) -#define LOCAL_TRACE -#else -//#define LOCAL_TRACE // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" /* * Low level hardware timing measurement @@ -57,6 +50,10 @@ #define sendPin IR_SEND_PIN #endif +#if !defined(NO_LED_SEND_FEEDBACK_CODE) +#define LED_SEND_FEEDBACK_CODE // Resolve the double negative +#endif + /** \addtogroup Sending Sending IR data for multiple protocols * @{ */ @@ -68,61 +65,40 @@ IRsend::IRsend() { // @suppress("Class members should be properly initialized") #if !defined(IR_SEND_PIN) sendPin = 0; #endif - -#if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(0, DO_NOT_ENABLE_LED_FEEDBACK); -#endif } +/****************************************************************************************************************** + * LED feedback is always enabled for sending. It can only be disabled by using the macro NO_LED_SEND_FEEDBACK_CODE + *****************************************************************************************************************/ #if defined(IR_SEND_PIN) /** - * Only required to set LED feedback - * Simple start with defaults - LED feedback enabled! Used if IR_SEND_PIN is defined. Saves program memory. + * Simple start with defaults. Used if IR_SEND_PIN is defined. Saves program memory. */ void IRsend::begin(){ -# if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(USE_DEFAULT_FEEDBACK_LED_PIN, LED_FEEDBACK_ENABLED_FOR_SEND); -# endif #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); #endif } /** - * Only required to set LED feedback - * @param aEnableLEDFeedback If true / ENABLE_LED_FEEDBACK, the feedback LED is activated while receiving or sending a PWM signal /a mark - * @param aFeedbackLEDPin If 0 / USE_DEFAULT_FEEDBACK_LED_PIN, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions + * Only required to set LED feedback pin + * @param aFeedbackLEDPin If USE_DEFAULT_FEEDBACK_LED_PIN / 0xFF, then take board specific LED_BUILTIN pin if it is defined as macro */ -void IRsend::begin(bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) { -#if !defined(NO_LED_FEEDBACK_CODE) - bool tEnableLEDFeedback = DO_NOT_ENABLE_LED_FEEDBACK; - if(aEnableLEDFeedback) { - tEnableLEDFeedback = LED_FEEDBACK_ENABLED_FOR_SEND; - } - setLEDFeedback(aFeedbackLEDPin, tEnableLEDFeedback); -#else - (void) aEnableLEDFeedback; - (void) aFeedbackLEDPin; -#endif +void IRsend::begin(uint_fast8_t aFeedbackLEDPin) { + setLEDFeedbackPin(aFeedbackLEDPin); } #else // defined(IR_SEND_PIN) IRsend::IRsend(uint_fast8_t aSendPin) { // @suppress("Class members should be properly initialized") sendPin = aSendPin; -# if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(0, DO_NOT_ENABLE_LED_FEEDBACK); -# endif } /** - * Initializes the send pin and enable LED feedback with board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions + * Initializes the send pin and enable LED feedback with board specific LED_BUILTIN pin if it is defined as macro * @param aSendPin The Arduino pin number, where a IR sender diode is connected. */ void IRsend::begin(uint_fast8_t aSendPin) { sendPin = aSendPin; -# if !defined(NO_LED_FEEDBACK_CODE) - setLEDFeedback(USE_DEFAULT_FEEDBACK_LED_PIN, LED_FEEDBACK_ENABLED_FOR_SEND); -# endif } void IRsend::setSendPin(uint_fast8_t aSendPin) { @@ -132,29 +108,29 @@ void IRsend::setSendPin(uint_fast8_t aSendPin) { /** * Initializes the send and feedback pin * @param aSendPin The Arduino pin number, where a IR sender diode is connected. - * @param aEnableLEDFeedback If true the feedback LED is activated while receiving or sending a PWM signal /a mark - * @param aFeedbackLEDPin If 0 / USE_DEFAULT_FEEDBACK_LED_PIN, then take board specific FEEDBACK_LED_ON() and FEEDBACK_LED_OFF() functions + * @param aFeedbackLEDPin If 0xFF, then take board specific LED_BUILTIN pin if it is defined as macro */ -void IRsend::begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) { +void IRsend::begin(uint_fast8_t aSendPin, uint_fast8_t aFeedbackLEDPin) { #if defined(IR_SEND_PIN) (void) aSendPin; // for backwards compatibility #else sendPin = aSendPin; #endif -#if !defined(NO_LED_FEEDBACK_CODE) - bool tEnableLEDFeedback = DO_NOT_ENABLE_LED_FEEDBACK; - if (aEnableLEDFeedback) { - tEnableLEDFeedback = LED_FEEDBACK_ENABLED_FOR_SEND; - } - setLEDFeedback(aFeedbackLEDPin, tEnableLEDFeedback); +#if defined(LED_SEND_FEEDBACK_CODE) + setLEDFeedbackPin(aFeedbackLEDPin); #else - (void) aEnableLEDFeedback; (void) aFeedbackLEDPin; #endif } #endif // defined(IR_SEND_PIN) +// Deprecated +void IRsend::begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) { + (void) aEnableLEDFeedback; + begin(aSendPin, aFeedbackLEDPin); +} + /** * Interprets and sends a IRData structure. * @param aIRSendData The values of protocol, address, command and repeat flag are taken for sending. @@ -220,7 +196,7 @@ size_t IRsend::write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats) { } else if (tProtocol == SAMSUNG48) { sendSamsung48(tAddress, tCommand, aNumberOfRepeats); - } else if (tProtocol == SAMSUNG_LG) { + } else if (tProtocol == SAMSUNGLG) { sendSamsungLG(tAddress, tCommand, aNumberOfRepeats); } else if (tProtocol == SONY) { @@ -247,6 +223,9 @@ size_t IRsend::write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats) { } else if (tProtocol == RC6) { sendRC6(tAddress, tCommand, aNumberOfRepeats, !tIsRepeat); // No toggle for repeats + } else if (tProtocol == RC6A) { + sendRC6A(tAddress, tCommand, aNumberOfRepeats, aIRSendData->extra, !tIsRepeat); + } else if (tProtocol == KASEIKYO_JVC) { sendKaseikyo_JVC(tAddress, tCommand, aNumberOfRepeats); @@ -282,6 +261,9 @@ size_t IRsend::write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats) { } else if (tProtocol == LEGO_PF) { sendLegoPowerFunctions(tAddress, tCommand, tCommand >> 4, tIsRepeat); // send 5 autorepeats + + } else if (tProtocol == OPENLASIR) { + sendOpenLASIR(tAddress, tCommand, aNumberOfRepeats); #endif } else { @@ -291,7 +273,7 @@ size_t IRsend::write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats) { } /** - * Simple version of write without support for MAGIQUEST and numberOfBits for SONY protocol + * Simple version of write without support for RC6A, MAGIQUEST and numberOfBits for SONY protocol * @param aNumberOfRepeats If aNumberOfRepeats < 0 then only a special repeat frame without leading and trailing space * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). */ @@ -341,7 +323,7 @@ size_t IRsend::write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aComma } else if (aProtocol == SAMSUNG48) { sendSamsung48(aAddress, aCommand, aNumberOfRepeats); - } else if (aProtocol == SAMSUNG_LG) { + } else if (aProtocol == SAMSUNGLG) { sendSamsungLG(aAddress, aCommand, aNumberOfRepeats); } else if (aProtocol == SONY) { @@ -399,6 +381,9 @@ size_t IRsend::write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aComma } else if (aProtocol == LEGO_PF) { sendLegoPowerFunctions(aAddress, aCommand, aCommand >> 4, (aNumberOfRepeats < 0)); // send 5 autorepeats, except for dedicated repeats + + } else if (aProtocol == OPENLASIR) { + sendOpenLASIR(aAddress, aCommand, aNumberOfRepeats); #endif } else { @@ -407,14 +392,24 @@ size_t IRsend::write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aComma return 1; } +/********************************************************************************************************************** + * SendRaw functions + **********************************************************************************************************************/ + /** - * Function using an 16 byte microsecond timing array for every purpose. + * Sends a 16 byte microsecond timing array. * Raw data starts with a Mark. No leading space as in received timing data! */ void IRsend::sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) { // Set IR carrier frequency enableIROut(aIRFrequencyKilohertz); + DEBUG_PRINT(F("aPGMBufferWithMicroseconds=0x")); + DEBUG_PRINT((uint32_t) aBufferWithMicroseconds, HEX); + DEBUG_PRINT(F(" [0]=")); + DEBUG_PRINTLN(aBufferWithMicroseconds[0]); // this crashes on ESP8266 if aBufferWithMicroseconds is PROGMEM + DEBUG_FLUSH(); + /* * Raw data starts with a mark. */ @@ -427,9 +422,35 @@ void IRsend::sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLe } } } +/* + * Version with repeat + * @param aRepeatPeriodMillis - Time between start of two frames. Thus independent from frame length. + */ +void IRsend::sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + sendRaw(aBufferWithMicroseconds, aLengthOfBuffer, aIRFrequencyKilohertz); + + tNumberOfCommands--; + + // skip last delay! + if (tNumberOfCommands > 0) { + auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis; + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + if (aRepeatPeriodMillis > tCurrentFrameDurationMillis) { + delay(aRepeatPeriodMillis - tCurrentFrameDurationMillis); + } + } + } +} /** - * Function using an 8 byte tick timing array to save program memory + * Sends an 8 byte tick timing array to save program memory. * Raw data starts with a Mark. No leading space as in received timing data! */ void IRsend::sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) { @@ -444,99 +465,290 @@ void IRsend::sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBu mark(aBufferWithTicks[i] * MICROS_PER_TICK); } } - IRLedOff(); // Always end with the LED off +} +void IRsend::sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + sendRaw(aBufferWithTicks, aLengthOfBuffer, aIRFrequencyKilohertz); + + tNumberOfCommands--; + + // skip last delay! + if (tNumberOfCommands > 0) { + auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis; + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + if (aRepeatPeriodMillis > tCurrentFrameDurationMillis) { + delay(aRepeatPeriodMillis - tCurrentFrameDurationMillis); + } + } + } } /** * Function using an 16 byte microsecond timing array in FLASH for every purpose. * Raw data starts with a Mark. No leading space as in received timing data! */ -void IRsend::sendRaw_P(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, +void IRsend::sendRaw_P(const uint16_t aPGMBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) { #if !defined(__AVR__) - sendRaw(aBufferWithMicroseconds, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms + sendRaw(aPGMBufferWithMicroseconds, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms #else // Set IR carrier frequency enableIROut(aIRFrequencyKilohertz); /* * Raw data starts with a mark */ + // If the PROGMEM array is defined in the function, the C-compiler uses a wrong address :-(. sizeof() works. + DEBUG_PRINT(F("aPGMBufferWithMicroseconds=0x")); + DEBUG_PRINTLN((uint16_t) aPGMBufferWithMicroseconds, HEX); + for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) { - auto duration = pgm_read_word(&aBufferWithMicroseconds[i]); + uint16_t duration = pgm_read_word(&aPGMBufferWithMicroseconds[i]); +// uint16_t duration = pgm_read_word(aPGMBufferWithMicroseconds); // is equivalent for the compiler if (i & 1) { // Odd space(duration); + DEBUG_PRINT(F("S=")); } else { mark(duration); + DEBUG_PRINT(F("M=")); } + DEBUG_PRINTLN(duration); } #endif } +void IRsend::sendRaw_P(const uint16_t aPGMBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, + uint_fast8_t aIRFrequencyKilohertz, uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { + + DEBUG_PRINT(F("aPGMBufferWithMicroseconds=0x")); + DEBUG_PRINT((uint32_t) aPGMBufferWithMicroseconds, HEX); + DEBUG_PRINT(F(" [0]=")); + DEBUG_PRINTLN(aPGMBufferWithMicroseconds[0]); // this crashes on ESP8266 + DEBUG_FLUSH(); + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + sendRaw_P(aPGMBufferWithMicroseconds, aLengthOfBuffer, aIRFrequencyKilohertz); + + tNumberOfCommands--; + + // skip last delay! + if (tNumberOfCommands > 0) { + auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis; + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + if (aRepeatPeriodMillis > tCurrentFrameDurationMillis) { + delay(aRepeatPeriodMillis - tCurrentFrameDurationMillis); + } + } + } +} + /** - * New function using an 8 byte tick timing array in FLASH to save program memory + * New function using an 8 byte tick (50 us) timing array in FLASH to save program memory * Raw data starts with a Mark. No leading space as in received timing data! */ -void IRsend::sendRaw_P(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) { +void IRsend::sendRaw_P(const uint8_t aPGMBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz) { #if !defined(__AVR__) - sendRaw(aBufferWithTicks, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms + sendRaw(aPGMBufferWithTicks, aLengthOfBuffer, aIRFrequencyKilohertz); // Let the function work for non AVR platforms #else // Set IR carrier frequency enableIROut(aIRFrequencyKilohertz); for (uint_fast16_t i = 0; i < aLengthOfBuffer; i++) { - uint_fast16_t duration = pgm_read_byte(&aBufferWithTicks[i]) * (uint_fast16_t) MICROS_PER_TICK; + uint16_t duration = pgm_read_byte(&aPGMBufferWithTicks[i]) * MICROS_PER_TICK; if (i & 1) { // Odd space(duration); + DEBUG_PRINT(F("S=")); } else { mark(duration); + DEBUG_PRINT(F("M=")); } + DEBUG_PRINTLN(duration); } - IRLedOff(); // Always end with the LED off #endif } +void IRsend::sendRaw_P(const uint8_t aPGMBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + sendRaw_P(aPGMBufferWithTicks, aLengthOfBuffer, aIRFrequencyKilohertz); + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis; + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + if (aRepeatPeriodMillis > tCurrentFrameDurationMillis) { + delay(aRepeatPeriodMillis - tCurrentFrameDurationMillis); + } + } + } +} + +/********************************************************************************************************************** + * Core send function + **********************************************************************************************************************/ /** - * Sends PulseDistance data from array - * For LSB First the LSB of array[0] is sent first then all bits until MSB of array[0]. Next is LSB of array[1] and so on. + * Sends PulseDistance data with timing parameters and flag parameters. * The output always ends with a space - * Stop bit is always sent + * @param aOneMarkMicros Timing for sending this protocol. + * @param aData uint32 or uint64 holding the bits to be sent. + * @param aNumberOfBits Number of bits from aData to be actually sent. + * @param aFlags Evaluated flags are PROTOCOL_IS_MSB_FIRST and SUPPRESS_STOP_BIT. Stop bit is otherwise sent for all pulse distance protocols. */ -void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, - uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit, - uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { - uint8_t tFlags = 0; - if (aMSBFirst) { - tFlags = PROTOCOL_IS_MSB_FIRST; +void IRsend::sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, + uint16_t aZeroSpaceMicros, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags) { + + DEBUG_PRINT(aData, HEX); + DEBUG_PRINT('|'); + DEBUG_PRINTLN(aNumberOfBits); + DEBUG_FLUSH(); + + // For MSBFirst, send data from MSB to LSB until mask bit is shifted out + IRDecodedRawDataType tMask = 1ULL << (aNumberOfBits - 1); + for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { + if (((aFlags & PROTOCOL_IS_MSB_MASK) && (aData & tMask)) || (!(aFlags & PROTOCOL_IS_MSB_MASK) && (aData & 1))) { + TRACE_PRINT('1'); + mark(aOneMarkMicros); + space(aOneSpaceMicros); + } else { + TRACE_PRINT('0'); + mark(aZeroMarkMicros); + space(aZeroSpaceMicros); + } + if (aFlags & PROTOCOL_IS_MSB_MASK) { + tMask >>= 1; + } else { + aData >>= 1; + } } - (void) aSendStopBit; + /* + * Stop bit is sent for all pulse distance protocols i.e. aOneSpaceMicros != aZeroSpaceMicros. + * Therefore it is not sent for Sony :-) + * For sending from an array, no intermediate stop bit must be sent for all but last data chunk. + */ + if ((!(aFlags & SUPPRESS_STOP_BIT)) && (uintDifferenceAbs(aOneSpaceMicros, aZeroSpaceMicros) > (aOneSpaceMicros / 4))) { + // Send stop bit here + TRACE_PRINT('S'); + mark(aOneMarkMicros); // Use aOneMarkMicros for stop bits. This seems to be correct for all protocols :-) + } + TRACE_PRINTLN(); +} + +/********************************************************************************************************************** + * Stubs for core send function with PulseDistanceWidthProtocolConstants parameter + **********************************************************************************************************************/ - sendPulseDistanceWidthFromArray(aFrequencyKHz, aHeaderMarkMicros, aHeaderSpaceMicros, aOneMarkMicros, aOneSpaceMicros, - aZeroMarkMicros, aZeroSpaceMicros, aDecodedRawDataArray, aNumberOfBits, tFlags, aRepeatPeriodMillis, aNumberOfRepeats); +/** + * Sends PulseDistance from data contained in parameter using ProtocolConstants structure for timing etc. + * The output always ends with a space + * Each additional call costs 16 bytes program memory + * @param aProtocolConstants The constants to use for sending this protocol. + * @param aData uint32 or uint64 holding the bits to be sent. + * @param aNumberOfBits Number of bits from aData to be actually sent. + */ +void IRsend::sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRDecodedRawDataType aData, + uint_fast8_t aNumberOfBits) { + + sendPulseDistanceWidthData(aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aData, aNumberOfBits, aProtocolConstants->Flags); } -void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, - int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidthFromArray(aFrequencyKHz, aDistanceWidthTimingInfo->HeaderMarkMicros, - aDistanceWidthTimingInfo->HeaderSpaceMicros, aDistanceWidthTimingInfo->OneMarkMicros, - aDistanceWidthTimingInfo->OneSpaceMicros, aDistanceWidthTimingInfo->ZeroMarkMicros, - aDistanceWidthTimingInfo->ZeroSpaceMicros, aDecodedRawDataArray, aNumberOfBits, aFlags, aRepeatPeriodMillis, - aNumberOfRepeats); +void IRsend::sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits) { + + PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants; + memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM, + sizeof(tTemporaryPulseDistanceWidthProtocolConstants)); + sendPulseDistanceWidthData(&tTemporaryPulseDistanceWidthProtocolConstants, aData, aNumberOfBits); +} + +/********************************************************************************************************************** + * Send functions with detailed parameters + **********************************************************************************************************************/ + +/** + * Sends PulseDistance frames and repeats. + * @param aFrequencyKHz, aHeaderMarkMicros, aHeaderSpaceMicros, aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aFlags, aRepeatPeriodMillis Values to use for sending this protocol, also contained in the PulseDistanceWidthProtocolConstants of this protocol. + * @param aData uint32 or uint64 holding the bits to be sent. + * @param aNumberOfBits Number of bits from aData to be actually sent. + * @param aFlags Evaluated flags are PROTOCOL_IS_MSB_FIRST and SUPPRESS_STOP_BIT. Stop bit is otherwise sent for all pulse distance protocols. + * @param aNumberOfRepeats If < 0 and a aProtocolConstants->SpecialSendRepeatFunction() is specified + * then it is called without leading and trailing space. + * @param aSpecialSendRepeatFunction If nullptr, the first frame is repeated completely, otherwise this function is used for sending the repeat frame. + */ +void IRsend::sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, + uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, + IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + int_fast8_t aNumberOfRepeats, void (*aSpecialSendRepeatFunction)()) { + + if (aNumberOfRepeats < 0) { + if (aSpecialSendRepeatFunction != nullptr) { + aSpecialSendRepeatFunction(); + return; + } else { + aNumberOfRepeats = 0; // send a plain frame as repeat + } + } + + // Set IR carrier frequency + enableIROut(aFrequencyKHz); + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + + if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aSpecialSendRepeatFunction != nullptr) { + // send special repeat + aSpecialSendRepeatFunction(); + } else { + // Header and regular frame + mark(aHeaderMarkMicros); + space(aHeaderSpaceMicros); + sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aData, aNumberOfBits, + aFlags); + } + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + auto tFrameDurationMillis = millis() - tStartOfFrameMillis; + if (aRepeatPeriodMillis > tFrameDurationMillis) { + delay(aRepeatPeriodMillis - tFrameDurationMillis); + } + } + } } void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { // Set IR carrier frequency enableIROut(aFrequencyKHz); uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; - uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1; + uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_DECODED_RAW_DATA_TYPE) + 1; #if defined(LOCAL_DEBUG) // fist data @@ -569,13 +781,13 @@ void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_ tFlags = aFlags; } else { // intermediate data - tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE; - tFlags = aFlags | SUPPRESS_STOP_BIT_FOR_THIS_DATA; // No stop bit for leading data + tNumberOfBitsForOneSend = BITS_IN_DECODED_RAW_DATA_TYPE; + tFlags = aFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data } sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aDecodedRawDataArray[i], tNumberOfBitsForOneSend, tFlags); - aNumberOfBits -= BITS_IN_RAW_DATA_TYPE; + aNumberOfBits -= BITS_IN_DECODED_RAW_DATA_TYPE; } tNumberOfCommands--; @@ -592,70 +804,61 @@ void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_ } } -/** - * Sends PulseDistance data from array using PulseDistanceWidthProtocolConstants - * For LSB First the LSB of array[0] is sent first then all bits until MSB of array[0]. Next is LSB of array[1] and so on. - * The output always ends with a space - * Stop bit is always sent - */ -void IRsend::sendPulseDistanceWidthFromArray(PulseDistanceWidthProtocolConstants *aProtocolConstants, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { +void IRsend::sendPulseDistanceWidthFromPGMArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, + uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + int_fast8_t aNumberOfRepeats) { -// Calling sendPulseDistanceWidthFromArray() costs 68 bytes program memory compared to the implementation below -// sendPulseDistanceWidthFromArray(aProtocolConstants->FrequencyKHz, aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros, -// aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros, -// aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, -// aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, -// aDecodedRawDataArray, aNumberOfBits, aProtocolConstants->Flags, aProtocolConstants->RepeatPeriodMillis, -// aNumberOfRepeats); // Set IR carrier frequency - enableIROut(aProtocolConstants->FrequencyKHz); + enableIROut(aFrequencyKHz); - uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE) + 1; + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_DECODED_RAW_DATA_TYPE) + 1; #if defined(LOCAL_DEBUG) // fist data Serial.print(F("Data[0]=0x")); - Serial.print(aDecodedRawDataArray[0], HEX); + Serial.print(aDecodedRawDataPGMArray[0], HEX); if (tNumberOf32Or64BitChunks > 1) { Serial.print(F(" Data[1]=0x")); - Serial.print(aDecodedRawDataArray[1], HEX); + Serial.print(aDecodedRawDataPGMArray[1], HEX); } Serial.print(F(" #=")); Serial.println(aNumberOfBits); Serial.flush(); #endif - uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { - auto tStartOfFrameMillis = millis(); - auto tNumberOfBits = aNumberOfBits; // refresh value for repeats + unsigned long tStartOfFrameMillis = millis(); // Header - mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros); - space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros); - uint8_t tOriginalFlags = aProtocolConstants->Flags; + mark(aHeaderMarkMicros); + space(aHeaderSpaceMicros); for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) { uint8_t tNumberOfBitsForOneSend; + // Manage stop bit uint8_t tFlags; if (i == (tNumberOf32Or64BitChunks - 1)) { // End of data - tNumberOfBitsForOneSend = tNumberOfBits; - tFlags = tOriginalFlags; + tNumberOfBitsForOneSend = aNumberOfBits; + tFlags = aFlags; } else { // intermediate data - tNumberOfBitsForOneSend = BITS_IN_RAW_DATA_TYPE; - tFlags = tOriginalFlags | SUPPRESS_STOP_BIT_FOR_THIS_DATA; // No stop bit for leading data + tNumberOfBitsForOneSend = BITS_IN_DECODED_RAW_DATA_TYPE; + tFlags = aFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data } - sendPulseDistanceWidthData(aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, - aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, - aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, - aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aDecodedRawDataArray[i], tNumberOfBitsForOneSend, - tFlags); - tNumberOfBits -= BITS_IN_RAW_DATA_TYPE; + IRDecodedRawDataType tDecodedRawData; +#if (__INT_WIDTH__ < 32) + tDecodedRawData = pgm_read_dword(&aDecodedRawDataPGMArray[i]); // pgm_read_dword reads 32 bit on AVR +#else + tDecodedRawData = aDecodedRawDataPGMArray[i]; // assume non Harvard architecture here +#endif + sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, tDecodedRawData, + tNumberOfBitsForOneSend, tFlags); + aNumberOfBits -= BITS_IN_DECODED_RAW_DATA_TYPE; } tNumberOfCommands--; @@ -665,38 +868,74 @@ void IRsend::sendPulseDistanceWidthFromArray(PulseDistanceWidthProtocolConstants * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. */ auto tFrameDurationMillis = millis() - tStartOfFrameMillis; - if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) { - delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis); + if (aRepeatPeriodMillis > tFrameDurationMillis) { + delay(aRepeatPeriodMillis - tFrameDurationMillis); } } } } +/********************************************************************************************************************** + * Stubs for send functions + **********************************************************************************************************************/ + +/** + * Sends PulseDistance data from array + * For LSB First the LSB of array[0] is sent first then all bits until MSB of array[0]. Next is LSB of array[1] and so on. + * The output always ends with a space + * Stop bit is always sent + * @param aFlags Evaluated flags are PROTOCOL_IS_MSB_FIRST and SUPPRESS_STOP_BIT. Stop bit is otherwise sent for all pulse distance protocols. + */ +void IRsend::sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidthFromArray(aFrequencyKHz, aDistanceWidthTimingInfo->HeaderMarkMicros, + aDistanceWidthTimingInfo->HeaderSpaceMicros, aDistanceWidthTimingInfo->OneMarkMicros, + aDistanceWidthTimingInfo->OneSpaceMicros, aDistanceWidthTimingInfo->ZeroMarkMicros, + aDistanceWidthTimingInfo->ZeroSpaceMicros, aDecodedRawDataArray, aNumberOfBits, aFlags, aRepeatPeriodMillis, + aNumberOfRepeats); +} + +void IRsend::sendPulseDistanceWidthFromArray_P(uint_fast8_t aFrequencyKHz, + DistanceWidthTimingInfoStruct const *aDistanceWidthTimingInfoPGM, IRDecodedRawDataType *aDecodedRawDataArray, + uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) { + + DistanceWidthTimingInfoStruct tTemporaryDistanceWidthTimingInfo; + memcpy_P(&tTemporaryDistanceWidthTimingInfo, aDistanceWidthTimingInfoPGM, sizeof(tTemporaryDistanceWidthTimingInfo)); + sendPulseDistanceWidthFromArray(aFrequencyKHz, &tTemporaryDistanceWidthTimingInfo, aDecodedRawDataArray, aNumberOfBits, aFlags, + aRepeatPeriodMillis, aNumberOfRepeats); +} + +/********************************************************************************************************************** + * Send functions with PulseDistanceWidthProtocolConstants parameter + **********************************************************************************************************************/ /** - * Sends PulseDistance frames and repeats and enables receiver again + * Sends PulseDistance frames and repeats * @param aProtocolConstants The constants to use for sending this protocol. * @param aData uint32 or uint64 holding the bits to be sent. * @param aNumberOfBits Number of bits from aData to be actually sent. * @param aNumberOfRepeats If < 0 and a aProtocolConstants->SpecialSendRepeatFunction() is specified * then it is called without leading and trailing space. */ -void IRsend::sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, +void IRsend::sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Data=0x")); - Serial.print(aData, HEX); - Serial.print(F(" #=")); - Serial.println(aNumberOfBits); - Serial.flush(); -#endif + DEBUG_PRINT(F("Data=0x")); + DEBUG_PRINT(aData, HEX); + DEBUG_PRINT(F(" #=")); + DEBUG_PRINTLN(aNumberOfBits); + DEBUG_FLUSH(); if (aNumberOfRepeats < 0) { - if (aProtocolConstants->SpecialSendRepeatFunction != NULL) { + if (aProtocolConstants->SpecialSendRepeatFunction != nullptr) { + /* + * Send only a special repeat and return + */ aProtocolConstants->SpecialSendRepeatFunction(); return; } else { - aNumberOfRepeats = 0; // send a plain frame as repeat + // Send only one plain frame (as repeat) + aNumberOfRepeats = 0; } } @@ -707,8 +946,8 @@ void IRsend::sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtoc while (tNumberOfCommands > 0) { unsigned long tStartOfFrameMillis = millis(); - if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aProtocolConstants->SpecialSendRepeatFunction != NULL) { - // send special repeat + if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aProtocolConstants->SpecialSendRepeatFunction != nullptr) { + // send special repeat, if specified and we are not in the first loop aProtocolConstants->SpecialSendRepeatFunction(); } else { /* @@ -720,71 +959,87 @@ void IRsend::sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtoc } tNumberOfCommands--; + // skip last delay! if (tNumberOfCommands > 0) { + auto tCurrentFrameDurationMillis = millis() - tStartOfFrameMillis; /* * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. */ - auto tFrameDurationMillis = millis() - tStartOfFrameMillis; - if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) { - delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis); + if (aProtocolConstants->RepeatPeriodMillis > tCurrentFrameDurationMillis) { + delay(aProtocolConstants->RepeatPeriodMillis - tCurrentFrameDurationMillis); } } } } /** - * Sends PulseDistance frames and repeats. - * @param aFrequencyKHz, aHeaderMarkMicros, aHeaderSpaceMicros, aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aFlags, aRepeatPeriodMillis Values to use for sending this protocol, also contained in the PulseDistanceWidthProtocolConstants of this protocol. - * @param aData uint32 or uint64 holding the bits to be sent. - * @param aNumberOfBits Number of bits from aData to be actually sent. + * Sends PulseDistance data from array using PulseDistanceWidthProtocolConstants + * For LSB First the LSB of array[0] is sent first then all bits until MSB of array[0]. Next is LSB of array[1] and so on. + * The output always ends with a space + * Stop bit is always sent + * @param aNumberOfBits Number of bits from aDecodedRawDataArray to be actually sent. * @param aNumberOfRepeats If < 0 and a aProtocolConstants->SpecialSendRepeatFunction() is specified * then it is called without leading and trailing space. - * @param aSpecialSendRepeatFunction If NULL, the first frame is repeated completely, otherwise this function is used for sending the repeat frame. */ -void IRsend::sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, - uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, IRRawDataType aData, - uint_fast8_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats, - void (*aSpecialSendRepeatFunction)()) { - uint8_t tFlags = 0; - if (aMSBFirst) { - tFlags = PROTOCOL_IS_MSB_FIRST; - } - (void) aSendStopBit; - sendPulseDistanceWidth(aFrequencyKHz, aHeaderMarkMicros, aHeaderSpaceMicros, aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, - aZeroSpaceMicros, aData, aNumberOfBits, tFlags, aRepeatPeriodMillis, aNumberOfRepeats, aSpecialSendRepeatFunction); +void IRsend::sendPulseDistanceWidthFromArray(PulseDistanceWidthProtocolConstants *aProtocolConstants, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { -} -void IRsend::sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, - uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, IRRawDataType aData, - uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats, - void (*aSpecialSendRepeatFunction)()) { +// Calling sendPulseDistanceWidthFromArray() costs 68 bytes program memory compared to the implementation below +// sendPulseDistanceWidthFromArray(aProtocolConstants->FrequencyKHz, aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros, +// aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros, +// aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, +// aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, +// aDecodedRawDataArray, aNumberOfBits, aProtocolConstants->Flags, aProtocolConstants->RepeatPeriodMillis, +// aNumberOfRepeats); + // Set IR carrier frequency + enableIROut(aProtocolConstants->FrequencyKHz); - if (aNumberOfRepeats < 0) { - if (aSpecialSendRepeatFunction != NULL) { - aSpecialSendRepeatFunction(); - return; - } else { - aNumberOfRepeats = 0; // send a plain frame as repeat - } - } + uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_DECODED_RAW_DATA_TYPE) + 1; - // Set IR carrier frequency - enableIROut(aFrequencyKHz); +#if defined(LOCAL_DEBUG) + // fist data + Serial.print(F("Data[0]=0x")); + Serial.print(aDecodedRawDataArray[0], HEX); + if (tNumberOf32Or64BitChunks > 1) { + Serial.print(F(" Data[1]=0x")); + Serial.print(aDecodedRawDataArray[1], HEX); + } + Serial.print(F(" #=")); + Serial.println(aNumberOfBits); + Serial.flush(); +#endif uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { - unsigned long tStartOfFrameMillis = millis(); + auto tStartOfFrameMillis = millis(); + auto tNumberOfBits = aNumberOfBits; // refresh value for repeats - if (tNumberOfCommands < ((uint_fast8_t) aNumberOfRepeats + 1) && aSpecialSendRepeatFunction != NULL) { - // send special repeat - aSpecialSendRepeatFunction(); - } else { - // Header and regular frame - mark(aHeaderMarkMicros); - space(aHeaderSpaceMicros); - sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aData, aNumberOfBits, - aFlags); + // Header + mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros); + space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros); + uint8_t tOriginalFlags = aProtocolConstants->Flags; + + for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) { + uint8_t tNumberOfBitsForOneSend; + + uint8_t tFlags; + if (i == (tNumberOf32Or64BitChunks - 1)) { + // End of data + tNumberOfBitsForOneSend = tNumberOfBits; + tFlags = tOriginalFlags; + } else { + // intermediate data + tNumberOfBitsForOneSend = BITS_IN_DECODED_RAW_DATA_TYPE; + tFlags = tOriginalFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data + } + + sendPulseDistanceWidthData(aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aDecodedRawDataArray[i], tNumberOfBitsForOneSend, + tFlags); + tNumberOfBits -= BITS_IN_DECODED_RAW_DATA_TYPE; } tNumberOfCommands--; @@ -794,138 +1049,187 @@ void IRsend::sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeader * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. */ auto tFrameDurationMillis = millis() - tStartOfFrameMillis; - if (aRepeatPeriodMillis > tFrameDurationMillis) { - delay(aRepeatPeriodMillis - tFrameDurationMillis); + if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) { + delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis); } } } } -/** - * Sends PulseDistance data - * The output always ends with a space - * Each additional call costs 16 bytes program memory - */ -void IRsend::sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, - uint_fast8_t aNumberOfBits) { +void IRsend::sendPulseDistanceWidthFromPGMArray(PulseDistanceWidthProtocolConstants *aProtocolConstants, + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidthData(aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, - aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, - aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, aData, aNumberOfBits, aProtocolConstants->Flags); -} +// Calling sendPulseDistanceWidthFromArray() costs 68 bytes program memory compared to the implementation below +// sendPulseDistanceWidthFromArray(aProtocolConstants->FrequencyKHz, aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros, +// aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros, +// aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, +// aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, +// aDecodedRawDataArray, aNumberOfBits, aProtocolConstants->Flags, aProtocolConstants->RepeatPeriodMillis, +// aNumberOfRepeats); + // Set IR carrier frequency + enableIROut(aProtocolConstants->FrequencyKHz); -/** - * Sends PulseDistance data - * The output always ends with a space - */ -void IRsend::sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, - uint16_t aZeroSpaceMicros, IRRawDataType aData, uint_fast8_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit) { - uint8_t tFlags = 0; - if (aMSBFirst) { - tFlags = PROTOCOL_IS_MSB_FIRST; - } - (void) aSendStopBit; - sendPulseDistanceWidthData(aOneMarkMicros, aOneSpaceMicros, aZeroMarkMicros, aZeroSpaceMicros, aData, aNumberOfBits, tFlags); -} -void IRsend::sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, - uint16_t aZeroSpaceMicros, IRRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags) { + uint_fast8_t tNumberOf32Or64BitChunks = ((aNumberOfBits - 1) / BITS_IN_DECODED_RAW_DATA_TYPE) + 1; #if defined(LOCAL_DEBUG) - Serial.print(aData, HEX); - Serial.print('|'); + // fist data + Serial.print(F("Data[0]=0x")); + Serial.print(aDecodedRawDataPGMArray[0], HEX); + if (tNumberOf32Or64BitChunks > 1) { + Serial.print(F(" Data[1]=0x")); + Serial.print(aDecodedRawDataPGMArray[1], HEX); + } + Serial.print(F(" #=")); Serial.println(aNumberOfBits); Serial.flush(); #endif - // For MSBFirst, send data from MSB to LSB until mask bit is shifted out - IRRawDataType tMask = 1ULL << (aNumberOfBits - 1); - for (uint_fast8_t i = aNumberOfBits; i > 0; i--) { - if (((aFlags & PROTOCOL_IS_MSB_FIRST) && (aData & tMask)) || (!(aFlags & PROTOCOL_IS_MSB_FIRST) && (aData & 1))) { -#if defined(LOCAL_TRACE) - Serial.print('1'); -#endif - mark(aOneMarkMicros); - space(aOneSpaceMicros); - } else { -#if defined(LOCAL_TRACE) - Serial.print('0'); + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + auto tStartOfFrameMillis = millis(); + auto tNumberOfBits = aNumberOfBits; // refresh value for repeats + + // Header + mark(aProtocolConstants->DistanceWidthTimingInfo.HeaderMarkMicros); + space(aProtocolConstants->DistanceWidthTimingInfo.HeaderSpaceMicros); + uint8_t tOriginalFlags = aProtocolConstants->Flags; + + for (uint_fast8_t i = 0; i < tNumberOf32Or64BitChunks; ++i) { + uint8_t tNumberOfBitsForOneSend; + + uint8_t tFlags; + if (i == (tNumberOf32Or64BitChunks - 1)) { + // End of data + tNumberOfBitsForOneSend = tNumberOfBits; + tFlags = tOriginalFlags; + } else { + // intermediate data + tNumberOfBitsForOneSend = BITS_IN_DECODED_RAW_DATA_TYPE; + tFlags = tOriginalFlags | SUPPRESS_STOP_BIT; // No stop bit for leading data + } + + IRDecodedRawDataType tDecodedRawData; +#if (__INT_WIDTH__ < 32) + tDecodedRawData = pgm_read_dword(&aDecodedRawDataPGMArray[i]); // pgm_read_dword reads 32 bit on AVR +#else + tDecodedRawData = aDecodedRawDataPGMArray[i]; // assume non Harvard architecture here #endif - mark(aZeroMarkMicros); - space(aZeroSpaceMicros); + sendPulseDistanceWidthData(aProtocolConstants->DistanceWidthTimingInfo.OneMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.OneSpaceMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroMarkMicros, + aProtocolConstants->DistanceWidthTimingInfo.ZeroSpaceMicros, tDecodedRawData, tNumberOfBitsForOneSend, tFlags); + tNumberOfBits -= BITS_IN_DECODED_RAW_DATA_TYPE; } - if (aFlags & PROTOCOL_IS_MSB_FIRST) { - tMask >>= 1; - } else { - aData >>= 1; + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + auto tFrameDurationMillis = millis() - tStartOfFrameMillis; + if (aProtocolConstants->RepeatPeriodMillis > tFrameDurationMillis) { + delay(aProtocolConstants->RepeatPeriodMillis - tFrameDurationMillis); + } } } - /* - * Stop bit is sent for all pulse distance protocols i.e. aOneMarkMicros == aZeroMarkMicros. - * Therefore it is not sent for Sony and Magiquest :-) - */ - if (!(aFlags & SUPPRESS_STOP_BIT_FOR_THIS_DATA) && aOneMarkMicros == aZeroMarkMicros) { - // Send stop bit here -#if defined(LOCAL_TRACE) - Serial.print('S'); -#endif - mark(aZeroMarkMicros); // Use aZeroMarkMicros for stop bits. This seems to be correct for all protocols :-) - } -#if defined(LOCAL_TRACE) - Serial.println(); -#endif +} + +/********************************************************************************************************************** + * Stubs for send functions with PulseDistanceWidthProtocolConstants parameter + **********************************************************************************************************************/ + +void IRsend::sendPulseDistanceWidthFromArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { + + PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants; + memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM, + sizeof(tTemporaryPulseDistanceWidthProtocolConstants)); + sendPulseDistanceWidthFromArray(&tTemporaryPulseDistanceWidthProtocolConstants, aDecodedRawDataArray, aNumberOfBits, + aNumberOfRepeats); +} +void IRsend::sendPulseDistanceWidthFromPGMArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { + + PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants; + memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM, + sizeof(tTemporaryPulseDistanceWidthProtocolConstants)); + sendPulseDistanceWidthFromPGMArray(&tTemporaryPulseDistanceWidthProtocolConstants, aDecodedRawDataPGMArray, aNumberOfBits, + aNumberOfRepeats); +} + +void IRsend::sendPulseDistanceWidth_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, + uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats) { + PulseDistanceWidthProtocolConstants tTemporaryPulseDistanceWidthProtocolConstants; + memcpy_P(&tTemporaryPulseDistanceWidthProtocolConstants, aProtocolConstantsPGM, + sizeof(tTemporaryPulseDistanceWidthProtocolConstants)); + sendPulseDistanceWidth(&tTemporaryPulseDistanceWidthProtocolConstants, aData, aNumberOfBits, aNumberOfRepeats); } /** - * Sends Biphase data MSB first - * Always send start bit, do not send the trailing space of the start bit + * Sends Biphase (Manchester) coded data MSB first + * This function concatenates two marks to one longer mark, + * thus avoiding the programmatically pause between the generation of two separate marks. + * Send an additional start bit if specified * 0 -> mark+space * 1 -> space+mark - * The output always ends with a space - * can only send 31 bit data, since we put the start bit as 32th bit on front + * The output always ends with a space / inactive level + * @param aData uint32 holding the bits to be sent. + * @param aNumberOfBits Number of bits from aData to be actually sent. + * @param aSendStartBit if true sends an additional start bit with value 1 as MSB, if false no start bit is sent and data may start with 0 or 1. */ -void IRsend::sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits) { - - IR_TRACE_PRINT(F("0x")); - IR_TRACE_PRINT(aData, HEX); +void IRsend::sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits, bool aSendStartBit) { -#if defined(LOCAL_TRACE) - Serial.print('S'); -#endif + TRACE_PRINT(F("0x")); + TRACE_PRINT(aData, HEX); + TRACE_PRINT('S'); // Data - Biphase code MSB first -// prepare for start with sending the start bit, which is 1 - uint32_t tMask = 1UL << aNumberOfBits; // mask is now set for the virtual start bit - uint_fast8_t tLastBitValue = 1; // Start bit is a 1 - bool tNextBitIsOne = 1; // Start bit is a 1 - for (uint_fast8_t i = aNumberOfBits + 1; i > 0; i--) { + + uint8_t tBitsToSend = aNumberOfBits; // total number of bits to send including start bit if specified + if (aSendStartBit) { + tBitsToSend++; // +1 for additional start bit + } + uint32_t tMask = 1UL << (tBitsToSend - 1); // Mask is now set to the the MSB of data or the virtual start bit before the MSB of data + + bool tLastBitWasOne; + bool tNextBitIsOne; + if (aSendStartBit) { + // prepare for start with sending the start bit, which is 1 + tNextBitIsOne = true; // Start bit is a 1, value is copied to tCurrentBitIsOne + tLastBitWasOne = false; // Force to send the mark if tNextBitIsOne is 0 (which it is not the case here). Does not increase code size :-). + } else { + // prepare to send only the data which may start with a 0 or 1 (e.g. after a defined pause or header when no additional start bit is needed) + tNextBitIsOne = ((aData & tMask) != 0) ? 1 : 0; // Value is copied to tCurrentBitIsOne + tLastBitWasOne = false; // Force to send the mark if tNextBitIsOne is 0 + } + + // now send all bits + for (uint_fast8_t i = tBitsToSend; i > 0; i--) { bool tCurrentBitIsOne = tNextBitIsOne; tMask >>= 1; tNextBitIsOne = ((aData & tMask) != 0) || (i == 1); // true for last bit to avoid extension of mark if (tCurrentBitIsOne) { -#if defined(LOCAL_TRACE) - Serial.print('1'); -#endif + TRACE_PRINT('1'); space(aBiphaseTimeUnit); if (tNextBitIsOne) { - mark(aBiphaseTimeUnit); + mark(aBiphaseTimeUnit); // if next bit is 1 send a single mark } else { // if next bit is 0, extend the current mark in order to generate a continuous signal without short breaks mark(2 * aBiphaseTimeUnit); } - tLastBitValue = 1; + tLastBitWasOne = true; } else { -#if defined(LOCAL_TRACE) - Serial.print('0'); -#endif - if (!tLastBitValue) { - mark(aBiphaseTimeUnit); + TRACE_PRINT('0'); + if (!tLastBitWasOne) { + mark(aBiphaseTimeUnit); // if last bit was 0 send a single mark } space(aBiphaseTimeUnit); - tLastBitValue = 0; + tLastBitWasOne = false; } } - IR_TRACE_PRINTLN(F("")); + TRACE_PRINTLN(); } /** @@ -933,14 +1237,21 @@ void IRsend::sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fas * The mark output is modulated at the PWM frequency if USE_NO_SEND_PWM is not defined. * The output is guaranteed to be OFF / inactive after after the call of the function. * This function may affect the state of feedback LED. + * Period time is 26 us for 38.46 kHz, 27 us for 37.04 kHz, 25 us for 40 kHz. + * On time is 8 us for 30% duty cycle + * + * The mark() function relies on the correct implementation of: + * delayMicroseconds() for pulse time, and micros() for pause time. + * The delayMicroseconds() of pulse time is guarded on AVR CPU's with noInterrupts() / interrupts(). + * At the start of pause time, interrupts are enabled once, the rest of the pause is also guarded on AVR CPU's with noInterrupts() / interrupts(). + * The maximum length of an interrupt during sending should not exceed 26 us - 8 us = 18 us, otherwise timing is disturbed. + * This disturbance is no problem, if the exceedance is small and does not happen too often. */ void IRsend::mark(uint16_t aMarkMicros) { #if defined(SEND_PWM_BY_TIMER) || defined(USE_NO_SEND_PWM) -# if !defined(NO_LED_FEEDBACK_CODE) - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(true); - } +# if defined(LED_SEND_FEEDBACK_CODE) + setFeedbackLED(true); # endif #endif @@ -958,62 +1269,87 @@ void IRsend::mark(uint16_t aMarkMicros) { * Here we generate no carrier PWM, just simulate an active low receiver signal. */ # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN) + // Here we have no hardware supported Open Drain outputs, so we must mimicking it pinModeFast(sendPin, OUTPUT); // active state for mimicking open drain +# elif defined(USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM) || defined(USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN) // USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN is old and deprecated + digitalWriteFast(sendPin, HIGH); // Set output to active high. # else digitalWriteFast(sendPin, LOW); // Set output to active low. # endif customDelayMicroseconds(aMarkMicros); IRLedOff(); -# if !defined(NO_LED_FEEDBACK_CODE) - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(false); - } +# if defined(LED_SEND_FEEDBACK_CODE) + setFeedbackLED(false); return; # endif #else // defined(SEND_PWM_BY_TIMER) - /* - * Generate PWM by bit banging - */ - unsigned long tStartMicros = micros(); - unsigned long tNextPeriodEnding = tStartMicros; - unsigned long tMicros; -# if !defined(NO_LED_FEEDBACK_CODE) - bool FeedbackLedIsActive = false; -# endif + unsigned long tMicros = micros(); + unsigned long tMicrosOfEndOfNextPWMPause = tMicros; +# if defined(LED_SEND_FEEDBACK_CODE) + unsigned long tEndMicros = tMicros + (136 / CLOCKS_PER_MICRO) + aMarkMicros; // To compensate for call duration and activating of LED + bool tFeedbackLedIsActive = false; +#else + unsigned long tEndMicros = tMicros + (112 / CLOCKS_PER_MICRO) + aMarkMicros; // To compensate for call duration - 112 is an empirical value +#endif + + /*************************************************************************************************** + * Generate the IR PWM with 30% duty cycle with a frequency of e.g. 38 kHz by software / bit banging + **************************************************************************************************/ do { // digitalToggleFast(_IR_TIMING_TEST_PIN); - /* - * Output the PWM pulse - */ + /***************************************** + * Output the PWM pulse - IR LED is active + ****************************************/ noInterrupts(); // do not let interrupts extend the short on period -# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) -# if defined(OUTPUT_OPEN_DRAIN) - digitalWriteFast(sendPin, LOW); // set output with pin mode OUTPUT_OPEN_DRAIN to active low +# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN) + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, LOW); // set output to active low. Also applicable for pin with mode OUTPUT_OPEN_DRAIN :-) + } else { + digitalWrite(sendPin, LOW); + } # else pinModeFast(sendPin, OUTPUT); // active state for mimicking open drain # endif # else // 3.5 us from FeedbackLed on to pin setting. 5.7 us from call of mark() to pin setting incl. setting of feedback pin. // 4.3 us from do{ to pin setting if sendPin is no constant - digitalWriteFast(sendPin, HIGH); + // check must be here because of MegaTinyCore and its badArg() check + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } # endif - delayMicroseconds (periodOnTimeMicros); // this is normally implemented by a blocking wait - /* - * Output the PWM pause + * Timing for the on time of the e.g. 38 kHz signal. + * On time is 8 us for 30% duty cycle. This is normally implemented by a blocking wait. */ -# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN) -# if defined(OUTPUT_OPEN_DRAIN) - digitalWriteFast(sendPin, HIGH); // Set output with pin mode OUTPUT_OPEN_DRAIN to inactive high. + delayMicroseconds (periodOnTimeMicros); + + /******************************************* + * Output the PWM pause - IR LED is inactive + ******************************************/ +# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN) + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); // Set output to inactive high. Also applicable for pin with mode OUTPUT_OPEN_DRAIN + } else { + digitalWrite(sendPin, HIGH); + } # else pinModeFast(sendPin, INPUT); // to mimic the open drain inactive state # endif # else - digitalWriteFast(sendPin, LOW); + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, LOW); + } else { + digitalWrite(sendPin, LOW); + } # endif /* * Enable interrupts at start of the longer off period. Required at least to keep micros correct. @@ -1021,25 +1357,26 @@ void IRsend::mark(uint16_t aMarkMicros) { */ interrupts(); -# if !defined(NO_LED_FEEDBACK_CODE) +# if defined(LED_SEND_FEEDBACK_CODE) /* * Delayed call of setFeedbackLED() to get better startup timing, especially required for consecutive marks */ - if (!FeedbackLedIsActive) { - FeedbackLedIsActive = true; - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(true); - } + if (!tFeedbackLedIsActive) { + tFeedbackLedIsActive = true; // do it only once + setFeedbackLED(true); } # endif - /* - * PWM pause timing - * Measured delta between pause duration values are 13 us for a 16 MHz UNO (from 13 to 26) - * Minimal pause duration is 5.2 us with NO_LED_FEEDBACK_CODE enabled - * and 8.1 us with NO_LED_FEEDBACK_CODE disabled. - */ - tNextPeriodEnding += periodTimeMicros; - noInterrupts(); + /******************************************************************************************************************************** + * Check for end of the PWM pause with micros() < tMicrosOfEndOfNextPWMPause. + * This generates the timing for the transmit frequency e.g. 38 kHz + * Measured delta between pause duration values are 8 us for a 16 MHz Uno (from 15 to 23), if interrupts are disabled below + * Minimal pause duration is 5.2 us + * For an 8 MHz Attiny we measure 10 us, 18 us and 27 us pause. Minimal pause duration is 10 us. (80 us for 1MHz -> 12 kHz) + *******************************************************************************************************************************/ + tMicrosOfEndOfNextPWMPause += periodTimeMicros; // Period time is 26 us for 38.46 kHz, 27 us for 37.04 kHz, 25 us for 40 kHz. +//#if defined(__AVR__) // micros() for STM sometimes give decreasing values if interrupts are disabled. See https://github.com/stm32duino/Arduino_Core_STM32/issues/1680 +// noInterrupts(); // disable interrupts (especially the 20 us receive interrupts) only at start of the PWM pause. Otherwise it may extend the pause too much. +//#endif do { #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) digitalWriteFast(_IR_TIMING_TEST_PIN, HIGH); // 2 clock cycles @@ -1047,42 +1384,29 @@ void IRsend::mark(uint16_t aMarkMicros) { /* * For AVR @16MHz we have only 4 us resolution. * The duration of the micros() call itself is 3 us. - * It takes 0.9 us from signal going low here. - * The rest of the loop takes 1.2 us with NO_LED_FEEDBACK_CODE enabled - * and 3 us with NO_LED_FEEDBACK_CODE disabled. + * It takes 0.9 us from signal going low to here. + * The rest of the loop takes 1.2 us */ - tMicros = micros(); // #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) digitalWriteFast(_IR_TIMING_TEST_PIN, LOW); // 2 clock cycles #endif - /* - * Exit the forever loop if aMarkMicros has reached - */ - unsigned int tDeltaMicros = tMicros - tStartMicros; -#if defined(__AVR__) -// tDeltaMicros += (160 / CLOCKS_PER_MICRO); // adding this once increases program size ! -# if !defined(NO_LED_FEEDBACK_CODE) - if (tDeltaMicros >= aMarkMicros - (30 + (112 / CLOCKS_PER_MICRO))) { // 30 to be constant. Using periodTimeMicros increases program size too much. - // reset feedback led in the last pause before end - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(false); - } - } -# endif - // Just getting variables and check for end condition takes minimal 3.8 us - if (tDeltaMicros >= aMarkMicros - (112 / CLOCKS_PER_MICRO)) { // To compensate for call duration - 112 is an empirical value -#else - if (tDeltaMicros >= aMarkMicros) { -# if !defined(NO_LED_FEEDBACK_CODE) - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(false); - } -# endif + + /************************************************* + * Check for end of mark duration / PWM generation + ************************************************/ + tMicros = micros(); + if (tMicros >= tEndMicros) { + // reset feedback led in the last pause before end +#if defined(LED_SEND_FEEDBACK_CODE) + setFeedbackLED(false); #endif - interrupts(); +//#if defined(__AVR__) +// interrupts(); // enable interrupts again before leaving mark() +//#endif return; } - } while (tMicros < tNextPeriodEnding); + + } while (tMicros < tMicrosOfEndOfNextPWMPause); // = End of one PWM period } while (true); # endif } @@ -1099,31 +1423,40 @@ void IRsend::IRLedOff() { # if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) && !defined(OUTPUT_OPEN_DRAIN) digitalWriteFast(sendPin, LOW); // prepare for all next active states. pinModeFast(sendPin, INPUT);// inactive state for open drain +# elif defined(USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM) || defined(USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN) // USE_ACTIVE_HIGH_OUTPUT_FOR_SEND_PIN is old and deprecated + digitalWriteFast(sendPin, LOW); // Set output to inactive low. # else digitalWriteFast(sendPin, HIGH); // Set output to inactive high. # endif #else -# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) -# if defined(OUTPUT_OPEN_DRAIN) - digitalWriteFast(sendPin, HIGH); // Set output to inactive high. +# if defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) || defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) || defined(OUTPUT_OPEN_DRAIN) + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); // set output to inactive high. + } else { + digitalWrite(sendPin, HIGH); + } # else pinModeFast(sendPin, INPUT); // inactive state to mimic open drain # endif # else - digitalWriteFast(sendPin, LOW); + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, LOW); // set output to active low. + } else { + digitalWrite(sendPin, LOW); + } # endif #endif -#if !defined(NO_LED_FEEDBACK_CODE) - if (FeedbackLEDControl.LedFeedbackEnabled == LED_FEEDBACK_ENABLED_FOR_SEND) { - setFeedbackLED(false); - } +#if defined(LED_SEND_FEEDBACK_CODE) + setFeedbackLED(false); #endif } /** * Sends an IR space for the specified number of microseconds. * A space is "no output", so just wait. + * Executing program between end of mark and start of next mark uses around 15 to 20 us @ 16 MHz. This time is added to the space delay here. */ void IRsend::space(uint16_t aSpaceMicros) { customDelayMicroseconds(aSpaceMicros); @@ -1163,7 +1496,7 @@ void IRsend::customDelayMicroseconds(unsigned long aMicroseconds) { * Enables IR output. The kHz value controls the modulation frequency in kilohertz. * IF PWM should be generated by a timer, it uses the platform specific timerConfigForSend() function, * otherwise it computes the delays used by the mark() function. - * If IR_SEND_PIN is defined, maximum PWM frequency for an AVR @16 MHz is 170 kHz (180 kHz if NO_LED_FEEDBACK_CODE is defined) + * If IR_SEND_PIN is defined, maximum PWM frequency for an AVR @16 MHz is 170 kHz (180 kHz if NO_LED_SEND_FEEDBACK_CODE is defined) */ void IRsend::enableIROut(uint_fast8_t aFrequencyKHz) { #if defined(SEND_PWM_BY_TIMER) @@ -1196,7 +1529,11 @@ void IRsend::enableIROut(uint_fast8_t aFrequencyKHz) { # if defined(IR_SEND_PIN) pinModeFast(IR_SEND_PIN, OUTPUT); # else - pinModeFast(sendPin, OUTPUT); + if (__builtin_constant_p(sendPin)) { + pinModeFast(sendPin, OUTPUT); + } else { + pinMode(sendPin, OUTPUT); + } # endif # endif #endif // defined(USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN) @@ -1226,10 +1563,6 @@ uint16_t IRsend::getPulseCorrectionNanos() { #if defined(_IR_MEASURE_TIMING) #undef _IR_MEASURE_TIMING #endif -#if defined(LOCAL_TRACE) -#undef LOCAL_TRACE -#endif -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_SEND_HPP diff --git a/src/IRVersion.h b/src/IRVersion.h new file mode 100644 index 000000000..8dc76ab92 --- /dev/null +++ b/src/IRVersion.h @@ -0,0 +1,51 @@ +/** + * @file IRversion.hpp + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + ************************************************************************************ + * MIT License + * + * Copyright (c) 2015-2025 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. + * + ************************************************************************************ + * + * For Ken Shiriffs original blog entry, see http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html + * Initially influenced by: + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * and http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + */ + +#ifndef _IR_VERSION_HPP +#define _IR_VERSION_HPP + +#define VERSION_IRREMOTE "4.7.1" +#define VERSION_IRREMOTE_MAJOR 4 +#define VERSION_IRREMOTE_MINOR 7 +#define VERSION_IRREMOTE_PATCH 1 + +/* + * Macro to convert 3 version parts into an integer + * To be used in preprocessor comparisons, such as #if VERSION_IRREMOTE_HEX >= VERSION_HEX_VALUE(3, 7, 0) + */ +#define VERSION_HEX_VALUE(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +#define VERSION_IRREMOTE_HEX VERSION_HEX_VALUE(VERSION_IRREMOTE_MAJOR, VERSION_IRREMOTE_MINOR, VERSION_IRREMOTE_PATCH) + +#endif // _IR_VERSION_HPP diff --git a/src/IRremote.h b/src/IRremote.h index 9b2ab8ccf..73cae0385 100644 --- a/src/IRremote.h +++ b/src/IRremote.h @@ -9,6 +9,14 @@ #include "IRremote.hpp" +#warning It seems, that you are using an old version 2.0 code / example. +#warning This version is no longer supported! +#warning Upgrade instructions can be found here: "https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#converting-your-2x-program-to-the-4x-version" +#warning Please use one of the new code examples from the library, available at "File > Examples > Examples from Custom Libraries / IRremote". +#warning Start with the SimpleReceiver or SimpleSender example. +#warning The examples are documented here: "https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#examples-for-this-library" +#warning Or just downgrade your library to version 2.6.0. + /********************************************************************************************************************** * The OLD and DEPRECATED decode function with parameter aResults, kept for backward compatibility to old 2.0 tutorials * This function calls the old MSB first decoders and fills only the 3 variables: @@ -22,17 +30,21 @@ bool IRrecv::decode(decode_results *aResults) { if (!sMessageWasSent) { Serial.println(F("**************************************************************************************************")); Serial.println(F("Thank you for using the IRremote library!")); - Serial.println(F("It seems, that you are using a old version 2.0 code / example.")); + Serial.println(F("It seems, that you are using an old version 2.0 code / example.")); Serial.println(F("This version is no longer supported!")); + Serial.println(); + Serial.println(F("Upgrade instructions can be found here:")); + Serial.println(F(" https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#converting-your-2x-program-to-the-4x-version")); + Serial.println(); Serial.println(F("Please use one of the new code examples from the library,")); Serial.println(F(" available at \"File > Examples > Examples from Custom Libraries / IRremote\".")); - Serial.println(); Serial.println(F("Start with the SimpleReceiver or SimpleSender example.")); - Serial.println(); Serial.println(F("The examples are documented here:")); - Serial.println(F(" https://github.com/Arduino-IRremote/Arduino-IRremote#examples-for-this-library")); - Serial.println(F("A guide how to convert your 2.0 program is here:")); - Serial.println(F(" https://github.com/Arduino-IRremote/Arduino-IRremote#converting-your-2x-program-to-the-4x-version")); + Serial.println(F(" https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#examples-for-this-library")); + Serial.println(); + Serial.println(F("Or just downgrade your library to version 2.6.0.")); + Serial.println(); + Serial.println(F("Thanks")); Serial.println(F("**************************************************************************************************")); Serial.println(); Serial.println(); diff --git a/src/IRremote.hpp b/src/IRremote.hpp index 7baa0bf78..409c7ea8e 100644 --- a/src/IRremote.hpp +++ b/src/IRremote.hpp @@ -13,7 +13,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2015-2023 Ken Shirriff http://www.righto.com, Rafi Khan, Armin Joachimsmeyer + * Copyright (c) 2015-2025 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 @@ -46,16 +46,21 @@ * * - RAW_BUFFER_LENGTH Buffer size of raw input buffer. Must be even! 100 is sufficient for *regular* protocols of up to 48 bits. * - IR_SEND_PIN If specified (as constant), reduces program size and improves send timing for AVR. + * - USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN Reverts the polarity at the send pin. + * - USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! * - SEND_PWM_BY_TIMER Disable carrier PWM generation in software and use (restricted) hardware PWM. * - USE_NO_SEND_PWM Use no carrier PWM, just simulate an **active low** receiver signal. Overrides SEND_PWM_BY_TIMER definition. - * - USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin! + * - USE_ACTIVE_HIGH_OUTPUT_FOR_NO_SEND_PWM Simulate an **active high** receiver signal instead of an active low signal. * - EXCLUDE_EXOTIC_PROTOCOLS If activated, BANG_OLUFSEN, BOSEWAVE, WHYNTER, FAST and LEGO_PF are excluded in decode() and in sending with IrSender.write(). * - EXCLUDE_UNIVERSAL_PROTOCOLS If activated, the universal decoder for pulse distance protocols and decodeHash (special decoder for all protocols) are excluded in decode(). * - DECODE_* Selection of individual protocols to be decoded. See below. + * - USE_THRESHOLD_DECODER May give slightly better results especially for jittering signals and protocols with short 1 pulses / pauses. * - MARK_EXCESS_MICROS Value is subtracted from all marks and added to all spaces before decoding, to compensate for the signal forming of different IR receiver modules. * - RECORD_GAP_MICROS Minimum gap between IR transmissions, to detect the end of a protocol. * - FEEDBACK_LED_IS_ACTIVE_LOW Required on some boards (like my BluePill and my ESP8266 board), where the feedback LED is active low. * - NO_LED_FEEDBACK_CODE This completely disables the LED feedback code for send and receive. + * - NO_LED_RECEIVE_FEEDBACK_CODE This disables the LED feedback code for receive. + * - NO_LED_SEND_FEEDBACK_CODE This disables the LED feedback code for send. * - IR_INPUT_IS_ACTIVE_HIGH Enable it if you use a RF receiver, which has an active HIGH output signal. * - IR_SEND_DUTY_CYCLE_PERCENT Duty cycle of IR send signal. * - MICROS_PER_TICK Resolution of the raw input buffer data. Corresponds to 2 pulses of each 26.3 us at 38 kHz. @@ -65,122 +70,77 @@ #ifndef _IR_REMOTE_HPP #define _IR_REMOTE_HPP -#define VERSION_IRREMOTE "4.1.0" -#define VERSION_IRREMOTE_MAJOR 4 -#define VERSION_IRREMOTE_MINOR 1 -#define VERSION_IRREMOTE_PATCH 0 - -/* - * Macro to convert 3 version parts into an integer - * To be used in preprocessor comparisons, such as #if VERSION_IRREMOTE_HEX >= VERSION_HEX_VALUE(3, 7, 0) - */ -#define VERSION_HEX_VALUE(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) -#define VERSION_IRREMOTE_HEX VERSION_HEX_VALUE(VERSION_IRREMOTE_MAJOR, VERSION_IRREMOTE_MINOR, VERSION_IRREMOTE_PATCH) +#include "IRVersion.h" // activate it for all cores that does not use the -flto flag, if you get false error messages regarding begin() during compilation. //#define SUPPRESS_ERROR_MESSAGE_FOR_BEGIN -/* - * If activated, BANG_OLUFSEN, BOSEWAVE, MAGIQUEST, WHYNTER, FAST and LEGO_PF are excluded in decoding and in sending with IrSender.write - */ -//#define EXCLUDE_EXOTIC_PROTOCOLS -/**************************************************** - * PROTOCOLS - ****************************************************/ -/* - * Supported IR protocols - * Each protocol you include costs memory and, during decode, costs time - * Copy the lines with the protocols you need in your program before the #include line - * See also SimpleReceiver example - */ - -#if !defined(NO_DECODER) // for sending raw only -# if (!(defined(DECODE_DENON) || defined(DECODE_JVC) || defined(DECODE_KASEIKYO) \ -|| defined(DECODE_PANASONIC) || defined(DECODE_LG) || defined(DECODE_NEC) || defined(DECODE_ONKYO) || defined(DECODE_SAMSUNG) \ -|| defined(DECODE_SONY) || defined(DECODE_RC5) || defined(DECODE_RC6) \ -|| defined(DECODE_DISTANCE_WIDTH) || defined(DECODE_HASH) || defined(DECODE_BOSEWAVE) \ -|| defined(DECODE_LEGO_PF) || defined(DECODE_MAGIQUEST) || defined(DECODE_FAST) || defined(DECODE_WHYNTER))) -/* - * If no protocol is explicitly enabled, we enable all protocols - */ -#define DECODE_DENON // Includes Sharp -#define DECODE_JVC -#define DECODE_KASEIKYO -#define DECODE_PANASONIC // alias for DECODE_KASEIKYO -#define DECODE_LG -#define DECODE_NEC // Includes Apple and Onkyo -#define DECODE_SAMSUNG -#define DECODE_SONY -#define DECODE_RC5 -#define DECODE_RC6 - -# if !defined(EXCLUDE_EXOTIC_PROTOCOLS) // saves around 2000 bytes program memory -#define DECODE_BOSEWAVE -#define DECODE_LEGO_PF -#define DECODE_MAGIQUEST // It modifies the RAW_BUFFER_LENGTH from 100 to 112 -#define DECODE_WHYNTER -#define DECODE_FAST -# endif - -# if !defined(EXCLUDE_UNIVERSAL_PROTOCOLS) -#define DECODE_DISTANCE_WIDTH // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory -#define DECODE_HASH // special decoder for all protocols - requires up to 250 bytes additional program memory -# endif -# endif -#endif // !defined(NO_DECODER) +#include "IRProtocol.h" -//#define DECODE_BEO // Bang & Olufsen protocol always must be enabled explicitly. It prevents decoding of SONY! +//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core. -#if defined(DECODE_NEC) && !(~(~DECODE_NEC + 0) == 0 && ~(~DECODE_NEC + 1) == 1) -#warning "The macros DECODE_XXX no longer require a value. Decoding is now switched by defining / non defining the macro." +// Helper macro for getting a macro definition as string +#if !defined(STR_HELPER) && !defined(STR) +#define STR_HELPER(x) #x +#define STR(x) STR_HELPER(x) #endif -//#define DEBUG // Activate this for lots of lovely debug output from the IRremote core. - /**************************************************** * RECEIVING ****************************************************/ /** * MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, - * to compensate for the signal forming of different IR receiver modules + * to compensate for the signal forming of different IR receiver modules. + * 20 is taken as default if not otherwise specified / defined. * For Vishay TSOP*, marks tend to be too long and spaces tend to be too short. - * If you set MARK_EXCESS_MICROS to approx. 50us then the TSOP4838 works best. - * At 100us it also worked, but not as well. - * Set MARK_EXCESS to 100us and the VS1838 doesn't work at all. - * - * The right value is critical for IR codes using short pulses like Denon / Sharp / Lego + * If you set MARK_EXCESS_MICROS to approx. 40 to 50 us then the TSOP4838 works best. + * At 100 us it also worked, but not as well. + * Set MARK_EXCESS to 100 us and the VS1838 doesn't work at all. * * Observed values: - * Delta of each signal type is around 50 up to 100 and at low signals up to 200. TSOP is better, especially at low IR signal level. - * VS1838 Mark Excess -50 at low intensity to +50 us at high intensity + * Delta of each signal type is around 50 up to 100 us and at low signals up to 200 us. + * TSOP is better, especially at low IR signal level. + * VS1838 Mark Excess -50 us at low intensity to +50 us at high intensity * TSOP31238 Mark Excess 0 to +50 */ #if !defined(MARK_EXCESS_MICROS) -// To change this value, you simply can add a line #define "MARK_EXCESS_MICROS " in your ino file before the line "#include " -#define MARK_EXCESS_MICROS 20 +# if defined(USE_THRESHOLD_DECODER) +#define MARK_EXCESS_MICROS 0 // MARK_EXCESS_MICROS is not very relevant here, so we set it to 0 to save up to 164 bytes programming space +# else +// To override this value, you simply can add a line #define "MARK_EXCESS_MICROS " in your ino file before the line "#include " +#define MARK_EXCESS_MICROS 20 // a value != 0 requires up to 100 bytes program space +# endif #endif /** - * Minimum gap between IR transmissions, to detect the end of a protocol. + * Minimum gap between IR transmissions, only used to detect the end of a frame. * Must be greater than any space of a protocol e.g. the NEC header space of 4500 us. - * Must be smaller than any gap between a command and a repeat; e.g. the retransmission gap for Sony is around 15 ms for Sony20 protocol. - * Keep in mind, that this is the delay between the end of the received command and the start of decoding. + * Must be smaller than any gap between a frame and a repeat frame; e.g. the retransmission gap for Sony is around 12 ms for Sony20 protocol. + * Bear in mind, that this is the delay between the end of the received frame + * and the time at which the software detects the end of this frame and can start decoding! */ #if !defined(RECORD_GAP_MICROS) -// To change this value, you simply can add a line #define "RECORD_GAP_MICROS " in your ino file before the line "#include " -#define RECORD_GAP_MICROS 5000 // FREDRICH28AC / LG2 header space is 9700, NEC header space is 4500 +// To change this value, you simply can add a line #define "RECORD_GAP_MICROS " in your *.ino file before the line "#include " +// Maximum value for RECORD_GAP_MICROS, which fit into 8 bit buffer, using 50 us as tick, is 12750 +#define RECORD_GAP_MICROS 8000 // RECS80 (https://www.mikrocontroller.net/articles/IRMP#RECS80) 1 bit space is 7500µs , NEC header space is 4500 +#endif +#define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK) // 160 for RECORD_GAP_MICROS == 8000 + +/** + * microseconds per clock interrupt tick + */ +#if !defined(MICROS_PER_TICK) +#define MICROS_PER_TICK 50 // We do not need it to be 50L!!! It saves 90 bytes for UnitTest compared with 50L :-) #endif + /** * Threshold for warnings at printIRResult*() to report about changing the RECORD_GAP_MICROS value to a higher value. */ #if !defined(RECORD_GAP_MICROS_WARNING_THRESHOLD) -// To change this value, you simply can add a line #define "RECORD_GAP_MICROS_WARNING_THRESHOLD " in your ino file before the line "#include " +// To change this value, you simply can add a line #define "RECORD_GAP_MICROS_WARNING_THRESHOLD " in your *.ino file before the line "#include " #define RECORD_GAP_MICROS_WARNING_THRESHOLD 15000 #endif -/** Minimum gap between IR transmissions, in MICROS_PER_TICK */ -#define RECORD_GAP_TICKS (RECORD_GAP_MICROS / MICROS_PER_TICK) // 100 - /* * Activate this line if your receiver has an external output driver transistor / "inverted" output */ @@ -200,17 +160,18 @@ */ //#define SEND_PWM_BY_TIMER // restricts send pin on many platforms to fixed pin numbers #if (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED) -# if !defined(SEND_PWM_BY_TIMER) -#define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc. -#warning INFO: For ESP32, RP2040, mbed and particle boards SEND_PWM_BY_TIMER is enabled by default. If this is not intended, deactivate the line in IRremote.hpp over this warning message in file IRremote.hpp. +# if defined(SEND_PWM_BY_TIMER) +#pragma message("INFO: For ESP32, RP2040, mbed and particle boards SEND_PWM_BY_TIMER is enabled by default, since we have the resources and timing is more exact than the software generated one.") +# else +#define SEND_PWM_BY_TIMER // the best and default method for ESP32 etc. If you want to use software generated PWM, you must deactivate this line. # endif #else # if defined(SEND_PWM_BY_TIMER) # if defined(IR_SEND_PIN) -#undef IR_SEND_PIN // to avoid warning 3 lines later -#warning Since SEND_PWM_BY_TIMER is defined, the existing value of IR_SEND_PIN is discarded and replaced by the value determined by timer used for PWM generation +#pragma message("INFO: Since SEND_PWM_BY_TIMER is defined, the current value of IR_SEND_PIN \"" STR(IR_SEND_PIN) "\" is discarded and will be replaced in IRTimer.hpp by the value determined by the timer used for PWM generation." ) +//#warning INFO: Since SEND_PWM_BY_TIMER is defined, the current value of IR_SEND_PIN is discarded and will be replaced in IRTimer.hpp by the value determined by the timer used for PWM generation # endif -#define IR_SEND_PIN DeterminedByTimer // must be set here, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp +#define IR_SEND_PIN ToBeOverwrittenLaterByPinNumberDeterminedByTimer // Must be set here to a dummy value, since it is evaluated at IRremoteInt.h, before the include of private/IRTimer.hpp # endif #endif @@ -252,28 +213,38 @@ #define IR_SEND_DUTY_CYCLE_PERCENT 30 // 30 saves power and is compatible to the old existing code #endif -/** - * microseconds per clock interrupt tick - */ -#if ! defined(MICROS_PER_TICK) -#define MICROS_PER_TICK 50L // must be with L to get 32 bit results if multiplied with rawbuf[] content. -#endif - -#define MILLIS_IN_ONE_SECOND 1000L +#define MILLIS_IN_ONE_SECOND 1000U // unused #define MICROS_IN_ONE_SECOND 1000000L -#define MICROS_IN_ONE_MILLI 1000L +#define MICROS_IN_ONE_MILLI 1000U + +#if defined(NO_LED_FEEDBACK_CODE) +// convert to receive and send macros +# if !defined(NO_LED_RECEIVE_FEEDBACK_CODE) +#define NO_LED_RECEIVE_FEEDBACK_CODE +# endif +# if !defined(NO_LED_SEND_FEEDBACK_CODE) +#define NO_LED_SEND_FEEDBACK_CODE +# endif +#endif +#if defined(NO_LED_RECEIVE_FEEDBACK_CODE) && defined(NO_LED_SEND_FEEDBACK_CODE) && !defined(NO_LED_FEEDBACK_CODE) +#define NO_LED_FEEDBACK_CODE +#endif -#include "IRremoteInt.h" /* * We always use digitalWriteFast() and digitalReadFast() functions to have a consistent mapping for pins. * For most non AVR cpu's, it is just a mapping to digitalWrite() and digitalRead() functions. */ +#if !defined(MEGATINYCORE) // megaTinyCore has it own digitalWriteFast function set, except digitalToggleFast(). #include "digitalWriteFast.h" +#endif + +#include "IRremoteInt.h" // definition (or no definition) of IR_SEND_PIN define determines the IRSender function signatures #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE) #include "private/IRTimer.hpp" // defines IR_SEND_PIN for AVR and SEND_PWM_BY_TIMER -# if !defined(NO_LED_FEEDBACK_CODE) +# if !defined(NO_LED_FEEDBACK_CODE) && !(defined(DISABLE_CODE_FOR_RECEIVER) && defined(NO_LED_SEND_FEEDBACK_CODE)) +// Led feedback code enabled here # if !defined(LED_BUILTIN) /* * print a warning @@ -281,6 +252,8 @@ #warning INFO: No definition for LED_BUILTIN found -> default LED feedback is disabled. # endif #include "IRFeedbackLED.hpp" +# else +void disableLEDFeedback() {}; // dummy function for examples # endif #include "LongUnion.h" // used in most decoders @@ -292,6 +265,10 @@ #if !defined(DISABLE_CODE_FOR_RECEIVER) #include "IRReceive.hpp" #endif +// Get absolute value of difference of two unsigned values +#if !defined(uintDifferenceAbs) +#define uintDifferenceAbs(a, b) ((a >= b) ? a - b : b - a) +#endif #include "IRSend.hpp" /* @@ -306,6 +283,7 @@ #include "ir_LG.hpp" #include "ir_MagiQuest.hpp" #include "ir_NEC.hpp" +#include "ir_OpenLASIR.hpp" #include "ir_RC5_RC6.hpp" #include "ir_Samsung.hpp" #include "ir_Sony.hpp" @@ -313,7 +291,7 @@ #include "ir_Others.hpp" #include "ir_Pronto.hpp" // pronto is an universal decoder and encoder # if defined(DECODE_DISTANCE_WIDTH) // universal decoder for pulse distance width protocols - requires up to 750 bytes additional program memory -#include +#include "ir_DistanceWidthProtocol.hpp" # endif #endif // #if !defined(USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE) diff --git a/src/IRremoteInt.h b/src/IRremoteInt.h index 7ff756e33..676cfd423 100644 --- a/src/IRremoteInt.h +++ b/src/IRremoteInt.h @@ -9,7 +9,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2015-2023 Ken Shirriff http://www.righto.com, Rafi Khan, Armin Joachimsmeyer + * Copyright (c) 2015-2026 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 @@ -35,14 +35,17 @@ #include -#define MARK 1 #define SPACE 0 +#define MARK 1 +#define NO_MARK_OR_SPACE 2 // Used as return value for getBiphaselevel() #if defined(PARTICLE) #define F_CPU 16000000 // definition for a board for which F_CPU is not defined #endif #if defined(F_CPU) // F_CPU is used to generate the receive send timings in some CPU's #define CLOCKS_PER_MICRO (F_CPU / MICROS_IN_ONE_SECOND) +#else +#define CLOCKS_PER_MICRO 48 // just a guess if F_CPU is not specified #endif /* @@ -57,31 +60,61 @@ //#define TRACE // Activate this for more debug output. /** - * For better readability of code - */ -#define DISABLE_LED_FEEDBACK false -#define ENABLE_LED_FEEDBACK true -#define USE_DEFAULT_FEEDBACK_LED_PIN 0 - -/** - * 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 + * The RAW_BUFFER_LENGTH determines the length of the byte buffer where the received IR timing data is stored before decoding. + * 100 is sufficient for standard protocols up to 48 bits, with 1 bit consisting of one mark and space plus 1 byte for initial gap, 2 bytes for header and 1 byte for stop bit. + * 48 bit protocols are PANASONIC, KASEIKYO, SAMSUNG48, RC6. + * 32 bit protocols like NEC, SAMSUNG, WHYNTER, SONY(20), LG(28) requires a buffer length of 68. + * 16 bit protocols like BOSEWAVE, DENON, FAST, JVC, LEGO_PF, RC5, SONY(12 or 15) requires a buffer length of 36. + * MAGIQUEST requires a buffer length of 112. + * Air conditioners often send a longer protocol data stream up to 750 bits. + * Default is 100 for 512 bytes RAM, 200 for 2k RAM and 750 for more than 2k RAM */ #if !defined(RAW_BUFFER_LENGTH) -# if defined(DECODE_MAGIQUEST) -#define RAW_BUFFER_LENGTH 112 // MagiQuest requires 112 bytes. -# else +# if (defined(RAMSIZE) && RAMSIZE <= 0x200) || (defined(RAMEND) && RAMEND <= 0x2FF) // assuming RAMSTART at 0x100 +// For RAMSIZE <= 512 bytes #define RAW_BUFFER_LENGTH 100 ///< Length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and 1 stop bit. -//#define RAW_BUFFER_LENGTH 750 // 750 (600 if we have only 2k RAM) is the value for air condition remotes. +# elif (defined(RAMSIZE) && RAMSIZE < 0x8FF) || (defined(RAMEND) && RAMEND <= 0x8FF) // assuming RAMSTART at 0x100 +// For RAMSIZE <= 2k +#define RAW_BUFFER_LENGTH 200 ///< Length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and 1 stop bit. +# else +// For undefined or bigger RAMsize +#define RAW_BUFFER_LENGTH 750 // The value required for air condition remotes. # endif #endif #if RAW_BUFFER_LENGTH % 2 == 1 #error RAW_BUFFER_LENGTH must be even, since the array consists of space / mark pairs. #endif -/**************************************************** +#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR +typedef uint_fast8_t IRRawlenType; +#else +typedef unsigned int IRRawlenType; +#endif + +/* + * We store IR timing values in an 8-bit buffer, where each unit represents 50 ticks. + * Since 8 bits can hold values from 0 to 255, the maximum measurable timing is 255 × 50 ticks = 12750 us. + * + * This means: + * - Any timing up to 12750 us is stored accurately. + * - Any timing greater than 12750 us is clipped and stored as 12750 us. + * - Therefore, you can detect that a timing exceeded 12750 us (because it appears as 12750 us). + * - However, you cannot distinguish between two different timings if both are greater than 12750 us — they will both appear as the same maximum value. + * + * For decoding purposes, 8 bits are acceptable as long as the protocol does not require distinguishing between two different timings + * that are both longer than 12750 us. + * As I am not currently (02/2026) aware of any protocols that require this, we use 8 bits. + * Use a 16-bit buffer if raw timing capture is required and exact values above 12750 us must be preserved. + */ +#if !defined(USE_16_BIT_TIMING_BUFFER) // Use uint16_t buffer for timing. Doubles the RAM requirement. this can be used to override our selection of 8 the bit array +typedef uint8_t IRRawbufType; // all timings up to 12750 us fit into 8 bit (for MICROS_PER_TICK == 50). +#else +typedef uint16_t IRRawbufType; // Use 16 bit array +#endif + +/********************************************************** * Declarations for the receiver Interrupt Service Routine - ****************************************************/ + **********************************************************/ // ISR State-Machine : Receiver States #define IR_REC_STATE_IDLE 0 // Counting the gap time and waiting for the start bit to arrive #define IR_REC_STATE_MARK 1 // A mark was received and we are counting the duration of it. @@ -89,63 +122,71 @@ #define IR_REC_STATE_STOP 3 // Stopped until set to IR_REC_STATE_IDLE which can only be done by resume() /** - * This struct contains the data and control used for receiver static functions and the ISR (interrupt service routine) - * Only StateForISR needs to be volatile. All the other fields are not written by ISR after data available and before start/resume. + * This struct contains the data and control used for receiver functions and the ISR (interrupt service routine) + * Only StateForISR needs to be volatile. All the other fields are not written by ISR after available() == true and before start() / resume(). */ struct irparams_struct { - // The fields are ordered to reduce memory over caused by struct-padding + // The fields are ordered to reduce memory overflow caused by struct-padding volatile uint8_t StateForISR; ///< State Machine state uint_fast8_t IRReceivePin; ///< Pin connected to IR data from detector #if defined(__AVR__) volatile uint8_t *IRReceivePinPortInputRegister; uint8_t IRReceivePinMask; #endif - volatile uint_fast16_t TickCounterForISR; ///< Counts 50uS ticks. The value is copied into the rawbuf array on every transition. -#if !IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK + volatile uint_fast16_t TickCounterForISR; ///< Counts 50uS ticks. The value is copied into the rawbuf array on every transition. Counting is independent of state or resume(). +#if !defined(IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK) void (*ReceiveCompleteCallbackFunction)(void); ///< The function to call if a protocol message has arrived, i.e. StateForISR changed to IR_REC_STATE_STOP #endif - bool OverflowFlag; ///< Raw buffer OverflowFlag occurred -#if RAW_BUFFER_LENGTH <= 254 // saves around 75 bytes program memory and speeds up ISR - uint_fast8_t rawlen; ///< counter of entries in rawbuf -#else - uint_fast16_t rawlen; ///< counter of entries in rawbuf +#if defined(DECODE_RC5) || defined(DECODE_RC6) || defined(DECODE_MARANTZ) + // Static variables for the getBiphaselevel() function + uint_fast8_t RawbuffOffsetForNextBiphaseLevel; // Index into raw timing array + uint16_t NumberOfTimingIntervalsInCurrentInterval; // 1, 2 or 3. Number of aBiphaseTimeUnit intervals of the current rawbuf[RawbuffOffsetForNextBiphaseLevel] timing. + uint_fast8_t AlreadyUsedTimingIntervalsOfCurrentInterval; // Number of already used intervals of sCurrentTimingIntervals. + uint16_t BiphaseTimeUnit; #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 + bool OverflowFlag; ///< Raw buffer OverflowFlag occurred + IRRawlenType rawlen; ///< counter of entries in rawbuf + uint16_t initialGapTicks; ///< Tick counts of the length of the gap between previous and current IR frame. Pre 4.4: rawbuf[0]. + IRRawbufType rawbuf[RAW_BUFFER_LENGTH]; ///< raw data / tick counts per mark/space. With 8 bit we can only store up to 12.7 ms. First entry is empty to be backwards compatible. }; #if (__INT_WIDTH__ < 32) -typedef uint32_t IRRawDataType; -#define BITS_IN_RAW_DATA_TYPE 32 +typedef uint32_t IRDecodedRawDataType; +#define BITS_IN_DECODED_RAW_DATA_TYPE 32 #else -typedef uint64_t IRRawDataType; -#define BITS_IN_RAW_DATA_TYPE 64 +typedef uint64_t IRDecodedRawDataType; +#define BITS_IN_DECODED_RAW_DATA_TYPE 64 #endif -#include "IRProtocol.h" +typedef IRDecodedRawDataType IRRawDataType; // Define old IRRawDataType (removed in 4.6.0) for backward compatibility -/* - * Debug directives - */ -#if defined(DEBUG) || defined(TRACE) -# define IR_DEBUG_PRINT(...) Serial.print(__VA_ARGS__) -# define IR_DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__) -#else +#define DECODED_RAW_DATA_ARRAY_SIZE ((((RAW_BUFFER_LENGTH - 2) - 1) / (2 * BITS_IN_DECODED_RAW_DATA_TYPE)) + 1) // The -2 is for initial gap + stop bit mark, 128 mark + spaces for 64 bit. /** - * If DEBUG, print the arguments, otherwise do nothing. + * Data structure for the user application, available as decodedIRData. + * Filled by decoders and read by print functions or user application. */ -# define IR_DEBUG_PRINT(...) void() -/** - * If DEBUG, print the arguments as a line, otherwise do nothing. - */ -# define IR_DEBUG_PRINTLN(...) void() +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. + IRDecodedRawDataType decodedRawData; ///< Up to 32/64 bit decoded raw data, to be used for sendRaw functions. +#if defined(DECODE_DISTANCE_WIDTH) + // This replaces the address, command, extra and decodedRawData in case of protocol == PULSE_DISTANCE or -rather seldom- protocol == PULSE_WIDTH. + DistanceWidthTimingInfoStruct DistanceWidthTimingInfo; // 12 bytes + IRDecodedRawDataType decodedRawDataArray[DECODED_RAW_DATA_ARRAY_SIZE]; ///< 32/64 bit decoded raw data, to be used for sendPulseDistanceWidthFromArray functions. #endif + uint16_t numberOfBits; ///< Number of bits received for data (address + command + parity) - to determine protocol length if different length are possible. + uint8_t flags; ///< IRDATA_FLAGS_IS_REPEAT, IRDATA_FLAGS_WAS_OVERFLOW etc. See IRDATA_FLAGS_* definitions above -#if defined(TRACE) -# define IR_TRACE_PRINT(...) Serial.print(__VA_ARGS__) -# define IR_TRACE_PRINTLN(...) Serial.println(__VA_ARGS__) -#else -# define IR_TRACE_PRINT(...) void() -# define IR_TRACE_PRINTLN(...) void() -#endif + /* + * These 2 variables allow to call resume() directly after decode. + * After resume(), irparams.initialGapTicks and irparams.rawlen are + * the first variables, which are overwritten by the next received frame. + * since 4.3.0. + */ + IRRawlenType rawlen; ///< Counter of entries in rawbuf of last received frame. + uint16_t initialGapTicks; ///< Contains the initial gap (pre 4.4: the value in rawbuf[0]) of the last received frame. +}; /**************************************************** * RECEIVING @@ -162,23 +203,39 @@ struct decode_results { 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 - uint_fast8_t rawlen; // deprecated, moved to decodedIRData.rawDataPtr->rawlen ///< Number of records in rawbuf +// next 3 values are copies of irparams_struct values - see above + uint16_t *rawbuf; // deprecated, moved to irparams.rawbuf ///< Raw intervals in 50uS ticks + uint_fast8_t rawlen; // deprecated, moved to irparams.rawlen ///< Number of records in rawbuf bool overflow; // deprecated, moved to decodedIRData.flags ///< true if IR raw code too long }; +extern unsigned long sMicrosAtLastStopTimer; // Used to adjust TickCounterForISR with uncounted ticks between stopTimer() and restartTimer() + /** * Main class for receiving IR signals */ +#define USE_DEFAULT_FEEDBACK_LED_PIN 0xFF // we need it here class IRrecv { public: IRrecv(); +#if defined(SUPPORT_MULTIPLE_RECEIVER_INSTANCES) IRrecv(uint_fast8_t aReceivePin); IRrecv(uint_fast8_t aReceivePin, uint_fast8_t aFeedbackLEDPin); +#else + IRrecv( + uint_fast8_t aReceivePin) + __attribute__ ((deprecated ("Please use the default IRrecv instance \"IrReceiver\" and IrReceiver.begin(), and not your own IRrecv instance."))); + IRrecv(uint_fast8_t aReceivePin, + uint_fast8_t aFeedbackLEDPin) + __attribute__ ((deprecated ("Please use the default IRrecv instance \"IrReceiver\" and IrReceiver.begin(), and not your own IRrecv instance.."))); +#endif void setReceivePin(uint_fast8_t aReceivePinNumber); +#if !defined(IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK) void registerReceiveCompleteCallback(void (*aReceiveCompleteCallbackFunction)(void)); +#endif + void ReceiveInterruptHandler(); + /* * Stream like API */ @@ -186,17 +243,16 @@ class IRrecv { USE_DEFAULT_FEEDBACK_LED_PIN); void start(); void enableIRIn(); // alias for start - void start(uint32_t aMicrosecondsToAddToGapCounter); - void startWithTicksToAdd(uint16_t aTicksToAddToGapCounter); + void restartTimer(); + void restartTimer(uint32_t aMicrosecondsToAddToGapCounter); + void restartTimerWithTicksToAdd(uint16_t aTicksToAddToGapCounter); void restartAfterSend(); - void addTicksToInternalTickCounter(uint16_t aTicksToAddToInternalTickCounter); - void addMicrosToInternalTickCounter(uint16_t aMicrosecondsToAddToInternalTickCounter); - bool available(); IRData* read(); // returns decoded data // write is a method of class IRsend below // size_t write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats = NO_REPEATS); + void stopTimer(); void stop(); void disableIRIn(); // alias for stop void end(); // alias for stop @@ -213,14 +269,20 @@ class IRrecv { * Useful info and print functions */ void printIRResultMinimal(Print *aSerial); + void printIRDuration(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks); void printIRResultRawFormatted(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks = true); void printIRResultAsCVariables(Print *aSerial); + uint8_t getMaximumMarkTicksFromRawData(); + uint8_t getMaximumSpaceTicksFromRawData(); + uint8_t getMaximumTicksFromRawData(bool aSearchSpaceInsteadOfMark); uint32_t getTotalDurationOfRawData(); /* * Next 4 functions are also available as non member functions */ - bool printIRResultShort(Print *aSerial, bool aPrintRepeatGap = true, bool aCheckForRecordGapsMicros = true); + bool printIRResultShort(Print *aSerial, bool aPrintRepeatGap, bool aCheckForRecordGapsMicros) + __attribute__ ((deprecated ("Remove second parameter, it is not supported any more."))); + bool printIRResultShort(Print *aSerial, bool aCheckForRecordGapsMicros = true); void printDistanceWidthTimingInfo(Print *aSerial, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo); void printIRSendUsage(Print *aSerial); #if defined(__AVR__) @@ -230,6 +292,7 @@ class IRrecv { #endif static void printActiveIRProtocols(Print *aSerial); + void printIRResultAsCArray(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks = true, bool aDoCompensate = true); void compensateAndPrintIRResultAsCArray(Print *aSerial, bool aOutputMicrosecondsInsteadOfTicks = true); void compensateAndPrintIRResultAsPronto(Print *aSerial, uint16_t frequency = 38000U); @@ -242,17 +305,38 @@ class IRrecv { /* * The main decoding functions used by the individual decoders */ - bool decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, - uint_fast8_t aStartOffset = 3); +#if defined(USE_STRICT_DECODER) + bool +#else + void +#endif + decodePulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, uint_fast8_t aNumberOfBits, + IRRawlenType aStartOffset = 3); + + void decodePulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset = 3); + + void decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMicros, + bool aIsPulseWidthProtocol, bool aMSBfirst); - bool decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset, uint16_t aOneMarkMicros, - uint16_t aZeroMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst); + void decodeWithThresholdPulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, + uint16_t aOneThresholdMicros, bool aIsPulseWidthProtocol, bool aMSBfirst); - bool decodeBiPhaseData(uint_fast8_t aNumberOfBits, uint_fast8_t aStartOffset, uint_fast8_t aStartClockCount, - uint_fast8_t aValueOfSpaceToMarkTransition, uint16_t aBiphaseTimeUnit); + void decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, bool aMSBfirst); + void decodePulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aZeroMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst) + __attribute__ ((deprecated ("Please use decodePulseDistanceWidthData() with 6 parameters."))); + + bool decodeStrictPulseDistanceWidthData(uint_fast8_t aNumberOfBits, IRRawlenType aStartOffset, uint16_t aOneMarkMicros, + uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, bool aMSBfirst); + +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) || defined(DECODE_RC6) void initBiphaselevel(uint_fast8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit); + static uint8_t getNumberOfUnitsInInterval(uint16_t aCurrentInterval, uint16_t aTimeUnit); uint_fast8_t getBiphaselevel(); +#endif /* * All standard (decode address + command) protocol decoders @@ -267,8 +351,13 @@ class IRrecv { bool decodeLG(); bool decodeMagiQuest(); // not completely standard bool decodeNEC(); + bool decodeOpenLASIR(); +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) bool decodeRC5(); +#endif +#if defined(DECODE_RC6) bool decodeRC6(); +#endif bool decodeSamsung(); bool decodeSharp(); // redirected to decodeDenon() bool decodeSony(); @@ -309,27 +398,43 @@ class IRrecv { void initDecodedIRData(); uint_fast8_t compare(uint16_t oldval, uint16_t newval); bool checkHeader(PulseDistanceWidthProtocolConstants *aProtocolConstants); + bool checkHeader_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM); void checkForRepeatSpaceTicksAndSetFlag(uint16_t aMaximumRepeatSpaceTicks); bool checkForRecordGapsMicros(Print *aSerial); - IRData decodedIRData; // New: decoded IR data for the application + irparams_struct irparams; + IRData decodedIRData; // Decoded IR data for the application - // Last decoded IR data for repeat detection and parity for Denon autorepeat + // Last decoded IR data for repeat detection and to fill in JVC, LG, NEC repeat values. Parity for Denon autorepeat decode_type_t lastDecodedProtocol; - uint32_t lastDecodedAddress; - uint32_t lastDecodedCommand; + uint16_t lastDecodedAddress; + uint16_t lastDecodedCommand; +#if defined(DECODE_DISTANCE_WIDTH) + IRDecodedRawDataType lastDecodedRawData; +#endif uint8_t repeatCount; // Used e.g. for Denon decode for autorepeat decoding. }; -extern uint_fast8_t sBiphaseDecodeRawbuffOffset; // +void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintRepeatGap) + __attribute__ ((deprecated ("Remove last parameter, it is not supported any more."))); +void printIRResultShort(Print *aSerial, IRData *aIRDataPtr) + __attribute__ ((deprecated ("Use member function or printIRDataShort() instead."))); +; +// A static function to be able to print send or copied received data. +void printIRDataShort(Print *aSerial, IRData *aIRDataPtr); /* * Mark & Space matching functions */ bool matchTicks(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); +bool matchTicks(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros, int16_t aCompensationMicrosForTicks); bool matchMark(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); bool matchSpace(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); +bool matchTicksWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); +bool matchTicksWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros, int16_t aCompensationMicrosForTicks); +bool matchMarkWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); +bool matchSpaceWithGreaterRange(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros); /* * Old function names @@ -345,13 +450,12 @@ void printActiveIRProtocols(Print *aSerial); /**************************************************** * Feedback LED related functions ****************************************************/ -#define DO_NOT_ENABLE_LED_FEEDBACK 0x00 -#define LED_FEEDBACK_DISABLED_COMPLETELY 0x00 -#define LED_FEEDBACK_ENABLED_FOR_RECEIVE 0x01 -#define LED_FEEDBACK_ENABLED_FOR_SEND 0x02 -void setFeedbackLED(bool aSwitchLedOn); -void setLEDFeedback(uint8_t aFeedbackLEDPin, uint8_t aEnableLEDFeedback); // if aFeedbackLEDPin == 0, then take board BLINKLED_ON() and BLINKLED_OFF() functions +#define DISABLE_LED_FEEDBACK false +#define ENABLE_LED_FEEDBACK true +//#define USE_DEFAULT_FEEDBACK_LED_PIN 0 // repeated definition for info void setLEDFeedback(bool aEnableLEDFeedback); // Direct replacement for blink13() +void setLEDFeedbackPin(uint8_t aFeedbackLEDPin); +void setFeedbackLED(bool aSwitchLedOn); void enableLEDFeedback(); constexpr auto enableLEDFeedbackForReceive = enableLEDFeedback; // alias for enableLEDFeedback void disableLEDFeedback(); @@ -366,23 +470,21 @@ void setBlinkPin(uint8_t aFeedbackLEDPin) __attribute__ ((deprecated ("Please us * First MARK is the one after the long gap * Pulse parameters in microseconds */ -#if !defined(TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING) -#define TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING 25 // Relative tolerance (in percent) for matchTicks(), matchMark() and matchSpace() functions used for protocol decoding. +#if !defined(TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT) +#define TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT 25 // Relative tolerance (in percent) for matchTicks(), matchMark() and matchSpace() functions used for protocol decoding. #endif +#define TICKS(us) ((us)/MICROS_PER_TICK) // (us)/50 +#if MICROS_PER_TICK == 50 && TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT == 25 // Defaults +#define TICKS_LOW(us) ((us)/67 ) // =(us * 0.75 /MICROS_PER_TICK), 67 = MICROS_PER_TICK / ((100-25)/100) = (MICROS_PER_TICK * 100) / (100-25) +#define TICKS_HIGH(us) (((us)/40) + 1) // =(us * 1,25 /MICROS_PER_TICK), 40 = MICROS_PER_TICK / ((100+25)/100) = (MICROS_PER_TICK * 100) / (100+25) +#else /** Lower tolerance for comparison of measured data */ //#define LTOL (1.0 - (TOLERANCE/100.)) -#define LTOL (100 - TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING) +#define LTOL (100 - TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT) /** Upper tolerance for comparison of measured data */ //#define UTOL (1.0 + (TOLERANCE/100.)) -#define UTOL (100 + TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING) - -//#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_FOR_DECODERS_MARK_OR_SPACE_MATCHING == 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 UTOL (100 + TOLERANCE_FOR_DECODERS_MARK_OR_SPACE_MATCHING_PERCENT) #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 @@ -415,23 +517,22 @@ class IRsend { IRsend(); /* - * IR_SEND_PIN is defined + * IR_SEND_PIN is defined or fixed by timer, value of IR_SEND_PIN is then "DeterminedByTimer" */ #if defined(IR_SEND_PIN) void begin(); - void begin(bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin = USE_DEFAULT_FEEDBACK_LED_PIN); - // The next function is a dummy to avoid acceptance of pre 4.0 calls to begin(IR_SEND_PIN, DISABLE_LED_FEEDBACK); - void begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback) -# if !defined (DOXYGEN) - __attribute__ ((deprecated ("You must use begin(ENABLE_LED_FEEDBACK) or begin(DISABLE_LED_FEEDBACK) since version 4.0."))); -# endif + // The default parameter allowed to specify IrSender.begin(7); without errors, if IR_SEND_PIN was defined. But the semantics is not the one the user expect. + void begin(uint_fast8_t aFeedbackLEDPin); #else IRsend(uint_fast8_t aSendPin); void begin(uint_fast8_t aSendPin); void setSendPin(uint_fast8_t aSendPin); // required if we use IRsend() as constructor - // Since 4.0 guarded and without default parameter - void begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin); // aFeedbackLEDPin can be USE_DEFAULT_FEEDBACK_LED_PIN #endif + void begin(uint_fast8_t aSendPin, uint_fast8_t aFeedbackLEDPin); // aFeedbackLEDPin is by default USE_DEFAULT_FEEDBACK_LED_PIN + void begin(uint_fast8_t aSendPin, bool aEnableLEDFeedback, uint_fast8_t aFeedbackLEDPin) +# if !defined (DOXYGEN) + __attribute__ ((deprecated ("Use begin(aSendPin, aFeedbackLEDPin) instead."))); +# endif size_t write(IRData *aIRSendData, int_fast8_t aNumberOfRepeats = NO_REPEATS); size_t write(decode_type_t aProtocol, uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats = NO_REPEATS); @@ -441,40 +542,48 @@ class IRsend { void enableHighFrequencyIROut(uint_fast16_t aFrequencyKHz); // Used for Bang&Olufsen #endif + /* + * Array functions + */ void sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); - void sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, + void sendPulseDistanceWidthFromPGMArray(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit, - uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) - __attribute__ ((deprecated ("Since version 4.1.0 parameter aSendStopBit is not longer required."))); + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, uint8_t aFlags, + uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); void sendPulseDistanceWidthFromArray(PulseDistanceWidthProtocolConstants *aProtocolConstants, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthFromPGMArray(PulseDistanceWidthProtocolConstants *aProtocolConstants, + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthFromArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthFromPGMArray_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, + IRDecodedRawDataType const *aDecodedRawDataPGMArray, uint16_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, DistanceWidthTimingInfoStruct *aDistanceWidthTimingInfo, - IRRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + IRDecodedRawDataType *aDecodedRawDataArray, uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthFromArray_P(uint_fast8_t aFrequencyKHz, + DistanceWidthTimingInfoStruct const *aDistanceWidthTimingInfoPGM, IRDecodedRawDataType *aDecodedRawDataArray, + uint16_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); - void sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, + void sendPulseDistanceWidth(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats); - void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRRawDataType aData, + void sendPulseDistanceWidth_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, + uint_fast8_t aNumberOfBits, int_fast8_t aNumberOfRepeats); + void sendPulseDistanceWidthData(PulseDistanceWidthProtocolConstants *aProtocolConstants, IRDecodedRawDataType aData, + uint_fast8_t aNumberOfBits); + void sendPulseDistanceWidthData_P(PulseDistanceWidthProtocolConstants const *aProtocolConstantsPGM, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits); void sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, - int_fast8_t aNumberOfRepeats, void (*aSpecialSendRepeatFunction)() = NULL); - void sendPulseDistanceWidth(uint_fast8_t aFrequencyKHz, uint16_t aHeaderMarkMicros, uint16_t aHeaderSpaceMicros, - uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, uint16_t aZeroSpaceMicros, - IRRawDataType aData, uint_fast8_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit, uint16_t aRepeatPeriodMillis, - int_fast8_t aNumberOfRepeats, void (*aSpecialSendRepeatFunction)() = NULL) - __attribute__ ((deprecated ("Since version 4.1.0 parameter aSendStopBit is not longer required."))); - void sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, - uint16_t aZeroSpaceMicros, IRRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags); + IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags, uint16_t aRepeatPeriodMillis, + int_fast8_t aNumberOfRepeats, void (*aSpecialSendRepeatFunction)() = nullptr); void sendPulseDistanceWidthData(uint16_t aOneMarkMicros, uint16_t aOneSpaceMicros, uint16_t aZeroMarkMicros, - uint16_t aZeroSpaceMicros, IRRawDataType aData, uint_fast8_t aNumberOfBits, bool aMSBFirst, bool aSendStopBit) - __attribute__ ((deprecated ("Since version 4.1.0 last parameter aSendStopBit is not longer required."))); - void sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits); + uint16_t aZeroSpaceMicros, IRDecodedRawDataType aData, uint_fast8_t aNumberOfBits, uint8_t aFlags); + void sendBiphaseData(uint16_t aBiphaseTimeUnit, uint32_t aData, uint_fast8_t aNumberOfBits, bool aSendStartBit = true); void mark(uint16_t aMarkMicros); static void space(uint16_t aSpaceMicros); @@ -482,11 +591,19 @@ class IRsend { // 8 Bit array void sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); - void sendRaw_P(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); + void sendRaw_P(const uint8_t aPGMBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); + void sendRaw(const uint8_t aBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); + void sendRaw_P(const uint8_t aPGMBufferWithTicks[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); // 16 Bit array void sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); - void sendRaw_P(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); + void sendRaw_P(const uint16_t aPGMBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz); + void sendRaw(const uint16_t aBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); + void sendRaw_P(const uint16_t aPGMBufferWithMicroseconds[], uint_fast16_t aLengthOfBuffer, uint_fast8_t aIRFrequencyKilohertz, + uint_fast16_t aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats); /* * New send functions @@ -499,29 +616,36 @@ class IRsend { void sendBangOlufsenRawDataLink(uint64_t aRawData, int_fast8_t aBits, bool aBackToBack = false, bool aUseDatalinkTiming = false); void sendBoseWave(uint8_t aCommand, int_fast8_t aNumberOfRepeats = NO_REPEATS); - void sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aSendSharp = false); + void sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aSendSharpFrameMarker = 0); void sendDenonRaw(uint16_t aRawData, int_fast8_t aNumberOfRepeats = NO_REPEATS) -#if !defined (DOXYGEN) __attribute__ ((deprecated ("Please use sendDenon(aAddress, aCommand, aNumberOfRepeats)."))); -#endif void sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats); void sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); - void sendLG2Repeat(); + void sendLGRepeat(); uint32_t computeLGRawDataAndChecksum(uint8_t aAddress, uint16_t aCommand); void sendLG(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); - void sendLG2(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); void sendLGRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats = NO_REPEATS); void sendNECRepeat(); uint32_t computeNECRawDataAndChecksum(uint16_t aAddress, uint16_t aCommand); - void sendNEC(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); - void sendNEC2(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); + void sendNEC(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); + void sendNEC2(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); void sendNECRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats = NO_REPEATS); // NEC variants void sendOnkyo(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); void sendApple(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); + void sendOpenLASIRRepeat(); + uint32_t computeOpenLASIRRawDataAndChecksum(uint8_t aAddress, uint16_t aCommand); + uint16_t computeOpenLASIRRawCommand(uint8_t aDeviceID, uint8_t aMode, uint8_t aData); + void sendOpenLASIR(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); + void sendOpenLASIR(uint8_t aAddress, uint8_t aDeviceID, uint8_t aMode, uint8_t aData, int_fast8_t aNumberOfRepeats); + void sendOpenLASIRRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats = NO_REPEATS); +#define OpenLASIR_GetMDeviceId(aCommand) (aCommand & 0xFF) +#define OpenLASIR_GetMode(aCommand) ((aCommand >> 8) & 0x1F) +#define OpenLASIR_GetData(aCommand) (aCommand >> 13) + void sendKaseikyo(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats, uint16_t aVendorCode); // LSB first void sendPanasonic(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats); // LSB first void sendKaseikyo_Denon(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats); // LSB first @@ -529,13 +653,21 @@ class IRsend { void sendKaseikyo_Sharp(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats); // LSB first void sendKaseikyo_JVC(uint16_t aAddress, uint8_t aData, int_fast8_t aNumberOfRepeats); // LSB first + void setNextToggleBitValueForRC5AndRC6(uint8_t aRC5ToggleBitValue); void sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle = true); + void sendRC5Marantz(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aMarantzExtension, + bool aEnableAutomaticToggle = true); void sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle = true); + void sendRC6A(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint16_t aCustomer, + bool aEnableAutomaticToggle = true); void sendSamsungLGRepeat(); void sendSamsung(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); + void sendSamsung16BitAddressAnd8BitCommand(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); + void sendSamsung16BitAddressAndCommand(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); void sendSamsung48(uint16_t aAddress, uint32_t aCommand, int_fast8_t aNumberOfRepeats); void sendSamsungLG(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats); void sendSharp(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); // redirected to sendDenon + void sendSharp2(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats); // redirected to sendDenon void sendSony(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t numberOfBits = 12); // SIRCS_12_PROTOCOL void sendLegoPowerFunctions(uint8_t aChannel, uint8_t tCommand, uint8_t aMode, bool aDoSend5Times = true); @@ -580,22 +712,32 @@ class IRsend { sendNECMSB(aRawData, nbits); } void sendNECMSB(uint32_t data, uint8_t nbits, bool repeat = false); - void sendRC5(uint32_t data, uint8_t nbits); - void sendRC5ext(uint8_t addr, uint8_t cmd, bool toggle); + void sendRC5(uint32_t data, + uint8_t nbits) + __attribute__ ((deprecated ("Please use sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) instead."))); + ; + void sendRC5ext(uint8_t addr, uint8_t cmd, + bool toggle) + __attribute__ ((deprecated ("Please use sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) instead."))); + ; void sendRC6Raw(uint32_t data, uint8_t nbits); void sendRC6(uint32_t data, uint8_t nbits) __attribute__ ((deprecated ("Please use sendRC6Raw()."))); void sendRC6Raw(uint64_t data, uint8_t nbits); void sendRC6(uint64_t data, uint8_t nbits) __attribute__ ((deprecated ("Please use sendRC6Raw()."))); - ; + void sendSharpRaw(unsigned long data, int nbits); void sendSharp(uint16_t address, uint16_t command); void sendSAMSUNG(unsigned long data, int nbits); __attribute__ ((deprecated ("This old function sends MSB first! Please use sendSamsung()."))); + void sendSamsungMSB(unsigned long data, int nbits); + void sendSonyMSB(unsigned long data, int nbits); void sendSony(unsigned long data, int nbits) __attribute__ ((deprecated ("This old function sends MSB first! Please use sendSony(aAddress, aCommand, aNumberOfRepeats)."))); - ; - void sendWhynter(uint32_t aData, uint8_t aNumberOfBitsToSend); + + void sendWhynter(uint32_t aData, int_fast8_t aNumberOfRepeats); + void sendVelux(uint8_t aCommand, uint8_t aMotorNumber, uint8_t aMotorSet, uint16_t aSecurityCode, int_fast8_t aNumberOfRepeats); + void sendVelux(uint32_t aData, int_fast8_t aNumberOfRepeats); #if !defined(IR_SEND_PIN) uint8_t sendPin; @@ -613,7 +755,8 @@ class IRsend { extern IRsend IrSender; void sendNECSpecialRepeat(); -void sendLG2SpecialRepeat(); +void sendOpenLASIRSpecialRepeat(); +void sendLGSpecialRepeat(); void sendSamsungLGSpecialRepeat(); #endif // _IR_REMOTE_INT_H diff --git a/src/LocalDebugLevelEnd.h b/src/LocalDebugLevelEnd.h new file mode 100644 index 000000000..e1f1de534 --- /dev/null +++ b/src/LocalDebugLevelEnd.h @@ -0,0 +1,44 @@ +/* + * LocalDebugLevelEnd.h + * Undefine local macros at the end of an included (.hpp) file + * + * Copyright (C) 2024 Armin Joachimsmeyer + * + * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. + * + * Arduino-Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public INFOse for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Undefine local macros at the end of an included (.hpp) file + */ +#if defined(LOCAL_TRACE) +#undef LOCAL_TRACE +#endif +#undef TRACE_PRINT +#undef TRACE_PRINTLN +#undef TRACE_FLUSH +#if defined(LOCAL_DEBUG) +#undef LOCAL_DEBUG +#endif +#undef DEBUG_PRINT +#undef DEBUG_PRINTLN +#undef DEBUG_FLUSH +#if defined(LOCAL_INFO) +#undef LOCAL_INFO +#endif +#undef INFO_PRINT +#undef INFO_PRINTLN +#undef INFO_FLUSH diff --git a/src/LocalDebugLevelStart.h b/src/LocalDebugLevelStart.h new file mode 100644 index 000000000..9427af71e --- /dev/null +++ b/src/LocalDebugLevelStart.h @@ -0,0 +1,93 @@ +/* + * LocalDebugLevelStart.h + * Include to propagate global debug levels to file local ones and to define appropriate print macros. + * !!! If used in included (.hpp) files, #include "LocalDebugLevelEnd.h" must be used at end of file to undefine local macros. + * If, for example, #define LOCAL_TRACE is placed before this include, it will not be propagated. This enables TRACE-level output to be selected only. + * + * LOCAL_TRACE // Information you need to understand details of a function or if you hunt a bug. + * LOCAL_DEBUG // Information need to understand the operating of your program. E.g. function calls and values of control variables. + * LOCAL_INFO // Information you want to see in regular operation to see what the program is doing. E.g. "Now playing Muppets melody". + * LOCAL_WARN // Information that the program may encounter problems, like small Heap/Stack area. + * LOCAL_ERROR // Informations to explain why the program will not run. E.g. not enough Ram for all created objects. + * + * Copyright (C) 2024-2026 Armin Joachimsmeyer + * + * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. + * + * Arduino-Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public INFOse for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/////////////// put this before the include ///////////////////////// +// This block must be located after the includes of other *.hpp files +//#define LOCAL_INFO // This enables info output only for this file +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development + +/* + * Propagate debug level to local ones but at first not to each other, i.e. enabling TRACE does not enable DEBUG and INFO + */ +#if defined(TRACE) // Information you need to understand details of a function or if you hunt a bug. +#define LOCAL_TRACE +# if !defined(DO_NOT_PROPAGATE_DEBUG_LEVELS) // Propagate levels by default i.e. enabling TRACE does enable DEBUG and INFO +#define LOCAL_DEBUG +#define LOCAL_INFO +# endif +#endif + +#if defined(DEBUG) // Information need to understand the operating of your program. E.g. function calls and values of control variables. +#define LOCAL_DEBUG +# if !defined(DO_NOT_PROPAGATE_DEBUG_LEVELS) +#define LOCAL_INFO +# endif +#endif + +#if defined(INFO) // Information you want to see in regular operation to see what the program is doing. E.g. "START ../src/LightToTone.cpp Version 1.2 from Dec 31 2019" or "Now playing Muppets melody". +#define LOCAL_INFO +#endif + +/* + * Define appropriate print macros + */ +#if defined(LOCAL_TRACE) +#define TRACE_PRINT(...) Serial.print(__VA_ARGS__) +#define TRACE_PRINTLN(...) Serial.println(__VA_ARGS__) +#define TRACE_FLUSH() Serial.flush() +#else +#define TRACE_PRINT(...) void() +#define TRACE_PRINTLN(...) void() +#define TRACE_FLUSH() void() +#endif + +#if defined(LOCAL_DEBUG) +#define DEBUG_PRINT(...) Serial.print(__VA_ARGS__) +#define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__) +#define DEBUG_FLUSH() Serial.flush() +#else +#define DEBUG_PRINT(...) void() +#define DEBUG_PRINTLN(...) void() +#define DEBUG_FLUSH() void() + +#endif + +#if defined(LOCAL_INFO) +#define INFO_PRINT(...) Serial.print(__VA_ARGS__) +#define INFO_PRINTLN(...) Serial.println(__VA_ARGS__) +#define INFO_FLUSH() Serial.flush() +#else +#define INFO_PRINT(...) void() +#define INFO_PRINTLN(...) void() +#define INFO_FLUSH() void() +#endif + diff --git a/src/LongUnion.h b/src/LongUnion.h index 1e09695ee..ce4837085 100644 --- a/src/LongUnion.h +++ b/src/LongUnion.h @@ -2,7 +2,6 @@ * LongUnion.h * * Copyright (C) 2020-2022 Armin Joachimsmeyer - * Email: armin.joachimsmeyer@gmail.com * * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. * @@ -87,13 +86,14 @@ union LongUnion { struct { WordUnion LowWord; WordUnion HighWord; - } WordUnion; + } TwoWordUnions; uint8_t UBytes[4]; // seems to have the same code size as using struct UByte int8_t Bytes[4]; // Bytes[0] is LowByte uint16_t UWords[2]; int16_t Words[2]; uint32_t ULong; int32_t Long; + float Float; }; #endif // _LONG_UNION_H @@ -121,7 +121,7 @@ union LongLongUnion { WordUnion MidLowWord; WordUnion MidHighWord; WordUnion HighWord; - } WordUnion; + } FourWordUnions; struct { uint32_t LowLong; uint32_t HighLong; @@ -133,13 +133,19 @@ union LongLongUnion { struct { LongUnion LowLong; LongUnion HighLong; - } LongUnion; + } TwoLongUnions; uint8_t UBytes[8]; // seems to have the same code size as using struct UByte int8_t Bytes[8]; uint16_t UWords[4]; int16_t Words[4]; uint64_t ULongLong; int64_t LongLong; +#if __DBL_MANT_DIG__== 24 + float Floats[2]; // 32 bit double, as for AVR +#else + // 64 bit double + double Double; +#endif }; #endif // _LONG_LONG_UNION_H diff --git a/src/TinyIR.h b/src/TinyIR.h index cc17bc357..f56877fd8 100644 --- a/src/TinyIR.h +++ b/src/TinyIR.h @@ -2,11 +2,10 @@ * TinyIR.h * * - * Copyright (C) 2021-2023 Armin Joachimsmeyer - * armin.joachimsmeyer@gmail.com + * Copyright (C) 2021-2025 Armin Joachimsmeyer * - * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. * * TinyIRReceiver is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,13 +29,13 @@ #include "LongUnion.h" -/** \addtogroup TinyReceiver Minimal receiver for NEC and FAST protocol +/** \addtogroup TinyIRReceiver Minimal receiver for NEC and FAST protocol * @{ */ -#define VERSION_TINYIR "1.2.0" -#define VERSION_TINYIR_MAJOR 1 -#define VERSION_TINYIR_MINOR 2 +#define VERSION_TINYIR "2.3.0" +#define VERSION_TINYIR_MAJOR 2 +#define VERSION_TINYIR_MINOR 3 #define VERSION_TINYIR_PATCH 0 // The change log is at the bottom of the file @@ -53,14 +52,14 @@ #define NEC_UNIT 560 -#define NEC_HEADER_MARK (16 * NEC_UNIT) // 9000 -#define NEC_HEADER_SPACE (8 * NEC_UNIT) // 4500 +#define NEC_HEADER_MARK (16 * NEC_UNIT) // 8860 +#define NEC_HEADER_SPACE (8 * NEC_UNIT) // 4480 #define NEC_BIT_MARK NEC_UNIT -#define NEC_ONE_SPACE (3 * NEC_UNIT) // 1690 +#define NEC_ONE_SPACE (3 * NEC_UNIT) // 1680 #define NEC_ZERO_SPACE NEC_UNIT -#define NEC_REPEAT_HEADER_SPACE (4 * NEC_UNIT) // 2250 +#define NEC_REPEAT_HEADER_SPACE (4 * NEC_UNIT) // 2240 #define NEC_REPEAT_PERIOD 110000 // Commands are repeated every 110 ms (measured from start to start) for as long as the key on the remote control is held down. #define NEC_MINIMAL_DURATION 49900 // NEC_HEADER_MARK + NEC_HEADER_SPACE + 32 * 2 * NEC_UNIT + NEC_UNIT // 2.5 because we assume more zeros than ones @@ -77,15 +76,15 @@ * - Repeats are sent as complete frames but in a 50 ms period / with a 21 ms distance. */ /* -Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first + Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first +2100,-1050 + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500 + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500 + 550,-1550 + 550,- 500 + 550,- 500 + 550,-1550 + 550,- 500 + 550,- 500 + 550,- 500 + 550,-1550 + 550 -Sum: 28900 -*/ + Sum: 28900 + */ #define FAST_KHZ 38 #define FAST_ADDRESS_BITS 0 // No address #define FAST_COMMAND_BITS 16 // Command and inverted command (parity) @@ -122,10 +121,12 @@ Sum: 28900 #define TINY_RECEIVER_HEADER_MARK FAST_HEADER_MARK #define TINY_RECEIVER_HEADER_SPACE FAST_HEADER_SPACE +#define TINY_RECEIVER_MARK_TIMEOUT (2 * FAST_HEADER_MARK) #define TINY_RECEIVER_BIT_MARK FAST_BIT_MARK #define TINY_RECEIVER_ONE_SPACE FAST_ONE_SPACE #define TINY_RECEIVER_ZERO_SPACE FAST_ZERO_SPACE +#define TINY_RECEIVER_ONE_THRESHOLD (2 * FAST_UNIT) // 1052 #define TINY_RECEIVER_MAXIMUM_REPEAT_DISTANCE FAST_MAXIMUM_REPEAT_DISTANCE // for repeat detection @@ -134,6 +135,8 @@ Sum: 28900 #define TINY_RECEIVER_ADDRESS_BITS NEC_ADDRESS_BITS // the address bits + parity # if defined(USE_ONKYO_PROTOCOL) #define TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY false // 16 bit address without parity +# elif defined(USE_EXTENDED_NEC_PROTOCOL) +#define TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY false // 16 bit address without parity # else #define TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY true // 8 bit and 8 bit parity # endif @@ -149,45 +152,23 @@ Sum: 28900 #define TINY_RECEIVER_UNIT NEC_UNIT #define TINY_RECEIVER_HEADER_MARK NEC_HEADER_MARK +#define TINY_RECEIVER_MARK_TIMEOUT (2 * NEC_HEADER_MARK) #define TINY_RECEIVER_HEADER_SPACE NEC_HEADER_SPACE #define TINY_RECEIVER_BIT_MARK NEC_BIT_MARK #define TINY_RECEIVER_ONE_SPACE NEC_ONE_SPACE #define TINY_RECEIVER_ZERO_SPACE NEC_ZERO_SPACE +#define TINY_RECEIVER_ONE_THRESHOLD (2 * NEC_UNIT) // 1120 #define TINY_RECEIVER_MAXIMUM_REPEAT_DISTANCE NEC_MAXIMUM_REPEAT_DISTANCE #endif +#if defined(USE_CALLBACK_FOR_TINY_RECEIVER) /* - * This function is called, if a complete command was received and must be implemented in the file (user code) which includes this library. - * The parameter size is dependent of the code variant used in order to save program memory. - * We have 6 cases: 0, 8 bit or 16 bit address, each with 8 or 16 bit command + * This function is called, if a complete command was received and must be implemented in the file (user code) + * which includes this library if USE_CALLBACK_FOR_TINY_RECEIVER is activated. */ -#if (TINY_RECEIVER_ADDRESS_BITS > 0) -# if TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY -// 8 bit address here -# if TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY -extern void handleReceivedTinyIRData(uint8_t aAddress, uint8_t aCommand, uint8_t aFlags); // Standard NEC callback -# else -extern void handleReceivedTinyIRData(uint8_t aAddress, uint16_t aCommand, uint8_t aFlags); // If SUPPORT_ONKYO_16_BIT_COMMAND is defined -# endif - -# else // TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY -// 16 bit address here -# if TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY -extern void handleReceivedTinyIRData(uint16_t aAddress, uint8_t aCommand, uint8_t aFlags); -# else -extern void handleReceivedTinyIRData(uint16_t aAddress, uint16_t aCommand, uint8_t aFlags); -# endif -# endif - -#else -// FAST protocol - No address here -# if TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY -extern void handleReceivedTinyIRData(uint8_t aCommand, uint8_t aFlags); // Standard FAST callback -# else -extern void handleReceivedTinyIRData(uint16_t aCommand, uint8_t aFlags); // If "TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY false" is defined. 16 bit without parity. -# endif +extern void handleReceivedTinyIRData(); #endif #if !defined(MICROS_IN_ONE_SECOND) @@ -216,7 +197,7 @@ extern void handleReceivedTinyIRData(uint16_t aCommand, uint8_t aFlags); // If " #define IR_RECEIVER_STATE_WAITING_FOR_DATA_MARK 4 #define IR_RECEIVER_STATE_WAITING_FOR_STOP_MARK 5 /** - * Control and data variables of the state machine for TinyReceiver + * Control and data variables of the state machine for TinyIRReceiver */ struct TinyIRReceiverStruct { /* @@ -240,16 +221,15 @@ struct TinyIRReceiverStruct { /* * Definitions for member TinyIRReceiverCallbackDataStruct.Flags - * From IRremoteInt.h + * This is a copy of flags from IRremoteInt.h */ #define IRDATA_FLAGS_EMPTY 0x00 #define IRDATA_FLAGS_IS_REPEAT 0x01 -#define IRDATA_FLAGS_IS_AUTO_REPEAT 0x02 // not used here, overwritten with _IRDATA_FLAGS_IS_SHORT_REPEAT +#define IRDATA_FLAGS_IS_AUTO_REPEAT 0x02 // not used for TinyIR #define IRDATA_FLAGS_PARITY_FAILED 0x04 ///< the current (autorepeat) frame violated parity check /** - * Can be used by the callback to transfer received data to main loop for further processing. - * E.g. with volatile struct TinyIRReceiverCallbackDataStruct sCallbackData; + * Is filled before calling the user callback to transfer received data to main loop for further processing. */ struct TinyIRReceiverCallbackDataStruct { #if (TINY_RECEIVER_ADDRESS_BITS > 0) @@ -266,27 +246,63 @@ struct TinyIRReceiverCallbackDataStruct { uint8_t Command; #endif uint8_t Flags; // Bit coded flags. Can contain one of the bits: IRDATA_FLAGS_IS_REPEAT and IRDATA_FLAGS_PARITY_FAILED - bool justWritten; ///< Is set true if new data is available. Used by the main loop, to avoid multiple evaluations of the same IR frame. + bool justWritten; ///< Is set true if new data is available. Used by the main loop / TinyIRReceiverDecode(), to avoid multiple evaluations of the same IR frame. }; +extern volatile TinyIRReceiverCallbackDataStruct TinyIRReceiverData; +bool isIRReceiverAttachedForTinyReceiver(); bool initPCIInterruptForTinyReceiver(); bool enablePCIInterruptForTinyReceiver(); void disablePCIInterruptForTinyReceiver(); bool isTinyReceiverIdle(); -#if defined(USE_FAST_PROTOCOL) -void printTinyReceiverResultMinimal(Print *aSerial, uint16_t aCommand, uint8_t aFlags); -#else -void printTinyReceiverResultMinimal(Print *aSerial, uint8_t aAddress, uint8_t aCommand, uint8_t aFlags); -#endif +bool TinyReceiverDecode(); +void printTinyReceiverResultMinimal(Print *aSerial); + +bool isIRReceiverAttachedForTinyIRReceiver(); +bool initPCIInterruptForTinyIRReceiver(); +bool enablePCIInterruptForTinyIRReceiver(); +void disablePCIInterruptForTinyIRReceiver(); +bool isTinyIRReceiverIdle(); +bool TinyIRReceiverDecode(); +void printTinyIRReceiverResultMinimal(Print *aSerial); + void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0); void sendFast8BitAndParity(uint8_t aSendPin, uint8_t aCommand, uint_fast8_t aNumberOfRepeats = 0); -void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0); // Send NEC with 16 bit command, even if aCommand < 0x100 +void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0, bool aSendNEC2Repeats = false); // Send NEC with 16 bit command, even if aCommand < 0x100 void sendNECMinimal(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0) __attribute__ ((deprecated ("Renamed to sendNEC()."))); -void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0); +void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0, bool aSendNEC2Repeats = false); +void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats = 0, bool aSendNEC2Repeats = false); + +#if defined(NO_LED_FEEDBACK_CODE) +# if !defined(NO_LED_RECEIVE_FEEDBACK_CODE) +#define NO_LED_RECEIVE_FEEDBACK_CODE +# endif +# if !defined(NO_LED_SEND_FEEDBACK_CODE) +#define NO_LED_SEND_FEEDBACK_CODE +# endif +#endif + +#if !defined(IR_FEEDBACK_LED_PIN) && defined(LED_BUILTIN) +#define IR_FEEDBACK_LED_PIN LED_BUILTIN +#endif /* + * Version 2.3.0 - 3/2026 + * - Renamed TinyReceiver*() functions to TinyIRReceiver*(). + * + * Version 2.2.0 - 7/2024 + * - New TinyReceiverDecode() function to be used as drop in for IrReceiver.decode(). + * + * Version 2.1.0 - 2/2024 + * - New sendExtendedNEC() function and new parameter aSendNEC2Repeats. + * + * Version 2.0.0 - 10/2023 + * - New TinyIRReceiverData which is filled with address, command and flags. + * - Removed parameters address, command and flags from callback handleReceivedTinyIRData() and printTinyReceiverResultMinimal(). + * - Callback function now only enabled if USE_CALLBACK_FOR_TINY_RECEIVER is activated. + * * Version 1.2.0 - 01/2023 * - Added ONKYO protocol, NEC with 16 bit address and command, instead of 8 bit + 8 bit parity address and command. * - Renamed functions and macros. diff --git a/src/TinyIRReceiver.hpp b/src/TinyIRReceiver.hpp index 42905bb44..0aabb7396 100644 --- a/src/TinyIRReceiver.hpp +++ b/src/TinyIRReceiver.hpp @@ -1,7 +1,7 @@ /* * TinyIRReceiver.hpp * - * Receives IR protocol data of NEC protocol using pin change interrupts. + * Receives IR data of NEC protocol using pin change interrupts. * NEC is the protocol of most cheap remote controls for Arduino. * * Parity check is done for address and data. @@ -22,13 +22,13 @@ * - Repeats are sent as complete frames but in a 50 ms period / with a 21 ms distance. * * - * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. * ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -56,11 +56,15 @@ * * - IR_RECEIVE_PIN The pin number for TinyIRReceiver IR input. * - IR_FEEDBACK_LED_PIN The pin number for TinyIRReceiver feedback LED. - * - NO_LED_FEEDBACK_CODE Disables the feedback LED function. Saves 14 bytes program memory. - * - DISABLE_PARITY_CHECKS Disable parity checks. Saves 48 bytes of program memory. + * - NO_LED_FEEDBACK_CODE Disables the feedback LED function for send and receive. Saves 14 bytes program memory. + * - NO_LED_RECEIVE_FEEDBACK_CODE Disables the LED feedback code for receive. + * - NO_LED_SEND_FEEDBACK_CODE Disables the LED feedback code for send. + * - DISABLE_PARITY_CHECKS Disable parity checks. Saves 48 bytes of program memory. + * - USE_EXTENDED_NEC_PROTOCOL Like NEC, but take the 16 bit address as one 16 bit value and not as 8 bit normal and 8 bit inverted value. * - USE_ONKYO_PROTOCOL Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. * - USE_FAST_PROTOCOL Use FAST protocol (no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command) instead of NEC. * - ENABLE_NEC2_REPEATS Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. + * - USE_CALLBACK_FOR_TINY_RECEIVER Call the user provided function "void handleReceivedTinyIRData()" each time a frame or repeat is received. */ #ifndef _TINY_IR_RECEIVER_HPP @@ -68,38 +72,37 @@ #include -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif - -//#define DISABLE_PARITY_CHECKS // Disable parity checks. Saves 48 bytes of program memory. +/* + * Protocol selection + */ +//#define USE_EXTENDED_NEC_PROTOCOL // Like NEC, but take the 16 bit address as one 16 bit value and not as 8 bit normal and 8 bit inverted value. //#define USE_ONKYO_PROTOCOL // Like NEC, but take the 16 bit address and command each as one 16 bit value and not as 8 bit normal and 8 bit inverted value. //#define USE_FAST_PROTOCOL // Use FAST protocol instead of NEC / ONKYO. //#define ENABLE_NEC2_REPEATS // Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. - -#include "TinyIR.h" // If not defined, it defines IR_RECEIVE_PIN, IR_FEEDBACK_LED_PIN and TINY_RECEIVER_USE_ARDUINO_ATTACH_INTERRUPT +//#define DISABLE_PARITY_CHECKS // Disable parity checks. Saves 48 bytes of program memory. +//#define IR_RECEIVE_PIN 2 +//#define IR_FEEDBACK_LED_PIN 12 // Use this, to disable use of LED_BUILTIN definition for IR_FEEDBACK_LED_PIN +#include "TinyIR.h" #include "digitalWriteFast.h" -/** \addtogroup TinyReceiver Minimal receiver for NEC and FAST protocol +/** \addtogroup TinyIRReceiver Minimal receiver for NEC and FAST protocol * @{ */ -#if defined(DEBUG) +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" +#if defined(LOCAL_DEBUG) #define LOCAL_DEBUG_ATTACH_INTERRUPT #else -//#define LOCAL_DEBUG_ATTACH_INTERRUPT // to see if attachInterrupt() or static interrupt (by register tweaking) is used -#endif -#if defined(TRACE) -#define LOCAL_TRACE_STATE_MACHINE -#else -//#define LOCAL_TRACE_STATE_MACHINE // to see the state of the ISR (Interrupt Service Routine) state machine +//#define LOCAL_DEBUG_ATTACH_INTERRUPT // To see if attachInterrupt() or static interrupt (by register tweaking) is used and no other debug output #endif //#define _IR_MEASURE_TIMING // Activate this if you want to enable internal hardware timing measurement. //#define _IR_TIMING_TEST_PIN 7 TinyIRReceiverStruct TinyIRReceiverControl; +volatile TinyIRReceiverCallbackDataStruct TinyIRReceiverData; // The persistent copy of all IR data after receiving a complete frame. To be used by main program. /* * Set input pin and output pin definitions etc. @@ -108,21 +111,22 @@ TinyIRReceiverStruct TinyIRReceiverControl; #warning "IR_INPUT_PIN is deprecated, use IR_RECEIVE_PIN" #define IR_RECEIVE_PIN IR_INPUT_PIN #endif + #if !defined(IR_RECEIVE_PIN) -#if defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) +# if defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) #warning "IR_RECEIVE_PIN is not defined, so it is set to 10" #define IR_RECEIVE_PIN 10 -#elif defined(__AVR_ATtiny816__) +# elif defined(__AVR_ATtiny816__) #warning "IR_RECEIVE_PIN is not defined, so it is set to 14" #define IR_RECEIVE_PIN 14 -#else +# else #warning "IR_RECEIVE_PIN is not defined, so it is set to 2" #define IR_RECEIVE_PIN 2 -#endif +# endif #endif -#if !defined(IR_FEEDBACK_LED_PIN) && defined(LED_BUILTIN) -#define IR_FEEDBACK_LED_PIN LED_BUILTIN +#if !defined(NO_LED_RECEIVE_FEEDBACK_CODE) +#define LED_RECEIVE_FEEDBACK_CODE // Resolve the double negative #endif #if !( \ @@ -136,18 +140,20 @@ TinyIRReceiverStruct TinyIRReceiverControl; || ( (defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)) && ( (defined(ARDUINO_AVR_DIGISPARKPRO) && ((IR_RECEIVE_PIN == 3) || (IR_RECEIVE_PIN == 9))) /*ATtinyX7(digisparkpro) and pin 3 or 9 */\ || (! defined(ARDUINO_AVR_DIGISPARKPRO) && ((IR_RECEIVE_PIN == 3) || (IR_RECEIVE_PIN == 14)))) ) /*ATtinyX7(ATTinyCore) and pin 3 or 14 */ \ ) -#define TINY_RECEIVER_USE_ARDUINO_ATTACH_INTERRUPT // Cannot use any static ISR vector here. In other cases we have code provided for generating interrupt on pin change. +/* + * Cannot use any static ISR vector here. In other cases we have code provided for generating interrupt on pin change. + * Requires additional 112 bytes program memory + 4 bytes RAM + */ +#define TINY_RECEIVER_USE_ARDUINO_ATTACH_INTERRUPT #endif /** * Declaration of the callback function provided by the user application. * It is called every time a complete IR command or repeat was received. */ -extern void handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition); +extern void handleReceivedTinyIRData(); -#if defined(LOCAL_DEBUG) -uint32_t sMicrosOfGap; // The length of the gap before the start bit -#endif +uint32_t sMicrosOfGap; // The length of the gap before the start bit, used for trace /** * The ISR (Interrupt Service Routine) of TinyIRRreceiver. * It handles the NEC protocol decoding and calls the user callback function on complete. @@ -166,8 +172,12 @@ void IRPinChangeInterruptHandler(void) { */ uint_fast8_t tIRLevel = digitalReadFast(IR_RECEIVE_PIN); -#if !defined(NO_LED_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) +#if defined(LED_RECEIVE_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, tIRLevel); +# else digitalWriteFast(IR_FEEDBACK_LED_PIN, !tIRLevel); +# endif #endif /* @@ -175,27 +185,25 @@ void IRPinChangeInterruptHandler(void) { */ // Repeats can be sent after a pause, which is longer than 64000 microseconds, so we need a 32 bit value for check of repeats uint32_t tCurrentMicros = micros(); - uint32_t tMicrosOfMarkOrSpace32 = tCurrentMicros - TinyIRReceiverControl.LastChangeMicros; + uint32_t tMicrosOfMarkOrSpace32 = tCurrentMicros - TinyIRReceiverControl.LastChangeMicros; // statement is required to force 32 bit arithmetic uint16_t tMicrosOfMarkOrSpace = tMicrosOfMarkOrSpace32; TinyIRReceiverControl.LastChangeMicros = tCurrentMicros; uint8_t tState = TinyIRReceiverControl.IRReceiverState; -#if defined(LOCAL_TRACE_STATE_MACHINE) - Serial.print(tState); - Serial.print(F(" D=")); - Serial.print(tMicrosOfMarkOrSpace); -// Serial.print(F(" I=")); -// Serial.print(tIRLevel); - Serial.print('|'); -#endif + TRACE_PRINT(tState); + TRACE_PRINT(F(" D=")); + TRACE_PRINT(tMicrosOfMarkOrSpace); +// TRACE_PRINT(F(" I=")); +// TRACE_PRINT(tIRLevel); + TRACE_PRINT('|'); if (tIRLevel == LOW) { /* - * We have a mark here + * We are at the start of a mark here and tMicrosOfMarkOrSpace is the time of the previous space */ - if (tMicrosOfMarkOrSpace > 2 * TINY_RECEIVER_HEADER_MARK) { + if (tMicrosOfMarkOrSpace > TINY_RECEIVER_MARK_TIMEOUT) { // timeout -> must reset state machine tState = IR_RECEIVER_STATE_WAITING_FOR_START_MARK; } @@ -203,7 +211,7 @@ void IRPinChangeInterruptHandler(void) { // We are at the beginning of the header mark, check timing at the next transition tState = IR_RECEIVER_STATE_WAITING_FOR_START_SPACE; TinyIRReceiverControl.Flags = IRDATA_FLAGS_EMPTY; // If we do it here, it saves 4 bytes -#if defined(LOCAL_TRACE) +#if defined(TRACE) // Do not use LOCAL_TRACE here since sMicrosOfGap is read in a cpp file at TRACE sMicrosOfGap = tMicrosOfMarkOrSpace32; #endif #if defined(ENABLE_NEC2_REPEATS) @@ -220,7 +228,7 @@ void IRPinChangeInterruptHandler(void) { if (tMicrosOfMarkOrSpace >= lowerValue25Percent(TINY_RECEIVER_HEADER_SPACE) && tMicrosOfMarkOrSpace <= upperValue25Percent(TINY_RECEIVER_HEADER_SPACE)) { /* - * We have a valid data header space here -> initialize data + * We had a valid data header space before -> initialize data */ TinyIRReceiverControl.IRRawDataBitCounter = 0; #if (TINY_RECEIVER_BITS > 16) @@ -230,8 +238,9 @@ void IRPinChangeInterruptHandler(void) { #endif TinyIRReceiverControl.IRRawDataMask = 1; tState = IR_RECEIVER_STATE_WAITING_FOR_DATA_SPACE; + #if !defined(ENABLE_NEC2_REPEATS) - // Check for NEC repeat header + // Alternatively check for NEC repeat header space length } else if (tMicrosOfMarkOrSpace >= lowerValue25Percent(NEC_REPEAT_HEADER_SPACE) && tMicrosOfMarkOrSpace <= upperValue25Percent(NEC_REPEAT_HEADER_SPACE) && TinyIRReceiverControl.IRRawDataBitCounter >= TINY_RECEIVER_BITS) { @@ -249,12 +258,15 @@ void IRPinChangeInterruptHandler(void) { } else if (tState == IR_RECEIVER_STATE_WAITING_FOR_DATA_MARK) { - // Check data space length + /* + * Start of data mark here, check data space length + * Maybe the minimum length check could be removed here. + */ if (tMicrosOfMarkOrSpace >= lowerValue50Percent(TINY_RECEIVER_ZERO_SPACE) && tMicrosOfMarkOrSpace <= upperValue50Percent(TINY_RECEIVER_ONE_SPACE)) { // We have a valid bit here tState = IR_RECEIVER_STATE_WAITING_FOR_DATA_SPACE; - if (tMicrosOfMarkOrSpace >= 2 * TINY_RECEIVER_UNIT) { + if (tMicrosOfMarkOrSpace >= TINY_RECEIVER_ONE_THRESHOLD) { // we received a 1 #if (TINY_RECEIVER_BITS > 16) TinyIRReceiverControl.IRRawData.ULong |= TinyIRReceiverControl.IRRawDataMask; @@ -279,7 +291,8 @@ void IRPinChangeInterruptHandler(void) { else { /* - * We have a space here + * We are at the start of a space here and tMicrosOfMarkOrSpace is the time of the previous mark + * */ if (tState == IR_RECEIVER_STATE_WAITING_FOR_START_SPACE) { /* @@ -319,7 +332,7 @@ void IRPinChangeInterruptHandler(void) { */ if (TinyIRReceiverControl.IRRawData.UBytes[0] != (uint8_t) (~TinyIRReceiverControl.IRRawData.UBytes[1])) { #if defined(ENABLE_NEC2_REPEATS) - TinyIRReceiverControl.Flags |= IRDATA_FLAGS_PARITY_FAILED; // here we can have the repeat flag already set + TinyIRReceiverControl.Flags |= IRDATA_FLAGS_PARITY_FAILED; // here we can have the repeat flag already set #else TinyIRReceiverControl.Flags = IRDATA_FLAGS_PARITY_FAILED; // here we do not check anything, if we have a repeat #endif @@ -332,26 +345,22 @@ void IRPinChangeInterruptHandler(void) { #if (TINY_RECEIVER_ADDRESS_BITS > 0) if (TinyIRReceiverControl.IRRawData.UBytes[2] != (uint8_t) (~TinyIRReceiverControl.IRRawData.UBytes[3])) { #if defined(ENABLE_NEC2_REPEATS) - TinyIRReceiverControl.Flags |= IRDATA_FLAGS_PARITY_FAILED; + TinyIRReceiverControl.Flags |= IRDATA_FLAGS_PARITY_FAILED; #else TinyIRReceiverControl.Flags = IRDATA_FLAGS_PARITY_FAILED; #endif -# if defined(LOCAL_DEBUG) - Serial.print(F("Parity check for command failed. Command=")); - Serial.print(TinyIRReceiverControl.IRRawData.UBytes[2], HEX); - Serial.print(F(" parity=")); - Serial.println(TinyIRReceiverControl.IRRawData.UBytes[3], HEX); -# endif + DEBUG_PRINT(F("Parity check for command failed. Command=")); + DEBUG_PRINT(TinyIRReceiverControl.IRRawData.UBytes[2], HEX); + DEBUG_PRINT(F(" parity=")); + DEBUG_PRINTLN(TinyIRReceiverControl.IRRawData.UBytes[3], HEX); #else // No address, so command and parity are in the lowest bytes if (TinyIRReceiverControl.IRRawData.UBytes[0] != (uint8_t) (~TinyIRReceiverControl.IRRawData.UBytes[1])) { TinyIRReceiverControl.Flags |= IRDATA_FLAGS_PARITY_FAILED; -# if defined(LOCAL_DEBUG) - Serial.print(F("Parity check for command failed. Command=")); - Serial.print(TinyIRReceiverControl.IRRawData.UBytes[0], HEX); - Serial.print(F(" parity=")); - Serial.println(TinyIRReceiverControl.IRRawData.UBytes[1], HEX); -# endif + DEBUG_PRINT(F("Parity check for command failed. Command=")); + DEBUG_PRINT(TinyIRReceiverControl.IRRawData.UBytes[0], HEX); + DEBUG_PRINT(F(" parity=")); + DEBUG_PRINTLN(TinyIRReceiverControl.IRRawData.UBytes[1], HEX); #endif } #endif @@ -360,37 +369,40 @@ void IRPinChangeInterruptHandler(void) { * The parameter size is dependent of the code variant used in order to save program memory. * We have 6 cases: 0, 8 bit or 16 bit address, each with 8 or 16 bit command */ -#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. in callback for ESP -> no interrupt required, WDT is running! +#if !defined(ARDUINO_ARCH_MBED) && !defined(ESP32) // no Serial etc. possible in callback for RTOS based cores like ESP, even when interrupts are enabled interrupts(); // enable interrupts, so delay() etc. works in callback #endif - handleReceivedTinyIRData( + TinyIRReceiverData.justWritten = true; + TinyIRReceiverData.Flags = TinyIRReceiverControl.Flags; #if (TINY_RECEIVER_ADDRESS_BITS > 0) # if TINY_RECEIVER_ADDRESS_HAS_8_BIT_PARITY - // Here we have 8 bit address - TinyIRReceiverControl.IRRawData.UBytes[0], + // Here we have 8 bit address + TinyIRReceiverData.Address = TinyIRReceiverControl.IRRawData.UBytes[0]; # else - // Here we have 16 bit address - TinyIRReceiverControl.IRRawData.UWord.LowWord, + // Here we have 16 bit address + TinyIRReceiverData.Address = TinyIRReceiverControl.IRRawData.UWord.LowWord; # endif # if TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY - // Here we have 8 bit command - TinyIRReceiverControl.IRRawData.UBytes[2], + // Here we have 8 bit command + TinyIRReceiverData.Command = TinyIRReceiverControl.IRRawData.UBytes[2]; # else - // Here we have 16 bit command - TinyIRReceiverControl.IRRawData.UWord.HighWord, + // Here we have 16 bit command + TinyIRReceiverData.Command = TinyIRReceiverControl.IRRawData.UWord.HighWord; # endif -#else - // Here we have NO address +#else + // Here we have NO address # if TINY_RECEIVER_COMMAND_HAS_8_BIT_PARITY - // Here we have 8 bit command - TinyIRReceiverControl.IRRawData.UBytes[0], + // Here we have 8 bit command + TinyIRReceiverData.Command = TinyIRReceiverControl.IRRawData.UBytes[0]; # else - // Here we have 16 bit command - TinyIRReceiverControl.IRRawData.UWord, + // Here we have 16 bit command + TinyIRReceiverData.Command = TinyIRReceiverControl.IRRawData.UWord; # endif #endif - TinyIRReceiverControl.Flags); +#if defined(USE_CALLBACK_FOR_TINY_RECEIVER) + handleReceivedTinyIRData(); +#endif } else { // not finished yet @@ -412,51 +424,85 @@ void IRPinChangeInterruptHandler(void) { #endif } -bool isTinyReceiverIdle() { +bool isTinyIRReceiverIdle() { return (TinyIRReceiverControl.IRReceiverState == IR_RECEIVER_STATE_WAITING_FOR_START_MARK); } +bool isTinyReceiverIdle() { + return isTinyIRReceiverIdle(); +} + +/* + * Function to be used as drop in for IrReceiver.decode() + */ +bool TinyIRReceiverDecode() { + bool tJustWritten = TinyIRReceiverData.justWritten; + if (tJustWritten) { + TinyIRReceiverData.justWritten = false; + } + return tJustWritten; +} +bool TinyReceiverDecode() { + return TinyIRReceiverDecode(); +} + +/* + * Checks if IR_RECEIVE_PIN is connected and high + * @return true, if IR Receiver is attached + */ +bool isIRReceiverAttachedForTinyIRReceiver() { + pinModeFast(IR_RECEIVE_PIN, OUTPUT); + digitalWriteFast(IR_RECEIVE_PIN, LOW); // discharge pin capacity + pinModeFast(IR_RECEIVE_PIN, INPUT); + return digitalRead(IR_RECEIVE_PIN); // use slow digitalRead here, since the pin capacity is not fully charged again if we use digitalReadFast. +} +bool isIRReceiverAttachedForTinyReceiver() { + return isIRReceiverAttachedForTinyIRReceiver(); +} /** * Sets IR_RECEIVE_PIN mode to INPUT, and if IR_FEEDBACK_LED_PIN is defined, sets feedback LED output mode. - * Then call enablePCIInterruptForTinyReceiver() + * Then call enablePCIInterruptForTinyIRReceiver() */ -bool initPCIInterruptForTinyReceiver() { +bool initPCIInterruptForTinyIRReceiver() { pinModeFast(IR_RECEIVE_PIN, INPUT); -#if !defined(NO_LED_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) +#if defined(LED_RECEIVE_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# endif #endif return enablePCIInterruptForTinyReceiver(); } +bool initPCIInterruptForTinyReceiver() { + return initPCIInterruptForTinyIRReceiver(); +} -#if defined(USE_FAST_PROTOCOL) -void printTinyReceiverResultMinimal(Print *aSerial, uint16_t aCommand, uint8_t aFlags) -#else -void printTinyReceiverResultMinimal(Print *aSerial, uint8_t aAddress, uint8_t aCommand, uint8_t aFlags) -#endif - { +void printTinyIRReceiverResultMinimal(Print *aSerial) { // Print only very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon - // Print only very short output, since we are in an interrupt context and do not want to miss the next interrupts of the repeats coming soon #if defined(USE_FAST_PROTOCOL) aSerial->print(F("C=0x")); #else aSerial->print(F("A=0x")); - aSerial->print(aAddress, HEX); + aSerial->print(TinyIRReceiverData.Address, HEX); aSerial->print(F(" C=0x")); #endif - aSerial->print(aCommand, HEX); - if (aFlags == IRDATA_FLAGS_IS_REPEAT) { + aSerial->print(TinyIRReceiverData.Command, HEX); + if (TinyIRReceiverData.Flags == IRDATA_FLAGS_IS_REPEAT) { aSerial->print(F(" R")); } #if !defined(DISABLE_PARITY_CHECKS) - if (aFlags == IRDATA_FLAGS_PARITY_FAILED) { + if (TinyIRReceiverData.Flags == IRDATA_FLAGS_PARITY_FAILED) { aSerial->print(F(" P")); } #endif aSerial->println(); } +void printTinyReceiverResultMinimal(Print *aSerial) { + printTinyIRReceiverResultMinimal(aSerial); +} -#if defined (LOCAL_DEBUG_ATTACH_INTERRUPT) && !defined(STR) +#if !defined(STR_HELPER) && !defined(STR) // Helper macro for getting a macro definition as string #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -535,21 +581,26 @@ void printTinyReceiverResultMinimal(Print *aSerial, uint8_t aAddress, uint8_t aC * Initializes hardware interrupt generation according to IR_RECEIVE_PIN or use attachInterrupt() function. * @return true if interrupt was successfully enabled */ -bool enablePCIInterruptForTinyReceiver() { +bool enablePCIInterruptForTinyIRReceiver() { #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); #endif #if defined(USE_ATTACH_INTERRUPT) || defined(USE_ATTACH_INTERRUPT_DIRECT) # if defined(USE_ATTACH_INTERRUPT) -#if defined(NOT_AN_INTERRUPT) +# if defined(NOT_AN_INTERRUPT) // check if IDE has defined the check of digitalPinToInterrupt if(digitalPinToInterrupt(IR_RECEIVE_PIN) == NOT_AN_INTERRUPT){ return false; } -#endif +# endif // costs 112 bytes program memory + 4 bytes RAM - attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), IRPinChangeInterruptHandler, CHANGE); +# if defined(ARDUINO_ARCH_SAMD) // see https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/ paragraph: Syntax + attachInterrupt(IR_RECEIVE_PIN, IRPinChangeInterruptHandler, CHANGE); // no extra pin mapping here :-( +# else + attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), IRPinChangeInterruptHandler, CHANGE); // CHANGE can be an enum :-( +# endif # else + // USE_ATTACH_INTERRUPT_DIRECT here, only defined for ATtinies *16, see above // 2.2 us more than version configured with macros and not compatible attachInterrupt(IR_RECEIVE_PIN, IRPinChangeInterruptHandler, CHANGE); // no extra pin mapping here # endif @@ -557,11 +608,11 @@ bool enablePCIInterruptForTinyReceiver() { # if defined(LOCAL_DEBUG_ATTACH_INTERRUPT) Serial.println(F("Use attachInterrupt for pin=" STR(IR_RECEIVE_PIN))); # endif - #else # if defined(LOCAL_DEBUG_ATTACH_INTERRUPT) - Serial.println(F("Use static interrupt for pin=" STR(IR_RECEIVE_PIN))); + Serial.println(F("Use hardware/static interrupt for pin=" STR(IR_RECEIVE_PIN))); # endif + # if defined(USE_INT0) // interrupt on any logical change EICRA |= _BV(ISC00); @@ -600,8 +651,11 @@ bool enablePCIInterruptForTinyReceiver() { #endif // defined(USE_ATTACH_INTERRUPT) return true; } +bool enablePCIInterruptForTinyReceiver() { + return enablePCIInterruptForTinyIRReceiver(); +} -void disablePCIInterruptForTinyReceiver() { +void disablePCIInterruptForTinyIRReceiver() { #if defined(_IR_MEASURE_TIMING) && defined(_IR_TIMING_TEST_PIN) pinModeFast(_IR_TIMING_TEST_PIN, OUTPUT); #endif @@ -642,6 +696,9 @@ void disablePCIInterruptForTinyReceiver() { # endif #endif // defined(USE_ATTACH_INTERRUPT) } +void disablePCIInterruptForTinyReceiver() { + disablePCIInterruptForTinyIRReceiver(); +} /* * Specify the right INT0, INT1 or PCINT0 interrupt vector according to different pins and cores. @@ -677,11 +734,6 @@ void dummyFunctionToAvoidCompilerErrors() #if defined(LOCAL_DEBUG_ATTACH_INTERRUPT) #undef LOCAL_DEBUG_ATTACH_INTERRUPT #endif -#if defined(LOCAL_TRACE_STATE_MACHINE) -#undef LOCAL_TRACE_STATE_MACHINE -#endif +#include "LocalDebugLevelEnd.h" -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif #endif // _TINY_IR_RECEIVER_HPP diff --git a/src/TinyIRSender.hpp b/src/TinyIRSender.hpp index 0672383bb..a9ae84f4a 100644 --- a/src/TinyIRSender.hpp +++ b/src/TinyIRSender.hpp @@ -13,13 +13,13 @@ * - Repeats are sent as complete frames but in a 50 ms period / with a 21 ms distance. * * - * This file is part of IRMP https://github.com/IRMP-org/IRMP. * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * This file is part of IRMP https://github.com/IRMP-org/IRMP. * ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -48,11 +48,8 @@ //#define ENABLE_NEC2_REPEATS // Instead of sending / receiving the NEC special repeat code, send / receive the original frame for repeat. -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +//#define NO_LED_SEND_FEEDBACK_CODE // Disables the LED feedback code for receive. +//#define IR_FEEDBACK_LED_PIN 12 // Use this, to disable use of LED_BUILTIN definition for IR_FEEDBACK_LED_PIN #include "TinyIR.h" // Defines protocol timings #include "digitalWriteFast.h" @@ -60,13 +57,25 @@ * @{ */ +#if !defined(IR_SEND_PIN) +#warning "IR_SEND_PIN is not defined, so it is set to 3" +#define IR_SEND_PIN 3 +#endif +#if !defined(NO_LED_SEND_FEEDBACK_CODE) +#define LED_SEND_FEEDBACK_CODE // Resolve the double negative +#endif + /* - * Generate 38 kHz IR signal by bit banging + * Generate 38 kHz IR signal by bit banging and using delayMicroseconds() and micros() */ void sendMark(uint8_t aSendPin, unsigned int aMarkMicros) { - unsigned long tStartMicros = micros(); - unsigned long tNextPeriodEnding = tStartMicros; - unsigned long tMicros; + unsigned long tMicros = micros(); + unsigned long tNextPeriodEnding = tMicros; +#if defined(F_CPU) + unsigned long tEndMicros = tMicros + (112 / (F_CPU / MICROS_IN_ONE_SECOND)) + aMarkMicros; // To compensate for call duration - 112 is an empirical value +#else + unsigned long tEndMicros = tMicros + aMarkMicros; +#endif do { /* * Generate pulse @@ -81,19 +90,13 @@ void sendMark(uint8_t aSendPin, unsigned int aMarkMicros) { * PWM pause timing and end check * Minimal pause duration is 4.3 us */ - tNextPeriodEnding += 26; // for 38 kHz + tNextPeriodEnding += 26; // 26.3 us period for 38 kHz; 26 us -> 38.48 kHz do { tMicros = micros(); // we have only 4 us resolution for AVR @16MHz /* * Exit the forever loop if aMarkMicros has reached */ - unsigned int tDeltaMicros = tMicros - tStartMicros; -#if defined(__AVR__) - // Just getting variables and check for end condition takes minimal 3.8 us - if (tDeltaMicros >= aMarkMicros - (112 / (F_CPU / MICROS_IN_ONE_SECOND))) { // To compensate for call duration - 112 is an empirical value -#else - if (tDeltaMicros >= aMarkMicros) { - #endif + if (tMicros >= tEndMicros) { return; } } while (tMicros < tNextPeriodEnding); @@ -101,28 +104,35 @@ void sendMark(uint8_t aSendPin, unsigned int aMarkMicros) { } /* - * Send NEC with 16 bit command, even if aCommand < 0x100 + * Send NEC with 16 bit address and command, even if aCommand < 0x100 (I.E. ONKYO) * @param aAddress - The 16 bit address to send. * @param aCommand - The 16 bit command to send. * @param aNumberOfRepeats - Number of repeats send at a period of 110 ms. + * @param aSendNEC2Repeats - Instead of sending the NEC special repeat code, send the original frame for repeat. */ -void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) { +void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendNEC2Repeats) { pinModeFast(aSendPin, OUTPUT); +#if !defined(NO_LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# endif +#endif + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { unsigned long tStartOfFrameMillis = millis(); sendMark(aSendPin, NEC_HEADER_MARK); -#if !defined(ENABLE_NEC2_REPEATS) - if (tNumberOfCommands < aNumberOfRepeats + 1) { + if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) { // send the NEC special repeat - delayMicroseconds(NEC_REPEAT_HEADER_SPACE); // - 2250 - } else -#endif - { + delayMicroseconds (NEC_REPEAT_HEADER_SPACE); // - 2250 + } else { // send header - delayMicroseconds(NEC_HEADER_SPACE); + delayMicroseconds (NEC_HEADER_SPACE); LongUnion tData; tData.UWord.LowWord = aAddress; tData.UWord.HighWord = aCommand; @@ -130,9 +140,9 @@ void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast for (uint_fast8_t i = 0; i < NEC_BITS; ++i) { sendMark(aSendPin, NEC_BIT_MARK); // constant mark length if (tData.ULong & 1) { - delayMicroseconds(NEC_ONE_SPACE); + delayMicroseconds (NEC_ONE_SPACE); } else { - delayMicroseconds(NEC_ZERO_SPACE); + delayMicroseconds (NEC_ZERO_SPACE); } tData.ULong >>= 1; // shift command for next bit } @@ -151,34 +161,49 @@ void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast } } } +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# endif +#endif } /* - * Send NEC with 8 or 16 bit address or data depending on the values of aAddress and aCommand. + * Send NEC with 8 or 16 bit address or command depending on the values of aAddress and aCommand. * @param aAddress - If aAddress < 0x100 send 8 bit address and 8 bit inverted address, else send 16 bit address. * @param aCommand - If aCommand < 0x100 send 8 bit command and 8 bit inverted command, else send 16 bit command. * @param aNumberOfRepeats - Number of repeats send at a period of 110 ms. + * @param aSendNEC2Repeats - Instead of sending the NEC special repeat code, send the original frame for repeat. */ void sendNECMinimal(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) { sendNEC(aSendPin, aAddress, aCommand, aNumberOfRepeats); // sendNECMinimal() is deprecated } -void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) { +void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendNEC2Repeats) { pinModeFast(aSendPin, OUTPUT); +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# endif +#endif + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { unsigned long tStartOfFrameMillis = millis(); sendMark(aSendPin, NEC_HEADER_MARK); -#if !defined(ENABLE_NEC2_REPEATS) - if (tNumberOfCommands < aNumberOfRepeats + 1) { + if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) { // send the NEC special repeat - delayMicroseconds(NEC_REPEAT_HEADER_SPACE); // - 2250 - } else -#endif - { + delayMicroseconds (NEC_REPEAT_HEADER_SPACE); // - 2250 + } else { // send header - delayMicroseconds(NEC_HEADER_SPACE); + delayMicroseconds (NEC_HEADER_SPACE); LongUnion tData; /* * The compiler is intelligent and removes the code for "(aAddress > 0xFF)" if we are called with an uint8_t address :-). @@ -201,9 +226,9 @@ void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_ sendMark(aSendPin, NEC_BIT_MARK); // constant mark length if (tData.ULong & 1) { - delayMicroseconds(NEC_ONE_SPACE); + delayMicroseconds (NEC_ONE_SPACE); } else { - delayMicroseconds(NEC_ZERO_SPACE); + delayMicroseconds (NEC_ZERO_SPACE); } tData.ULong >>= 1; // shift command for next bit } @@ -222,6 +247,88 @@ void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_ } } } +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# endif +#endif +} + +/* + * Send Extended NEC with a forced 16 bit address and 8 or 16 bit command depending on the value of aCommand. + * @param aAddress - Send 16 bit address. + * @param aCommand - If aCommand < 0x100 send 8 bit command and 8 bit inverted command, else send 16 bit command. + * @param aNumberOfRepeats - Number of repeats send at a period of 110 ms. + * @param aSendNEC2Repeats - Instead of sending the NEC special repeat code, send the original frame for repeat. + */ +void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendNEC2Repeats) { + pinModeFast(aSendPin, OUTPUT); + +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# endif +#endif + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + unsigned long tStartOfFrameMillis = millis(); + + sendMark(aSendPin, NEC_HEADER_MARK); + if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) { + // send the NEC special repeat + delayMicroseconds (NEC_REPEAT_HEADER_SPACE); // - 2250 + } else { + // send header + delayMicroseconds (NEC_HEADER_SPACE); + LongUnion tData; + tData.UWord.LowWord = aAddress; + if (aCommand > 0xFF) { + tData.UWord.HighWord = aCommand; + } else { + tData.UByte.MidHighByte = aCommand; + tData.UByte.HighByte = ~aCommand; // LSB first + } + // Send data + for (uint_fast8_t i = 0; i < NEC_BITS; ++i) { + sendMark(aSendPin, NEC_BIT_MARK); // constant mark length + + if (tData.ULong & 1) { + delayMicroseconds (NEC_ONE_SPACE); + } else { + delayMicroseconds (NEC_ZERO_SPACE); + } + tData.ULong >>= 1; // shift command for next bit + } + } // send stop bit + sendMark(aSendPin, NEC_BIT_MARK); + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + /* + * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. + */ + auto tFrameDurationMillis = millis() - tStartOfFrameMillis; + if (NEC_REPEAT_PERIOD / 1000 > tFrameDurationMillis) { + delay(NEC_REPEAT_PERIOD / 1000 - tFrameDurationMillis); + } + } + } +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# endif +#endif } /* @@ -237,6 +344,15 @@ void sendFast8BitAndParity(uint8_t aSendPin, uint8_t aCommand, uint_fast8_t aNum void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) { pinModeFast(aSendPin, OUTPUT); +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# endif +#endif + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { unsigned long tStartOfFrameMillis = millis(); @@ -280,11 +396,16 @@ void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats } } } +#if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) + pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); +# if defined(FEEDBACK_LED_IS_ACTIVE_LOW) + digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); +# else + digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); +# endif +#endif } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif #endif // _TINY_IR_SENDER_HPP diff --git a/src/ac_LG.h b/src/ac_LG.h index 4f56de7b7..b19bea21f 100644 --- a/src/ac_LG.h +++ b/src/ac_LG.h @@ -131,7 +131,6 @@ class Aircondition_LG { uint8_t FanIntensity = 1; // 0 -> low, 4 high, 5 -> cycle uint8_t Temperature = 22; // temperature : 18 ~ 30 uint8_t Mode = AC_MODE_COOLING; - bool useLG2Protocol = false; }; /** @}*/ diff --git a/src/ac_LG.hpp b/src/ac_LG.hpp index d5037c2d7..56d86321d 100644 --- a/src/ac_LG.hpp +++ b/src/ac_LG.hpp @@ -34,12 +34,11 @@ #define _AC_LG_HPP #include -#if defined(INFO) && !defined(LOCAL_INFO) -#define LOCAL_INFO -#else -//#define LOCAL_INFO // This enables info output only for this file -#endif -//#define DEBUG // for more output from the LG-AC driver. +// This block must be located after the includes of other *.hpp files +//#define LOCAL_INFO // This enables info output only for this file +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" + #include "IRremoteInt.h" #include "ac_LG.h" // useful constants #include "LongUnion.h" @@ -63,10 +62,8 @@ const int AC_FAN_WALL[SIZE_OF_FAN_SPEED_MAPPING_TABLE] = { 0, 2, 4, 5 }; // 0 -> void Aircondition_LG::setType(bool aIsWallType) { ACIsWallType = aIsWallType; -#if defined(LOCAL_INFO) - Serial.print(F("Set wall type to ")); - Serial.println(aIsWallType); -#endif + INFO_PRINT(F("Set wall type to ")); + INFO_PRINTLN(aIsWallType); } void Aircondition_LG::printMenu(Print *aSerial) { @@ -113,7 +110,7 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { return true; case LG_COMMAND_JET: - IR_DEBUG_PRINTLN(F("Send jet on")); + DEBUG_PRINTLN(F("Send jet on")); sendIRCommand(LG_JET_ON); return true; @@ -151,7 +148,7 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { * Now the commands which require a parameter */ if (aParameter < 0) { - IR_DEBUG_PRINT(F("Error: Parameter is less than 0")); + DEBUG_PRINT(F("Error: Parameter is less than 0")); return false; } switch (aCommand) { @@ -162,8 +159,8 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { break; case LG_COMMAND_SWING: - IR_DEBUG_PRINT(F("Send air swing=")); - IR_DEBUG_PRINTLN(aParameter); + DEBUG_PRINT(F("Send air swing=")); + DEBUG_PRINTLN(aParameter); if (ACIsWallType) { if (aParameter) { sendIRCommand(LG_WALL_SWING_ON); @@ -180,8 +177,8 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { break; case LG_COMMAND_AUTO_CLEAN: - IR_DEBUG_PRINT(F("Send auto clean=")); - IR_DEBUG_PRINTLN(aParameter); + DEBUG_PRINT(F("Send auto clean=")); + DEBUG_PRINTLN(aParameter); if (aParameter) { sendIRCommand(LG_AUTO_CLEAN_ON); } else { @@ -190,8 +187,8 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { break; case LG_COMMAND_ENERGY: - IR_DEBUG_PRINT(F("Send energy saving on=")); - IR_DEBUG_PRINTLN(aParameter); + DEBUG_PRINT(F("Send energy saving on=")); + DEBUG_PRINTLN(aParameter); if (aParameter) { sendIRCommand(LG_ENERGY_SAVING_ON); } else { @@ -251,14 +248,13 @@ bool Aircondition_LG::sendCommandAndParameter(char aCommand, int aParameter) { void Aircondition_LG::sendIRCommand(uint16_t aCommand) { -#if defined(LOCAL_INFO) - Serial.print(F("Send code=0x")); - Serial.print(aCommand, HEX); - Serial.print(F(" | 0b")); - Serial.println(aCommand, BIN); -#endif + INFO(F("Send code=0x")); + INFO_PRINT(aCommand, HEX); + INFO_PRINT(F(" | 0b")); + INFO_PRINTLN(aCommand, BIN); + - IrSender.sendLG2((uint8_t) LG_ADDRESS, aCommand, 0); + IrSender.sendLG((uint8_t) LG_ADDRESS, aCommand, 0); } /* @@ -267,14 +263,13 @@ void Aircondition_LG::sendIRCommand(uint16_t aCommand) { void Aircondition_LG::sendTemperatureFanSpeedAndMode() { uint8_t tTemperature = Temperature; -#if defined(LOCAL_INFO) - Serial.print(F("Send temperature=")); - Serial.print(tTemperature); - Serial.print(F(" fan intensity=")); - Serial.print(FanIntensity); - Serial.print(F(" mode=")); - Serial.println((char )Mode); -#endif + INFO_PRINT(F("Send temperature=")); + INFO_PRINT(tTemperature); + INFO_PRINT(F(" fan intensity=")); + INFO_PRINT(FanIntensity); + INFO_PRINT(F(" mode=")); + INFO_PRINTLN((char )Mode); + WordUnion tIRCommand; tIRCommand.UWord = 0; @@ -319,4 +314,6 @@ void Aircondition_LG::sendTemperatureFanSpeedAndMode() { } /** @}*/ +#include "LocalDebugLevelEnd.h" + #endif // _AC_LG_HPP diff --git a/src/digitalWriteFast.h b/src/digitalWriteFast.h index 5da511107..7087d75e4 100644 --- a/src/digitalWriteFast.h +++ b/src/digitalWriteFast.h @@ -5,12 +5,22 @@ * by Watterott electronic (www.watterott.com) * based on https://code.google.com/p/digitalwritefast * + * The value of DigitalReadFast() is the content of the input register e.g. 0x04 for pin2 and NOT always 0 or 1. + * * License: BSD 3-Clause License (https://opensource.org/licenses/BSD-3-Clause) */ #ifndef __digitalWriteFast_h_ #define __digitalWriteFast_h_ 1 +//#define THROW_ERROR_IF_NOT_FAST // If activated, an error is thrown if pin is not a compile time constant +void NonConstantsUsedForPinModeFast( void ) __attribute__ (( error("Parameter for pinModeFast() function is not constant") )); +void NonConstantsUsedForDigitalWriteFast( void ) __attribute__ (( error("Parameter for digitalWriteFast() function is not constant") )); +void NonConstantsUsedForDigitalToggleFast( void ) __attribute__ (( error("Parameter for digitalToggleFast() function is not constant") )); +int NonConstantsUsedForDigitalReadFast( void ) __attribute__ (( error("Parameter for digitalReadFast() function is not constant") )); + +#if !defined(MEGATINYCORE) // megaTinyCore has it own digitalWriteFast function set, except digitalToggleFast(). + //#define SANGUINO_PINOUT // define for Sanguino pinout // general macros/defines @@ -27,6 +37,8 @@ # define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit)) #endif +#include // declarations for the fallback to digitalWrite(), digitalRead() etc. + // --- Arduino Mega and ATmega128x/256x based boards --- #if (defined(ARDUINO_AVR_MEGA) || \ defined(ARDUINO_AVR_MEGA1280) || \ @@ -299,39 +311,36 @@ #define __digitalPinToPortReg(P) (((P) <= 7) ? &PORTA : &PORTB) #define __digitalPinToDDRReg(P) (((P) <= 7) ? &DDRA : &DDRB) #define __digitalPinToPINReg(P) (((P) <= 7) ? &PINA : &PINB) -# endif -# if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) +# if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) // https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/variants/tinyx41_cw/pins_arduino.h#L334 // Clockwise layout #define __digitalPinToBit(P) (((P) <= 7) ? (P) : ((P) == 11 ? (3) : 10 - (P))) -# else +# else #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 ) +# endif # endif - #endif - -void NonConstantsUsedForPinModeFast( void ) __attribute__ (( error("Parameter for pinModeFast() function is not constant") )); -void NonConstantsUsedForDigitalWriteFast( void ) __attribute__ (( error("Parameter for digitalWriteFast() function is not constant") )); -void NonConstantsUsedForDigitalToggleFast( void ) __attribute__ (( error("Parameter for digitalToggleFast() function is not constant") )); -int NonConstantsUsedForDigitalReadFast( void ) __attribute__ (( error("Parameter for digitalReadFast() function is not constant") )); - #if !defined(digitalWriteFast) # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) # if defined(THROW_ERROR_IF_NOT_FAST) #define digitalWriteFast(P, V) \ -if (__builtin_constant_p(P)) { \ - BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ -} else { \ +do { \ + if (__builtin_constant_p(P)) { \ + BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ + } else { \ NonConstantsUsedForDigitalWriteFast(); \ -} + } \ +} while (0) # else #define digitalWriteFast(P, V) \ -if (__builtin_constant_p(P)) { \ - BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ -} else { \ - digitalWrite((P), (V)); \ -} +do { \ + if (__builtin_constant_p(P)) { \ + BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ + } else { \ + digitalWrite((P), (V)); \ + } \ +} while (0) # endif // defined(THROW_ERROR_IF_NOT_FAST) # else #define digitalWriteFast digitalWrite @@ -342,28 +351,32 @@ if (__builtin_constant_p(P)) { \ # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) # if defined(THROW_ERROR_IF_NOT_FAST) #define pinModeFast(P, V) \ -if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ - if (V == INPUT_PULLUP) {\ - BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ - BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ +do { \ + if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ + if (V == INPUT_PULLUP) {\ + BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ + BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ + } else { \ + BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ + } \ } else { \ - BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ - } \ -} else { \ NonConstantsUsedForPinModeFast(); \ -} + } \ +} while (0) # else #define pinModeFast(P, V) \ -if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ - if (V == INPUT_PULLUP) {\ - BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ - BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ +do { \ + if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ + if (V == INPUT_PULLUP) {\ + BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ + BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ + } else { \ + BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ + } \ } else { \ - BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ + pinMode((P), (V)); \ } \ -} else { \ - pinMode((P), (V)); \ -} +} while (0) # endif // defined(THROW_ERROR_IF_NOT_FAST) # else #define pinModeFast pinMode @@ -375,17 +388,11 @@ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ # if defined(THROW_ERROR_IF_NOT_FAST) #define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) // since we have return values, it is easier to implement it by ?: -#define __digitalReadFast(P ) \ - (__builtin_constant_p(P) ) ? \ - (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ - NonConstantsUsedForDigitalReadFast() +#define __digitalReadFast(P ) ( (__builtin_constant_p(P) ) ? (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : NonConstantsUsedForDigitalReadFast() ) # else #define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) // since we have return values, it is easier to implement it by ?: -#define __digitalReadFast(P ) \ - (__builtin_constant_p(P) ) ? \ - (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ - digitalRead((P)) +#define __digitalReadFast(P ) ( (__builtin_constant_p(P) ) ? (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : digitalRead((P)) ) # endif // defined(THROW_ERROR_IF_NOT_FAST) # else #define digitalReadFast digitalRead @@ -396,22 +403,27 @@ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg) # if defined(THROW_ERROR_IF_NOT_FAST) #define digitalToggleFast(P) \ -if (__builtin_constant_p(P)) { \ - BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ -} else { \ +do { \ + if (__builtin_constant_p(P)) { \ + BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ + } else { \ NonConstantsUsedForDigitalToggleFast(); \ -} + } \ +} while (0) # else #define digitalToggleFast(P) \ -if (__builtin_constant_p(P)) { \ - BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ -} else { \ - digitalWrite(P, ! digitalRead(P)); \ -} +do { \ + if (__builtin_constant_p(P)) { \ + BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ + } else { \ + digitalWrite(P, ! digitalRead(P)); \ + } \ +} while (0) # endif // defined(THROW_ERROR_IF_NOT_FAST) # else #define digitalToggleFast(P) digitalWrite(P, ! digitalRead(P)) # endif #endif // !defined(digitalToggleFast) +#endif // !defined(MEGATINYCORE) #endif //__digitalWriteFast_h_ diff --git a/src/ir_BangOlufsen.hpp b/src/ir_BangOlufsen.hpp index 3ccaad451..de95898b4 100644 --- a/src/ir_BangOlufsen.hpp +++ b/src/ir_BangOlufsen.hpp @@ -10,7 +10,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Daniel Wallner and Armin Joachimsmeyer + * Copyright (c) 2022-2026 Daniel Wallner and 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 @@ -34,6 +34,15 @@ #ifndef _IR_BANG_OLUFSEN_HPP #define _IR_BANG_OLUFSEN_HPP +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" + +/** \addtogroup Decoder Decoders and encoders for different protocols + * @{ + */ + //============================================================================== // // @@ -41,13 +50,12 @@ // // //============================================================================== -// https://www.mikrocontroller.net/attachment/33137/datalink.pdf +// https://www.mikrocontroller.net/attachment/33137/datalink.pdf page 6 // https://www.mikrocontroller.net/articles/IRMP_-_english#B&O - +// BEO is a Pulse Distance Protocol with 200 us pulse // This protocol is unusual in two ways: - // 1. The carrier frequency is 455 kHz - +// // You can build your own receiver as Bang & Olufsen did (check old schematics) or use a TSOP7000 // Vishay stopped producing TSOP7000 since 2009 so you will probably only find counterfeits: // https://www.vishay.com/files/whatsnew/doc/ff_FastFacts_CounterfeitTSOP7000_Dec72018.pdf @@ -57,47 +65,62 @@ // Other examples may require a different treatment // This particular receiver also did receive lower frequencies but rather poorly and with a lower delay than usual // If you need to parallel a receiver with another one you may need to delay the signal to get in phase with the other receiver - +// // 2. A stream of messages can be sent back to back with a new message immediately following the previous stop space - // It might be that this only happens over IR and not on the datalink protocol // You can choose to support this or not: - -// Alt 1: Mode with gaps between frames -// Set RECORD_GAP_MICROS to at least 16000 to accommodate the unusually long 3. start space -// Can only receive single messages and back to back repeats will result in overflow - -// Alt 2: Break at start mode -// Define ENABLE_BEO_WITHOUT_FRAME_GAP and set RECORD_GAP_MICROS to 13000 to treat the 3. start space as a gap between messages -// The start of a transmission will result in a dummy decode with 0 bits data followed by the actual messages -// If the receiver is not resumed within a ms or so, partial messages will be decoded -// Debug printing in the wrong place is very likely to break reception -// Make sure to check the number of bits to filter dummy and incomplete messages - +// +// Mode 1: Mode with gaps between frames +// Do NOT define ENABLE_BEO_WITHOUT_FRAME_GAP and set RECORD_GAP_MICROS to at least 16000 to accept the unusually long 3. start space +// Can only receive single messages. Back to back repeats will result in overflow +// +// Mode 2: Break at start mode +// Define ENABLE_BEO_WITHOUT_FRAME_GAP and set RECORD_GAP_MICROS to less than 15000 +// This treats the 3. start space of 15.5 ms as a gap between 2 messages, which makes decoding easier :-). +// The receiving of a transmission will then result in a dummy decode of the first 2 start bits with 0 bits data +// followed by a 15.5 ms gap and a data frame with one start bit (originally sent as 4. start bit). +// If the receiver is not immediately resumed after the 2 start bit frame, partial second frame will be decoded! +// Thus debug printing in the wrong place is very likely to break reception! +// Make sure to check the number of bits to filter dummy and incomplete messages. // !!! We assume that the real implementations never set the official first header bit to anything other than 0 !!! // !!! We therefore use 4 start bits instead of the specified 3 and in turn ignore the first header bit of the specification !!! - -// IR messages are 16 bits long and datalink messages have different lengths +// +// IR messages are 16 bits long. Datalink messages have different lengths. // This implementation supports up to 40 bits total length split into 8 bit data/command and a header/address of variable length // Header data with more than 16 bits is stored in decodedIRData.extra - // B&O is a pulse distance protocol, but it has 3 bit values 0, 1 and (equal/repeat) as well as a special start and trailing bit. -// MSB first, 4 start bits + 8 to 16? bit address + 8 bit command + 1 special trailing bit + 1 stop bit. -// Address can be longer than 8 bit. +// +/* + 16 bit Bang&Olufsen, ENABLE_BEO_WITHOUT_FRAME_GAP is enabled + rawIRTimings[44]: + -749450 + + 250,-2850 + + 300,-2850 + 250,-12750 + 250,-2850 + 250,-9050 // 12750 is clipped big value of 15425 + + 250,-5950 + 250,-5950 + 300,-5950 + 250,-2850 + + 250,-5950 + 300,-5900 + 300,-9000 + 250,-2900 + + 250,-9050 + 250,-5950 + 300,-5900 + 300,-2850 + + 300,-9000 + 250,-5950 + 250,-2850 + 300,-12100 // +300, -12100 is trailing bit + + 300 // stop bit + Duration=134400us + + MSB first, 4 start bits + 8 (to 16?) bit address + 8 bit command + 1 special trailing bit + 1 stop bit. + 4 Start bits have the length 1, 1, 5, 1 and are +200 -2925, +200 -2925, +200 -15425, +200 -2925 + Address can be longer than 8 bit. + */ /* * Options for this decoder */ -//#define ENABLE_BEO_WITHOUT_FRAME_GAP // Requires additional 30 bytes program memory. +#define ENABLE_BEO_WITHOUT_FRAME_GAP // Requires additional 30 bytes program memory. Enabled by default, see https://github.com/Arduino-IRremote/Arduino-IRremote/discussions/1181 //#define SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE // This also supports headers up to 32 bit. Requires additional 150 bytes program memory. #if defined(DECODE_BEO) # if defined(ENABLE_BEO_WITHOUT_FRAME_GAP) -# if RECORD_GAP_MICROS > 13000 -#warning If defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to 1300 by "#define RECORD_GAP_MICROS 13000" +# if RECORD_GAP_MICROS > 15000 && !defined(SUPPRESS_BEO_RECORD_GAP_MICROS_WARNING) +#warning If defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to <= 15000 by "#define RECORD_GAP_MICROS 12750" # endif # else -# if RECORD_GAP_MICROS < 16000 -#error If not defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to a value >= 1600 by "#define RECORD_GAP_MICROS 16000" +# if RECORD_GAP_MICROS < 16000 && !defined(SUPPRESS_BEO_RECORD_GAP_MICROS_WARNING) +#error If not defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to a value >= 16000 by "#define RECORD_GAP_MICROS 16000" # endif # endif #endif @@ -106,53 +129,45 @@ #define BEO_UNIT 3125 // All timings are in microseconds -#define BEO_IR_MARK 200 // The length of a mark in the IR protocol -#define BEO_DATALINK_MARK (BEO_UNIT / 2) // The length of a mark in the Datalink protocol +#define BEO_BIT_MARK 200 // The length of a mark in the IR protocol -#define BEO_PULSE_LENGTH_ZERO BEO_UNIT // The length of a one to zero transition -#define BEO_PULSE_LENGTH_EQUAL (2 * BEO_UNIT) // 6250 The length of an equal bit -#define BEO_PULSE_LENGTH_ONE (3 * BEO_UNIT) // 9375 The length of a zero to one transition -#define BEO_PULSE_LENGTH_TRAILING_BIT (4 * BEO_UNIT) // 12500 The length of the stop bit -#define BEO_PULSE_LENGTH_START_BIT (5 * BEO_UNIT) // 15625 The length of the start bit -// It is not allowed to send two ones or zeros, you must send a one or zero and a equal instead. - -//#define BEO_LOCAL_DEBUG -//#define BEO_LOCAL_TRACE +// With decode we see length from 200 to 300 and the 300 leads to errors, if we use 200 as mark length for decode. +// And the space value is at least 3125, so we can do a reluctant test for the mark anyway. +#define BEO_BIT_MARK_FOR_DECODE 250 +#define BEO_DATALINK_BIT_MARK (BEO_UNIT / 2) // The length of a mark in the Datalink protocol -#ifdef BEO_LOCAL_DEBUG -# define BEO_DEBUG_PRINT(...) Serial.print(__VA_ARGS__) -# define BEO_DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__) -#else -# define BEO_DEBUG_PRINT(...) void() -# define BEO_DEBUG_PRINTLN(...) void() -#endif +/* + * For all spaces really sent, the time of one bit mark (200 or 1562) is subtracted before the durations defined below + */ +#define BEO_ZERO_SPACE BEO_UNIT // 3125 +#define BEO_REPETITION_OF_PREVIOUS_BIT_SPACE (2 * BEO_UNIT) // 6250 The length of an repetition bit +#define BEO_ONE_SPACE (3 * BEO_UNIT) // 9375 +#define BEO_TRAILING_BIT_SPACE (4 * BEO_UNIT) // 12500 The length of the space of stop bit +#define BEO_START_BIT_SPACE (5 * BEO_UNIT) // 15625 +#define BEO_REPEAT_PERIOD 100000 // 100 ms - Not used yet -#ifdef BEO_LOCAL_TRACE -# undef BEO_TRACE_PRINT -# undef BEO_TRACE_PRINTLN -# define BEO_TRACE_PRINT(...) Serial.print(__VA_ARGS__) -# define BEO_TRACE_PRINTLN(...) Serial.println(__VA_ARGS__) -#else -# define BEO_TRACE_PRINT(...) void() -# define BEO_TRACE_PRINTLN(...) void() -#endif +// It is not allowed to send two ones or zeros, you must send a one or zero and a equal instead. /************************************ * Start of send and decode functions ************************************/ /* - * TODO aNumberOfRepeats are handled not correctly if ENABLE_BEO_WITHOUT_FRAME_GAP is defined + * TODO aNumberOfRepeats is handled not correctly if ENABLE_BEO_WITHOUT_FRAME_GAP is defined + * By default 16 bits are sent. + * @param aNumberOfHeaderBits default is 8, can be 24 at maximum */ void IRsend::sendBangOlufsen(uint16_t aHeader, uint8_t aData, int_fast8_t aNumberOfRepeats, int8_t aNumberOfHeaderBits) { for (int_fast8_t i = 0; i < aNumberOfRepeats + 1; ++i) { - sendBangOlufsenRaw((uint32_t(aHeader) << 8) | aData, aNumberOfHeaderBits + 8, i != 0); + // send 16 bits by default + sendBangOlufsenRaw((uint32_t(aHeader) << aNumberOfHeaderBits) | aData, aNumberOfHeaderBits + BEO_DATA_BITS, i != 0); } } void IRsend::sendBangOlufsenDataLink(uint32_t aHeader, uint8_t aData, int_fast8_t aNumberOfRepeats, int8_t aNumberOfHeaderBits) { for (int_fast8_t i = 0; i < aNumberOfRepeats + 1; ++i) { - sendBangOlufsenRawDataLink((uint64_t(aHeader) << 8) | aData, aNumberOfHeaderBits + 8, i != 0, true); + sendBangOlufsenRawDataLink((uint64_t(aHeader) << aNumberOfHeaderBits) | aData, aNumberOfHeaderBits + BEO_DATA_BITS, i != 0, + true); } } @@ -175,41 +190,44 @@ void IRsend::sendBangOlufsenRaw(uint32_t aRawData, int_fast8_t aBits, bool aBack // AGC / Start - 3 bits + first constant 0 header bit described in the official documentation if (!aBackToBack) { - mark(BEO_IR_MARK); + mark(BEO_BIT_MARK); } - space(BEO_PULSE_LENGTH_ZERO - BEO_IR_MARK); - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_ZERO - BEO_IR_MARK); - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_START_BIT - BEO_IR_MARK); + space(BEO_ZERO_SPACE - BEO_BIT_MARK); + mark(BEO_BIT_MARK); + space(BEO_ZERO_SPACE - BEO_BIT_MARK); + mark(BEO_BIT_MARK); + space(BEO_START_BIT_SPACE - BEO_BIT_MARK); // First bit of header is assumed to be a constant 0 to have a fixed state to begin with the equal decisions. // So this first 0 is treated as the last bit of AGC - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_ZERO - BEO_IR_MARK); + mark(BEO_BIT_MARK); + space(BEO_ZERO_SPACE - BEO_BIT_MARK); bool tLastBitValueWasOne = false; -// Header / Data + // Send 8 (default) to 24 bit header and 8 bit data. uint32_t mask = 1UL << (aBits - 1); for (; mask; mask >>= 1) { if (tLastBitValueWasOne && !(aRawData & mask)) { - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_ZERO - BEO_IR_MARK); + // 1 to 0 transition + mark(BEO_BIT_MARK); + space(BEO_ZERO_SPACE - BEO_BIT_MARK); tLastBitValueWasOne = false; } else if (!tLastBitValueWasOne && (aRawData & mask)) { - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_ONE - BEO_IR_MARK); + // 0 to 1 transition + mark(BEO_BIT_MARK); + space(BEO_ONE_SPACE - BEO_BIT_MARK); tLastBitValueWasOne = true; } else { - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_EQUAL - BEO_IR_MARK); + // Both values are equal + mark(BEO_BIT_MARK); + space(BEO_REPETITION_OF_PREVIOUS_BIT_SPACE - BEO_BIT_MARK); } } // Stop - mark(BEO_IR_MARK); - space(BEO_PULSE_LENGTH_TRAILING_BIT - BEO_IR_MARK); - mark(BEO_IR_MARK); + mark(BEO_BIT_MARK); + space(BEO_TRAILING_BIT_SPACE - BEO_BIT_MARK); + mark(BEO_BIT_MARK); #else (void) aRawData; @@ -225,7 +243,7 @@ void IRsend::sendBangOlufsenRaw(uint32_t aRawData, int_fast8_t aBits, bool aBack */ void IRsend::sendBangOlufsenRawDataLink(uint64_t aRawData, int_fast8_t aBits, bool aBackToBack, bool aUseDatalinkTiming) { #if defined(USE_NO_SEND_PWM) || BEO_KHZ == 38 // BEO_KHZ == 38 is for unit test which runs the B&O protocol with 38 kHz instead 0f 455 kHz - uint16_t tSendBEOMarkLength = aUseDatalinkTiming ? BEO_DATALINK_MARK : BEO_IR_MARK; + uint16_t tSendBEOMarkLength = aUseDatalinkTiming ? BEO_DATALINK_BIT_MARK : BEO_BIT_MARK; /* * 455 kHz PWM is currently not supported, maximum is 180 kHz @@ -238,16 +256,16 @@ void IRsend::sendBangOlufsenRawDataLink(uint64_t aRawData, int_fast8_t aBits, bo if (!aBackToBack) { mark(tSendBEOMarkLength); } - space(BEO_PULSE_LENGTH_ZERO - tSendBEOMarkLength); + space(BEO_ZERO_SPACE - tSendBEOMarkLength); mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_ZERO - tSendBEOMarkLength); + space(BEO_ZERO_SPACE - tSendBEOMarkLength); mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_START_BIT - tSendBEOMarkLength); + space(BEO_START_BIT_SPACE - tSendBEOMarkLength); // First bit of header is assumed to be a constant 0 to have a fixed state to begin with the equal decisions. // So this first 0 is treated as the last bit of AGC mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_ZERO - tSendBEOMarkLength); + space(BEO_ZERO_SPACE - tSendBEOMarkLength); bool tLastBitValueWasOne = false; // Header / Data @@ -255,21 +273,21 @@ void IRsend::sendBangOlufsenRawDataLink(uint64_t aRawData, int_fast8_t aBits, bo for (; mask; mask >>= 1) { if (tLastBitValueWasOne && !(aRawData & mask)) { mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_ZERO - tSendBEOMarkLength); + space(BEO_ZERO_SPACE - tSendBEOMarkLength); tLastBitValueWasOne = false; } else if (!tLastBitValueWasOne && (aRawData & mask)) { mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_ONE - tSendBEOMarkLength); + space(BEO_ONE_SPACE - tSendBEOMarkLength); tLastBitValueWasOne = true; } else { mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_EQUAL - tSendBEOMarkLength); + space(BEO_REPETITION_OF_PREVIOUS_BIT_SPACE - tSendBEOMarkLength); } } // Stop mark(tSendBEOMarkLength); - space(BEO_PULSE_LENGTH_TRAILING_BIT - tSendBEOMarkLength); + space(BEO_TRAILING_BIT_SPACE - tSendBEOMarkLength); mark(tSendBEOMarkLength); #else @@ -280,7 +298,7 @@ void IRsend::sendBangOlufsenRawDataLink(uint64_t aRawData, int_fast8_t aBits, bo #endif } -#define BEO_MATCH_DELTA (BEO_UNIT / 2 - MICROS_PER_TICK) +#define BEO_MATCH_DELTA (BEO_UNIT / 2 - MICROS_PER_TICK) // use a bigger margin for match than regular matching function static bool matchBeoLength(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) { const uint16_t tMeasuredMicros = aMeasuredTicks * MICROS_PER_TICK; return aMatchValueMicros - BEO_MATCH_DELTA < tMeasuredMicros && tMeasuredMicros < aMatchValueMicros + BEO_MATCH_DELTA; @@ -288,15 +306,21 @@ static bool matchBeoLength(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) bool IRrecv::decodeBangOlufsen() { #if defined(ENABLE_BEO_WITHOUT_FRAME_GAP) - if (decodedIRData.rawDataPtr->rawlen != 6 && decodedIRData.rawDataPtr->rawlen < 36) { // 16 bits minimum + if (decodedIRData.rawlen != 6 && decodedIRData.rawlen < 38) { // 16 bits minimum + DEBUG_PRINT(F("B&O: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 6 or not greater equal 38")); #else - if (decodedIRData.rawDataPtr->rawlen < 44) { // 16 bits minimum + if (decodedIRData.rawlen < 44) { // 16 bits minimum + DEBUG_PRINT(F("B&O: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not greater equal 44")); #endif return false; } #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) - uint16_t protocolMarkLength = 0; // contains BEO_IR_MARK or BEO_DATALINK_MARK depending of 4. mark received + uint16_t protocolMarkLength = 0; // contains BEO_BIT_MARK or BEO_DATALINK_BIT_MARK depending of 4. mark received uint64_t tDecodedRawData = 0; #else uint32_t tDecodedRawData = 0; @@ -305,64 +329,67 @@ bool IRrecv::decodeBangOlufsen() { uint8_t tPulseNumber = 0; uint8_t tBitNumber = 0; - BEO_TRACE_PRINT(F("Pre gap: ")); - BEO_TRACE_PRINT(decodedIRData.rawDataPtr->rawbuf[0] * 50); - BEO_TRACE_PRINT(F(" raw len: ")); - BEO_TRACE_PRINTLN(decodedIRData.rawDataPtr->rawlen); + TRACE_PRINT(F("Pre gap: ")); + TRACE_PRINT((uint32_t)decodedIRData.initialGapTicks * 50); + TRACE_PRINT(F(" raw len: ")); + TRACE_PRINTLN(decodedIRData.rawlen); #if defined(ENABLE_BEO_WITHOUT_FRAME_GAP) - /* - * Check if we have the AGC part of the first frame in a row - */ - if (decodedIRData.rawDataPtr->rawlen == 6) { - if ((matchMark(decodedIRData.rawDataPtr->rawbuf[3], BEO_IR_MARK) - || matchMark(decodedIRData.rawDataPtr->rawbuf[3], BEO_DATALINK_MARK)) - && (matchSpace(decodedIRData.rawDataPtr->rawbuf[4], BEO_PULSE_LENGTH_ZERO - BEO_IR_MARK) - || matchSpace(decodedIRData.rawDataPtr->rawbuf[4], BEO_PULSE_LENGTH_ZERO - BEO_DATALINK_MARK))) { - BEO_TRACE_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_TRACE_PRINTLN(F("B&O: AGC only part detected")); + if (decodedIRData.rawlen == 6) { + /* + * Here we have the AGC part of the "Break at start mode" i.e. start bit 1 and 2. + * Test start bit 2 using IR or Datalink timing + */ + if ((matchMarkWithGreaterRange(irparams.rawbuf[3], BEO_BIT_MARK_FOR_DECODE) + && (matchSpace(irparams.rawbuf[4], BEO_ZERO_SPACE - BEO_BIT_MARK_FOR_DECODE))) + || (matchMark(irparams.rawbuf[3], BEO_DATALINK_BIT_MARK) + && matchSpace(irparams.rawbuf[4], BEO_ZERO_SPACE - BEO_DATALINK_BIT_MARK))) { + TRACE_PRINTLN(F("B&O: AGC only part (start bits 1 + 2 of 4) detected")); } else { - return false; // no B&O protocol + DEBUG_PRINTLN(F("B&O: No AGC only part (start bits 1 + 2 of 4) detected")); + DEBUG_PRINT(F("matchMarkWithGreaterRange([3], 250)=")); + DEBUG_PRINTLN(matchMarkWithGreaterRange(irparams.rawbuf[3], BEO_BIT_MARK_FOR_DECODE)); + return false; } } else { /* - * Check if leading gap is trailing bit of first frame + * Check if leading gap is the start bit space we interpret as gap in "Break at start mode" */ - if (!matchSpace(decodedIRData.rawDataPtr->rawbuf[0], BEO_PULSE_LENGTH_START_BIT)) { - BEO_TRACE_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_TRACE_PRINTLN(F(": Leading gap is wrong")); // Leading gap is trailing bit of first frame - return false; // no B&O protocol + if (!matchSpace(decodedIRData.initialGapTicks, BEO_START_BIT_SPACE)) { + DEBUG_PRINT(F("B&O: Leading gap of ")); + DEBUG_PRINT((uint32_t)decodedIRData.initialGapTicks * 50); + DEBUG_PRINTLN(F(" us is wrong")); + return false; } - if (matchMark(decodedIRData.rawDataPtr->rawbuf[1], BEO_IR_MARK)) { -#if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) - protocolMarkLength = BEO_IR_MARK; - } else if (matchMark(decodedIRData.rawDataPtr->rawbuf[1], BEO_DATALINK_MARK)) { - protocolMarkLength = BEO_DATALINK_MARK; -#endif + if (matchMarkWithGreaterRange(irparams.rawbuf[1], BEO_BIT_MARK_FOR_DECODE)) { +# if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) + protocolMarkLength = BEO_BIT_MARK_FOR_DECODE; + } else if (matchMark(irparams.rawbuf[1], BEO_DATALINK_BIT_MARK)) { + protocolMarkLength = BEO_DATALINK_BIT_MARK; +# endif } else { - BEO_TRACE_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_TRACE_PRINTLN(F(": mark length is wrong")); + DEBUG_PRINTLN(F("B&O: mark length is wrong")); return false; } // skip first zero header bit - for (uint8_t tRawBufferMarkIndex = 3; tRawBufferMarkIndex < decodedIRData.rawDataPtr->rawlen; tRawBufferMarkIndex += 2) { + for (uint8_t tRawBufferMarkIndex = 3; tRawBufferMarkIndex < decodedIRData.rawlen; tRawBufferMarkIndex += 2) { #else - for (uint8_t tRawBufferMarkIndex = 1; tRawBufferMarkIndex < decodedIRData.rawDataPtr->rawlen; tRawBufferMarkIndex += 2) { -#endif + for (uint8_t tRawBufferMarkIndex = 1; tRawBufferMarkIndex < decodedIRData.rawlen; tRawBufferMarkIndex += 2) { +#endif // defined(ENABLE_BEO_WITHOUT_FRAME_GAP) - uint16_t markLength = decodedIRData.rawDataPtr->rawbuf[tRawBufferMarkIndex]; - uint16_t spaceLength = decodedIRData.rawDataPtr->rawbuf[tRawBufferMarkIndex + 1]; + uint16_t markLength = irparams.rawbuf[tRawBufferMarkIndex]; + uint16_t spaceLength = irparams.rawbuf[tRawBufferMarkIndex + 1]; - BEO_TRACE_PRINT(tPulseNumber); - BEO_TRACE_PRINT(' '); - BEO_TRACE_PRINT(markLength * MICROS_PER_TICK); - BEO_TRACE_PRINT(' '); - BEO_TRACE_PRINT(spaceLength * MICROS_PER_TICK); - BEO_TRACE_PRINT(F(" (")); - BEO_TRACE_PRINT((markLength + spaceLength) * MICROS_PER_TICK); - BEO_TRACE_PRINTLN(F(") ")); + TRACE_PRINT(tPulseNumber); + TRACE_PRINT(' '); + TRACE_PRINT(markLength * MICROS_PER_TICK); + TRACE_PRINT(' '); + TRACE_PRINT(spaceLength * MICROS_PER_TICK); + TRACE_PRINT(F(" (")); + TRACE_PRINT((markLength + spaceLength) * MICROS_PER_TICK); + TRACE_PRINTLN(F(") ")); #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP) /* @@ -372,34 +399,32 @@ bool IRrecv::decodeBangOlufsen() { if (tPulseNumber < 4) { if (tPulseNumber < 2) { // bit 0 and 1 - if (matchSpace(spaceLength, BEO_PULSE_LENGTH_START_BIT - BEO_IR_MARK)) { - BEO_TRACE_PRINTLN(F(": detected long start bit -> synchronize state now")); + if (matchSpace(spaceLength, BEO_START_BIT_SPACE - BEO_BIT_MARK_FOR_DECODE)) { + TRACE_PRINTLN(F(": detected long start bit -> synchronize state now")); tPulseNumber = 2; } } else { if (tPulseNumber == 3) { - if (matchMark(markLength, BEO_IR_MARK)) { -#if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) - protocolMarkLength = BEO_IR_MARK; - } else if (matchMark(markLength, BEO_DATALINK_MARK)) { - protocolMarkLength = BEO_DATALINK_MARK; -#endif + if (matchMarkWithGreaterRange(markLength, BEO_BIT_MARK_FOR_DECODE)) { +# if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) + protocolMarkLength = BEO_BIT_MARK_FOR_DECODE; + } else if (matchMark(markLength, BEO_DATALINK_BIT_MARK)) { + protocolMarkLength = BEO_DATALINK_BIT_MARK; +# endif } else { - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINTLN(F(": 4. (start) mark length is wrong")); + DEBUG_PRINTLN(F("B&O: 4. (start) mark length is wrong")); return false; } } // bit 2 and 3 if (!matchBeoLength(markLength + spaceLength, - (tPulseNumber == 2) ? BEO_PULSE_LENGTH_START_BIT : BEO_PULSE_LENGTH_ZERO)) { - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINTLN(F(": Start length is wrong")); + (tPulseNumber == 2) ? BEO_START_BIT_SPACE : BEO_ZERO_SPACE)) { + DEBUG_PRINTLN(F("B&O: Start length is wrong")); return false; } } } else { -#endif +#endif // !defined(ENABLE_BEO_WITHOUT_FRAME_GAP) /* * Decode header / data @@ -408,10 +433,9 @@ bool IRrecv::decodeBangOlufsen() { #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE) if (!matchMark(markLength, protocolMarkLength)) { #else - if (!matchMark(markLength, BEO_IR_MARK)) { + if (!matchMarkWithGreaterRange(markLength, BEO_BIT_MARK_FOR_DECODE)) { #endif - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINTLN(F(": Mark length is wrong")); + DEBUG_PRINTLN(F("B&O: Mark length is wrong")); return false; } @@ -419,15 +443,13 @@ bool IRrecv::decodeBangOlufsen() { * Check for stop after receiving at least 8 bits for data and 4 bits for header */ if (tBitNumber > BEO_DATA_BITS + 4) { - if (matchBeoLength(markLength + spaceLength, BEO_PULSE_LENGTH_TRAILING_BIT)) { - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINTLN(F(": Trailing bit detected")); + if (matchBeoLength(markLength + spaceLength, BEO_TRAILING_BIT_SPACE)) { + DEBUG_PRINTLN(F("B&O: Trailing bit detected")); break; } #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP) - if (tRawBufferMarkIndex >= decodedIRData.rawDataPtr->rawlen - 3) { // (rawlen - 3) is index of trailing bit mark - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINTLN(F(": End of buffer, but no trailing bit detected")); + if (tRawBufferMarkIndex >= decodedIRData.rawlen - 3) { // (rawlen - 3) is index of trailing bit mark + DEBUG_PRINTLN(F("B&O: End of buffer, but no trailing bit detected")); return false; } #endif @@ -436,28 +458,27 @@ bool IRrecv::decodeBangOlufsen() { /* * Decode bit */ - if (tLastDecodedBitValue == 0 && matchBeoLength(markLength + spaceLength, BEO_PULSE_LENGTH_ONE)) { + if (tLastDecodedBitValue == 0 && matchBeoLength(markLength + spaceLength, BEO_ONE_SPACE)) { tLastDecodedBitValue = 1; - } else if (tLastDecodedBitValue == 1 && matchBeoLength(markLength + spaceLength, BEO_PULSE_LENGTH_ZERO)) { + } else if (tLastDecodedBitValue == 1 && matchBeoLength(markLength + spaceLength, BEO_ZERO_SPACE)) { tLastDecodedBitValue = 0; - } else if (!matchBeoLength(markLength + spaceLength, BEO_PULSE_LENGTH_EQUAL)) { - BEO_DEBUG_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_DEBUG_PRINT(F(": Index=")); - BEO_DEBUG_PRINT(tRawBufferMarkIndex); - BEO_DEBUG_PRINT(F(" Length ")); - BEO_DEBUG_PRINT((markLength + spaceLength) * MICROS_PER_TICK); - BEO_DEBUG_PRINTLN(F(" is wrong")); + } else if (!matchBeoLength(markLength + spaceLength, BEO_REPETITION_OF_PREVIOUS_BIT_SPACE)) { + DEBUG_PRINT(F("B&O: Index=")); + DEBUG_PRINT(tRawBufferMarkIndex); + DEBUG_PRINT(F(" Length ")); + DEBUG_PRINT((markLength + spaceLength) * MICROS_PER_TICK); + DEBUG_PRINTLN(F(" is wrong")); return false; } tDecodedRawData <<= 1; tDecodedRawData |= tLastDecodedBitValue; ++tBitNumber; - BEO_TRACE_PRINT(F("Bits ")); - BEO_TRACE_PRINT(tBitNumber); - BEO_TRACE_PRINT(F(" ")); - BEO_TRACE_PRINT(uint32_t(tDecodedRawData >> BEO_DATA_BITS), HEX); - BEO_TRACE_PRINT(F(" ")); - BEO_TRACE_PRINTLN(uint8_t(tDecodedRawData & ((1 << BEO_DATA_BITS) - 1)), HEX); + TRACE_PRINT(F("Bits ")); + TRACE_PRINT(tBitNumber); + TRACE_PRINT(F(" ")); + TRACE_PRINT(uint32_t(tDecodedRawData >> BEO_DATA_BITS), HEX); + TRACE_PRINT(F(" ")); + TRACE_PRINTLN(uint8_t(tDecodedRawData & ((1 << BEO_DATA_BITS) - 1)), HEX); // End of bit decode #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP) } @@ -466,9 +487,8 @@ bool IRrecv::decodeBangOlufsen() { /* * Check for last bit after decoding it */ - if (tRawBufferMarkIndex >= decodedIRData.rawDataPtr->rawlen - 3) { // (rawlen - 3) is index of last bit mark - BEO_TRACE_PRINT(::getProtocolString(BANG_OLUFSEN)); - BEO_TRACE_PRINTLN(F(": Last bit reached")); + if (tRawBufferMarkIndex >= decodedIRData.rawlen - 3) { // (rawlen - 3) is index of last bit mark + TRACE_PRINTLN(F("B&O: Last bit reached")); break; } #endif @@ -479,14 +499,26 @@ bool IRrecv::decodeBangOlufsen() { } #endif - decodedIRData.protocol = BANG_OLUFSEN; - decodedIRData.address = tDecodedRawData >> BEO_DATA_BITS; // lower header tBitNumber - decodedIRData.command = tDecodedRawData & ((1 << BEO_DATA_BITS) - 1); // lower 8 tBitNumber - decodedIRData.extra = tDecodedRawData >> (BEO_DATA_BITS + 16); // upper header tBitNumber - decodedIRData.numberOfBits = tBitNumber; - decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; + LongUnion tValue; + tValue.ULong = tDecodedRawData; decodedIRData.decodedRawData = tDecodedRawData; + decodedIRData.numberOfBits = tBitNumber; + + decodedIRData.protocol = BANG_OLUFSEN; + decodedIRData.command = tValue.UByte.LowByte; + tValue.ULong = tValue.ULong >> BEO_DATA_BITS; + decodedIRData.address = tValue.UWord.LowWord; + if (tBitNumber > 24) { // 24 = 8 bit command and 16 bit address + decodedIRData.extra = tValue.UByte.MidHighByte; + decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST | IRDATA_FLAGS_EXTRA_INFO; + } else { + decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; + } return true; } + +/** @}*/ +#include "LocalDebugLevelEnd.h" + #endif // _IR_BANG_OLUFSEN_HPP diff --git a/src/ir_BoseWave.hpp b/src/ir_BoseWave.hpp index bac9dcce9..0118273b7 100644 --- a/src/ir_BoseWave.hpp +++ b/src/ir_BoseWave.hpp @@ -9,11 +9,9 @@ #ifndef _IR_BOSEWAVE_HPP #define _IR_BOSEWAVE_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -30,10 +28,10 @@ // // Support for Bose Wave Radio CD initially provided by https://github.com/uvotguy. // -// As seen on my trusty oscilloscope, there is no repeat code. Instead, when I +// As seen on my oscilloscope, there is no repeat code. Instead, when I // press and hold a button on my remote, it sends a command, makes a 51.2ms space, -// and resends the command, etc, etc. -// LSB first, 1 start bit + 8 bit data + 8 bit inverted data + 1 stop bit. +// and resends the command again, and so on. +// 38 kHz, LSB first, 1 start bit + 8 bit data + 8 bit inverted data + 1 stop bit. #define BOSEWAVE_BITS 16 // Command and inverted command #define BOSEWAVE_HEADER_MARK 1014 // 1014 are 39 clock periods (I counted 3 times!) @@ -46,9 +44,9 @@ #define BOSEWAVE_REPEAT_DISTANCE 50000 #define BOSEWAVE_MAXIMUM_REPEAT_DISTANCE 62000 -struct PulseDistanceWidthProtocolConstants BoseWaveProtocolConstants = { BOSEWAVE, BOSEWAVE_KHZ, BOSEWAVE_HEADER_MARK, -BOSEWAVE_HEADER_SPACE, BOSEWAVE_BIT_MARK, BOSEWAVE_ONE_SPACE, BOSEWAVE_BIT_MARK, BOSEWAVE_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST - , (BOSEWAVE_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const BoseWaveProtocolConstants PROGMEM = {BOSEWAVE, BOSEWAVE_KHZ, BOSEWAVE_HEADER_MARK, + BOSEWAVE_HEADER_SPACE, BOSEWAVE_BIT_MARK, BOSEWAVE_ONE_SPACE, BOSEWAVE_BIT_MARK, BOSEWAVE_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE + , (BOSEWAVE_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions @@ -58,38 +56,28 @@ void IRsend::sendBoseWave(uint8_t aCommand, int_fast8_t aNumberOfRepeats) { // send 8 command bits and then 8 inverted command bits LSB first uint16_t tData = ((~aCommand) << 8) | aCommand; - sendPulseDistanceWidth(&BoseWaveProtocolConstants, tData, BOSEWAVE_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&BoseWaveProtocolConstants, tData, BOSEWAVE_BITS, aNumberOfRepeats); } bool IRrecv::decodeBoseWave() { - if (!checkHeader(&BoseWaveProtocolConstants)) { + if (!checkHeader_P(&BoseWaveProtocolConstants)) { return false; } // Check we have enough data +4 for initial gap, start bit mark and space + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != (2 * BOSEWAVE_BITS) + 4) { - IR_DEBUG_PRINT(F("Bose: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 36")); + if (decodedIRData.rawlen != (2 * BOSEWAVE_BITS) + 4) { + DEBUG_PRINT(F("Bose: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 36")); return false; } - if (!decodePulseDistanceWidthData(&BoseWaveProtocolConstants, BOSEWAVE_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Bose: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&BoseWaveProtocolConstants, BOSEWAVE_BITS); // Stop bit - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[3 + (2 * BOSEWAVE_BITS)], BOSEWAVE_BIT_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Bose: ")); - Serial.println(F("Stop bit mark length is wrong")); -#endif + if (!matchMark(irparams.rawbuf[3 + (2 * BOSEWAVE_BITS)], BOSEWAVE_BIT_MARK)) { + DEBUG_PRINTLN(F("Bose: Stop bit mark length is wrong")); return false; } @@ -100,10 +88,7 @@ bool IRrecv::decodeBoseWave() { uint8_t tCommandInverted = tDecodedValue >> 8; // parity check for command. Use this variant to avoid compiler warning "comparison of promoted ~unsigned with unsigned [-Wsign-compare]" if ((tCommandNotInverted ^ tCommandInverted) != 0xFF) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Bose: ")); - Serial.println(F("Command and inverted command check failed")); -#endif + DEBUG_PRINTLN(F("Bose: Command and inverted command check failed")); return false; } decodedIRData.command = tCommandNotInverted; @@ -117,7 +102,6 @@ bool IRrecv::decodeBoseWave() { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_BOSEWAVE_HPP diff --git a/src/ir_Denon.hpp b/src/ir_Denon.hpp index bfb48a6df..ec1a3324d 100644 --- a/src/ir_Denon.hpp +++ b/src/ir_Denon.hpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2026 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 @@ -32,11 +32,9 @@ #ifndef _IR_DENON_HPP #define _IR_DENON_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -82,7 +80,7 @@ * 000A 0046 000A 0046 000A 001E 000A 001E 000A 001E 000A 0046 000A 001E 000A 001E // 8 inverted command bits * 000A 0046 000A 0046 000A 0679 // 2 frame bits 1,1 + stop bit + space for Repeat * From analyzing the codes for Tuner preset 1 to 8 in tab Main Zone ID#1 it is obvious, that the protocol is LSB first at least for command. - * All Denon codes with 32 as 3. value use the Kaseyikyo Denon variant. + * All Denon codes with 32 as 3. value use the Kaseikyo Denon variant. */ // LSB first, no start bit, 5 address + 8 command + 2 frame (0,0) + 1 stop bit - each frame 2 times // Every frame is auto repeated with a space period of 45 ms and the command and frame inverted to (1,1) or (0,1) for SHARP. @@ -105,47 +103,61 @@ #define DENON_HEADER_MARK DENON_UNIT // The length of the Header:Mark #define DENON_HEADER_SPACE (3 * DENON_UNIT) // 780 // The length of the Header:Space -struct PulseDistanceWidthProtocolConstants DenonProtocolConstants = { DENON, DENON_KHZ, DENON_HEADER_MARK, DENON_HEADER_SPACE, -DENON_BIT_MARK, DENON_ONE_SPACE, DENON_BIT_MARK, DENON_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, - (DENON_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const DenonProtocolConstants PROGMEM = {DENON, DENON_KHZ, DENON_HEADER_MARK, DENON_HEADER_SPACE, + DENON_BIT_MARK, DENON_ONE_SPACE, DENON_BIT_MARK, DENON_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, + (DENON_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions ************************************/ void IRsend::sendSharp(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { - sendDenon(aAddress, aCommand, aNumberOfRepeats, true); + sendDenon(aAddress, aCommand, aNumberOfRepeats, 1); + // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1272 +} + +void IRsend::sendSharp2(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { + sendDenon(aAddress, aCommand, aNumberOfRepeats, 2); } -void IRsend::sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aSendSharp) { +/* + * Denon frames are always sent 3 times. A non inverted (normal), an inverted frame, ending with a normal frame. + * Repeats are done by just adding an inverted and a normal frame with no extra delay, so it is quite responsible :-) + * If you specify a repeat of e.g. 3, then 3 + 6 frames are sent. + * Measured at Denon RC 1081. + */ +void IRsend::sendDenon(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aSendSharpFrameMarker) { // Set IR carrier frequency enableIROut (DENON_KHZ); // 38 kHz // Add frame marker for sharp uint16_t tCommand = aCommand; - if (aSendSharp) { - tCommand |= 0x0200; // the 2 upper bits are 00 for Denon and 10 for Sharp - } + // see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1272 + tCommand |= aSendSharpFrameMarker << 8; // the 2 upper bits are 00 for Denon and 01 or 10 for Sharp + uint16_t tData = aAddress | ((uint16_t) tCommand << DENON_ADDRESS_BITS); - uint16_t tInvertedData = (tData ^ 0x7FE0); // Command and frame (upper 10 bits) are inverted + uint16_t tInvertedData = (tData ^ 0x7FE0); // Command and frame (upper 10 bits, bit 5 to 14) are inverted uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { // Data - sendPulseDistanceWidthData(&DenonProtocolConstants, tData, DENON_BITS); + sendPulseDistanceWidthData_P(&DenonProtocolConstants, tData, DENON_BITS); // Inverted autorepeat frame delay(DENON_AUTO_REPEAT_DISTANCE / MICROS_IN_ONE_MILLI); - sendPulseDistanceWidthData(&DenonProtocolConstants, tInvertedData, DENON_BITS); + sendPulseDistanceWidthData_P(&DenonProtocolConstants, tInvertedData, DENON_BITS); tNumberOfCommands--; - // skip last delay! - if (tNumberOfCommands > 0) { - // send repeated command with a fixed space gap - delay( DENON_AUTO_REPEAT_DISTANCE / MICROS_IN_ONE_MILLI); - } + // send repeated command with a fixed space gap + delay( DENON_AUTO_REPEAT_DISTANCE / MICROS_IN_ONE_MILLI); } + /* + * always end with a normal frame + * skip last delay! + */ + sendPulseDistanceWidthData_P(&DenonProtocolConstants, tData, DENON_BITS); + } bool IRrecv::decodeSharp() { @@ -156,31 +168,22 @@ bool IRrecv::decodeDenon() { // we have no start bit, so check for the exact amount of data bits // Check we have the right amount of data (32). The + 2 is for initial gap + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != (2 * DENON_BITS) + 2) { - IR_DEBUG_PRINT(F("Denon: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 32")); + if (decodedIRData.rawlen != (2 * DENON_BITS) + 2) { + DEBUG_PRINT(F("Denon: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 32")); return false; } - // Try to decode as Denon protocol - if (!decodePulseDistanceWidthData(&DenonProtocolConstants, DENON_BITS, 1)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Denon: ")); - Serial.println(F("Decode failed")); -#endif + // Check for first mark, which is no AGC or start bit. This prevents Sony15 from being decoded as Denon. + // matchMark is too sensitive! + if (irparams.rawbuf[1] >= ((2 * DENON_HEADER_MARK) / MICROS_PER_TICK)) { + DEBUG_PRINTLN(F("Denon: First mark length is wrong")); return false; } - // Check for stop mark - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[(2 * DENON_BITS) + 1], DENON_HEADER_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Denon: ")); - Serial.println(F("Stop bit mark length is wrong")); -#endif - return false; - } + // Try to decode as Denon protocol + decodePulseDistanceWidthData_P(&DenonProtocolConstants, DENON_BITS, 1); // Success decodedIRData.address = decodedIRData.decodedRawData & 0x1F; @@ -189,50 +192,52 @@ bool IRrecv::decodeDenon() { decodedIRData.command &= 0xFF; // Check for (auto) repeat - if (decodedIRData.rawDataPtr->rawbuf[0] < ((DENON_AUTO_REPEAT_DISTANCE + (DENON_AUTO_REPEAT_DISTANCE / 4)) / MICROS_PER_TICK)) { - repeatCount++; - if (repeatCount > 1) { // skip first auto repeat - decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT; - } + if (decodedIRData.initialGapTicks < ((DENON_AUTO_REPEAT_DISTANCE + (DENON_AUTO_REPEAT_DISTANCE / 4)) / MICROS_PER_TICK)) { + decodedIRData.flags |= IRDATA_FLAGS_IS_AUTO_REPEAT; - if (tFrameBits & 0x01) { + repeatCount++; + /* + * 1. repeat is inverted autorepeat -> IRDATA_FLAGS_IS_AUTO_REPEAT + * 2. repeat is normal autorepeat (end) or 1. normal repeat -> IRDATA_FLAGS_IS_AUTO_REPEAT + * 3. repeat is inverted autorepeat of the 1. repeat -> IRDATA_FLAGS_IS_REPEAT (not the correct frame, but this enables easy counting of repeats) + * 4. repeat is normal autorepeat (end) or 2. normal repeat -> IRDATA_FLAGS_IS_AUTO_REPEAT + * 5. repeat is inverted autorepeat of the 2. repeat -> IRDATA_FLAGS_IS_REPEAT (not the correct frame, but this enables easy counting of repeats) + * 6. repeat is normal autorepeat (end) or 3. normal repeat -> IRDATA_FLAGS_IS_AUTO_REPEAT + */ + + if (repeatCount & 0x01) { /* - * Here we are in the auto repeated frame with the inverted command + * Here we are in an inverted auto repeated frame where the command and frame bits are inverted */ -#if defined(LOCAL_DEBUG) - Serial.print(F("Denon: ")); - Serial.println(F("Autorepeat received=")); -#endif - decodedIRData.flags |= IRDATA_FLAGS_IS_AUTO_REPEAT; + DEBUG_PRINTLN(F("Denon: Inverted frame")); + + if (repeatCount > 1) { // skip first auto repeat + decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT; + } // Check parity of consecutive received commands. There is no parity in one data set. if ((uint8_t) lastDecodedCommand != (uint8_t)(~decodedIRData.command)) { decodedIRData.flags |= IRDATA_FLAGS_PARITY_FAILED; -#if defined(LOCAL_DEBUG) - Serial.print(F("Denon: ")); - Serial.print(F("Parity check for repeat failed. Last command=")); - Serial.print(lastDecodedCommand, HEX); - Serial.print(F(" current=")); - Serial.println(~decodedIRData.command, HEX); -#endif + + DEBUG_PRINT(F("Denon: Parity check of inverted with non inverted frame failed. Last command=")); + DEBUG_PRINT((uint8_t )lastDecodedCommand, HEX); + DEBUG_PRINT(F(" current=")); + DEBUG_PRINTLN((uint8_t )~decodedIRData.command, HEX); } // always take non inverted command decodedIRData.command = lastDecodedCommand; - } - // repeated command here - if (tFrameBits == 1 || tFrameBits == 2) { - decodedIRData.protocol = SHARP; - } else { - decodedIRData.protocol = DENON; + // inverted command here, re-invert the frame bits for later protocol decoding + tFrameBits = tFrameBits ^ 0x03; } } else { - repeatCount = 0; // first command here - if (tFrameBits == 2) { - decodedIRData.protocol = SHARP; - } else { - decodedIRData.protocol = DENON; - } + repeatCount = 0; + } + + if (tFrameBits) { + decodedIRData.protocol = SHARP; + } else { + decodedIRData.protocol = DENON; } decodedIRData.numberOfBits = DENON_BITS; @@ -257,8 +262,8 @@ void IRsend::sendDenon(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut (DENON_KHZ); #if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)) -// Serial.println( -// "The function sendDenon(data, nbits) is deprecated and may not work as expected! Use sendDenonRaw(data, NumberOfRepeats) or better sendDenon(Address, Command, NumberOfRepeats)."); + DEBUG_PRINTLN( + "The function sendDenon(data, nbits) is deprecated and may not work as expected! Use sendDenonRaw(data, NumberOfRepeats) or better sendDenon(Address, Command, NumberOfRepeats)."); #endif // Header @@ -274,13 +279,13 @@ void IRsend::sendDenon(unsigned long data, int nbits) { * Old function without parameter aNumberOfRepeats */ void IRsend::sendSharp(uint16_t aAddress, uint16_t aCommand) { - sendDenon(aAddress, aCommand, true, 0); + sendDenon(aAddress, aCommand, 0, true); } bool IRrecv::decodeDenonOld(decode_results *aResults) { // Check we have the right amount of data - if (decodedIRData.rawDataPtr->rawlen != 1 + 2 + (2 * DENON_BITS) + 1) { + if (decodedIRData.rawlen != 1 + 2 + (2 * DENON_BITS) + 1) { return false; } @@ -293,10 +298,8 @@ bool IRrecv::decodeDenonOld(decode_results *aResults) { return false; } - // Try to decode as Denon protocol - if (!decodePulseDistanceWidthData(DENON_BITS, 3, DENON_BIT_MARK, 0, DENON_ONE_SPACE, DENON_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST)) { - return false; - } + // Try to decode as Denon protocol. + decodePulseDistanceWidthData(DENON_BITS, 3, DENON_BIT_MARK, DENON_ONE_SPACE, 0, PROTOCOL_IS_MSB_FIRST); // Success aResults->value = decodedIRData.decodedRawData; @@ -307,7 +310,6 @@ bool IRrecv::decodeDenonOld(decode_results *aResults) { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_DENON_HPP diff --git a/src/ir_DistanceWidthProtocol.hpp b/src/ir_DistanceWidthProtocol.hpp index 0908f1544..4313b320b 100644 --- a/src/ir_DistanceWidthProtocol.hpp +++ b/src/ir_DistanceWidthProtocol.hpp @@ -2,9 +2,16 @@ * ir_DistanceWidthProtocol.hpp * * Contains only the decoder functions for universal pulse width or pulse distance protocols! - * The send functions are used by almost all protocols and therefore in IRSend.hh. + * The send functions are used by almost all protocols and are therefore located in IRSend.hpp. + * + * If RAM is not more than 2k, the decoder only accepts mark or space durations up to 50 * 50 (MICROS_PER_TICK) = 2500 microseconds + * to save RAM space, otherwise it accepts durations up to 10 ms. + * + * This decoder tries to decode the protocols: + * - Pulse distance with constant pulse length + * - Pulse distance width with constant period length + * - Pulse width with constant pause length - not enabled yet * - * This decoder tries to decode a pulse distance or pulse distance width with constant period (or pulse width - not enabled yet) protocol. * 1. Analyze all space and mark length * 2. Decide which protocol we have * 3. Try to decode with the mark and space data found in step 1 @@ -23,15 +30,15 @@ * https://github.com/Arduino-IRremote/Arduino-IRremote/blob/d51b540cb2ddf1424888d2d9e6b62fe1ef46859d/examples/SendDemo/SendDemo.ino#L175 * sendPulseDistanceWidthFromArray(uint_fast8_t aFrequencyKHz, unsigned int aHeaderMarkMicros, * unsigned int aHeaderSpaceMicros, unsigned int aOneMarkMicros, unsigned int aOneSpaceMicros, unsigned int aZeroMarkMicros, - * unsigned int aZeroSpaceMicros, uint32_t *aDecodedRawDataArray, unsigned int aNumberOfBits, bool aMSBFirst, - * bool aSendStopBit, unsigned int aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) + * unsigned int aZeroSpaceMicros, uint32_t *aDecodedRawDataArray, unsigned int aNumberOfBits, uint8_t aFlags, + * unsigned int aRepeatPeriodMillis, int_fast8_t aNumberOfRepeats) * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2022-2023 Armin Joachimsmeyer + * Copyright (c) 2022-2026 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 @@ -55,25 +62,31 @@ #ifndef _IR_DISTANCE_WIDTH_HPP #define _IR_DISTANCE_WIDTH_HPP +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" + +/** \addtogroup Decoder Decoders and encoders for different protocols + * @{ + */ + #if !defined(DISTANCE_WIDTH_MAXIMUM_REPEAT_DISTANCE_MICROS) #define DISTANCE_WIDTH_MAXIMUM_REPEAT_DISTANCE_MICROS 100000 // 100 ms, bit it is just a guess #endif -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +//#define SHOW_DISTANCE_WIDTH_DECODER_ERRORS // Prints errors which prevents data to be decoded as distance width data -// accept durations up to 50 * 50 (MICROS_PER_TICK) 2500 microseconds -#define DURATION_ARRAY_SIZE 50 +#if !defined(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE) +# if (defined(RAMSIZE) && RAMSIZE <= 0x800) || (defined(RAMEND) && RAMEND <= 0x8FF) +#define DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE 50 // To save program space, the decoder only accepts mark or space durations up to 50 * 50 (MICROS_PER_TICK) = 2500 microseconds +# else +#define DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE 200 // The decoder accepts mark or space durations up to 200 * 50 (MICROS_PER_TICK) = 10 milliseconds +# endif +#endif // Switch the decoding according to your needs //#define USE_MSB_DECODING_FOR_DISTANCE_DECODER // If active, it resembles LG, otherwise LSB first as most other protocols e.g. NEC and Kaseikyo/Panasonic -/** \addtogroup Decoder Decoders and encoders for different protocols - * @{ - */ //===================================================================================== // DDD III SSS TTTTTT AA N N CCC EEEE W W III DDD TTTTTT H H // D D I S TT A A NN N C E W W I D D TT H H @@ -82,6 +95,34 @@ // DDD III SSSS TT A A N N CCC EEEE W W III DDD TT H H //===================================================================================== // see: https://www.mikrocontroller.net/articles/IRMP_-_english#Codings +/* + Example output of UnitTest.ino for PulseWidth protocol: + Protocol=PulseWidth Raw-Data=0x87654321 32 bits LSB first + Send on a 8 bit platform with: IrSender.sendPulseDistanceWidth(38, 950, 550, 600, 300, 300, 300, 0x87654321, 32, PROTOCOL_IS_LSB_FIRST, , ); + rawData[66]: + -1088600 + + 950,- 550 + + 600,- 300 + 300,- 300 + 350,- 250 + 350,- 250 + + 350,- 300 + 600,- 300 + 300,- 300 + 300,- 300 + + 650,- 250 + 650,- 250 + 300,- 300 + 350,- 250 + + 350,- 300 + 300,- 300 + 600,- 300 + 300,- 300 + + 600,- 300 + 350,- 250 + 600,- 300 + 350,- 250 + + 350,- 300 + 600,- 300 + 600,- 300 + 300,- 300 + + 600,- 300 + 600,- 300 + 600,- 300 + 300,- 300 + + 300,- 300 + 300,- 300 + 350,- 250 + 650 + Sum: 24500 + + Example output of UnitTest.ino for PulseDistanceWidth protocol: + Protocol=PulseDistance Raw-Data=0x76 7 bits LSB first + Send on a 8 bit platform with: IrSender.sendPulseDistanceWidth(38, 5950, 500, 550, 1450, 1550, 500, 0x76, 7, PROTOCOL_IS_LSB_FIRST, , ); + rawData[18]: + -1092450 + +5950,- 500 + +1500,- 500 + 500,-1450 + 550,-1450 +1550,- 450 + + 550,-1450 + 550,-1450 + 550,-1450 + 550 + Sum: 20950 + */ + #if defined(LOCAL_DEBUG) void printDurations(uint8_t aArray[], uint8_t aMaxIndex) { for (uint_fast8_t i = 0; i <= aMaxIndex; i++) { @@ -108,11 +149,13 @@ void printDurations(uint8_t aArray[], uint8_t aMaxIndex) { #endif /* + * We count all consecutive (allow only one gap between) durations and compute the average. * @return false if more than 2 distinct duration values found */ bool aggregateArrayCounts(uint8_t aArray[], uint8_t aMaxIndex, uint8_t *aShortIndex, uint8_t *aLongIndex) { uint8_t tSum = 0; uint16_t tWeightedSum = 0; + uint8_t tGapCount = 0; for (uint_fast8_t i = 0; i <= aMaxIndex; i++) { uint8_t tCurrentDurations = aArray[i]; if (tCurrentDurations != 0) { @@ -120,9 +163,14 @@ bool aggregateArrayCounts(uint8_t aArray[], uint8_t aMaxIndex, uint8_t *aShortIn tSum += tCurrentDurations; tWeightedSum += (tCurrentDurations * i); aArray[i] = 0; + tGapCount = 0; + } else { + tGapCount++; } - if ((tCurrentDurations == 0 || i == aMaxIndex) && tSum != 0) { - // here we have a sum and a gap after the values + if (tSum != 0 && (i == aMaxIndex || tGapCount > 1)) { + /* + * Here we have a sum AND last element OR more than 1 consecutive gap + */ uint8_t tAggregateIndex = (tWeightedSum + (tSum / 2)) / tSum; // with rounding aArray[tAggregateIndex] = tSum; // disabling this line increases code size by 2 - unbelievable! // store aggregate for later decoding @@ -148,44 +196,57 @@ bool aggregateArrayCounts(uint8_t aArray[], uint8_t aMaxIndex, uint8_t *aShortIn * 2. Decide if we have an pulse width or distance protocol * 3. Try to decode with the mark and space data found in step 1 * No data and address decoding, only raw data as result. + * + * Restrictions: + * Only protocols with at least 7 bits (+ start and trailing stop bit) are accepted. + * Pulse or pause duration must be below 2500 us (depends on DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE). + * + * calloc() version is 700 bytes larger :-( */ bool IRrecv::decodeDistanceWidth() { - uint8_t tDurationArray[DURATION_ARRAY_SIZE]; // For up to 49 ticks / 2450 us + /* + * Array for up to 49 ticks / 2500 us (or 199 ticks / 10 ms us if RAM > 2k) + * tick array index 0 covers mark or space durations from 0 to 49 us, and index 49 from 2450 to 2499 us + */ + uint8_t tDurationArray[DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE]; /* - * Accept only protocols with at least 8 bits + * Only protocols with at least 7 bits are accepted */ - if (decodedIRData.rawDataPtr->rawlen < (2 * 8) + 4) { - IR_DEBUG_PRINT(F("PULSE_DISTANCE_WIDTH: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is less than 20")); + if (decodedIRData.rawlen < (2 * 7) + 4) { +#if defined(DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS) + Serial.print(F("PULSE_DISTANCE_WIDTH: ")); + Serial.print(F("Data length=")); + Serial.print(decodedIRData.rawlen); + Serial.println(F(" is less than 18")); +#endif return false; } - uint_fast8_t i; - // Reset duration array - memset(tDurationArray, 0, DURATION_ARRAY_SIZE); + memset(tDurationArray, 0, DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE); uint8_t tIndexOfMaxDuration = 0; /* - * Count number of mark durations up to 49 ticks. Skip leading start and trailing stop bit. + * Count number of mark durations. Skip leading start and trailing stop bit. */ - for (i = 3; i < (uint_fast8_t) decodedIRData.rawDataPtr->rawlen - 2; i += 2) { - auto tDurationTicks = decodedIRData.rawDataPtr->rawbuf[i]; - if (tDurationTicks < DURATION_ARRAY_SIZE) { - tDurationArray[tDurationTicks]++; // count duration if less than DURATION_ARRAY_SIZE (50) + for (IRRawlenType i = 3; i < decodedIRData.rawlen - 2; i += 2) { +#if(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE > 0xFF) + uint16_t tDurationTicks = irparams.rawbuf[i]; +#else + auto tDurationTicks = irparams.rawbuf[i]; +#endif + if (tDurationTicks < DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE) { + tDurationArray[tDurationTicks]++; // count duration if less than DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE if (tIndexOfMaxDuration < tDurationTicks) { tIndexOfMaxDuration = tDurationTicks; } } else { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_DISTANCE_WIDTH: ")); - Serial.print(F("Mark ")); +#if defined(LOCAL_DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS) + Serial.print(F("PULSE_DISTANCE_WIDTH: Mark ")); Serial.print(tDurationTicks * MICROS_PER_TICK); Serial.print(F(" is longer than maximum ")); - Serial.print(DURATION_ARRAY_SIZE * MICROS_PER_TICK); + Serial.print(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE * MICROS_PER_TICK); Serial.print(F(" us. Index=")); Serial.println(i); #endif @@ -205,34 +266,32 @@ bool IRrecv::decodeDistanceWidth() { #endif if (!tSuccess) { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_DISTANCE_WIDTH: ")); - Serial.println(F("Mark aggregation failed, more than 2 distinct mark duration values found")); +#if defined(LOCAL_DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS) + Serial.println(F("PULSE_DISTANCE_WIDTH: Mark aggregation failed, more than 2 distinct mark duration values found")); #endif return false; } // Reset duration array - memset(tDurationArray, 0, DURATION_ARRAY_SIZE); + memset(tDurationArray, 0, DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE); /* * Count number of space durations. Skip leading start and trailing stop bit. */ tIndexOfMaxDuration = 0; - for (i = 4; i < (uint_fast8_t) decodedIRData.rawDataPtr->rawlen - 2; i += 2) { - auto tDurationTicks = decodedIRData.rawDataPtr->rawbuf[i]; - if (tDurationTicks < DURATION_ARRAY_SIZE) { + for (IRRawlenType i = 4; i < decodedIRData.rawlen - 2; i += 2) { + auto tDurationTicks = irparams.rawbuf[i]; + if (tDurationTicks < DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE) { tDurationArray[tDurationTicks]++; if (tIndexOfMaxDuration < tDurationTicks) { tIndexOfMaxDuration = tDurationTicks; } } else { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_DISTANCE_WIDTH: ")); - Serial.print(F("Space ")); +#if defined(LOCAL_DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS) + Serial.print(F("PULSE_DISTANCE_WIDTH: Space ")); Serial.print(tDurationTicks * MICROS_PER_TICK); - Serial.print(F(" is longer than ")); - Serial.print(DURATION_ARRAY_SIZE * MICROS_PER_TICK); + Serial.print(F(" is longer than maximum ")); + Serial.print(DISTANCE_WIDTH_DECODER_DURATION_ARRAY_SIZE * MICROS_PER_TICK); Serial.print(F(" us. Index=")); Serial.println(i); #endif @@ -252,155 +311,191 @@ bool IRrecv::decodeDistanceWidth() { #endif if (!tSuccess) { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_DISTANCE_WIDTH: ")); - Serial.println(F("Space aggregation failed, more than 2 distinct space duration values found")); +#if defined(LOCAL_DEBUG) || defined(SHOW_DISTANCE_WIDTH_DECODER_ERRORS) + Serial.println(F("PULSE_DISTANCE_WIDTH: Space aggregation failed, more than 2 distinct space duration values found")); #endif return false; } +#if RAW_BUFFER_LENGTH <= (512 -4) + uint_fast8_t tNumberOfBits; +#else + uint16_t tNumberOfBits; +#endif + tNumberOfBits = (decodedIRData.rawlen / 2) - 1; + if (tSpaceTicksLong > 0) { + // For PULSE_DISTANCE -including PULSE_DISTANCE_WIDTH- a stop bit is mandatory, for PULSE_WIDTH it is not required! + tNumberOfBits--; // Correct for PULSE_DISTANCE stop bit + } + decodedIRData.numberOfBits = tNumberOfBits; + /* - * Print characteristics of this protocol. Durations are in ticks. + * Print characteristics of this protocol. Durations are in (50 us) ticks. * Number of bits, start bit, start pause, long mark, long space, short mark, short space * - * NEC: 32, 180, 90, 0, 34, 11, 11 - * Samsung32: 32, 90, 90, 0, 34, 11, 11 - * LG: 28, 180, 84, 0, 32, 10, 11 - * JVC: 16, 168, 84, 0, 32, 10, 10 - * Kaseikyo: 48. 69, 35, 0, 26, 9, 9 - * Sony: 12|15|20, 48, 12, 24, 0, 12, 12 // the only known pulse width protocol + * NEC: 32, 180, 90, 11, 34, 11, 11 + * Samsung32: 32, 90, 90, 11, 34, 11, 11 + * LG: 28, 180, 84, 10, 32, 10, 11 + * JVC: 16, 168, 84, 10, 32, 10, 10 + * Kaseikyo: 48. 69, 35, 9, 26, 9, 9 + * Sony: 12|15|20, 48, 12, 24, 12, 12, 12 // the only known pulse width protocol + * Disney monorail + * model: 7, 120, 10, 30, 30, 10, 10 // PulseDistanceWidth. Can be seen as direct conversion of a 7 bit serial timing at 250 baud with a 6 ms start bit. */ #if defined(LOCAL_DEBUG) Serial.print(F("DistanceWidthTimingInfoStruct: ")); - Serial.print(decodedIRData.rawDataPtr->rawbuf[1] * MICROS_PER_TICK); + Serial.print(tNumberOfBits); Serial.print(F(", ")); - Serial.print(decodedIRData.rawDataPtr->rawbuf[2] * MICROS_PER_TICK); + Serial.print(irparams.rawbuf[1] * MICROS_PER_TICK); Serial.print(F(", ")); - Serial.print(tMarkTicksLong * MICROS_PER_TICK); + Serial.print(irparams.rawbuf[2] * MICROS_PER_TICK); Serial.print(F(", ")); - Serial.print(tSpaceTicksLong * MICROS_PER_TICK); + if(tMarkTicksLong == 0) { + Serial.print(tMarkTicksShort * MICROS_PER_TICK); + } else { + Serial.print(tMarkTicksLong * MICROS_PER_TICK); + } + Serial.print(F(", ")); + if(tSpaceTicksLong == 0) { + Serial.print(tSpaceTicksShort * MICROS_PER_TICK); + } else { + Serial.print(tSpaceTicksLong * MICROS_PER_TICK); + } Serial.print(F(", ")); Serial.print(tMarkTicksShort * MICROS_PER_TICK); Serial.print(F(", ")); Serial.println(tSpaceTicksShort * MICROS_PER_TICK); #endif - uint8_t tStartIndex = 3; - // skip leading start bit for decoding. - uint16_t tNumberOfBits = (decodedIRData.rawDataPtr->rawlen / 2) - 1; - if (tSpaceTicksLong > 0 && tMarkTicksLong == 0) { - // For PULSE_DISTANCE a stop bit is mandatory, for PULSE_WIDTH it is not required! - tNumberOfBits--; // Correct for stop bit - } - decodedIRData.numberOfBits = tNumberOfBits; - uint8_t tNumberOfAdditionalArrayValues = (tNumberOfBits - 1) / BITS_IN_RAW_DATA_TYPE; + + uint8_t tNumberOfAdditionalArrayValues = (tNumberOfBits - 1) / BITS_IN_DECODED_RAW_DATA_TYPE; /* * We can have the following protocol timings - * Pulse distance: Pulses/marks are constant, pause/spaces have different length, like NEC. - * Pulse width: Pulses/marks have different length, pause/spaces are constant, like Sony. - * Pulse distance width: Pulses/marks and pause/spaces have different length, often the bit length is constant, like MagiQuest. - * Pulse distance width can be decoded by pulse width decoder, if this decoder does not check the length of pause/spaces. + * PULSE_DISTANCE: Pause/spaces have different length and determine the bit value, longer space is 1. Pulses/marks can be constant, like NEC. + * PULSE_WIDTH: Pulses/marks have different length and determine the bit value, longer mark is 1. Pause/spaces can be constant, like Sony. + * PULSE_DISTANCE_WIDTH: Pulses/marks and pause/spaces have different length, often the bit length is constant, like MagiQuest. Can be decoded by PULSE_DISTANCE approach. */ if (tMarkTicksLong == 0 && tSpaceTicksLong == 0) { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_DISTANCE: ")); - Serial.println(F("Only 1 distinct duration value for each space and mark found")); -#endif + DEBUG_PRINTLN( + F("PULSE_DISTANCE: Cannot decode, because there is only one distinct duration value for each space and mark")); return false; } unsigned int tSpaceMicrosShort; -#if defined DECODE_STRICT_CHECKS +#if defined(LOCAL_DEBUG) if(tMarkTicksLong > 0 && tSpaceTicksLong > 0) { - // We have different mark and space length here, so signal decodePulseDistanceWidthData() not to check against constant length decodePulseDistanceWidthData - tSpaceMicrosShort = 0; + Serial.println(F("PULSE_DISTANCE_WIDTH signal found")); } #endif tSpaceMicrosShort = tSpaceTicksShort * MICROS_PER_TICK; unsigned int tMarkMicrosShort = tMarkTicksShort * MICROS_PER_TICK; unsigned int tMarkMicrosLong = tMarkTicksLong * MICROS_PER_TICK; unsigned int tSpaceMicrosLong = tSpaceTicksLong * MICROS_PER_TICK; + IRRawlenType tStartIndex = 3; // skip leading start bit for decoding. for (uint_fast8_t i = 0; i <= tNumberOfAdditionalArrayValues; ++i) { uint8_t tNumberOfBitsForOneDecode = tNumberOfBits; /* * Decode in 32/64 bit chunks. Only the last chunk can contain less than 32/64 bits */ - if (tNumberOfBitsForOneDecode > BITS_IN_RAW_DATA_TYPE) { - tNumberOfBitsForOneDecode = BITS_IN_RAW_DATA_TYPE; + if (tNumberOfBitsForOneDecode > BITS_IN_DECODED_RAW_DATA_TYPE) { + tNumberOfBitsForOneDecode = BITS_IN_DECODED_RAW_DATA_TYPE; } - bool tResult; - if (tMarkTicksLong > 0) { + if (tSpaceTicksLong > 0) { /* - * Here short and long mark durations found. + * Here short and long space durations found. So we have PULSE_DISTANCE or PULSE_DISTANCE_WIDTH. + * PULSE_DISTANCE_WIDTH can be successfully decoded by only using the timings of space :-). */ - decodedIRData.protocol = PULSE_WIDTH; - tResult = decodePulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, tMarkMicrosLong, tMarkMicrosShort, - tSpaceMicrosShort, 0, + decodedIRData.protocol = PULSE_DISTANCE; // NEC etc. + PULSE_DISTANCE_WIDTH +#if defined(USE_THRESHOLD_DECODER) + decodeWithThresholdPulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, + ((tSpaceMicrosLong + tSpaceMicrosShort) / 2) + MARK_EXCESS_MICROS, // MARK_EXCESS_MICROS is 0 here if not explicitly specified by user +#else + decodePulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, tSpaceMicrosLong, +#endif + PROTOCOL_IS_PULSE_DISTANCE, #if defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER) - true + PROTOCOL_IS_MSB_FIRST #else - false + PROTOCOL_IS_LSB_FIRST #endif ); + } else { /* - * Here short and long space durations found. + * Here no long space duration but short and long mark durations found. So we have PULSE_WIDTH. + * Use timing of marks for decoding here. + * This else case will most likely never be used, but it only requires 12 bytes additional programming space :-) */ - decodedIRData.protocol = PULSE_DISTANCE; - tResult = decodePulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, tMarkMicrosShort, tMarkMicrosShort, - tSpaceMicrosLong, tSpaceMicrosShort, + decodedIRData.protocol = PULSE_WIDTH; // Sony +#if defined(USE_THRESHOLD_DECODER) + decodeWithThresholdPulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, + ((tMarkMicrosLong+ tMarkMicrosShort) / 2) - MARK_EXCESS_MICROS, // MARK_EXCESS_MICROS is 0 here if not explicitly specified by user +#else + decodePulseDistanceWidthData(tNumberOfBitsForOneDecode, tStartIndex, tMarkMicrosLong, +#endif + PROTOCOL_IS_PULSE_WIDTH, #if defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER) - true + PROTOCOL_IS_MSB_FIRST #else - false + PROTOCOL_IS_LSB_FIRST #endif ); + } - if (!tResult) { -#if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_WIDTH: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + DEBUG_PRINT(F("PULSE_WIDTH: decodedRawData=0x")); #if defined(LOCAL_DEBUG) - Serial.print(F("PULSE_WIDTH: ")); - Serial.print(F("decodedRawData=0x")); +# if (__INT_WIDTH__ < 32) Serial.println(decodedIRData.decodedRawData, HEX); +# else + PrintULL::println(&Serial, decodedIRData.decodedRawData, HEX); +# endif #endif + // fill array with decoded data decodedIRData.decodedRawDataArray[i] = decodedIRData.decodedRawData; - tStartIndex += (2 * BITS_IN_RAW_DATA_TYPE); - tNumberOfBits -= BITS_IN_RAW_DATA_TYPE; + tStartIndex += (2 * BITS_IN_DECODED_RAW_DATA_TYPE); + tNumberOfBits -= BITS_IN_DECODED_RAW_DATA_TYPE; } #if defined(USE_MSB_DECODING_FOR_DISTANCE_DECODER) decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; #endif - // Check for repeat - checkForRepeatSpaceTicksAndSetFlag(DISTANCE_WIDTH_MAXIMUM_REPEAT_DISTANCE_MICROS / MICROS_PER_TICK); + // Check for repeat. Check also for equality of last DecodedRawData. + if (decodedIRData.initialGapTicks < DISTANCE_WIDTH_MAXIMUM_REPEAT_DISTANCE_MICROS / MICROS_PER_TICK + && decodedIRData.decodedRawDataArray[tNumberOfAdditionalArrayValues] == lastDecodedRawData) { + decodedIRData.flags |= IRDATA_FLAGS_IS_REPEAT; + } + lastDecodedRawData = decodedIRData.decodedRawData; /* * Store timing data to reproduce frame for sending */ - decodedIRData.DistanceWidthTimingInfo.HeaderMarkMicros = (decodedIRData.rawDataPtr->rawbuf[1] * MICROS_PER_TICK); - decodedIRData.DistanceWidthTimingInfo.HeaderSpaceMicros = (decodedIRData.rawDataPtr->rawbuf[2] * MICROS_PER_TICK); + decodedIRData.DistanceWidthTimingInfo.HeaderMarkMicros = (irparams.rawbuf[1] * MICROS_PER_TICK); + decodedIRData.DistanceWidthTimingInfo.HeaderSpaceMicros = (irparams.rawbuf[2] * MICROS_PER_TICK); decodedIRData.DistanceWidthTimingInfo.ZeroMarkMicros = tMarkMicrosShort; decodedIRData.DistanceWidthTimingInfo.ZeroSpaceMicros = tSpaceMicrosShort; if (tMarkMicrosLong != 0) { - decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosLong; - - decodedIRData.DistanceWidthTimingInfo.OneSpaceMicros = tSpaceMicrosShort; - if (tSpaceMicrosLong != 0) { - // Assume long space for zero when we have PulseDistanceWidth -> enables constant bit length - decodedIRData.DistanceWidthTimingInfo.ZeroSpaceMicros = tSpaceMicrosLong; + if (tSpaceMicrosLong == 0) { + // PULSE_DISTANCE, Sony + decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosLong; + decodedIRData.DistanceWidthTimingInfo.OneSpaceMicros = tSpaceMicrosShort; + } else { + // PULSE_DISTANCE_WIDTH, we have 4 distinct values here + // Assume long space for a one when we have PulseDistanceWidth like for RS232, where a long inactive period (high) is a 1 + decodedIRData.DistanceWidthTimingInfo.OneSpaceMicros = tSpaceMicrosLong; + decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosShort; + decodedIRData.DistanceWidthTimingInfo.ZeroMarkMicros = tMarkMicrosLong; +// // Assume long mark for a one when we have PulseDistanceWidth +// decodedIRData.DistanceWidthTimingInfo.OneSpaceMicros = tSpaceMicrosShort; +// decodedIRData.DistanceWidthTimingInfo.ZeroSpaceMicros = tSpaceMicrosLong; +// decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosLong; } } else { - decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosShort; - + // PULSE_WIDTH, NEC etc. // Here tMarkMicrosLong is 0 => tSpaceMicrosLong != 0 + decodedIRData.DistanceWidthTimingInfo.OneMarkMicros = tMarkMicrosShort; decodedIRData.DistanceWidthTimingInfo.OneSpaceMicros = tSpaceMicrosLong; } @@ -413,7 +508,6 @@ bool IRrecv::decodeDistanceWidth() { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_DISTANCE_WIDTH_HPP diff --git a/src/ir_FAST.hpp b/src/ir_FAST.hpp index 09998ac0e..65017ed97 100644 --- a/src/ir_FAST.hpp +++ b/src/ir_FAST.hpp @@ -1,14 +1,15 @@ /* * ir_FAST.hpp * - * Contains functions for receiving and sending FAST IR protocol with 8 bit command + * Contains functions for receiving and sending FAST IR protocol + * with no address and 16 bit data, interpreted as 8 bit command and 8 bit inverted command * * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * ************************************************************************************ * MIT License * - * Copyright (c) 2023 Armin Joachimsmeyer + * Copyright (c) 2023-2026 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 @@ -34,11 +35,9 @@ #include "TinyIR.h" -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -53,18 +52,18 @@ //============================================================================== #include "TinyIR.h" /* -Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first + Protocol=FAST Address=0x0 Command=0x76 Raw-Data=0x8976 16 bits LSB first +2100,-1050 + 550,- 500 + 550,-1550 + 550,-1550 + 550,- 500 + 550,-1550 + 550,-1550 + 550,-1550 + 550,- 500 + 550,-1550 + 550,- 500 + 550,- 500 + 550,-1550 + 550,- 500 + 550,- 500 + 550,- 500 + 550,-1550 + 550 -Sum: 28900 -*/ -struct PulseDistanceWidthProtocolConstants FASTProtocolConstants = { FAST, FAST_KHZ, FAST_HEADER_MARK, FAST_HEADER_SPACE, -FAST_BIT_MARK, FAST_ONE_SPACE, FAST_BIT_MARK, FAST_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (FAST_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), -NULL }; + Sum: 28900 + */ +struct PulseDistanceWidthProtocolConstants const FASTProtocolConstants PROGMEM = { FAST, FAST_KHZ, FAST_HEADER_MARK, +FAST_HEADER_SPACE, FAST_BIT_MARK, FAST_ONE_SPACE, FAST_BIT_MARK, FAST_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST + | PROTOCOL_IS_PULSE_DISTANCE, (FAST_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr }; /************************************ * Start of send and decode functions @@ -83,7 +82,7 @@ void IRsend::sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats) { mark(FAST_HEADER_MARK); space(FAST_HEADER_SPACE); - sendPulseDistanceWidthData(&FASTProtocolConstants, aCommand | (((uint8_t)(~aCommand)) << 8), FAST_BITS); + sendPulseDistanceWidthData_P(&FASTProtocolConstants, aCommand | (((uint8_t)(~aCommand)) << 8), FAST_BITS); tNumberOfCommands--; // skip last delay! @@ -96,42 +95,32 @@ void IRsend::sendFAST(uint8_t aCommand, int_fast8_t aNumberOfRepeats) { bool IRrecv::decodeFAST() { -// uint_fast8_t tRawlen = decodedIRData.rawDataPtr->rawlen; // Using a local variable does not improve code size +// uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size // Check we have the right amount of data (36). The +4 is for initial gap, start bit mark and space + stop bit mark. - if (decodedIRData.rawDataPtr->rawlen != ((2 * FAST_BITS) + 4)) { - IR_DEBUG_PRINT(F("FAST: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 36")); - return false; - } - - if (!checkHeader(&FASTProtocolConstants)) { + if (decodedIRData.rawlen != ((2 * FAST_BITS) + 4)) { + DEBUG_PRINT(F("FAST: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 36")); return false; } - if (!decodePulseDistanceWidthData(&FASTProtocolConstants, FAST_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("FAST: ")); - Serial.println(F("Decode failed")); -#endif + if (!checkHeader_P(&FASTProtocolConstants)) { return false; } + decodePulseDistanceWidthData_P(&FASTProtocolConstants, FAST_BITS); WordUnion tValue; tValue.UWord = decodedIRData.decodedRawData; - if (tValue.UByte.LowByte != (uint8_t)~(tValue.UByte.HighByte)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("FAST: ")); - Serial.print(F("8 bit parity is not correct. Expected=0x")); - Serial.print((uint8_t)~(tValue.UByte.LowByte), HEX); - Serial.print(F(" received=0x")); - Serial.print(tValue.UByte.HighByte, HEX); - Serial.print(F(" data=0x")); - Serial.println(tValue.UWord, HEX); -#endif + if (tValue.UByte.LowByte != (uint8_t) ~(tValue.UByte.HighByte)) { + DEBUG_PRINT(F("FAST: 8 bit parity is not correct. Expected=0x")); + DEBUG_PRINT((uint8_t) ~(tValue.UByte.LowByte), HEX); + DEBUG_PRINT(F(" received=0x")); + DEBUG_PRINT(tValue.UByte.HighByte, HEX); + DEBUG_PRINT(F(" data=0x")); + DEBUG_PRINTLN(tValue.UWord, HEX); + decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED; } @@ -148,7 +137,6 @@ bool IRrecv::decodeFAST() { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_FAST_HPP diff --git a/src/ir_JVC.hpp b/src/ir_JVC.hpp index 89f9f919f..332c502b9 100644 --- a/src/ir_JVC.hpp +++ b/src/ir_JVC.hpp @@ -32,11 +32,7 @@ #ifndef _IR_JVC_HPP #define _IR_JVC_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -62,7 +58,7 @@ // IRP: {38k,525}<1,-1|1,-3>(16,-8,(D:8,F:8,1,-45)+) // LSB first, 1 start bit + 8 bit address + 8 bit command + 1 stop bit. // The JVC protocol repeats by skipping the header mark and space -> this leads to a poor repeat detection for JVC protocol. -// Some JVC devices require to send 3 repeats. https://github.com/Arduino-IRremote/Arduino-IRremote/issues/21 +// Some JVC devices require to send 3 repeats. #define JVC_ADDRESS_BITS 8 // 8 bit address #define JVC_COMMAND_BITS 8 // Command @@ -79,8 +75,8 @@ #define JVC_REPEAT_DISTANCE (uint16_t)(45 * JVC_UNIT) // 23625 - Commands are repeated with a distance of 23 ms for as long as the key on the remote control is held down. #define JVC_REPEAT_PERIOD 65000 // assume around 40 ms for a JVC frame. JVC IR Remotes: RM-SA911U, RM-SX463U have 45 ms period -struct PulseDistanceWidthProtocolConstants JVCProtocolConstants = { JVC, JVC_KHZ, JVC_HEADER_MARK, JVC_HEADER_SPACE, JVC_BIT_MARK, -JVC_ONE_SPACE, JVC_BIT_MARK, JVC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (JVC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const JVCProtocolConstants PROGMEM = {JVC, JVC_KHZ, JVC_HEADER_MARK, JVC_HEADER_SPACE, JVC_BIT_MARK, + JVC_ONE_SPACE, JVC_BIT_MARK, JVC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, (JVC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions @@ -105,7 +101,7 @@ void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRe while (tNumberOfCommands > 0) { // Address + command - sendPulseDistanceWidthData(&JVCProtocolConstants, aAddress | (aCommand << JVC_ADDRESS_BITS), JVC_BITS); + sendPulseDistanceWidthData_P(&JVCProtocolConstants, aAddress | (aCommand << JVC_ADDRESS_BITS), JVC_BITS); tNumberOfCommands--; // skip last delay! @@ -118,26 +114,25 @@ void IRsend::sendJVC(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRe bool IRrecv::decodeJVC() { -// uint_fast8_t tRawlen = decodedIRData.rawDataPtr->rawlen; // Using a local variable does not improve code size +// uint_fast8_t tRawlen = decodedIRData.rawlen; // Using a local variable does not improve code size // Check we have the right amount of data (36 or 34). The +4 is for initial gap, start bit mark and space + stop bit mark. // +4 is for first frame, +2 is for repeats - if (decodedIRData.rawDataPtr->rawlen != ((2 * JVC_BITS) + 2) && decodedIRData.rawDataPtr->rawlen != ((2 * JVC_BITS) + 4)) { - IR_DEBUG_PRINT(F("JVC: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 34 or 36")); + if (!(decodedIRData.rawlen == ((2 * JVC_BITS) + 2) || decodedIRData.rawlen == ((2 * JVC_BITS) + 4))) { + DEBUG_PRINT(F("JVC: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 34 or 36")); return false; } - if (decodedIRData.rawDataPtr->rawlen == ((2 * JVC_BITS) + 2)) { + if (decodedIRData.rawlen == ((2 * JVC_BITS) + 2)) { /* - * Check for repeat - * Check leading space and first and last mark length + * 34 -> check for repeat distance and check leading space and first and last mark length */ - if (decodedIRData.rawDataPtr->rawbuf[0] < ((JVC_REPEAT_DISTANCE + (JVC_REPEAT_DISTANCE / 4) / MICROS_PER_TICK)) - && matchMark(decodedIRData.rawDataPtr->rawbuf[1], JVC_BIT_MARK) - && matchMark(decodedIRData.rawDataPtr->rawbuf[decodedIRData.rawDataPtr->rawlen - 1], JVC_BIT_MARK)) { + if (lastDecodedProtocol == JVC + && decodedIRData.initialGapTicks < ((JVC_REPEAT_DISTANCE + (JVC_REPEAT_DISTANCE / 4) / MICROS_PER_TICK)) + && matchMark(irparams.rawbuf[1], JVC_BIT_MARK) + && matchMark(irparams.rawbuf[decodedIRData.rawlen - 1], JVC_BIT_MARK)) { /* * We have a repeat here, so do not check for start bit */ @@ -148,19 +143,13 @@ bool IRrecv::decodeJVC() { } } else { - if (!checkHeader(&JVCProtocolConstants)) { + // 36 -> check for new start frame + if (!checkHeader_P(&JVCProtocolConstants)) { return false; } - if (!decodePulseDistanceWidthData(&JVCProtocolConstants, JVC_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("JVC: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&JVCProtocolConstants, JVC_BITS); - // Success // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value decodedIRData.command = decodedIRData.decodedRawData >> JVC_ADDRESS_BITS; // upper 8 bits of LSB first value decodedIRData.address = decodedIRData.decodedRawData & 0xFF; // lowest 8 bit of LSB first value @@ -195,9 +184,9 @@ bool IRrecv::decodeJVCMSB(decode_results *aResults) { // Check we have enough data - +3 for start bit mark and space + stop bit mark if (aResults->rawlen <= (2 * JVC_BITS) + 3) { - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(aResults->rawlen); - IR_DEBUG_PRINTLN(F(" is too small. >= 36 is required.")); + DEBUG_PRINT(F("Data length=")); + DEBUG_PRINT(aResults->rawlen); + DEBUG_PRINTLN(F(" is too small. >= 36 is required.")); return false; } @@ -207,15 +196,11 @@ bool IRrecv::decodeJVCMSB(decode_results *aResults) { } offset++; - if (!decodePulseDistanceWidthData(JVC_BITS, offset, JVC_BIT_MARK, 0, JVC_ONE_SPACE, JVC_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST)) { - return false; - } + decodePulseDistanceWidthData(JVC_BITS, offset, JVC_BIT_MARK, JVC_ONE_SPACE, 0, PROTOCOL_IS_MSB_FIRST); // Stop bit if (!matchMark(aResults->rawbuf[offset + (2 * JVC_BITS)], JVC_BIT_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.println(F("Stop bit mark length is wrong")); -#endif + DEBUG_PRINTLN(F("Stop bit mark length is wrong")); return false; } @@ -231,6 +216,7 @@ bool IRrecv::decodeJVCMSB(decode_results *aResults) { /** * With Send sendJVCMSB() you can send your old 32 bit codes. * To convert one into the other, you must reverse the byte positions and then reverse all bit positions of each byte. + * Use bitreverse32Bit(). * Or write it as one binary string and reverse/mirror it. * Example: * 0xCB340102 byte reverse -> 02 01 34 CB bit reverse-> 40 80 2C D3. @@ -253,7 +239,6 @@ void IRsend::sendJVCMSB(unsigned long data, int nbits, bool repeat) { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_JVC_HPP diff --git a/src/ir_Kaseikyo.hpp b/src/ir_Kaseikyo.hpp index 294ea94e8..5fa32fcd6 100644 --- a/src/ir_Kaseikyo.hpp +++ b/src/ir_Kaseikyo.hpp @@ -32,11 +32,9 @@ #ifndef _IR_KASEIKYO_HPP #define _IR_KASEIKYO_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -75,22 +73,22 @@ */ // http://www.hifi-remote.com/johnsfine/DecodeIR.html#Panasonic // http://www.hifi-remote.com/johnsfine/DecodeIR.html#Kaseikyo +// LSB first // The first two (8-bit) bytes contains the vendor code. +// The next 4 bit is VendorID parity. +// The last byte is parity (XOR) of the 3 bytes before. // There are multiple interpretations of the next fields: // IRP: {37k,432}<1,-1|1,-3>(8,-4,M:8,N:8,X:4,D:4,S:8,F:8,G:8,1,-173)+ {X=M:4:0^M:4:4^N:4:0^N:4:4} -// 1. interpretation: After the vendor code, the next byte is 4 bit VendorID parity and 4 bit Device and Subdevice -// The 5th byte is the function and the last (6.th) byte is xor of the three bytes before it. -// 0_______ 1_______ 2______ 3_______ 4_______ 5 +// 1. interpretation: 4 bit Device, 8 bitSubdevice and 8 bit function. +// 0_______ 1_______ 2______ 3_______ 4_______ 5_______ // 01234567 89ABCDEF 01234567 01234567 01234567 01234567 -// 01000000 00100100 Dev____ Sub_Dev_ Fun____ XOR( B2, B3, B4) - showing Panasonic vendor code 0x2002 +// 01000000 00100100 0110Dev_ Sub_Dev_ Fun____ XOR( B2, B3, B4) - Byte 0,1 and vendor parity showing Panasonic vendor code 0x2002. +// 1. interpretation: // see: http://www.remotecentral.com/cgi-bin/mboard/rc-pronto/thread.cgi?26152 -// -// 2. interpretation: LSB first, start bit + 16 VendorID + 4 VendorID parity + 4 Genre1 + 4 Genre2 + 10 Command + 2 ID + 8 Parity + stop bit +// 2. interpretation (Flipper Zero style): // see: https://www.mikrocontroller.net/articles/IRMP_-_english#KASEIKYO -// 32 bit raw data LSB is VendorID parity. -// -// We reduce it to: IRP: {37k,432}<1,-1|1,-3>(8,-4,V:16,X:4,D:4,S:8,F:8,(X^D^S^F):8,1,-173)+ {X=M:4:0^M:4:4^N:4:0^N:4:4} -// start bit + 16 VendorID + 4 VendorID parity + 12 Address + 8 Command + 8 Parity of VendorID parity, Address and Command + stop bit +// Implemented is Samsung style: +// which is derived from Samsung remotes and may not be optimal for Denon kind of Kaseikyo protokol usage. // #define KASEIKYO_VENDOR_ID_BITS 16 #define KASEIKYO_VENDOR_ID_PARITY_BITS 4 @@ -118,16 +116,16 @@ #define SHARP_VENDOR_ID_CODE 0x5AAA #define JVC_VENDOR_ID_CODE 0x0103 -struct PulseDistanceWidthProtocolConstants KaseikyoProtocolConstants = { KASEIKYO, KASEIKYO_KHZ, KASEIKYO_HEADER_MARK, -KASEIKYO_HEADER_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ONE_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST - , (KASEIKYO_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const KaseikyoProtocolConstants PROGMEM = {KASEIKYO, KASEIKYO_KHZ, KASEIKYO_HEADER_MARK, + KASEIKYO_HEADER_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ONE_SPACE, KASEIKYO_BIT_MARK, KASEIKYO_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE + , (KASEIKYO_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions ************************************/ /** - * Address can be interpreted as sub-device << 8 + device + * Address can be interpreted as sub-device << 4 + 4 bit device */ void IRsend::sendKaseikyo(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint16_t aVendorCode) { // Set IR carrier frequency @@ -140,13 +138,13 @@ void IRsend::sendKaseikyo(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumb #if __INT_WIDTH__ < 32 LongUnion tSendValue; // Compute parity - tSendValue.UWord.LowWord = (aAddress << KASEIKYO_VENDOR_ID_PARITY_BITS) | tVendorParity; // set low nibble to parity + tSendValue.UWord.LowWord = (aAddress << KASEIKYO_VENDOR_ID_PARITY_BITS) | tVendorParity; // set low nibble with vendor parity tSendValue.UBytes[2] = aCommand; - tSendValue.UBytes[3] = aCommand ^ tSendValue.UBytes[0] ^ tSendValue.UBytes[1]; // Parity - IRRawDataType tRawKaseikyoData[2]; + tSendValue.UBytes[3] = aCommand ^ tSendValue.UBytes[0] ^ tSendValue.UBytes[1]; // 8 bit parity of 3 bytes command, address and vendor parity + IRDecodedRawDataType tRawKaseikyoData[2]; tRawKaseikyoData[0] = (uint32_t) tSendValue.UWord.LowWord << 16 | aVendorCode; // LSB of tRawKaseikyoData[0] is sent first tRawKaseikyoData[1] = tSendValue.UWord.HighWord; - sendPulseDistanceWidthFromArray(&KaseikyoProtocolConstants, &tRawKaseikyoData[0], KASEIKYO_BITS, aNumberOfRepeats); + sendPulseDistanceWidthFromArray_P(&KaseikyoProtocolConstants, &tRawKaseikyoData[0], KASEIKYO_BITS, aNumberOfRepeats); #else LongLongUnion tSendValue; tSendValue.UWords[0] = aVendorCode; @@ -154,7 +152,7 @@ void IRsend::sendKaseikyo(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumb tSendValue.UWords[1] = (aAddress << KASEIKYO_VENDOR_ID_PARITY_BITS) | tVendorParity; // set low nibble to parity tSendValue.UBytes[4] = aCommand; tSendValue.UBytes[5] = aCommand ^ tSendValue.UBytes[2] ^ tSendValue.UBytes[3]; // Parity - sendPulseDistanceWidth(&KaseikyoProtocolConstants, tSendValue.ULongLong, KASEIKYO_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&KaseikyoProtocolConstants, tSendValue.ULongLong, KASEIKYO_BITS, aNumberOfRepeats); #endif } @@ -200,26 +198,19 @@ bool IRrecv::decodeKaseikyo() { decode_type_t tProtocol; // Check we have enough data (96 + 4) 4 for initial gap, start bit mark and space + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != ((2 * KASEIKYO_BITS) + 4)) { - IR_DEBUG_PRINT(F("Kaseikyo: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 100")); + if (decodedIRData.rawlen != ((2 * KASEIKYO_BITS) + 4)) { + DEBUG_PRINT(F("Kaseikyo: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 100")); return false; } - if (!checkHeader(&KaseikyoProtocolConstants)) { + if (!checkHeader_P(&KaseikyoProtocolConstants)) { return false; } // decode first 16 Vendor ID bits - if (!decodePulseDistanceWidthData(&KaseikyoProtocolConstants, KASEIKYO_VENDOR_ID_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Kaseikyo: ")); - Serial.println(F("Vendor ID decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&KaseikyoProtocolConstants, KASEIKYO_VENDOR_ID_BITS); uint16_t tVendorId = decodedIRData.decodedRawData; if (tVendorId == PANASONIC_VENDOR_ID_CODE) { @@ -243,15 +234,9 @@ bool IRrecv::decodeKaseikyo() { /* * Decode next 32 bits, 8 VendorID parity parity + 12 address (device and subdevice) + 8 command + 8 parity */ - if (!decodePulseDistanceWidthData(&KaseikyoProtocolConstants, + decodePulseDistanceWidthData_P(&KaseikyoProtocolConstants, KASEIKYO_VENDOR_ID_PARITY_BITS + KASEIKYO_ADDRESS_BITS + KASEIKYO_COMMAND_BITS + KASEIKYO_PARITY_BITS, - 3 + (2 * KASEIKYO_VENDOR_ID_BITS))) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Kaseikyo: ")); - Serial.println(F("VendorID parity, address, command + parity decode failed")); -#endif - return false; - } + 3 + (2 * KASEIKYO_VENDOR_ID_BITS)); // Success // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value @@ -268,15 +253,12 @@ bool IRrecv::decodeKaseikyo() { if (tVendorParity != (tValue.UByte.LowByte & 0xF)) { decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED | IRDATA_FLAGS_IS_LSB_FIRST; -#if defined(LOCAL_DEBUG) - Serial.print(F("Kaseikyo: ")); - Serial.print(F("4 bit VendorID parity is not correct. Expected=0x")); - Serial.print(tVendorParity, HEX); - Serial.print(F(" received=0x")); - Serial.print(decodedIRData.decodedRawData, HEX); - Serial.print(F(" VendorID=0x")); - Serial.println(tVendorId, HEX); -#endif + DEBUG_PRINT(F("Kaseikyo: 4 bit VendorID parity is not correct. Expected=0x")); + DEBUG_PRINT(tVendorParity, HEX); + DEBUG_PRINT(F(" received=0x")); + DEBUG_PRINT(decodedIRData.decodedRawData, HEX); + DEBUG_PRINT(F(" VendorID=0x")); + DEBUG_PRINTLN(tVendorId, HEX); } if (tProtocol == KASEIKYO) { @@ -287,17 +269,14 @@ bool IRrecv::decodeKaseikyo() { if (tValue.UByte.HighByte != tParity) { decodedIRData.flags |= IRDATA_FLAGS_PARITY_FAILED; -#if defined(LOCAL_DEBUG) - Serial.print(F("Kaseikyo: ")); - Serial.print(F("8 bit parity is not correct. Expected=0x")); - Serial.print(tParity, HEX); - Serial.print(F(" received=0x")); - Serial.print(decodedIRData.decodedRawData >> KASEIKYO_COMMAND_BITS, HEX); - Serial.print(F(" address=0x")); - Serial.print(decodedIRData.address, HEX); - Serial.print(F(" command=0x")); - Serial.println(decodedIRData.command, HEX); -#endif + DEBUG_PRINT(F("Kaseikyo: 8 bit parity is not correct. Expected=0x")); + DEBUG_PRINT(tParity, HEX); + DEBUG_PRINT(F(" received=0x")); + DEBUG_PRINT(decodedIRData.decodedRawData >> KASEIKYO_COMMAND_BITS, HEX); + DEBUG_PRINT(F(" address=0x")); + DEBUG_PRINT(decodedIRData.address, HEX); + DEBUG_PRINT(F(" command=0x")); + DEBUG_PRINTLN(decodedIRData.command, HEX); } decodedIRData.numberOfBits = KASEIKYO_BITS; @@ -316,7 +295,6 @@ bool IRrecv::decodeKaseikyo() { */ /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_KASEIKYO_HPP diff --git a/src/ir_LG.hpp b/src/ir_LG.hpp index 6990cff78..b15af079b 100644 --- a/src/ir_LG.hpp +++ b/src/ir_LG.hpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2017-2023 Darryl Smith, Armin Joachimsmeyer + * Copyright (c) 2017-2026 Darryl Smith, 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 @@ -32,11 +32,7 @@ #ifndef _IR_LG_HPP #define _IR_LG_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -62,25 +58,26 @@ Sum: 62400 */ -// LG originally added by Darryl Smith (based on the JVC protocol) -// see: https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/LGAirConditionerSendDemo +// LG originally added by Darryl Smith +// see: https://github.com/Arduino-IRremote/Arduino-IRremote/tree/master/examples/SendLGAirConditionerDemo // see: https://www.mikrocontroller.net/articles/IRMP_-_english#LGAIR // MSB first, 1 start bit + 8 bit address + 16 bit command + 4 bit checksum + 1 stop bit (28 data bits). -// Bit and repeat timing is like NEC -// LG2 has different header timing and a shorter bit time +// +// LG is MSB first and has 28 bits in contrast to NEC, which is LSB first and has 32 bits. +// LG Bit and repeat timing is like NEC, but with 526 us instead of 560 us unit. /* * LG remote IR-LED measurements: Type AKB 73315611 for air conditioner, Ver1.1 from 2011.03.01 - * Protocol: LG2 + * Protocol: LG * Internal crystal: 4 MHz * Header: 8.9 ms mark 4.15 ms space - * Data: 500 / 540 and 500 / 1580; + * Data: 526 / 526 and 526 / 1578; * Clock is not synchronized with gate so you have 19 and sometimes 19 and a spike pulses for mark * Duty: 9 us on 17 us off => around 33 % duty * NO REPEAT: If value like temperature has changed during long press, the last value is send at button release. * If you do a double press, the next value can be sent after around 118 ms. Tested with the fan button. * LG remote IR-LED measurements: Type AKB 75095308 for LG TV - * Protocol: NEC!!! + * Protocol: !!!NEC!!! * Frequency 37.88 kHz * Header: 9.0 ms mark 4.5 ms space * Data: 560 / 560 and 560 / 1680; @@ -96,40 +93,34 @@ #define LG_CHECKSUM_BITS 4 #define LG_BITS (LG_ADDRESS_BITS + LG_COMMAND_BITS + LG_CHECKSUM_BITS) // 28 -#define LG_UNIT 500 // 19 periods of 38 kHz - -#define LG_HEADER_MARK (18 * LG_UNIT) // 9000 -#define LG_HEADER_SPACE 4200 // 4200 | 84 +#define LG_UNIT 526 // 20 periods of 38 kHz -#define LG2_HEADER_MARK (19 * LG_UNIT) // 9500 -#define LG2_HEADER_SPACE (6 * LG_UNIT) // 3000 +#define LG_HEADER_MARK (16 * LG_UNIT) // 8416 +#define LG_HEADER_SPACE (8 * LG_UNIT) // 4208 #define LG_BIT_MARK LG_UNIT -#define LG_ONE_SPACE 1580 // 60 periods of 38 kHz +#define LG_ONE_SPACE 1578 // 60 periods of 38 kHz #define LG_ZERO_SPACE 550 -#define LG_REPEAT_HEADER_SPACE (4 * LG_UNIT) // 2250 +#define LG_REPEAT_HEADER_SPACE (4 * LG_UNIT) // 2104 #define LG_REPEAT_PERIOD 110000 // Commands are repeated every 110 ms (measured from start to start) for as long as the key on the remote control is held down. //#define LG_AVERAGE_DURATION 58000 // LG_HEADER_MARK + LG_HEADER_SPACE + 32 * 2,5 * LG_UNIT) + LG_UNIT // 2.5 because we assume more zeros than ones //#define LG_REPEAT_DURATION (LG_HEADER_MARK + LG_REPEAT_HEADER_SPACE + LG_BIT_MARK) //#define LG_REPEAT_DISTANCE (LG_REPEAT_PERIOD - LG_AVERAGE_DURATION) // 52 ms -struct PulseDistanceWidthProtocolConstants LGProtocolConstants = { LG, LG_KHZ, LG_HEADER_MARK, LG_HEADER_SPACE, LG_BIT_MARK, -LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST, (LG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), &sendNECSpecialRepeat }; - -struct PulseDistanceWidthProtocolConstants LG2ProtocolConstants = { LG2, LG_KHZ, LG2_HEADER_MARK, LG2_HEADER_SPACE, LG_BIT_MARK, -LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST, (LG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), &sendLG2SpecialRepeat }; +struct PulseDistanceWidthProtocolConstants const LGProtocolConstants PROGMEM= {LG, LG_KHZ, LG_HEADER_MARK, LG_HEADER_SPACE, LG_BIT_MARK, + LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, (LG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), &sendLGSpecialRepeat}; /************************************ * Start of send and decode functions ************************************/ /* - * Send special LG2 repeat not used yet + * Send special LG repeat. Like NEC repeat, but with unit 526 instead of 560 - not used internally */ -void IRsend::sendLG2Repeat() { - enableIROut (LG_KHZ); // 38 kHz - mark(LG2_HEADER_MARK); // + 3000 - space(LG_REPEAT_HEADER_SPACE); // - 2250 +void IRsend::sendLGRepeat() { + enableIROut (LG_KHZ); // 38 kHz + mark(LG_HEADER_MARK); // + 8416 + space(LG_REPEAT_HEADER_SPACE); // - 2104 mark(LG_BIT_MARK); // + 500 } @@ -137,11 +128,11 @@ void IRsend::sendLG2Repeat() { * Static function for sending special repeat frame. * For use in ProtocolConstants. Saves up to 250 bytes compared to a member function. */ -void sendLG2SpecialRepeat() { - IrSender.enableIROut(LG_KHZ); // 38 kHz - IrSender.mark(LG2_HEADER_MARK); // + 3000 - IrSender.space(LG_REPEAT_HEADER_SPACE); // - 2250 - IrSender.mark(LG_BIT_MARK); // + 500 +void sendLGSpecialRepeat() { + IrSender.enableIROut(LG_KHZ); // 38 kHz + IrSender.mark(LG_HEADER_MARK); // + 8416 + IrSender.space(LG_REPEAT_HEADER_SPACE); // - 2104 + IrSender.mark(LG_BIT_MARK); // + 500 } uint32_t IRsend::computeLGRawDataAndChecksum(uint8_t aAddress, uint16_t aCommand) { @@ -159,22 +150,14 @@ uint32_t IRsend::computeLGRawDataAndChecksum(uint8_t aAddress, uint16_t aCommand return (tRawData | (tChecksum & 0xF)); } -/** - * LG uses the NEC repeat. - */ void IRsend::sendLG(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&LGProtocolConstants, computeLGRawDataAndChecksum(aAddress, aCommand), LG_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&LGProtocolConstants, computeLGRawDataAndChecksum(aAddress, aCommand), LG_BITS, aNumberOfRepeats); } -/** - * LG2 uses a special repeat. +/* + * Decode MSB first and 28 bits */ -void IRsend::sendLG2(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&LG2ProtocolConstants, computeLGRawDataAndChecksum(aAddress, aCommand), LG_BITS, aNumberOfRepeats); -} - bool IRrecv::decodeLG() { - decode_type_t tProtocol = LG; uint16_t tHeaderSpace = LG_HEADER_SPACE; /* @@ -184,61 +167,41 @@ bool IRrecv::decodeLG() { */ // Check we have the right amount of data (60). The +4 is for initial gap, start bit mark and space + stop bit mark. - if (decodedIRData.rawDataPtr->rawlen != ((2 * LG_BITS) + 4) && (decodedIRData.rawDataPtr->rawlen != 4)) { - IR_DEBUG_PRINT(F("LG: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 60 or 4")); + if (!(decodedIRData.rawlen == ((2 * LG_BITS) + 4) || (decodedIRData.rawlen == 4))) { + // Is only printed, if LOCAL_DEBUG is defined globally + DEBUG_PRINT(F("LG: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 60 or 4")); return false; } // Check header "mark" this must be done for repeat and data - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], LG_HEADER_MARK)) { - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], LG2_HEADER_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("LG: ")); - Serial.println(F("Header mark is wrong")); -#endif - return false; - } else { - tProtocol = LG2; - tHeaderSpace = LG2_HEADER_SPACE; - } + if (!matchMark(irparams.rawbuf[1], LG_HEADER_MARK)) { + DEBUG_PRINTLN(F("LG: Header mark is wrong")); + return false; } // Check for repeat - here we have another header space length - if (decodedIRData.rawDataPtr->rawlen == 4) { - if (matchSpace(decodedIRData.rawDataPtr->rawbuf[2], LG_REPEAT_HEADER_SPACE) - && matchMark(decodedIRData.rawDataPtr->rawbuf[3], LG_BIT_MARK)) { + if (decodedIRData.rawlen == 4) { + if (lastDecodedProtocol == LG && matchSpace(irparams.rawbuf[2], LG_REPEAT_HEADER_SPACE) + && matchMark(irparams.rawbuf[3], LG_BIT_MARK)) { decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_MSB_FIRST; decodedIRData.address = lastDecodedAddress; decodedIRData.command = lastDecodedCommand; - decodedIRData.protocol = lastDecodedProtocol; + decodedIRData.protocol = LG; return true; } -#if defined(LOCAL_DEBUG) - Serial.print(F("LG: ")); - Serial.print(F("Repeat header space is wrong")); -#endif + DEBUG_PRINTLN(F("LG: Repeat header space is wrong")); return false; } // Check command header space - if (!matchSpace(decodedIRData.rawDataPtr->rawbuf[2], tHeaderSpace)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("LG: ")); - Serial.println(F("Header space length is wrong")); -#endif + if (!matchSpace(irparams.rawbuf[2], tHeaderSpace)) { + DEBUG_PRINTLN(F("LG: Header space length is wrong")); return false; } - if (!decodePulseDistanceWidthData(&LGProtocolConstants, LG_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("LG: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&LGProtocolConstants, LG_BITS); // Success decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; @@ -256,19 +219,18 @@ bool IRrecv::decodeLG() { } // Checksum check if ((tChecksum & 0xF) != (decodedIRData.decodedRawData & 0xF)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("LG: ")); - Serial.print(F("4 bit checksum is not correct. expected=0x")); - Serial.print(tChecksum, HEX); - Serial.print(F(" received=0x")); - Serial.print((decodedIRData.decodedRawData & 0xF), HEX); - Serial.print(F(" data=0x")); - Serial.println(decodedIRData.command, HEX); -#endif + + DEBUG_PRINT(F("LG: 4 bit checksum is not correct. expected=0x")); + DEBUG_PRINT(tChecksum, HEX); + DEBUG_PRINT(F(" received=0x")); + DEBUG_PRINT((decodedIRData.decodedRawData & 0xF), HEX); + DEBUG_PRINT(F(" data=0x")); + DEBUG_PRINTLN(decodedIRData.command, HEX); + decodedIRData.flags |= IRDATA_FLAGS_PARITY_FAILED; } - decodedIRData.protocol = tProtocol; // LG or LG2 + decodedIRData.protocol = LG; decodedIRData.numberOfBits = LG_BITS; return true; @@ -284,7 +246,7 @@ bool IRrecv::decodeLG() { * @param aNumberOfRepeats If < 0 then only a special repeat frame will be sent. */ void IRsend::sendLGRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&LGProtocolConstants, aRawData, LG_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&LGProtocolConstants, aRawData, LG_BITS, aNumberOfRepeats); } bool IRrecv::decodeLGMSB(decode_results *aResults) { @@ -306,14 +268,11 @@ bool IRrecv::decodeLGMSB(decode_results *aResults) { } offset++; - if (!decodePulseDistanceWidthData(LG_BITS, offset, LG_BIT_MARK, 0, LG_ONE_SPACE, LG_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST)) { - return false; - } + decodePulseDistanceWidthData(LG_BITS, offset, LG_BIT_MARK, LG_ONE_SPACE, 0, PROTOCOL_IS_MSB_FIRST); + // Stop bit if (!matchMark(aResults->rawbuf[offset + (2 * LG_BITS)], LG_BIT_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.println(F("Stop bit mark length is wrong")); -#endif + DEBUG_PRINTLN(F("Stop bit mark length is wrong")); return false; } @@ -330,20 +289,18 @@ void IRsend::sendLG(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut (LG_KHZ); #if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)) -// Serial.println(F( -// "The function sendLG(data, nbits) is deprecated and may not work as expected! Use sendLGRaw(data, NumberOfRepeats) or better sendLG(Address, Command, NumberOfRepeats).")); + DEBUG_PRINTLN( + F( "The function sendLG(data, nbits) is deprecated and may not work as expected! Use sendLGRaw(data, NumberOfRepeats) or better sendLG(Address, Command, NumberOfRepeats).")); #endif // Header mark(LG_HEADER_MARK); space(LG_HEADER_SPACE); -// mark(LG_BIT_MARK); // Data + stop bit sendPulseDistanceWidthData(LG_BIT_MARK, LG_ONE_SPACE, LG_BIT_MARK, LG_ZERO_SPACE, data, nbits, PROTOCOL_IS_MSB_FIRST); } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_LG_HPP diff --git a/src/ir_Lego.hpp b/src/ir_Lego.hpp index 2f87be673..574921a01 100644 --- a/src/ir_Lego.hpp +++ b/src/ir_Lego.hpp @@ -32,6 +32,8 @@ #ifndef _IR_LEGO_HPP #define _IR_LEGO_HPP +#include "LocalDebugLevelStart.h" + /** \addtogroup Decoder Decoders and encoders for different protocols * @{ */ @@ -45,20 +47,33 @@ // from LEGO Power Functions RC Manual 26.02.2010 Version 1.20 // https://github.com/jurriaan/Arduino-PowerFunctions/raw/master/LEGO_Power_Functions_RC_v120.pdf // https://oberguru.net/elektronik/ir/codes/lego_power_functions_train.lircd.conf +// For original LEGO receiver see: https://www.philohome.com/pfrec/pfrec.htm and https://www.youtube.com/watch?v=KCM4Ug1bPrM // // To ensure correct detection of IR messages six 38 kHz cycles are transmitted as mark. -// Low bit consists of 6 cycles of IR and 10 “cycles” of pause, -// high bit of 6 cycles IR and 21 “cycles” of pause and start bit of 6 cycles IR and 39 “cycles” of pause. -// Low bit range 316 - 526 us -// High bit range 526 – 947 us -// Start/stop bit range 947 – 1579 us +// Low bit consists of 6 cycles of IR and 10 cycles of pause, +// High bit of 6 cycles IR and 21 cycles of pause, +// Start/stop of 6 cycles IR and 39 cycles of pause. +// // If tm is the maximum message length (16ms) and Ch is the channel number, then -// The delay before transmitting the first message is: (4 – Ch)*tm -// The time from start to start for the next 2 messages is: 5*tm -// The time from start to start for the following messages is: (6 + 2*Ch)*tm +// The delay before transmitting the first message is: (4 - Ch) * tm +// The time from start to start for the next 2 messages is: 5 * tm +// The time from start to start for the following messages is: (6 + 2 * Ch) * tm // Supported Devices // LEGO Power Functions IR Receiver 8884 // MSB first, 1 start bit + 4 bit channel, 4 bit mode + 4 bit command + 4 bit parity + 1 stop bit. +/* Protocol=Lego Address=0x1, Command=0x16, Raw-Data=0x1169 ,16 bits, MSB first, Gap=1050600us, Duration=10000us + Send with: IrSender.sendLego(0x1, 0x16, ); + rawData[36]: + -1050600 + + 250,- 950 + + 250,- 500 + 200,- 200 + 200,- 250 + 200,- 500 + + 200,- 250 + 200,- 500 + 200,- 500 + 200,- 250 + + 200,- 500 + 200,- 200 + 250,- 200 + 200,- 200 + + 250,- 500 + 200,- 200 + 250,- 200 + 200,- 250 + + 200 + Duration=10000us + */ + #define LEGO_CHANNEL_BITS 4 #define LEGO_MODE_BITS 4 #define LEGO_COMMAND_BITS 4 @@ -72,6 +87,7 @@ #define LEGO_BIT_MARK 158 // 6 cycles #define LEGO_ONE_SPACE 553 // 21 cycles #define LEGO_ZERO_SPACE 263 // 10 cycles +#define LEGO_ONE_THRESHOLD 408 // 15.5 cycles - not used, just for info #define LEGO_AVERAGE_DURATION 11000 // LEGO_HEADER_MARK + LEGO_HEADER_SPACE + 16 * 600 + 158 @@ -82,9 +98,10 @@ #define LEGO_MODE_COMBO 1 #define LEGO_MODE_SINGLE 0x4 // here the 2 LSB have meanings like Output A / Output B -struct PulseDistanceWidthProtocolConstants LegoProtocolConstants = { LEGO_PF, 38, LEGO_HEADER_MARK, LEGO_HEADER_SPACE, LEGO_BIT_MARK, -LEGO_ONE_SPACE, LEGO_BIT_MARK, LEGO_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (LEGO_AUTO_REPEAT_PERIOD_MIN - / MICROS_IN_ONE_MILLI), NULL }; +// Cannot be constant, since we need to change RepeatPeriodMillis during sending +struct PulseDistanceWidthProtocolConstants LegoProtocolConstants = { LEGO_PF, 38, LEGO_HEADER_MARK, LEGO_HEADER_SPACE, +LEGO_BIT_MARK, LEGO_ONE_SPACE, LEGO_BIT_MARK, LEGO_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, + (LEGO_AUTO_REPEAT_PERIOD_MIN / MICROS_IN_ONE_MILLI), nullptr }; /************************************ * Start of send and decode functions @@ -106,8 +123,8 @@ void IRsend::sendLegoPowerFunctions(uint8_t aChannel, uint8_t aCommand, uint8_t void IRsend::sendLegoPowerFunctions(uint16_t aRawData, uint8_t aChannel, bool aDoSend5Times) { - IR_DEBUG_PRINT(F("sendLego aRawData=0x")); - IR_DEBUG_PRINTLN(aRawData, HEX); + DEBUG_PRINT(F("sendLego aRawData=0x")); + DEBUG_PRINTLN(aRawData, HEX); aChannel &= 0x03; // we have 4 channels @@ -126,31 +143,31 @@ void IRsend::sendLegoPowerFunctions(uint16_t aRawData, uint8_t aChannel, bool aD */ bool IRrecv::decodeLegoPowerFunctions() { - if (!checkHeader(&LegoProtocolConstants)) { + /* + * Check header timings + * Since LEGO_HEADER_MARK is just 158 us use a relaxed threshold compare (237) for it instead of matchMark() + */ + if (!(matchMarkWithGreaterRange(irparams.rawbuf[1], LEGO_HEADER_MARK) && (matchSpace(irparams.rawbuf[2], LEGO_HEADER_SPACE)))) { + DEBUG_PRINTLN(F("LEGO: No header mark and space")); return false; } // Check we have enough data - +4 for initial gap, start bit mark and space + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != (2 * LEGO_BITS) + 4) { - IR_DEBUG_PRINT(F("LEGO: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 36")); + if (decodedIRData.rawlen != (2 * LEGO_BITS) + 4) { + DEBUG_PRINT(F("LEGO: Data length=")); + DEBUG_PRINT(irparams.rawlen); + DEBUG_PRINTLN(F(" is not 36")); return false; } - if (!decodePulseDistanceWidthData(&LegoProtocolConstants, LEGO_BITS)) { - IR_DEBUG_PRINT(F("LEGO: ")); - IR_DEBUG_PRINTLN(F("Decode failed")); - return false; - } + decodePulseDistanceWidthData(&LegoProtocolConstants, LEGO_BITS); - // Stop bit - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[3 + (2 * LEGO_BITS)], LEGO_BIT_MARK)) { - IR_DEBUG_PRINT(F("LEGO: ")); - IR_DEBUG_PRINTLN(F("Stop bit mark length is wrong")); - return false; - } + // Stop bit, use threshold decoding - not required :-) +// if (irparams.rawbuf[3 + (2 * LEGO_BITS)] > (2 * LEGO_BIT_MARK)) { +// DEBUG_PRINT(F("LEGO: ")); +// DEBUG_PRINTLN(F("Stop bit mark length is wrong")); +// return false; +// } // Success decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; @@ -166,19 +183,18 @@ bool IRrecv::decodeLegoPowerFunctions() { // parity check if (tParityReceived != tParityComputed) { - IR_DEBUG_PRINT(F("LEGO: ")); - IR_DEBUG_PRINT(F("Parity is not correct. expected=0x")); - IR_DEBUG_PRINT(tParityComputed, HEX); - IR_DEBUG_PRINT(F(" received=0x")); - IR_DEBUG_PRINT(tParityReceived, HEX); - IR_DEBUG_PRINT(F(", raw=0x")); - IR_DEBUG_PRINT(tDecodedValue, HEX); - IR_DEBUG_PRINT(F(", 3 nibbles are 0x")); - IR_DEBUG_PRINT(tToggleEscapeChannel, HEX); - IR_DEBUG_PRINT(F(", 0x")); - IR_DEBUG_PRINT(tMode, HEX); - IR_DEBUG_PRINT(F(", 0x")); - IR_DEBUG_PRINTLN(tData, HEX); + DEBUG_PRINT(F("LEGO: Parity is not correct. expected=0x")); + DEBUG_PRINT(tParityComputed, HEX); + DEBUG_PRINT(F(" received=0x")); + DEBUG_PRINT(tParityReceived, HEX); + DEBUG_PRINT(F(", raw=0x")); + DEBUG_PRINT(tDecodedValue, HEX); + DEBUG_PRINT(F(", 3 nibbles are 0x")); + DEBUG_PRINT(tToggleEscapeChannel, HEX); + DEBUG_PRINT(F(", 0x")); + DEBUG_PRINT(tMode, HEX); + DEBUG_PRINT(F(", 0x")); + DEBUG_PRINTLN(tData, HEX); // might not be an error, so just continue decodedIRData.flags = IRDATA_FLAGS_PARITY_FAILED | IRDATA_FLAGS_IS_MSB_FIRST; } @@ -186,11 +202,11 @@ bool IRrecv::decodeLegoPowerFunctions() { /* * Check for autorepeat (should happen 4 times for one press) */ - if (decodedIRData.rawDataPtr->rawbuf[0] < (LEGO_AUTO_REPEAT_PERIOD_MAX / MICROS_PER_TICK)) { + if (decodedIRData.initialGapTicks < (LEGO_AUTO_REPEAT_PERIOD_MAX / MICROS_PER_TICK)) { decodedIRData.flags |= IRDATA_FLAGS_IS_AUTO_REPEAT; } decodedIRData.address = tToggleEscapeChannel; - decodedIRData.command = tData | tMode << LEGO_COMMAND_BITS; + decodedIRData.command = tData | (tMode << LEGO_COMMAND_BITS); decodedIRData.numberOfBits = LEGO_BITS; decodedIRData.protocol = LEGO_PF; @@ -206,4 +222,6 @@ void IRsend::sendLegoPowerFunctions(uint16_t aRawData, bool aDoSend5Times) { } /** @}*/ +#include "LocalDebugLevelEnd.h" + #endif // _IR_LEGO_HPP diff --git a/src/ir_MagiQuest.hpp b/src/ir_MagiQuest.hpp index 6e82550bf..27e75251e 100644 --- a/src/ir_MagiQuest.hpp +++ b/src/ir_MagiQuest.hpp @@ -14,7 +14,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2017-2023 E. Stuart Hicks , Armin Joachimsmeyer + * Copyright (c) 2017-2025 E. Stuart Hicks , 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 @@ -38,11 +38,13 @@ #ifndef _IR_MAGIQUEST_HPP #define _IR_MAGIQUEST_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" + +/** \addtogroup Decoder Decoders and encoders for different protocols + * @{ + */ // //============================================================================== // @@ -55,7 +57,6 @@ //============================================================================== /* * https://github.com/kitlaan/Arduino-IRremote/blob/master/ir_Magiquest.cpp - * https://github.com/Arduino-IRremote/Arduino-IRremote/discussions/1027#discussioncomment-3636857 * https://github.com/Arduino-IRremote/Arduino-IRremote/issues/1015#issuecomment-1222247231 Protocol=MagiQuest Address=0xFF00 Command=0x176 Raw-Data=0x6BCDFF00 56 bits MSB first @@ -79,6 +80,8 @@ // Checksum (+ sum of the 5 bytes before == 0) + 250,- 900 + 300,- 900 + 250,- 850 + 550,- 600 + 600,- 550 + 300,- 900 + 250,- 850 + 550 + + // No stop bit! */ // MSB first, 8 start bits (zero), 31 wand id bits, 9 magnitude bits 8 checksum bits and no stop bit => 56 bits #define MAGIQUEST_CHECKSUM_BITS 8 // magiquest_t.cmd.checksum @@ -92,6 +95,8 @@ #define MAGIQUEST_BITS (MAGIQUEST_CHECKSUM_BITS + MAGIQUEST_MAGNITUDE_BITS + MAGIQUEST_WAND_ID_BITS + MAGIQUEST_START_BITS) // 56 Size of the command with the start bits /* + * Protocol is Pulse Distance Width not pure Pulse Distance and a longer space is not a one but a zero + * * 0 = 25% mark & 75% space across 1 period * 1150 * 0.25 = 288 usec mark * 1150 - 288 = 862 usec space @@ -106,9 +111,10 @@ #define MAGIQUEST_ZERO_MARK MAGIQUEST_UNIT // 287.5 #define MAGIQUEST_ZERO_SPACE (3 * MAGIQUEST_UNIT) // 864 -// assume 110 as repeat period -struct PulseDistanceWidthProtocolConstants MagiQuestProtocolConstants = { MAGIQUEST, 38, MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE, -MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE, MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST, 110, NULL }; +// assume 110 as repeat period. +struct PulseDistanceWidthProtocolConstants const MagiQuestProtocolConstants PROGMEM = {MAGIQUEST, 38, MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE, + MAGIQUEST_ONE_MARK, MAGIQUEST_ONE_SPACE, MAGIQUEST_ZERO_MARK, MAGIQUEST_ZERO_SPACE, + PROTOCOL_IS_MSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE_WIDTH | SUPPRESS_STOP_BIT, 110, nullptr}; //+============================================================================= // /** @@ -128,16 +134,15 @@ void IRsend::sendMagiQuest(uint32_t aWandId, uint16_t aMagnitude) { tChecksum = ~tChecksum + 1; // 8 start bits - sendPulseDistanceWidthData(&MagiQuestProtocolConstants, 0, 8); + sendPulseDistanceWidthData_P(&MagiQuestProtocolConstants, 0, 8); // 48 bit data - sendPulseDistanceWidthData(&MagiQuestProtocolConstants, aWandId, MAGIQUEST_WAND_ID_BITS); // send only 31 bit, do not send MSB here - sendPulseDistanceWidthData(&MagiQuestProtocolConstants, aMagnitude, MAGIQUEST_MAGNITUDE_BITS); - sendPulseDistanceWidthData(&MagiQuestProtocolConstants, tChecksum, MAGIQUEST_CHECKSUM_BITS); -#if defined(LOCAL_DEBUG) + sendPulseDistanceWidthData_P(&MagiQuestProtocolConstants, aWandId, MAGIQUEST_WAND_ID_BITS); // send only 31 bit, do not send MSB here + sendPulseDistanceWidthData_P(&MagiQuestProtocolConstants, aMagnitude, MAGIQUEST_MAGNITUDE_BITS); + sendPulseDistanceWidthData_P(&MagiQuestProtocolConstants, tChecksum, MAGIQUEST_CHECKSUM_BITS); + // must be after sending, in order not to destroy the send timing - Serial.print(F("MagiQuest checksum=0x")); - Serial.println(tChecksum, HEX); -#endif + DEBUG_PRINT(F("MagiQuest checksum=0x")); + DEBUG_PRINTLN(tChecksum, HEX); } //+============================================================================= @@ -151,84 +156,69 @@ void IRsend::sendMagiQuest(uint32_t aWandId, uint16_t aMagnitude) { bool IRrecv::decodeMagiQuest() { // Check we have the right amount of data, magnitude and ID bits and 8 start bits + 0 stop bit - if (decodedIRData.rawDataPtr->rawlen != (2 * MAGIQUEST_BITS)) { - IR_DEBUG_PRINT(F("MagiQuest: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 112")); + if (decodedIRData.rawlen != (2 * MAGIQUEST_BITS)) { + DEBUG_PRINT(F("MagiQuest: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 112")); return false; } /* * Check for 8 zero header bits */ - if (!decodePulseDistanceWidthData(&MagiQuestProtocolConstants, MAGIQUEST_START_BITS, 1)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("MagiQuest: ")); - Serial.println(F("Start bit decode failed")); -#endif - return false; - } - if (decodedIRData.decodedRawData != 0) { -#if defined(LOCAL_DEBUG) - Serial.print(F("MagiQuest: ")); - Serial.print(F("Not 8 leading zero start bits received, RawData=0x")); - Serial.println(decodedIRData.decodedRawData, HEX); + decodePulseDistanceWidthData_P(&MagiQuestProtocolConstants, MAGIQUEST_START_BITS, 1); +#if defined(USE_THRESHOLD_DECODER) + if (decodedIRData.decodedRawData != 0xFF) // For Magiquest a small pause is a 1 which is inverse to threshold decoding +#else + if (decodedIRData.decodedRawData != 0) #endif + { + DEBUG_PRINT(F("MagiQuest: Not 8 leading zero start bits received, RawData=0x")); + DEBUG_PRINTLN(decodedIRData.decodedRawData, HEX); return false; } /* * Decode the 31 bit ID */ - if (!decodePulseDistanceWidthData(&MagiQuestProtocolConstants, MAGIQUEST_WAND_ID_BITS, (MAGIQUEST_START_BITS * 2) + 1)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("MagiQuest: ")); - Serial.println(F("ID decode failed")); + decodePulseDistanceWidthData_P(&MagiQuestProtocolConstants, MAGIQUEST_WAND_ID_BITS, (MAGIQUEST_START_BITS * 2) + 1); +#if defined(USE_THRESHOLD_DECODER) + decodedIRData.decodedRawData = decodedIRData.decodedRawData ^ 0x7FFFFFFF; // We have 31 bit. For Magiquest a small pause is a 1 which is inverse to threshold decoding #endif - return false; - } + LongUnion tDecodedRawData; -#if defined(LOCAL_DEBUG) - Serial.print(F("31 bit WandId=0x")); - Serial.println(decodedIRData.decodedRawData, HEX); -#endif uint32_t tWandId = decodedIRData.decodedRawData; // save tWandId for later use tDecodedRawData.ULong = decodedIRData.decodedRawData << 1; // shift for checksum computation uint8_t tChecksum = tDecodedRawData.Bytes[0] + tDecodedRawData.Bytes[1] + tDecodedRawData.Bytes[2] + tDecodedRawData.Bytes[3]; -#if defined(LOCAL_DEBUG) - Serial.print(F("31 bit WandId=0x")); - Serial.print(decodedIRData.decodedRawData, HEX); - Serial.print(F(" shifted=0x")); - Serial.println(tDecodedRawData.ULong, HEX); -#endif + + DEBUG_PRINT(F("31 bit WandId=0x")); + DEBUG_PRINT(decodedIRData.decodedRawData, HEX); + DEBUG_PRINT(F(" shifted=0x")); + DEBUG_PRINTLN(tDecodedRawData.ULong, HEX); + /* * Decode the 9 bit Magnitude + 8 bit checksum */ - if (!decodePulseDistanceWidthData(&MagiQuestProtocolConstants, MAGIQUEST_MAGNITUDE_BITS + MAGIQUEST_CHECKSUM_BITS, - ((MAGIQUEST_WAND_ID_BITS + MAGIQUEST_START_BITS) * 2) + 1)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("MagiQuest: ")); - Serial.println(F("Magnitude + checksum decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&MagiQuestProtocolConstants, MAGIQUEST_MAGNITUDE_BITS + MAGIQUEST_CHECKSUM_BITS, + ((MAGIQUEST_WAND_ID_BITS + MAGIQUEST_START_BITS) * 2) + 1); + +#if defined(USE_THRESHOLD_DECODER) + decodedIRData.decodedRawData = decodedIRData.decodedRawData ^ 0x0001FFFF; // We have 17 bit. For Magiquest a small pause is a 1 which is inverse to threshold decoding -#if defined(LOCAL_DEBUG) - Serial.print(F("Magnitude + checksum=0x")); - Serial.println(decodedIRData.decodedRawData, HEX); #endif + + DEBUG_PRINT(F("Magnitude + checksum=0x")); + DEBUG_PRINTLN(decodedIRData.decodedRawData, HEX); + tDecodedRawData.ULong = decodedIRData.decodedRawData; decodedIRData.command = tDecodedRawData.UBytes[1] | tDecodedRawData.UBytes[2] << 8; // Values observed are 0x102,01,04,37,05,38,2D| 02,06,04|03,103,12,18,0E|09 tChecksum += tDecodedRawData.UBytes[2] /* only one bit */+ tDecodedRawData.UBytes[1] + tDecodedRawData.UBytes[0]; if (tChecksum != 0) { decodedIRData.flags |= IRDATA_FLAGS_PARITY_FAILED; -#if defined(LOCAL_DEBUG) - Serial.print(F("Checksum 0x")); - Serial.print(tChecksum, HEX); - Serial.println(F(" is not 0")); -#endif + DEBUG_PRINT(F("Checksum 0x")); + DEBUG_PRINT(tChecksum, HEX); + DEBUG_PRINTLN(F(" is not 0")); } // Success @@ -242,7 +232,8 @@ bool IRrecv::decodeMagiQuest() { return true; } -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif + +/** @}*/ +#include "LocalDebugLevelEnd.h" + #endif // _IR_MAGIQUEST_HPP diff --git a/src/ir_NEC.hpp b/src/ir_NEC.hpp index 1c02e7d4f..cdf5a951d 100644 --- a/src/ir_NEC.hpp +++ b/src/ir_NEC.hpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020-2023 Armin Joachimsmeyer + * Copyright (c) 2020-2025 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 @@ -32,11 +32,9 @@ #ifndef _IR_NEC_HPP #define _IR_NEC_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -71,17 +69,20 @@ */ // http://www.hifi-remote.com/wiki/index.php/NEC // https://www.sbprojects.net/knowledge/ir/nec.php -// for Apple see https://en.wikipedia.org/wiki/Apple_Remote - Fixed address 0x87EE, 8 bit device ID, 7 bit command, 1 bit parity - untested! -// ONKYO like NEC but 16 independent address and command bits -// APPLE like ONKYO with special NEC repeat but with constant address of 0x87EE and and 16 bit command interpreted as MSB = 8 bit device ID, LSB = 8 bit command -// PIONEER (not implemented) is NEC2 with 40 kHz -// LSB first, 1 start bit + 16 bit address (or 8 bit address and 8 bit inverted address) + 8 bit command + 8 bit inverted command + 1 stop bit. +// NEC: LSB first, (or ) . +// ONKYO (sometimes called NECext): like NEC but force to 16 independent address and 16 bit command bits: // Standard NEC sends a special fixed repeat frame. -// NEC2 sends the same full frame after the 110 ms. I have a DVD remote with NEC2. +// NEC2: like NEC, but for repeat, the same full frame is sent after the 110 ms. I have a DVD remote with NEC2. // NEC and NEC 2 only differ in the repeat frames, so the protocol can only be detected correctly after the first repeat. +// PIONEER (not implemented) is NEC2 with 40 kHz +// +// For Apple see https://en.wikipedia.org/wiki/Apple_Remote - <0x87EE:16> - not implemented! +// The parity is not implemented, so we get: <0x87EE:16> // +// IRP notation: // IRP: NEC {38.0k,564}<1,-1|1,-3>(16,-8,D:8,S:8,F:8,~F:8,1,^108m,(16,-4,1,^108m)*) ==> "*" means send special repeat frames o ore more times // IRP: NEC2 {38.0k,564}<1,-1|1,-3>(16,-8,D:8,S:8,F:8,~F:8,1,^108m)+ ==> "+" means send frame 1 or more times (special repeat is missing here!) +// Interpretation of IRP notation: // {38.0k,564} ==> 38.0k -> Frequency , 564 -> unit in microseconds (we use 560), no "msb", so "lsb" is assumed // <1,-1|1,-3> ==> Zero is 1 unit mark and space | One is 1 unit mark and 3 units space // 16,-8 ==> Start bit durations @@ -94,14 +95,14 @@ #define NEC_BITS (NEC_ADDRESS_BITS + NEC_COMMAND_BITS) #define NEC_UNIT 560 // 21.28 periods of 38 kHz, 11.2 ticks TICKS_LOW = 8.358 TICKS_HIGH = 15.0 -#define NEC_HEADER_MARK (16 * NEC_UNIT) // 9000 | 180 -#define NEC_HEADER_SPACE (8 * NEC_UNIT) // 4500 | 90 +#define NEC_HEADER_MARK (16 * NEC_UNIT) // 8960 | 180 +#define NEC_HEADER_SPACE (8 * NEC_UNIT) // 4480 | 90 #define NEC_BIT_MARK NEC_UNIT #define NEC_ONE_SPACE (3 * NEC_UNIT) // 1690 | 33.8 TICKS_LOW = 25.07 TICKS_HIGH = 45.0 #define NEC_ZERO_SPACE NEC_UNIT -#define NEC_REPEAT_HEADER_SPACE (4 * NEC_UNIT) // 2250 +#define NEC_REPEAT_HEADER_SPACE (4 * NEC_UNIT) // 2240 #define NEC_AVERAGE_DURATION 62000 // NEC_HEADER_MARK + NEC_HEADER_SPACE + 32 * 2,5 * NEC_UNIT + NEC_UNIT // 2.5 because we assume more zeros than ones #define NEC_MINIMAL_DURATION 49900 // NEC_HEADER_MARK + NEC_HEADER_SPACE + 32 * 2 * NEC_UNIT + NEC_UNIT // 2.5 because we assume more zeros than ones @@ -112,14 +113,13 @@ #define APPLE_ADDRESS 0x87EE -struct PulseDistanceWidthProtocolConstants NECProtocolConstants = - { NEC, NEC_KHZ, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK, - NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), - &sendNECSpecialRepeat }; +struct PulseDistanceWidthProtocolConstants const NECProtocolConstants PROGMEM = {NEC, NEC_KHZ, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK, + NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), + &sendNECSpecialRepeat}; // Like NEC but repeats are full frames instead of special NEC repeats -struct PulseDistanceWidthProtocolConstants NEC2ProtocolConstants = { NEC2, NEC_KHZ, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK, -NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const NEC2ProtocolConstants PROGMEM = {NEC2, NEC_KHZ, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK, + NEC_ONE_SPACE, NEC_BIT_MARK, NEC_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, (NEC_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions @@ -137,7 +137,7 @@ void IRsend::sendNECRepeat() { } /** - * Static function for sending special repeat frame. + * Static function variant of IRsend::sendNECRepeat * For use in ProtocolConstants. Saves up to 250 bytes compared to a member function. */ void sendNECSpecialRepeat() { @@ -147,6 +147,13 @@ void sendNECSpecialRepeat() { IrSender.mark(NEC_BIT_MARK); // + 560 } +/** + * Convert 16 bit address and 16 bit command to 32 bit NECRaw data + * If we get a command < 0x100, we send command and then ~command + * If we get an address < 0x100, we send 8 bit address and then ~address + * !!! Be aware, that this is flexible, but makes it impossible to send e.g. 0x0042 as 16 bit value!!! + * To force send 16 bit address, use: sendOnkyo(). + */ uint32_t IRsend::computeNECRawDataAndChecksum(uint16_t aAddress, uint16_t aCommand) { LongUnion tRawData; @@ -168,61 +175,58 @@ uint32_t IRsend::computeNECRawDataAndChecksum(uint16_t aAddress, uint16_t aComma /** * NEC Send frame and special repeats * There is NO delay after the last sent repeat! - * @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space - * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). + * @param aNumberOfRepeats If < 0 then only a special NEC repeat frame will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). */ -void IRsend::sendNEC(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&NECProtocolConstants, computeNECRawDataAndChecksum(aAddress, aCommand), NEC_BITS, aNumberOfRepeats); +void IRsend::sendNEC(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NECProtocolConstants, computeNECRawDataAndChecksum(aAddress, aCommand), NEC_BITS, aNumberOfRepeats); } -/* - * NEC2 Send frame and repeat the frame for each requested repeat +/** * There is NO delay after the last sent repeat! - * @param aNumberOfRepeats If < 0 then nothing is sent. + * @param aNumberOfRepeats If < 0 then only a special NEC repeat frame without leading and trailing space + * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). */ -void IRsend::sendNEC2(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&NEC2ProtocolConstants, computeNECRawDataAndChecksum(aAddress, aCommand), NEC_BITS, aNumberOfRepeats); +void IRsend::sendOnkyo(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NECProtocolConstants, (uint32_t) aCommand << 16 | aAddress, NEC_BITS, aNumberOfRepeats); } -/* - * Repeat commands should be sent in a 110 ms raster. +/** + * NEC2 Send frame !!! and repeat the frame for each requested repeat !!! * There is NO delay after the last sent repeat! - * @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space - * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). + * @param aNumberOfRepeats If < 0 then nothing is sent. */ -void IRsend::sendOnkyo(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&NECProtocolConstants, (uint32_t) aCommand << 16 | aAddress, NEC_BITS, aNumberOfRepeats); +void IRsend::sendNEC2(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NEC2ProtocolConstants, computeNECRawDataAndChecksum(aAddress, aCommand), NEC_BITS, aNumberOfRepeats); } -/* - * Repeat commands should be sent in a 110 ms raster. +/** + * Apple: Send NEC with fixed 16 bit Apple address 0x87EE. * There is NO delay after the last sent repeat! * https://en.wikipedia.org/wiki/Apple_Remote * https://gist.github.com/darconeous/4437f79a34e3b6441628 - * @param aAddress is the DeviceId* * @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). */ void IRsend::sendApple(uint8_t aDeviceId, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { LongUnion tRawData; - // Address 16 bit LSB first + // Address 16 bit LSB first fixed value of 0x87EE tRawData.UWord.LowWord = APPLE_ADDRESS; // send Apple code and then 8 command bits LSB first tRawData.UByte.MidHighByte = aCommand; tRawData.UByte.HighByte = aDeviceId; // e.g. 0xD7 - sendPulseDistanceWidth(&NECProtocolConstants, tRawData.ULong, NEC_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&NECProtocolConstants, tRawData.ULong, NEC_BITS, aNumberOfRepeats); } -/* - * Sends NEC1 protocol +/** + * Sends NEC protocol * @param aNumberOfRepeats If < 0 then only a special repeat frame without leading and trailing space * will be sent by calling NECProtocolConstants.SpecialSendRepeatFunction(). */ void IRsend::sendNECRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&NECProtocolConstants, aRawData, NEC_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&NECProtocolConstants, aRawData, NEC_BITS, aNumberOfRepeats); } /** @@ -235,49 +239,39 @@ bool IRrecv::decodeNEC() { * Next try the decode */ // Check we have the right amount of data (68). The +4 is for initial gap, start bit mark and space + stop bit mark. - if (decodedIRData.rawDataPtr->rawlen != ((2 * NEC_BITS) + 4) && (decodedIRData.rawDataPtr->rawlen != 4)) { - IR_DEBUG_PRINT(F("NEC: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 68 or 4")); + if (!(decodedIRData.rawlen == ((2 * NEC_BITS) + 4) || (decodedIRData.rawlen == 4))) { + DEBUG_PRINT(F("NEC: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 68 or 4")); return false; } // Check header "mark" this must be done for repeat and data - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], NEC_HEADER_MARK)) { + if (!matchMark(irparams.rawbuf[1], NEC_HEADER_MARK)) { return false; } // Check for repeat - here we have another header space length - if (decodedIRData.rawDataPtr->rawlen == 4) { - if (matchSpace(decodedIRData.rawDataPtr->rawbuf[2], NEC_REPEAT_HEADER_SPACE) - && matchMark(decodedIRData.rawDataPtr->rawbuf[3], NEC_BIT_MARK)) { + if (decodedIRData.rawlen == 4) { + if (matchSpace(irparams.rawbuf[2], NEC_REPEAT_HEADER_SPACE) + && matchMark(irparams.rawbuf[3], NEC_BIT_MARK)) { decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST; decodedIRData.address = lastDecodedAddress; decodedIRData.command = lastDecodedCommand; - decodedIRData.protocol = lastDecodedProtocol; + decodedIRData.protocol = lastDecodedProtocol; // Allow recognition of repeats of NEC, APPLE, ONKYO and OPENLASIR and maybe LG return true; } return false; } // Check command header space - if (!matchSpace(decodedIRData.rawDataPtr->rawbuf[2], NEC_HEADER_SPACE)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("NEC: ")); - Serial.println(F("Header space length is wrong")); -#endif + if (!matchSpace(irparams.rawbuf[2], NEC_HEADER_SPACE)) { + DEBUG_PRINTLN(F("NEC: Header space length is wrong")); return false; } - // Try to decode as NEC protocol - if (!decodePulseDistanceWidthData(&NECProtocolConstants, NEC_BITS)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("NEC: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + // Decode as NEC protocol + decodePulseDistanceWidthData_P(&NECProtocolConstants, NEC_BITS); // Success // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value @@ -285,8 +279,8 @@ bool IRrecv::decodeNEC() { tValue.ULong = decodedIRData.decodedRawData; decodedIRData.command = tValue.UByte.MidHighByte; // 8 bit -#if defined(DECODE_ONKYO) - // Here only Onkyo protocol is supported -> force 16 bit address and command decoding +#if defined(DECODE_ONKYO) // Decodes NEC and Apple as Onkyo + // Here only Onkyo protocol is supported -> force 16 bit address and command decoding. No NEC decoding possible! decodedIRData.address = tValue.UWord.LowWord; // first 16 bit decodedIRData.protocol = ONKYO; decodedIRData.command = tValue.UWord.HighWord; // 16 bit command @@ -326,6 +320,7 @@ bool IRrecv::decodeNEC() { checkForRepeatSpaceTicksAndSetFlag(NEC_MAXIMUM_REPEAT_DISTANCE / MICROS_PER_TICK); if (decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) { decodedIRData.protocol = NEC2; + decodedIRData.flags |= IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT; } return true; } @@ -355,37 +350,24 @@ bool IRrecv::decodeNECMSB(decode_results *aResults) { // Check we have the right amount of data (32). +4 for initial gap, start bit mark and space + stop bit mark if (aResults->rawlen != (2 * NEC_BITS) + 4) { - IR_DEBUG_PRINT(F("NEC MSB: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(aResults->rawlen); - IR_DEBUG_PRINTLN(F(" is not 68")); + DEBUG_PRINT(F("NEC MSB: Data length=")); + DEBUG_PRINT(aResults->rawlen); + DEBUG_PRINTLN(F(" is not 68")); return false; } // Check header "space" if (!matchSpace(aResults->rawbuf[offset], NEC_HEADER_SPACE)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("NEC MSB: ")); - Serial.println(F("Header space length is wrong")); -#endif + DEBUG_PRINTLN(F("NEC MSB: Header space length is wrong")); return false; } offset++; - if (!decodePulseDistanceWidthData(NEC_BITS, offset, NEC_BIT_MARK, 0, NEC_ONE_SPACE, NEC_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("NEC MSB: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData(NEC_BITS, offset, NEC_BIT_MARK, NEC_ONE_SPACE, 0, PROTOCOL_IS_MSB_FIRST); // Stop bit if (!matchMark(aResults->rawbuf[offset + (2 * NEC_BITS)], NEC_BIT_MARK)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("NEC MSB: ")); - Serial.println(F("Stop bit mark length is wrong")); -#endif + DEBUG_PRINTLN(F("NEC MSB: Stop bit mark length is wrong")); return false; } @@ -401,6 +383,7 @@ bool IRrecv::decodeNECMSB(decode_results *aResults) { /** * With Send sendNECMSB() you can send your old 32 bit codes. * To convert one into the other, you must reverse the byte positions and then reverse all bit positions of each byte. + * Use bitreverse32Bit(). * Or write it as one binary string and reverse/mirror it. * Example: * 0xCB340102 byte reverse -> 02 01 34 CB bit reverse-> 40 80 2C D3. @@ -426,7 +409,6 @@ void IRsend::sendNECMSB(uint32_t data, uint8_t nbits, bool repeat) { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_NEC_HPP diff --git a/src/ir_OpenLASIR.hpp b/src/ir_OpenLASIR.hpp new file mode 100644 index 000000000..acb3a77f2 --- /dev/null +++ b/src/ir_OpenLASIR.hpp @@ -0,0 +1,312 @@ +/* + * ir_OpenLASIR.hpp + * + * Contains functions for receiving and sending the OpenLASIR IR Protocol. + * OpenLASIR is a modified NEC protocol with 8-bit validated address (with inverted complement) + * and 16-bit command (no error check on command). This is the opposite of NEC Extended, + * which has 16-bit address and 8-bit validated command. + * + * Protocol details: + * - Bits 0-7: Address (8 bits, Block ID) + * - Bits 8-15: ~Address (8-bit inverted copy, for error checking) + * - Bits 16-31: Command (16 bits, no error check) + * - Same timing as NEC: 38 kHz carrier, 9ms leading mark, 4.5ms leading space, + * 562.5us bit mark, 1687.5us "1" space, 562.5us "0" space, 562.5us stop bit + * - LSB first, pulse distance encoding + * - Special NEC-style repeat frame (9ms mark + 2.25ms space + stop bit) + * + * See: https://github.com/danielweidman/OpenLASIR + * + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. + * + ************************************************************************************ + * MIT License + * + * Copyright (c) 2025-2026 Daniel Weidmann, 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 _IR_OPENLASIR_HPP +#define _IR_OPENLASIR_HPP + +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +#include "LocalDebugLevelStart.h" + +/** \addtogroup Decoder Decoders and encoders for different protocols + * @{ + */ +//============================================================================== +// OpenLASIR - Modified NEC Extended Protocol +// 8-bit validated address + 16-bit command +//============================================================================== +/* + * OpenLASIR uses the same timing as NEC but rearranges the address/command structure: + * - 8-bit address with 8-bit inverted complement (for error checking) + * - 16-bit command with no error check + * Bits 0-7: Block ID (8 bits) - Address low byte + * Bits 8-15: ~Block ID (8 bits) - Address high byte (inverted, for error check) + * Bits 16-23: Device ID (8 bits) - Command bits 0-7 + * Bits 24-28: Mode (5 bits) - Command bits 8-12 + * Bits 29-31: Data (color, etc.) (3 bits) - Command bits 13-15 + * + * This is the opposite of NEC Extended, which uses 16-bit address and 8-bit validated command. + * + * The timing constants are shared with NEC (defined in ir_NEC.hpp): + * NEC_UNIT, NEC_HEADER_MARK, NEC_HEADER_SPACE, NEC_BIT_MARK, + * NEC_ONE_SPACE, NEC_ZERO_SPACE, NEC_REPEAT_HEADER_SPACE, etc. + * + * IRP notation: + * {38.0k,564}<1,-1|1,-3>(16,-8,A:8,~A:8,C:16,1,^108m,(16,-4,1,^108m)*) + * A = 8-bit address (Block ID) + * ~A = inverted address (error check) + * C = 16-bit command (Device ID + Mode + Data) + */ + +// OpenLASIR address and command bit widths +#define OPENLASIR_ADDRESS_BITS 16 // 8 bit address + 8 bit inverted address +#define OPENLASIR_COMMAND_BITS 16 // 16 bit command, no error check +#define OPENLASIR_BITS (OPENLASIR_ADDRESS_BITS + OPENLASIR_COMMAND_BITS) // 32 bits total + +/* + * Constants for Mode + */ +#define OPENLASIR_MODE_LASER_TAG_FIRE 0 // Laser tag shot. Data = color. +#define OPENLASIR_MODE_USER_PRESENCE_ANNOUNCEMENT 1 // User device saying "I'm here." No response expected. +#define OPENLASIR_MODE_BASE_STATION_PRESENCE_ANNOUNCEMENT 2 // Fixed base station saying "I'm here." +#define OPENLASIR_MODE_USER_TO_USER_HANDSHAKE_INITIATION 3 // User badge initiates handshake with another user badge. +#define OPENLASIR_MODE_USER_TO_USER_HANDSHAKE_RESPONSE 4 // Response to a user-to-user handshake initiation. +#define OPENLASIR_MODE_USER_TO_BASE_STATION_HANDSHAKE_INITIATION 5 // User badge initiates handshake with a base station. +#define OPENLASIR_MODE_USER_TO_BASE_STATION_HANDSHAKE_RESPONSE 6 // Base station responds to a user-initiated handshake. +#define OPENLASIR_MODE_BASE_STATION_TO_USER_HANDSHAKE_INITIATION 7 // Base station initiates handshake with a user badge. +#define OPENLASIR_MODE_BASE_STATION_TO_USER_HANDSHAKE_RESPONSE 8 // User badge responds to a base-station-initiated handshake. +#define OPENLASIR_MODE_COLOR_SET_TEMPORARY 9 // Tell a badge to display a color temporarily. +#define OPENLASIR_MODE_COLOR_SET_PERMANENT 10 // Tell a badge to display a color and "remember" it according to some device-specific logic. +#define OPENLASIR_MODE_GENERAL_INTERACT 11 // Tell a device to execute a general "interact" action. The specific behavior is defined by the receiver. +// modes 12 to 31 are reserved for future use + +/* + * Constants for Data / Color + */ +#define OPENLASIR_COLOR_CYAN 0 // (0, 255, 255) +#define OPENLASIR_COLOR_MAGENTA 1 // (255, 0, 255) +#define OPENLASIR_COLOR_YELLOW 2 // (255, 255, 0) +#define OPENLASIR_COLOR_GREEN 3 // (0, 255, 0) +#define OPENLASIR_COLOR_RED 4 // (255, 0, 0) +#define OPENLASIR_COLOR_BLUE 5 // (0, 0, 255) +#define OPENLASIR_COLOR_ORANGE 6 // (255, 165, 0) +#define OPENLASIR_COLOR_WHITE 7 // (255, 255, 255) + +// Timing is identical to NEC (reuse NEC_* constants from ir_NEC.hpp) + +/************************************ + * Start of send and decode functions + ************************************/ + +/** + * Send special OpenLASIR repeat frame (same as NEC repeat frame). + * Repeat commands should be sent in a 110 ms raster. + */ +void IRsend::sendOpenLASIRRepeat() { + sendNECRepeat(); +} + +/** + * Static function variant of IRsend::sendOpenLASIRRepeat + * For use in ProtocolConstants. Saves up to 250 bytes compared to a member function. + */ +void sendOpenLASIRSpecialRepeat() { + sendNECSpecialRepeat(); +} + +/** + * Compute the raw 32-bit data for an OpenLASIR frame from 8-bit address and 16-bit command. + * Address is sent as: [address:8][~address:8] (inverted complement for error checking) + * Command is sent as: [command:16] (no error check) + * + * @param aAddress 8-bit address (Block ID). Only lower 8 bits are used. + * @param aCommand 16-bit command (contains Device ID, Mode, and Data). + * @return 32-bit raw data ready for transmission. + */ +uint32_t IRsend::computeOpenLASIRRawDataAndChecksum(uint8_t aAddress, uint16_t aCommand) { + LongUnion tRawData; + + // Address: 8 bit address + 8 bit inverted address for error checking + tRawData.UByte.LowByte = aAddress; + tRawData.UByte.MidLowByte = ~aAddress; + + // Command: full 16 bits, no error check + tRawData.UWord.HighWord = aCommand; + + return tRawData.ULong; +} + +/** + * Compute the raw 32-bit data for an OpenLASIR frame from 8-bit address, 8-bit DeviceID, 5-bit Mode and 3-bit Data. + * + * @param aAddress 8-bit address (Block ID). Only lower 8 bits are used. + * @param aDeviceID 8-bit Device ID. + * @param aMode 5-bit Mode. + * @param aData 3-bit Data (color, etc.). + * @return 32-bit raw data ready for transmission. + */ +uint16_t IRsend::computeOpenLASIRRawCommand(uint8_t aDeviceID, uint8_t aMode, uint8_t aData) { + WordUnion tRawCommand; + + tRawCommand.UByte.LowByte = aDeviceID; + tRawCommand.UByte.HighByte = (aMode & 0x1F) | ((aData & 0x07) << 5); + + return tRawCommand.UWord; +} + +/** + * Send an OpenLASIR frame with special NEC-style repeats. + * There is NO delay after the last sent repeat! + * + * @param aAddress 8-bit address (Block ID). Only lower 8 bits are used. + * @param aCommand 16-bit command (Device ID + Mode + Data). + * @param aNumberOfRepeats If < 0 then only a special NEC repeat frame will be sent. + */ +void IRsend::sendOpenLASIR(uint8_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NECProtocolConstants, computeOpenLASIRRawDataAndChecksum(aAddress, aCommand), OPENLASIR_BITS, + aNumberOfRepeats); +} + +/** + * Send an OpenLASIR frame with special NEC-style repeats. + * There is NO delay after the last sent repeat! + * + * @param aAddress 8-bit address (Block ID). Only lower 8 bits are used. + * @param aDeviceID 8-bit Device ID. + * @param aMode 5-bit Mode. + * @param aData 3-bit Data (color, etc.). + * @param aNumberOfRepeats If < 0 then only a special NEC repeat frame will be sent. + */ +void IRsend::sendOpenLASIR(uint8_t aAddress, uint8_t aDeviceID, uint8_t aMode, uint8_t aData, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NECProtocolConstants, + computeOpenLASIRRawDataAndChecksum(aAddress, computeOpenLASIRRawCommand(aDeviceID, aMode, aData)), + OPENLASIR_BITS, aNumberOfRepeats); +} + +/** + * Send raw 32-bit OpenLASIR data. + * @param aRawData The pre-computed 32-bit raw data. + * @param aNumberOfRepeats If < 0 then only a special NEC repeat frame will be sent. + */ +void IRsend::sendOpenLASIRRaw(uint32_t aRawData, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&NECProtocolConstants, aRawData, OPENLASIR_BITS, aNumberOfRepeats); +} + +/** + * Decode an OpenLASIR frame. + * + * OpenLASIR uses the same physical layer as NEC but with different address/command structure: + * - 8-bit address with inverted complement (error check on address) + * - 16-bit command without error check + * + * The decoder validates the address by checking that the second byte is the bitwise + * inverse of the first byte. The full 16-bit command is returned as-is. + * + * @return true if a valid OpenLASIR frame was decoded. + */ +bool IRrecv::decodeOpenLASIR() { + /* + * First check for right data length + * Next check start bit + * Next try the decode + */ + + // Check we have the right amount of data (68). The +4 is for initial gap, start bit mark and space + stop bit mark. + if (!(decodedIRData.rawlen == ((2 * OPENLASIR_BITS) + 4) || (decodedIRData.rawlen == 4))) { + DEBUG_PRINT(F("OpenLASIR: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 68 or 4")); + return false; + } + + // Check header "mark" - this must be done for repeat and data + if (!matchMark(irparams.rawbuf[1], NEC_HEADER_MARK)) { + return false; + } + +#if !defined(DECODE_NEC) // This code is also contained in NEC sources and does also decode LASIR Repeats :-) + // Check for repeat - here we have another header space length + if (decodedIRData.rawlen == 4) { + if (matchSpace(irparams.rawbuf[2], NEC_REPEAT_HEADER_SPACE) && matchMark(irparams.rawbuf[3], NEC_BIT_MARK)) { + decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST; + decodedIRData.address = lastDecodedAddress; + decodedIRData.command = lastDecodedCommand; + decodedIRData.protocol = lastDecodedProtocol; // Allow recognition of repeats of another look alike protocol + return true; + } + return false; + } +#endif + + // Check command header space + if (!matchSpace(irparams.rawbuf[2], NEC_HEADER_SPACE)) { + DEBUG_PRINTLN(F("OpenLASIR: Header space length is wrong")); + return false; + } + + // Decode the pulse distance data using NEC timing + decodePulseDistanceWidthData_P(&NECProtocolConstants, OPENLASIR_BITS); + + // Success - now interpret the 32 raw bits + LongUnion tValue; + tValue.ULong = decodedIRData.decodedRawData; + + // Validate address: second byte must be inverted first byte + if (tValue.UByte.LowByte != (uint8_t)(~tValue.UByte.MidLowByte)) { + // Address validation failed - this is not a valid OpenLASIR frame + DEBUG_PRINTLN(F("OpenLASIR: Address validation failed")); + return false; + } + + /* + * Disambiguation with standard NEC: + * If the command also has a valid inverted pattern (upper 8 bits == ~lower 8 bits), + * then this looks like a standard NEC frame, not OpenLASIR. + * By design, OpenLASIR uses 16-bit commands that should NOT have this property, + * so we let the NEC decoder handle these frames instead. + * (See OpenLASIR spec: "This is to prevent OpenLASIR packets from causing issues + * with NEC devices except in very rare cases of collisions.") + */ + if (tValue.UByte.MidHighByte == (uint8_t)(~tValue.UByte.HighByte)) { + DEBUG_PRINTLN(F("OpenLASIR: Command has valid inverse - looks like standard NEC, skipping")); + return false; + } + + // Valid OpenLASIR frame + decodedIRData.protocol = OPENLASIR; + decodedIRData.address = tValue.UByte.LowByte; // 8-bit validated address (Block ID) + decodedIRData.command = tValue.UWord.HighWord; // 16-bit command (Device ID + Mode + Data) + decodedIRData.numberOfBits = OPENLASIR_BITS; + + // Check for repeat (same frame sent again within repeat window) + checkForRepeatSpaceTicksAndSetFlag(NEC_MAXIMUM_REPEAT_DISTANCE / MICROS_PER_TICK); + + return true; +} + +/** @}*/ +#include "LocalDebugLevelEnd.h" + +#endif // _IR_OPENLASIR_HPP diff --git a/src/ir_Others.hpp b/src/ir_Others.hpp index 29fcf6c9d..39b04e4ee 100644 --- a/src/ir_Others.hpp +++ b/src/ir_Others.hpp @@ -58,11 +58,11 @@ #define DISH_ZERO_SPACE 2800 #define DISH_REPEAT_SPACE 6200 // really? -struct PulseDistanceWidthProtocolConstants DishProtocolConstants = { UNKNOWN, 56, DISH_HEADER_MARK, DISH_HEADER_SPACE, -DISH_BIT_MARK, DISH_ONE_SPACE, DISH_BIT_MARK, DISH_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST, 40, NULL }; +struct PulseDistanceWidthProtocolConstants const DishProtocolConstants PROGMEM = {UNKNOWN, 56, DISH_HEADER_MARK, DISH_HEADER_SPACE, + DISH_BIT_MARK, DISH_ONE_SPACE, DISH_BIT_MARK, DISH_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, 40, nullptr}; void IRsend::sendDish(uint16_t aData) { - sendPulseDistanceWidth(&DishProtocolConstants, aData, DISH_BITS, 4); + sendPulseDistanceWidth_P(&DishProtocolConstants, aData, DISH_BITS, 4); } //============================================================================== @@ -84,30 +84,142 @@ void IRsend::sendDish(uint16_t aData) { #define WHYNTER_ONE_SPACE 2150 #define WHYNTER_ZERO_SPACE 750 -struct PulseDistanceWidthProtocolConstants WhynterProtocolConstants = { WHYNTER, 38, WHYNTER_HEADER_MARK, WHYNTER_HEADER_SPACE, -WHYNTER_BIT_MARK, WHYNTER_ONE_SPACE, WHYNTER_BIT_MARK, WHYNTER_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST, 110, NULL }; +struct PulseDistanceWidthProtocolConstants const WhynterProtocolConstants PROGMEM = {WHYNTER, 38, WHYNTER_HEADER_MARK, WHYNTER_HEADER_SPACE, + WHYNTER_BIT_MARK, WHYNTER_ONE_SPACE, WHYNTER_BIT_MARK, WHYNTER_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, 110, nullptr}; -void IRsend::sendWhynter(uint32_t aData, uint8_t aNumberOfBitsToSend) { - sendPulseDistanceWidth(&WhynterProtocolConstants, aData, NEC_BITS, aNumberOfBitsToSend); +void IRsend::sendWhynter(uint32_t aData, int_fast8_t aNumberOfRepeats) { + sendPulseDistanceWidth_P(&WhynterProtocolConstants, aData, NEC_BITS, aNumberOfRepeats); } bool IRrecv::decodeWhynter() { // Check we have the right amount of data (68). The +4 is for initial gap, start bit mark and space + stop bit mark. - if (decodedIRData.rawDataPtr->rawlen != (2 * WHYNTER_BITS) + 4) { + if (decodedIRData.rawlen != (2 * WHYNTER_BITS) + 4) { return false; } - if (!checkHeader(&WhynterProtocolConstants)) { + if (!checkHeader_P(&WhynterProtocolConstants)) { return false; } - if (!decodePulseDistanceWidthData(&WhynterProtocolConstants, WHYNTER_BITS)) { - return false; - } - // Success + decodePulseDistanceWidthData_P(&WhynterProtocolConstants, WHYNTER_BITS); + decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; decodedIRData.numberOfBits = WHYNTER_BITS; decodedIRData.protocol = WHYNTER; return true; } +/** + * VELUX + * see https://github.com/XPModder/Velux-IR-protocol + * see https://github.com/Arduino-IRremote/Arduino-IRremote/issues/612 + * We have a pulse width protocol with constant bit length of 1700 us with no header and one autorepeat after 27 ms. + * Length of one frame is constant 23 * 1700 + 425 (for stop bit) = 39525 = 40 ms + * + * BIT meaning for MSB first: + * Bit 23 is stop + * Bit 22 is up = 0 or down = 1, 0 for stop + * Bit 21 is automatic and also set for stop + * Bit 20 is Motor 3 + * Bit 19 is Motor 2 + * Bit 18 is Motor 1 + * [14:17] is 4 bit motor set (from 1 to 10), 0 = all sets + * [4:13] 10 bit security code + * [1:3] is checksum + * + * Checksum is independent of the 10 bit security code + * + * !!! MOTOR 3 is coded with 0x04, since motor numbers are bit position coded to enable 0x07 as all motors!!! + * Automatic bit is set for all following codes! + * Checksum for UP (0x1): + * All (Motor = 0x7, set = 0) -> 2 == Motor 1 set A or Motor 3 set 5 + * Table of checksum (x) for motor / set combinations + * Set 1 2 3 4 5 6 7 8 9 A + * Motor 1 9 A B C D E F 0 1 2 3 4 5 6 | x XOR set = 8 or set XOR 8 = checksum + * Motor 2 C F E 9 8 B A 5 4 7 6 1 0 2 | x XOR set = D = 8 XOR 5 or set XOR 8 XOR 5 = checksum + * Motor 3/4 6 5 4 3 2 1 0 F E D C B A 9 | x XOR set = 7 = 8 XOR F or set XOR 8 XOR F = checksum + * Checksum for DOWN (0x3): + * All -> 7 == Motor 1 set A + * Table of checksum (x) for motor / set combinations + * Set 1 2 3 4 5 6 7 8 9 A + * Motor 1 C F E 9 8 B A 5 4 7 6 1 0 2 | x XOR set = D + * Motor 2 9 A B C D E F 0 1 2 3 4 5 6 | x XOR set = 8 = D XOR 5 + * Motor 3/4 3 0 1 6 7 4 5 A B 8 9 E F D | x XOR set = 2 = D XOR F + * Checksum for STOP (0x5): + * All -> 8 == Motor 1 set A + * Table of checksum (x) for motor / set combinations + * Set 1 2 3 4 5 6 7 8 9 A + * Motor 1 3 0 1 6 7 4 5 A B 8 9 E F D | x XOR set = 2 + * Motor 2 6 5 4 3 2 1 0 F E D C B A 9 | x XOR set = 7 = 2 XOR 5 + * Motor 3/4 C F E 9 8 B A 5 4 7 6 1 0 2 | x XOR set = D = 2 XOR F + */ + +// All timings are in microseconds +#define VELUX_BITS 24 // We have pulse width, so we have no stop bit +#define VELUX_HEADER_MARK 0 +#define VELUX_HEADER_SPACE 0 +#define VELUX_UNIT 425 +#define VELUX_ONE_MARK (3*VELUX_UNIT) // 1275 +#define VELUX_ONE_SPACE VELUX_UNIT +#define VELUX_ZERO_MARK VELUX_UNIT +#define VELUX_ZERO_SPACE (3*VELUX_UNIT) +#define VELUX_PERIOD ((23 * 4) + 1 ) * VELUX_UNIT) // 39525 +#define VELUX_AUTOREPEAT_SPACE 27000 // 27ms +#define VELUX_REPEAT_SPACE 100000 // 100ms, which is just a guess + +#define VELUX_COMMAND_AUTO_UP 0x1 +#define VELUX_COMMAND_AUTO_DOWN 0x3 +#define VELUX_COMMAND_STOP 0x5 + +struct PulseDistanceWidthProtocolConstants const VeluxProtocolConstants PROGMEM = {OTHER, 30, VELUX_HEADER_MARK, VELUX_HEADER_SPACE, + VELUX_ONE_MARK, VELUX_ONE_SPACE, VELUX_ZERO_MARK, VELUX_ZERO_SPACE, PROTOCOL_IS_MSB_FIRST | PROTOCOL_IS_PULSE_WIDTH, 27, nullptr}; + +/* + * @param aCommand VELUX_COMMAND_AUTO_UP or VELUX_COMMAND_AUTO_DOWN or VELUX_COMMAND_STOP + * @param aMotorNumber 1, 2, 4 = Motor3, 7 = All + * @param aMotorSet 0 = All, 1 to 10 + * !!!NO parameter range check here!!! + */ +void IRsend::sendVelux(uint8_t aCommand, uint8_t aMotorNumber, uint8_t aMotorSet, uint16_t aSecurityCode, + int_fast8_t aNumberOfRepeats) { + // Just in case... + if (aMotorNumber == 3) { + aMotorNumber = 4; // motor numbers are bit position coded + } + + /* + * Compute checksum (only for automatic bit set to 1) + */ + uint8_t tChecksum = 8; // Start checksum for command + if (aCommand == VELUX_COMMAND_AUTO_DOWN) { + tChecksum = 0xD; + } + if (aCommand == VELUX_COMMAND_STOP) { + tChecksum = 2; + } + + uint8_t tXORForMotor = 0; + if (aMotorNumber == 2) { + tXORForMotor = 5; + } + if (aMotorNumber == 4) { + tXORForMotor = 0xF; + } + + tChecksum ^= aMotorSet; + tChecksum ^= tXORForMotor; + + sendVelux( + ((uint32_t) aCommand << 21) | ((uint32_t) aMotorNumber << 18) | (aMotorSet << 14) | ((uint32_t) aSecurityCode << 4) + | tChecksum, aNumberOfRepeats); +} + +void IRsend::sendVelux(uint32_t aData, int_fast8_t aNumberOfRepeats) { + do { + sendPulseDistanceWidth_P(&VeluxProtocolConstants, aData, VELUX_BITS, 0); + delay(VELUX_AUTOREPEAT_SPACE / MICROS_IN_ONE_MILLI); + sendPulseDistanceWidth_P(&VeluxProtocolConstants, aData, VELUX_BITS, 0); + delay(VELUX_REPEAT_SPACE / MICROS_IN_ONE_MILLI); + aNumberOfRepeats--; + } while (aNumberOfRepeats >= 0); +} /** @}*/ #endif // _IR_OTHERS_HPP diff --git a/src/ir_Pronto.hpp b/src/ir_Pronto.hpp index 2a8c9bc32..c4723a168 100644 --- a/src/ir_Pronto.hpp +++ b/src/ir_Pronto.hpp @@ -2,6 +2,8 @@ * @file ir_Pronto.hpp * @brief In this file, the functions IRrecv::compensateAndPrintPronto and IRsend::sendPronto are defined. * + * Pronto is the standard for the professional audio and video hardware market. + * * See http://www.harctoolbox.org/Glossary.html#ProntoSemantics * Pronto database http://www.remotecentral.com/search.htm * @@ -10,7 +12,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2020 Bengt Martensson + * Copyright (c) 2020-2025 Bengt Martensson, 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 @@ -34,11 +36,7 @@ #ifndef _IR_PRONTO_HPP #define _IR_PRONTO_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -82,12 +80,12 @@ void IRsend::sendPronto(const uint16_t *data, uint16_t length, int_fast8_t aNumb } uint16_t intros = 2 * data[2]; uint16_t repeats = 2 * data[3]; -#if defined(LOCAL_DEBUG) - Serial.print(F("sendPronto intros=")); - Serial.print(intros); - Serial.print(F(" repeats=")); - Serial.println(repeats); -#endif + + DEBUG_PRINT(F("sendPronto intros=")); + DEBUG_PRINT(intros); + DEBUG_PRINT(F(" repeats=")); + DEBUG_PRINTLN(repeats); + if (numbersInPreamble + intros + repeats != length) { // inconsistent sizes return; } @@ -99,7 +97,7 @@ void IRsend::sendPronto(const uint16_t *data, uint16_t length, int_fast8_t aNumb uint16_t durations[intros + repeats]; for (uint16_t i = 0; i < intros + repeats; i++) { uint32_t duration = ((uint32_t) data[i + numbersInPreamble]) * timebase; - durations[i] = (uint16_t) ((duration <= UINT16_MAX) ? duration : UINT16_MAX); + durations[i] = (uint16_t)((duration <= UINT16_MAX) ? duration : UINT16_MAX); } /* @@ -174,7 +172,7 @@ void IRsend::sendPronto(const char *str, int_fast8_t aNumberOfRepeats) { void IRsend::sendPronto_PF(uint_farptr_t str, int_fast8_t aNumberOfRepeats) { size_t len = strlen_PF(str); char work[len + 1]; - strncpy_PF(work, str, len); + strcpy_PF(work, str); // We know that string including terminating character fits in work sendPronto(work, aNumberOfRepeats); } @@ -182,15 +180,18 @@ void IRsend::sendPronto_PF(uint_farptr_t str, int_fast8_t aNumberOfRepeats) { void IRsend::sendPronto_P(const char *str, int_fast8_t aNumberOfRepeats) { size_t len = strlen_P(str); char work[len + 1]; - strncpy_P(work, str, len); + strcpy_P(work, str); sendPronto(work, aNumberOfRepeats); } #endif +/* + * Copy flash data to ram buffer in stack + */ void IRsend::sendPronto(const __FlashStringHelper *str, int_fast8_t aNumberOfRepeats) { size_t len = strlen_P(reinterpret_cast(str)); char work[len + 1]; - strncpy_P(work, reinterpret_cast(str), len); + strcpy_P(work, reinterpret_cast(str)); return sendPronto(work, aNumberOfRepeats); } @@ -206,30 +207,31 @@ static uint16_t toFrequencyCode(uint16_t frequency) { return referenceFrequency / effectiveFrequency(frequency); } -static char hexDigit(uint16_t x) { +static char DigitToHex(uint8_t x) { return (char) (x <= 9 ? ('0' + x) : ('A' + (x - 10))); } -static void dumpDigit(Print *aSerial, uint16_t number) { - aSerial->print(hexDigit(number)); +static void dumpDigitHex(Print *aSerial, uint8_t number) { + aSerial->print(DigitToHex(number)); } -static void dumpNumber(Print *aSerial, uint16_t number) { +static void dumpNumberHex(Print *aSerial, uint16_t number) { + // Loop through all 4 nibbles for (uint16_t i = 0; i < digitsInProntoNumber; i++) { uint16_t shifts = bitsInHexadecimal * (digitsInProntoNumber - 1 - i); - dumpDigit(aSerial, (number >> shifts) & hexMask); + dumpDigitHex(aSerial, (number >> shifts) & hexMask); } aSerial->print(' '); } -static void dumpDuration(Print *aSerial, uint32_t duration, uint16_t timebase) { - dumpNumber(aSerial, (duration + timebase / 2) / timebase); +static void dumpDurationHex(Print *aSerial, uint32_t duration, uint16_t timebase) { + dumpNumberHex(aSerial, (duration + timebase / 2) / timebase); } /* * Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding! */ -static void compensateAndDumpSequence(Print *aSerial, const volatile uint16_t *data, size_t length, uint16_t timebase) { +static void compensateAndDumpSequence(Print *aSerial, const volatile IRRawbufType *data, size_t length, uint16_t timebase) { for (size_t i = 0; i < length; i++) { uint32_t tDuration = data[i] * MICROS_PER_TICK; if (i & 1) { @@ -238,29 +240,30 @@ static void compensateAndDumpSequence(Print *aSerial, const volatile uint16_t *d } else { tDuration += getMarkExcessMicros(); } - dumpDuration(aSerial, tDuration, timebase); + dumpDurationHex(aSerial, tDuration, timebase); } // append a gap - dumpDuration(aSerial, PRONTO_DEFAULT_GAP, timebase); + dumpDurationHex(aSerial, PRONTO_DEFAULT_GAP, timebase); } /** * Print the result (second argument) as Pronto Hex on the Print supplied as argument. * Used in the ReceiveDump example. - * @param aSerial The Print object on which to write, for Arduino you can use &Serial. + * Do not print repeat sequence data. + * @param aSerial The Print object on which to write, you can use &Serial for Arduino. * @param aFrequencyHertz Modulation frequency in Hz. Often 38000Hz. */ void IRrecv::compensateAndPrintIRResultAsPronto(Print *aSerial, uint16_t aFrequencyHertz) { - aSerial->println(F("Pronto Hex as string")); + aSerial->println(F("Pronto Hex as string without repeat sequence")); aSerial->print(F("char prontoData[] = \"")); - dumpNumber(aSerial, aFrequencyHertz > 0 ? learnedToken : learnedNonModulatedToken); - dumpNumber(aSerial, toFrequencyCode(aFrequencyHertz)); - dumpNumber(aSerial, (decodedIRData.rawDataPtr->rawlen + 1) / 2); - dumpNumber(aSerial, 0); + dumpNumberHex(aSerial, aFrequencyHertz > 0 ? learnedToken : learnedNonModulatedToken); + dumpNumberHex(aSerial, toFrequencyCode(aFrequencyHertz)); + dumpNumberHex(aSerial, (decodedIRData.rawlen + 1) / 2); + dumpNumberHex(aSerial, 0); // no repeat data uint16_t timebase = toTimebase(aFrequencyHertz); - compensateAndDumpSequence(aSerial, &decodedIRData.rawDataPtr->rawbuf[1], decodedIRData.rawDataPtr->rawlen - 1, timebase); // skip leading space - aSerial->println("\";"); + compensateAndDumpSequence(aSerial, &irparams.rawbuf[1], decodedIRData.rawlen - 1, timebase); // skip leading space + aSerial->println(F("\";")); } /* @@ -268,18 +271,18 @@ void IRrecv::compensateAndPrintIRResultAsPronto(Print *aSerial, uint16_t aFreque * and can lead to resource problems especially on small processors like AVR's */ -static bool dumpDigit(String *aString, uint16_t number) { - aString->concat(hexDigit(number)); +static bool dumpDigitHex(String *aString, uint8_t number) { + aString->concat(DigitToHex(number)); return number; } -static size_t dumpNumber(String *aString, uint16_t number) { +static size_t dumpNumberHex(String *aString, uint16_t number) { size_t size = 0; for (uint16_t i = 0; i < digitsInProntoNumber; i++) { uint16_t shifts = bitsInHexadecimal * (digitsInProntoNumber - 1 - i); - size += dumpDigit(aString, (number >> shifts) & hexMask); + size += dumpDigitHex(aString, (number >> shifts) & hexMask); } aString->concat(' '); size++; @@ -290,11 +293,11 @@ static size_t dumpNumber(String *aString, uint16_t number) { /* * Compensate received values by MARK_EXCESS_MICROS, like it is done for decoding! */ -static size_t dumpDuration(String *aString, uint32_t duration, uint16_t timebase) { - return dumpNumber(aString, (duration + timebase / 2) / timebase); +static size_t dumpDurationHex(String *aString, uint32_t duration, uint16_t timebase) { + return dumpNumberHex(aString, (duration + timebase / 2) / timebase); } -static size_t compensateAndDumpSequence(String *aString, const volatile uint16_t *data, size_t length, uint16_t timebase) { +static size_t compensateAndDumpSequence(String *aString, const volatile IRRawbufType *data, size_t length, uint16_t timebase) { size_t size = 0; @@ -306,11 +309,11 @@ static size_t compensateAndDumpSequence(String *aString, const volatile uint16_t } else { tDuration += getMarkExcessMicros(); } - size += dumpDuration(aString, tDuration, timebase); + size += dumpDurationHex(aString, tDuration, timebase); } // append minimum gap - size += dumpDuration(aString, PRONTO_DEFAULT_GAP, timebase); + size += dumpDurationHex(aString, PRONTO_DEFAULT_GAP, timebase); return size; } @@ -324,18 +327,16 @@ size_t IRrecv::compensateAndStorePronto(String *aString, uint16_t frequency) { size_t size = 0; uint16_t timebase = toTimebase(frequency); - size += dumpNumber(aString, frequency > 0 ? learnedToken : learnedNonModulatedToken); - size += dumpNumber(aString, toFrequencyCode(frequency)); - size += dumpNumber(aString, (decodedIRData.rawDataPtr->rawlen + 1) / 2); - size += dumpNumber(aString, 0); - size += compensateAndDumpSequence(aString, &decodedIRData.rawDataPtr->rawbuf[1], decodedIRData.rawDataPtr->rawlen - 1, - timebase); // skip leading space + size += dumpNumberHex(aString, frequency > 0 ? learnedToken : learnedNonModulatedToken); + size += dumpNumberHex(aString, toFrequencyCode(frequency)); + size += dumpNumberHex(aString, (decodedIRData.rawlen + 1) / 2); + size += dumpNumberHex(aString, 0); + size += compensateAndDumpSequence(aString, &irparams.rawbuf[1], decodedIRData.rawlen - 1, timebase); // skip leading space return size; } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_PRONTO_HPP diff --git a/src/ir_RC5_RC6.hpp b/src/ir_RC5_RC6.hpp index 594bb079a..b988011bf 100644 --- a/src/ir_RC5_RC6.hpp +++ b/src/ir_RC5_RC6.hpp @@ -8,6 +8,8 @@ ************************************************************************************ * MIT License * + * Copyright (c) 2020-2026 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 @@ -30,17 +32,15 @@ #ifndef _IR_RC5_RC6_HPP #define _IR_RC5_RC6_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +// This block must be located after the includes of other *.hpp files +//#define LOCAL_DEBUG // This enables debug output only for this file - only for development +//#define LOCAL_TRACE // This enables trace output only for this file - only for development +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ */ -uint8_t sLastSendToggleValue = 1; // To start first command with toggle 0 -//uint8_t sLastReceiveToggleValue = 3; // 3 -> start value +uint8_t sLastSendToggleValue = 1; // To start first command with toggle 0. Only required for biphase protocols. //============================================================================== // RRRR CCCC 55555 @@ -50,31 +50,76 @@ uint8_t sLastSendToggleValue = 1; // To start first command with toggle 0 // R R CCCC 5555 //============================================================================== /* - Protocol=RC5 Address=0x11 Command=0x36 Raw-Data=0x1476 13 bits MSB first - + 900,- 900 - +1800,-1750 +1800,- 850 + 900,- 850 + 900,-1750 - + 950,- 850 + 900,- 850 +1800,-1750 + 950,- 850 - +1800 - Sum: 23100 - - RC5X with 7.th MSB of command set - Protocol=RC5 Address=0x11 Command=0x76 Toggle=1 Raw-Data=0xC76 13 bits MSB first - +1800,-1750 - + 850,- 900 +1800,- 850 + 950,- 850 + 900,-1750 - + 900,- 850 + 950,- 850 +1800,-1750 + 900,- 850 - +1800 - Sum: 23050 + Protocol=RC5 Address=0x11, Command=0x36, Raw-Data=0x1476, 13 bits, MSB first + + 950,- 850 + +1850,-1700 +1850,- 850 + 900,- 850 +1000,-1700 + + 950,- 850 + 950,- 800 +1850,-1750 + 950,- 850 + +1850 + Duration=23300us + + RC5X with 7.th MSB of command set as 1 + Protocol=RC5 Address=0x11, Command=0x76, Toggle=1, Raw-Data=0xC76, 13 bits, MSB first + +1900,-1700 + + 950,- 850 +1850,- 800 + 950,- 800 +1000,-1700 + +1000,- 750 + 950,- 900 +1800,-1700 +1000,- 800 + +1850 + Duration=23250us + + RC5 minimal length (RX5X) + Protocol=RC5 Address=0xA, Command=0x6A, Toggle=1, Raw-Data=0xAAA, 13 bits, MSB first + rawIRTimings[14]: + -746950 + +1900,-1700 + +1850,-1700 +1800,-1750 +1800,-1750 +1800,-1750 + +1800,-1750 +1750 + Duration=23100us + + RC5 maximal length + Protocol=RC5 Address=0x1F, Command=0x3F, Toggle=1, Raw-Data=0x1FFF, 13 bits, MSB first + rawIRTimings[28]: + -391800 + + 950,- 850 + + 950,- 800 + 950,- 850 + 900,- 900 + 950,- 800 + + 950,- 850 + 900,- 900 + 900,- 850 +1000,- 800 + +1000,- 800 + 850,- 950 + 950,- 800 +1000,- 800 + + 900 + Duration=24100us + + Protocol=Marantz Address=0x11, Command=0x76, Extra=0x9, Toggle=1, Raw-Data=0x31D89, 19 bits, MSB first + +1850,-1700 + + 950,- 850 +1850,- 850 + 950,- 800 +1000,-1700 + + 950,-4350 + 950,- 900 +1850,-1700 + 900,- 850 + +1850,- 850 + 950,- 800 +1000,-1700 +1800,- 900 + + 900,-1750 + 950 + Duration=38400us + +Marantz maximal length +Protocol=Marantz Address=0x1F, Command=0x3F, Extra=0x3F, Toggle=1, Raw-Data=0x7FFFF, 19 bits, MSB first +rawIRTimings[40]: + -398900 + + 950,- 850 + + 850,- 950 + 900,- 900 + 950,- 850 + 950,- 800 + +1000,- 800 + 900,- 900 + 950,-4350 + 950,- 850 + + 950,- 800 +1000,- 800 + 850,- 950 + 950,- 850 + + 900,- 850 + 950,- 850 + 950,- 850 + 950,- 800 + +1000,- 800 + 950,- 850 + 850 +Duration=38350us */ // // see: https://www.sbprojects.net/knowledge/ir/rc5.php // https://en.wikipedia.org/wiki/Manchester_code -// https://forum.arduino.cc/t/sending-rc-5-extended-code-using-irsender/1045841/10 - Protocol Maranz Extended +// https://en.wikipedia.org/wiki/RC-5 // mark->space => 0 // space->mark => 1 -// MSB first 1 start bit, 1 field bit, 1 toggle bit + 5 bit address + 6 bit command, no stop bit -// Field bit is 1 for RC5 and inverted 7. command bit for RC5X. That way the first 64 commands of RC5X remain compatible with the original RC5. +// MSB first, 1 start bit, 1 field bit, 1 toggle bit + 5 bit address + 6 bit command, no stop bit 14 bits incl. field bit and start bit +// Field bit is 1 for RC5 and 0 (=inverted 7. command bit) for RC5X. That way the first 64 commands of RC5X are indistinguishable from RC5. // SF TAAA AACC CCCC -// IR duty factor is 25%, +// IR duty factor is 25% +// +// MARANTZ +// https://forum.arduino.cc/t/sending-rc-5-extended-code-using-irsender/1045841/10 - Protocol Maranz Extended +// Marantz uses RC5X and adds a 3.5 ms pause after the address / first 8 bits +// After the 6 bit command (of RC5) an additional 6 bit command extension is sent -> 20 bits incl. field bit and start bit // #define RC5_ADDRESS_BITS 5 #define RC5_COMMAND_BITS 6 @@ -85,44 +130,129 @@ uint8_t sLastSendToggleValue = 1; // To start first command with toggle 0 #define RC5_UNIT 889 // 32 periods of 36 kHz (888.8888) -#define MIN_RC5_MARKS ((RC5_BITS + 1) / 2) // 7. Divided by 2 to handle the bit sequence of 01010101 which gives one mark and space for each 2 bits +#define MIN_RC5_MARKS ((RC5_BITS + 1) / 2) // 7 - Divided by 2 to handle the bit sequence of 01010101 which gives one mark and space for each 2 bits -#define RC5_DURATION (15L * RC5_UNIT) // 13335 +#define RC5_DURATION (26 * RC5_UNIT) // 23114 #define RC5_REPEAT_PERIOD (128L * RC5_UNIT) // 113792 -#define RC5_REPEAT_DISTANCE (RC5_REPEAT_PERIOD - RC5_DURATION) // 100 ms -#define RC5_MAXIMUM_REPEAT_DISTANCE (RC5_REPEAT_DISTANCE + (RC5_REPEAT_DISTANCE / 4)) // Just a guess +#define RC5_REPEAT_DISTANCE (RC5_REPEAT_PERIOD - RC5_DURATION) // 90 ms +#define RC5_MAXIMUM_REPEAT_DISTANCE (RC5_REPEAT_DISTANCE + (RC5_REPEAT_DISTANCE / 4)) // Just a guess + +#define MARANTZ_COMMAND_EXTENSION_BITS 6 +#define MARANTZ_BITS (RC5_COMMAND_FIELD_BIT + RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS + MARANTZ_COMMAND_EXTENSION_BITS) // 19 +#define MARANTZ_PAUSE_BIT_INDEX (RC5_COMMAND_FIELD_BIT + RC5_TOGGLE_BIT + RC5_ADDRESS_BITS) // 7 +#define MARANTZ_PAUSE_DURATION (4 * RC5_UNIT) // 3556 + +#define MARANTZ_DURATION (42L * RC5_UNIT) // RC5 + 6 Extension bits + 4 pause units = 37338 +#define MARANTZ_REPEAT_DISTANCE (RC5_REPEAT_PERIOD - MARANTZ_DURATION) // 100 ms /************************************ * Start of send and decode functions ************************************/ +/* + * Just in case to permanently send it as 0 because start value is 1, + * or to reset toggle bit after a transmission with automatic toggling. + * Sets sLastSendToggleValue to inverse in order to get aRC5ToggleBitValue as next sent toggle value because it is inverted before each sending! + * @param aRC5ToggleBitValue 0 or 1, only LSB is taken + */ +void IRsend::setNextToggleBitValueForRC5AndRC6(uint8_t aRC5ToggleBitValue) { + sLastSendToggleValue = (aRC5ToggleBitValue & 0x01) ^ 0x01; +} + /** - * @param aCommand If aCommand is >=0x40 then we switch automatically to RC5X. + * Send function for the Marantz version of RC5(X) with a pause of 4 * RC5_UNIT after address / first 8 bits + * and before the bits of command and command extension. + * Marantz seems to require at least one repetition with toggle bit set + * @param aAddress 5 address bits to be sent first (MSB first). + * @param aCommand 6 or 7 (RC5X) bits. If aCommand is >=0x40 then we switch automatically to RC5X. + * @param aMarantzExtension 6 bit command extension which is sent after 6 command bits of aCommand. aCommand and aMarantzExtension are sent after a short pause. * @param aEnableAutomaticToggle Send toggle bit according to the state of the static sLastSendToggleValue variable. */ -void IRsend::sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) { +void IRsend::sendRC5Marantz(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t aMarantzExtension, + bool aEnableAutomaticToggle) { + // Set IR carrier frequency enableIROut (RC5_RC6_KHZ); - uint16_t tIRData = ((aAddress & 0x1F) << RC5_COMMAND_BITS); + uint16_t tIRData = (aAddress & 0x1F); - if (aCommand < 0x40) { - // Auto discovery of RC5X, set field bit to 1 - tIRData |= 1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS); + /* + * Process field bit (the bit after start bit) + * Field bit is 1 for RC5 and 0 (inverted 7. command bit) for RC5X + */ + if (aCommand >= 0x40) { // Auto discovery of RC5X + // Mask bit 7 of command to set field bit to 0 (inverted 1) for RC5X + aCommand &= 0x3F; } else { - // Mask bit 7 of command and let field bit 0 + // Set field bit to 1 for RC5 + tIRData |= 1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS); // 1 << 6 = 0x40 + } + + // Combine command and command extension for the 2nd part of data to be sent after the pause + uint16_t tIRExtData = (aCommand << MARANTZ_COMMAND_EXTENSION_BITS); + // Set the Marantz command extension bits + tIRExtData |= (aMarantzExtension & 0x3F); + + if (aEnableAutomaticToggle) { + // invert toggle bit if enabled + sLastSendToggleValue ^= 1; + } + // set toggled bit independent of current state of aEnableAutomaticToggle + if (sLastSendToggleValue) { + tIRData |= 1 << RC5_ADDRESS_BITS; + } + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + + // start bit is sent by sendBiphaseData followed by the field bit and toggle bit and address + sendBiphaseData(RC5_UNIT, tIRData, RC5_COMMAND_FIELD_BIT + RC5_TOGGLE_BIT + RC5_ADDRESS_BITS); + // pause before the bits of command and command extension to indicate that it's Marantz-RC5x + space(MARANTZ_PAUSE_DURATION); // 3556, Marantz-RC5x has a pause before the bits of command and command extension + // send command and command extension + sendBiphaseData(RC5_UNIT, tIRExtData, RC5_COMMAND_BITS + MARANTZ_COMMAND_EXTENSION_BITS, false); + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + // send repeated command in a fixed raster of 100 ms + delay(MARANTZ_REPEAT_DISTANCE / MICROS_IN_ONE_MILLI); + } + } +} + +/** + * @param aAddress 5 address bits to be sent first (MSB first). + * @param aCommand 6 or 7 (RC5X) bits. If aCommand is >=0x40 then we switch automatically to RC5X. + * @param aEnableAutomaticToggle Send toggle bit according to the state of the static sLastSendToggleValue variable. + */ +void IRsend::sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) { + + // Set IR carrier frequency + enableIROut (RC5_RC6_KHZ); + + uint16_t tIRData = ((aAddress & 0x1F) << (RC5_COMMAND_BITS)); // << 6 + + /* + * Process field bit (the bit after start bit) + * Field bit is 1 for RC5 and 0 (inverted 7. command bit) for RC5X + */ + if (aCommand >= 0x40) { // Auto discovery of RC5X + // Mask bit 7 of command to set field bit to 0 (inverted 1) for RC5X aCommand &= 0x3F; + } else { + // Set field bit to 1 for RC5 + tIRData |= 1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS); // 1 << 12 = 0x1000 } tIRData |= aCommand; if (aEnableAutomaticToggle) { - if (sLastSendToggleValue == 0) { - sLastSendToggleValue = 1; - // set toggled bit - tIRData |= 1 << (RC5_ADDRESS_BITS + RC5_COMMAND_BITS); - } else { - sLastSendToggleValue = 0; - } + // invert toggle bit if enabled + sLastSendToggleValue ^= 1; + } + // set toggled bit independent of current state of aEnableAutomaticToggle + if (sLastSendToggleValue) { + tIRData |= 1 << (RC5_ADDRESS_BITS + RC5_COMMAND_BITS); } uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; @@ -140,17 +270,96 @@ void IRsend::sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRe } } +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) || defined(DECODE_RC6) +void IRrecv::initBiphaselevel(uint_fast8_t aRCDecodeRawbuffOffset, uint16_t aBiphaseTimeUnit) { + irparams.RawbuffOffsetForNextBiphaseLevel = aRCDecodeRawbuffOffset; + irparams.BiphaseTimeUnit = aBiphaseTimeUnit; + irparams.AlreadyUsedTimingIntervalsOfCurrentInterval = 0; +} + +/* + * Margin is 1/2 of unit. + */ +uint8_t IRrecv::getNumberOfUnitsInInterval(uint16_t aCurrentInterval, uint16_t aTimeUnit) { + return (aCurrentInterval + (aTimeUnit / 2)) / aTimeUnit; +} + +/** + * Gets the level of one time interval (aBiphaseTimeUnit) at a time from the raw buffer. + * The RC5/6 decoding is easier if the data is broken into time intervals. + * E.g. if the buffer has mark for 2 time intervals and space for 1, + * successive calls to getBiphaselevel will return 1, 1, 0. + * + * _ _ _ _ _ _ _ _ _ _ _ _ _ + * _____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | + * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Significant clock edge /sample point for bit value + * | | | | | | | | | | | | | | Bit period + * _ _ _ ___ _ ___ ___ _ - Mark + * Data _____| |___| |_| |_| |_| |___| |___| |_| | - Data starts with a mark->space bit + * 1 0 0 0 1 1 0 1 0 1 1 - Space + * + * Returns current level [MARK or SPACE] or NO_MARK_OR_SPACE for error (measured time interval is not a multiple of BiphaseTimeUnit). + */ +uint_fast8_t IRrecv::getBiphaselevel() { + uint_fast8_t tLevelOfCurrentInterval; // Return value: 0 (SPACE) or 1 (MARK) + + if (irparams.RawbuffOffsetForNextBiphaseLevel >= decodedIRData.rawlen) { + return SPACE; // After end of recorded buffer, assume space. + } + + tLevelOfCurrentInterval = (irparams.RawbuffOffsetForNextBiphaseLevel) & 1; // on odd rawbuf offsets we have mark timings + + /* + * Refill NumberOfTimingIntervalsInCurrentInterval if AlreadyUsedTimingIntervalsOfCurrentInterval is 0 + * i.e. we went to next rawbuf interval + */ + if (irparams.AlreadyUsedTimingIntervalsOfCurrentInterval == 0) { + uint16_t tCurrentIntervalWithMicros = irparams.rawbuf[irparams.RawbuffOffsetForNextBiphaseLevel] * MICROS_PER_TICK; + uint16_t tMarkExcessCorrectionMicros = (tLevelOfCurrentInterval == MARK) ? MARK_EXCESS_MICROS : -MARK_EXCESS_MICROS; + irparams.NumberOfTimingIntervalsInCurrentInterval = getNumberOfUnitsInInterval( + tCurrentIntervalWithMicros + tMarkExcessCorrectionMicros, irparams.BiphaseTimeUnit); + // 666 is 3/4 of RC5 time unit + TRACE_PRINT(tLevelOfCurrentInterval); + TRACE_PRINT(F("=")); + TRACE_PRINT(tCurrentIntervalWithMicros + tMarkExcessCorrectionMicros); + TRACE_PRINT(F(" ")); + TRACE_PRINTLN(irparams.NumberOfTimingIntervalsInCurrentInterval); + } + if (irparams.NumberOfTimingIntervalsInCurrentInterval == 0) { + return NO_MARK_OR_SPACE; + } + +// We use another interval from tCurrentTimingIntervals + irparams.AlreadyUsedTimingIntervalsOfCurrentInterval++; + + if (irparams.AlreadyUsedTimingIntervalsOfCurrentInterval >= irparams.NumberOfTimingIntervalsInCurrentInterval) { + /* + * We have used all intervals of current interval (mark or space duration in rawbuf), go to next rawbuf interval + */ + irparams.AlreadyUsedTimingIntervalsOfCurrentInterval = 0; + irparams.RawbuffOffsetForNextBiphaseLevel++; + } + + + return tLevelOfCurrentInterval; +} +# endif // defined(DECODE_RC5) || defined(DECODE_MARANTZ) || defined(DECODE_RC6) + +#if defined(DECODE_RC5) || defined(DECODE_MARANTZ) /** * Try to decode data as RC5 protocol + * mark->space => 0 - Inverse of RC6! + * space->mark => 1 * _ _ _ _ _ _ _ _ _ _ _ _ _ * Clock _____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | - * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ End of each data bit period - * _ _ - Mark - * 2 Start bits for RC5 _____| |_| ... - Data starts with a space->mark bit - * - Space - * _ - * 1 Start bit for RC5X _____| ... - * + * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Significant clock edge /sample point for bit value + * | | | | | | | | | | | | | Bit period + * _ _ + * 2 Start bits for RC5 _____| |_| ..|...|.. + * S S T Address + * ___ + * 1 Start bit for RC5X _____| |_..|...|.. + * S 0 T Address */ bool IRrecv::decodeRC5() { uint8_t tBitIndex; @@ -159,27 +368,44 @@ bool IRrecv::decodeRC5() { // Set Biphase decoding start values initBiphaselevel(1, RC5_UNIT); // Skip gap space - // Check we have the right amount of data (11 to 26). The +2 is for initial gap and start bit mark. - if (decodedIRData.rawDataPtr->rawlen < ((RC5_BITS + 1) / 2) + 2 && (RC5_BITS + 2) < decodedIRData.rawDataPtr->rawlen) { + // Check we have the right amount of data (14 to 26). The +1 is for initial gap. +2 for initial gap and mark of last bit which is a 1 + if (decodedIRData.rawlen < (RC5_BITS + 1) /* 14 */ || +#if defined(DECODE_MARANTZ) + ((MARANTZ_BITS * 2) + 2) /* 40, the pause is just extended */ < decodedIRData.rawlen +#else + ((RC5_BITS * 2) + 2) /* 28 */ < decodedIRData.rawlen +#endif + ) { // no debug output, since this check is mainly to determine the received protocol - IR_DEBUG_PRINT(F("RC5: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not between 9 and 15")); + DEBUG_PRINT(F("RC5: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); +#if defined(DECODE_MARANTZ) + DEBUG_PRINTLN(F(" is not between 14 and 40")); +#else + DEBUG_PRINTLN(F(" is not between 14 and 28")); +#endif + return false; + } + + // Check length of first mark / header + if (irparams.rawbuf[1] > (((2 * RC5_UNIT) + (RC5_UNIT / 2)) / MICROS_PER_TICK)) { + DEBUG_PRINTLN(F("RC5: first MARK is too long")); return false; } -// Check start bit, the first space is included in the gap + // Check start bit, the first space is included in the gap if (getBiphaselevel() != MARK) { - IR_DEBUG_PRINT(F("RC5: ")); - IR_DEBUG_PRINTLN(F("first getBiphaselevel() is not MARK")); + DEBUG_PRINTLN(F("RC5: first getBiphaselevel() is not MARK")); return false; } /* * Get data bits - MSB first */ - for (tBitIndex = 0; sBiphaseDecodeRawbuffOffset < decodedIRData.rawDataPtr->rawlen; tBitIndex++) { +#if defined(DECODE_MARANTZ) + bool RC5Marantz = false; +#endif + for (tBitIndex = 0; irparams.RawbuffOffsetForNextBiphaseLevel < decodedIRData.rawlen; tBitIndex++) { // get next 2 levels and check for transition uint8_t tStartLevel = getBiphaselevel(); uint8_t tEndLevel = getBiphaselevel(); @@ -190,26 +416,72 @@ bool IRrecv::decodeRC5() { } else if ((tStartLevel == MARK) && (tEndLevel == SPACE)) { // we have a mark to space transition here tDecodedRawData = (tDecodedRawData << 1) | 0; - } else { -#if defined(LOCAL_DEBUG) - Serial.print(F("RC5: ")); - Serial.println(F("no transition found, decode failed")); +#if defined(DECODE_MARANTZ) + } else if (tBitIndex == MARANTZ_PAUSE_BIT_INDEX) { + /* + * Check for RC5 Marantz format i.e. long space after 8 bits (including start bit) + * Check if timing buffer contains a pause, which is longer than 3/4 the expected pause + * Some dumb compiler throw a warning: comparison is always false due to limited range of data type [-Wtype-limits] which is nonsense + */ + if (irparams.rawbuf[irparams.RawbuffOffsetForNextBiphaseLevel] > ((MARANTZ_PAUSE_DURATION * 3L) / (MICROS_PER_TICK * 4L))) { // 3556 * 3 / 200 = 53 + RC5Marantz = true; + DEBUG_PRINTLN(F("Marantz detected")); + /* + * Here we are at the space interval and have 4 cases: + * With 0 -> mark+space and 1 -> space+mark and pause = 4*space we get the following space length + * 0 | pause | 0 -> 5*space + * 0 | pause | 1 -> 6*space + * 1 | pause | 0 -> 4*space + * 1 | pause | 1 -> 5*space + */ + irparams.AlreadyUsedTimingIntervalsOfCurrentInterval += 2; // We already consumed 2 to get here + if (irparams.AlreadyUsedTimingIntervalsOfCurrentInterval >= irparams.NumberOfTimingIntervalsInCurrentInterval){ + irparams.RawbuffOffsetForNextBiphaseLevel++; + } + } #endif + } else { + DEBUG_PRINT(F("RC5: no transition found, decode failed, BitIndex=")); + DEBUG_PRINTLN(tBitIndex); return false; } } // Success - decodedIRData.numberOfBits = tBitIndex; // must be RC5_BITS LongUnion tValue; tValue.ULong = tDecodedRawData; decodedIRData.decodedRawData = tDecodedRawData; + +#if defined(DECODE_MARANTZ) + if (RC5Marantz) { + decodedIRData.numberOfBits = tBitIndex - 1; // Above we count space handling as bit + + decodedIRData.extra = tValue.UWord.LowWord & 0x3F; + decodedIRData.command = (tValue.UWord.LowWord >> MARANTZ_COMMAND_EXTENSION_BITS) & 0x3F; + decodedIRData.address = (tValue.ULong >> (RC5_COMMAND_BITS + MARANTZ_COMMAND_EXTENSION_BITS)) & 0x1F; + + // Get the inverted 7. command bit to decide if we have RC5X. For RC5, the inverted value is always 1 and serves as a second start bit. + if ((tValue.ULong & (1L << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS + MARANTZ_COMMAND_EXTENSION_BITS))) == 0) { + // Here we have detected RC5X! + decodedIRData.command += 0x40; + } + + decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST | IRDATA_FLAGS_EXTRA_INFO; + if (tValue.ULong & (1L << (RC5_ADDRESS_BITS + RC5_COMMAND_BITS + MARANTZ_COMMAND_EXTENSION_BITS))) { + decodedIRData.flags |= IRDATA_FLAGS_TOGGLE_BIT; + } + decodedIRData.protocol = MARANTZ; + } else { +#endif + decodedIRData.numberOfBits = tBitIndex; // must be RC5_BITS + decodedIRData.command = tValue.UByte.LowByte & 0x3F; decodedIRData.address = (tValue.UWord.LowWord >> RC5_COMMAND_BITS) & 0x1F; - // Get the inverted 7. command bit for RC5X, the inverted value is always 1 for RC5 and serves as a second start bit. + // Get the inverted 7. command bit to decide if we have RC5X. For RC5, the inverted value is always 1 and serves as a second start bit. if ((tValue.UWord.LowWord & (1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS))) == 0) { + // Here we have detected RC5X! decodedIRData.command += 0x40; } @@ -219,11 +491,15 @@ bool IRrecv::decodeRC5() { } decodedIRData.protocol = RC5; +#if defined(DECODE_MARANTZ) + } +#endif // check for repeat checkForRepeatSpaceTicksAndSetFlag(RC5_MAXIMUM_REPEAT_DISTANCE / MICROS_PER_TICK); return true; } +#endif // defined(DECODE_RC5) || defined(DECODE_MARANTZ) //+============================================================================= // RRRR CCCC 6666 @@ -234,19 +510,56 @@ bool IRrecv::decodeRC5() { //+============================================================================= // /* - Protocol=RC6 Address=0xF1 Command=0x76 Raw-Data=0xF176 20 bits MSB first - +2650,- 850 - + 500,- 850 + 500,- 400 + 450,- 450 + 450,- 850 - +1400,- 400 + 450,- 450 + 450,- 450 + 450,- 900 - + 450,- 450 + 450,- 400 + 950,- 850 + 900,- 450 - + 450,- 450 + 450,- 850 + 950,- 400 + 450,- 900 - + 450 - Sum: 23150 + Protocol=RC6 Address=0xF1, Command=0x76, Raw-Data=0xF176, 20 bits, MSB first + +2700,- 850 + + 550,- 800 + 550,- 350 + 550,- 350 + 550,- 800 + +1400,- 400 + 550,- 400 + 550,- 350 + 550,- 800 + + 550,- 350 + 500,- 450 +1000,- 750 +1000,- 450 + + 500,- 400 + 500,- 850 + 950,- 450 + 550,- 750 + + 550 + Duration=23600us + + Protocol=RC6A Address=0xF1, Command=0x76, Extra=0x2711, Toggle=1, Raw-Data=0xA711F176, 35 bits, MSB first + +2700,- 850 + + 500,- 400 + 500,- 400 + 500,- 850 +1450,-1300 + +1000,- 850 + 550,- 350 +1000,- 400 + 550,- 350 + + 500,- 850 + 500,- 450 + 500,- 400 + 950,- 900 + + 500,- 400 + 550,- 350 +1000,- 400 + 500,- 400 + + 550,- 400 + 500,- 400 + 500,- 850 + 550,- 350 + + 550,- 400 +1000,- 800 +1000,- 400 + 500,- 400 + + 500,- 900 +1000,- 350 + 550,- 850 + 500 + Duration=37450us + + RC6 minimal length + Protocol=RC6 Address=0x55, Command=0x55, Toggle=1, Raw-Data=0x15555, 20 bits, MSB first + rawIRTimings[26]: + -397700 + +2700,- 800 + + 550,- 850 + 450,- 450 + 500,- 400 +1400,-1300 + + 950,- 850 + 900,- 900 +1000,- 850 + 950,- 850 + +1000,- 850 + 950,- 850 + 900,- 900 +1000 + Duration=23100us + + RC6A maximal length + Protocol=RC6A Address=0xFF, Command=0xFF, Extra=0x3FFF, Raw-Data=0x7FFFFFFF, 35 bits, MSB first + rawIRTimings[72]: + -399750 + +2700,- 850 + + 500,- 400 + 550,- 400 + 400,- 900 + 500,- 850 + +1450,- 400 + 500,- 400 + 550,- 400 + 400,- 500 + + 500,- 400 + 550,- 350 + 550,- 400 + 400,- 500 + + 450,- 450 + 500,- 400 + 500,- 400 + 550,- 400 + + 400,- 500 + 450,- 450 + 550,- 350 + 500,- 450 + + 400,- 500 + 450,- 450 + 550,- 350 + 500,- 450 + + 400,- 500 + 450,- 450 + 550,- 350 + 550,- 400 + + 400,- 500 + 450,- 450 + 550,- 350 + 550,- 400 + + 450,- 450 + 450,- 450 + 450 + Duration=36800us */ -// Frame RC6: 1 start bit + 1 Bit "1" + 3 mode bits (000) + 1 toggle bit + 8 address + 8 command bits + 2666us pause -// Frame RC6A: 1 start bit + 1 Bit "1" + 3 mode bits (110) + 1 toggle bit + "1" + 14 customer bits + 8 system bits + 8 command bits (=31bits) + 2666us pause -// !!! toggle bit has another timing :-( !!! -// mark->space => 1 +// Frame RC6: 1 start bit + 1 Bit "1" + 3 mode bits (000) + 1 toggle bit + 8 address + 8 command bits + 2666us pause - 22 bits incl. start bit and constant bit 1 +// Frame RC6A: 1 start bit + 1 Bit "1" + 3 mode bits (110) + 1 toggle bit + "1" + 14 customer bits + 8 system bits + 8 command bits + 2666us pause - 37 bits incl. start bit +// !!! toggle bit has double timing !!! +// mark->space => 1 - Inverse of RC5! // space->mark => 0 // https://www.sbprojects.net/knowledge/ir/rc6.php // https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A @@ -255,14 +568,19 @@ bool IRrecv::decodeRC5() { #define RC6_RPT_LENGTH 46000 -#define RC6_LEADING_BIT 1 -#define RC6_MODE_BITS 3 // never seen others than all 0 for Philips TV -#define RC6_TOGGLE_BIT 1 // toggles at every key press. Can be used to distinguish repeats from 2 key presses and has another timing :-(. +#define RC6_LEADING_BIT_ONE 1 +#define RC6_MODE_BITS 3 // Never seen others than all 0 for Philips TV :-) +#define RC6_TOGGLE_BIT 1 // Toggles at every key press. Can be used to distinguish repeats from 2 key presses and has another timing :-(. #define RC6_TOGGLE_BIT_INDEX RC6_MODE_BITS // fourth position, index = 3 #define RC6_ADDRESS_BITS 8 #define RC6_COMMAND_BITS 8 +#define RC6A_CUSTOMER_BIT_ONE 1 +#define RC6A_CUSTOMER_BITS 14 -#define RC6_BITS (RC6_LEADING_BIT + RC6_MODE_BITS + RC6_TOGGLE_BIT + RC6_ADDRESS_BITS + RC6_COMMAND_BITS) // 21 +#define RC6_BITS (RC6_LEADING_BIT_ONE + RC6_MODE_BITS + RC6_TOGGLE_BIT + RC6_ADDRESS_BITS + RC6_COMMAND_BITS) // 21 +#define RC6A_BITS (RC6_LEADING_BIT_ONE + RC6_MODE_BITS + RC6_TOGGLE_BIT + RC6A_CUSTOMER_BIT_ONE + RC6A_CUSTOMER_BITS + RC6_ADDRESS_BITS + RC6_COMMAND_BITS) // 36 +#define RC6A_FIXED_BITS (RC6_LEADING_BIT_ONE + RC6_MODE_BITS) // 4 +#define RC6A_VARIABLE_BITS (RC6_TOGGLE_BIT + RC6A_CUSTOMER_BIT_ONE + RC6A_CUSTOMER_BITS + RC6_ADDRESS_BITS + RC6_COMMAND_BITS) // Without fixed protocol specific bits 33 #define RC6_UNIT 444 // 16 periods of 36 kHz (444.4444) @@ -270,7 +588,7 @@ bool IRrecv::decodeRC5() { #define RC6_HEADER_SPACE (2 * RC6_UNIT) // 889 #define RC6_TRAILING_SPACE (6 * RC6_UNIT) // 2666 -#define MIN_RC6_MARKS 4 + ((RC6_ADDRESS_BITS + RC6_COMMAND_BITS) / 2) // 12, 4 are for preamble +#define MIN_RC6_MARKS (4 + ((RC6_ADDRESS_BITS + RC6_COMMAND_BITS) / 2)) // 12, 4 are for preamble #define RC6_REPEAT_DISTANCE 107000 // just a guess but > 2.666ms #define RC6_MAXIMUM_REPEAT_DISTANCE (RC6_REPEAT_DISTANCE + (RC6_REPEAT_DISTANCE / 4)) // Just a guess @@ -278,7 +596,7 @@ bool IRrecv::decodeRC5() { /** * Main RC6 send function */ -void IRsend::sendRC6(uint32_t aRawData, uint8_t aNumberOfBitsToSend) { +void IRsend::sendRC6(uint32_t aRawData, uint8_t aNumberOfBitsToSend) { // Deprecated sendRC6Raw(aRawData, aNumberOfBitsToSend); } void IRsend::sendRC6Raw(uint32_t aRawData, uint8_t aNumberOfBitsToSend) { @@ -312,7 +630,7 @@ void IRsend::sendRC6Raw(uint32_t aRawData, uint8_t aNumberOfBitsToSend) { * Send RC6 64 bit raw data * Can be used to send RC6A with ?31? data bits */ -void IRsend::sendRC6(uint64_t aRawData, uint8_t aNumberOfBitsToSend) { +void IRsend::sendRC6(uint64_t aRawData, uint8_t aNumberOfBitsToSend) { // Deprecated sendRC6Raw(aRawData, aNumberOfBitsToSend); } void IRsend::sendRC6Raw(uint64_t aRawData, uint8_t aNumberOfBitsToSend) { @@ -323,15 +641,15 @@ void IRsend::sendRC6Raw(uint64_t aRawData, uint8_t aNumberOfBitsToSend) { mark(RC6_HEADER_MARK); space(RC6_HEADER_SPACE); -// Start bit +// Leading bit 1 mark(RC6_UNIT); space(RC6_UNIT); // Data MSB first uint64_t mask = 1ULL << (aNumberOfBitsToSend - 1); - for (uint_fast8_t i = 1; mask; i++, mask >>= 1) { + for (uint_fast8_t i = 0; mask; i++, mask >>= 1) { // The fourth bit we send is the "double width toggle bit" - unsigned int t = (i == (RC6_TOGGLE_BIT_INDEX + 1)) ? (RC6_UNIT * 2) : (RC6_UNIT); + unsigned int t = (i == RC6_TOGGLE_BIT_INDEX) ? (RC6_UNIT * 2) : (RC6_UNIT); if (aRawData & mask) { mark(t); space(t); @@ -353,25 +671,21 @@ void IRsend::sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRe tIRRawData.UByte.LowByte = aCommand; tIRRawData.UByte.MidLowByte = aAddress; - tIRRawData.UWord.HighWord = 0; // must clear high word + tIRRawData.UWord.HighWord = 0; // must clear high word for the 3 mode bits to be 0 + if (aEnableAutomaticToggle) { - if (sLastSendToggleValue == 0) { - sLastSendToggleValue = 1; - // set toggled bit - IR_DEBUG_PRINT(F("Set Toggle ")); - tIRRawData.UByte.MidHighByte = 1; // 3 Mode bits are 0 - } else { - sLastSendToggleValue = 0; - } + // invert toggle bit if enabled + sLastSendToggleValue ^= 1; + } + // set toggled bit independent of current state of aEnableAutomaticToggle + if (sLastSendToggleValue) { + tIRRawData.UByte.MidHighByte = 1; // 3 Mode bits are 0 } -#if defined(LOCAL_DEBUG) - Serial.print(F("RC6: ")); - Serial.print(F("sLastSendToggleValue=")); - Serial.print (sLastSendToggleValue); - Serial.print(F(" RawData=")); - Serial.println(tIRRawData.ULong, HEX); -#endif + DEBUG_PRINT(F("RC6: ToggleValue=")); + DEBUG_PRINT(sLastSendToggleValue); + DEBUG_PRINT(F(" RawData=")); + DEBUG_PRINTLN(tIRRawData.ULong, HEX); uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; while (tNumberOfCommands > 0) { @@ -388,70 +702,124 @@ void IRsend::sendRC6(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRe } } +/** + * Assemble raw data for RC6 from parameters and toggle state and send + * We do not wait for the minimal trailing space of 2666 us + * @param aEnableAutomaticToggle Send toggle bit according to the state of the static sLastSendToggleValue variable. + */ +void IRsend::sendRC6A(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint16_t aCustomer, + bool aEnableAutomaticToggle) { + + LongUnion tIRRawData; + tIRRawData.UByte.LowByte = aCommand; + tIRRawData.UByte.MidLowByte = aAddress; + + tIRRawData.UWord.HighWord = aCustomer | 0x4000; // bit 31 is always 1 + + if (aEnableAutomaticToggle) { + // invert toggle bit if enabled + sLastSendToggleValue ^= 1; + } + // set toggled bit independent of current state of aEnableAutomaticToggle + if (sLastSendToggleValue) { + tIRRawData.UByte.HighByte |= 0x80; // toggle bit is bit 32 + } + + // Set mode bits + uint64_t tRawData = tIRRawData.ULong + 0x0600000000; + + DEBUG_PRINT(F("RC6A: ToggleValue=")); + DEBUG_PRINT(sLastSendToggleValue); + DEBUG_PRINT(F(" RawData=")); + DEBUG_PRINTLN(tIRRawData.ULong, HEX); + + uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; + while (tNumberOfCommands > 0) { + + // start and leading bits are sent by sendRC6 + sendRC6Raw(tRawData, RC6A_BITS - 1); // -1 since the leading bit 1 is sent by sendRC6Raw() + + tNumberOfCommands--; + // skip last delay! + if (tNumberOfCommands > 0) { + // send repeated command in a fixed raster + delay(RC6_REPEAT_DISTANCE / MICROS_IN_ONE_MILLI); + } + } +} + +#if defined(DECODE_RC6) /** * Try to decode data as RC6 protocol + * Unit is 444 us and half of RC5 unit 888 + * mark->space => 1 - Inverse of RC5! + * space->mark => 0 + * _ _ _ _ _ _ _ _ _ _ _ _ _ + * Clock _____| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | 444 us high and low + * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Significant clock edge /sample point for bit value + * | | | | | | | | | Bit period + * ______ _ _ _ _ + * Start bit for RC6 _____| |__| |___| |_| |_| ......|.......|.. + * Start 1 0 0 0 ^double timing toggle bit + 8 bit address + 8 bit command + * ______ _ _ _ _ _ + * Start bit for RC6A _____| |__| |_| |_| |___| ......|...... |_.. + * Start 1 1 1 0 ^ 1 + 14 bit extra + 8 bit address + 8 bit command + * ^ toggle bit ^ + * Fixed 1 for RC6 Fixed 1 for RC6A */ bool IRrecv::decodeRC6() { uint8_t tBitIndex; uint32_t tDecodedRawData = 0; - // Check we have the right amount of data (). The +3 for initial gap, start bit mark and space - if (decodedIRData.rawDataPtr->rawlen < MIN_RC6_MARKS + 3 && (RC6_BITS + 3) < decodedIRData.rawDataPtr->rawlen) { - IR_DEBUG_PRINT(F("RC6: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not between 15 and 25")); + // Check we have the right amount of data (). The +3 for initial gap, start bit mark and space. +6 for timing of fixed 1 and mode + if (decodedIRData.rawlen < 26 || 72 < decodedIRData.rawlen) { + DEBUG_PRINT(F("RC6: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not between 26 and 72")); return false; } // Check header "mark" and "space", this must be done for repeat and data - if (!matchMark(decodedIRData.rawDataPtr->rawbuf[1], RC6_HEADER_MARK) - || !matchSpace(decodedIRData.rawDataPtr->rawbuf[2], RC6_HEADER_SPACE)) { + if (!matchMark(irparams.rawbuf[1], RC6_HEADER_MARK) || !matchSpace(irparams.rawbuf[2], RC6_HEADER_SPACE)) { // no debug output, since this check is mainly to determine the received protocol - IR_DEBUG_PRINT(F("RC6: ")); - IR_DEBUG_PRINTLN(F("Header mark or space length is wrong")); + DEBUG_PRINTLN(F("RC6: Header mark or space length is wrong")); return false; } // Set Biphase decoding start values - initBiphaselevel(3, RC6_UNIT); // Skip gap-space and start-bit mark + space + initBiphaselevel(3, RC6_UNIT); // Skip gap-space and start-bit mark and space -// Process first bit, which is known to be a 1 (mark->space) + /* + * Check first bit, which is known to be a 1 (mark->space) + */ if (getBiphaselevel() != MARK) { - IR_DEBUG_PRINT(F("RC6: ")); - IR_DEBUG_PRINTLN(F("first getBiphaselevel() is not MARK")); + DEBUG_PRINTLN(F("RC6: first getBiphaselevel() is not MARK")); return false; } if (getBiphaselevel() != SPACE) { - IR_DEBUG_PRINT(F("RC6: ")); - IR_DEBUG_PRINTLN(F("second getBiphaselevel() is not SPACE")); + DEBUG_PRINTLN(F("RC6: second getBiphaselevel() is not SPACE")); return false; } - for (tBitIndex = 0; sBiphaseDecodeRawbuffOffset < decodedIRData.rawDataPtr->rawlen; tBitIndex++) { + // Now start decoding at bit 2 / mode bits + for (tBitIndex = 0; irparams.RawbuffOffsetForNextBiphaseLevel < decodedIRData.rawlen; tBitIndex++) { uint8_t tStartLevel; // start level of coded bit uint8_t tEndLevel; // end level of coded bit tStartLevel = getBiphaselevel(); + tEndLevel = getBiphaselevel(); + if (tBitIndex == RC6_TOGGLE_BIT_INDEX) { - // Toggle bit is double wide; make sure second half is equal first half - if (tStartLevel != getBiphaselevel()) { -#if defined(LOCAL_DEBUG) - Serial.print(F("RC6: ")); - Serial.println(F("Toggle mark or space length is wrong")); -#endif + /* + * Toggle bit is double wide; level of 1. and 2. time slot and 3. and 4.time slot must be equal + */ + if (tStartLevel != tEndLevel) { // 1. and 2. time slot must be equal + DEBUG_PRINTLN(F("RC6: Toggle mark or space length is wrong")); return false; } - } - - tEndLevel = getBiphaselevel(); - if (tBitIndex == RC6_TOGGLE_BIT_INDEX) { - // Toggle bit is double wide; make sure second half matches - if (tEndLevel != getBiphaselevel()) { -#if defined(LOCAL_DEBUG) - Serial.print(F("RC6: ")); - Serial.println(F("Toggle mark or space length is wrong")); -#endif + tEndLevel = getBiphaselevel(); + if (tEndLevel != getBiphaselevel()) { // 3. and 4. time slot must be equal + DEBUG_PRINTLN(F("RC6: Toggle mark or space length is wrong")); return false; } } @@ -460,16 +828,13 @@ bool IRrecv::decodeRC6() { * Determine tDecodedRawData bit value by checking the transition type */ if ((tStartLevel == MARK) && (tEndLevel == SPACE)) { - // we have a mark to space transition here - tDecodedRawData = (tDecodedRawData << 1) | 1; // inverted compared to RC5 + // we have a mark to space transition here -> 1 + tDecodedRawData = (tDecodedRawData << 1) | 1; // inverted value compared to RC5 } else if ((tStartLevel == SPACE) && (tEndLevel == MARK)) { - // we have a space to mark transition here - tDecodedRawData = (tDecodedRawData << 1) | 0; + // we have a space to mark transition here -> 0 + tDecodedRawData = (tDecodedRawData << 1); } else { -#if defined(LOCAL_DEBUG) - Serial.print(F("RC6: ")); - Serial.println(F("Decode failed")); -#endif + DEBUG_PRINTLN(F("RC6: Decode failed")); // we have no transition here or one level is -1 -> error return false; // Error } @@ -482,7 +847,7 @@ bool IRrecv::decodeRC6() { tValue.ULong = tDecodedRawData; decodedIRData.decodedRawData = tDecodedRawData; - if (tBitIndex < 36) { + if (tBitIndex < 35) { // RC6 8 address bits, 8 command bits decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; decodedIRData.command = tValue.UByte.LowByte; @@ -494,23 +859,26 @@ bool IRrecv::decodeRC6() { if (tBitIndex > 20) { decodedIRData.flags |= IRDATA_FLAGS_EXTRA_INFO; } + decodedIRData.protocol = RC6; + } else { - // RC6A - 32 bits - decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST; - if ((tValue.UByte.MidLowByte & 0x80) != 0) { - decodedIRData.flags = IRDATA_FLAGS_TOGGLE_BIT | IRDATA_FLAGS_IS_MSB_FIRST; - } - tValue.UByte.MidLowByte &= 0x87F; // mask toggle bit + // RC6A + decodedIRData.flags = IRDATA_FLAGS_IS_MSB_FIRST | IRDATA_FLAGS_EXTRA_INFO; decodedIRData.command = tValue.UByte.LowByte; decodedIRData.address = tValue.UByte.MidLowByte; + decodedIRData.extra = tValue.UWord.HighWord & 0x3FFF; // Mask to 14 bits, remove toggle and constant 1 + if ((tValue.UByte.HighByte & 0x80) != 0) { + decodedIRData.flags |= IRDATA_FLAGS_TOGGLE_BIT; + } + decodedIRData.protocol = RC6A; } // check for repeat, do not check toggle bit yet checkForRepeatSpaceTicksAndSetFlag(RC6_MAXIMUM_REPEAT_DISTANCE / MICROS_PER_TICK); - decodedIRData.protocol = RC6; return true; } +#endif // #if defined(DECODE_RC6) /********************************************************************************* * Old deprecated functions, kept for backward compatibility to old 2.0 tutorials @@ -541,7 +909,7 @@ void IRsend::sendRC5(uint32_t data, uint8_t nbits) { } /* - * Not longer required, use sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) instead + * Deprecated, use sendRC5(uint8_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, bool aEnableAutomaticToggle) instead */ void IRsend::sendRC5ext(uint8_t addr, uint8_t cmd, bool toggle) { // Set IR carrier frequency @@ -569,6 +937,7 @@ void IRsend::sendRC5ext(uint8_t addr, uint8_t cmd, bool toggle) { // Toggle bit static int toggleBit = 1; if (toggle) { + // invert static toggle bit if (toggleBit == 0) { toggleBit = 1; } else { @@ -607,7 +976,6 @@ void IRsend::sendRC5ext(uint8_t addr, uint8_t cmd, bool toggle) { } /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_RC5_RC6_HPP diff --git a/src/ir_Samsung.hpp b/src/ir_Samsung.hpp index c61590633..d9a1b9186 100644 --- a/src/ir_Samsung.hpp +++ b/src/ir_Samsung.hpp @@ -8,7 +8,7 @@ ************************************************************************************ * MIT License * - * Copyright (c) 2017-2023 Darryl Smith, Armin Joachimsmeyer + * Copyright (c) 2017-2026 Darryl Smith, 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 @@ -32,11 +32,7 @@ #ifndef _IR_SAMSUNG_HPP #define _IR_SAMSUNG_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -61,9 +57,10 @@ + 600,- 550 + 600,- 550 + 550,- 550 + 600,-1650 + 550 Sum: 68750 + * Values are like NEC except SAMSUNG_HEADER_MARK (4500 instead of 9000) */ /* - * Samsung repeat frame can be the original frame again or a special repeat frame, + * Samsung repeat frame can be the original frame again or a special short repeat frame, * then we call the protocol SamsungLG. They differ only in the handling of repeat, * so we can not decide for the first frame which protocol is used. */ @@ -72,6 +69,12 @@ // https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG48 // LSB first, 1 start bit + 16 bit address + 16 or 32 bit data + 1 stop bit. // Here https://forum.arduino.cc/t/klimaanlage-per-ir-steuern/1051381/10 the address (0xB24D) is also 8 bits and then 8 inverted bits +// +// Here https://github.com/flipperdevices/flipperzero-firmware/blob/master/lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c#L18 +// Address is 8 bit + same 8 bit if command is 8 bit and ~8 bit. +// +// So we assume 8 bit address, if command is 8 bit and ~8 bit! +// // IRP notation: {38k,5553}<1,-1|1,-3>(8,-8,D:8,S:8,F:8,~F:8,1,^110)+ ==> 8 bit + 8 bit inverted data - Samsung32 // IRP notation: {38k,5553}<1,-1|1,-3>(8,-8,D:8,S:8,F:16,1,^110)+ ==> 16 bit data - still Samsung32 // IRP notation: {38k,5553}<1,-1|1,-3>(8,-8,D:8,S:8,F:8,~F:8,G:8,~G:8,1,^110)+ ==> 2 x (8 bit + 8 bit inverted data) - Samsung48 @@ -82,24 +85,27 @@ #define SAMSUNG_BITS (SAMSUNG_ADDRESS_BITS + SAMSUNG_COMMAND16_BITS) #define SAMSUNG48_BITS (SAMSUNG_ADDRESS_BITS + SAMSUNG_COMMAND32_BITS) -// except SAMSUNG_HEADER_MARK, values are like NEC +// Values are like NEC except SAMSUNG_HEADER_MARK (4500 instead of 9000) #define SAMSUNG_UNIT 560 // 21.28 periods of 38 kHz, 11.2 ticks TICKS_LOW = 8.358 TICKS_HIGH = 15.0 -#define SAMSUNG_HEADER_MARK (8 * SAMSUNG_UNIT) // 4500 | 180 +#define SAMSUNG_HEADER_MARK (8 * SAMSUNG_UNIT) // 4500 | 180 periods #define SAMSUNG_HEADER_SPACE (8 * SAMSUNG_UNIT) // 4500 #define SAMSUNG_BIT_MARK SAMSUNG_UNIT #define SAMSUNG_ONE_SPACE (3 * SAMSUNG_UNIT) // 1690 | 33.8 TICKS_LOW = 25.07 TICKS_HIGH = 45.0 #define SAMSUNG_ZERO_SPACE SAMSUNG_UNIT -#define SAMSUNG_AVERAGE_DURATION 55000 // SAMSUNG_HEADER_MARK + SAMSUNG_HEADER_SPACE + 32 * 2,5 * SAMSUNG_UNIT + SAMSUNG_UNIT // 2.5 because we assume more zeros than ones +#define SAMSUNG_AVERAGE_DURATION 55000 // Not used. SAMSUNG_HEADER_MARK + SAMSUNG_HEADER_SPACE + 32 * 2,5 * SAMSUNG_UNIT + SAMSUNG_UNIT // 2.5 because we assume more zeros than ones #define SAMSUNG_REPEAT_DURATION (SAMSUNG_HEADER_MARK + SAMSUNG_HEADER_SPACE + SAMSUNG_BIT_MARK + SAMSUNG_ZERO_SPACE + SAMSUNG_BIT_MARK) #define SAMSUNG_REPEAT_PERIOD 110000 // Commands are repeated every 110 ms (measured from start to start) for as long as the key on the remote control is held down. -#define SAMSUNG_REPEAT_DISTANCE (SAMSUNG_REPEAT_PERIOD - SAMSUNG_AVERAGE_DURATION) -#define SAMSUNG_MAXIMUM_REPEAT_DISTANCE (SAMSUNG_REPEAT_DISTANCE + (SAMSUNG_REPEAT_DISTANCE / 4)) // Just a guess +#define SAMSUNG_MAXIMUM_REPEAT_DISTANCE (SAMSUNG_REPEAT_PERIOD + (SAMSUNG_REPEAT_PERIOD / 4)) // 137000 - Just a guess -struct PulseDistanceWidthProtocolConstants SamsungProtocolConstants = { SAMSUNG, SAMSUNG_KHZ, SAMSUNG_HEADER_MARK, -SAMSUNG_HEADER_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, - (SAMSUNG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), &sendSamsungLGSpecialRepeat }; +// 19 byte RAM +struct PulseDistanceWidthProtocolConstants const SamsungProtocolConstants PROGMEM = {SAMSUNG, SAMSUNG_KHZ, SAMSUNG_HEADER_MARK, + SAMSUNG_HEADER_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, + (SAMSUNG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr}; +struct PulseDistanceWidthProtocolConstants const SamsungLGProtocolConstants PROGMEM = {SAMSUNGLG, SAMSUNG_KHZ, SAMSUNG_HEADER_MARK, + SAMSUNG_HEADER_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_DISTANCE, + (SAMSUNG_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), &sendSamsungLGSpecialRepeat}; /************************************ * Start of send and decode functions ************************************/ @@ -119,7 +125,8 @@ void IRsend::sendSamsungLGRepeat() { } /** - * Static function for sending special repeat frame. + * Like above, but implemented as a static function + * Used for sending special repeat frame. * For use in ProtocolConstants. Saves up to 250 bytes compared to a member function. */ void sendSamsungLGSpecialRepeat() { @@ -133,6 +140,7 @@ void sendSamsungLGSpecialRepeat() { /* * Sent e.g. by an LG 6711R1P071A remote + * @param aAddress 16 bit address. If < 0x100, i.e. only 8 bit, then a (standard) 16 bit address <8_bit_address><8_bit_address> is generated. * @param aNumberOfRepeats If < 0 then only a special repeat frame will be sent */ void IRsend::sendSamsungLG(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { @@ -144,35 +152,81 @@ void IRsend::sendSamsungLG(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNu // send 16 bit address and 8 command bits and then 8 inverted command bits LSB first LongUnion tRawData; tRawData.UWord.LowWord = aAddress; + if (aAddress < 0x100) { // This disables the sending of an (non standard?) 16 bit address with upper byte = 0 like 0x0014. + tRawData.UByte.MidLowByte = aAddress; // here we have 8 bit address which must be duplicated + } tRawData.UByte.MidHighByte = aCommand; tRawData.UByte.HighByte = ~aCommand; - sendPulseDistanceWidth(&SamsungProtocolConstants, tRawData.ULong, SAMSUNG_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&SamsungLGProtocolConstants, tRawData.ULong, SAMSUNG_BITS, aNumberOfRepeats); } /** * Here we send Samsung32 * If we get a command < 0x100, we send command and then ~command + * If we get an address < 0x100, we send 8 bit address and then the same 8 bit address again, this makes it flipper IRDB compatible * !!! Be aware, that this is flexible, but makes it impossible to send e.g. 0x0042 as 16 bit value!!! + * To force send 16 bit address, use: sendSamsung16BitAddressAndCommand(). * @param aNumberOfRepeats If < 0 then only a special repeat frame will be sent */ void IRsend::sendSamsung(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { - // send 16 bit address LongUnion tSendValue; - tSendValue.UWords[0] = aAddress; + if (aAddress < 0x100) { + // This makes it flipper IRDB compatible: + // https://github.com/flipperdevices/flipperzero-firmware/blob/master/lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c#L18 + // Duplicate address byte, if address is only 8 bit + tSendValue.UBytes[1] = aAddress; + tSendValue.UBytes[0] = aAddress; + } else { + tSendValue.UWords[0] = aAddress; + } + if (aCommand < 0x100) { // Send 8 command bits and then 8 inverted command bits LSB first tSendValue.UBytes[2] = aCommand; tSendValue.UBytes[3] = ~aCommand; + } else { // Send 16 command bits tSendValue.UWords[1] = aCommand; } - sendPulseDistanceWidth(&SamsungProtocolConstants, tSendValue.ULong, SAMSUNG_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&SamsungProtocolConstants, tSendValue.ULong, SAMSUNG_BITS, aNumberOfRepeats); } +/** + * Maybe no one needs it in the wild... + * As above, but we are able to send e.g. 0x0042 as 16 bit address, which is otherwise interpreted as 8 bit address + * @param aNumberOfRepeats If < 0 then only a special repeat frame will be sent + */ +void IRsend::sendSamsung16BitAddressAnd8BitCommand(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { + + LongUnion tSendValue; + // send 16 bit address + tSendValue.UWords[0] = aAddress; + // Send 8 command bits and then 8 inverted command bits LSB first + tSendValue.UBytes[2] = aCommand; + tSendValue.UBytes[3] = ~aCommand; + + sendPulseDistanceWidth_P(&SamsungProtocolConstants, tSendValue.ULong, SAMSUNG_BITS, aNumberOfRepeats); +} + +/** + * Maybe no one needs it in the wild... + * As above, but we are able to send e.g. 0x0042 as 16 bit address, which is otherwise interpreted as 8 bit address + * @param aNumberOfRepeats If < 0 then only a special repeat frame will be sent + */ +void IRsend::sendSamsung16BitAddressAndCommand(uint16_t aAddress, uint16_t aCommand, int_fast8_t aNumberOfRepeats) { + + LongUnion tSendValue; + // send 16 bit address + tSendValue.UWords[0] = aAddress; + // Send 16 command bits + tSendValue.UWords[1] = aCommand; + + sendPulseDistanceWidth_P(&SamsungProtocolConstants, tSendValue.ULong, SAMSUNG_BITS, aNumberOfRepeats); +} /** * Here we send Samsung48 * We send 2 x (8 bit command and then ~command) @@ -191,7 +245,7 @@ void IRsend::sendSamsung48(uint16_t aAddress, uint32_t aCommand, int_fast8_t aNu tRawSamsungData[1] = tUpper8BitsOfCommand | (~tUpper8BitsOfCommand) << 8; tRawSamsungData[0] = tSendValue.ULong; - sendPulseDistanceWidthFromArray(&SamsungProtocolConstants, &tRawSamsungData[0], SAMSUNG48_BITS, aNumberOfRepeats); + sendPulseDistanceWidthFromArray_P(&SamsungProtocolConstants, &tRawSamsungData[0], SAMSUNG48_BITS, aNumberOfRepeats); #else LongLongUnion tSendValue; tSendValue.UWords[0] = aAddress; @@ -204,62 +258,54 @@ void IRsend::sendSamsung48(uint16_t aAddress, uint32_t aCommand, int_fast8_t aNu } else { tSendValue.ULongLong = aAddress | aCommand << 16; } - sendPulseDistanceWidth(&SamsungProtocolConstants, tSendValue.ULongLong, SAMSUNG48_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&SamsungProtocolConstants, tSendValue.ULongLong, SAMSUNG48_BITS, aNumberOfRepeats); #endif } +/* + * We cannot decode frames with 8 command bits and then 8 inverted command bits LSB and 16 bit address, + * because in this case we always assume 8 bit address. + * This is, because we did not see 8 bit command and real 16 bit address in the wild. + */ bool IRrecv::decodeSamsung() { // Check we have enough data (68). The +4 is for initial gap, start bit mark and space + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != ((2 * SAMSUNG_BITS) + 4) - && decodedIRData.rawDataPtr->rawlen != ((2 * SAMSUNG48_BITS) + 4) && (decodedIRData.rawDataPtr->rawlen != 6)) { - IR_DEBUG_PRINT(F("Samsung: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 6 or 68 or 100")); + if (!(decodedIRData.rawlen == ((2 * SAMSUNG_BITS) + 4) || decodedIRData.rawlen == ((2 * SAMSUNG48_BITS) + 4) + || (decodedIRData.rawlen == 6))) { + DEBUG_PRINT(F("Samsung: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 6 or 68 or 100")); return false; } - if (!checkHeader(&SamsungProtocolConstants)) { + if (!checkHeader_P(&SamsungProtocolConstants)) { return false; } // Check for SansungLG style repeat - if (decodedIRData.rawDataPtr->rawlen == 6) { - decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST; + if (lastDecodedProtocol == SAMSUNGLG && decodedIRData.rawlen == 6) { + decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT | IRDATA_FLAGS_IS_PROTOCOL_WITH_DIFFERENT_REPEAT | IRDATA_FLAGS_IS_LSB_FIRST; decodedIRData.address = lastDecodedAddress; decodedIRData.command = lastDecodedCommand; - decodedIRData.protocol = SAMSUNG_LG; + decodedIRData.protocol = SAMSUNGLG; return true; } /* * Decode first 32 bits */ - if (!decodePulseDistanceWidthData(&SamsungProtocolConstants, SAMSUNG_BITS, 3)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Samsung: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&SamsungProtocolConstants, SAMSUNG_BITS, 3); LongUnion tValue; tValue.ULong = decodedIRData.decodedRawData; decodedIRData.address = tValue.UWord.LowWord; - if (decodedIRData.rawDataPtr->rawlen == (2 * SAMSUNG48_BITS) + 4) { + if (decodedIRData.rawlen == (2 * SAMSUNG48_BITS) + 4) { /* * Samsung48 */ // decode additional 16 bit - if (!decodePulseDistanceWidthData(&SamsungProtocolConstants, (SAMSUNG_COMMAND32_BITS - SAMSUNG_COMMAND16_BITS), - 3 + (2 * SAMSUNG_BITS))) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Samsung: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&SamsungProtocolConstants, (SAMSUNG_COMMAND32_BITS - SAMSUNG_COMMAND16_BITS), + 3 + (2 * SAMSUNG_BITS)); /* * LSB data is already in tValue.UWord.HighWord! @@ -287,14 +333,20 @@ bool IRrecv::decodeSamsung() { } else { /* * Samsung32 + * check if we have 8 bit command and / or 8 bit address */ if (tValue.UByte.MidHighByte == (uint8_t)(~tValue.UByte.HighByte)) { - // 8 bit command protocol + // 8 bit command decodedIRData.command = tValue.UByte.MidHighByte; // first 8 bit } else { - // 16 bit command protocol - decodedIRData.command = tValue.UWord.HighWord; // first 16 bit + // 16 bit command + decodedIRData.command = tValue.UWord.HighWord; + } + + if (tValue.UByte.MidLowByte == tValue.UByte.LowByte) { + decodedIRData.address = tValue.UByte.LowByte; // 8 bit address as seen for a LG HX906 A/V Receive E8172C2C } + decodedIRData.numberOfBits = SAMSUNG_BITS; decodedIRData.protocol = SAMSUNG; } @@ -334,12 +386,8 @@ bool IRrecv::decodeSAMSUNG(decode_results *aResults) { } offset++; - if (!decodePulseDistanceWidthData(SAMSUNG_BITS, offset, SAMSUNG_BIT_MARK, 0, SAMSUNG_ONE_SPACE, SAMSUNG_ZERO_SPACE, - PROTOCOL_IS_MSB_FIRST)) { - return false; - } + decodePulseDistanceWidthData(SAMSUNG_BITS, offset, SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, 0, PROTOCOL_IS_MSB_FIRST); - // Success aResults->value = decodedIRData.decodedRawData; aResults->bits = SAMSUNG_BITS; aResults->decode_type = SAMSUNG; @@ -348,7 +396,7 @@ bool IRrecv::decodeSAMSUNG(decode_results *aResults) { } // Old version with MSB first -void IRsend::sendSAMSUNG(unsigned long data, int nbits) { +void IRsend::sendSamsungMSB(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut (SAMSUNG_KHZ); @@ -360,9 +408,11 @@ void IRsend::sendSAMSUNG(unsigned long data, int nbits) { sendPulseDistanceWidthData(SAMSUNG_BIT_MARK, SAMSUNG_ONE_SPACE, SAMSUNG_BIT_MARK, SAMSUNG_ZERO_SPACE, data, nbits, PROTOCOL_IS_MSB_FIRST); } +void IRsend::sendSAMSUNG(unsigned long data, int nbits) { + sendSamsungMSB(data, nbits); +} /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_SAMSUNG_HPP diff --git a/src/ir_Sony.hpp b/src/ir_Sony.hpp index 591d58dcc..0d76da346 100644 --- a/src/ir_Sony.hpp +++ b/src/ir_Sony.hpp @@ -8,6 +8,8 @@ ************************************************************************************ * MIT License * + * Copyright (c) 2020-2026 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 @@ -30,11 +32,7 @@ #ifndef _IR_SONY_HPP #define _IR_SONY_HPP -#if defined(DEBUG) && !defined(LOCAL_DEBUG) -#define LOCAL_DEBUG -#else -//#define LOCAL_DEBUG // This enables debug output only for this file -#endif +#include "LocalDebugLevelStart.h" /** \addtogroup Decoder Decoders and encoders for different protocols * @{ @@ -52,7 +50,7 @@ // 7 command bits +1300,- 450 +1350,- 450 +1300,- 450 + 700,- 450 + 700,- 450 + 750,- 450 + 700,- 400 - // (5,8,) 13 address bits + // (5,8,) 13 address bits and NO stop bit! +1300,- 500 + 700,- 450 + 700,- 450 +1300,- 500 +1300,- 450 +1300,- 450 + 700,- 450 +1350,- 400 + 750,- 450 @@ -65,7 +63,7 @@ // see https://www.sbprojects.net/knowledge/ir/sirc.php // https://www.mikrocontroller.net/articles/IRMP_-_english#SIRCS // Frames are repeated every 45ms (measured from start to start) for as long as the key on the remote control is held down. -// This leads to a 15 ms gap for a Sony20 protocol! +// This leads to a 12 ms gap for a Sony20 protocol! // Here http://picprojects.org.uk/projects/sirc/ it is claimed, that many Sony remotes send each frame a minimum of 3 times. But 1 repeat (2 sends) has also been seen in real life. // LSB first, start bit + 7 command + 5 to 13 address, no stop bit // IRP: Sony12 {40k,600}<1,-1|2,-1>(4,-1,F:7,D:5,^45m)+ ==> 40 kHz, Unit is 600, LSB, One mark is 2 units, Start bit is 4 units, 7 bit Function, 5 bit Device, no Stop bit, every 45 milliseconds @@ -85,13 +83,13 @@ #define SONY_ZERO_MARK SONY_UNIT #define SONY_SPACE SONY_UNIT -#define SONY_AVERAGE_DURATION_MIN 21000 // SONY_HEADER_MARK + SONY_SPACE + 12 * 2,5 * SONY_UNIT // 2.5 because we assume more zeros than ones -#define SONY_AVERAGE_DURATION_MAX 33000 // SONY_HEADER_MARK + SONY_SPACE + 20 * 2,5 * SONY_UNIT // 2.5 because we assume more zeros than ones -#define SONY_REPEAT_PERIOD 45000 // Commands are repeated every 45 ms (measured from start to start) for as long as the key on the remote control is held down. -#define SONY_MAXIMUM_REPEAT_DISTANCE (SONY_REPEAT_PERIOD - SONY_AVERAGE_DURATION_MIN) // 24 ms +#define SONY_DURATION_MIN 17400 // SONY_HEADER_MARK + SONY_SPACE + 12 * 2 * SONY_UNIT = 29 * SONY_UNIT +#define SONY_DURATION_MAX 37200 // SONY_HEADER_MARK + SONY_SPACE + 20 * 3 * SONY_UNIT = 65 * SONY_UNIT +#define SONY_REPEAT_PERIOD 45000 // Commands are repeated every 45 ms (measured from start to start) for as long as the key on the remote control is held down. +#define SONY_MAXIMUM_REPEAT_DISTANCE (SONY_REPEAT_PERIOD - SONY_DURATION_MIN) // 27,6 ms -struct PulseDistanceWidthProtocolConstants SonyProtocolConstants = { SONY, SONY_KHZ, SONY_HEADER_MARK, SONY_SPACE, SONY_ONE_MARK, -SONY_SPACE, SONY_ZERO_MARK, SONY_SPACE, PROTOCOL_IS_LSB_FIRST, (SONY_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const SonyProtocolConstants PROGMEM = { SONY, SONY_KHZ, SONY_HEADER_MARK, SONY_SPACE, SONY_ONE_MARK, +SONY_SPACE, SONY_ZERO_MARK, SONY_SPACE, PROTOCOL_IS_LSB_FIRST | PROTOCOL_IS_PULSE_WIDTH, (SONY_REPEAT_PERIOD / MICROS_IN_ONE_MILLI), nullptr }; /************************************ * Start of send and decode functions @@ -103,38 +101,31 @@ SONY_SPACE, SONY_ZERO_MARK, SONY_SPACE, PROTOCOL_IS_LSB_FIRST, (SONY_REPEAT_PERI void IRsend::sendSony(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats, uint8_t numberOfBits) { uint32_t tData = (uint32_t) aAddress << 7 | (aCommand & 0x7F); // send 5, 8, 13 address bits LSB first - sendPulseDistanceWidth(&SonyProtocolConstants, tData, numberOfBits, aNumberOfRepeats); + sendPulseDistanceWidth_P(&SonyProtocolConstants, tData, numberOfBits, aNumberOfRepeats); } bool IRrecv::decodeSony() { - if (!checkHeader(&SonyProtocolConstants)) { + if (!checkHeader_P(&SonyProtocolConstants)) { return false; } // Check we have enough data. +2 for initial gap and start bit mark and space minus the last/MSB space. NO stop bit! 26, 32, 42 - if (decodedIRData.rawDataPtr->rawlen != (2 * SONY_BITS_MIN) + 2 && decodedIRData.rawDataPtr->rawlen != (2 * SONY_BITS_MAX) + 2 - && decodedIRData.rawDataPtr->rawlen != (2 * SONY_BITS_15) + 2) { - IR_DEBUG_PRINT(F("Sony: ")); - IR_DEBUG_PRINT(F("Data length=")); - IR_DEBUG_PRINT(decodedIRData.rawDataPtr->rawlen); - IR_DEBUG_PRINTLN(F(" is not 12, 15 or 20")); + if (!(decodedIRData.rawlen == (2 * SONY_BITS_MIN) + 2 || decodedIRData.rawlen == (2 * SONY_BITS_MAX) + 2 + || decodedIRData.rawlen == (2 * SONY_BITS_15) + 2)) { + DEBUG_PRINT(F("Sony: Data length=")); + DEBUG_PRINT(decodedIRData.rawlen); + DEBUG_PRINTLN(F(" is not 12, 15 or 20")); return false; } - if (!decodePulseDistanceWidthData(&SonyProtocolConstants, (decodedIRData.rawDataPtr->rawlen - 1) / 2, 3)) { -#if defined(LOCAL_DEBUG) - Serial.print(F("Sony: ")); - Serial.println(F("Decode failed")); -#endif - return false; - } + decodePulseDistanceWidthData_P(&SonyProtocolConstants, (decodedIRData.rawlen - 1) / 2, 3); // Success // decodedIRData.flags = IRDATA_FLAGS_IS_LSB_FIRST; // Not required, since this is the start value decodedIRData.command = decodedIRData.decodedRawData & 0x7F; // first 7 bits decodedIRData.address = decodedIRData.decodedRawData >> 7; // next 5 or 8 or 13 bits - decodedIRData.numberOfBits = (decodedIRData.rawDataPtr->rawlen - 1) / 2; + decodedIRData.numberOfBits = (decodedIRData.rawlen - 1) / 2; decodedIRData.protocol = SONY; //Check for repeat @@ -163,9 +154,8 @@ bool IRrecv::decodeSonyMSB(decode_results *aResults) { // Some Sony's deliver repeats fast after first // unfortunately can't spot difference from of repeat from two fast clicks if (aResults->rawbuf[0] < (SONY_DOUBLE_SPACE_USECS / MICROS_PER_TICK)) { -#if defined(LOCAL_DEBUG) - Serial.println(F("IR Gap found")); -#endif + DEBUG_PRINTLN(F("IR Gap found")); + aResults->bits = 0; aResults->value = 0xFFFFFFFF; decodedIRData.flags = IRDATA_FLAGS_IS_REPEAT; @@ -213,7 +203,7 @@ bool IRrecv::decodeSonyMSB(decode_results *aResults) { /** * Old version with MSB first data */ -void IRsend::sendSony(unsigned long data, int nbits) { +void IRsend::sendSonyMSB(unsigned long data, int nbits) { // Set IR carrier frequency enableIROut (SONY_KHZ); @@ -224,9 +214,11 @@ void IRsend::sendSony(unsigned long data, int nbits) { // Old version with MSB first Data sendPulseDistanceWidthData(SONY_ONE_MARK, SONY_SPACE, SONY_ZERO_MARK, SONY_SPACE, data, nbits, PROTOCOL_IS_MSB_FIRST); } +void IRsend::sendSony(unsigned long data, int nbits) { + sendSonyMSB(data, nbits); +} /** @}*/ -#if defined(LOCAL_DEBUG) -#undef LOCAL_DEBUG -#endif +#include "LocalDebugLevelEnd.h" + #endif // _IR_SONY_HPP diff --git a/src/ir_Template.hpp b/src/ir_Template.hpp index 9855f51a3..6ca74d918 100644 --- a/src/ir_Template.hpp +++ b/src/ir_Template.hpp @@ -92,6 +92,8 @@ #ifndef _IR_SHUZU_HPP #define _IR_SHUZU_HPP +#include "LocalDebugLevelStart.h" + //============================================================================== // // @@ -123,9 +125,9 @@ #define SHUZU_OTHER 1234 // Other things you may need to define // use BOSEWAVE, we have no SHUZU code -struct PulseDistanceWidthProtocolConstants ShuzuProtocolConstants = { BOSEWAVE, 38, SHUZU_HEADER_MARK, SHUZU_HEADER_SPACE, -SHUZU_BIT_MARK, SHUZU_ONE_SPACE, SHUZU_BIT_MARK, SHUZU_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (SHUZU_REPEAT_PERIOD - / MICROS_IN_ONE_MILLI), NULL }; +struct PulseDistanceWidthProtocolConstants const ShuzuProtocolConstants PROGMEM = {BOSEWAVE, 38, SHUZU_HEADER_MARK, SHUZU_HEADER_SPACE, + SHUZU_BIT_MARK, SHUZU_ONE_SPACE, SHUZU_BIT_MARK, SHUZU_ZERO_SPACE, PROTOCOL_IS_LSB_FIRST, (SHUZU_REPEAT_PERIOD + / MICROS_IN_ONE_MILLI), nullptr}; /************************************ * Start of send and decode functions @@ -133,7 +135,7 @@ SHUZU_BIT_MARK, SHUZU_ONE_SPACE, SHUZU_BIT_MARK, SHUZU_ZERO_SPACE, PROTOCOL_IS_L void IRsend::sendShuzu(uint16_t aAddress, uint8_t aCommand, int_fast8_t aNumberOfRepeats) { - sendPulseDistanceWidth(&ShuzuProtocolConstants, (uint32_t) aCommand << 8 | aCommand, SHUZU_BITS, aNumberOfRepeats); + sendPulseDistanceWidth_P(&ShuzuProtocolConstants, (uint32_t) aCommand << 8 | aCommand, SHUZU_BITS, aNumberOfRepeats); } bool IRrecv::decodeShuzu() { @@ -143,20 +145,19 @@ bool IRrecv::decodeShuzu() { * Next try the decode */ // Check we have the right amount of data (28). The +4 is for initial gap, start bit mark and space + stop bit mark - if (decodedIRData.rawDataPtr->rawlen != (2 * SHUZU_BITS) + 4) { + if (irparams.rawlen != (2 * SHUZU_BITS) + 4) { // no debug output, since this check is mainly to determine the received protocol return false; } // Check header - if (!checkHeader(&ShuzuProtocolConstants)) { + if (!checkHeader_P(&ShuzuProtocolConstants)) { return false; } // Decode - if (!decodePulseDistanceData(&ShuzuProtocolConstants, SHUZU_BITS)) { - IR_DEBUG_PRINT(F("Shuzu: ")); - IR_DEBUG_PRINTLN(F("Decode failed")); + if (!decodePulseDistanceData_P(&ShuzuProtocolConstants, SHUZU_BITS)) { + DEBUG_PRINTLN(F("Shuzu: Decode failed")); return false; } @@ -172,4 +173,7 @@ bool IRrecv::decodeShuzu() { return true; } + +#include "LocalDebugLevelEnd.h" + #endif // _IR_SHUZU_HPP diff --git a/src/private/IRTimer.hpp b/src/private/IRTimer.hpp index 1d87c971e..0e951f0b6 100644 --- a/src/private/IRTimer.hpp +++ b/src/private/IRTimer.hpp @@ -11,7 +11,7 @@ ************************************************************************************* * MIT License * - * Copyright (c) 2021-2023 Armin Joachimsmeyer + * Copyright (c) 2021-2026 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 @@ -32,6 +32,15 @@ * ************************************************************************************ */ + +/** + * Hardware PWM generation of sending signal with 8 bit timer: + * 16 MHZ F_CPU and 38 kHz -> prescaling = 2, divider = 210.526 -> 38.1 kHz with divider 210 + * 8 MHZ F_CPU and 38 kHz -> no prescaling , divider = 210.526 -> 38.1 kHz with divider 210 + * 4 MHZ F_CPU and 38 kHz -> no prescaling , divider = 105.26 -> 38.1 kHz with divider 105 + * 1 MHZ F_CPU and 38 kHz -> no prescaling , divider = 26.31 -> 38.4 kHz with divider 36 + * 38 kHz = 26.3157 us + */ #ifndef _IR_TIMER_HPP #define _IR_TIMER_HPP @@ -44,20 +53,32 @@ /* * Functions declared here */ -void timerResetInterruptPending(); -void timerEnableReceiveInterrupt(); -void timerDisableReceiveInterrupt(); -void timerConfigForReceive(); -void enableSendPWMByTimer(); -void disableSendPWMByTimer(); -void timerConfigForSend(uint16_t aFrequencyKHz); - -#if defined(SEND_PWM_BY_TIMER) && ( (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED) ) -#define SEND_PWM_DOES_NOT_USE_RECEIVE_TIMER // Receive timer and send generation are independent, so it is recommended to always define SEND_PWM_BY_TIMER +void timerConfigForReceive(); // Initialization of 50 us timer, interrupts are still disabled +void timerEnableReceiveInterrupt(); // Enable interrupts of an initialized timer +void timerDisableReceiveInterrupt(); // Disable interrupts of an initialized timer +void timerResetInterruptPending(); // ISR helper function for some architectures, which require a manual reset +// of the pending interrupt (TIMER_REQUIRES_RESET_INTR_PENDING is defined). Otherwise empty. + +void timerConfigForSend(uint16_t aFrequencyKHz); // Initialization of timer hardware generated PWM, if defined(SEND_PWM_BY_TIMER) +void enableSendPWMByTimer(); // Switch on PWM generation +void disableSendPWMByTimer(); // Switch off PWM generation + +void IRReceiveTimerInterruptHandler(); // defined in IRReceive.hpp + +// SEND_PWM_BY_TIMER for different architectures is enabled / defined at IRremote.hpp line 195. +#if defined(SEND_PWM_BY_TIMER) && ( (defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(PARTICLE)) || defined(ARDUINO_ARCH_MBED) ) +#define SEND_PWM_DOES_NOT_USE_RECEIVE_TIMER // Receive timer and send generation timer are independent here. +#endif + +#if defined(IR_SEND_PIN) && defined(SEND_PWM_BY_TIMER) && !defined(SEND_PWM_DOES_NOT_USE_RECEIVE_TIMER) // For ESP32 etc. IR_SEND_PIN definition is useful +#undef IR_SEND_PIN // To avoid "warning: "IR_SEND_PIN" redefined". The user warning is done at IRremote.hpp line 202. #endif -#if defined(IR_SEND_PIN) && defined(SEND_PWM_BY_TIMER) && !defined(SEND_PWM_DOES_NOT_USE_RECEIVE_TIMER) // For e.g ESP32 IR_SEND_PIN definition is useful -#undef IR_SEND_PIN // avoid warning below, user warning is done at IRremote.hpp +#if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +// Use the inverse value, so same code should work for active Low output +#define IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH (100 - IR_SEND_DUTY_CYCLE_PERCENT) +#else +#define IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH IR_SEND_DUTY_CYCLE_PERCENT #endif // Macros for enabling timers for development @@ -85,6 +106,7 @@ void timerConfigForSend(uint16_t aFrequencyKHz); //#define __STM32F1__ //#define STM32F1xx //#define PARTICLE +//#define ARDUINO_ARCH_RENESAS #if defined (DOXYGEN) /** @@ -115,7 +137,7 @@ void timerDisableReceiveInterrupt() { /** * IF PWM should be generated not by software, but by a timer, this function sets output pin mode, - * configures the timer for generating a PWM with duty cycle of IR_SEND_DUTY_CYCLE_PERCENT + * configures the timer for generating a PWM with HIGH output level of duty cycle of IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * and disables the receive interrupt if it uses the same resource. * For most architectures, the pin number(s) which can be used for output is determined by the timer used! * The output of the PWM signal is controlled by enableSendPWMByTimer() and disableSendPWMByTimer(). @@ -172,15 +194,15 @@ void disableSendPWMByTimer() { // Nano Every, Uno WiFi Rev2 and similar #elif defined(__AVR_ATmega808__) || defined(__AVR_ATmega809__) || defined(__AVR_ATmega3208__) || defined(__AVR_ATmega3209__) \ - || defined(__AVR_ATmega1608__) || defined(__AVR_ATmega1609__) || defined(__AVR_ATmega4808__) || defined(__AVR_ATmega4809__) || defined(__AVR_ATtiny1604__) + || defined(__AVR_ATmega1608__) || defined(__AVR_ATmega1609__) || defined(__AVR_ATmega4808__) || defined(__AVR_ATmega4809__) # if !defined(IR_USE_AVR_TIMER_B) #define IR_USE_AVR_TIMER_B // send pin = pin 6 on ATmega4809 1 on ATmega4809 # endif -#elif defined(__AVR_ATtiny816__) || defined(__AVR_ATtiny1614__) || defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) // e.g. TinyCore boards +#elif defined(__AVR_ATtiny816__) || defined(__AVR_ATtiny1604__) || defined(__AVR_ATtiny1614__) || defined(__AVR_ATtiny1624__) \ + || defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) || defined(__AVR_ATtiny3227__) // e.g. TinyCore boards # if !defined(IR_USE_AVR_TIMER_A) && !defined(IR_USE_AVR_TIMER_D) -#define IR_USE_AVR_TIMER_A // use this if you use MegaTinyCore, Tone is on TCB and millis() on TCD -//#define IR_USE_AVR_TIMER_D // use this if you use TinyCore +#define IR_USE_AVR_TIMER_A // use this if you use megaTinyCore, Tone is on TCB and millis() on TCD # endif // ATmega8u2, ATmega16U2, ATmega32U2, ATmega8 - Timer 2 does not work with existing code below @@ -192,7 +214,7 @@ void disableSendPWMByTimer() { // ATtiny84 #elif defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny88__) # if !defined(IR_USE_AVR_TIMER1) -#define IR_USE_AVR_TIMER1 // send pin = pin 6 +#define IR_USE_AVR_TIMER1 // send pin = pin 6, no tone() available when using ATTinyCore # endif #elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) @@ -335,6 +357,7 @@ void timerConfigForReceive() { } # if defined(SEND_PWM_BY_TIMER) +// Set IR_SEND_PIN depending on CPU # if defined(CORE_OC1A_PIN) #define IR_SEND_PIN CORE_OC1A_PIN // Teensy @@ -375,9 +398,9 @@ void timerConfigForReceive() { //#define IR_SEND_PIN PIN_PB6 // OC1AX / PB6 / Pin14 at ATTinyCore # endif -# else +# else // defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) #define IR_SEND_PIN 9 // OC1A Arduino Duemilanove, Diecimila, LilyPad, Sparkfun Pro Micro, Leonardo, MH-ET Tiny88 etc. -# endif // defined(CORE_OC1A_PIN) +# endif // Set IR_SEND_PIN depending on CPU # if defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when down counting. @@ -391,37 +414,72 @@ void enableSendPWMByTimer() { //TCNT1 = 0; TCCR1A |= _BV(COM1B1); TCCR1D |= _BV(OC1BX); // + enable OC1BX as output } # else -void disableSendPWMByTimer() { +void enableSendPWMByTimer() { TCNT1 = 0; TCCR1A |= _BV(COM1A1); - TCCR1D |= _BV(OC1AU); // + enable OC1BU as output + TCCR1D |= _BV(OC1AU); // + enable OC1AU as output //TCNT1 = 0; TCCR1A |= _BV(COM1A1); TCCR1D |= _BV(OC1AV); // + enable OC1BV as output //TCNT1 = 0; TCCR1A |= _BV(COM1A1); TCCR1D |= _BV(OC1AW); // + enable OC1BW as output //TCNT1 = 0; TCCR1A |= _BV(COM1A1); TCCR1D |= _BV(OC1AX); // + enable OC1BX as output } +# endif // defined(USE_TIMER_CHANNEL_B) -# endif void disableSendPWMByTimer() { TCCR1D = 0; +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } -# else +# else // defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) # if defined(USE_TIMER_CHANNEL_B) void enableSendPWMByTimer() { - TCNT1 = 0; (TCCR1A |= _BV(COM1B1)) // Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when downcounting. + TCNT1 = 0; + TCCR1A |= _BV(COM1B1); // Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when counting down. } void disableSendPWMByTimer() { TCCR1A &= ~(_BV(COM1B1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } -# else +# else // defined(USE_TIMER_CHANNEL_B) void enableSendPWMByTimer() { TCNT1 = 0; TCCR1A |= _BV(COM1A1); // Clear OC1A/OC1B on Compare Match when up-counting. Set OC1A/OC1B on Compare Match when downcounting. } void disableSendPWMByTimer() { TCCR1A &= ~(_BV(COM1A1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } -# endif -# endif +# endif // defined(USE_TIMER_CHANNEL_B) + +# endif // defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) /* * timerConfigForSend() is used exclusively by IRsend::enableIROut() @@ -430,34 +488,34 @@ void disableSendPWMByTimer() { void timerConfigForSend(uint16_t aFrequencyKHz) { timerDisableReceiveInterrupt(); -# if (((F_CPU / 2000) / 38) < 256) +# if (((F_CPU / 2000) / 38) < 256) const uint16_t tPWMWrapValue = (F_CPU / 2000) / (aFrequencyKHz); // 210,52 for 38 kHz @16 MHz clock, 2000 instead of 1000 because of Phase Correct PWM TCCR1A = _BV(WGM11); // PWM, Phase Correct, Top is ICR1 TCCR1B = _BV(WGM13) | _BV(CS10); // CS10 -> no prescaling ICR1 = tPWMWrapValue - 1; -# if defined(USE_TIMER_CHANNEL_B) - OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; -# else - OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; -# endif +# if defined(USE_TIMER_CHANNEL_B) + OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; +# else + OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; +# endif TCNT1 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible -# else +# else const uint16_t tPWMWrapValue = ((F_CPU / 8) / 2000) / (aFrequencyKHz); // 2000 instead of 1000 because of Phase Correct PWM TCCR1A = _BV(WGM11);// PWM, Phase Correct, Top is ICR1 TCCR1B = _BV(WGM13) | _BV(CS11);// CS11 -> Prescaling by 8 ICR1 = tPWMWrapValue - 1; -# if defined(USE_TIMER_CHANNEL_B) - OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; -# else - OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; -# endif +# if defined(USE_TIMER_CHANNEL_B) + OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; +# else + OCR1A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; +# endif TCNT1 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible -# endif +# endif // if (((F_CPU / 2000) / 38) < 256) } -# endif // defined(SEND_PWM_BY_TIMER) +# endif // defined(SEND_PWM_BY_TIMER) - Timer1 /* - * AVR Timer2 (8 bits) // Tone timer on UNO + * AVR Timer2 (8 bits) // Tone timer on Uno */ #elif defined(IR_USE_AVR_TIMER2) @@ -468,7 +526,6 @@ void timerDisableReceiveInterrupt() { TIMSK2 = 0; } #define TIMER_INTR_NAME TIMER2_COMPB_vect // We use TIMER2_COMPB_vect to be compatible with tone() library - #define TIMER_COUNT_TOP (F_CPU * MICROS_PER_TICK / MICROS_IN_ONE_SECOND) void timerConfigForReceive() { @@ -488,6 +545,7 @@ void timerConfigForReceive() { } # if defined(SEND_PWM_BY_TIMER) +// Set IR_SEND_PIN depending on CPU # if defined(CORE_OC2B_PIN) #define IR_SEND_PIN CORE_OC2B_PIN // Teensy @@ -502,8 +560,13 @@ void timerConfigForReceive() { #define IR_SEND_PIN 14 // MightyCore, MegaCore # else -#define IR_SEND_PIN 3 // Arduino Duemilanove, Diecimila, LilyPad, etc -# endif // defined(CORE_OC2B_PIN) +/* + * Using pin 11 / PB3 / OC2A for this purpose is NOT possible, since we need a PWM with a selectable frequency. + * This is only possible by using Phase Correct with Top as OCR2A. + * Thus the OCR2A register cannot be used for comparing for channel A and TOP with OCR2B is not supported by Hardware :-(. + */ +#define IR_SEND_PIN 3 // Arduino Uno Pin PD3, Duemilanove, Diecimila, LilyPad, etc +# endif // Set IR_SEND_PIN depending on CPU void enableSendPWMByTimer() { TCNT2 = 0; @@ -511,6 +574,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR2A &= ~(_BV(COM2B1)); // Normal port operation, OC2B disconnected. +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -530,14 +604,14 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { TCCR2A = _BV(WGM20); // PWM, Phase Correct, Top is OCR2A TCCR2B = _BV(WGM22) | _BV(CS20); // CS20 -> no prescaling OCR2A = tPWMWrapValue - 1; // The top value for the timer. The modulation frequency will be F_CPU / 2 / (OCR2A + 1). - OCR2B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR2B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT2 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible # else const uint16_t tPWMWrapValue = ((F_CPU / 8) / 2000) / (aFrequencyKHz); // 2000 instead of 1000 because of Phase Correct PWM TCCR2A = _BV(WGM20);// PWM, Phase Correct, Top is OCR2A TCCR2B = _BV(WGM22) | _BV(CS21);// CS21 -> Prescaling by 8 OCR2A = tPWMWrapValue - 1; - OCR2B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR2B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT2 = 0;// not really required, since we have an 8 bit counter, but makes the signal more reproducible # endif } @@ -565,6 +639,7 @@ void timerConfigForReceive() { } # if defined(SEND_PWM_BY_TIMER) +// Set IR_SEND_PIN depending on CPU # if defined(CORE_OC3A_PIN) #define IR_SEND_PIN CORE_OC3A_PIN // Teensy @@ -577,7 +652,7 @@ void timerConfigForReceive() { # else #error Please add OC3A pin number here -# endif +# endif // Set IR_SEND_PIN depending on CPU void enableSendPWMByTimer() { TCNT3 = 0; @@ -585,6 +660,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR3A &= ~(_BV(COM3A1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -592,16 +678,16 @@ void disableSendPWMByTimer() { * Set output pin mode and disable receive interrupt if it uses the same resource */ void timerConfigForSend(uint16_t aFrequencyKHz) { -#if F_CPU > 16000000 +# if F_CPU > 16000000 #error "Creating timer PWM with timer 3 is not supported for F_CPU > 16 MHz" -#endif +# endif timerDisableReceiveInterrupt(); const uint16_t tPWMWrapValue = (F_CPU / 2000) / (aFrequencyKHz); // 210,52 for 38 kHz @16 MHz clock, 2000 instead of 1000 because of Phase Correct PWM TCCR3A = _BV(WGM31); TCCR3B = _BV(WGM33) | _BV(CS30); // PWM, Phase Correct, ICRn as TOP, complete period is double of tPWMWrapValue ICR3 = tPWMWrapValue - 1; - OCR3A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR3A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT3 = 0; // required, since we have an 16 bit counter } # endif // defined(SEND_PWM_BY_TIMER) @@ -626,6 +712,7 @@ void timerConfigForReceive() { } # if defined(SEND_PWM_BY_TIMER) +// Set IR_SEND_PIN depending on CPU # if defined(CORE_OC4A_PIN) #define IR_SEND_PIN CORE_OC4A_PIN # elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) @@ -640,18 +727,29 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR4A &= ~(_BV(COM4A1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } void timerConfigForSend(uint16_t aFrequencyKHz) { -#if F_CPU > 16000000 +# if F_CPU > 16000000 #error "Creating timer PWM with timer 4 is not supported for F_CPU > 16 MHz" -#endif +# endif timerDisableReceiveInterrupt(); const uint16_t tPWMWrapValue = (F_CPU / 2000) / (aFrequencyKHz); // 210,52 for 38 kHz @16 MHz clock, 2000 instead of 1000 because of Phase Correct PWM TCCR4A = _BV(WGM41); TCCR4B = _BV(WGM43) | _BV(CS40); ICR4 = tPWMWrapValue - 1; - OCR4A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR4A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT4 = 0; // required, since we have an 16 bit counter } # endif // defined(SEND_PWM_BY_TIMER) @@ -693,8 +791,24 @@ void timerConfigForReceive() { # endif # if defined(ARDUINO_AVR_PROMICRO) // Sparkfun Pro Micro -void enableSendPWMByTimer() { TCNT4 = 0; (TCCR4A |= _BV(COM4A0)) // Use complementary OC4A output on pin 5 -void disableSendPWMByTimer() { (TCCR4A &= ~(_BV(COM4A0))) // (Pro Micro does not map PC7 (32/ICP3/CLK0/OC4A) +void enableSendPWMByTimer() { + TCNT4 = 0; + TCCR4A |= _BV(COM4A0); // Use complementary OC4A output on pin 5 +} +void disableSendPWMByTimer() { + TCCR4A &= ~(_BV(COM4A0)); // (Pro Micro does not map PC7 (32/ICP3/CLK0/OC4A) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +} // of ATmega32U4 ) # else void enableSendPWMByTimer() { @@ -704,6 +818,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR4A &= ~(_BV(COM4A1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } # endif @@ -725,8 +850,8 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { TCCR4E = 0; TC4H = tPWMWrapValue >> 8; OCR4C = tPWMWrapValue; - TC4H = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT / 100) >> 8; - OCR4A = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT / 100) & 255; + TC4H = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH / 100) >> 8; + OCR4A = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH / 100) & 255; TCNT4 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible } # endif // defined(SEND_PWM_BY_TIMER) @@ -766,6 +891,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR5A &= ~(_BV(COM5A1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -782,7 +918,7 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { TCCR5A = _BV(WGM51); TCCR5B = _BV(WGM53) | _BV(CS50); ICR5 = tPWMWrapValue - 1; - OCR5A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR5A = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT5 = 0; // required, since we have an 16 bit counter } # endif // defined(SEND_PWM_BY_TIMER) @@ -825,6 +961,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCCR0A &= ~(_BV(COM0B1)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -832,16 +979,16 @@ void disableSendPWMByTimer() { * Set output pin mode and disable receive interrupt if it uses the same resource */ void timerConfigForSend(uint16_t aFrequencyKHz) { -#if F_CPU > 16000000 +# if F_CPU > 16000000 #error "Creating timer PWM with timer TINY0 is not supported for F_CPU > 16 MHz" -#endif +# endif timerDisableReceiveInterrupt(); const uint16_t tPWMWrapValue = (F_CPU / 2000) / (aFrequencyKHz); // 210,52 for 38 kHz @16 MHz clock, 2000 instead of 1000 because of Phase Correct PWM TCCR0A = _BV(WGM00); // PWM, Phase Correct, Top is OCR0A TCCR0B = _BV(WGM02) | _BV(CS00); // CS00 -> no prescaling OCR0A = tPWMWrapValue - 1; - OCR0B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR0B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT0 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible } # endif // defined(SEND_PWM_BY_TIMER) @@ -884,6 +1031,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { GTCCR &= ~(_BV(PWM1B) | _BV(COM1B0)); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -897,14 +1055,14 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { const uint16_t tPWMWrapValue = (F_CPU / 1000) / (aFrequencyKHz); // 421 @16 MHz, 26 @1 MHz and 38 kHz TCCR1 = _BV(CTC1) | _BV(CS10);// CTC1 = 1: TOP value set to OCR1C, CS10 No Prescaling OCR1C = tPWMWrapValue - 1; - OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT1 = 0;// not really required, since we have an 8 bit counter, but makes the signal more reproducible GTCCR = _BV(PWM1B) | _BV(COM1B0);// PWM1B = 1: Enable PWM for OCR1B, COM1B0 Clear on compare match # else - const uint16_t tPWMWrapValue = ((F_CPU / 2) / 1000) / (aFrequencyKHz); // 210 for 16 MHz and 38 kHz + const uint16_t tPWMWrapValue = ((F_CPU / 2) / 1000) / (aFrequencyKHz); // 210.526 for 16 MHz and 38 kHz or 38.1 kHz for 210 TCCR1 = _BV(CTC1) | _BV(CS11); // CTC1 = 1: TOP value set to OCR1C, CS11 Prescaling by 2 OCR1C = tPWMWrapValue - 1; - OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; + OCR1B = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; TCNT1 = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible GTCCR = _BV(PWM1B) | _BV(COM1B0); // PWM1B = 1: Enable PWM for OCR1B, COM1B0 Clear on compare match # endif @@ -980,6 +1138,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCB0.CTRLB &= ~(TCB_CCMPEN_bm); +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -996,7 +1165,7 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { const uint16_t tPWMWrapValue = (F_CPU / 2000) / (aFrequencyKHz); // 210,52 for 38 kHz @16 MHz clock, 2000 instead of 1000 because of using CLK / 2 TCB0.CTRLB = TCB_CNTMODE_PWM8_gc; // 8 bit PWM mode TCB0.CCMPL = tPWMWrapValue - 1; // Period of 8 bit PWM - TCB0.CCMPH = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; // Duty cycle of waveform of 8 bit PWM + TCB0.CCMPH = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; // Duty cycle of waveform of 8 bit PWM TCB0.CTRLA = (TCB_CLKSEL_CLKDIV2_gc) | (TCB_ENABLE_bm); // use CLK / 2 TCB0.CNT = 0; // not really required, since we have an 8 bit counter, but makes the signal more reproducible } @@ -1049,6 +1218,17 @@ void enableSendPWMByTimer() { } void disableSendPWMByTimer() { TCD0.CTRLA = 0; // do not disable output, disable complete timer +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) +# if defined(IR_SEND_PIN) + digitalWriteFast(IR_SEND_PIN, HIGH); +# else + if (__builtin_constant_p(sendPin)) { + digitalWriteFast(sendPin, HIGH); + } else { + digitalWrite(sendPin, HIGH); + } +# endif // defined(IR_SEND_PIN) +# endif // defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) } /* @@ -1069,7 +1249,7 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { // Generate duty cycle signal for debugging etc. TCD0.CMPASET = 0; - TCD0.CMPACLR = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT / 100) - 1; // duty cycle for WOA + TCD0.CMPACLR = (tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH / 100) - 1; // duty cycle for WOA TCD0.INTFLAGS = TCD_OVF_bm; // reset interrupt flags TCD0.INTCTRL = TCD_OVF_bm; // overflow interrupt @@ -1084,6 +1264,67 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { * End of AVR timers **********************************************************************************************************************/ +/********************************************** + * Uno R4 boards + **********************************************/ +#elif defined(ARDUINO_ARCH_RENESAS) +#include "FspTimer.h" +FspTimer s50usTimer; + +// Undefine ISR, because we register/call the plain function IRReceiveTimerInterruptHandler() +# if defined(ISR) +#undef ISR +# endif + +// callback method used by timer +void IRTimerInterruptHandlerHelper(timer_callback_args_t __attribute((unused)) *p_args) { + IRReceiveTimerInterruptHandler(); +} +void timerEnableReceiveInterrupt() { +// s50usTimer.enable_overflow_irq(); + s50usTimer.start(); +} +void timerDisableReceiveInterrupt() { +// s50usTimer.disable_overflow_irq(); + s50usTimer.stop(); // May save power +} + +void timerConfigForReceive() { + uint8_t tTimerType = GPT_TIMER; + int8_t tIndex = FspTimer::get_available_timer(tTimerType); // Get first unused channel. Here we need the address of tTimerType + if (tIndex < 0 || tTimerType != GPT_TIMER) { + // here we found no unused GPT channel + tIndex = FspTimer::get_available_timer(tTimerType, true); // true to force use of already used PWM channel. Sets "force_pwm_reserved" if timer found + if (tIndex < 0) { + // If we already get an tIndex < 0 we have an error, but do not know how to handle :-( + return; + } + } + s50usTimer.begin(TIMER_MODE_PERIODIC, tTimerType, tIndex, MICROS_IN_ONE_SECOND / MICROS_PER_TICK, 0.0, + IRTimerInterruptHandlerHelper); + s50usTimer.setup_overflow_irq(); + s50usTimer.open(); // In turn calls R_GPT_Enable() + s50usTimer.stop(); // May save power +} + +# if defined(SEND_PWM_BY_TIMER) +#error PWM generation by hardware not yet implemented for Arduino Uno R4 +// Not yet implemented +void enableSendPWMByTimer() { +} +void disableSendPWMByTimer() { +} + +/* + * timerConfigForSend() is used exclusively by IRsend::enableIROut() + */ +void timerConfigForSend(uint16_t aFrequencyKHz) { +# if defined(IR_SEND_PIN) +# else +# endif +} +# endif + /********************************************** * Teensy 3.0 / Teensy 3.1 / Teensy 3.2 boards **********************************************/ @@ -1328,6 +1569,9 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { } # endif // defined(SEND_PWM_BY_TIMER) +/********************************************************** + * ESP8266 boards + **********************************************************/ #elif defined(ESP8266) # if defined(SEND_PWM_BY_TIMER) #error "No support for hardware PWM generation for ESP8266" @@ -1342,7 +1586,7 @@ void timerEnableReceiveInterrupt() { timer1_attachInterrupt(&IRReceiveTimerInterruptHandler); // enables interrupt too } void timerDisableReceiveInterrupt() { - timer1_detachInterrupt(); // disables interrupt too } + timer1_detachInterrupt(); // disables interrupt too } void timerConfigForReceive() { @@ -1362,75 +1606,167 @@ void timerConfigForReceive() { * so it is recommended to always define SEND_PWM_BY_TIMER **********************************************************/ #elif defined(ESP32) +# if !defined(ESP_ARDUINO_VERSION) +#define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 +# endif + // Variables specific to the ESP32. // the ledc functions behave like hardware timers for us :-), so we do not require our own soft PWM generation code. -hw_timer_t *s50usTimer = NULL; // set by timerConfigForReceive() +hw_timer_t *s50usTimer = nullptr; // set by timerConfigForReceive() +#define _IRREMOTE_ESP32_LEDC_RESOLUTION 8 +#define _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE 255 - -# if !defined(SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL) -#define SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL 0 // The channel used for PWM 0 to 7 are high speed PWM channels +//# if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3, 0, 0) && !defined(SEND_LEDC_CHANNEL) +# if ESP_ARDUINO_VERSION < (3 << 16 | 0 << 8 | 0) && !defined(SEND_LEDC_CHANNEL) // works also in case ESP_ARDUINO_VERSION_VAL is not defined +#define SEND_LEDC_CHANNEL 0 // The channel used for PWM 0 to 7 are high speed PWM channels # endif void timerEnableReceiveInterrupt() { +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) + timerStart(s50usTimer); +# else timerAlarmEnable(s50usTimer); +# endif } -#if !defined(ESP_ARDUINO_VERSION) -#define ESP_ARDUINO_VERSION 0 -#endif -#if !defined(ESP_ARDUINO_VERSION_VAL) -#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) 202 -#endif -#if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 2) +//# if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 2) +# if ESP_ARDUINO_VERSION < (2 << 16 | 0 << 8 | 2) +/* + * Special support for ESP core < 202 + */ void timerDisableReceiveInterrupt() { - if (s50usTimer != NULL) { + if (s50usTimer != nullptr) { timerDetachInterrupt(s50usTimer); timerEnd(s50usTimer); } } -#else +# else + void timerDisableReceiveInterrupt() { - if (s50usTimer != NULL) { + if (s50usTimer != nullptr) { +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) + timerStop(s50usTimer); +# else timerAlarmDisable(s50usTimer); +# endif } } -#endif +# endif // Undefine ISR, because we register/call the plain function IRReceiveTimerInterruptHandler() # if defined(ISR) #undef ISR # endif +# if !defined(DISABLE_CODE_FOR_RECEIVER) // Otherwise the &IRReceiveTimerInterruptHandler is referenced, but not available void timerConfigForReceive() { // ESP32 has a proper API to setup timers, no weird chip macros needed // simply call the readable API versions :) // 3 timers, choose #1, 80 divider for microsecond precision @80MHz clock, count_up = true - if(s50usTimer == NULL) { + if (s50usTimer == nullptr) { +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) + s50usTimer = timerBegin(1000000); // Only 1 parameter is required. 1000000 corresponds to 1 MHz / 1 uSec. After successful setup the timer will automatically start. + timerStop(s50usTimer); // Stop it here, to avoid "error E (3447) gptimer: gptimer_start(348): timer is not enabled yet" at timerEnableReceiveInterrupt() + timerAttachInterrupt(s50usTimer, &IRReceiveTimerInterruptHandler); + timerAlarm(s50usTimer, MICROS_PER_TICK, true, 0); // 0 in the last parameter is repeat forever +# else s50usTimer = timerBegin(1, 80, true); timerAttachInterrupt(s50usTimer, &IRReceiveTimerInterruptHandler, false); // false -> level interrupt, true -> edge interrupt, but this is not supported :-( timerAlarmWrite(s50usTimer, MICROS_PER_TICK, true); +# endif } // every 50 us, autoreload = true } +# endif + +uint8_t sLastSendPin = 0; // 0 means channel not initialized / pin not attached +uint16_t sLastFrequencyKHz = 0; # if defined(SEND_PWM_BY_TIMER) void enableSendPWMByTimer() { - ledcWrite(SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL, (IR_SEND_DUTY_CYCLE_PERCENT * 256) / 100); // * 256 since we have 8 bit resolution +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) +# if defined(IR_SEND_PIN) + ledcWrite(IR_SEND_PIN, (IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE) / 100); // 3.x API +# else + ledcWrite(IrSender.sendPin, (IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE) / 100); // 3.x API +# endif +# else + // ESP version < 3.0 + ledcWrite(SEND_LEDC_CHANNEL, (IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE) / 100); // * 256 since we have 8 bit resolution +# endif } void disableSendPWMByTimer() { - ledcWrite(SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL, 0); +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) +# if defined(IR_SEND_PIN) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + ledcWrite(IR_SEND_PIN, _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE); // 3.x API +# else + ledcWrite(IR_SEND_PIN, 0); // 3.x API +# endif +# else +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + ledcWrite(IrSender.sendPin, _IRREMOTE_ESP32_LEDC_RESOLUTION_MAX_PWM_VALUE); // 3.x API +# else + ledcWrite(IrSender.sendPin, 0); // 3.x API +# endif +# endif +# else + // ESP version < 3.0 + ledcWrite(SEND_LEDC_CHANNEL, 0); +# endif } /* - * timerConfigForSend() is used exclusively by IRsend::enableIROut() - * ledcWrite since ESP 2.0.2 does not work if pin mode is set. Disable receive interrupt if it uses the same resource + * timerConfigForSend() is used exclusively by IRsend::enableIROut() (or enableHighFrequencyIROut()) + * ledcWrite since ESP 2.0.2 does not work if pin mode is set. */ void timerConfigForSend(uint16_t aFrequencyKHz) { - ledcSetup(SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL, aFrequencyKHz * 1000, 8); // 8 bit PWM resolution -# if defined(IR_SEND_PIN) - ledcAttachPin(IR_SEND_PIN, SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL); // bind pin to channel +//# if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) +# if ESP_ARDUINO_VERSION >= (3 << 16 | 0 << 8 | 0) +# if defined(IR_SEND_PIN) + if(sLastSendPin == 0){ + // Do it only once - except for frequency change + ledcAttach(IR_SEND_PIN, aFrequencyKHz * 1000, _IRREMOTE_ESP32_LEDC_RESOLUTION); + sLastSendPin = IR_SEND_PIN; + } else if(sLastFrequencyKHz != aFrequencyKHz){ + // Frequency change here + ledcDetach(IR_SEND_PIN); // detach pin before new attaching see #1194 + ledcAttach(IR_SEND_PIN, aFrequencyKHz * 1000, _IRREMOTE_ESP32_LEDC_RESOLUTION); // 3.x API + sLastFrequencyKHz = aFrequencyKHz; + } +# else + if(sLastSendPin != IrSender.sendPin || sLastFrequencyKHz != aFrequencyKHz){ + if(sLastSendPin != 0) { + // do not detach initially + ledcDetach(sLastSendPin); // detach pin before new attaching see #1194 + } + ledcAttach(IrSender.sendPin, aFrequencyKHz * 1000, _IRREMOTE_ESP32_LEDC_RESOLUTION); // 3.x API + sLastSendPin = IrSender.sendPin; + sLastFrequencyKHz = aFrequencyKHz; + } +# endif # else - ledcAttachPin(IrSender.sendPin, SEND_AND_RECEIVE_TIMER_LEDC_CHANNEL); // bind pin to channel + // ESP version < 3.0 - no support for changing frequency + ledcSetup(SEND_LEDC_CHANNEL, aFrequencyKHz * 1000, _IRREMOTE_ESP32_LEDC_RESOLUTION); // 8 bit PWM resolution +# if defined(IR_SEND_PIN) + ledcAttachPin(IR_SEND_PIN, SEND_LEDC_CHANNEL); // attach pin to channel +# else + if(sLastSendPin != 0 && sLastSendPin != IrSender.sendPin){ + } + if( sLastSendPin != IrSender.sendPin){ + if(sLastSendPin != 0) { + // do not detach initially + ledcDetachPin(sLastSendPin); // detach pin before new attaching see #1194 + } + ledcAttachPin(IrSender.sendPin, SEND_LEDC_CHANNEL); // attach pin to channel + sLastSendPin = IrSender.sendPin; + } +# endif # endif } # endif // defined(SEND_PWM_BY_TIMER) @@ -1445,8 +1781,13 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { # if !defined(IR_SAMD_TIMER) # if defined(__SAMD51__) +# if defined(TC5) #define IR_SAMD_TIMER TC5 #define IR_SAMD_TIMER_IRQ TC5_IRQn +# else +#define IR_SAMD_TIMER TC3 +#define IR_SAMD_TIMER_IRQ TC3_IRQn +# endif # else // SAMD21 #define IR_SAMD_TIMER TC3 @@ -1481,7 +1822,11 @@ void timerConfigForReceive() { # if defined(__SAMD51__) // Enable the TC5 clock, use generic clock generator 0 (F_CPU) for TC5 +# if defined(TC5_GCLK_ID) GCLK->PCHCTRL[TC5_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK0_Val | (1 << GCLK_PCHCTRL_CHEN_Pos); +# else + GCLK->PCHCTRL[TC3_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK0_Val | (1 << GCLK_PCHCTRL_CHEN_Pos); +# endif // The TC should be disabled before the TC is reset in order to avoid undefined behavior. TC->CTRLA.reg &= ~TC_CTRLA_ENABLE; // Disable the Timer @@ -1538,18 +1883,12 @@ void timerConfigForReceive() { } # if !defined(DISABLE_CODE_FOR_RECEIVER) -# if defined(__SAMD51__) -void TC5_Handler(void) { - TcCount16 *TC = (TcCount16*) IR_SAMD_TIMER; - // Check for right interrupt bit - if (TC->INTFLAG.bit.MC0 == 1) { - // reset bit for next turn - TC->INTFLAG.bit.MC0 = 1; - IRReceiveTimerInterruptHandler(); - } -} +# if defined(__SAMD51__) && defined(TC5) +void TC5_Handler(void) # else -void TC3_Handler(void) { +void TC3_Handler(void) +# endif // defined(__SAMD51__) +{ TcCount16 *TC = (TcCount16*) IR_SAMD_TIMER; // Check for right interrupt bit if (TC->INTFLAG.bit.MC0 == 1) { @@ -1558,7 +1897,6 @@ void TC3_Handler(void) { IRReceiveTimerInterruptHandler(); } } -# endif // defined(__SAMD51__) # endif // !defined(DISABLE_CODE_FOR_RECEIVER) /*************************************** @@ -1593,6 +1931,7 @@ mbed::PwmOut sPwmOutForSendPWM(digitalPinToPinName(IR_SEND_PIN)); mbed::PwmOut sPwmOutForSendPWM(digitalPinToPinName(IrSender.sendPin)); # endif uint8_t sIROutPuseWidth; +uint8_t sIROutPuseWidthForHigh; // for setting level to 1 void enableSendPWMByTimer() { sPwmOutForSendPWM.pulsewidth_us(sIROutPuseWidth); @@ -1601,7 +1940,11 @@ void enableSendPWMByTimer() { //void disableSendPWMByTimer() { sPwmOutForSendPWM.suspend();} // this kills pulsewidth_us value and does not set output level to LOW void disableSendPWMByTimer() { +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + sPwmOutForSendPWM.pulsewidth_us(sIROutPuseWidthForHigh); // this also sets output level to HIGH :-) +# else sPwmOutForSendPWM.pulsewidth_us(0); // this also sets output level to LOW :-) +# endif } /* @@ -1609,8 +1952,9 @@ void disableSendPWMByTimer() { * Set output pin mode and disable receive interrupt if it uses the same resource */ void timerConfigForSend(uint16_t aFrequencyKHz) { - sPwmOutForSendPWM.period_us(1000 / aFrequencyKHz); // 26.315 for 38 kHz - sIROutPuseWidth = (1000 * IR_SEND_DUTY_CYCLE_PERCENT) / (aFrequencyKHz * 100); + sIROutPuseWidthForHigh = 1000 / aFrequencyKHz; + sPwmOutForSendPWM.period_us(sIROutPuseWidthForHigh); // 26.315 for 38 kHz + sIROutPuseWidth = (1000 * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / (aFrequencyKHz * 100); } # endif // defined(SEND_PWM_BY_TIMER) @@ -1637,7 +1981,7 @@ bool IRTimerInterruptHandlerHelper(repeating_timer_t*) { } void timerEnableReceiveInterrupt() { - add_repeating_timer_us(-(MICROS_PER_TICK), IRTimerInterruptHandlerHelper, NULL, &s50usTimer); + add_repeating_timer_us(-(MICROS_PER_TICK), IRTimerInterruptHandlerHelper, nullptr, &s50usTimer); } void timerDisableReceiveInterrupt() { cancel_repeating_timer(&s50usTimer); @@ -1647,22 +1991,62 @@ void timerConfigForReceive() { // no need for initializing timer at setup() } +#if !defined(USE_NO_SEND_PWM) +#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM. +#endif + # if defined(SEND_PWM_BY_TIMER) #include "hardware/pwm.h" +#define USE_RP2040_NATIVE_COMMANDS +# if defined(USE_RP2040_NATIVE_COMMANDS) uint sSliceNumberForSendPWM; uint sChannelNumberForSendPWM; uint sIROutPuseWidth; +uint16_t sIROutPuseWidthForHigh; // for setting level to 1 +# else +uint sFrequency; +# endif /* * If we just disable the PWM, the counter stops and the output stays at the state is currently has */ void enableSendPWMByTimer() { +# if defined(USE_RP2040_NATIVE_COMMANDS) pwm_set_counter(sSliceNumberForSendPWM, 0); pwm_set_chan_level(sSliceNumberForSendPWM, sChannelNumberForSendPWM, sIROutPuseWidth); +# else + analogWriteFreq(sFrequency); +# if defined(IR_SEND_PIN) + analogWrite(IR_SEND_PIN, (uint8_t) (IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * 255 / 100)); // Calculate duty as 0-255 value (analogWrite uses 8-bit resolution) +# else + analogWrite(IrSender.sendPin, (uint8_t) (IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH * 255 / 100)); // Calculate duty as 0-255 value (analogWrite uses 8-bit resolution) +# endif +# endif } + void disableSendPWMByTimer() { +# if defined(USE_RP2040_NATIVE_COMMANDS) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + pwm_set_chan_level(sSliceNumberForSendPWM, sChannelNumberForSendPWM, sIROutPuseWidthForHigh); // this sets output also to HIGH +# else pwm_set_chan_level(sSliceNumberForSendPWM, sChannelNumberForSendPWM, 0); // this sets output also to LOW +# endif +# else +# if defined(IR_SEND_PIN) +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + analogWrite(IR_SEND_PIN, 255); // analogWrite(0) disables PWM and sets pin HIGH +# else + analogWrite(IR_SEND_PIN, 0); // analogWrite(0) disables PWM and sets pin LOW +# endif +# else +# if defined(USE_ACTIVE_LOW_OUTPUT_FOR_SEND_PIN) + analogWrite(IrSender.sendPin, 255); // analogWrite(0) disables PWM and sets pin HIGH +# else + analogWrite(IrSender.sendPin, 0); // analogWrite(0) disables PWM and sets pin LOW +# endif +# endif +# endif } /* @@ -1670,32 +2054,44 @@ void disableSendPWMByTimer() { * Set output pin mode and disable receive interrupt if it uses the same resource */ void timerConfigForSend(uint16_t aFrequencyKHz) { -# if defined(IR_SEND_PIN) +# if defined(USE_RP2040_NATIVE_COMMANDS) +# if defined(IR_SEND_PIN) gpio_set_function(IR_SEND_PIN, GPIO_FUNC_PWM); // Find out which PWM slice is connected to IR_SEND_PIN sSliceNumberForSendPWM = pwm_gpio_to_slice_num(IR_SEND_PIN); sChannelNumberForSendPWM = pwm_gpio_to_channel(IR_SEND_PIN); -# else +# else gpio_set_function(IrSender.sendPin, GPIO_FUNC_PWM); // Find out which PWM slice is connected to IR_SEND_PIN sSliceNumberForSendPWM = pwm_gpio_to_slice_num(IrSender.sendPin); sChannelNumberForSendPWM = pwm_gpio_to_channel(IrSender.sendPin); +# endif +# else +# if defined(IR_SEND_PIN) + pinMode(IR_SEND_PIN, OUTPUT); // Set the pin to output mode initially +# else + pinMode(IrSender.sendPin, OUTPUT); // Set the pin to output mode initially +# endif # endif +# if defined(USE_RP2040_NATIVE_COMMANDS) uint16_t tPWMWrapValue = (clock_get_hz(clk_sys)) / (aFrequencyKHz * 1000); // 3289.473 for 38 kHz @125 MHz clock. We have a 16 bit counter and use system clock (125 MHz) - pwm_config tPWMConfig = pwm_get_default_config(); + sIROutPuseWidthForHigh = tPWMWrapValue; pwm_config_set_wrap(&tPWMConfig, tPWMWrapValue - 1); pwm_init(sSliceNumberForSendPWM, &tPWMConfig, false); // we do not want to send now - sIROutPuseWidth = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT) / 100) - 1; // 985.84 for 38 kHz + sIROutPuseWidth = ((tPWMWrapValue * IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH) / 100) - 1; // 985.84 for 38 kHz pwm_set_chan_level(sSliceNumberForSendPWM, sChannelNumberForSendPWM, 0); pwm_set_enabled(sSliceNumberForSendPWM, true); +# else + sFrequency = aFrequencyKHz * 1000; +# endif } # endif // defined(SEND_PWM_BY_TIMER) /*************************************** * NRF5 boards like the BBC:Micro ***************************************/ -#elif defined(NRF5) || defined(ARDUINO_ARCH_NRF52840) +#elif defined(NRF5) || defined(ARDUINO_ARCH_NRF52840) || defined(ARDUINO_ARCH_NRF52) # if defined(SEND_PWM_BY_TIMER) #error PWM generation by hardware not implemented for NRF5 # endif @@ -1852,14 +2248,14 @@ void timerConfigForReceive() { # if defined(SEND_PWM_BY_TIMER) # if defined(IR_SEND_PIN) void enableSendPWMByTimer() { - analogWrite(IR_SEND_PIN, ((256L * 100) / IR_SEND_DUTY_CYCLE_PERCENT)), ir_out_kHz*1000); + analogWrite(IR_SEND_PIN, ((255L * 100) / IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH)), ir_out_kHz*1000); } void disableSendPWMByTimer() { analogWrite(IR_SEND_PIN, 0, ir_out_kHz*1000); } # else void enableSendPWMByTimer() { - analogWrite(IrSender.sendPin, ((256L * 100) / IR_SEND_DUTY_CYCLE_PERCENT), ir_out_kHz * 1000); + analogWrite(IrSender.sendPin, ((255L * 100) / IR_SEND_DUTY_CYCLE_PERCENT_FOR_LEVEL_HIGH), ir_out_kHz * 1000); } void disableSendPWMByTimer() { analogWrite(IrSender.sendPin, 0, ir_out_kHz * 1000); @@ -1882,10 +2278,52 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { } # endif // defined(SEND_PWM_BY_TIMER) +#elif defined(VEGA_ARIES_V2) || defined(VEGA_ARIES_V3) || defined(VEGA_ARIES_IOT) || defined(VEGA_ARIES_MICRO) +#include "Timer.h" +Timer Timer(0); + +#define TIMER_RESET_INTR_PENDING +#define TIMER_ENABLE_RECEIVE_INTR Timer.attachInterrupt(IRTimerInterruptHandler) +#define TIMER_DISABLE_RECEIVE_INTR Timer.detachInterrupt() + +void timerEnableReceiveInterrupt() { + Timer.resume(); +} +void timerDisableReceiveInterrupt() { + Timer.stop(); +} + +# if defined(ISR) +#undef ISR +# endif +#define ISR() void IRTimerInterruptHandler(void) +void IRTimerInterruptHandler(void); + +void timerConfigForReceive() { + Timer.initialize(MICROS_PER_TICK); // 50 uS + Timer.attachInterrupt(IRTimerInterruptHandler); + Timer.resume(); +} + +# if defined(SEND_PWM_BY_TIMER) +#define ENABLE_SEND_PWM_BY_TIMER +#define DISABLE_SEND_PWM_BY_TIMER + +void timerConfigForSend(uint8_t aFrequencyKHz) { + TIMER_DISABLE_RECEIVE_INTR; +# if defined(IR_SEND_PIN) + pinMode(IR_SEND_PIN, OUTPUT); +# else + pinMode(IrSender.sendPin, OUTPUT); +# endif + (void) aFrequencyKHz; +} +# endif // defined(SEND_PWM_BY_TIMER) + +#else // CPU types /*************************************** * Unknown CPU board ***************************************/ -#else #error Internal code configuration error, no timer functions implemented for this CPU / board /* * Dummy definitions to avoid more irritating compile errors @@ -1918,9 +2356,12 @@ void timerConfigForSend(uint16_t aFrequencyKHz) { (void) aFrequencyKHz; } # endif // defined(SEND_PWM_BY_TIMER) - #endif // defined(DOXYGEN / CPU_TYPES) +#if defined(SEND_PWM_BY_TIMER) && defined(IR_SEND_PIN) +#pragma message("INFO: Value of IR_SEND_PIN determined by SEND_PWM_BY_TIMER is: " STR(IR_SEND_PIN)) +#endif + /** @}*/ /** @}*/ #endif // _IR_TIMER_HPP