Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / modules / tools / switch / Switch.h
1 /*
2 this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
3 smoothie is free software: you can redistribute it and/or modify it under the terms of the gnu general public license as published by the free software foundation, either version 3 of the license, or (at your option) any later version.
4 smoothie is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. see the gnu general public license for more details.
5 you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef SWITCH_H
9 #define SWITCH_H
10
11 #include "Pin.h"
12 #include "Pwm.h"
13 #include <math.h>
14
15 #include <string>
16 using std::string;
17
18 class Gcode;
19 class StreamOutput;
20
21 namespace mbed {
22 class PwmOut;
23 }
24
25 class Switch : public Module {
26 public:
27 Switch();
28 Switch(uint16_t name);
29
30 void on_module_loaded();
31 void on_main_loop(void *argument);
32 void on_config_reload(void* argument);
33 void on_gcode_received(void* argument);
34 void on_get_public_data(void* argument);
35 void on_set_public_data(void* argument);
36 void on_halt(void *arg);
37
38 uint32_t pinpoll_tick(uint32_t dummy);
39 enum OUTPUT_TYPE {NONE, SIGMADELTA, DIGITAL, HWPWM};
40
41 private:
42 void flip();
43 void send_gcode(string msg, StreamOutput* stream);
44 bool match_input_on_gcode(const Gcode* gcode) const;
45 bool match_input_off_gcode(const Gcode* gcode) const;
46
47 Pin input_pin;
48 float switch_value;
49 OUTPUT_TYPE output_type;
50 union {
51 Pin *digital_pin;
52 Pwm *sigmadelta_pin;
53 mbed::PwmOut *pwm_pin;
54 };
55 string output_on_command;
56 string output_off_command;
57 uint16_t name_checksum;
58 uint16_t input_pin_behavior;
59 uint16_t input_on_command_code;
60 uint16_t input_off_command_code;
61 char input_on_command_letter;
62 char input_off_command_letter;
63 struct {
64 bool switch_changed:1;
65 bool input_pin_state:1;
66 bool switch_state:1;
67 bool ignore_on_halt:1;
68 uint8_t failsafe:1;
69 };
70 };
71
72 #endif // SWITCH_H