Lots of Keysets
[pierogi] / protocols / pirprotocol.h
1 #ifndef PIRPROTOCOL_H
2 #define PIRPROTOCOL_H
3
4 // The generic remote controller.
5
6 #include <QObject>
7 #include "pirkeynames.h"
8
9 #include <map>
10 #include <deque>
11
12 // We'll define a maximum number of repetitions, regardless of how long the
13 // user presses the button.  (This is just in case we miss the point at which
14 // he stops pressing it...)  500 should be plenty.
15 #define MAX_REPEAT_COUNT 500
16
17 typedef std::deque<bool> CommandSequence;
18
19 // As I've learned more about IR protocols, the concept of what a specific
20 // key is gets more and more complex.  To deal with this, I'm going to allow
21 // a key to have more than one command sequence associated with it.  (I need
22 // up to three codes for Sony keys, and as many as four to define an
23 // individual Pioneer key.)
24 class PIRKeyBits
25 {
26 public:
27   CommandSequence firstCode;
28   CommandSequence secondCode;
29   CommandSequence thirdCode;
30   CommandSequence fourthCode;
31 };
32
33 // I'll go ahead and use associative arrays to build up lists of keycodes.
34 typedef std::map<int, PIRKeyBits> KeycodeCollection;
35
36
37 // Right now, the only reason for this object to inherit from QObject is
38 // so it can participate in Qt-style threading.  Note that it has no
39 // event loop, and no access to the GUI, so don't go trying to communicate
40 // with the user here...
41 class PIRProtocol: public QObject
42 {
43   Q_OBJECT
44
45 public:
46   PIRProtocol(
47     QObject *guiObject,
48     unsigned int index,
49     unsigned int gSpace,
50     bool iclflag);
51
52   void addKey(
53     PIRKeyName key,
54     unsigned long data,
55     unsigned int size);
56
57   // A special addKey used for Sony's SIRC protocol:
58   void addSIRCKey(
59     PIRKeyName key,
60     unsigned int addressData,
61     unsigned int size,
62     unsigned int commandData);
63
64   void addSIRC20Key(
65     PIRKeyName key,
66     unsigned int secondaryAddressData,
67     unsigned int primaryAddressData,
68     unsigned int commandData);
69
70   void addSharpKey(
71     PIRKeyName key,
72     unsigned int addressData,
73     unsigned int commandData);
74
75   void addNECKey(
76     PIRKeyName key,
77     unsigned int addressData,
78     unsigned int commandData);
79
80   void addPioneerKey(
81     PIRKeyName key,
82     unsigned int firstAddress,
83     unsigned int firstCommand,
84     unsigned int secondAddress,
85     unsigned int secondCommand);
86
87 /*
88   void addRCAKey(
89     PIRKeyName key,
90     unsigned int addressData,
91     unsigned int commandData);
92 */
93
94   void addKaseikyoKey(
95     PIRKeyName key,
96     unsigned int addressData,
97     unsigned int commandData);
98
99   void addDishKey(
100     PIRKeyName key,
101     unsigned int firstCommand,
102     unsigned int secondCommand);
103
104   void setCarrierFrequency(
105     unsigned int freq);
106
107   void setDutyCycle(
108     unsigned int dc);
109
110   void setMinimumRepetitions(
111     unsigned int minrep);
112
113   void setPreData(
114     unsigned long data,
115     unsigned int bits);
116
117   void setPostData(
118     unsigned long data,
119     unsigned int bits);
120
121 public slots:
122   virtual void startSendingCommand(
123     unsigned int threadableID,
124     PIRKeyName command) = 0;
125
126 signals:
127   void commandFailed(
128     const char *errString);
129
130 protected:
131   bool isCommandSupported(
132     PIRKeyName command);
133
134   void clearRepeatFlag();
135   bool checkRepeatFlag();
136
137   unsigned int carrierFrequency;
138   unsigned int dutyCycle;
139
140   void appendToBitSeq(
141     CommandSequence &bits,
142     unsigned int code,
143     int size);
144
145   KeycodeCollection keycodes;
146
147   // A sleep function for all protocols:
148   void sleepUntilRepeat(
149     int commandDuration);
150
151   // The "gap" parameter from LIRC.  If the commands are "variable-length",
152   // this indicates the amount of time between the last pulse of one
153   // command and the first pulse of the next.  If "constant-length", it is
154   // the time between the _first_ pulse of one command and the first pulse
155   // of the next.
156
157   void setGapSize(
158     int gapSize,
159     bool iclFlag);
160
161   bool isConstantLength;
162   int gap;
163
164   // More administrative data wrapped around the actual command:
165   CommandSequence preData;
166   CommandSequence postData;
167
168   // Some remotes require a minimum number of repetitions:
169   // Note: thinking about removing this -- don't know if it is needed
170   int minimumRepetitions;
171
172   unsigned int id;
173 };
174
175 #endif // PIRPROTOCOL_H