remove on_config_reload event
[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 #include "checksumm.h"
16 #include "ConfigValue.h"
17
18
19 #define pause_led_pin_checksum CHECKSUM("pause_led_pin")
20 #define play_led_pin_checksum CHECKSUM("play_led_pin")
21 #define play_led_disable_checksum CHECKSUM("play_led_disable")
22
23 PlayLed::PlayLed() {}
24
25 void PlayLed::on_module_loaded()
26 {
27 if(THEKERNEL->config->value( play_led_disable_checksum )->by_default(false)->as_bool()) {
28 delete this;
29 return;
30 }
31
32 //register_for_event(ON_PLAY);
33 //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
34 //register_for_event(ON_BLOCK_BEGIN);
35 //register_for_event(ON_BLOCK_END);
36
37 on_config_reload(this);
38
39 THEKERNEL->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
40 }
41
42 void PlayLed::on_config_reload(void *argument)
43 {
44 string ledpin = "4.28!";
45
46 ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
47 ledpin = THEKERNEL->config->value( play_led_pin_checksum )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
48
49 led.from_string(ledpin)->as_output()->set(false);
50 }
51
52 void PlayLed::on_block_begin(void *argument)
53 {
54 //led.set(true);
55 }
56
57 void PlayLed::on_block_end(void *argument)
58 {
59 //led.set(false);
60 }
61
62 void PlayLed::on_play(void *argument)
63 {
64 led.set(false);
65 }
66
67 uint32_t PlayLed::half_second_tick(uint32_t)
68 {
69 if (THEKERNEL->pauser->paused())
70 led.set(!led.get());
71 else led.set(!THEKERNEL->conveyor->is_queue_empty());
72
73 return 0;
74 }