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

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