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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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(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 other_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. auto echo_value_oor = [] (const char ltr, const bool ten=true) {
  40. SERIAL_CHAR('?'); SERIAL_CHAR(ltr);
  41. SERIAL_ECHOPGM(" value out of range");
  42. if (ten) SERIAL_ECHOPGM(" (0-10)");
  43. SERIAL_ECHOLNPGM(".");
  44. }
  45. if (!parser.seen_any()) {
  46. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  47. #if EXTRUDERS < 2
  48. SERIAL_ECHOLNPAIR("Advance S", int(new_slot), " K", kref, "(S", int(!new_slot), " K", lref, ")");
  49. #else
  50. LOOP_L_N(i, EXTRUDERS) {
  51. const bool slot = TEST(lin_adv_slot, i);
  52. SERIAL_ECHOLNPAIR("Advance T", int(i), " S", int(slot), " K", planner.extruder_advance_K[i],
  53. "(S", int(!slot), " K", other_extruder_advance_K[i], ")");
  54. SERIAL_EOL();
  55. }
  56. #endif
  57. #else
  58. SERIAL_ECHO_START();
  59. #if EXTRUDERS < 2
  60. SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
  61. #else
  62. SERIAL_ECHOPGM("Advance K");
  63. LOOP_L_N(i, EXTRUDERS) {
  64. SERIAL_CHAR(' ', '0' + i, ':');
  65. SERIAL_ECHO(planner.extruder_advance_K[i]);
  66. }
  67. SERIAL_EOL();
  68. #endif
  69. #endif
  70. return;
  71. }
  72. #if EXTRUDERS < 2
  73. constexpr uint8_t tool_index = 0;
  74. #else
  75. const uint8_t tool_index = parser.intval('T', active_extruder);
  76. if (tool_index >= EXTRUDERS) {
  77. echo_value_oor('T', false);
  78. return;
  79. }
  80. #endif
  81. float &kref = planner.extruder_advance_K[tool_index],
  82. &lref = other_extruder_advance_K[tool_index];
  83. const float oldK = kref, oldOther = lref;
  84. float newK = oldK;
  85. #if ENABLED(EXTRA_LIN_ADVANCE_K)
  86. const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1)
  87. new_slot = parser.boolval('S', old_slot); // The passed slot (default = current)
  88. // If a new slot is being selected swap the current and
  89. // saved K values. Do here so K/L will apply correctly.
  90. if (new_slot != old_slot) { // Not the same slot?
  91. SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool
  92. newK = oldOther; // Get new K value from backup
  93. lref = oldK; // Save K to backup
  94. }
  95. // Set the main K value. Apply if the main slot is active.
  96. if (parser.seenval('K')) {
  97. const float newK = parser.value_float();
  98. if (!WITHIN(newK, 0, 10)) echo_value_oor('K');
  99. else if (new_slot) lref = newK; // S1 Knn
  100. else newK = newK; // S0 Knn
  101. }
  102. // Set the extra K value. Apply if the extra slot is active.
  103. if (parser.seenval('L')) {
  104. const float newL = parser.value_float();
  105. if (!WITHIN(newL, 0, 10)) echo_value_oor('L');
  106. else if (!new_slot) lref = newL; // S0 Lnn
  107. else newK = newL; // S1 Lnn
  108. }
  109. #else
  110. if (parser.seenval('K')) {
  111. const float newK = parser.value_float();
  112. if (WITHIN(newK, 0, 10))
  113. newK = newK;
  114. else
  115. echo_value_oor('K');
  116. }
  117. #endif
  118. if (newK != oldK) {
  119. planner.synchronize();
  120. kref = newK;
  121. }
  122. }
  123. #endif // LIN_ADVANCE