Commit | Line | Data |
---|---|---|
81b547a1 AW |
1 | #include "libs/Kernel.h" |
2 | #include "PauseButton.h" | |
3 | #include "libs/nuts_bolts.h" | |
4 | #include "libs/utils.h" | |
61134a65 JM |
5 | #include "Config.h" |
6 | #include "SlowTicker.h" | |
7 | #include "Pauser.h" | |
8 | ||
81b547a1 AW |
9 | #include <string> |
10 | using namespace std; | |
11 | ||
b547a424 | 12 | PauseButton::PauseButton(){} |
81b547a1 AW |
13 | |
14 | void PauseButton::on_module_loaded(){ | |
15 | this->button_state = true; | |
16 | this->play_state = true; | |
81b547a1 | 17 | |
314ab8f7 MM |
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(); | |
81b547a1 | 20 | |
314ab8f7 | 21 | THEKERNEL->slow_ticker->attach( 100, this, &PauseButton::button_tick ); |
81b547a1 AW |
22 | } |
23 | ||
7b49793d | 24 | //TODO: Make this use InterruptIn |
81b547a1 | 25 | //Check the state of the button and act accordingly |
8b8b3339 | 26 | uint32_t PauseButton::button_tick(uint32_t dummy){ |
2d9cf0e9 | 27 | if(!this->enable) return 0; |
df27a6a3 | 28 | // If button changed |
62529560 MM |
29 | bool newstate = this->button.get(); |
30 | if(this->button_state != newstate){ | |
31 | this->button_state = newstate; | |
df27a6a3 | 32 | // If button pressed |
81b547a1 AW |
33 | if( this->button_state ){ |
34 | if( this->play_state ){ | |
35 | this->play_state = false; | |
314ab8f7 | 36 | THEKERNEL->pauser->take(); |
81b547a1 AW |
37 | }else{ |
38 | this->play_state = true; | |
314ab8f7 | 39 | THEKERNEL->pauser->release(); |
df27a6a3 MM |
40 | } |
41 | } | |
81b547a1 | 42 | } |
f03d3c1c | 43 | return 0; |
81b547a1 | 44 | } |