Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PauseButton.cpp Source File

PauseButton.cpp

00001 #include "libs/Kernel.h"
00002 #include "PauseButton.h"
00003 #include "libs/nuts_bolts.h"
00004 #include "libs/utils.h"
00005 #include <string>
00006 using namespace std;
00007 
00008 PauseButton::PauseButton(){}
00009 
00010 void PauseButton::on_module_loaded(){
00011     this->button_state = true;
00012     this->play_state   = true;
00013 
00014     this->enable     =  THEKERNEL->config->value( pause_button_enable_checksum )->by_default(false)->as_bool();
00015     this->button.from_string( THEKERNEL->config->value( pause_button_pin_checksum )->by_default("2.12")->as_string())->as_input();
00016 
00017     THEKERNEL->slow_ticker->attach( 100, this, &PauseButton::button_tick );
00018 }
00019 
00020 //TODO: Make this use InterruptIn
00021 //Check the state of the button and act accordingly
00022 uint32_t PauseButton::button_tick(uint32_t dummy){
00023     if(!this->enable) return 0;
00024     // If button changed
00025     bool newstate = this->button.get();
00026     if(this->button_state != newstate){
00027         this->button_state = newstate;
00028         // If button pressed
00029         if( this->button_state ){
00030             if( this->play_state ){
00031                 this->play_state = false;
00032                 THEKERNEL->pauser->take();
00033             }else{
00034                 this->play_state = true;
00035                 THEKERNEL->pauser->release();
00036             }
00037         }
00038     }
00039     return 0;
00040 }