X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=pirprotocol.cpp;h=ddacbfd5866b7b63d06ea704e34b7b888f129825;hb=305addf8d83ed71844e938551ee900d06359d42a;hp=f3b8ff12aef01437cd09d7338ec278cf12accf36;hpb=4d7d993950ffa96e6822274d07261f05a9c11baf;p=pierogi diff --git a/pirprotocol.cpp b/pirprotocol.cpp index f3b8ff1..ddacbfd 100644 --- a/pirprotocol.cpp +++ b/pirprotocol.cpp @@ -12,6 +12,10 @@ extern bool stopRepeatingFlag; extern QMutex stopRepeatingMutex; +// Total of all running commands +extern bool commandInFlight; +extern QMutex commandIFMutex; + // From what I understand (mostly from reading LIRC config files), NEC // protocol based remotes mostly use a frequency of 38000 units and a // duty cycle of 50%. They'll be set to these defaults here, and overridden @@ -50,19 +54,80 @@ PIRProtocol::PIRProtocol( void PIRProtocol::addKey( PIRKeyName key, unsigned long command, - unsigned int bits) + unsigned int size) { - appendToBitSeq(keycodes[key], command, bits); + // First, if key already exists, clear it out: + KeycodeCollection::iterator i = keycodes.find(key); + if (i != keycodes.end()) + { + i->second.clear(); + } + + appendToBitSeq(keycodes[key], command, size); } -/* -void PIRProtocol::setIndex( - unsigned int i) +void PIRProtocol::addSIRCKey( + PIRKeyName key, + unsigned int addressData, + unsigned int size, + unsigned int commandData) { - id = i; + // First, if key already exists, clear it out: + KeycodeCollection::iterator i = keycodes.find(key); + if (i != keycodes.end()) + { + i->second.clear(); + } + + // First, append the address data: + appendToBitSeq(keycodes[key], addressData, size); + + // Next, the command data. The size is always 7 bits: + appendToBitSeq(keycodes[key], commandData, 7); +} + + +void PIRProtocol::addSIRC20Key( + PIRKeyName key, + unsigned int secondaryAddressData, + unsigned int primaryAddressData, + unsigned int commandData) +{ + // First, if key already exists, clear it out: + KeycodeCollection::iterator i = keycodes.find(key); + if (i != keycodes.end()) + { + i->second.clear(); + } + + // First, append the secondary address data: + appendToBitSeq(keycodes[key], secondaryAddressData, 8); + + // Next, the primary address data: + appendToBitSeq(keycodes[key], primaryAddressData, 5); + + // Next, the command data. The size is always 7 bits: + appendToBitSeq(keycodes[key], commandData, 7); +} + + +void PIRProtocol::addSharpKey( + PIRKeyName key, + unsigned int addressData, + unsigned int commandData) +{ + // First, if key already exists, clear it out: + KeycodeCollection::iterator i = keycodes.find(key); + if (i != keycodes.end()) + { + i->second.clear(); + } + + // Sharp commands are all 5 bit address, 8 bit command: + appendToBitSeq(keycodes[key], addressData, 5); + appendToBitSeq(keycodes[key], commandData, 8); } -*/ void PIRProtocol::setCarrierFrequency( @@ -86,6 +151,34 @@ void PIRProtocol::setMinimumRepetitions( } +void PIRProtocol::setPreData( + unsigned long data, + unsigned int bits) +{ + // If the container is not empty, first clear it out: + if (!preData.empty()) + { + preData.clear(); + } + + appendToBitSeq(preData, data, bits); +} + + +void PIRProtocol::setPostData( + unsigned long data, + unsigned int bits) +{ + // If the container is not empty, first clear it out: + if (!postData.empty()) + { + postData.clear(); + } + + appendToBitSeq(postData, data, bits); +} + + bool PIRProtocol::isCommandSupported( PIRKeyName command) { @@ -96,9 +189,9 @@ bool PIRProtocol::isCommandSupported( void PIRProtocol::appendToBitSeq( CommandSequence &sequence, unsigned int bits, - int significantBits) + int size) { - if (significantBits == 0) + if (size == 0) { // This is bad, but just return silently for now... return; @@ -106,7 +199,7 @@ void PIRProtocol::appendToBitSeq( // For each bit in the char, append a 1 or a 0 into the sequence. // Starting with the largest bit, move forward one bit at a time: - unsigned int currentBit = 1 << (significantBits - 1); + unsigned int currentBit = 1 << (size - 1); do { @@ -166,11 +259,19 @@ void PIRProtocol::sleepUntilRepeat( microseconds = gap - PIEROGI_OVERHEAD_HACK; } +/* // Don't even bother sleeping if there's only a few microseconds: if (microseconds < 1000) { return; } +*/ + // For now, I'm going to enforce a minimum sleep of 10 ms, so that we + // don't get runaway commands: + if (microseconds < 10000) + { + microseconds = 10000; + } timespec sleeptime; sleeptime.tv_sec = 0;