Keyset Memory Management Bugfix
[pierogi] / protocols / necprotocol.cpp
index c29e539..ccaca00 100644 (file)
@@ -9,13 +9,18 @@
 extern bool commandInFlight;
 extern QMutex commandIFMutex;
 
+// Debugging:
+#include <iostream>
+
 // The official NEC protocol, as I understand it, has the following attributes:
 // A "zero" is encoded with a 560 usec pulse, 560 usec space.
 // A "one" is encoded with a 560 usec pulse, and 3*560 (1680) usec space.
 // The header is a 9000 usec pulse, 4500 usec space.
 // Commands end with a trailing 560 usec pulse.
-// A repeat block is a 9000 usec pulse, 2250 usec space, then trailing pulse.
+// A repeat block (if used) is a 9000 usec pulse, 2250 usec space, then
+// trailing pulse.
 // Each command runs for 110000 usec before another can be executed.
+// The normal carrier frequency is 38 kHz.
 
 NECProtocol::NECProtocol(
   QObject *guiObject,
@@ -34,6 +39,7 @@ NECProtocol::NECProtocol(
     isExtendedNEC(extNEC),
     isShortRepeat(srtRep)
 {
+  setMinimumRepetitions(1);
 }
 
 
@@ -62,8 +68,11 @@ void NECProtocol::startSendingCommand(
     // Do we even have this key defined?
     if (i == keycodes.end())
     {
-      std::string s = "Tried to send a non-existent command.\n";
-      throw PIRException(s);
+      QMutexLocker cifLocker(&commandIFMutex);
+      commandInFlight = false;
+      return;
+//      std::string s = "Tried to send a non-existent command.\n";
+//      throw PIRException(s);
     }
 
     // construct the device:
@@ -96,23 +105,26 @@ void NECProtocol::startSendingCommand(
         // 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());
   }
-
-  QMutexLocker cifLocker(&commandIFMutex);
-  commandInFlight = false;
 }