Move M163-M165 MIXING_EXTRUDER to cpp
This commit is contained in:
parent
8ca0b2fd68
commit
1a37ebc76d
@ -62,6 +62,10 @@
|
|||||||
#include "feature/digipot/digipot.h"
|
#include "feature/digipot/digipot.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
#include "feature/mixing.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
||||||
#include "module/planner_bezier.h"
|
#include "module/planner_bezier.h"
|
||||||
#endif
|
#endif
|
||||||
@ -186,13 +190,6 @@ millis_t max_inactive_time = 0,
|
|||||||
AdvancedPauseMenuResponse advanced_pause_menu_response;
|
AdvancedPauseMenuResponse advanced_pause_menu_response;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
|
||||||
float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
|
|
||||||
#if MIXING_VIRTUAL_TOOLS > 1
|
|
||||||
float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CHDK
|
#ifdef CHDK
|
||||||
millis_t chdkHigh = 0;
|
millis_t chdkHigh = 0;
|
||||||
bool chdkActive = false;
|
bool chdkActive = false;
|
||||||
@ -302,45 +299,6 @@ void suicide() {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
|
||||||
|
|
||||||
void normalize_mix() {
|
|
||||||
float mix_total = 0.0;
|
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
|
|
||||||
// Scale all values if they don't add up to ~1.0
|
|
||||||
if (!NEAR(mix_total, 1.0)) {
|
|
||||||
SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
|
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLED(DIRECT_MIXING_IN_G1)
|
|
||||||
// Get mixing parameters from the GCode
|
|
||||||
// The total "must" be 1.0 (but it will be normalized)
|
|
||||||
// If no mix factors are given, the old mix is preserved
|
|
||||||
void gcode_get_mix() {
|
|
||||||
const char* mixing_codes = "ABCDHI";
|
|
||||||
byte mix_bits = 0;
|
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) {
|
|
||||||
if (parser.seenval(mixing_codes[i])) {
|
|
||||||
SBI(mix_bits, i);
|
|
||||||
float v = parser.value_float();
|
|
||||||
NOLESS(v, 0.0);
|
|
||||||
mixing_factor[i] = RECIPROCAL(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If any mixing factors were included, clear the rest
|
|
||||||
// If none were included, preserve the last mix
|
|
||||||
if (mix_bits) {
|
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
|
||||||
if (!TEST(mix_bits, i)) mixing_factor[i] = 0.0;
|
|
||||||
normalize_mix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
***************** GCode Handlers *****************
|
***************** GCode Handlers *****************
|
||||||
**************************************************/
|
**************************************************/
|
||||||
@ -362,16 +320,6 @@ void quickstop_stepper() {
|
|||||||
SYNC_PLAN_POSITION_KINEMATIC();
|
SYNC_PLAN_POSITION_KINEMATIC();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
|
||||||
#include "gcode/feature/mixing/M163.h"
|
|
||||||
#if MIXING_VIRTUAL_TOOLS > 1
|
|
||||||
#include "gcode/feature/mixing/M164.h"
|
|
||||||
#endif
|
|
||||||
#if ENABLED(DIRECT_MIXING_IN_G1)
|
|
||||||
#include "gcode/feature/mixing/M165.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "gcode/control/M999.h"
|
#include "gcode/control/M999.h"
|
||||||
|
|
||||||
#include "gcode/control/T.h"
|
#include "gcode/control/T.h"
|
||||||
@ -957,12 +905,7 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
|
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
|
||||||
// Initialize mixing to 100% color 1
|
mixing_tools_init();
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
|
||||||
mixing_factor[i] = (i == 0) ? 1.0 : 0.0;
|
|
||||||
for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS; t++)
|
|
||||||
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
|
||||||
mixing_virtual_tool_mix[t][i] = mixing_factor[i];
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(BLTOUCH)
|
#if ENABLED(BLTOUCH)
|
||||||
|
@ -223,13 +223,6 @@ extern millis_t max_inactive_time, stepper_inactive_time;
|
|||||||
extern int lpq_len;
|
extern int lpq_len;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
|
||||||
extern float mixing_factor[MIXING_STEPPERS];
|
|
||||||
#if MIXING_VIRTUAL_TOOLS > 1
|
|
||||||
extern float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void calculate_volumetric_multipliers();
|
void calculate_volumetric_multipliers();
|
||||||
|
|
||||||
bool pin_is_protected(const int8_t pin);
|
bool pin_is_protected(const int8_t pin);
|
||||||
|
79
Marlin/src/feature/mixing.cpp
Normal file
79
Marlin/src/feature/mixing.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* Based on Sprinter and grbl.
|
||||||
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
|
||||||
|
float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
|
||||||
|
|
||||||
|
#if MIXING_VIRTUAL_TOOLS > 1
|
||||||
|
|
||||||
|
float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
||||||
|
|
||||||
|
void mixing_tools_init() {
|
||||||
|
// Initialize mixing to 100% color 1
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
||||||
|
mixing_factor[i] = (i == 0) ? 1.0 : 0.0;
|
||||||
|
for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS; t++)
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
||||||
|
mixing_virtual_tool_mix[t][i] = mixing_factor[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MIXING_VIRTUAL_TOOLS > 1
|
||||||
|
|
||||||
|
void normalize_mix() {
|
||||||
|
float mix_total = 0.0;
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
|
||||||
|
// Scale all values if they don't add up to ~1.0
|
||||||
|
if (!NEAR(mix_total, 1.0)) {
|
||||||
|
SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ENABLED(DIRECT_MIXING_IN_G1)
|
||||||
|
// Get mixing parameters from the GCode
|
||||||
|
// The total "must" be 1.0 (but it will be normalized)
|
||||||
|
// If no mix factors are given, the old mix is preserved
|
||||||
|
void gcode_get_mix() {
|
||||||
|
const char mixing_codes[] = { 'A', 'B', 'C', 'D', 'H', 'I' };
|
||||||
|
byte mix_bits = 0;
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) {
|
||||||
|
if (parser.seenval(mixing_codes[i])) {
|
||||||
|
SBI(mix_bits, i);
|
||||||
|
float v = parser.value_float();
|
||||||
|
NOLESS(v, 0.0);
|
||||||
|
mixing_factor[i] = RECIPROCAL(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If any mixing factors were included, clear the rest
|
||||||
|
// If none were included, preserve the last mix
|
||||||
|
if (mix_bits) {
|
||||||
|
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
|
||||||
|
if (!TEST(mix_bits, i)) mixing_factor[i] = 0.0;
|
||||||
|
normalize_mix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MIXING_EXTRUDER
|
41
Marlin/src/feature/mixing.h
Normal file
41
Marlin/src/feature/mixing.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* Based on Sprinter and grbl.
|
||||||
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MIXING_H__
|
||||||
|
#define __MIXING_H__
|
||||||
|
|
||||||
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
extern float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
|
||||||
|
|
||||||
|
#if MIXING_VIRTUAL_TOOLS > 1
|
||||||
|
extern float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
|
||||||
|
void mixing_tools_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void normalize_mix();
|
||||||
|
|
||||||
|
#if ENABLED(DIRECT_MIXING_IN_G1)
|
||||||
|
void gcode_get_mix();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __MIXING_H__
|
@ -20,6 +20,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
|
||||||
|
#include "../../gcode.h"
|
||||||
|
#include "../../../feature/mixing.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M163: Set a single mix factor for a mixing extruder
|
* M163: Set a single mix factor for a mixing extruder
|
||||||
* This is called "weight" by some systems.
|
* This is called "weight" by some systems.
|
||||||
@ -28,7 +35,7 @@
|
|||||||
* P[float] The mix value
|
* P[float] The mix value
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void gcode_M163() {
|
void GcodeSuite::M163() {
|
||||||
const int mix_index = parser.intval('S');
|
const int mix_index = parser.intval('S');
|
||||||
if (mix_index < MIXING_STEPPERS) {
|
if (mix_index < MIXING_STEPPERS) {
|
||||||
float mix_value = parser.floatval('P');
|
float mix_value = parser.floatval('P');
|
||||||
@ -36,3 +43,5 @@ void gcode_M163() {
|
|||||||
mixing_factor[mix_index] = RECIPROCAL(mix_value);
|
mixing_factor[mix_index] = RECIPROCAL(mix_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MIXING_EXTRUDER
|
@ -20,13 +20,20 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
|
||||||
|
|
||||||
|
#include "../../gcode.h"
|
||||||
|
#include "../../../feature/mixing.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M164: Store the current mix factors as a virtual tool.
|
* M164: Store the current mix factors as a virtual tool.
|
||||||
*
|
*
|
||||||
* S[index] The virtual tool to store
|
* S[index] The virtual tool to store
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void gcode_M164() {
|
void GcodeSuite::M164() {
|
||||||
const int tool_index = parser.intval('S');
|
const int tool_index = parser.intval('S');
|
||||||
if (tool_index < MIXING_VIRTUAL_TOOLS) {
|
if (tool_index < MIXING_VIRTUAL_TOOLS) {
|
||||||
normalize_mix();
|
normalize_mix();
|
||||||
@ -34,3 +41,5 @@ void gcode_M164() {
|
|||||||
mixing_virtual_tool_mix[tool_index][i] = mixing_factor[i];
|
mixing_virtual_tool_mix[tool_index][i] = mixing_factor[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MIXING_EXTRUDER && MIXING_VIRTUAL_TOOLS > 1
|
@ -20,6 +20,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if ENABLED(DIRECT_MIXING_IN_G1)
|
||||||
|
|
||||||
|
#include "../../gcode.h"
|
||||||
|
#include "../../../feature/mixing.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* M165: Set multiple mix factors for a mixing extruder.
|
* M165: Set multiple mix factors for a mixing extruder.
|
||||||
* Factors that are left out will be set to 0.
|
* Factors that are left out will be set to 0.
|
||||||
@ -33,4 +40,6 @@
|
|||||||
* I[factor] Mix factor for extruder stepper 6
|
* I[factor] Mix factor for extruder stepper 6
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void gcode_M165() { gcode_get_mix(); }
|
void GcodeSuite::M165() { gcode_get_mix(); }
|
||||||
|
|
||||||
|
#endif // DIRECT_MIXING_IN_G1
|
@ -116,9 +116,6 @@ void GcodeSuite::dwell(millis_t time) {
|
|||||||
//
|
//
|
||||||
// Placeholders for non-migrated codes
|
// Placeholders for non-migrated codes
|
||||||
//
|
//
|
||||||
extern void gcode_M163();
|
|
||||||
extern void gcode_M164();
|
|
||||||
extern void gcode_M165();
|
|
||||||
extern void gcode_M999();
|
extern void gcode_M999();
|
||||||
extern void gcode_T(uint8_t tmp_extruder);
|
extern void gcode_T(uint8_t tmp_extruder);
|
||||||
|
|
||||||
@ -462,18 +459,12 @@ void GcodeSuite::process_next_command() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(MIXING_EXTRUDER)
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
case 163: // M163: Set a component weight for mixing extruder
|
case 163: M163(); break; // M163: Set a component weight for mixing extruder
|
||||||
gcode_M163();
|
|
||||||
break;
|
|
||||||
#if MIXING_VIRTUAL_TOOLS > 1
|
#if MIXING_VIRTUAL_TOOLS > 1
|
||||||
case 164: // M164: Save current mix as a virtual extruder
|
case 164: M164(); break; // M164: Save current mix as a virtual extruder
|
||||||
gcode_M164();
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#if ENABLED(DIRECT_MIXING_IN_G1)
|
#if ENABLED(DIRECT_MIXING_IN_G1)
|
||||||
case 165: // M165: Set multiple mix weights
|
case 165: M165(); break; // M165: Set multiple mix weights
|
||||||
gcode_M165();
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -80,6 +80,10 @@
|
|||||||
#include "../feature/baricuda.h"
|
#include "../feature/baricuda.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
#include "../feature/mixing.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
Planner planner;
|
Planner planner;
|
||||||
|
|
||||||
// public:
|
// public:
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
#include "../feature/snmm.h"
|
#include "../feature/snmm.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(MIXING_EXTRUDER)
|
||||||
|
#include "../feature/mixing.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLED(SWITCHING_EXTRUDER)
|
#if ENABLED(SWITCHING_EXTRUDER)
|
||||||
|
|
||||||
#if EXTRUDERS > 3
|
#if EXTRUDERS > 3
|
||||||
|
Loading…
Reference in New Issue
Block a user