My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M672.cpp 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
  24. #include "../gcode.h"
  25. #include "../../HAL/shared/Delay.h"
  26. #include "../parser.h"
  27. /**
  28. * The Marlin format for the M672 command is different than shown in the Duet Smart Effector
  29. * documentation https://duet3d.dozuki.com/Wiki/Smart_effector_and_carriage_adapters_for_delta_printer
  30. *
  31. * To set custom sensitivity:
  32. * Duet: M672 S105:aaa:bbb
  33. * Marlin: M672 Saaa
  34. *
  35. * (where aaa is the desired sensitivity and bbb is 255 - aaa).
  36. *
  37. * Revert sensitivity to factory settings:
  38. * Duet: M672 S105:131:131
  39. * Marlin: M672 R
  40. */
  41. #define M672_PROGBYTE 105 // magic byte to start programming custom sensitivity
  42. #define M672_ERASEBYTE 131 // magic byte to clear custom sensitivity
  43. //
  44. // Smart Effector byte send protocol:
  45. //
  46. // 0 0 1 0 ... always 0010
  47. // b7 b6 b5 b4 ~b4 ... hi bits, NOT last bit
  48. // b3 b2 b1 b0 ~b0 ... lo bits, NOT last bit
  49. //
  50. void M672_send(uint8_t b) { // bit rate requirement: 1KHz +/- 30%
  51. LOOP_L_N(bits, 14) {
  52. switch (bits) {
  53. default: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); b <<= 1; break; } // send bit, shift next into place
  54. case 7:
  55. case 12: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !!(b & 0x80)); break; } // send bit. no shift
  56. case 8:
  57. case 13: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, !(b & 0x80)); b <<= 1; break; } // send inverted previous bit
  58. case 0: case 1: // 00
  59. case 3: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); break; } // 0010
  60. case 2: { OUT_WRITE(SMART_EFFECTOR_MOD_PIN, HIGH); break; } // 001
  61. }
  62. DELAY_US(1000);
  63. }
  64. }
  65. /**
  66. * M672 - Set/reset Duet Smart Effector sensitivity
  67. *
  68. * One of these is required:
  69. * S<sensitivity> - 0-255
  70. * R - Flag to reset sensitivity to default
  71. */
  72. void GcodeSuite::M672() {
  73. if (parser.seen('R')) {
  74. M672_send(M672_ERASEBYTE);
  75. M672_send(M672_ERASEBYTE);
  76. }
  77. else if (parser.seenval('S')) {
  78. const int8_t M672_sensitivity = parser.value_byte();
  79. M672_send(M672_PROGBYTE);
  80. M672_send(M672_sensitivity);
  81. M672_send(255 - M672_sensitivity);
  82. }
  83. else {
  84. SERIAL_ECHO_MSG("!'S' or 'R' parameter required.");
  85. return;
  86. }
  87. OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Keep Smart Effector in NORMAL mode
  88. }
  89. #endif // DUET_SMART_EFFECTOR && SMART_EFFECTOR_MOD_PIN