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.

M163-M165.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(MIXING_EXTRUDER)
  24. #include "../../gcode.h"
  25. #include "../../../feature/mixing.h"
  26. /**
  27. * M163: Set a single mix factor for a mixing extruder
  28. * This is called "weight" by some systems.
  29. * Must be followed by M164 to normalize and commit them.
  30. *
  31. * S[index] The channel index to set
  32. * P[float] The mix value
  33. */
  34. void GcodeSuite::M163() {
  35. const int mix_index = parser.intval('S');
  36. if (mix_index < MIXING_STEPPERS)
  37. mixer.set_collector(mix_index, parser.floatval('P'));
  38. }
  39. /**
  40. * M164: Normalize and commit the mix.
  41. *
  42. * S[index] The virtual tool to store
  43. * If 'S' is omitted update the active virtual tool.
  44. */
  45. void GcodeSuite::M164() {
  46. #if MIXING_VIRTUAL_TOOLS > 1
  47. const int tool_index = parser.intval('S', -1);
  48. #else
  49. constexpr int tool_index = 0;
  50. #endif
  51. if (tool_index >= 0) {
  52. if (tool_index < MIXING_VIRTUAL_TOOLS)
  53. mixer.normalize(tool_index);
  54. }
  55. else
  56. mixer.normalize();
  57. }
  58. #if ENABLED(DIRECT_MIXING_IN_G1)
  59. /**
  60. * M165: Set multiple mix factors for a mixing extruder.
  61. * Omitted factors will be set to 0.
  62. * The mix is normalized and stored in the current virtual tool.
  63. *
  64. * A[factor] Mix factor for extruder stepper 1
  65. * B[factor] Mix factor for extruder stepper 2
  66. * C[factor] Mix factor for extruder stepper 3
  67. * D[factor] Mix factor for extruder stepper 4
  68. * H[factor] Mix factor for extruder stepper 5
  69. * I[factor] Mix factor for extruder stepper 6
  70. */
  71. void GcodeSuite::M165() {
  72. // Get mixing parameters from the GCode
  73. // The total "must" be 1.0 (but it will be normalized)
  74. // If no mix factors are given, the old mix is preserved
  75. const char mixing_codes[] = { LIST_N(MIXING_STEPPERS, 'A', 'B', 'C', 'D', 'H', 'I') };
  76. uint8_t mix_bits = 0;
  77. MIXER_STEPPER_LOOP(i) {
  78. if (parser.seenval(mixing_codes[i])) {
  79. SBI(mix_bits, i);
  80. mixer.set_collector(i, parser.value_float());
  81. }
  82. }
  83. // If any mixing factors were included, clear the rest
  84. // If none were included, preserve the last mix
  85. if (mix_bits) {
  86. MIXER_STEPPER_LOOP(i)
  87. if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f);
  88. mixer.normalize();
  89. }
  90. }
  91. #endif // DIRECT_MIXING_IN_G1
  92. #endif // MIXING_EXTRUDER