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