|
@@ -0,0 +1,99 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+#include "../../inc/MarlinConfig.h"
|
|
24
|
+
|
|
25
|
+#if ENABLED(SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
|
|
26
|
+
|
|
27
|
+#include "../gcode.h"
|
|
28
|
+#include "../../HAL/shared/Delay.h"
|
|
29
|
+#include "../parser.h"
|
|
30
|
+
|
|
31
|
+/**
|
|
32
|
+ * M672 - Set/reset Duet Smart Effector sensitivity
|
|
33
|
+ *
|
|
34
|
+ * One of these is required:
|
|
35
|
+ * S<sensitivity> - 0-255
|
|
36
|
+ * R - Flag to reset sensitivity to default
|
|
37
|
+ */
|
|
38
|
+
|
|
39
|
+/**
|
|
40
|
+ * The Marlin format for the M672 command is different than shown in the Duet Smart Effector
|
|
41
|
+ * documentation https://duet3d.dozuki.com/Wiki/Smart_effector_and_carriage_adapters_for_delta_printer
|
|
42
|
+ *
|
|
43
|
+ * To set custom sensitivity:
|
|
44
|
+ * Duet: M672 S105:aaa:bbb
|
|
45
|
+ * Marlin: M672 Saaa
|
|
46
|
+ *
|
|
47
|
+ * (where aaa is the desired sensitivity and bbb is 255 - aaa).
|
|
48
|
+ *
|
|
49
|
+ * Revert sensitivity to factory settings:
|
|
50
|
+ * Duet: M672 S105:131:131
|
|
51
|
+ * Marlin: M672 R
|
|
52
|
+ */
|
|
53
|
+
|
|
54
|
+#define M672_PROGBYTE 105 // magic byte to start programming custom sensitivity
|
|
55
|
+#define M672_ERASEBYTE 131 // magic byte to clear custom sensitivity
|
|
56
|
+
|
|
57
|
+//
|
|
58
|
+// Smart Effector byte send protocol:
|
|
59
|
+//
|
|
60
|
+// 0 0 1 0 ... always 0010
|
|
61
|
+// b7 b6 b5 b4 ~b4 ... hi bits, NOT last bit
|
|
62
|
+// b3 b2 b1 b0 ~b0 ... lo bits, NOT last bit
|
|
63
|
+//
|
|
64
|
+void M672_send(uint8_t b) { // bit rate requirement: 1KHz +/- 30%
|
|
65
|
+ for (uint8_t bits = 0; bits < 14; bits++) {
|
|
66
|
+ switch (bits) {
|
|
67
|
+ default: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); b <<= 1; break; } // send bit, shift next into place
|
|
68
|
+ case 7:
|
|
69
|
+ case 12: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); break; } // send bit. no shift
|
|
70
|
+ case 8:
|
|
71
|
+ case 13: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !(b & 0x80)); b <<= 1; break; } // send inverted previous bit
|
|
72
|
+ case 0: case 1: // 00
|
|
73
|
+ case 3: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); break; } // 0010
|
|
74
|
+ case 2: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, HIGH); break; } // 001
|
|
75
|
+ }
|
|
76
|
+ DELAY_US(1000);
|
|
77
|
+ }
|
|
78
|
+}
|
|
79
|
+
|
|
80
|
+void GcodeSuite::M672() {
|
|
81
|
+ if (parser.seen('R')) {
|
|
82
|
+ M672_send(M672_ERASEBYTE);
|
|
83
|
+ M672_send(M672_ERASEBYTE);
|
|
84
|
+ }
|
|
85
|
+ else if (parser.seenval('S')) {
|
|
86
|
+ const int8_t M672_sensitivity = parser.value_byte();
|
|
87
|
+ M672_send(M672_PROGBYTE);
|
|
88
|
+ M672_send(M672_sensitivity);
|
|
89
|
+ M672_send(255 - M672_sensitivity);
|
|
90
|
+ }
|
|
91
|
+ else {
|
|
92
|
+ SERIAL_ECHO_MSG("!'S' or 'R' parameter required.");
|
|
93
|
+ return;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Keep Smart Effector in NORMAL mode
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+#endif // SMART_EFFECTOR && SMART_EFFECTOR_MOD_PIN
|