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.

M900.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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(LIN_ADVANCE)
  24. #include "../../gcode.h"
  25. #include "../../../module/planner.h"
  26. #include "../../../module/stepper.h"
  27. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  28. float saved_extruder_advance_K[EXTRUDERS];
  29. uint8_t lin_adv_slot = 0;
  30. #endif
  31. /**
  32. * M900: Get or Set Linear Advance K-factor
  33. * T<tool> Which tool to address
  34. * K<factor> Set current advance K factor (Slot 0).
  35. * L<factor> Set secondary advance K factor (Slot 1). Requires EXTRA_LIN_ADVANCE_K.
  36. * S<0/1> Activate slot 0 or 1. Requires EXTRA_LIN_ADVANCE_K.
  37. */
  38. void GcodeSuite::M900() {
  39. #if EXTRUDERS < 2
  40. constexpr uint8_t tool_index = 0;
  41. #else
  42. const uint8_t tool_index = parser.intval('T', active_extruder);
  43. if (tool_index >= EXTRUDERS) {
  44. SERIAL_ECHOLNPGM("?T value out of range.");
  45. return;
  46. }
  47. #endif
  48. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  49. bool ext_slot = TEST(lin_adv_slot, tool_index);
  50. if (parser.seenval('S')) {
  51. const bool slot = parser.value_bool();
  52. if (ext_slot != slot) {
  53. ext_slot = slot;
  54. SET_BIT_TO(lin_adv_slot, tool_index, slot);
  55. planner.synchronize();
  56. const float temp = planner.extruder_advance_K[tool_index];
  57. planner.extruder_advance_K[tool_index] = saved_extruder_advance_K[tool_index];
  58. saved_extruder_advance_K[tool_index] = temp;
  59. }
  60. }
  61. if (parser.seenval('K')) {
  62. const float newK = parser.value_float();
  63. if (WITHIN(newK, 0, 10)) {
  64. if (ext_slot)
  65. saved_extruder_advance_K[tool_index] = newK;
  66. else {
  67. planner.synchronize();
  68. planner.extruder_advance_K[tool_index] = newK;
  69. }
  70. }
  71. else
  72. SERIAL_ECHOLNPGM("?K value out of range (0-10).");
  73. }
  74. if (parser.seenval('L')) {
  75. const float newL = parser.value_float();
  76. if (WITHIN(newL, 0, 10)) {
  77. if (!ext_slot)
  78. saved_extruder_advance_K[tool_index] = newL;
  79. else {
  80. planner.synchronize();
  81. planner.extruder_advance_K[tool_index] = newL;
  82. }
  83. }
  84. else
  85. SERIAL_ECHOLNPGM("?L value out of range (0-10).");
  86. }
  87. if (!parser.seen_any()) {
  88. #if EXTRUDERS < 2
  89. SERIAL_ECHOLNPAIR("Advance S", ext_slot, " K", planner.extruder_advance_K[0],
  90. "(Slot ", 1 - ext_slot, " K", saved_extruder_advance_K[0], ")");
  91. #else
  92. LOOP_L_N(i, EXTRUDERS) {
  93. const int slot = (int)TEST(lin_adv_slot, i);
  94. SERIAL_ECHOLNPAIR("Advance T", int(i), " S", slot, " K", planner.extruder_advance_K[i],
  95. "(Slot ", 1 - slot, " K", saved_extruder_advance_K[i], ")");
  96. SERIAL_EOL();
  97. }
  98. #endif
  99. }
  100. #else
  101. if (parser.seenval('K')) {
  102. const float newK = parser.value_float();
  103. if (WITHIN(newK, 0, 10)) {
  104. planner.synchronize();
  105. planner.extruder_advance_K[tool_index] = newK;
  106. }
  107. else
  108. SERIAL_ECHOLNPGM("?K value out of range (0-10).");
  109. }
  110. else {
  111. SERIAL_ECHO_START();
  112. #if EXTRUDERS < 2
  113. SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
  114. #else
  115. SERIAL_ECHOPGM("Advance K");
  116. LOOP_L_N(i, EXTRUDERS) {
  117. SERIAL_CHAR(' '); SERIAL_ECHO(int(i));
  118. SERIAL_CHAR('='); SERIAL_ECHO(planner.extruder_advance_K[i]);
  119. }
  120. SERIAL_EOL();
  121. #endif
  122. }
  123. #endif
  124. }
  125. #endif // LIN_ADVANCE