Browse Source

ClosedLoop as singleton

Scott Lahteine 4 years ago
parent
commit
48151d1778

+ 1
- 1
Marlin/src/MarlinCore.cpp View File

1136
   #endif
1136
   #endif
1137
 
1137
 
1138
   #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
1138
   #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
1139
-    SETUP_RUN(init_closedloop());
1139
+    SETUP_RUN(closedloop.init());
1140
   #endif
1140
   #endif
1141
 
1141
 
1142
   #ifdef STARTUP_COMMANDS
1142
   #ifdef STARTUP_COMMANDS

+ 4
- 2
Marlin/src/feature/closedloop.cpp View File

29
 
29
 
30
 #include "closedloop.h"
30
 #include "closedloop.h"
31
 
31
 
32
-void init_closedloop() {
32
+ClosedLoop closedloop;
33
+
34
+void ClosedLoop::init() {
33
   OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, LOW);
35
   OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, LOW);
34
   SET_INPUT_PULLUP(CLOSED_LOOP_MOVE_COMPLETE_PIN);
36
   SET_INPUT_PULLUP(CLOSED_LOOP_MOVE_COMPLETE_PIN);
35
 }
37
 }
36
 
38
 
37
-void set_closedloop(const byte val) {
39
+void ClosedLoop::set(const byte val) {
38
   OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, val);
40
   OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, val);
39
 }
41
 }
40
 
42
 

+ 9
- 2
Marlin/src/feature/closedloop.h View File

21
  */
21
  */
22
 #pragma once
22
 #pragma once
23
 
23
 
24
-void init_closedloop();
25
-void set_closedloop(const byte val);
24
+class ClosedLoop {
25
+public:
26
+  static void init();
27
+  static void set(const byte val);
28
+};
29
+
30
+extern ClosedLoop closedloop;
31
+
32
+#define CLOSED_LOOP_WAITING() (READ(CLOSED_LOOP_ENABLE_PIN) && !READ(CLOSED_LOOP_MOVE_COMPLETE_PIN))

+ 4
- 1
Marlin/src/gcode/calibrate/M12.cpp View File

28
 #include "../../feature/closedloop.h"
28
 #include "../../feature/closedloop.h"
29
 
29
 
30
 void GcodeSuite::M12() {
30
 void GcodeSuite::M12() {
31
+
31
   planner.synchronize();
32
   planner.synchronize();
33
+
32
   if (parser.seenval('S'))
34
   if (parser.seenval('S'))
33
-    set_closedloop(parser.value_int()); // Force a CLC set
35
+    closedloop.set(parser.value_int()); // Force a CLC set
36
+
34
 }
37
 }
35
 
38
 
36
 #endif
39
 #endif

+ 6
- 5
Marlin/src/module/planner.cpp View File

91
   #include "../feature/power.h"
91
   #include "../feature/power.h"
92
 #endif
92
 #endif
93
 
93
 
94
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
95
+  #include "../feature/closedloop.h"
96
+#endif
97
+
94
 #if ENABLED(BACKLASH_COMPENSATION)
98
 #if ENABLED(BACKLASH_COMPENSATION)
95
   #include "../feature/backlash.h"
99
   #include "../feature/backlash.h"
96
 #endif
100
 #endif
1634
  * Block until all buffered steps are executed / cleaned
1638
  * Block until all buffered steps are executed / cleaned
1635
  */
1639
  */
1636
 void Planner::synchronize() {
1640
 void Planner::synchronize() {
1637
-  while (
1638
-    has_blocks_queued() || cleaning_buffer_counter
1639
-    #if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
1640
-      || (READ(CLOSED_LOOP_ENABLE_PIN) && !READ(CLOSED_LOOP_MOVE_COMPLETE_PIN))
1641
-    #endif
1641
+  while (has_blocks_queued() || cleaning_buffer_counter
1642
+      || TERN0(EXTERNAL_CLOSED_LOOP_CONTROLLER, CLOSED_LOOP_WAITING())
1642
   ) idle();
1643
   ) idle();
1643
 }
1644
 }
1644
 
1645
 

+ 5
- 2
buildroot/tests/mega1280-tests View File

20
 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
20
 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \
21
            SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
21
            SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \
22
            MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
22
            MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \
23
-           G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS
24
-exec_test $1 $2 "Spindle, MESH_BED_LEVELING, and LCD"
23
+           G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \
24
+           EXTERNAL_CLOSED_LOOP_CONTROLLER
25
+opt_set CLOSED_LOOP_ENABLE_PIN 44
26
+opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45
27
+exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, and LCD"
25
 
28
 
26
 #
29
 #
27
 # Test DUAL_X_CARRIAGE
30
 # Test DUAL_X_CARRIAGE

Loading…
Cancel
Save