gnea\grbl-Mega  1.0f
Source Code Documentation ( Internal Workings )
coolant_control.c
Go to the documentation of this file.
1 /*
2  coolant_control.c - coolant control methods
3  Part of Grbl
4 
5  Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
6 
7  Grbl is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Grbl is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Grbl. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "grbl.h"
22 
23 
25 {
26  COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT);
27  COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
28  coolant_stop();
29 }
30 
33 {
34  uint8_t cl_state = COOLANT_STATE_DISABLE;
35  #ifdef INVERT_COOLANT_FLOOD_PIN
36  if (bit_isfalse(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) {
37  #else
38  if (bit_istrue(COOLANT_FLOOD_PORT,(1 << COOLANT_FLOOD_BIT))) {
39  #endif
40  cl_state |= COOLANT_STATE_FLOOD;
41  }
42  #ifdef INVERT_COOLANT_MIST_PIN
43  if (bit_isfalse(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) {
44  #else
45  if (bit_istrue(COOLANT_MIST_PORT,(1 << COOLANT_MIST_BIT))) {
46  #endif
47  cl_state |= COOLANT_STATE_MIST;
48  }
49  return(cl_state);
50 }
51 
53 // an interrupt-level. No report flag set, but only called by routines that don't need it.
55 {
56  #ifdef INVERT_COOLANT_FLOOD_PIN
57  COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
58  #else
59  COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
60  #endif
61  #ifdef INVERT_COOLANT_MIST_PIN
62  COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
63  #else
64  COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
65  #endif
66 }
67 
69 // if enabled. Also sets a flag to report an update to a coolant state.
70 // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code
71 // parser program end, and g-code parser coolant_sync().
72 void coolant_set_state(uint8_t mode)
73 {
74  if (sys.abort) { return; }
75 
76  if (mode == COOLANT_DISABLE) {
77 
78  coolant_stop();
79 
80  } else {
81 
82  if (mode & COOLANT_FLOOD_ENABLE) {
83  #ifdef INVERT_COOLANT_FLOOD_PIN
84  COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
85  #else
86  COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
87  #endif
88  }
89 
90  if (mode & COOLANT_MIST_ENABLE) {
91  #ifdef INVERT_COOLANT_MIST_PIN
92  COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
93  #else
94  COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
95  #endif
96  }
97 
98  }
100 }
101 
103 // if an abort or check-mode is active.
104 void coolant_sync(uint8_t mode)
105 {
106  if (sys.state == STATE_CHECK_MODE) { return; }
108  coolant_set_state(mode);
109 }
void coolant_sync(uint8_t mode)
G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails...
void protocol_buffer_synchronize()
Block until all buffered steps are executed or in a cycle state. Works with feed hold.
Definition: protocol.c:177
#define COOLANT_MIST_ENABLE
NOTE: Uses planner condition bit flag)
Definition: gcode.h:114
uint8_t state
Tracks the current system state of Grbl.
Definition: system.h:112
#define COOLANT_STATE_MIST
uint8_t abort
System abort flag. Forces exit back to main loop for reset.
Definition: system.h:113
void coolant_init()
Initializes coolant control pins.
#define STATE_CHECK_MODE
G-code check mode. Locks out planner and motion only.
Definition: system.h:74
uint8_t coolant_get_state()
Returns current coolant output state. Overrides may alter it from programmed state.
system_t sys
Declare system global variable structure.
Definition: main.c:25
uint8_t report_ovr_counter
Tracks when to add override data to status reports.
Definition: system.h:123
#define bit_isfalse(x, mask)
Definition: nuts_bolts.h:61
#define COOLANT_DISABLE
NOTE: Uses planner condition bit flag)
Definition: gcode.h:111
#define COOLANT_STATE_DISABLE
Must be zero.
#define COOLANT_FLOOD_ENABLE
M8 (.
Definition: gcode.h:112
#define COOLANT_STATE_FLOOD
void coolant_stop()
Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at...
void coolant_set_state(uint8_t mode)
Main program only. Immediately sets flood coolant running state and also mist coolant,.
#define bit_istrue(x, mask)
Definition: nuts_bolts.h:60