* 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. */
| 111 | * @param aSendNEC2Repeats - Instead of sending the NEC special repeat code, send the original frame for repeat. |
| 112 | */ |
| 113 | void sendONKYO(uint8_t aSendPin, uint16_t aAddress, uint16_t aCommand, uint_fast8_t aNumberOfRepeats, bool aSendNEC2Repeats) { |
| 114 | pinModeFast(aSendPin, OUTPUT); |
| 115 | |
| 116 | #if !defined(NO_LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) |
| 117 | pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); |
| 118 | # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) |
| 119 | digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); |
| 120 | # else |
| 121 | digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); |
| 122 | # endif |
| 123 | #endif |
| 124 | |
| 125 | uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; |
| 126 | while (tNumberOfCommands > 0) { |
| 127 | unsigned long tStartOfFrameMillis = millis(); |
| 128 | |
| 129 | sendMark(aSendPin, NEC_HEADER_MARK); |
| 130 | if ((!aSendNEC2Repeats) && (tNumberOfCommands < aNumberOfRepeats + 1)) { |
| 131 | // send the NEC special repeat |
| 132 | delayMicroseconds (NEC_REPEAT_HEADER_SPACE); // - 2250 |
| 133 | } else { |
| 134 | // send header |
| 135 | delayMicroseconds (NEC_HEADER_SPACE); |
| 136 | LongUnion tData; |
| 137 | tData.UWord.LowWord = aAddress; |
| 138 | tData.UWord.HighWord = aCommand; |
| 139 | // Send data |
| 140 | for (uint_fast8_t i = 0; i < NEC_BITS; ++i) { |
| 141 | sendMark(aSendPin, NEC_BIT_MARK); // constant mark length |
| 142 | if (tData.ULong & 1) { |
| 143 | delayMicroseconds (NEC_ONE_SPACE); |
| 144 | } else { |
| 145 | delayMicroseconds (NEC_ZERO_SPACE); |
| 146 | } |
| 147 | tData.ULong >>= 1; // shift command for next bit |
| 148 | } |
| 149 | } // send stop bit |
| 150 | sendMark(aSendPin, NEC_BIT_MARK); |
| 151 | |
| 152 | tNumberOfCommands--; |
| 153 | // skip last delay! |
| 154 | if (tNumberOfCommands > 0) { |
| 155 | /* |
| 156 | * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. |
| 157 | */ |
| 158 | auto tFrameDurationMillis = millis() - tStartOfFrameMillis; |
| 159 | if (NEC_REPEAT_PERIOD / 1000 > tFrameDurationMillis) { |
| 160 | delay(NEC_REPEAT_PERIOD / 1000 - tFrameDurationMillis); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) |
| 165 | pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); |
| 166 | # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) |
| 167 | digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); |
| 168 | # else |
| 169 | digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); |
| 170 | # endif |
nothing calls this directly
no test coverage detected