4eeded526767bfbf6082257e7f884f3af5f84553
[clinton/Smoothieware.git] / src / modules / utils / PlayLed / PlayLed.cpp
1 #include "PlayLed.h"
2
3 /*
4 * LED indicator:
5 * off = not paused, nothing to do
6 * flash = paused
7 * on = a block is being executed
8 */
9
10 #include "PauseButton.h"
11 #include "modules/robot/Conveyor.h"
12
13 PlayLed::PlayLed(){}
14
15 void PlayLed::on_module_loaded()
16 {
17 register_for_event(ON_CONFIG_RELOAD);
18
19 //register_for_event(ON_PLAY);
20 //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
21 //register_for_event(ON_BLOCK_BEGIN);
22 //register_for_event(ON_BLOCK_END);
23
24 on_config_reload(this);
25
26 THEKERNEL->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
27 }
28
29 void PlayLed::on_config_reload(void* argument)
30 {
31 string ledpin = "4.28!";
32
33 ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
34 ledpin = THEKERNEL->config->value( play_led_pin_checksum )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
35
36 led.from_string(ledpin)->as_output()->set(false);
37 }
38
39 void PlayLed::on_block_begin(void* argument)
40 {
41 //led.set(true);
42 }
43
44 void PlayLed::on_block_end(void* argument)
45 {
46 //led.set(false);
47 }
48
49 void PlayLed::on_play(void* argument)
50 {
51 led.set(false);
52 }
53
54 uint32_t PlayLed::half_second_tick(uint32_t)
55 {
56 if (THEKERNEL->pauser->paused())
57 led.set(!led.get());
58 else led.set(!THEKERNEL->conveyor->queue.is_empty());
59
60 return 0;
61 }