Commit | Line | Data |
---|---|---|
81b547a1 AW |
1 | #include "mbed.h" |
2 | #include "libs/Kernel.h" | |
3 | #include "PauseButton.h" | |
4 | #include "libs/nuts_bolts.h" | |
5 | #include "libs/utils.h" | |
6 | #include <string> | |
7 | using namespace std; | |
8 | ||
9 | PauseButton::PauseButton(){} | |
10 | ||
11 | void PauseButton::on_module_loaded(){ | |
12 | this->button_state = true; | |
13 | this->play_state = true; | |
14 | this->register_for_event(ON_PLAY); | |
15 | this->register_for_event(ON_PAUSE); | |
16 | ||
17 | this->button = this->kernel->config->value( pause_button_pin_checksum )->by_default("0.0")->as_pin()->as_input(); | |
18 | this->led = this->kernel->config->value( pause_led_pin_checksum )->by_default("0.1")->as_pin()->as_output(); | |
19 | ||
20 | this->kernel->slow_ticker->attach( 100, this, &PauseButton::button_tick ); | |
21 | } | |
22 | ||
23 | //TODO: Make this use InterruptIn | |
24 | //Check the state of the button and act accordingly | |
25 | void PauseButton::button_tick(){ | |
26 | // If button changed | |
27 | if(this->button_state != this->button->get()){ | |
28 | this->button_state = this->button->get(); | |
29 | // If button pressed | |
30 | if( this->button_state ){ | |
31 | if( this->play_state ){ | |
32 | this->play_state = false; | |
33 | this->kernel->pauser->take(); | |
34 | }else{ | |
35 | this->play_state = true; | |
36 | this->kernel->pauser->release(); | |
37 | } | |
38 | } | |
39 | } | |
40 | } | |
41 | ||
42 | void PauseButton::on_play( void* argument ){ | |
43 | this->led->set(0); | |
44 | } | |
45 | ||
46 | void PauseButton::on_pause( void* argument ){ | |
47 | this->led->set(1); | |
48 | } | |
49 |