1 #include "libs/Kernel.h"
2 #include "PauseButton.h"
3 #include "libs/nuts_bolts.h"
4 #include "libs/utils.h"
6 #include "SlowTicker.h"
12 PauseButton::PauseButton(){}
14 void PauseButton::on_module_loaded(){
15 this->button_state
= true;
16 this->play_state
= true;
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();
21 THEKERNEL
->slow_ticker
->attach( 100, this, &PauseButton::button_tick
);
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;
29 bool newstate
= this->button
.get();
30 if(this->button_state
!= newstate
){
31 this->button_state
= newstate
;
33 if( this->button_state
){
34 if( this->play_state
){
35 this->play_state
= false;
36 THEKERNEL
->pauser
->take();
38 this->play_state
= true;
39 THEKERNEL
->pauser
->release();