Пример #1
0
void F12Protocol::startSendingCommand(
  unsigned int threadableID,
  PIRKeyName command)
{
  // Exceptions here are problematic; I'll try to weed them out by putting the
  // whole thing in a try/catch block:
  try
  {
    // First, check if we are meant to be the recipient of this command:
    if (threadableID != id) return;

    clearRepeatFlag();

    KeycodeCollection::const_iterator i = keycodes.find(command);

    // Do we even have this key defined?
    if (i == keycodes.end())
    {
      QMutexLocker cifLocker(&commandIFMutex);
      commandInFlight = false;
      return;
//      std::string s = "Tried to send a non-existent command.\n";
//      throw PIRException(s);
    }

    // construct the device:
    PIRInfraredLED led(carrierFrequency, dutyCycle);

    int commandDuration = 0;

    if (isSingleShot((*i).second.firstCode))
    {
      commandDuration = generateSingleShotCommand((*i).second, led);
      led.sendCommandToDevice();
      f12SleepUntilRepeat(33760);
      led.sendCommandToDevice();
    }
    else
    {
      int repeatCount = 0;

      commandDuration = generateRepeatableCommand((*i).second, led);

      while (repeatCount < MAX_REPEAT_COUNT)
      {
        led.sendCommandToDevice();

        if (repeatCount % 2)
        {
          f12SleepUntilRepeat(33760);
        }
        else
        {
          f12SleepUntilRepeat(87776);
        }

        // Check whether we've reached the minimum number of repetitons:
        if (repeatCount >= minimumRepetitions)
        {
          // Check whether we've been asked to stop:
          if (checkRepeatFlag())
          {
            break;
          }
        }

        ++repeatCount;
      }
    }

    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
  }
  catch (PIRException e)
  {
    // inform the gui:
    emit commandFailed(e.getError().c_str());
  }
}
Пример #2
0
void F12Protocol::startSendingCommand(
  unsigned int threadableID,
  PIRKeyName command)
{
  // First, check if we are meant to be the recipient of this command:
  if (threadableID != id) return;

  clearRepeatFlag();

  KeycodeCollection::const_iterator i = keycodes.find(command);

  // Do we even have this key defined?
  if (i == keycodes.end())
  {
    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
    emit errorMessage("Key not defined in this keyset.");
    return;
  }

  // construct the device:
  PIRInfraredLED led(carrierFrequency, dutyCycle);

  connect(
    &led,
    SIGNAL(errorMessage(QString)),
    this,
    SIGNAL(errorMessage(QString)));

  int commandDuration = 0;

  if (isSingleShot((*i).second.firstCode))
  {
    commandDuration = generateSingleShotCommand((*i).second, led);
    if (led.sendCommandToDevice())
    {
      f12SleepUntilRepeat(33760);
      led.sendCommandToDevice();
    }
  }
  else
  {
    int repeatCount = 0;

    commandDuration = generateRepeatableCommand((*i).second, led);

    while (repeatCount < MAX_REPEAT_COUNT)
    {
      if (!led.sendCommandToDevice())
      {
        break;
      }

      if (repeatCount % 2)
      {
        f12SleepUntilRepeat(33760);
      }
      else
      {
        f12SleepUntilRepeat(87776);
      }

      // Check whether we've reached the minimum number of repetitons:
      if (repeatCount >= minimumRepetitions)
      {
        // Check whether we've been asked to stop:
        if (checkRepeatFlag())
        {
          break;
        }
     }

      ++repeatCount;
    }
  }

  QMutexLocker cifLocker(&commandIFMutex);
  commandInFlight = false;
}