smoothie port to mbed online compiler (smoothieware.org)
For documentation, license, ..., please check http://smoothieware.org/
This version has been tested with a 3 axis machine
modules/utils/pausebutton/PauseButton.cpp@0:31e91bb0ef3c, 2012-07-31 (annotated)
- Committer:
- scachat
- Date:
- Tue Jul 31 21:11:18 2012 +0000
- Revision:
- 0:31e91bb0ef3c
smoothie port to mbed online compiler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scachat | 0:31e91bb0ef3c | 1 | #include "libs/Kernel.h" |
scachat | 0:31e91bb0ef3c | 2 | #include "PauseButton.h" |
scachat | 0:31e91bb0ef3c | 3 | #include "libs/nuts_bolts.h" |
scachat | 0:31e91bb0ef3c | 4 | #include "libs/utils.h" |
scachat | 0:31e91bb0ef3c | 5 | #include <string> |
scachat | 0:31e91bb0ef3c | 6 | using namespace std; |
scachat | 0:31e91bb0ef3c | 7 | |
scachat | 0:31e91bb0ef3c | 8 | PauseButton::PauseButton(){} |
scachat | 0:31e91bb0ef3c | 9 | |
scachat | 0:31e91bb0ef3c | 10 | void PauseButton::on_module_loaded(){ |
scachat | 0:31e91bb0ef3c | 11 | this->button_state = true; |
scachat | 0:31e91bb0ef3c | 12 | this->play_state = true; |
scachat | 0:31e91bb0ef3c | 13 | this->register_for_event(ON_PLAY); |
scachat | 0:31e91bb0ef3c | 14 | this->register_for_event(ON_PAUSE); |
scachat | 0:31e91bb0ef3c | 15 | |
scachat | 0:31e91bb0ef3c | 16 | this->button = this->kernel->config->value( pause_button_pin_checksum )->by_default("2.12")->as_pin()->as_input(); |
scachat | 0:31e91bb0ef3c | 17 | this->led = this->kernel->config->value( pause_led_pin_checksum )->by_default("4.28")->as_pin()->as_output(); |
scachat | 0:31e91bb0ef3c | 18 | |
scachat | 0:31e91bb0ef3c | 19 | this->kernel->slow_ticker->attach( 100, this, &PauseButton::button_tick ); |
scachat | 0:31e91bb0ef3c | 20 | } |
scachat | 0:31e91bb0ef3c | 21 | |
scachat | 0:31e91bb0ef3c | 22 | //TODO: Make this use InterruptIn |
scachat | 0:31e91bb0ef3c | 23 | //Check the state of the button and act accordingly |
scachat | 0:31e91bb0ef3c | 24 | uint32_t PauseButton::button_tick(uint32_t dummy){ |
scachat | 0:31e91bb0ef3c | 25 | // If button changed |
scachat | 0:31e91bb0ef3c | 26 | if(this->button_state != this->button->get()){ |
scachat | 0:31e91bb0ef3c | 27 | this->button_state = this->button->get(); |
scachat | 0:31e91bb0ef3c | 28 | // If button pressed |
scachat | 0:31e91bb0ef3c | 29 | if( this->button_state ){ |
scachat | 0:31e91bb0ef3c | 30 | if( this->play_state ){ |
scachat | 0:31e91bb0ef3c | 31 | this->play_state = false; |
scachat | 0:31e91bb0ef3c | 32 | this->kernel->pauser->take(); |
scachat | 0:31e91bb0ef3c | 33 | }else{ |
scachat | 0:31e91bb0ef3c | 34 | this->play_state = true; |
scachat | 0:31e91bb0ef3c | 35 | this->kernel->pauser->release(); |
scachat | 0:31e91bb0ef3c | 36 | } |
scachat | 0:31e91bb0ef3c | 37 | } |
scachat | 0:31e91bb0ef3c | 38 | } |
scachat | 0:31e91bb0ef3c | 39 | } |
scachat | 0:31e91bb0ef3c | 40 | |
scachat | 0:31e91bb0ef3c | 41 | void PauseButton::on_play( void* argument ){ |
scachat | 0:31e91bb0ef3c | 42 | this->led->set(0); |
scachat | 0:31e91bb0ef3c | 43 | } |
scachat | 0:31e91bb0ef3c | 44 | |
scachat | 0:31e91bb0ef3c | 45 | void PauseButton::on_pause( void* argument ){ |
scachat | 0:31e91bb0ef3c | 46 | this->led->set(1); |
scachat | 0:31e91bb0ef3c | 47 | } |
scachat | 0:31e91bb0ef3c | 48 |