f6179ec4b3c9cf37cd844ac5065096bde824dcce
[pierogi] / protocols / spaceprotocol.cpp
1 #include "spaceprotocol.h"
2
3 SpaceProtocol::SpaceProtocol(
4   QObject *guiObject,
5   unsigned int index,
6   unsigned int zerop,
7   unsigned int zeros,
8   unsigned int onep,
9   unsigned int ones,
10   unsigned int headerp,
11   unsigned int headers,
12   unsigned int trailerp,
13   unsigned int gaps,
14   bool iclflag)
15   : PIRProtocol(guiObject, index, gaps, iclflag),
16     zeroPulse(zerop),
17     zeroSpace(zeros),
18     onePulse(onep),
19     oneSpace(ones),
20     headerPulse(headerp),
21     headerSpace(headers),
22     trailerPulse(trailerp)
23 {
24 }
25
26
27 int SpaceProtocol::pushBits(
28   const CommandSequence &bits,
29   PIRRX51Hardware &rx51device)
30 {
31   int duration = 0;
32   CommandSequence::const_iterator i = bits.begin();
33   while (i != bits.end())
34   {
35     if (*i)
36     {
37       // Send the pulse for "One":
38       rx51device.addPair(onePulse, oneSpace);
39       duration += (onePulse + oneSpace);
40     }
41     else
42     {
43       // Send the pulse for "Zero":
44       rx51device.addPair(zeroPulse, zeroSpace);
45       duration += (zeroPulse + zeroSpace);
46     }
47     ++i;
48   }
49
50   return duration;
51 }
52
53
54 int SpaceProtocol::pushReverseBits(
55   const CommandSequence &bits,
56   PIRRX51Hardware &rx51device)
57 {
58   int duration = 0;
59   CommandSequence::const_reverse_iterator i = bits.rbegin();
60   while (i != bits.rend())
61   {
62     if (*i)
63     {
64       // Send the pulse for "One":
65       rx51device.addPair(onePulse, oneSpace);
66       duration += (onePulse + oneSpace);
67     }
68     else
69     {
70       // Send the pulse for "Zero":
71       rx51device.addPair(zeroPulse, zeroSpace);
72       duration += (zeroPulse + zeroSpace);
73     }
74     ++i;
75   }
76
77   return duration;
78 }
79
80
81 int SpaceProtocol::pushInvertedReverseBits(
82   const CommandSequence &bits,
83   PIRRX51Hardware &rx51device)
84 {
85   int duration = 0;
86   CommandSequence::const_reverse_iterator i = bits.rbegin();
87   while (i != bits.rend())
88   {
89     if (*i)
90     {
91       // Send the pulse for "Zero":
92       rx51device.addPair(zeroPulse, zeroSpace);
93       duration += (zeroPulse + zeroSpace);
94     }
95     else
96     {
97       // Send the pulse for "One":
98       rx51device.addPair(onePulse, oneSpace);
99       duration += (onePulse + oneSpace);
100     }
101     ++i;
102   }
103
104   return duration;
105 }