Use static kernel singleton pointer instead of per-class instance pointer
[clinton/Smoothieware.git] / src / libs / Pauser.cpp
CommitLineData
423df6df
AW
1#include "libs/Kernel.h"
2#include "Pauser.h"
3#include "libs/nuts_bolts.h"
4#include "libs/utils.h"
5#include <string>
6using namespace std;
7
93694d6b
AW
8// 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
9// ( 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,
10// a pause event is called, and the pause does not end before all modules have called the release() method.
d337942a 11// Please note : Modules should keep track of their pause status themselves
423df6df
AW
12Pauser::Pauser(){}
13
14void Pauser::on_module_loaded(){
15 this->counter = 0;
16}
17
93694d6b 18// Pause smoothie if nobody else is currently doing so
423df6df
AW
19void Pauser::take(){
20 this->counter++;
314ab8f7 21 //THEKERNEL->streams->printf("take: %u \r\n", this->counter );
423df6df 22 if( this->counter == 1 ){
314ab8f7 23 THEKERNEL->call_event(ON_PAUSE, &this->counter);
423df6df
AW
24 }
25}
26
93694d6b 27// Unpause smoothie unless something else is pausing it too
423df6df
AW
28void Pauser::release(){
29 this->counter--;
314ab8f7 30 //THEKERNEL->streams->printf("release: %u \r\n", this->counter );
423df6df 31 if( this->counter == 0 ){
314ab8f7 32 THEKERNEL->call_event(ON_PLAY, &this->counter);
423df6df
AW
33 }
34}
8e075270 35
93694d6b
AW
36// Return wether smoothie is paused
37bool Pauser::paused(){
8e075270
MM
38 return (counter != 0);
39}