Stéphane Cachat
/
Smoothie
smoothie port to mbed online compiler (smoothieware.org)
Embed:
(wiki syntax)
Show/hide line numbers
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 this->register_for_event(ON_PLAY); 00014 this->register_for_event(ON_PAUSE); 00015 00016 this->button = this->kernel->config->value( pause_button_pin_checksum )->by_default("2.12")->as_pin()->as_input(); 00017 this->led = this->kernel->config->value( pause_led_pin_checksum )->by_default("4.28")->as_pin()->as_output(); 00018 00019 this->kernel->slow_ticker->attach( 100, this, &PauseButton::button_tick ); 00020 } 00021 00022 //TODO: Make this use InterruptIn 00023 //Check the state of the button and act accordingly 00024 uint32_t PauseButton::button_tick(uint32_t dummy){ 00025 // If button changed 00026 if(this->button_state != this->button->get()){ 00027 this->button_state = this->button->get(); 00028 // If button pressed 00029 if( this->button_state ){ 00030 if( this->play_state ){ 00031 this->play_state = false; 00032 this->kernel->pauser->take(); 00033 }else{ 00034 this->play_state = true; 00035 this->kernel->pauser->release(); 00036 } 00037 } 00038 } 00039 } 00040 00041 void PauseButton::on_play( void* argument ){ 00042 this->led->set(0); 00043 } 00044 00045 void PauseButton::on_pause( void* argument ){ 00046 this->led->set(1); 00047 } 00048
Generated on Tue Jul 12 2022 14:14:41 by 1.7.2