Exemplo n.º 1
0
void ProtonProtocol::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 repeatCount = 0;
  int commandDuration = 0;
  while (repeatCount < MAX_REPEAT_COUNT)
  {
    commandDuration = generateStandardCommand((*i).second, led);

    // Now, tell the device to send the whole command:
    if (!led.sendCommandToDevice())
    {
      break;
    }

    // sleep until the next repetition of command:
    sleepUntilRepeat(commandDuration);

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

    ++repeatCount;
  }

  QMutexLocker cifLocker(&commandIFMutex);
  commandInFlight = false;
}
Exemplo n.º 2
0
void DaewooProtocol::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 repeatCount = 0;
    int commandDuration = 0;
    while (repeatCount < MAX_REPEAT_COUNT)
    {
      commandDuration = generateStandardCommand((*i).second, led);

      // Now, tell the device to send the whole command:
      led.sendCommandToDevice();

      // sleep until the next repetition of command:
      sleepUntilRepeat(commandDuration);

      // Check whether we've reached the minimum required number of repetitons:
      if (repeatCount >= minimumRepetitions)
      {
        // Check whether we've been asked to stop:
        if (checkRepeatFlag())
        {
          break;
/*
          QMutexLocker cifLocker(&commandIFMutex);
          commandInFlight = false;
          return;
*/
        }
      }

      ++repeatCount;
    }

    QMutexLocker cifLocker(&commandIFMutex);
    commandInFlight = false;
  }
  catch (PIRException e)
  {
    // inform the gui:
    emit commandFailed(e.getError().c_str());
  }
}
Exemplo n.º 3
0
void NECProtocol::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;

        // An object that helps keep track of the number of commands:
//    PIRCommandCounter commandCounter;

        // Ok, we're going to lock down this method and make sure
        // only one guy at a time passes this point:
//    QMutexLocker commandLocker(&commandMutex);

        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 repeatCount = 0;
        int commandDuration = 0;
        while (repeatCount < MAX_REPEAT_COUNT)
        {
            // If we are currently repeating, and have a special "repeat signal",
            // use that signal.  Otherwise, generate a normal command string.
            if (isShortRepeat && repeatCount)
            {
                commandDuration = generateRepeatCommand(led);
            }
            else
            {
                commandDuration = generateStandardCommand((*i).second, led);
            }

            // Now, tell the device to send the whole command:
            led.sendCommandToDevice();

            // sleep until the next repetition of command:
            sleepUntilRepeat(commandDuration);

            // Check whether we've reached the minimum required number of repetitons:
            if (repeatCount >= minimumRepetitions)
            {
                // Check whether we've been asked to stop:
                if (checkRepeatFlag())
                {
                    break;
                    /*
                              QMutexLocker cifLocker(&commandIFMutex);
                              commandInFlight = false;
                              return;
                    */
                }
            }

            ++repeatCount;
        }

        QMutexLocker cifLocker(&commandIFMutex);
        commandInFlight = false;
    }
    catch (PIRException e)
    {
        // inform the gui:
        emit commandFailed(e.getError().c_str());
    }
}