34 #ifndef _IR_PRONTO_HPP
35 #define _IR_PRONTO_HPP
37 #if defined(DEBUG) && !defined(LOCAL_DEBUG)
49 static const uint16_t learnedToken = 0x0000U;
50 static const uint16_t learnedNonModulatedToken = 0x0100U;
51 static const uint16_t bitsInHexadecimal = 4U;
52 static const uint16_t digitsInProntoNumber = 4U;
53 static const uint16_t numbersInPreamble = 4U;
54 static const uint16_t hexMask = 0xFU;
55 static const uint32_t referenceFrequency = 4145146UL;
56 static const uint16_t fallbackFrequency = 64767U;
57 static const uint32_t microsecondsInSeconds = 1000000UL;
58 static const uint16_t PRONTO_DEFAULT_GAP = 45000;
62 return ((referenceFrequency / code) + 500) / 1000;
71 uint16_t timebase = (microsecondsInSeconds * data[1] + referenceFrequency / 2) / referenceFrequency;
77 case learnedNonModulatedToken:
83 uint16_t intros = 2 * data[2];
84 uint16_t repeats = 2 * data[3];
85 #if defined(LOCAL_DEBUG)
86 Serial.print(F(
"sendPronto intros="));
88 Serial.print(F(
" repeats="));
89 Serial.println(repeats);
91 if (numbersInPreamble + intros + repeats != length) {
99 uint16_t durations[intros + repeats];
100 for (uint16_t i = 0; i < intros + repeats; i++) {
101 uint32_t duration = ((uint32_t) data[i + numbersInPreamble]) * timebase;
102 durations[i] = (uint16_t) ((duration <= UINT16_MAX) ? duration : UINT16_MAX);
110 sendRaw(durations, intros - 1, khz);
125 sendRaw(durations + intros, repeats - 1, khz);
150 size_t len = strlen(str) / (digitsInProntoNumber + 1) + 1;
154 for (uint16_t i = 0; i < len; i++) {
155 long x = strtol(p, endptr, 16);
156 if (x == 0 && i >= numbersInPreamble) {
161 data[i] =
static_cast<uint16_t
>(x);
174 void IRsend::sendPronto_PF(uint_farptr_t str, int_fast8_t aNumberOfRepeats) {
175 size_t len = strlen_PF(str);
177 strcpy_PF(work, str);
182 void IRsend::sendPronto_P(
const char *str, int_fast8_t aNumberOfRepeats) {
183 size_t len = strlen_P(str);
194 size_t len = strlen_P(
reinterpret_cast<const char*
>(str));
196 strcpy_P(work,
reinterpret_cast<const char*
>(str));
201 return frequency > 0 ? frequency : fallbackFrequency;
213 return (
char) (x <= 9 ? (
'0' + x) : (
'A' + (x - 10)));
216 static void dumpDigit(Print *aSerial, uint16_t number) {
221 for (uint16_t i = 0; i < digitsInProntoNumber; i++) {
222 uint16_t shifts = bitsInHexadecimal * (digitsInProntoNumber - 1 - i);
223 dumpDigit(aSerial, (number >> shifts) & hexMask);
228 static void dumpDuration(Print *aSerial, uint32_t duration, uint16_t timebase) {
229 dumpNumber(aSerial, (duration + timebase / 2) / timebase);
236 for (
size_t i = 0; i < length; i++) {
258 aSerial->println(F(
"Pronto Hex as string"));
259 aSerial->print(F(
"char prontoData[] = \""));
260 dumpNumber(aSerial, aFrequencyHertz > 0 ? learnedToken : learnedNonModulatedToken);
264 uint16_t timebase =
toTimebase(aFrequencyHertz);
266 aSerial->println(
"\";");
274 static bool dumpDigit(String *aString, uint16_t number) {
283 for (uint16_t i = 0; i < digitsInProntoNumber; i++) {
284 uint16_t shifts = bitsInHexadecimal * (digitsInProntoNumber - 1 - i);
285 size +=
dumpDigit(aString, (number >> shifts) & hexMask);
287 aString->concat(
' ');
296 static size_t dumpDuration(String *aString, uint32_t duration, uint16_t timebase) {
297 return dumpNumber(aString, (duration + timebase / 2) / timebase);
304 for (
size_t i = 0; i < length; i++) {
316 size +=
dumpDuration(aString, PRONTO_DEFAULT_GAP, timebase);
330 size +=
dumpNumber(aString, frequency > 0 ? learnedToken : learnedNonModulatedToken);
341 #if defined(LOCAL_DEBUG)
344 #endif // _IR_PRONTO_HPP