Improved Keyset Selection Window
[pierogi] / necprotocol.h
1 #ifndef NECPROTOCOL_H
2 #define NECPROTOCOL_H
3
4 #include "pirprotocol.h"
5 #include "pirrx51hardware.h"
6
7 //
8 // The "NEC" Protocol is, more or less, followed by the majority of
9 // remotes defined in the LIRC config files, which means it is probably
10 // followed by most of the remotes out there.
11 //
12 // Remotes using this protocol seem to use a frequency of 38000 Hz, lead off
13 // each command with a signal that should be unique to the manufacturer,
14 // and mostly define 0s and 1s by the length of time between pulses...
15 //
16
17 class NECProtocol: public PIRProtocol
18 {
19 public:
20   // An NEC protocol will always have differing times for "zero" and "one".
21   // Also, all protocols have some space set between commands.  However,
22   // some protocols specify a fixed delay between the end of one
23   // command and the start of the next, and others specify each command be
24   // started at a precise interval (so the spacing between the end of one
25   // and the start of another may vary).
26   NECProtocol(
27     QObject *guiObject,
28     unsigned int index,
29     unsigned int zPulse,
30     unsigned int zSpace,
31     unsigned int oPulse,
32     unsigned int oSpace,
33     unsigned int gapSpace,
34     bool iclflag);
35
36   void setHeaderPair(
37     unsigned int pulse,
38     unsigned int space);
39
40   void setTrailerPulse(
41     unsigned int pulse);
42
43   void setRepeatPair(
44     unsigned int pulse,
45     unsigned int space);
46
47   void setPreData(
48     unsigned long data,
49     unsigned int bits);
50
51   void setPostData(
52     unsigned long data,
53     unsigned int bits);
54
55   void setRepeatNeedsHeader(
56     bool flag);
57
58   void setFullHeadlessRepeat(
59     bool flag);
60
61 public slots:
62   void startSendingCommand(
63     unsigned int threadableID,
64     PIRKeyName command);
65
66 private:
67   // First, define what is used to represent 0 and 1:
68   unsigned int zeroPulse;
69   unsigned int zeroSpace;
70   unsigned int onePulse;
71   unsigned int oneSpace;
72
73   // A tailing on-request, not followed by a specific off time:
74   unsigned int trailerPulse;
75   bool hasTrailerPulse;
76
77   // Each remote key has a unique command sequence:
78 //  KeyCommandMap commands;
79
80   // Some administrative data that most NEC Protocol remotes have:
81   unsigned int headerPulse;
82   unsigned int headerSpace;
83   bool hasHeaderPair;
84
85   // More administrative data wrapped around the actual command:
86   CommandSequence preData;
87   CommandSequence postData;
88
89   // A pulse that means "repeat the last command":
90   unsigned int repeatPulse;
91   unsigned int repeatSpace;
92   bool hasRepeatPair;
93   bool repeatNeedsHeader; // Put the header ahead of the repeat pulse
94   bool fullHeadlessRepeat; // Repeat full command but without header
95
96   int generateStandardCommand(
97     const CommandSequence &bits,
98     PIRRX51Hardware &device);
99
100   int generateHeadlessCommand(
101     const CommandSequence &bits,
102     PIRRX51Hardware &device);
103
104   int generateRepeatCommand(
105     PIRRX51Hardware &device);
106
107   int pushBits(
108     const CommandSequence &bits,
109     PIRRX51Hardware &device);
110 };
111
112 #endif // NECPROTOCOL_H