enabled specifying numeric config values using all strtof capabilities
[clinton/Smoothieware.git] / src / libs / Pauser.cpp
CommitLineData
423df6df 1#include "Pauser.h"
43b1a6e8
MM
2
3#include "libs/Kernel.h"
4#include "Block.h"
423df6df
AW
5#include "libs/nuts_bolts.h"
6#include "libs/utils.h"
43b1a6e8 7
423df6df
AW
8#include <string>
9using namespace std;
10
93694d6b
AW
11// The Pauser module is the core of the pausing subsystem in smoothie. Basically we want several modules to be able to pause smoothie at the same time
12// ( 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,
13// a pause event is called, and the pause does not end before all modules have called the release() method.
d337942a 14// Please note : Modules should keep track of their pause status themselves
43b1a6e8
MM
15Pauser::Pauser(){
16 paused_block = NULL;
17}
423df6df
AW
18
19void Pauser::on_module_loaded(){
20 this->counter = 0;
43b1a6e8
MM
21 register_for_event(ON_BLOCK_BEGIN);
22}
23
24void Pauser::on_block_begin(void* argument)
25{
26 Block* block = static_cast<Block*>(argument);
27
28 if (counter)
29 {
30 block->take();
31 paused_block = block;
32 }
423df6df
AW
33}
34
93694d6b 35// Pause smoothie if nobody else is currently doing so
423df6df
AW
36void Pauser::take(){
37 this->counter++;
314ab8f7 38 //THEKERNEL->streams->printf("take: %u \r\n", this->counter );
423df6df 39 if( this->counter == 1 ){
314ab8f7 40 THEKERNEL->call_event(ON_PAUSE, &this->counter);
423df6df
AW
41 }
42}
43
93694d6b 44// Unpause smoothie unless something else is pausing it too
423df6df
AW
45void Pauser::release(){
46 this->counter--;
314ab8f7 47 //THEKERNEL->streams->printf("release: %u \r\n", this->counter );
423df6df 48 if( this->counter == 0 ){
314ab8f7 49 THEKERNEL->call_event(ON_PLAY, &this->counter);
43b1a6e8
MM
50 if (paused_block)
51 {
4e7a5763 52 Block* tmp = paused_block;
43b1a6e8 53 paused_block = NULL;
4e7a5763 54 tmp->release();
43b1a6e8 55 }
423df6df
AW
56 }
57}
8e075270 58
93694d6b
AW
59// Return wether smoothie is paused
60bool Pauser::paused(){
8e075270
MM
61 return (counter != 0);
62}