-#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;
// ( 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
//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;
+ }
}
}
#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;
};