удалила лишнее

This commit is contained in:
KLASSENTS 2025-01-16 16:57:45 +07:00
parent ffd72d6bd9
commit 2ce95a5ab1

View File

@ -34,10 +34,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
//#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. * 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 Bang&Olufsen) are active.
@ -62,24 +58,14 @@
//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols //#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols
//#define DECODE_HASH // special decoder for all 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_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.
// !!! 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
// etc. see IRremote.hpp // etc. see IRremote.hpp
// //
#if !defined(RAW_BUFFER_LENGTH)
// For air condition remotes it requires 750. Default is 200.
# if !((defined(RAMEND) && RAMEND <= 0x4FF) || (defined(RAMSIZE) && RAMSIZE < 0x4FF))
#define RAW_BUFFER_LENGTH 730 // this allows usage of 16 bit raw buffer, for RECORD_GAP_MICROS > 20000
# 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_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 IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK // saves 32 bytes program memory #define IR_REMOTE_DISABLE_RECEIVE_COMPLETE_CALLBACK // saves 32 bytes program memory
// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding, // 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 142.
@ -94,29 +80,21 @@
#include <IRremote.hpp> #include <IRremote.hpp>
#if defined(APPLICATION_PIN) #define STR_HELPER(x) #x
#define DEBUG_BUTTON_PIN APPLICATION_PIN // if low, print timing for each received data set #define STR(x) STR_HELPER(x)
#else
#define DEBUG_BUTTON_PIN 6 #define IR_RECEIVE_PIN P0_11
#endif // #define IR_SEND_PIN 3
// #define TONE_PIN P0_4
void generateTone();
void handleOverflow(); void handleOverflow();
bool detectLongPress(uint16_t aLongPressDurationMillis); bool detectLongPress(uint16_t aLongPressDurationMillis);
void setup() { void setup() {
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc. Serial.begin(9600);
pinMode(DEBUG_BUTTON_PIN, INPUT_PULLUP);
#endif
Serial.begin(115200);
while (!Serial) while (!Serial)
; // Wait for Serial to become available. Is optimized away for some cores. ; // Wait for Serial to become available. Is optimized away for some cores.
#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 // 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("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
@ -129,36 +107,16 @@ void setup() {
Serial.print(F("Ready to receive IR signals of protocols: ")); Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial); printActiveIRProtocols(&Serial);
#if defined(IR_RECEIVE_PIN_STRING)
Serial.println(F("at pin " IR_RECEIVE_PIN_STRING));
#else
Serial.println(F("at pin " STR(IR_RECEIVE_PIN))); 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.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 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();
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 and tone is disabled"));
// infos for receive // infos for receive
Serial.print(RECORD_GAP_MICROS); Serial.print(RECORD_GAP_MICROS);
Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed")); Serial.println(F(" us is the (minimum) gap, after which the start of a new IR packet is assumed"));
Serial.print(MARK_EXCESS_MICROS); Serial.print(MARK_EXCESS_MICROS);
Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding")); Serial.println(F(" us are subtracted from all marks and added to all spaces for decoding"));
#endif
} }
void loop() { void loop() {
@ -172,44 +130,25 @@ void loop() {
*/ */
if (IrReceiver.decode()) { if (IrReceiver.decode()) {
Serial.println(); Serial.println();
#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) { if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
handleOverflow(); handleOverflow();
} else { } else {
/* /*
* No overflow here. * No overflow here.
* Stop receiver, generate a single beep, print short info and send usage and start receiver again * Stop receiver, print short info and send usage and start receiver again
*/ */
if ((IrReceiver.decodedIRData.protocol != SONY) && (IrReceiver.decodedIRData.protocol != PULSE_WIDTH)
&& (IrReceiver.decodedIRData.protocol != PULSE_DISTANCE) && (IrReceiver.decodedIRData.protocol != UNKNOWN)
&& digitalRead(DEBUG_BUTTON_PIN) != LOW) {
/*
* 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();
}
/* if (IrReceiver.decodedIRData.protocol == UNKNOWN)
* Print info {
*/
if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) {
// We have debug enabled or an unknown protocol, print extended info // We have debug enabled or an unknown protocol, print extended info
if (IrReceiver.decodedIRData.protocol == UNKNOWN) { if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
} }
IrReceiver.printIRResultRawFormatted(&Serial, true); IrReceiver.printIRResultRawFormatted(&Serial, true);
} }
if (IrReceiver.decodedIRData.protocol != UNKNOWN) { if (IrReceiver.decodedIRData.protocol != UNKNOWN)
{
/* /*
* The info output for a successful receive * The info output for a successful receive
*/ */
@ -217,7 +156,6 @@ void loop() {
IrReceiver.printIRSendUsage(&Serial); IrReceiver.printIRSendUsage(&Serial);
} }
} }
#endif // #if FLASHEND >= 0x3FFF
/* /*
* !!!Important!!! Enable receiving of the next value, because receiving * !!!Important!!! Enable receiving of the next value, because receiving
@ -255,44 +193,17 @@ void loop() {
} }
/*
* Stop receiver, generate a single beep and start receiver again
*/
void generateTone() {
#if !defined(ESP8266) && !defined(NRF5) // 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
}
void handleOverflow() { void handleOverflow() {
Serial.println(F("Overflow detected")); Serial.println(F("Overflow detected"));
Serial.println(F("Try to increase the \"RAW_BUFFER_LENGTH\" value of " STR(RAW_BUFFER_LENGTH) " in " __FILE__)); 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 // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
#if !defined(ESP8266) && !defined(NRF5) // 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(); IrReceiver.stopTimer();
tone(TONE_PIN, 1100, 10); // tone(TONE_PIN, 1100, 10);
delay(50); // delay(50);
tone(TONE_PIN, 1100, 10); // tone(TONE_PIN, 1100, 10);
delay(50); delay(50);
IrReceiver.restartTimer(); IrReceiver.restartTimer();
# endif
#endif
} }
unsigned long sMillisOfFirstReceive; unsigned long sMillisOfFirstReceive;