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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(LIN_ADVANCE)
  24. #include "../../gcode.h"
  25. #include "../../../module/planner.h"
  26. #if ENABLED(ADVANCE_K_EXTRA)
  27. float other_extruder_advance_K[DISTINCT_E];
  28. uint8_t lin_adv_slot = 0;
  29. #endif
  30. /**
  31. * M900: Get or Set Linear Advance K-factor
  32. * T<tool> Which tool to address
  33. * K<factor> Set current advance K factor (Slot 0).
  34. * L<factor> Set secondary advance K factor (Slot 1). Requires ADVANCE_K_EXTRA.
  35. * S<0/1> Activate slot 0 or 1. Requires ADVANCE_K_EXTRA.
  36. */
  37. void GcodeSuite::M900() {
  38. auto echo_value_oor = [](const char ltr, const bool ten=true) {
  39. SERIAL_CHAR('?', ltr);
  40. SERIAL_ECHOPGM(" value out of range");
  41. if (ten) SERIAL_ECHOPGM(" (0-10)");
  42. SERIAL_ECHOLNPGM(".");
  43. };
  44. #if EXTRUDERS < 2
  45. constexpr uint8_t tool_index = 0;
  46. #else
  47. const uint8_t tool_index = parser.intval('T', active_extruder);
  48. if (tool_index >= EXTRUDERS) {
  49. echo_value_oor('T', false);
  50. return;
  51. }
  52. #endif
  53. float &kref = planner.extruder_advance_K[E_INDEX_N(tool_index)], newK = kref;
  54. const float oldK = newK;
  55. #if ENABLED(ADVANCE_K_EXTRA)
  56. float &lref = other_extruder_advance_K[E_INDEX_N(tool_index)];
  57. const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1)
  58. new_slot = parser.boolval('S', old_slot); // The passed slot (default = current)
  59. // If a new slot is being selected swap the current and
  60. // saved K values. Do here so K/L will apply correctly.
  61. if (new_slot != old_slot) { // Not the same slot?
  62. SET_BIT_TO(lin_adv_slot, tool_index, new_slot); // Update the slot for the tool
  63. newK = lref; // Get new K value from backup
  64. lref = oldK; // Save K to backup
  65. }
  66. // Set the main K value. Apply if the main slot is active.
  67. if (parser.seenval('K')) {
  68. const float K = parser.value_float();
  69. if (!WITHIN(K, 0, 10)) echo_value_oor('K');
  70. else if (new_slot) lref = K; // S1 Knn
  71. else newK = K; // S0 Knn
  72. }
  73. // Set the extra K value. Apply if the extra slot is active.
  74. if (parser.seenval('L')) {
  75. const float L = parser.value_float();
  76. if (!WITHIN(L, 0, 10)) echo_value_oor('L');
  77. else if (!new_slot) lref = L; // S0 Lnn
  78. else newK = L; // S1 Lnn
  79. }
  80. #else
  81. if (parser.seenval('K')) {
  82. const float K = parser.value_float();
  83. if (WITHIN(K, 0, 10))
  84. newK = K;
  85. else
  86. echo_value_oor('K');
  87. }
  88. #endif
  89. if (newK != oldK) {
  90. planner.synchronize();
  91. kref = newK;
  92. }
  93. if (!parser.seen_any()) {
  94. #if ENABLED(ADVANCE_K_EXTRA)
  95. #if DISTINCT_E < 2
  96. SERIAL_ECHOLNPGM("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")");
  97. #else
  98. EXTRUDER_LOOP() {
  99. const bool slot = TEST(lin_adv_slot, e);
  100. SERIAL_ECHOLNPGM("Advance T", e, " S", slot, " K", planner.extruder_advance_K[e],
  101. "(S", !slot, " K", other_extruder_advance_K[e], ")");
  102. SERIAL_EOL();
  103. }
  104. #endif
  105. #else
  106. SERIAL_ECHO_START();
  107. #if DISTINCT_E < 2
  108. SERIAL_ECHOLNPGM("Advance K=", planner.extruder_advance_K[0]);
  109. #else
  110. SERIAL_ECHOPGM("Advance K");
  111. EXTRUDER_LOOP() {
  112. SERIAL_CHAR(' ', '0' + e, ':');
  113. SERIAL_DECIMAL(planner.extruder_advance_K[e]);
  114. }
  115. SERIAL_EOL();
  116. #endif
  117. #endif
  118. }
  119. }
  120. void GcodeSuite::M900_report(const bool forReplay/*=true*/) {
  121. report_heading(forReplay, F(STR_LINEAR_ADVANCE));
  122. #if DISTINCT_E < 2
  123. report_echo_start(forReplay);
  124. SERIAL_ECHOLNPGM(" M900 K", planner.extruder_advance_K[0]);
  125. #else
  126. EXTRUDER_LOOP() {
  127. report_echo_start(forReplay);
  128. SERIAL_ECHOLNPGM(" M900 T", e, " K", planner.extruder_advance_K[e]);
  129. }
  130. #endif
  131. }
  132. #endif // LIN_ADVANCE