Compare commits
2 Commits
7c7ced8ecb
...
2c2be06431
Author | SHA1 | Date |
---|---|---|
Armin | 2c2be06431 | |
Buzzerb | 483aaa2cc3 |
|
@ -30,6 +30,6 @@ 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 macro to TinyIR.
|
||||
- [Buzzerb](https://github.com/Buzzerb) Added Extended NEC protocol to TinyIR and making it more consistent.
|
||||
|
||||
Note: Please let [ArminJo](https://github.com/ArminJo) know if you have been missed.
|
||||
|
|
|
@ -447,7 +447,7 @@ void loop() {
|
|||
#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() {}
|
||||
|
@ -604,7 +604,7 @@ They use pin change interrupt for on the fly decoding, which is the reason for t
|
|||
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**.<br/>
|
||||
It sends NEC protocol codes in standard format with 8 bit address and 8 bit command as in SimpleSender example.
|
||||
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
|
||||
|
|
|
@ -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:
|
||||
|
@ -21,7 +23,7 @@
|
|||
************************************************************************************
|
||||
* 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
|
||||
|
@ -46,12 +48,6 @@
|
|||
|
||||
#include "PinDefinitionsAndMore.h" // Set IR_SEND_PIN for different CPU's
|
||||
|
||||
//#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 "TinyIRSender.hpp"
|
||||
|
||||
void setup() {
|
||||
|
@ -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
|
||||
|
|
12
src/TinyIR.h
12
src/TinyIR.h
|
@ -34,9 +34,9 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#define VERSION_TINYIR "2.0.0"
|
||||
#define VERSION_TINYIR "2.1.0"
|
||||
#define VERSION_TINYIR_MAJOR 2
|
||||
#define VERSION_TINYIR_MINOR 0
|
||||
#define VERSION_TINYIR_MINOR 1
|
||||
#define VERSION_TINYIR_PATCH 0
|
||||
// The change log is at the bottom of the file
|
||||
|
||||
|
@ -256,12 +256,16 @@ void printTinyReceiverResultMinimal(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);
|
||||
|
||||
/*
|
||||
* 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().
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
************************************************************************************
|
||||
* 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
|
||||
|
@ -59,7 +59,7 @@
|
|||
* - 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.
|
||||
* - 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 both the 16 bit address and command each 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 fixed function "void handleReceivedTinyIRData()" each time a frame or repeat is received.
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
************************************************************************************
|
||||
* 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
|
||||
|
@ -105,12 +105,13 @@ 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);
|
||||
|
||||
uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
|
||||
|
@ -118,13 +119,10 @@ void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast
|
|||
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
|
||||
{
|
||||
} else {
|
||||
// send header
|
||||
delayMicroseconds(NEC_HEADER_SPACE);
|
||||
LongUnion tData;
|
||||
|
@ -158,15 +156,16 @@ void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast
|
|||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
|
||||
|
@ -174,13 +173,10 @@ void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_
|
|||
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
|
||||
{
|
||||
} else {
|
||||
// send header
|
||||
delayMicroseconds(NEC_HEADER_SPACE);
|
||||
LongUnion tData;
|
||||
|
@ -228,6 +224,63 @@ void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* LSB first, send header, command, inverted command and stop bit
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue