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