Still fixing install, more keyset work
[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 bits);
44
45   void setCarrierFrequency(
46     unsigned int freq);
47
48   void setDutyCycle(
49     unsigned int dc);
50
51   void setMinimumRepetitions(
52     unsigned int minrep);
53
54   void setPreData(
55     unsigned long data,
56     unsigned int bits);
57
58   void setPostData(
59     unsigned long data,
60     unsigned int bits);
61
62 public slots:
63   virtual void startSendingCommand(
64     unsigned int threadableID,
65     PIRKeyName command) = 0;
66
67 signals:
68   void commandFailed(
69     const char *errString);
70
71 protected:
72   bool isCommandSupported(
73     PIRKeyName command);
74
75   void clearRepeatFlag();
76   bool checkRepeatFlag();
77
78   unsigned int carrierFrequency;
79   unsigned int dutyCycle;
80
81   // "appendToBitSeq" really doesn't belong in this class...
82   void appendToBitSeq(
83     CommandSequence &sequence,
84     unsigned int bits,
85     int significantBits);
86
87   KeycodeCollection keycodes;
88
89   // A sleep function for all protocols:
90   void sleepUntilRepeat(
91     int commandDuration);
92
93   // The "gap" parameter from LIRC.  If the commands are "variable-length",
94   // this indicates the amount of time between the last pulse of one
95   // command and the first pulse of the next.  If "constant-length", it is
96   // the time between the _first_ pulse of one command and the first pulse
97   // of the next.
98
99   bool isConstantLength;
100   int gap;
101
102   // More administrative data wrapped around the actual command:
103   CommandSequence preData;
104   CommandSequence postData;
105
106   // Some remotes require a minimum number of repetitions:
107   // Note: thinking about removing this -- don't know if it is needed
108   int minimumRepetitions;
109
110   unsigned int id;
111 };
112
113 #endif // PIRPROTOCOL_H