ef6e1cca837fa11431ee9400340a372fc38e0ed2
[pierogi] / necprotocol.h
1 #ifndef NECPROTOCOL_H
2 #define NECPROTOCOL_H
3
4 #include "pirprotocol.h"
5 #include "pirrx51hardware.h"
6
7 //
8 // The "NEC" Protocol is, more or less, followed by the majority of
9 // remotes defined in the LIRC config files, which means it is probably
10 // followed by most of the remotes out there.
11 //
12 // Remotes using this protocol seem to use a frequency of 38000 Hz, lead off
13 // each command with a signal that should be unique to the manufacturer,
14 // and mostly define 0s and 1s by the length of time between pulses...
15 //
16
17 //
18 // There exist two well-defined NEC protocols: "standard" and "extended".
19 // Some remotes might not fit into either format; LIRC has given up and
20 // simply recorded the exact set of IR pulses as bits, rather than attempt
21 // to follow the standard encodings.  I'll use the following enum to
22 // describe which mechanism the key data follows:
23 //
24
25 enum NECKeyFormat
26 {
27   Standard_NEC,
28   Extended_NEC,
29   LIRC_NEC
30 };
31
32 class NECProtocol: public PIRProtocol
33 {
34 public:
35   // An NEC protocol will always have differing times for "zero" and "one".
36   // Also, all protocols have some space set between commands.  However,
37   // some protocols specify a fixed delay between the end of one
38   // command and the start of the next, and others specify each command be
39   // started at a precise interval (so the spacing between the end of one
40   // and the start of another may vary).
41
42   // Constructor for standard NEC:
43   NECProtocol(
44     QObject *guiObject,
45     unsigned int index,
46     NECKeyFormat type);
47
48   // Constructor for non-standard NEC:
49   NECProtocol(
50     QObject *guiObject,
51     unsigned int index,
52     unsigned int zPulse,
53     unsigned int zSpace,
54     unsigned int oPulse,
55     unsigned int oSpace,
56     unsigned int gapSpace,
57     bool iclflag,
58     NECKeyFormat type);
59
60   void setHeaderPair(
61     unsigned int pulse,
62     unsigned int space);
63
64   void setTrailerPulse(
65     unsigned int pulse);
66
67   void setRepeatPair(
68     unsigned int pulse,
69     unsigned int space);
70
71   void setRepeatNeedsHeader(
72     bool flag);
73
74   void setFullHeadlessRepeat(
75     bool flag);
76
77   void setElevenBitToggle(
78     bool flag);
79
80 public slots:
81   void startSendingCommand(
82     unsigned int threadableID,
83     PIRKeyName command);
84
85 private:
86   // First, define what is used to represent 0 and 1:
87   unsigned int zeroPulse;
88   unsigned int zeroSpace;
89   unsigned int onePulse;
90   unsigned int oneSpace;
91
92   // Some administrative data that most NEC Protocol remotes have:
93   unsigned int headerPulse;
94   unsigned int headerSpace;
95   bool hasHeaderPair;
96
97   // A tailing on-request, not followed by a specific off time:
98   unsigned int trailerPulse;
99   bool hasTrailerPulse;
100
101   // A pulse that means "repeat the last command":
102   unsigned int repeatPulse;
103   unsigned int repeatSpace;
104   bool hasRepeatPair;
105   bool repeatNeedsHeader; // Put the header ahead of the repeat pulse
106   bool fullHeadlessRepeat; // Repeat full command but without header
107   bool elevenBitToggle; // A few remotes toggle the last eleven bits on repeat
108
109   // A flag used to determine how to encode the bits:
110   NECKeyFormat encodingFormat;
111
112   int generateStandardCommand(
113     const CommandSequence &bits,
114     PIRRX51Hardware &device);
115
116   int generateHeadlessCommand(
117     const CommandSequence &bits,
118     PIRRX51Hardware &device);
119
120   int generateRepeatCommand(
121     PIRRX51Hardware &device);
122
123   int generateToggledCommand(
124     const CommandSequence &bits,
125     PIRRX51Hardware &device);
126
127   int pushBits(
128     const CommandSequence &bits,
129     PIRRX51Hardware &device);
130
131   int pushReverseBits(
132     const CommandSequence &bits,
133     PIRRX51Hardware &device);
134
135   int pushInvertedReverseBits(
136     const CommandSequence &bits,
137     PIRRX51Hardware &device);
138 };
139
140 #endif // NECPROTOCOL_H