/
devpicolcd.c
658 lines (601 loc) · 18.2 KB
/
devpicolcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/*
* Library for using picolcd devices
*
* Written by Mandar Joshi (emailmandar at gmail.com)
* License: LGPL
*
*
*/
#include "devpicolcd.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/**
* PicoLCD Open Function
*
* Opens Requested PicoLCD Device
* @param whichDevice PICOLCD_20x2 or PICOLCD_20x4
* @return An initialized MyLcdDevice on success. NULL on failure
*/
MyLcdDevice* picolcd_open (unsigned int whichDevice) {
libusb_context *ctx;
MyLcdDevice *myLcdDevice;
switch (whichDevice) {
case PICOLCD_20x2:
myLcdDevice = &LcdDevices[0];
break;
case PICOLCD_20x4:
myLcdDevice = &LcdDevices[1];
break;
}
printf("libusb_init %d\n",libusb_init(&ctx));
libusb_set_debug(ctx,3);
/* libusb_open(myLcdDevice->lcdDevice, &myLcdDevice->lcdHandle);*/
myLcdDevice->lcdHandle = libusb_open_device_with_vid_pid (ctx, MINI_BOX, whichDevice);
if (!myLcdDevice->lcdHandle)
return NULL;
myLcdDevice->lcdDevice = libusb_get_device (myLcdDevice->lcdHandle);
libusb_detach_kernel_driver(myLcdDevice->lcdHandle,0);
libusb_claim_interface(myLcdDevice->lcdHandle,0);
libusb_set_interface_alt_setting(myLcdDevice->lcdHandle,0,0);
return myLcdDevice;
}
/**
* PicoLCD 20x2 Initialization Function
*
* The 20x2 doesn't need any initialization. This function just returns 0.
* @param lcdDevice Pointer to the LcdDevice structure
* @return returns 0
*/
int lcd_20x2_init(MyLcdDevice *lcdDevice) {
libusb_clear_halt(lcdDevice->lcdHandle, LIBUSB_ENDPOINT_IN + 1);
/* Initialize your decode stuff here*/
IR20x4 *ir20x4;
lcdDevice->irStruct=(void*)malloc(sizeof(IR20x4));
ir20x4=(IR20x4*)lcdDevice->irStruct;
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
ir20x4->rc5Raw=(unsigned char *)malloc(128); /*assuming each element in irData is a LONG_PULSE (1 1) or LONG_SPACE(0 0) */
memset(ir20x4->rc5Raw,0,128);
return 0;
}
/**
* PicoLCD 20x4 Initialization Function
*
* This initializes the 20x4 LCD.
* @param lcdDevice Pointer to the LcdDevice structure
* @return returns 0
*/
int lcd_20x4_init(MyLcdDevice *lcdDevice) {
lcdDevice->write_interrupt(lcdDevice,lcdDevice->initData,INIT_DATA_LEN);
/* Initialize your decode stuff here*/
IR20x4 *ir20x4;
lcdDevice->irStruct=(void*)malloc(sizeof(IR20x4));
ir20x4=(IR20x4*)lcdDevice->irStruct;
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
ir20x4->rc5Raw=(unsigned char *)malloc(128); /*assuming each element in irData is a LONG_PULSE (1 1) or LONG_SPACE(0 0) */
memset(ir20x4->rc5Raw,0,128);
return 0;
}
/**
* PicoLCD Set Backlight
*
* The sets the backlight brightness of the LcdDevice
* @param lcdDevice Pointer to the LcdDevice structure
* @param value Ranges frorm 0x00 to 0xFF. Higher the value, higher the brightness.
* @return returns 0
*/
int lcd_set_backlight(MyLcdDevice *lcdDevice,unsigned char value) {
unsigned char lcdPacket[2] = { 0x91 ,value};
lcdDevice->write_interrupt(lcdDevice,lcdPacket,2);
return 0;
}
/**
* PicoLCD Write Interrupt Function
*
* Does an interrupt write to the OUT Endpoint on the LcdDevice.
* @param lcdDevice Pointer to the LcdDevice structure
* @param data Pointer to data to be sent to the LcdDevice
* @param len Length of the data
* @return returns the number of bytes transferred to the LcdDevice
*/
int lcd_write_interrupt(MyLcdDevice *lcdDevice,unsigned char *data,int len) {
int transferred;
libusb_interrupt_transfer(lcdDevice->lcdHandle, LIBUSB_ENDPOINT_OUT + 1, (char *) data, len, &transferred,1000);
return transferred;
}
/**
* PicoLCD 20x4 Display Data Function
*
* Writes data to the 20x4 LcdDevice begining at the specified row and column
* @param lcdDevice Pointer to the LcdDevice structure
* @param row Row Number
* @param col Column Number
* @param data Pointer to data to be sent to the LcdDevice. Should be NULL terminated
* @return returns 0
*/
int lcd_20x4_display(MyLcdDevice *lcdDevice,int row,int col,unsigned char *data)
{
unsigned char lcdPacket[64]={0x95,0x01,0x00,0x01};
int len, i, ret;
int writeRow;
unsigned char rowBytes[4][6] = {
{ 0x94, 0x00, 0x01, 0x00, 0x64, 0x80+col },
{ 0x94, 0x00, 0x01, 0x00, 0x64, 0xC0+col },
{ 0x94, 0x00, 0x01, 0x00, 0x64, 0x94+col },
{ 0x94, 0x00, 0x01, 0x00, 0x64, 0xD4+col }
};
writeRow=row>3?0:row;
ret = lcdDevice->write_interrupt(lcdDevice,rowBytes[writeRow],6);
len = strlen((char *)data);
if(len+col>20)
len=20-col;
lcdPacket[4] = len;
memcpy(lcdPacket+5,data,len);
lcdDevice->write_interrupt(lcdDevice, lcdPacket, 5+len);
return ret;
}
/**
* PicoLCD 20x2 Display Data Function
*
* Writes data to the 20x2 LcdDevice begining at the specified row and column
* @param lcdDevice Pointer to the LcdDevice structure
* @param row Row Number
* @param col Column Number
* @param data Pointer to data to be sent to the LcdDevice. Should be NULL terminated
* @return returns 0
*/
int lcd_20x2_display(MyLcdDevice *lcdDevice,int row,int col,unsigned char *data)
{
int len, ret;
len = strlen((char *)data);
if (len+col > 20)
len = 20-col;
unsigned char lcdPacket[64]={0x98,row,col,len};
memcpy(lcdPacket+4,data,len);
ret = lcdDevice->write_interrupt(lcdDevice, lcdPacket, 4+len);
return ret;
}
/**
* PicoLCD 20x2 Clear Screen Function
*
* This clears the 20x2 screen
* @param lcdDevice Pointer to the LcdDevice structure
* @return returns 0
*/
int lcd_20x2_clear(MyLcdDevice *lcdDevice) {
lcdDevice->display(lcdDevice,0,0," ");
lcdDevice->display(lcdDevice,1,0," ");
return 0;
}
/**
* PicoLCD 20x4 Clear Screen Function
*
* This clears the 20x4 screen
* @param lcdDevice Pointer to the LcdDevice structure
* @return returns 0
*/
int lcd_20x4_clear(MyLcdDevice *lcdDevice) {
lcdDevice->display(lcdDevice,0,0," ");
lcdDevice->display(lcdDevice,1,0," ");
lcdDevice->display(lcdDevice,2,0," ");
lcdDevice->display(lcdDevice,3,0," ");
return 0;
}
/**
* PicoLCD 20x4 Set Char Function
*
* Sets the special character (1 -7) on the 20x4 LcdDevice
* @param lcdDevice Pointer to the LcdDevice structure
* @param n Character Number (1 -7)
* @param charData A 8 byte array. Each byte describes a 5 bit row
* @return returns 0
*/
int lcd_20x4_set_char (MyLcdDevice *lcdDevice, int n, unsigned char *charData)
{
unsigned char setCharCmd[6] = { 0x94, 0x00, 0x01, 0x00, 0x64, 0x40+8*n };
unsigned char setCharData[13] = { 0x95, 0x01, 0x00, 0x01, 0x08,
charData[0], charData[1], charData[2], charData[3],
charData[4], charData[5], charData[6], charData[7]};
lcdDevice->write_interrupt(lcdDevice, setCharCmd, 6);
lcdDevice->write_interrupt(lcdDevice, setCharData, 13);
return 0;
}
/**
* PicoLCD 20x2 Set Char Function
*
* Sets the special character (1 -7) on the 20x2 LcdDevice
* @param lcdDevice Pointer to the LcdDevice structure
* @param n Character Number (1 -7)
* @param charData A 8 byte array. Each byte describes a 5 bit row
* @return returns 0
*/
int lcd_20x2_set_char (MyLcdDevice *lcdDevice, int n, unsigned char *charData)
{
unsigned char lcdPacket[10] = { 0x9c,n,
charData[0], charData[1], charData[2], charData[3],
charData[4],charData[5],charData[6],charData[7] };
lcdDevice->write_interrupt(lcdDevice, lcdPacket, 10);
return 0;
}
/**
* PicoLCD 20x2 Set Key Lights Function
*
* Switches on or Switches off Lights on the Keys of the 20x2 LcdDevice
* @param lcdDevice Pointer to the LcdDevice structure
* @param lightSet 1 Byte data describing which lights to switch on
* @param state 1 to set the lights as per lightSet. 0 to switch them off
* @return returns 0
*/
int lcd_20x2_lights(MyLcdDevice *lcdDevice, unsigned char lightSet, int state) {
unsigned char lcdPacket[]={0x81,0xFF};
lcdPacket[1]=(state==0)?0:lightSet;
lcdDevice->write_interrupt(lcdDevice,lcdPacket,2);
return 0;
}
/**
* PicoLCD 20x4 Set Lights Function
*
* The 20x4 LcdDevice does not have key lights. This function just returns 0.
* @param lcdDevice Pointer to the LcdDevice structure
* @param lightSet 1 Byte data describing which lights to switch on
* @param state 1 to set the lights as per lightSet. 0 to switch them off
* @return returns 0
*/
int lcd_20x4_lights(MyLcdDevice *lcdDevice, unsigned char lightSet, int state) {
return 0;
}
/**
* Get a 2 byte null terminated array having the first byte as n
*
* This function is used to get the data required to display a special character
* @param n Special Character index (1 - 7)
* @return returns a 2 byte null terminated array having the first byte as n
*/
char * SpecialChar(int n) {
char *specialChar;
specialChar=(char *)malloc(2);
specialChar[0]=(char)n;
specialChar[1]=0;
return specialChar;
}
/**
* PicoLCD Read Input Function
*
* Reads input from user (IR and Key Press)
* @param lcdDevice Pointer to the LcdDevice structure
* @return returns an InputPacket which contains inputType, inputLen,inputData and keyCode;
*/
InputPacket* lcd_read_input(MyLcdDevice *lcdDevice) {
int ret=0,transferred;
unsigned char *recvBytes;
InputPacket *inputPacket;
inputPacket=(InputPacket*)malloc(sizeof(InputPacket));
inputPacket->inputData=(unsigned char*)malloc(lcdDevice->maxLen);
recvBytes=(unsigned char*)malloc(lcdDevice->maxLen+2);
int keyCode=-1,count=0;
while(1) {
ret = libusb_interrupt_transfer(lcdDevice->lcdHandle, LIBUSB_ENDPOINT_IN + 1, recvBytes, lcdDevice->maxLen, &transferred,0xFFFF);
// printf("recvBytes: %d %02X %02X %02X\n",transferred,recvBytes[0],recvBytes[1],recvBytes[2]);
if(ret==0) {
switch(recvBytes[0]) {
case KEY_INPUT:
// libusb_clear_halt(lcdDevice->lcdHandle, LIBUSB_ENDPOINT_IN + 1);
if(recvBytes[1]==0 && recvBytes[2]==0 && keyCode!=-1) {
inputPacket->inputType=KEY_INPUT;
inputPacket->keyCode=keyCode;
return inputPacket;
}
keyCode=recvBytes[1];
break;
case IR_INPUT:
// libusb_clear_halt(lcdDevice->lcdHandle, LIBUSB_ENDPOINT_IN + 1);
if(lcdDevice->irEnabled) {
inputPacket->inputType=IR_INPUT;
inputPacket->inputLen=recvBytes[1];
inputPacket->inputData=recvBytes+2;
return inputPacket;
}
break;
}
}
count++;
}
}
/**
* PicoLCD 20x4 IR Decode function for Philips RC5 Remotes
*
* Decodes IR Data
* @param irData Pointer to the received IR data
* @param len Length of the received IR data
* @return returns a short int. The binary format is 00<start-2-bits>0<address-5-bits><command-6-bits>
*/
short decode_rc5_20x4(unsigned char *irData,int len) {
int i;
short data;
IR20x4 *ir20x4;
if(len%2==1) {
#ifdef DEBUG
printf("len should be even\n");
#endif
return -1;
}
ir20x4=(IR20x4*)malloc(sizeof(IR20x4));
ir20x4->irData=(short *)irData;
ir20x4->irDataLen=len/2;
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
ir20x4->rc5Raw=(unsigned char *)malloc(ir20x4->irDataLen*2); /*assuming each element in irData is a LONG_PULSE (1 1) or LONG_SPACE(0 0) */
memset(ir20x4->rc5Raw,0,ir20x4->irDataLen*2);
#ifdef DEBUG
printf("irDataLen: %d\n",ir20x4->irDataLen);
#endif
for(i=0;i<ir20x4->irDataLen;i++) {
data=-ir20x4->irData[i];
// printf("(%d)",data);
if(data<0) {
data=abs(data);
if(data> 444 && data < 1333) {
#ifdef DEBUG
printf("_");
#endif
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
}
else if(data > 1334 && data < 2222) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
#ifdef DEBUG
printf("__");
#endif
}
else
return -1;
}
else {
if(data> 444 && data < 1333) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
#ifdef DEBUG
printf("-");
#endif
}
else if(data > 1334 && data < 2222) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
#ifdef DEBUG
printf("--");
#endif
}
else
return -1;
}
}
#ifdef DEBUG
printf("\n");
#endif
if(ir20x4->rawBitCount<0x1A) {
#ifdef DEBUG
printf("Not a Complete RC5 Code\n");
#endif
return -1;
}
#ifdef DEBUG
printf("RawBitCount:%d\n",ir20x4->rawBitCount);
for(i=0;i<ir20x4->rawBitCount;i++)
printf("%d",ir20x4->rc5Raw[i]);
printf("\n");
#endif
#ifdef DEBUG
printf("1\ti=0\n");
#endif
ir20x4->irCode[ir20x4->bitCount++]=1; /*it will always begins with 1 [at least with the Philips remote I have]*/
i=1; /* we skip the first bit as it is always 1 [at least with the Philips remote I have]*/
for(i=1;i<25;i+=2) {
#ifdef DEBUG
printf("%d %d = ",ir20x4->rc5Raw[i],ir20x4->rc5Raw[i+1]);
#endif
if(ir20x4->rc5Raw[i]==0 && ir20x4->rc5Raw[i+1]==1) {
#ifdef DEBUG
printf("1");
#endif
ir20x4->irCode[ir20x4->bitCount++]=1;
}
else if(ir20x4->rc5Raw[i]==1 && ir20x4->rc5Raw[i+1]==0) {
#ifdef DEBUG
printf("0");
#endif
ir20x4->irCode[ir20x4->bitCount++]=0;
}
else {
#ifdef DEBUG
printf("\nError: %d %d\n",ir20x4->rc5Raw[i],ir20x4->rc5Raw[i+1]);
#endif
return -1;
}
#ifdef DEBUG
printf("\ti=%d\n",i);
#endif
}
#ifdef DEBUG
printf("%d %d = ",ir20x4->rc5Raw[25],ir20x4->rc5Raw[26]);
#endif
if(ir20x4->rc5Raw[25]==0) {
#ifdef DEBUG
printf("1");
#endif
ir20x4->irCode[ir20x4->bitCount++]=1;
}
else if(ir20x4->rc5Raw[25]==1) {
#ifdef DEBUG
printf("0");
#endif
ir20x4->irCode[ir20x4->bitCount++]=0;
}
#ifdef DEBUG
printf("\n");
printf("BitCount:%d\n\n",ir20x4->bitCount);
printf("Address: %d %d %d %d %d\n",ir20x4->irCode[3],ir20x4->irCode[4],ir20x4->irCode[5],ir20x4->irCode[6],ir20x4->irCode[7]);
printf("Command: %d %d %d %d %d %d\n",ir20x4->irCode[8],ir20x4->irCode[9],ir20x4->irCode[10],ir20x4->irCode[11],ir20x4->irCode[12],ir20x4->irCode[13]);
#endif
ir20x4->address=(ir20x4->irCode[3]<<4)+(ir20x4->irCode[4]<<3)+(ir20x4->irCode[5]<<2)+(ir20x4->irCode[6]<<1)+(ir20x4->irCode[7]);
ir20x4->command=(ir20x4->irCode[8]<<5)+(ir20x4->irCode[9]<<4)+(ir20x4->irCode[10]<<3)+(ir20x4->irCode[11]<<2)+(ir20x4->irCode[12]<<1)+(ir20x4->irCode[13]);
#ifdef DEBUG
printf("Address:%u Command:%u\n",ir20x4->address,ir20x4->command);
#endif
return (ir20x4->irCode[0]<<13)+(ir20x4->irCode[1]<<12)+(ir20x4->address << 6) + ir20x4->command;
}
/**
* PicoLCD 20x2 IR Decode function for Philips RC5 Remotes
*
* Decodes IR Data
* @param irData Pointer to the received IR data
* @param len Length of the received IR data
* @return returns address and command. address=(return >> 6)&0x1F. command=return&0x3F
*/
short decode_rc5_20x2(unsigned char *irData,int len) {
return decode_rc5_20x4(irData,len);
}
/**
* PicoLCD 20x4 IR Decode function for Philips RC5 Remotes
*
* Decodes IR Data
* @param irData Pointer to the received IR data
* @param len Length of the received IR data
* @return returns a short int. The binary format is 00<start-2-bits>0<address-5-bits><command-6-bits>
*/
short decode_rc5_20x4_new(MyLcdDevice *lcdDevice,unsigned char *irData,int len) {
int i;
short data;
IR20x4 *ir20x4=(IR20x4*)lcdDevice->irStruct;
ir20x4->irData=(short *)irData;
ir20x4->irDataLen=len/2;
#ifdef DEBUG
printf("irDataLen: %d\n",ir20x4->irDataLen);
for(i=0;i<len;i++)
printf("%02X ",irData[i]);
printf("\n");
#endif
for(i=0;i<ir20x4->irDataLen;i++) {
data=-ir20x4->irData[i];
// printf("(%d) ",data);
if(data<0) {
data=abs(data);
if(data> 444 && data < 1333) {
#ifdef DEBUG
printf("_");
#endif
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
}
else if(data > 1332 && data < 2222) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
ir20x4->rc5Raw[ir20x4->rawBitCount++]=0;
#ifdef DEBUG
printf("__");
#endif
}
else {
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
return -1;
}
}
else {
if(data> 444 && data < 1333) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
#ifdef DEBUG
printf("-");
#endif
}
else if(data > 1332 && data < 2222) {
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
ir20x4->rc5Raw[ir20x4->rawBitCount++]=1;
#ifdef DEBUG
printf("--");
#endif
}
else {
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
return -1;
}
}
}
#ifdef DEBUG
printf("\n");
#endif
#ifdef DEBUG
printf("RawBitCount:%d\n",ir20x4->rawBitCount);
for(i=0;i<ir20x4->rawBitCount;i++)
printf("%d",ir20x4->rc5Raw[i]);
printf("\n");
#endif
#ifdef DEBUG
printf("1\ti=0\n");
#endif
ir20x4->bitCount=0;
ir20x4->irCode[ir20x4->bitCount++]=1; /*it will always begins with 1 [at least with the Philips remote I have]*/
i=1; /* we skip the first bit as it is always 1 [at least with the Philips remote I have]*/
for(i=1;i<ir20x4->rawBitCount-1;i+=2) {
#ifdef DEBUG
printf("%d %d = ",ir20x4->rc5Raw[i],ir20x4->rc5Raw[i+1]);
#endif
if(ir20x4->rc5Raw[i]==0 && ir20x4->rc5Raw[i+1]==1) {
#ifdef DEBUG
printf("1");
#endif
ir20x4->irCode[ir20x4->bitCount++]=1;
}
else if(ir20x4->rc5Raw[i]==1 && ir20x4->rc5Raw[i+1]==0) {
#ifdef DEBUG
printf("0");
#endif
ir20x4->irCode[ir20x4->bitCount++]=0;
}
else {
#ifdef DEBUG
printf("\nError: %d %d\n",ir20x4->rc5Raw[i],ir20x4->rc5Raw[i+1]);
#endif
ir20x4->bitCount=0;
ir20x4->rawBitCount=0;
return -1;
}
#ifdef DEBUG
printf("\ti=%d\n",i);
#endif
}
if(ir20x4->rawBitCount<0x1A) {
#ifdef DEBUG
printf("Not a Complete RC5 Code\n");
#endif
return -1;
}
#ifdef DEBUG
printf("%d %d = ",ir20x4->rc5Raw[25],ir20x4->rc5Raw[26]);
#endif
if(ir20x4->rc5Raw[25]==0) {
#ifdef DEBUG
printf("1");
#endif
ir20x4->irCode[ir20x4->bitCount++]=1;
}
else if(ir20x4->rc5Raw[25]==1) {
#ifdef DEBUG
printf("0");
#endif
ir20x4->irCode[ir20x4->bitCount++]=0;
}
#ifdef DEBUG
printf("\n");
printf("BitCount:%d\n\n",ir20x4->bitCount);
printf("Address: %d %d %d %d %d\n",ir20x4->irCode[3],ir20x4->irCode[4],ir20x4->irCode[5],ir20x4->irCode[6],ir20x4->irCode[7]);
printf("Command: %d %d %d %d %d %d\n",ir20x4->irCode[8],ir20x4->irCode[9],ir20x4->irCode[10],ir20x4->irCode[11],ir20x4->irCode[12],ir20x4->irCode[13]);
#endif
ir20x4->address=(ir20x4->irCode[3]<<4)+(ir20x4->irCode[4]<<3)+(ir20x4->irCode[5]<<2)+(ir20x4->irCode[6]<<1)+(ir20x4->irCode[7]);
ir20x4->command=(ir20x4->irCode[8]<<5)+(ir20x4->irCode[9]<<4)+(ir20x4->irCode[10]<<3)+(ir20x4->irCode[11]<<2)+(ir20x4->irCode[12]<<1)+(ir20x4->irCode[13]);
#ifdef DEBUG
printf("Address:%u Command:%u\n",ir20x4->address,ir20x4->command);
#endif
ir20x4->rawBitCount=0;
ir20x4->bitCount=0;
return (ir20x4->irCode[0]<<13)+(ir20x4->irCode[1]<<12)+(ir20x4->address << 6) + ir20x4->command;
}