Pauser: take block during on_block_begin to correctly stall queue while paused origin/feature/Pauser_stall_queue
authorMichael Moon <triffid.hunter@gmail.com>
Sun, 19 Jan 2014 08:20:30 +0000 (19:20 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Sun, 19 Jan 2014 08:20:30 +0000 (19:20 +1100)
src/libs/Kernel.h
src/libs/Pauser.cpp
src/libs/Pauser.h

index c8f0fc4..4122c91 100644 (file)
@@ -30,6 +30,8 @@ class Config;
 class Module;
 class Conveyor;
 class SlowTicker;
+class Pauser;
+
 class Kernel {
     public:
         Kernel();
index be469c2..65712f0 100644 (file)
@@ -1,7 +1,10 @@
-#include "libs/Kernel.h"
 #include "Pauser.h"
+
+#include "libs/Kernel.h"
+#include "Block.h"
 #include "libs/nuts_bolts.h"
 #include "libs/utils.h"
+
 #include <string>
 using namespace std;
 
@@ -9,10 +12,24 @@ using namespace std;
 // ( think both the user with a button, and the temperature control because a temperature is not reached ). To do that, modules call the take() methode, 
 // a pause event is called, and the pause does not end before all modules have called the release() method. 
 // Please note : Modules should keep track of their pause status themselves
-Pauser::Pauser(){}
+Pauser::Pauser(){
+    paused_block = NULL;
+}
 
 void Pauser::on_module_loaded(){
     this->counter = 0;
+    register_for_event(ON_BLOCK_BEGIN);
+}
+
+void Pauser::on_block_begin(void* argument)
+{
+    Block* block = static_cast<Block*>(argument);
+
+    if (counter)
+    {
+        block->take();
+        paused_block = block;
+    }
 }
 
 // Pause smoothie if nobody else is currently doing so
@@ -30,6 +47,11 @@ void Pauser::release(){
     //THEKERNEL->streams->printf("release: %u \r\n", this->counter );
     if( this->counter == 0 ){
         THEKERNEL->call_event(ON_PLAY, &this->counter);
+        if (paused_block)
+        {
+            paused_block->release();
+            paused_block = NULL;
+        }
     }
 }
 
index b9e3be3..6f8f299 100644 (file)
@@ -5,15 +5,20 @@
 #include "libs/nuts_bolts.h"
 #include "libs/utils.h"
 
+class Block;
+
 class Pauser : public Module {
     public:
         Pauser();
         void on_module_loaded();
+        void on_block_begin(void*);
+
         void take();
         void release();
 
         bool paused();
 
+        Block* paused_block;
         unsigned short counter;
 };