forked from Ho-Ro/ComponentTester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR_RX.c
2019 lines (1699 loc) · 62.9 KB
/
IR_RX.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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ************************************************************************
*
* IR remote control: receiver
*
* (c) 2015-2021 by Markus Reschke
*
* ************************************************************************ */
/* local includes */
#include "config.h" /* global configuration */
#if defined (SW_IR_RECEIVER) || defined (HW_IR_RECEIVER)
/*
* local constants
*/
/* source management */
#define IR_RX_C
/*
* include header files
*/
/* local includes */
#include "common.h" /* common header file */
#include "variables.h" /* global variables */
#include "functions.h" /* external functions */
/*
* local constants
*/
/* important constants */
#define IR_SAMPLE_PERIOD 50 /* 50 µs */
/* code bit mode */
#define IR_LSB 1 /* LSB */
#define IR_MSB 2 /* MSB */
/* bi-phase modes (bitfield) */
#define IR_IEEE 0b00000001 /* IEEE bit encoding */
#define IR_THOMAS 0b00000010 /* Thomas bit encoding */
#define IR_PRE_PAUSE 0b00000100 /* heading pause */
/* timing control flags (bitfield) */
#define IR_STD_TOLER 0b00000000 /* use default tolerance */
#define IR_RELAX_SHORT 0b00000001 /* relax short pulses */
#define IR_RELAX_LONG 0b00000010 /* relax long pulses */
/* signal types */
#define IR_PAUSE 0b00000001 /* pause */
#define IR_PULSE 0b00000010 /* pulse */
/*
* local variables
*/
/* decoding logic */
uint8_t IR_State = 0; /* multi packet protocol state */
/* multi packet data fields */
uint8_t IR_Data_1; /* data field #1 */
/* ************************************************************************
* IR detection/decoder tool (receiver)
* ************************************************************************ */
/*
* check if pulse/pause duration matches reference value
*
* requires:
* - time units of pause/pulse
* - time units of reference period
* - timing control
* IR_STD_TOLER - use standard tolerance
* IR_RELAX_SHORT - increase tolerance for short pulses/pauses
* IR_RELAX_LONG - increase tolerance for long pulses/pauses
*
* returns:
* - 0 for no match
* - 1 for match
*/
uint8_t PulseCheck(uint8_t PulseWidth, uint8_t Ref, uint8_t Control)
{
uint8_t Flag; /* return value */
/* define tolerance based on value */
if (Ref > 10) /* long pulse */
{
Flag = 3; /* default: 3 units */
/* be tolerent with long pulses/pauses */
if (Control & IR_RELAX_LONG) /* relax timing */
{
Flag = 5; /* increase to 5 units */
}
}
else /* short pulse */
{
Flag = 1; /* default: 1 unit */
/* be tolerent with short pulses/pauses */
if (Control & IR_RELAX_SHORT) /* relax timing */
{
Flag = 3; /* increase to 3 units */
}
}
/* prevent underflow for very short pulses/pauses */
if (Flag > Ref)
{
Flag = Ref; /* set to reference value */
}
/* calculate min and max values */
Control = Ref;
Control += Flag; /* upper limit */
Ref -= Flag; /* lower limit */
Flag = 0; /* reset flag */
/* check if pulse duration is within allowed time window */
if ((PulseWidth >= Ref) && (PulseWidth <= Control))
{
Flag = 1;
}
return Flag;
}
/*
* Bi-Phase demodulation
* - similar to Manchester encoding
* - special case of BPSK (binary phase-shift keying)
*
* requires:
* - pointer to pulse/pause duration data
* first item has to be a pulse
* - number of pulses/pauses
* - mode: Thomas or IEEE, heading pause
* IR_IEEE - decoding based on IEEE 802.3
* IR_THOMAS - decoding based on G.E. Thomas
* IR_PRE_PAUSE - heading pause (not logged)
* - time units of clock half cycle
* - timing control
* IR_STD_TOLER - use standard tolerance
* IR_RELAX_SHORT - increase tolerance for short pulses/pauses
* IR_RELAX_LONG - increase tolerance for long pulses/pauses
*
* returns:
* - 0 for any error
* - number of bits
*/
uint8_t BiPhase_Demod(uint8_t *PulseData, uint8_t Pulses, uint8_t Mode, uint8_t tH, uint8_t Control)
{
uint8_t Counter = 0; /* return value: number of bits */
uint8_t Pulse = 1; /* pulse counter */
uint8_t Time; /* pulse duration */
uint8_t Width; /* 1x / 2x pulse width */
uint8_t Dir; /* direction of pulse change */
uint8_t PrePulse = 0; /* pulse for half-bit */
uint8_t Data = 0; /* code byte */
uint8_t *Code; /* pointer to code data */
uint8_t Bits = 0; /* counter for bits */
uint8_t Bytes = 0; /* counter for bytes */
Code = &IR_Code[0]; /* set start address */
/*
* Bi-Phase Modulation:
* - fixed time slot for each bit
* - bit is encoded as a phase shift (H-L or L-H transition)
* - two encoding conventions
* - G.E. Thomas (Manchester II or Biphase-L)
* pause - pulse -> 0
* pulse - pause -> 1
* - IEEE 802.3
* pulse - pause -> 0
* pause - pulse -> 1
*/
/* take care about heading pause */
if (Mode & IR_PRE_PAUSE) PrePulse = 1;
while (Pulse <= Pulses) /* process all data items */
{
Time = *PulseData; /* get duration */
Dir = 0; /* reset pulse change direction */
Width = 1; /* reset pulse width */
/* check for pulse duration */
if (PulseCheck(Time, tH, Control)) /* half clock cycle */
{
/* do nothing */
}
else if (PulseCheck(Time, tH * 2, Control)) /* full clock cycle */
{
Width++; /* double pulse */
}
else /* wrong duration */
{
Counter = 0; /* signal error */
break; /* exit loop */
}
if (Pulse % 2 == 0) /* pause */
{
if (PrePulse == 2) /* prior pulse */
{
Dir = 1; /* H-L change */
if (Width == 1) /* second half of clock cycle */
{
PrePulse = 0; /* clock cycle done */
}
else /* full clock cycle */
{
PrePulse = 1; /* first half of the next clock cycle */
}
}
else /* new clock cycle */
{
if (Width == 1) /* first half of clock cycle */
{
PrePulse = 1; /* first half of clock cycle */
}
else /* full clock cycle */
{
Counter = 0; /* signal error */
break; /* exit loop */
}
}
}
else /* pulse */
{
if (PrePulse == 1) /* prior pause */
{
Dir = 2; /* L-H change */
if (Width == 1) /* second half of clock cycle */
{
PrePulse = 0; /* clock cycle done */
}
else /* full clock cycle */
{
PrePulse = 2; /* first half of the next clock cycle */
}
}
else /* new clock cycle */
{
if (Width == 1) /* first half of clock cycle */
{
PrePulse = 2; /* first half of clock cycle */
}
else /* full clock cycle */
{
Counter = 0; /* signal error */
break; /* exit loop */
}
}
}
/* process pulse change */
if (Dir) /* got a pulse change */
{
Bits++; /* got another bit */
Counter++; /* increase counter */
Data <<= 1; /* shift left for new bit */
if (Mode & IR_THOMAS) /* Thomas */
{
if (Dir == 1) /* H-L is 1 */
{
Data |= 0b00000001; /* set bit */
}
}
else /* IEEE */
{
if (Dir == 2) /* L-H is 1 */
{
Data |= 0b00000001; /* set bit */
}
}
if (Bits == 8) /* completed byte */
{
*Code = Data; /* save code byte */
Bytes++; /* got another byte */
Data = 0; /* reset code byte */
Bits = 0; /* reset bit counter */
if (Bytes < IR_CODE_BYTES) /* prevent overflow */
{
Code++; /* next code byte */
}
}
}
/* special case: missing pause at end */
if (Pulse == Pulses) /* last pause/pulse */
{
/* only for pulse */
if (PrePulse == 2) /* first half of cycle */
{
/* assume that pause follows and simulate it */
*PulseData = tH; /* half cycle */
PulseData--; /* stay here */
Pulses++; /* add trailing pause */
}
}
PulseData++; /* next one */
Pulse++; /* next one */
}
/* shift remaining bits to left end of current byte */
if (Bits > 0) /* some bits left */
{
while (Bits < 8)
{
Data <<= 1; /* shift left */
Bits++; /* next bit */
}
*Code = Data; /* save code byte */
}
return Counter;
}
#ifdef SW_IR_RX_EXTRA
/*
* PPM demodulation
* - Pulse Position Modulation
*
* requires:
* - pointer to pulse/pause duration data
* (first one has to be a pulse)
* - number of pulses/pauses
* - time units of pulse/pause
* should be lower end of valid range
* - number of time slots (= bits) expected
* - timing control
* IR_STD_TOLER - use standard tolerance
* IR_RELAX_SHORT - increase tolerance for short pulses/pauses
* IR_RELAX_LONG - increase tolerance for long pulses/pauses
*
* returns:
* - 0 for any error
* - number of bits
*/
uint8_t PPM_Demod(uint8_t *PulseData, uint8_t Pulses, int8_t tP, uint8_t Slots, uint8_t Control)
{
uint8_t Counter = 0; /* return value */
uint8_t Pulse = 1; /* pulse counter */
uint8_t Time; /* pulse duration */
uint8_t Data = 0; /* code byte */
uint8_t *Code; /* pointer to code data */
uint8_t Bits = 0; /* counter for bits */
uint8_t Bytes = 0; /* counter for bytes */
uint8_t n; /* counter */
Code = &IR_Code[0]; /* set start address */
/*
* PPM:
* - fixed time slot for each bit
* - pause -> 0
* - pulse -> 1
*/
while (Pulse <= Pulses) /* process all data items */
{
Time = *PulseData; /* get duration */
/* estimate number of bits for current pulse/pause */
n = Time / tP; /* number of bits */
Time = Time % tP; /* remaining time */
Time /= n; /* offset per bit */
/* check if time is in tolerance */
if (! PulseCheck(tP + Time, tP, Control))
{
Counter = 0; /* signal error */
break; /* exit loop */
}
Bits += n; /* add to number of bits */
Counter += n; /* add to totals */
/* copy bits */
while (n > 0)
{
Data <<= 1; /* shift left for new bit */
/* set bit in data */
if (Pulse % 2 != 0) /* pulse */
{
Data |= 0b00000001; /* "1" */
}
/* otherwise stays "0" for pause */
if (Bits == 8) /* completed byte */
{
*Code = Data; /* save code byte */
Bytes++; /* got another byte */
Data = 0; /* reset code byte */
Bits = 0; /* reset bit counter */
if (Bytes < IR_CODE_BYTES) /* prevent overflow */
{
Code++; /* next code byte */
}
}
n--; /* next bit */
}
/* manage trailing pauses */
if (Pulse == Pulses) /* last pulse */
{
if (Counter < Slots) /* we have trailing pauses */
{
/* create pseudo pause(s) */
Time = Slots - Counter; /* number of bits missing */
Time *= tP; /* * pause duration */
*PulseData = Time; /* save time */
PulseData--; /* re-use last item */
Pulses++; /* add pseudo pause */
}
}
PulseData++; /* next one */
Pulse++; /* next one */
}
/* shift remaining bits to left end of current byte */
if (Bits > 0) /* some bits left */
{
while (Bits < 8)
{
Data <<= 1; /* shift left */
Bits++; /* next bit */
}
*Code = Data; /* save code byte */
}
return Counter;
}
#endif
/*
* PDM/PWM demodulation
* - PDM - Pulse Distance Modulation
* - PWM - Pulse Width Modulation
*
* requires:
* - pointer to pulse/pause duration data
* first item has to be a pulse for PDM or a pause for PWM
* - number of pulses/pauses
* - time units of spacer
* - time units of 0
* - time units of 1
* - timing control
* IR_STD_TOLER - use standard tolerance
* IR_RELAX_SHORT - increase tolerance for short pulses/pauses
* IR_RELAX_LONG - increase tolerance for long pulses/pauses
*
* returns:
* - 0 for any error
* - number of bits
*/
uint8_t PxM_Demod(uint8_t *PulseData, uint8_t Pulses, uint8_t tS, uint8_t t0, uint8_t t1, uint8_t Control)
{
uint8_t Counter = 0; /* return value: number of bits */
uint8_t Pulse = 1; /* pulse counter */
uint8_t Time; /* pulse duration */
uint8_t Data = 0; /* code byte */
uint8_t *Code; /* pointer to code data */
uint8_t Bits = 0; /* counter for bits */
uint8_t Bytes = 0; /* counter for bytes */
Code = &IR_Code[0]; /* set start address */
/*
* PWM / pulse encoding:
* - fixed pause time
* - two different pulse times to encode 0/1
* - even number of data items
*
* PDM / space encoding:
* - fixed pulse time
* - two different pause times to encode 0/1
* - last item is pulse (stop bit)
* required to indicate end of pause of last data bit
* - odd number of data items
*/
while (Pulse <= Pulses) /* process all data items */
{
Time = *PulseData; /* get duration */
if (Pulse % 2 == 0) /* pulse/pause with variable time */
{
Bits++; /* got another bit */
Counter++; /* increase counter for total bits */
Data <<= 1; /* shift left for new bit */
if (PulseCheck(Time, t0, Control)) /* 0 */
{
/* set 0 ;) */
}
else if (PulseCheck(Time, t1, Control)) /* 1 */
{
Data |= 0b00000001; /* set bit */
}
else /* invalid pulse */
{
Counter = 0; /* signal error */
break; /* exit loop */
}
if (Bits == 8) /* completed byte */
{
*Code = Data; /* save code byte */
Bytes++; /* got another byte */
Data = 0; /* reset code byte */
Bits = 0; /* reset bit counter */
if (Bytes < IR_CODE_BYTES) /* prevent overflow */
{
Code++; /* next code byte */
}
}
}
else /* pulse/pause with fixed time */
{
if (! PulseCheck(Time, tS, Control)) /* time doesn't match */
{
Counter = 0; /* signal error */
break; /* exit loop */
}
}
PulseData++; /* next one */
Pulse++; /* next one */
}
#if 0
/* debugging output */
if (Counter == 0) /* error */
{
Display_NextLine();
Display_Value(Counter, 0, 0); /* display pulse number */
Display_Colon(); /* display; : */
Display_Value(Time, 0, 0); /* display pulse duration */
}
#endif
/* shift remaining bits to left end of current byte */
if (Bits > 0) /* some bits left */
{
while (Bits < 8)
{
Data <<= 1; /* shift left */
Bits++; /* next bit */
}
*Code = Data; /* save code byte */
}
return Counter;
}
/*
* adjust special bi-phase pulse pair to standard timing
*
* requires:
* - pointer to pulse/pause duration data
* first item has to be a pulse
* - number of pulses
* - offset to special pulse-pause pair (half cycles)
* - time units of normal pulse/pause
* - time units of special pulse/pause
*
* returns:
* - number of special pulses
*/
uint8_t SpecialBiPhasePulse(uint8_t *PulseData, uint8_t Pulses, uint8_t Offset, uint8_t Normal, uint8_t Special)
{
uint8_t Counter = 0; /* return value: number of pulses */
uint8_t Mixed; /* duration of mixed pulse */
uint8_t Time; /* pulse duration */
uint8_t Cycles = 0; /* half cycles */
uint8_t n = 0; /* counter */
Mixed = Normal + Special; /* mixed pulse */
while (Pulses > 0)
{
Time = *PulseData; /* get duration */
if (Cycles <= Offset) /* offset not reached yet */
{
if (PulseCheck(Time, Normal, IR_STD_TOLER)) /* normal pulse */
{
Cycles++;
}
else /* double or mixed pulse */
{
Cycles += 2;
}
}
if (Cycles > Offset) /* reached offset */
{
if (PulseCheck(Time, Special, IR_STD_TOLER)) /* special pulse */
{
*PulseData = Normal; /* adjust to normal */
Counter++; /* increase counter */
}
else if (PulseCheck(Time, Mixed, IR_STD_TOLER)) /* mixed pulse */
{
*PulseData = 2 * Normal; /* adjust to normal double pulse */
Counter++; /* increase counter */
}
n++; /* increase counter */
if (n == 2) break; /* exit loop for pulse pair */
}
Pulses--; /* next pulse */
PulseData++;
}
return(Counter);
}
/*
* get specific number of bits from IR code
*
* requires:
* - start bit in IR code (1-...)
* - number of bits (1-8)
* - bit mode
* IR_LSB - LSB
* IR_MSB - MSB
* returns:
* - code byte
*/
uint8_t GetBits(uint8_t StartBit, uint8_t Bits, uint8_t Mode)
{
uint8_t Data = 0; /* return value */
uint8_t *Code; /* pointer to code data */
uint8_t Counter; /* bit counter */
uint8_t Temp;
uint8_t n; /* counter */
/*
* IR_Code: bits stored as received (bit #7 is first bit received)
* IR_Code[0] is first byte
* LSB: bit #7 of IR_Code goes to bit #0 of Data
* bit #0 of IR_Code goes to bit #7 of Data
* MSB: bit #7 of IR_Code goes to bit #7 of Data
* bit #0 of IR_Code goes to bit #0 of Data
*/
/* determine start position in IR_Code */
StartBit--; /* align */
Temp = StartBit / 8; /* start byte (0-) */
Counter = StartBit % 8; /* start bit in byte (0-) */
Code = &IR_Code[Temp]; /* get start address */
Temp = *Code; /* copy code byte */
/* shift start bit to bit #7 */
n = Counter; /* number of positions to shift */
while (n > 0)
{
Temp <<= 1; /* shift left */
n--; /* next bit */
}
/* get bits */
Counter = 8 - Counter; /* remaining bits in first byte */
n = 1;
while (n <= Bits)
{
Data <<= 1; /* shift destination left */
if (Temp & 0b10000000) /* bit set */
{
Data |= 0b00000001; /* set bit */
}
Temp <<= 1; /* shift source left */
if (n == Counter) /* byte overflow */
{
Code++; /* next byte */
Temp = *Code; /* copy code byte */
}
n++; /* next bit */
}
/* post processing */
if (Mode == IR_LSB) /* LSB mode */
{
/* reverse bit sequence */
Temp = Data; /* Temp becomes source */
Data = 0; /* Data becomes destination */
n = Bits; /* number of bits to process */
while (n > 0)
{
Data <<= 1; /* shift destination left */
if (Temp & 0b00000001) /* if bit in source is set */
{
Data |= 0b00000001; /* set it in destination too */
}
Temp >>= 1; /* shift source right */
n--; /* next bit */
}
}
return Data;
}
/*
* detect and decode IR protocol
* - uses IR_State to keep track of multi-packet protocols
*
* requires:
* - pointer to array of pulse/pause duration data
* - number of pulses/pauses
*/
void IR_Decode(uint8_t *PulseData, uint8_t Pulses)
{
uint8_t Flag = 0; /* control flag */
uint8_t *Pulse; /* pointer to pause/pulse data */
uint8_t PulsesLeft; /* remaining pulses/pauses */
uint8_t Time1; /* time units #1 */
uint8_t Time2; /* time units #2 */
uint8_t Bits = 0; /* number of bits received */
uint8_t Address; /* RC address */
uint8_t Command; /* RC command */
uint8_t Extras = 0; /* RC extra stuff */
uint8_t Temp; /* temporary value */
/* local constants for Flag */
#define PROTO_UNKNOWN 0 /* unknown protocol */
#define PROTO_DETECTED 1 /* protocol detected */
#define PACKET_OK 2 /* valid packet */
#define PACKET_DISPLAY 3 /* valid packet & display standard values */
#define PACKET_MULTI 4 /* multi packet (more to follow) */
if (Pulses < 2) return; /* not enough pulses */
/*
* figure out the IR protocol by checking the first pulse-pause pair,
* number of pulses/pauses and other features
*/
/* get first pulse-pause pair */
Pulse = PulseData; /* first pulse */
Time1 = *Pulse; /* duration of first pulse */
Pulse++; /* first pause */
Time2 = *Pulse; /* duration of first pause */
Pulse++; /* second pulse (skip start pair) */
PulsesLeft = Pulses - 2; /* start pair done */
/*
* NEC (µPD6121/µPD6122)
* - start: pulse 9ms, pause 4.5ms
* - PDM: pulse 560µs, pause 0=560µs 1=1690µs
* - bit mode: LSB
* - stop: pulse 560µs
* - standard format:
* <start><address:8><inverted address:8><command:8><inverted command:8><stop>
* - extended format:
* <start><low address:8><high address:8><command:8><inverted command:8><stop>
* - repeat sequence:
* <pulse 9ms><pause 2.25ms><stop>
* - repeat delay is 108ms (start to start)
*/
/*
* Sanyo (LC7461)
* - start: pulse 9ms, pause 4.5ms
* - PDM: pulse 560µs, pause 0=560µs 1=1690µs
* - bit mode: LSB
* - stop: pulse 560µs
* - format:
* <start><custom code:13><inverted custom code:13><key data:8><inverted key data:8><stop>
* - repeat sequence:
* <start><stop>
* - repeat delay is 108ms (start to start) or 23.6ms (end to start)
* - carrier 38kHz (455kHz/12), duty cycle 1/3
*/
if (PulseCheck(Time1, 179, IR_RELAX_LONG)) /* pulse 9ms */
{
if (PulseCheck(Time2, 89, IR_RELAX_LONG)) /* pause 4.5ms */
{
/* try to demodulate NEC */
Bits = PxM_Demod(Pulse, PulsesLeft, 11, 11, 33, IR_STD_TOLER);
if (Bits == 32) /* we expect 32 bits for NEC */
{
Display_NL_EEString_Space(IR_NEC_str); /* display protocol */
Address = GetBits(1, 8, IR_LSB); /* get address */
Extras = GetBits(9, 8, IR_LSB); /* get inverted address */
Command = GetBits(17, 8, IR_LSB); /* get command */
/* determine protocol version */
Temp = ~Extras; /* invert */
if (Address != Temp) /* address is not inverted */
{
/* extended format with 16 bit address */
Display_HexByte(Extras); /* display high address */
}
Flag = PACKET_DISPLAY; /* packet ok & default output */
goto result; /* skip other checks */
}
#ifdef SW_IR_RX_EXTRA
else if (Bits == 42) /* we expect 42 bits for Sanyo */
{
Display_NL_EEString_Space(IR_Sanyo_str); /* display protocol */
Address = GetBits(1, 8, IR_LSB); /* get custom code LSB */
Extras = GetBits(9, 5, IR_LSB); /* get custom code MSB */
Command = GetBits(27, 8, IR_LSB); /* get key data */
Display_HexByte(Extras); /* display custom code MSB */
Flag = PACKET_DISPLAY; /* packet ok & default output */
goto result; /* skip other checks */
}
#endif
}
else if (PulseCheck(Time2, 45, IR_STD_TOLER)) /* pause 2.25ms */
{
/* check for NEC repeat sequence */
if (Pulses == 3) /* just 3 pulses */
{
if (PulseCheck(*Pulse, 11, IR_STD_TOLER)) /* pulse 560µs */
{
Display_NL_EEString_Space(IR_NEC_str); /* display protocol */
Display_Char('R'); /* display: R (for repeat) */
Flag = PACKET_OK; /* packet ok */
goto result; /* skip other checks */
}
}
}
}
/*
* Proton
* - also: Mitsubishi (M50560)
* - start: pulse 8ms, pause 4ms
* - sync/separator between address and command: pause 4ms
* - PDM: pulse 500µs, pause 0=500µs 1=1500µs
* - bit mode: LSB
* - stop: pulse 500µs
* - format: <start><address:8><stop><sync><command:8><stop>
* - code repeat delay is 60ms (start to start)
*/
if (PulseCheck(Time1, 162, IR_RELAX_LONG)) /* pulse 8ms */
{
if (PulseCheck(Time2, 80, IR_STD_TOLER)) /* pause 4ms */
{
if (PulsesLeft == 35) /* correct number of pulses/pauses */
{
/* check if we got the sync pause */
Pulse += 17; /* 16 pulses for first part + terminating pulse */
if (PulseCheck(*Pulse, 80, IR_STD_TOLER)) /* pause 4ms */
{
*Pulse = 11; /* change sync into "0" */
Pulse -= 17; /* back to second pulse */
Display_NL_EEString_Space(IR_Proton_str); /* display protocol */
Flag = PROTO_DETECTED; /* detected protocol */
Bits = PxM_Demod(Pulse, PulsesLeft, 11, 11, 30, IR_STD_TOLER);
if (Bits == 17) /* we expect 8 + 1 + 8 bits */
{
Address = GetBits(1, 8, IR_LSB); /* get address */
Command = GetBits(10, 8, IR_LSB); /* get command */
Flag = PACKET_DISPLAY; /* packet ok & default output */
}
goto result; /* skip other checks */
}
}
}
}
/*
* JVC C8D8
* - start: pulse 8.44ms, pause 4.22ms
* - PDM: pulse 525µs, pause 0=525µs 1=1575µs
* - bit mode: LSB
* - stop: pulse 525µs
* - format: <start><address:8><command:8><stop>
* - repeat sequence format: <address:8><command:8><stop>
* - repeat sequence delay is <start> + 46.42ms (start to start)
* - alternative timings:
* - start: pulse 9.4ms, pause 4.05ms (188/81)
* PDM: pulse 560µs, pause 0:600µs 1:1620µs
* - start: pulse 9ms, pause 4.2ms (180/84)
* PDM: pulse 550µs, pause 0:550µs 1:1580µs
*/
if ((PulseCheck(Time1, 168, IR_STD_TOLER)) || /* pulse 8.44ms */
(PulseCheck(Time1, 184, IR_RELAX_LONG))) /* 9 - 9.5ms */
{
if (PulseCheck(Time2, 84, IR_STD_TOLER)) /* pause 4.22ms */
{
/* try to demodulate JVC */
Bits = PxM_Demod(Pulse, PulsesLeft, 11, 11, 32, IR_STD_TOLER);
if (Bits == 16) /* we expect 16 bits */
{
Display_NL_EEString_Space(IR_JVC_str); /* display protocol */
Address = GetBits(1, 8, IR_LSB); /* get address */
Command = GetBits(9, 8, IR_LSB); /* get command */
Flag = PACKET_DISPLAY; /* packet ok & default output */
goto result; /* skip other checks */
}
}
}
/*
* Matsushita (Panasonic, MN6014)
* - start: pulse 3.5ms, pause 3.5ms
* - PDM: pulse 872µs, pause 0=872µs 1=2616µs
* - bit mode: LSB
* - stop: pulse 872µs
* - format 12 bits / C6D6:
* <start><custom code:6><data code:6><inverted custom code:6><inverted data code:6><stop>
* - format 11 bits / C5D6:
* <start><custom code:5><data code:6><inverted custom code:5><inverted data code:6><stop>
* - repeat delay is 104.7ms (start to start), or 34ms (end to start) for 12 bit format
* and 39.24ms (end to start) for 11 bit format
*/
/*
* Kaseikyo (Japanese Code)
* - start: pulse 3456µs, pause 1728µs
* - PDM: pulse 432µs, pause 0=432µs 1=1296µs
* - bit mode: LSB
* - stop: pulse 432µs
* - format (48 bits):
* <start><manufacturer code:16><parity:4><system:4><product:8><function:8><check:8><stop>
* - parity: 0000