Allow TABS in config
[clinton/Smoothieware.git] / src / modules / utils / pausebutton / PauseButton.cpp
1 #include "libs/Kernel.h"
2 #include "PauseButton.h"
3 #include "libs/nuts_bolts.h"
4 #include "libs/utils.h"
5 #include "Config.h"
6 #include "SlowTicker.h"
7 #include "Pauser.h"
8
9 #include <string>
10 using namespace std;
11
12 PauseButton::PauseButton(){}
13
14 void PauseButton::on_module_loaded(){
15 this->button_state = true;
16 this->play_state = true;
17
18 this->enable = THEKERNEL->config->value( pause_button_enable_checksum )->by_default(false)->as_bool();
19 this->button.from_string( THEKERNEL->config->value( pause_button_pin_checksum )->by_default("2.12")->as_string())->as_input();
20
21 THEKERNEL->slow_ticker->attach( 100, this, &PauseButton::button_tick );
22 }
23
24 //TODO: Make this use InterruptIn
25 //Check the state of the button and act accordingly
26 uint32_t PauseButton::button_tick(uint32_t dummy){
27 if(!this->enable) return 0;
28 // If button changed
29 bool newstate = this->button.get();
30 if(this->button_state != newstate){
31 this->button_state = newstate;
32 // If button pressed
33 if( this->button_state ){
34 if( this->play_state ){
35 this->play_state = false;
36 THEKERNEL->pauser->take();
37 }else{
38 this->play_state = true;
39 THEKERNEL->pauser->release();
40 }
41 }
42 }
43 return 0;
44 }