1 #include "libs/Kernel.h"
2 #include "PauseButton.h"
3 #include "libs/nuts_bolts.h"
4 #include "libs/utils.h"
8 PauseButton::PauseButton(){}
10 void PauseButton::on_module_loaded(){
11 this->button_state
= true;
12 this->play_state
= true;
14 this->enable
= THEKERNEL
->config
->value( pause_button_enable_checksum
)->by_default(false)->as_bool();
15 this->button
.from_string( THEKERNEL
->config
->value( pause_button_pin_checksum
)->by_default("2.12")->as_string())->as_input();
17 THEKERNEL
->slow_ticker
->attach( 100, this, &PauseButton::button_tick
);
20 //TODO: Make this use InterruptIn
21 //Check the state of the button and act accordingly
22 uint32_t PauseButton::button_tick(uint32_t dummy
){
23 if(!this->enable
) return 0;
25 bool newstate
= this->button
.get();
26 if(this->button_state
!= newstate
){
27 this->button_state
= newstate
;
29 if( this->button_state
){
30 if( this->play_state
){
31 this->play_state
= false;
32 THEKERNEL
->pauser
->take();
34 this->play_state
= true;
35 THEKERNEL
->pauser
->release();