13 void enableIROut(
int freq) {
14 printf(
"\nFreq = %d KHz\n", freq);
28 return (((ch >=
'0') && (ch <=
'9')) || ((ch >=
'A') && (ch <=
'F')) || ((ch >=
'a') && (ch <=
'f'))) ? true :
false;
34 bool isblank(
char ch) {
35 return ((ch ==
' ') || (ch ==
'\t') || (ch ==
'\0')) ? true :
false;
41 void byp(
char** pcp) {
42 while (isblank(**pcp))
50 uint8_t htob(
char ch) {
51 if ((ch >=
'0') && (ch <=
'9')) {
54 if ((ch >=
'A') && (ch <=
'F')) {
57 if ((ch >=
'a') && (ch <=
'f')) {
68 uint16_t htow(
char* cp) {
69 return ((htob(cp[0]) << 12) | (htob(cp[1]) << 8) | (htob(cp[2]) << 4) | (htob(cp[3])));
74 bool sendPronto(
char* s,
bool repeat,
bool fallback) {
85 for (cp = s; *cp; cp += 4) {
87 if (!ishex(cp[0]) || !ishex(cp[1]) || !ishex(cp[2]) || !ishex(cp[3]) || !isblank(cp[4])) {
97 if (htow(cp) != 0000) {
104 freq = (int) (1000000 / (htow(cp) * 0.241246));
105 usec = (int) (((1.0 / freq) * 1000000) + 0.5);
123 len = once * 2, skip = 0;
126 len = rpt * 2, skip = 0;
130 len = rpt * 2, skip = 0;
133 len = once * 2, skip = 0;
138 len = once * 2, skip = 0;
141 len = rpt * 2, skip = once;
146 for (i = 0; i < skip; i++, cp += 4) {
152 for (i = 0; i < len; i++) {
155 space(htow(cp) * usec);
157 mark(htow(cp) * usec);
167 #define PRONTO_ONCE false
168 #define PRONTO_REPEAT true
169 #define PRONTO_FALLBACK true
170 #define PRONTO_NOFALLBACK false
173 char prontoTest[] =
"0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 "
174 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
175 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
176 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 "
177 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
178 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 "
179 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
180 "0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 "
181 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 "
182 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 "
183 "0010 0030 0010 0aa6";
195 #endif // SEND_PRONTO
214 char prontoTest[] =
"0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 "
215 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
216 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
217 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 "
218 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
219 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 "
220 "0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 "
221 "0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 "
222 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 "
223 "0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 "
224 "0010 0030 0010 0aa6";
237 uint16_t code[CODEMAX];
303 uint8_t code[CODEMAX];
307 #define DEBUGF(...) printf(__VA_ARGS__)
312 bool validate(
char* cp,
int* len) {
313 for (*len = 0; *cp; (*len)++, cp += 4) {
315 if (!ishex(cp[0]) || !ishex(cp[1]) || !ishex(cp[2]) || !ishex(cp[3]) || !isblank(cp[4]))
326 uint8_t htob(
char ch) {
327 if ((ch >=
'0') && (ch <=
'9')) {
330 if ((ch >=
'A') && (ch <=
'F')) {
331 return ch -
'A' + 10;
333 if ((ch >=
'a') && (ch <=
'f')) {
334 return ch -
'a' + 10;
343 uint16_t htow(
char* cp) {
344 return ((htob(cp[0]) << 12) | (htob(cp[1]) << 8) | (htob(cp[2]) << 4) | (htob(cp[3])));
350 bool decode(
char* s, pronto_t* p, irCode_t* ir) {
355 if (!validate(s, &p->codeLen)) {
356 DEBUGF(
"Invalid pronto string\n");
359 DEBUGF(
"Found %d hex codes\n", p->codeLen);
368 if (p->codeLen > CODEMAX) {
369 DEBUGF(
"Code too long, edit CODEMAX and recompile\n");
375 for (i = 0; i < p->codeLen; i++, cp += 4) {
377 p->code[i] = htow(cp);
381 DEBUGF(
"Input: |%s|\n", s);
383 for (i = 0; i < p->codeLen; i++) {
384 DEBUGF(
"%04x ", p->code[i]);
388 DEBUGF(
"Form [%04X] : ", p->code[0]);
389 if (p->code[0] == 0x0000) {
390 DEBUGF(
"Oscillated (Learned)\n");
391 }
else if (p->code[0] == 0x0100) {
392 DEBUGF(
"Unmodulated\n");
396 if (p->code[0] != 0x0000) {
402 p->freq = (int) (1000000 / (p->code[1] * 0.241246));
403 p->usec = (int) (((1.0 / p->freq) * 1000000) + 0.5);
404 ir->code[0] = p->freq / 1000;
405 DEBUGF(
"Freq [%04X] : %d Hz (%d uS/pluse) -> %d KHz\n", p->code[1], p->freq, p->usec, ir->code[0]);
408 p->onceLen = p->code[2];
409 p->once = &p->code[4];
410 ir->code[1] = p->onceLen;
411 DEBUGF(
"Once [%04X] : %d\n", p->code[2], p->onceLen);
414 p->rptLen = p->code[3];
415 p->rpt = &p->code[4 + p->onceLen];
416 ir->code[2] = p->rptLen;
417 DEBUGF(
"Rpt [%04X] : %d\n", p->code[3], p->rptLen);
420 if (1 + 1 + 1 + 1 + (p->onceLen * 2) + (p->rptLen * 2) != p->codeLen) {
421 DEBUGF(
"Bad code length\n");
426 ir->FF = p->code[p->codeLen - 1];
428 len = (p->onceLen * 2) + (p->rptLen * 2);
429 DEBUGF(
"Encoded: |");
430 for (i = 0; i < len; i++) {
431 if (p->code[i + 4] == ir->FF) {
432 ir->code[i + 3] = 0xFF;
433 }
else if (p->code[i + 4] > 0xFE) {
434 DEBUGF(
"\n%04X : Mark/Space overflow\n", p->code[i + 4]);
437 ir->code[i + 3] = (p->code[i + 4] * p->usec) /
USECPERTICK;
439 DEBUGF(
"%s%d", !i ?
"" : (i & 1 ?
"," :
", "), ir->code[i + 3]);
444 DEBUGF(
"FF -> %d\n", ir->FF);
451 void irDump(irCode_t* ir) {
454 printf(
"uint8_t buttonName[%d] = {", len);
456 printf(
"%d,%d, ", (ir->FF >> 8), ir->FF & 0xFF);
457 printf(
"%d,%d,%d, ", ir->code[0], ir->code[1], ir->code[2]);
459 len = (ir->code[1] * 2) + (ir->code[2] * 2);
460 for (i = 0; i < len; i++) {
461 printf(
"%s%d", !i ?
"" : (i & 1 ?
"," :
", "), ir->code[i + 3]);
474 decode(prontoTest, &pCode, &irCode);