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