44 #ifndef _TINY_IR_SENDER_HPP
45 #define _TINY_IR_SENDER_HPP
60 #if !defined(IR_SEND_PIN)
61 #warning "IR_SEND_PIN is not defined, so it is set to 3"
64 #if !defined(NO_LED_SEND_FEEDBACK_CODE)
65 #define LED_SEND_FEEDBACK_CODE // Resolve the double negative
71 void sendMark(uint8_t aSendPin,
unsigned int aMarkMicros) {
72 unsigned long tStartMicros = micros();
73 unsigned long tNextPeriodEnding = tStartMicros;
74 unsigned long tMicros;
89 tNextPeriodEnding += 26;
95 unsigned int tDeltaMicros = tMicros - tStartMicros;
100 if (tDeltaMicros >= aMarkMicros) {
104 }
while (tMicros < tNextPeriodEnding);
115 void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
118 #if !defined(NO_LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
120 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
127 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
128 while (tNumberOfCommands > 0) {
129 unsigned long tStartOfFrameMillis = millis();
132 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
142 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
144 if (tData.
ULong & 1) {
156 if (tNumberOfCommands > 0) {
160 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
166 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
168 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
183 void sendNECMinimal(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
184 sendNEC(aSendPin, aAddress, aCommand, aNumberOfRepeats);
186 void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
189 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
191 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
198 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
199 while (tNumberOfCommands > 0) {
200 unsigned long tStartOfFrameMillis = millis();
203 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
214 if (aAddress > 0xFF) {
220 if (aCommand > 0xFF) {
227 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
230 if (tData.
ULong & 1) {
242 if (tNumberOfCommands > 0) {
246 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
252 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
254 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
269 void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
272 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
274 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
281 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
282 while (tNumberOfCommands > 0) {
283 unsigned long tStartOfFrameMillis = millis();
286 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
294 if (aCommand > 0xFF) {
301 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
304 if (tData.
ULong & 1) {
316 if (tNumberOfCommands > 0) {
320 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
326 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
328 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
340 sendFAST(aSendPin, aCommand, aNumberOfRepeats);
346 void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
349 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
351 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
358 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
359 while (tNumberOfCommands > 0) {
360 unsigned long tStartOfFrameMillis = millis();
370 if (aCommand > 0xFF) {
373 tData = aCommand | (((uint8_t) (~aCommand)) << 8);
376 for (uint_fast8_t i = 0; i <
FAST_BITS; ++i) {
391 if (tNumberOfCommands > 0) {
395 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
401 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
403 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
413 #endif // _TINY_IR_SENDER_HPP