44 #ifndef _TINY_IR_SENDER_HPP
45 #define _TINY_IR_SENDER_HPP
65 #if !defined(IR_SEND_PIN)
66 #warning "IR_SEND_PIN is not defined, so it is set to 3"
69 #if !defined(NO_LED_SEND_FEEDBACK_CODE)
70 #define LED_SEND_FEEDBACK_CODE // Resolve the double negative
76 void sendMark(uint8_t aSendPin,
unsigned int aMarkMicros) {
77 unsigned long tStartMicros = micros();
78 unsigned long tNextPeriodEnding = tStartMicros;
79 unsigned long tMicros;
94 tNextPeriodEnding += 26;
100 unsigned int tDeltaMicros = tMicros - tStartMicros;
105 if (tDeltaMicros >= aMarkMicros) {
109 }
while (tMicros < tNextPeriodEnding);
120 void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
123 #if !defined(NO_LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
125 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
132 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
133 while (tNumberOfCommands > 0) {
134 unsigned long tStartOfFrameMillis = millis();
137 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
147 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
149 if (tData.
ULong & 1) {
161 if (tNumberOfCommands > 0) {
165 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
171 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
173 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
188 void sendNECMinimal(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
189 sendNEC(aSendPin, aAddress, aCommand, aNumberOfRepeats);
191 void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
194 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
196 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
203 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
204 while (tNumberOfCommands > 0) {
205 unsigned long tStartOfFrameMillis = millis();
208 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
219 if (aAddress > 0xFF) {
225 if (aCommand > 0xFF) {
232 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
235 if (tData.
ULong & 1) {
247 if (tNumberOfCommands > 0) {
251 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
257 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
259 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
274 void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
277 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
279 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
286 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
287 while (tNumberOfCommands > 0) {
288 unsigned long tStartOfFrameMillis = millis();
291 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
299 if (aCommand > 0xFF) {
306 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
309 if (tData.
ULong & 1) {
321 if (tNumberOfCommands > 0) {
325 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
331 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
333 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
345 sendFAST(aSendPin, aCommand, aNumberOfRepeats);
351 void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
354 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
356 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
363 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
364 while (tNumberOfCommands > 0) {
365 unsigned long tStartOfFrameMillis = millis();
375 if (aCommand > 0xFF) {
378 tData = aCommand | (((uint8_t) (~aCommand)) << 8);
381 for (uint_fast8_t i = 0; i <
FAST_BITS; ++i) {
396 if (tNumberOfCommands > 0) {
400 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
406 #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN)
408 # if defined(FEEDBACK_LED_IS_ACTIVE_LOW)
418 #if defined(LOCAL_DEBUG)
421 #endif // _TINY_IR_SENDER_HPP