Change back to real tabbed window, updates 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 addPanOldKey(
81     PIRKeyName key,
82     unsigned int addressData,
83     unsigned int commandData);
84
85   void addPioneerKey(
86     PIRKeyName key,
87     unsigned int firstAddress,
88     unsigned int firstCommand,
89     unsigned int secondAddress,
90     unsigned int secondCommand);
91
92 /*
93   void addRCAKey(
94     PIRKeyName key,
95     unsigned int addressData,
96     unsigned int commandData);
97 */
98
99   void addKaseikyoKey(
100     PIRKeyName key,
101     unsigned int addressData,
102     unsigned int commandData);
103
104   void addDishKey(
105     PIRKeyName key,
106     unsigned int firstCommand,
107     unsigned int secondCommand);
108
109   void addXMPKey(
110     PIRKeyName key,
111     unsigned int firstCommand,
112     unsigned int secondCommand);
113
114   void setCarrierFrequency(
115     unsigned int freq);
116
117   void setDutyCycle(
118     unsigned int dc);
119
120   void setMinimumRepetitions(
121     unsigned int minrep);
122
123   void setPreData(
124     unsigned long data,
125     unsigned int bits);
126
127   void setPostData(
128     unsigned long data,
129     unsigned int bits);
130
131 public slots:
132   virtual void startSendingCommand(
133     unsigned int threadableID,
134     PIRKeyName command) = 0;
135
136 signals:
137   void commandFailed(
138     const char *errString);
139
140 protected:
141   bool isCommandSupported(
142     PIRKeyName command);
143
144   void clearRepeatFlag();
145   bool checkRepeatFlag();
146
147   unsigned int carrierFrequency;
148   unsigned int dutyCycle;
149
150   void appendToBitSeq(
151     CommandSequence &bits,
152     unsigned int code,
153     int size);
154
155   KeycodeCollection keycodes;
156
157   // A sleep function for all protocols:
158   void sleepUntilRepeat(
159     int commandDuration);
160
161   // The "gap" parameter from LIRC.  If the commands are "variable-length",
162   // this indicates the amount of time between the last pulse of one
163   // command and the first pulse of the next.  If "constant-length", it is
164   // the time between the _first_ pulse of one command and the first pulse
165   // of the next.
166
167   void setGapSize(
168     int gapSize,
169     bool iclFlag);
170
171   bool isConstantLength;
172   int gap;
173
174   // More administrative data wrapped around the actual command:
175   CommandSequence preData;
176   CommandSequence postData;
177
178   // Some remotes require a minimum number of repetitions:
179   // Note: thinking about removing this -- don't know if it is needed
180   int minimumRepetitions;
181
182   unsigned int id;
183 };
184
185 #endif // PIRPROTOCOL_H