示例#1
0
int ProtonProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // The Proton protocol contains an 8 bit address and an 8 bit command,
  // in LSB order.  Between these two is a gap made up of a 500 usec pulse
  // and a 4000 usec space.
  // - "preData" should contain the address.
  // - "firstCode" should contain the command.

  duration += pushReverseBits(preData, led);

  led.addPair(500, 4000);
  duration += 4500;

  duration += pushReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#2
0
int DenonProtocol::generateRepeatCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // The address should be 5 bits long, and the control data 8 bits.
  // For the repeat, the control data is inverted.
  // Both are sent in LSB order.
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushInvertedReverseBits(pkb.secondCode, led);

  // Next, two One bits are sent (the inverse of the normal command):
  led.addPair(onePulse, oneSpace);
  duration += onePulse + oneSpace;

  led.addPair(onePulse, oneSpace);
  duration += onePulse + oneSpace;

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#3
0
int XMPProtocol::generateRepeatCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // an XMP repeat frame is identical to the start frame, except that
  // the "toggle" value is now 8.

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(calculateChecksumOne(), led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushHalfByte(0xF, led);
  duration += pushFullByte(oemCode, led);
  duration += pushFullByte(deviceCode, led);

  led.addPair(210, 13800);
  duration += 14010;

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(
    calculateChecksumTwo(0x8, pkb.firstCode, pkb.secondCode),
    led);
  duration += pushHalfByte(0x8, led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushBits(pkb.firstCode, led);
  duration += pushBits(pkb.secondCode, led);

  // Finally add the "trail":
  led.addSingle(210);
  duration += 210;

  return duration;
}
示例#4
0
int RECS80Protocol::generateCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Next, a toggle bit:
  if (keypressCount % 2)
  {
    led.addPair(zeroPulse, zeroSpace);
    duration += (zeroPulse + zeroSpace);
  }
  else
  {
    led.addPair(onePulse, oneSpace);
    duration += (onePulse + oneSpace);
  }

  // Next, the device code and command code.  The device code is three
  // bits long; the command code is six bits long.  Both are sent in MSB order.
  duration += pushBits(preData, led);
  duration += pushBits(pkb.firstCode, led);

  // Finally, add the trailing pulse:
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#5
0
int AiwaProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // From the information I've got, the "address" portion of the Aiwa protocol
  // might be split into 8-bit device and 5-bit subdevice subsections, but
  // for now, I'm just lumping both into a single 13-bit address value.
  // The command is an 8-bit value.
  // As with NEC, the address is sent LSB first, then inverted LSB first,
  // then the command is sent LSB first, then inverted LSB first.
  duration += pushReverseBits(preData, led);
  duration += pushInvertedReverseBits(preData, led);
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushInvertedReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#6
0
int KathreinProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Kathrein protocol has four bits of address and eight bits of command.
  // As in NEC protocol, the address and command are complemented.
  // - "preData" should contain the 4-bit address
  // - "firstCode" should contain the 8-bit command
  duration += pushReverseBits(preData, led);
  duration += pushInvertedReverseBits(preData, led);
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushInvertedReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#7
0
int DaewooProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // The address data:
  duration += pushReverseBits(preData, led);

  // The Daewoo mid-train marker:
  led.addPair(midPulse, midSpace);
  duration += (midPulse + midSpace);

  // The command data:
  duration += pushReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#8
0
int PaceProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Next, the toggle bit:
  if (keypressCount % 2)
  {
    led.addPair(onePulse, oneSpace);
    duration += (onePulse + oneSpace);
  }
  else
  {
    led.addPair(zeroPulse, zeroSpace);
    duration += (zeroPulse + zeroSpace);
  }

  // Next, three bits of pre-data:
  duration += pushBits(preData, led);

  // Next, six bits of data:
  duration += pushBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#9
0
int XMPProtocol::generateFinalCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // an XMP final frame is basically a pair of repeat frames, but the
  // gap between them is only 13800 usec, and the "toggle" value of the
  // second frame is 9.

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(calculateChecksumOne(), led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushHalfByte(0xF, led);
  duration += pushFullByte(oemCode, led);
  duration += pushFullByte(deviceCode, led);

  led.addPair(210, 13800);
  duration += 14010;

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(
    calculateChecksumTwo(0x8, pkb.firstCode, pkb.secondCode),
    led);
  duration += pushHalfByte(0x8, led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushBits(pkb.firstCode, led);
  duration += pushBits(pkb.secondCode, led);

  led.addPair(210, 13800);
  duration += 14010;

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(calculateChecksumOne(), led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushHalfByte(0xF, led);
  duration += pushFullByte(oemCode, led);
  duration += pushFullByte(deviceCode, led);

  led.addPair(210, 13800);
  duration += 14010;

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(
    calculateChecksumTwo(0x9, pkb.firstCode, pkb.secondCode),
    led);
  duration += pushHalfByte(0x9, led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushBits(pkb.firstCode, led);
  duration += pushBits(pkb.secondCode, led);

  // Finally add the "trail":
  led.addSingle(210);
  duration += 210;

  return duration;
}
示例#10
0
int XMPProtocol::pushFullByte(
  unsigned int fullByte,
  PIRInfraredLED &led)
{
  unsigned int firstSpace = 760 + (136 * (fullByte >> 4));
  unsigned int secondSpace = 760 + (136 * (fullByte & 0xF));

  led.addPair(210, firstSpace);
  led.addPair(210, secondSpace);

  return (420 + firstSpace + secondSpace);
}
示例#11
0
void SamsungACProtocol::generateTimerCommand(
  PIRInfraredLED &led)
{
  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);

  // Next, the "address" information (12 bits):
  pushReverseBits(preData, led);

  // The checksum (4 bits):
  CommandSequence checksum;
  calculateTimerChecksum(checksum);
  pushReverseBits(checksum, led);

  // Push an 0xF to indicate this is a timer command.
  pushBits(timerHeader, led);

  // if this is an off timer, push the time, otherwise 0:
  if (timerCommandType == 0x4)
  {
    pushReverseBits(timerMinutes, led);
    pushReverseBits(timerHours, led);
  }
  else
  {
    pushBits(emptyTimer, led);
  }

  // if this is an on timer, push the time, otherwise 0:
  if (timerCommandType == 0x2)
  {
    pushReverseBits(timerMinutes, led);
    pushReverseBits(timerHours, led);
  }
  else
  {
    pushBits(emptyTimer, led);
  }

  // This is a hack to add in 4 bits of 0:
  pushBits(fourBitZero, led);

  // Push the timer command type:
  pushReverseBits(timerOption, led);

  // Finish off the command:
  pushBits(timerFooter, led);

  // Add the "trail":
  led.addSingle(trailerPulse);
}
示例#12
0
int XMPProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // XMP frames have the following structure:
  // 1) The first 4 bits of the "sub-device" code
  // 2) A four-bit checksum value
  // 3) The second 4 bits of the "sub-device" code
  // 4) The four-bit value 0xF
  // 5) An eight-bit OEM code (normally 0x44)
  // 6) An eight-bit device code
  // 7) a 210 usec pulse, 13800 usec space divider
  // 8) The first 4 bits of the "sub-device" code (again)
  // 9) Another four-bit checksum value
  // 10) The four-bit toggle value
  // 11) The second 4 bits of the "sub-device" code (again)
  // 12) A pair of 8-bit command codes (often one of them will be 0)
  // All of this is sent in MSB order.
  // The checksums are constructed by adding up all the half-bytes in
  // their side of the frame to 15, taking the complement, and modding the
  // result with 16.

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(calculateChecksumOne(), led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushHalfByte(0xF, led);
  duration += pushFullByte(oemCode, led);
  duration += pushFullByte(deviceCode, led);

  led.addPair(210, 13800);
  duration += 14010;

  duration += pushHalfByte(subDeviceOne, led);
  duration += pushHalfByte(
    calculateChecksumTwo(0x0, pkb.firstCode, pkb.secondCode),
    led);
  duration += pushHalfByte(0x0, led);
  duration += pushHalfByte(subDeviceTwo, led);
  duration += pushBits(pkb.firstCode, led);
  duration += pushBits(pkb.secondCode, led);

  // Finally add the "trail":
  led.addSingle(210);
  duration += 210;

  return duration;
}
示例#13
0
int GIProtocol::generateRepeatCommand(
  PIRInfraredLED &led)
{
  int duration = 0;

  // Add the repeat pulse:
  led.addPair(repeatPulse, repeatSpace);
  duration += (repeatPulse + repeatSpace);

  // Add the trailer:
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#14
0
int XMPProtocol::pushHalfByte(
  unsigned int halfByte,
  PIRInfraredLED &led)
{
  unsigned int space = 760 + (136 * halfByte);
  led.addPair(210, space);

  return (210 + space);
}
示例#15
0
int KathreinProtocol::generateRepeatCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // The Kathrein repeat block contains the 8-bit command and nothing else:
  duration += pushReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#16
0
int NECXProtocol::generateRepeatCommand(
  PIRInfraredLED &led)
{
  int duration = 0;

  // Start with the header:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Add a "1":
  led.addPair(onePulse, oneSpace);
  duration += (onePulse + oneSpace);

  // Add the trailer:
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#17
0
void SamsungACProtocol::generateCommand(
  PIRInfraredLED &led)
{
  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);

  // Next, the "address" information (12 bits):
  pushReverseBits(preData, led);

  // Now, the fun part.  We'll need to construct a massive command, containing
  // all the state information for the air conditioner.

  // First, calculate and push the checksum (4 bits):
  CommandSequence checksum;
  calculateChecksum(checksum);
  pushReverseBits(checksum, led);

  // Next, push the swing mode (8 bits):
  pushReverseBits(swing, led);

  // Next, the turbo mode (8 bits):
  pushReverseBits(turbo, led);

  // Next, the temperature (8 bits):
  pushReverseBits(temperature, led);

  // Next, the fan (4 bits):
  pushReverseBits(fan, led);

  // Next, the mode (4 bits):
  pushReverseBits(mode, led);

  // Next, "air clean" (4 bits):
  pushReverseBits(airclean, led);

  // Next, power (4 bits):
  pushReverseBits(power, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
}
示例#18
0
int NECProtocol::generateStandardCommand(
    const PIRKeyBits &pkb,
    PIRInfraredLED &led)
{
    int duration = 0;

    // First, the "header" pulse:
    led.addPair(headerPulse, headerSpace);
    duration += (headerPulse + headerSpace);

    // Now, check the encoding format:
    if (isExtendedNEC)
    {
        // In extended NEC, the address has been extended to 16 bits, and is only
        // sent once.  The command portion stays the same.
        // - "preData" should contain 16-bit value
        // - "bits" should contain 8-bit value
        duration += pushReverseBits(preData, led);
        duration += pushReverseBits(pkb.firstCode, led);
        duration += pushInvertedReverseBits(pkb.firstCode, led);
    }
    else
    {
        // Standard NEC is made up of an eight-bit "address" and an eight-bit
        // "command".  First the address bits are sent (in reverse order), then
        // the address bits are inverted and sent again (in reverse order).
        // Next, we do the same to the command bits.
        // - "preData" should contain 8-bit value
        // - "bits" should contain 8-bit value
        duration += pushReverseBits(preData, led);
        duration += pushInvertedReverseBits(preData, led);
        duration += pushReverseBits(pkb.firstCode, led);
        duration += pushInvertedReverseBits(pkb.firstCode, led);
    }

    // Finally add the "trail":
    led.addSingle(trailerPulse);
    duration += trailerPulse;

    return duration;
}
示例#19
0
int XMPProtocol::pushBits(
  const CommandSequence &bits,
  PIRInfraredLED &led)
{
  unsigned int duration = 0;

  // We can only sent 4-bit values in XMP, so need to collect bits up into
  // bundles of 4:

  unsigned int bitsValue = 0;
  int count = 0;
  CommandSequence::const_iterator i = bits.begin();

  while (i != bits.end())
  {
    if (count < 4)
    {
      bitsValue = bitsValue << 1;
      bitsValue += *i;
      ++count;
    }
    else
    {
      led.addPair(210, 760 + (136 * bitsValue));
      duration += 970 + (136 * bitsValue);

      count = 1;
      bitsValue = *i;
    }

    ++i;
  }

  if (count == 4)
  {
    led.addPair(210, 760 + (136 * bitsValue));
    duration += 970 + (136 * bitsValue);
  }

  return duration;
}
示例#20
0
int PanasonicProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the header pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Similar to the "Kaseikyo" protocol, this protocol is 48 bits long.
  // In this case, the first 16 bits are a fixed value (defining the
  // manufacturer?).  Next comes eight bits for the "device", eight more
  // bits for the "subdevice", and then eight bits for the "command".
  // Finally, the last eight bits are a checksum generated by x-oring the
  // device, subdevice, and command bytes.

  // The 16 manufacturer code bits:
  duration += pushReverseBits(preData, led);

  // The eight device bits:
  duration += pushReverseBits(pkb.firstCode, led);

  // The eight subdevice bits:
  duration += pushReverseBits(pkb.secondCode, led);

  // The eight command bits:
  duration += pushReverseBits(pkb.thirdCode, led);

  // Finally, the checksum:
  CommandSequence checksum;
  generateChecksum(pkb.firstCode, pkb.secondCode, pkb.thirdCode, checksum);
  duration += pushReverseBits(checksum, led);

  // Add the trailer pulse:
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#21
0
int RCAProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // Now, set up the address and command bits:
  duration += pushBits(preData, led);
  duration += pushBits(pkb.firstCode, led);
  duration += pushInvertedBits(preData, led);
  duration += pushInvertedBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#22
0
int BoseProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // The Bose protocol uses 1/2 of the NEC protocol; it has the command
  // portion, but no device address portion.  So, we only need to reverse
  // the command, then invert and reverse the command:
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushInvertedReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#23
0
int DenonProtocol::generateCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // The address should be 5 bits long, and the control data 8 bits.
  // Both are sent in LSB order.
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushReverseBits(pkb.secondCode, led);

  // Next, two Zero bits are sent:
  led.addPair(zeroPulse, zeroSpace);
  duration += zeroPulse + zeroSpace;

  led.addPair(zeroPulse, zeroSpace);
  duration += zeroPulse + zeroSpace;

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#24
0
int NECXProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // In NECX, the address is 16 bits, and is only sent once.  The command
  // portion is 8 bits, and an inverted copy is sent.
  // - "preData" should contain 16-bit value
  // - "bits" should contain 8-bit value
  duration += pushReverseBits(preData, led);
  duration += pushReverseBits(pkb.firstCode, led);
  duration += pushInvertedReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#25
0
int GIProtocol::generateStandardCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // First, the "header" pulse:
  led.addPair(headerPulse, headerSpace);
  duration += (headerPulse + headerSpace);

  // The GI protocol consists of a 4-bit device code and an 8-bit command.
  // These are sent in reverse order.  Finally, a checksum is added at the
  // end.  I am lacking enough information to calculate the checksum right
  // now, so I'm going to dump all 16 bits into the "firstCode" in MSB
  // order, and reverse them here:

  duration += pushReverseBits(pkb.firstCode, led);

  // Finally add the "trail":
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#26
0
int MitsubishiProtocol::generateCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // For this protocol, the device code and command code are both 8 bits,
  // and sent in LSB order:
  duration += pushReverseBits(preData, led);
  duration += pushReverseBits(pkb.firstCode, led);

  // Finally add the "trail" bit:
  led.addSingle(trailerPulse);
  duration += trailerPulse;

  return duration;
}
示例#27
0
int F12Protocol::generateRepeatableCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // In the F12 protocol, the device code has 3 bits, and the command has 8
  // (sort of).  In reality, bits 4, 5, and 6 are "mode" bits, but it seems
  // 5 and 6 get pushed into the two least significant bits of the command
  // by the sources I've got (the command being sent in LSB mode).  This
  // method is only for "repeatable" commands, so bit 4 is always going to
  // be "1".
  // 
  // - "preData" contains 3-bit device code.
  // - "pkb.firstCode" contains 8-bit command code.
  duration += pushReverseBits(preData, led);
  led.addPair(onePulse, oneSpace);
  duration += (onePulse + oneSpace);
  duration += pushReverseBits(pkb.firstCode, led);

  return duration;
}
示例#28
0
int CanalSatProtocol::pushBit(
  bool bitValue,
  PIRInfraredLED &led)
{
  unsigned int duration = 0;

  if (bitValue)
  {
    // This is a "1", so first pulse, then space:
    if (bufferContainsPulse)
    {
      // Merge our pulse with preceding pulse, and add it to device:
      led.addSingle(buffer + biphaseUnit);
      duration += (buffer + biphaseUnit);
      buffer = 0;
      bufferContainsPulse = false;
    }
    else
    {
      // Flush out the buffer:
      if (bufferContainsSpace)
      {
        led.addSingle(buffer);
        duration += buffer;
        buffer = 0;
        bufferContainsSpace = false;
      }

      // Push our pulse into the device:
      led.addSingle(biphaseUnit);
      duration += biphaseUnit;
    }

    // Finally, push our space into the buffer:
    buffer = biphaseUnit;
    bufferContainsSpace = true;
  }
  else
  {
    // This is a "0", so first space, then pulse.
    if (bufferContainsSpace)
    {
      // Merge our space with the preceding space, and add it to device:
      led.addSingle(buffer + biphaseUnit);
      duration += (buffer + biphaseUnit);
      buffer = 0;
      bufferContainsSpace = false;
    }
    else
    {
      // Flush out the buffer:
      if (bufferContainsPulse)
      {
        led.addSingle(buffer);
        duration += buffer;
        buffer = 0;
        bufferContainsPulse = false;
      }

      // Add a space:
      led.addSingle(biphaseUnit);
      duration += biphaseUnit;
    }

    // Finally, push a pulse into the buffer:
    buffer = biphaseUnit;
    bufferContainsPulse = true;
  }

  return duration;
}
示例#29
0
int IRobotProtocol::generateCommand(
  const PIRKeyBits &pkb,
  PIRInfraredLED &led)
{
  int duration = 0;

  // The protocol seems to involve 8 command bits, a 16000 usec pause, and
  // the same 8 bits repeated again.  So, we need to tack a 16000 usec
  // space on at the end of the first 8 bits, and just drop the last space
  // definition at the end of the second 8 bits:

  // The first 7 bits:
  int index = 0;
  CommandSequence::const_iterator i = pkb.firstCode.begin();
  while ((index < 7) && (i != pkb.firstCode.end()))
  {
    if (*i)
    {
      led.addPair(onePulse, oneSpace);
      duration += onePulse + oneSpace;
    }
    else
    {
      led.addPair(zeroPulse, zeroSpace);
      duration += zeroPulse + zeroSpace;
    }

    ++index;
    ++i;
  }

  // Eighth bit with extra space at the end:
  if (i != pkb.firstCode.end())
  {
    if (*i)
    {
      led.addPair(onePulse, oneSpace + 16000);
      duration += onePulse + oneSpace + 16000;
    }
    else
    {
      led.addPair(zeroPulse, zeroSpace + 16000);
      duration += zeroPulse + zeroSpace + 16000;
    }
  }

  // The following seven bits:
  index = 0;
  i = pkb.firstCode.begin();
  while ((index < 7) && (i != pkb.firstCode.end()))
  {
    if (*i)
    {
      led.addPair(onePulse, oneSpace);
      duration += onePulse + oneSpace;
    }
    else
    {
      led.addPair(zeroPulse, zeroSpace);
      duration += zeroPulse + zeroSpace;
    }

    ++index;
    ++i;
  }

  // The last half-bit:
  if (i != pkb.firstCode.end())
  {
    if (*i)
    {
      led.addSingle(onePulse);
      duration += onePulse;
    }
    else
    {
      led.addSingle(zeroPulse);
      duration += zeroPulse;
    }
  }

  return duration;
}