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 PlayLed.cpp Source File

PlayLed.cpp

00001 #include "PlayLed.h"
00002 
00003 /*
00004  * LED indicator:
00005  * off   = not paused, nothing to do
00006  * flash = paused
00007  * on    = a block is being executed
00008  */
00009 
00010 #include "PauseButton.h"
00011 #include "modules/robot/Conveyor.h"
00012 
00013 PlayLed::PlayLed(){}
00014 
00015 void PlayLed::on_module_loaded()
00016 {
00017     register_for_event(ON_CONFIG_RELOAD);
00018 
00019     //register_for_event(ON_PLAY);
00020     //TODO: these two events happen in interrupt context and it's extremely important they don't last long. This should be done by checking the size of the queue once a second or something
00021     //register_for_event(ON_BLOCK_BEGIN);
00022     //register_for_event(ON_BLOCK_END);
00023 
00024     on_config_reload(this);
00025 
00026     THEKERNEL->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
00027 }
00028 
00029 void PlayLed::on_config_reload(void* argument)
00030 {
00031     string ledpin = "4.28!";
00032 
00033     ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
00034     ledpin = THEKERNEL->config->value( play_led_pin_checksum  )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
00035 
00036     led.from_string(ledpin)->as_output()->set(false);
00037 }
00038 
00039 void PlayLed::on_block_begin(void* argument)
00040 {
00041     //led.set(true);
00042 }
00043 
00044 void PlayLed::on_block_end(void* argument)
00045 {
00046     //led.set(false);
00047 }
00048 
00049 void PlayLed::on_play(void* argument)
00050 {
00051     led.set(false);
00052 }
00053 
00054 uint32_t PlayLed::half_second_tick(uint32_t)
00055 {
00056     if (THEKERNEL->pauser->paused())
00057         led.set(!led.get());
00058     else led.set(!THEKERNEL->conveyor->queue.is_empty());
00059 
00060     return 0;
00061 }