Improved to "half-way usable" (version 0.5)
[pierogi] / 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 //#include "pirdevice.h"
10
11 #include <map>
12 #include <deque>
13
14 // We'll define a maximum number of repetitions, regardless of how long the
15 // user presses the button.  (This is just in case we miss the point at which
16 // he stops pressing it...)  500 should be plenty.
17 #define MAX_REPEAT_COUNT 500
18
19 typedef std::deque<bool> CommandSequence;
20
21 // I'll go ahead and use associative arrays to build up lists of keycodes.
22 typedef std::map<int, CommandSequence> KeycodeCollection;
23
24
25 // Right now, the only reason for this object to inherit from QObject is
26 // so it can participate in Qt-style threading.  Note that it has no
27 // event loop, and no access to the GUI, so don't go trying to communicate
28 // with the user here...
29 class PIRProtocol: public QObject
30 {
31   Q_OBJECT
32
33 public:
34   PIRProtocol(
35     QObject *guiObject,
36     unsigned int index,
37     unsigned int gSpace,
38     bool iclflag);
39
40   void addKey(
41     PIRKeyName key,
42     unsigned long data,
43     unsigned int size);
44
45   // A special addKey used for Sony's SIRC protocol:
46   void addSIRCKey(
47     PIRKeyName key,
48     unsigned int addressData,
49     unsigned int size,
50     unsigned int commandData);
51
52   void addSIRC20Key(
53     PIRKeyName key,
54     unsigned int secondaryAddressData,
55     unsigned int primaryAddressData,
56     unsigned int commandData);
57
58   void addSharpKey(
59     PIRKeyName key,
60     unsigned int addressData,
61     unsigned int commandData);
62
63   void setCarrierFrequency(
64     unsigned int freq);
65
66   void setDutyCycle(
67     unsigned int dc);
68
69   void setMinimumRepetitions(
70     unsigned int minrep);
71
72   void setPreData(
73     unsigned long data,
74     unsigned int bits);
75
76   void setPostData(
77     unsigned long data,
78     unsigned int bits);
79
80 public slots:
81   virtual void startSendingCommand(
82     unsigned int threadableID,
83     PIRKeyName command) = 0;
84
85 signals:
86   void commandFailed(
87     const char *errString);
88
89 protected:
90   bool isCommandSupported(
91     PIRKeyName command);
92
93   void clearRepeatFlag();
94   bool checkRepeatFlag();
95
96   unsigned int carrierFrequency;
97   unsigned int dutyCycle;
98
99   // "appendToBitSeq" really doesn't belong in this class...
100   void appendToBitSeq(
101     CommandSequence &sequence,
102     unsigned int bits,
103     int significantBits);
104
105   KeycodeCollection keycodes;
106
107   // A sleep function for all protocols:
108   void sleepUntilRepeat(
109     int commandDuration);
110
111   // The "gap" parameter from LIRC.  If the commands are "variable-length",
112   // this indicates the amount of time between the last pulse of one
113   // command and the first pulse of the next.  If "constant-length", it is
114   // the time between the _first_ pulse of one command and the first pulse
115   // of the next.
116
117   bool isConstantLength;
118   int gap;
119
120   // More administrative data wrapped around the actual command:
121   CommandSequence preData;
122   CommandSequence postData;
123
124   // Some remotes require a minimum number of repetitions:
125   // Note: thinking about removing this -- don't know if it is needed
126   int minimumRepetitions;
127
128   unsigned int id;
129 };
130
131 #endif // PIRPROTOCOL_H