* Parse the string given as Pronto Hex, and send it a number of times given as argument. * The first number denotes the type of the signal. 0000 denotes a raw IR signal with modulation, // The second number denotes a frequency code */
| 66 | // The second number denotes a frequency code |
| 67 | */ |
| 68 | void IRsend::sendPronto(const uint16_t *data, uint16_t length, int_fast8_t aNumberOfRepeats) { |
| 69 | uint16_t timebase = (microsecondsInSeconds * data[1] + referenceFrequency / 2) / referenceFrequency; |
| 70 | uint16_t khz; |
| 71 | switch (data[0]) { |
| 72 | case learnedToken: // normal, "learned" |
| 73 | khz = toFrequencyKHz(data[1]); |
| 74 | break; |
| 75 | case learnedNonModulatedToken: // non-demodulated, "learned" |
| 76 | khz = 0U; |
| 77 | break; |
| 78 | default: |
| 79 | return; // There are other types, but they are not handled yet. |
| 80 | } |
| 81 | uint16_t intros = 2 * data[2]; |
| 82 | uint16_t repeats = 2 * data[3]; |
| 83 | |
| 84 | DEBUG_PRINT(F("sendPronto intros=")); |
| 85 | DEBUG_PRINT(intros); |
| 86 | DEBUG_PRINT(F(" repeats=")); |
| 87 | DEBUG_PRINTLN(repeats); |
| 88 | |
| 89 | if (numbersInPreamble + intros + repeats != length) { // inconsistent sizes |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | * Generate a new microseconds timing array for sendRaw. |
| 95 | * If recorded by IRremote, intro contains the whole IR data and repeat is empty |
| 96 | */ |
| 97 | uint16_t durations[intros + repeats]; |
| 98 | for (uint16_t i = 0; i < intros + repeats; i++) { |
| 99 | uint32_t duration = ((uint32_t) data[i + numbersInPreamble]) * timebase; |
| 100 | durations[i] = (uint16_t)((duration <= UINT16_MAX) ? duration : UINT16_MAX); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Send the intro. intros is even. |
| 105 | * Do not send the trailing space here, send it if repeats are requested |
| 106 | */ |
| 107 | if (intros >= 2) { |
| 108 | sendRaw(durations, intros - 1, khz); |
| 109 | } |
| 110 | |
| 111 | if (repeats == 0 || aNumberOfRepeats == 0) { |
| 112 | // only send intro once |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Now send the trailing space/gap of the intro and all the repeats |
| 118 | */ |
| 119 | if (intros >= 2) { |
| 120 | delay(durations[intros - 1] / MICROS_IN_ONE_MILLI); // equivalent to space(durations[intros - 1]); but allow bigger values for the gap |
| 121 | } |
| 122 | for (int i = 0; i < aNumberOfRepeats; i++) { |
| 123 | sendRaw(durations + intros, repeats - 1, khz); |
| 124 | if ((i + 1) < aNumberOfRepeats) { // skip last trailing space/gap, see above |
| 125 | delay(durations[intros + repeats - 1] / MICROS_IN_ONE_MILLI); |
nothing calls this directly
no test coverage detected