* LSB first, send header, 16 bit command or 8 bit command, inverted command and stop bit */
| 342 | * LSB first, send header, 16 bit command or 8 bit command, inverted command and stop bit |
| 343 | */ |
| 344 | void sendFAST(uint8_t aSendPin, uint16_t aCommand, uint_fast8_t aNumberOfRepeats) { |
| 345 | pinModeFast(aSendPin, OUTPUT); |
| 346 | |
| 347 | #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) |
| 348 | pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); |
| 349 | # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) |
| 350 | digitalWriteFast(IR_FEEDBACK_LED_PIN, LOW); |
| 351 | # else |
| 352 | digitalWriteFast(IR_FEEDBACK_LED_PIN, HIGH); |
| 353 | # endif |
| 354 | #endif |
| 355 | |
| 356 | uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1; |
| 357 | while (tNumberOfCommands > 0) { |
| 358 | unsigned long tStartOfFrameMillis = millis(); |
| 359 | |
| 360 | // send header |
| 361 | sendMark(aSendPin, FAST_HEADER_MARK); |
| 362 | delayMicroseconds(FAST_HEADER_SPACE); |
| 363 | uint16_t tData; |
| 364 | /* |
| 365 | * The compiler is intelligent and removes the code for "(aCommand > 0xFF)" if we are called with an uint8_t command :-). |
| 366 | * Using an uint16_t command requires additional 56 bytes program memory. |
| 367 | */ |
| 368 | if (aCommand > 0xFF) { |
| 369 | tData = aCommand; |
| 370 | } else { |
| 371 | tData = aCommand | (((uint8_t) (~aCommand)) << 8); // LSB first |
| 372 | } |
| 373 | // Send data |
| 374 | for (uint_fast8_t i = 0; i < FAST_BITS; ++i) { |
| 375 | sendMark(aSendPin, FAST_BIT_MARK); // constant mark length |
| 376 | |
| 377 | if (tData & 1) { |
| 378 | delayMicroseconds(FAST_ONE_SPACE); |
| 379 | } else { |
| 380 | delayMicroseconds(FAST_ZERO_SPACE); |
| 381 | } |
| 382 | tData >>= 1; // shift command for next bit |
| 383 | } |
| 384 | // send stop bit |
| 385 | sendMark(aSendPin, FAST_BIT_MARK); |
| 386 | |
| 387 | tNumberOfCommands--; |
| 388 | // skip last delay! |
| 389 | if (tNumberOfCommands > 0) { |
| 390 | /* |
| 391 | * Check and fallback for wrong RepeatPeriodMillis parameter. I.e the repeat period must be greater than each frame duration. |
| 392 | */ |
| 393 | auto tFrameDurationMillis = millis() - tStartOfFrameMillis; |
| 394 | if (FAST_REPEAT_PERIOD / 1000 > tFrameDurationMillis) { |
| 395 | delay(FAST_REPEAT_PERIOD / 1000 - tFrameDurationMillis); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | #if defined(LED_SEND_FEEDBACK_CODE) && defined(IR_FEEDBACK_LED_PIN) |
| 400 | pinModeFast(IR_FEEDBACK_LED_PIN, OUTPUT); |
| 401 | # if defined(FEEDBACK_LED_IS_ACTIVE_LOW) |
no test coverage detected