My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

M900.cpp 4.5KB

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