Allow TABS in config
[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 #include "SlowTicker.h"
13 #include "Config.h"
14 #include "Pauser.h"
15
16 PlayLed::PlayLed(){}
17
18 void PlayLed::on_module_loaded()
19 {
20 register_for_event(ON_CONFIG_RELOAD);
21
22 //register_for_event(ON_PLAY);
23 //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
24 //register_for_event(ON_BLOCK_BEGIN);
25 //register_for_event(ON_BLOCK_END);
26
27 on_config_reload(this);
28
29 THEKERNEL->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
30 }
31
32 void PlayLed::on_config_reload(void* argument)
33 {
34 string ledpin = "4.28!";
35
36 ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
37 ledpin = THEKERNEL->config->value( play_led_pin_checksum )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
38
39 led.from_string(ledpin)->as_output()->set(false);
40 }
41
42 void PlayLed::on_block_begin(void* argument)
43 {
44 //led.set(true);
45 }
46
47 void PlayLed::on_block_end(void* argument)
48 {
49 //led.set(false);
50 }
51
52 void PlayLed::on_play(void* argument)
53 {
54 led.set(false);
55 }
56
57 uint32_t PlayLed::half_second_tick(uint32_t)
58 {
59 if (THEKERNEL->pauser->paused())
60 led.set(!led.get());
61 else led.set(!THEKERNEL->conveyor->queue.is_empty());
62
63 return 0;
64 }