44 #ifndef _TINY_IR_SENDER_HPP
45 #define _TINY_IR_SENDER_HPP
51 #if defined(DEBUG) && !defined(LOCAL_DEBUG)
63 #if !defined(IR_SEND_PIN)
64 #warning "IR_SEND_PIN is not defined, so it is set to 3"
70 void sendMark(uint8_t aSendPin,
unsigned int aMarkMicros) {
71 unsigned long tStartMicros = micros();
72 unsigned long tNextPeriodEnding = tStartMicros;
73 unsigned long tMicros;
88 tNextPeriodEnding += 26;
94 unsigned int tDeltaMicros = tMicros - tStartMicros;
99 if (tDeltaMicros >= aMarkMicros) {
103 }
while (tMicros < tNextPeriodEnding);
114 void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
117 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
118 while (tNumberOfCommands > 0) {
119 unsigned long tStartOfFrameMillis = millis();
122 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
132 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
134 if (tData.
ULong & 1) {
146 if (tNumberOfCommands > 0) {
150 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
165 void sendNECMinimal(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
166 sendNEC(aSendPin, aAddress, aCommand, aNumberOfRepeats);
168 void sendNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
171 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
172 while (tNumberOfCommands > 0) {
173 unsigned long tStartOfFrameMillis = millis();
176 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
187 if (aAddress > 0xFF) {
193 if (aCommand > 0xFF) {
200 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
203 if (tData.
ULong & 1) {
215 if (tNumberOfCommands > 0) {
219 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
234 void sendExtendedNEC(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats,
bool aSendNEC2Repeats) {
237 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
238 while (tNumberOfCommands > 0) {
239 unsigned long tStartOfFrameMillis = millis();
242 if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) {
250 if (aCommand > 0xFF) {
257 for (uint_fast8_t i = 0; i <
NEC_BITS; ++i) {
260 if (tData.
ULong & 1) {
272 if (tNumberOfCommands > 0) {
276 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
288 sendFAST(aSendPin, aCommand, aNumberOfRepeats);
294 void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) {
297 uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
298 while (tNumberOfCommands > 0) {
299 unsigned long tStartOfFrameMillis = millis();
309 if (aCommand > 0xFF) {
312 tData = aCommand | (((uint8_t) (~aCommand)) << 8);
315 for (uint_fast8_t i = 0; i <
FAST_BITS; ++i) {
330 if (tNumberOfCommands > 0) {
334 auto tFrameDurationMillis = millis() - tStartOfFrameMillis;
344 #if defined(LOCAL_DEBUG)
347 #endif // _TINY_IR_SENDER_HPP