refactor ON_HALT, add THEKERNEL->is_halted() for modules that just need to test it...
[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 * slow flash = paused
7 * fast flash = halted
8 * on = a block is being executed
9 */
10
11 #include "PauseButton.h"
12 #include "modules/robot/Conveyor.h"
13 #include "SlowTicker.h"
14 #include "Config.h"
15 #include "Pauser.h"
16 #include "checksumm.h"
17 #include "ConfigValue.h"
18 #include "Gcode.h"
19
20 #define pause_led_pin_checksum CHECKSUM("pause_led_pin")
21 #define play_led_pin_checksum CHECKSUM("play_led_pin")
22 #define play_led_disable_checksum CHECKSUM("play_led_disable")
23
24 PlayLed::PlayLed() {
25 cnt= 0;
26 }
27
28 void PlayLed::on_module_loaded()
29 {
30 if(THEKERNEL->config->value( play_led_disable_checksum )->by_default(false)->as_bool()) {
31 delete this;
32 return;
33 }
34
35 on_config_reload(this);
36
37 THEKERNEL->slow_ticker->attach(12, this, &PlayLed::led_tick);
38 }
39
40 void PlayLed::on_config_reload(void *argument)
41 {
42 string ledpin = "4.28!";
43
44 ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
45 ledpin = THEKERNEL->config->value( play_led_pin_checksum )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
46
47 led.from_string(ledpin)->as_output()->set(false);
48 }
49
50 uint32_t PlayLed::led_tick(uint32_t)
51 {
52 if(THEKERNEL->is_halted()) {
53 led.set(!led.get());
54 return 0;
55 }
56
57 if(++cnt >= 6) { // 6 ticks ~ 500ms
58 cnt= 0;
59
60 if (THEKERNEL->pauser->paused()) {
61 led.set(!led.get());
62 } else {
63 led.set(!THEKERNEL->conveyor->is_queue_empty());
64 }
65 }
66
67 return 0;
68 }