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; }
// Note: it seems that Samsung AC remotes do not repeat commands! I'd love // to find verification of this, I've only one source for it... void SamsungACProtocol::startSendingCommand( unsigned int threadableID, PIRKeyName command) { // First, check if we are meant to be the recipient of this command: if (threadableID != id) return; 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))); if (command == ACSetTimer_Key) { generateTimerCommand(led); } else { generateCommand(led); } // Now, tell the device to send the whole command: led.sendCommandToDevice(); QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; }
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()); } }
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()); } }
void CanalSatProtocol::startSendingCommand( unsigned int threadableID, PIRKeyName command) { try { if (threadableID != id) return; clearRepeatFlag(); KeycodeCollection::const_iterator i = keycodes.find(command); // Sanity check, make sure command exists first: if (i == keycodes.end()) { QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; return; // should send an error message here!!! } // Create object to communicate with device driver: PIRInfraredLED led(carrierFrequency, dutyCycle); int repeatCount = 0; int commandDuration = 0; while (repeatCount < MAX_REPEAT_COUNT) { // Construct the CanalSat command string. commandDuration += pushBits((*i).second, repeatCount, led); // Clear out the buffer, if necessary: if (buffer) { led.addSingle(buffer); commandDuration += buffer; buffer = 0; bufferContainsSpace = false; bufferContainsPulse = false; } // Send the command: led.sendCommandToDevice(); // Sleep for the prescribed amount of time: sleepUntilRepeat(commandDuration); // Have we been told to stop? if (checkRepeatFlag()) { break; } ++repeatCount; } QMutexLocker cifLocker(&commandIFMutex); commandInFlight = false; } catch (PIRException e) { emit commandFailed(e.getError().c_str()); } catch (...) { emit commandFailed("Generic Error Message"); } }