Skip to content

Commit

Permalink
clean up and complete
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 21, 2023
1 parent ff17f1f commit f9c10c8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
7 changes: 5 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,6 @@
#define COOLER_AUTO_FAN_TEMPERATURE 18
#define COOLER_AUTO_FAN_SPEED 255

#define DEFAULT_EXTRUDER_FLOWRATE 100

/**
* Hotend Cooling Fans tachometers
*
Expand Down Expand Up @@ -2238,6 +2236,11 @@

// @section extruder

/**
* Default flow percentage. Override with 'M221 T<tool> S<flow>'.
*/
#define DEFAULT_FLOW_PERCENT 100

/**
* Linear Pressure Control v1.5
*
Expand Down
17 changes: 8 additions & 9 deletions Marlin/src/gcode/config/M221.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

#if HAS_EXTRUDERS

void GcodeSuite::M221_report(const bool forReplay/*=true*/) {
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

report_heading_etc(forReplay, F(STR_FLOW_RATE));
SERIAL_ECHOLNPGM(" M221 S", planner.flow_percentage[target_extruder]);
}

/**
* M221: Set extrusion percentage (M221 T0 S95)
*/
Expand All @@ -44,13 +52,4 @@ void GcodeSuite::M221() {
}
}

void GcodeSuite::M221_report(const bool forReplay/*=true*/) {
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

report_heading_etc(forReplay, F(STR_FLOW_RATE));
SERIAL_ECHOPGM(" M221 S", planner.flow_percentage[target_extruder]);
SERIAL_EOL();
}

#endif // EXTRUDERS
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class GcodeSuite {

#if HAS_EXTRUDERS
static void M221();
static void M221_report(const bool forReplay=true);
static void M221_report(const bool forReplay=true);
#endif

#if ENABLED(DIRECT_PIN_CONTROL)
Expand Down
66 changes: 44 additions & 22 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ typedef struct SettingsDataStruct {
xyz_pos_t hotend_offset[HOTENDS - 1]; // M218 XYZ
#endif

//
// Flow Percentage
//
#if HAS_EXTRUDERS
uint16_t flow_percentage[EXTRUDERS]; // M221 T S
#endif

//
// FILAMENT_RUNOUT_SENSOR
//
Expand Down Expand Up @@ -881,13 +888,19 @@ void MarlinSettings::postprocess() {
//
// Hotend Offsets, if any
//
{
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; ++e)
EEPROM_WRITE(hotend_offset[e]);
#endif
}
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; ++e)
EEPROM_WRITE(hotend_offset[e]);
#endif

//
// Flow Percentage
//
#if HAS_EXTRUDERS
_FIELD_TEST(flow_percentage);
EEPROM_WRITE(planner.flow_percentage);
#endif

//
// Filament Runout Sensor
Expand Down Expand Up @@ -1899,13 +1912,19 @@ void MarlinSettings::postprocess() {
//
// Hotend Offsets, if any
//
{
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; ++e)
EEPROM_READ(hotend_offset[e]);
#endif
}
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
for (uint8_t e = 1; e < HOTENDS; ++e)
EEPROM_READ(hotend_offset[e]);
#endif

//
// Flow Percentage
//
#if HAS_EXTRUDERS
_FIELD_TEST(flow_percentage);
EEPROM_READ(planner.flow_percentage);
#endif

//
// Filament Runout Sensor
Expand Down Expand Up @@ -3115,6 +3134,16 @@ void MarlinSettings::reset() {

TERN_(HAS_HOTEND_OFFSET, reset_hotend_offsets());

//
// Extruder Flowrate
//
#if HAS_EXTRUDERS
#ifndef DEFAULT_FLOW_PERCENT
#define DEFAULT_FLOW_PERCENT 100
#endif
EXTRUDER_LOOP() planner.flow_percentage[e] = DEFAULT_FLOW_PERCENT;
#endif

//
// Filament Runout Sensor
//
Expand Down Expand Up @@ -3467,13 +3496,6 @@ void MarlinSettings::reset() {
#endif
#endif

//
// M221 Extruder Flowrate
//
#if HAS_EXTRUDERS
planner.flow_percentage[0] = DEFAULT_EXTRUDER_FLOWRATE;
#endif

endstops.enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));

reset_stepper_drivers();
Expand Down Expand Up @@ -3715,7 +3737,7 @@ void MarlinSettings::reset() {
//
// M221 Extruder Flowrate
//
TERN_(HAS_EXTRUDERS, gcode.M221_report(forReplay));
TERN_(HAS_EXTRUDERS, gcode.M221_report(forReplay));

//
// Bed Leveling
Expand Down

0 comments on commit f9c10c8

Please sign in to comment.