Simplify menu items, use enum, adjust settings

This commit is contained in:
Scott Lahteine
2022-03-26 18:54:02 -05:00
parent 489b75ae3c
commit bdfe4ca4d1
7 changed files with 79 additions and 83 deletions
+2 -2
View File
@@ -217,8 +217,8 @@ bool load_filament(const_float_t slow_load_length/*=0*/, const_float_t fast_load
REPEAT_1(NUM_RUNOUT_SENSORS, _CASE_RUNOUT)
#undef _CASE_RUNOUT
}
const uint8_t rm = runout.mode[i - 1];
if (rm != 0 && rm != 7 && extDigitalRead(pin) != runout.out_state(i - 1))
const RunoutMode rm = runout.mode[i - 1];
if (rm != RM_NONE && rm != RM_MOTION_SENSOR && extDigitalRead(pin) != runout.out_state(i - 1))
wait_for_user = false;
}
#else
+1 -1
View File
@@ -34,7 +34,7 @@ FilamentMonitor runout;
bool FilamentMonitorBase::enabled[NUM_RUNOUT_SENSORS], // Initialized by settings.load
FilamentMonitorBase::filament_ran_out; // = false
uint8_t FilamentMonitorBase::mode[NUM_RUNOUT_SENSORS]; // Initialized by settings.load
RunoutMode FilamentMonitorBase::mode[NUM_RUNOUT_SENSORS]; // Initialized by settings.load
#if ENABLED(HOST_ACTION_COMMANDS)
bool FilamentMonitorBase::host_handling; // = false
#endif
+13 -6
View File
@@ -61,12 +61,19 @@ extern FilamentMonitor runout;
/*******************************************************************************************/
enum RunoutMode : uint8_t {
RM_NONE,
RM_OUT_ON_LOW,
RM_OUT_ON_HIGH,
RM_MOTION_SENSOR
};
class FilamentMonitorBase {
public:
static bool enabled[NUM_RUNOUT_SENSORS], filament_ran_out;
static uint8_t mode[NUM_RUNOUT_SENSORS]; // 0:NONE 1:Switch NC 2:Switch NO 7:Motion Sensor
static RunoutMode mode[NUM_RUNOUT_SENSORS];
static uint8_t out_state(const uint8_t e=0) { return mode[e] == 2 ? HIGH : LOW; }
static uint8_t out_state(const uint8_t e=0) { return mode[e] == RM_OUT_ON_HIGH ? HIGH : LOW; }
#if ENABLED(HOST_ACTION_COMMANDS)
static bool host_handling;
@@ -111,7 +118,7 @@ class TFilamentMonitor : public FilamentMonitorBase {
// Give the response a chance to update its counter.
static void run() {
if (enabled[active_extruder] && mode[active_extruder]!=0 && !filament_ran_out && (printingIsActive() || did_pause_print)) {
if (enabled[active_extruder] && mode[active_extruder] != RM_NONE && !filament_ran_out && (printingIsActive() || did_pause_print)) {
cli(); // Prevent RunoutResponseDelayed::block_completed from accumulating here
response.run();
sensor.run();
@@ -251,7 +258,7 @@ class FilamentSensorCore : public FilamentSensorBase {
public:
static void block_completed(const block_t * const b) {
if (runout.mode[active_extruder] != 7) return;
if (runout.mode[active_extruder] != RM_MOTION_SENSOR) return;
// If the sensor wheel has moved since the last call to
// this method reset the runout counter for the extruder.
@@ -263,10 +270,10 @@ class FilamentSensorCore : public FilamentSensorBase {
}
static void run() {
if (runout.mode[active_extruder] == 7) {
if (runout.mode[active_extruder] == RM_MOTION_SENSOR) {
poll_motion_sensor();
}
else if (runout.mode[active_extruder] != 0) {
else if (runout.mode[active_extruder] != RM_NONE) {
LOOP_L_N(s, NUM_RUNOUT_SENSORS) {
const bool out = poll_runout_state(s);
if (!out) filament_present(s);
+11 -13
View File
@@ -39,7 +39,7 @@
* P<index> : Mode 0 = NONE
* 1 = Switch NO (HIGH = filament present)
* 2 = Switch NC (LOW = filament present)
* 7 = Encoder / Motion Sensor
* 3 = Encoder / Motion Sensor
*/
void GcodeSuite::M591() {
if (parser.seen("RSDP" TERN_(HOST_ACTION_COMMANDS, "H"))) {
@@ -48,19 +48,17 @@ void GcodeSuite::M591() {
#endif
const bool seenR = parser.seen_test('R'), seenS = parser.seen('S');
if (seenR || seenS) runout.reset();
#if NUM_RUNOUT_SENSORS > 1
const uint8_t tool = parser.ushortval('E', active_extruder);
#else
constexpr uint8_t tool = 0;
#endif
const uint8_t tool = TERN0(MULTI_FILAMENT_SENSOR, parser.ushortval('E', active_extruder));
if (seenS) runout.enabled[tool] = parser.value_bool();
if (parser.seen('D')) runout.set_runout_distance(parser.value_linear_units(), tool);
if (parser.seen('L')) runout.set_runout_distance(parser.value_linear_units(), tool);
if (parser.seen('D') || parser.seen('L')) runout.set_runout_distance(parser.value_linear_units(), tool);
if (parser.seen('P')) {
const uint8_t tmp_mode = parser.value_int();
if (tmp_mode < 3 || tmp_mode == 7) {
runout.mode[tool] = tmp_mode;
runout.reset();
const RunoutMode tmp_mode = (RunoutMode)parser.value_int();
switch (tmp_mode) {
case RM_NONE ... RM_OUT_ON_HIGH:
case RM_MOTION_SENSOR:
runout.mode[tool] = tmp_mode;
runout.reset();
default: break;
}
}
}
@@ -83,7 +81,7 @@ void GcodeSuite::M591_report(const bool forReplay/*=true*/) {
LOOP_S_L_N(e, 1, NUM_RUNOUT_SENSORS)
SERIAL_ECHOLNPGM(
" M591"
#if NUM_RUNOUT_SENSORS > 1
#if MULTI_FILAMENT_SENSOR
" E", e,
#endif
" S", runout.enabled[e]
+11 -11
View File
@@ -99,23 +99,23 @@ void menu_backlash();
#if HAS_FILAMENT_SENSOR
void set_runout_mode_none(const uint8_t e) { runout.mode[e] = RM_NONE; }
void set_runout_mode_high(const uint8_t e) { runout.mode[e] = RM_OUT_ON_HIGH; }
void set_runout_mode_low(const uint8_t e) { runout.mode[e] = RM_OUT_ON_LOW; }
void set_runout_mode_motion(const uint8_t e) { runout.mode[e] = RM_MOTION_SENSOR; }
#define RUNOUT_EDIT_ITEMS(F) do{ \
EDIT_ITEM_N(bool, F, MSG_RUNOUT_SENSOR, &runout.enabled[F]); \
ACTION_ITEM_N(F, MSG_RUNOUT_MODE_NONE, []{ set_runout_mode_none(F);}); \
ACTION_ITEM_N(F, MSG_RUNOUT_MODE_HIGH, []{ set_runout_mode_high(F);}); \
ACTION_ITEM_N(F, MSG_RUNOUT_MODE_LOW, []{ set_runout_mode_low(F);}); \
ACTION_ITEM_N(F, MSG_RUNOUT_MODE_MOTION, []{ set_runout_mode_motion(F);}); \
EDIT_ITEM(bool, MSG_RUNOUT_SENSOR, &runout.enabled[F]); \
ACTION_ITEM(MSG_RUNOUT_MODE_NONE, []{ set_runout_mode_none(F); }); \
ACTION_ITEM(MSG_RUNOUT_MODE_HIGH, []{ set_runout_mode_high(F); }); \
ACTION_ITEM(MSG_RUNOUT_MODE_LOW, []{ set_runout_mode_low(F); }); \
ACTION_ITEM(MSG_RUNOUT_MODE_MOTION, []{ set_runout_mode_motion(F); }); \
editable.decimal = runout.runout_distance(F); \
EDIT_ITEM_FAST_N(float3, F, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 999, \
EDIT_ITEM_FAST(float3, MSG_RUNOUT_DISTANCE_MM, &editable.decimal, 1, 999, \
[]{ runout.set_runout_distance(editable.decimal, F); }, true \
); \
}while(0)
void set_runout_mode_none(uint8_t e) { runout.mode[e] = 0; }
void set_runout_mode_high(uint8_t e) { runout.mode[e] = 1; }
void set_runout_mode_low(uint8_t e) { runout.mode[e] = 2; }
void set_runout_mode_motion(uint8_t e) { runout.mode[e] = 7; }
void menu_runout_config() {
START_MENU();
BACK_ITEM(MSG_CONFIGURATION);
+7 -7
View File
@@ -583,20 +583,20 @@ void _O2 Endstops::report_states() {
REPEAT_1(NUM_RUNOUT_SENSORS, _CASE_RUNOUT)
#undef _CASE_RUNOUT
}
const uint8_t rm = runout.mode[i - 1],
state = runout.out_state(i - 1);
const RunoutMode rm = runout.mode[i - 1];
const uint8_t outval = runout.out_state(i - 1);
SERIAL_ECHOPGM(STR_FILAMENT);
if (i > 1) SERIAL_CHAR(' ', '0' + i);
SERIAL_ECHOPGM(": ");
if (rm == 0)
SERIAL_ECHOLNPGM("DISABLED");
else if (rm == 7) {
if (rm == RM_NONE)
SERIAL_ECHOLNPGM(STR_OFF);
else if (rm == RM_MOTION_SENSOR) {
SERIAL_ECHOPGM("MOTION : ");
print_es_state(extDigitalRead(pin) == state);
print_es_state(extDigitalRead(pin) == outval);
}
else
SERIAL_ECHOLNPGM_P(extDigitalRead(pin) == state ? PSTR("MISSING") : PSTR("PRESENT"));
SERIAL_ECHOLNPGM_P(extDigitalRead(pin) == outval ? PSTR("OUT") : PSTR("PRESENT"));
}
#endif
+34 -43
View File
@@ -112,9 +112,6 @@
#if HAS_FILAMENT_SENSOR
#include "../feature/runout.h"
#define NRS NUM_RUNOUT_SENSORS
#else
#define NRS 1
#endif
#if ENABLED(EXTRA_LIN_ADVANCE_K)
@@ -235,9 +232,11 @@ typedef struct SettingsDataStruct {
//
// FILAMENT_RUNOUT_SENSOR
//
bool runout_enabled[NRS]; // M591 S
float runout_distance_mm[NRS]; // M591 D
uint8_t runout_mode[NRS]; // M591 P
#if HAS_FILAMENT_SENSOR
bool runout_enabled[NUM_RUNOUT_SENSORS]; // M591 S
float runout_distance_mm[NUM_RUNOUT_SENSORS]; // M591 D
uint8_t runout_mode[NUM_RUNOUT_SENSORS]; // M591 P
#endif
//
// ENABLE_LEVELING_FADE_HEIGHT
@@ -781,29 +780,23 @@ void MarlinSettings::postprocess() {
//
// Hotend Offsets, if any
//
{
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
LOOP_S_L_N(e, 1, HOTENDS)
EEPROM_WRITE(hotend_offset[e]);
#endif
}
#if HAS_HOTEND_OFFSET
// Skip hotend 0 which must be 0
LOOP_S_L_N(e, 1, HOTENDS)
EEPROM_WRITE(hotend_offset[e]);
#endif
//
// Filament Runout Sensor
//
#if HAS_FILAMENT_SENSOR
{
_FIELD_TEST(runout_enabled);
#if HAS_FILAMENT_SENSOR
LOOP_L_N(e, NRS) EEPROM_WRITE(runout.enabled[e]);
LOOP_L_N(e, NRS) EEPROM_WRITE(runout.runout_distance(e));
LOOP_L_N(e, NRS) EEPROM_WRITE(runout.mode[e]);
#else
EEPROM_WRITE((int8_t)-1);
EEPROM_WRITE((float)-0.0f);
EEPROM_WRITE((uint8_t)0);
#endif
LOOP_L_N(e, NUM_RUNOUT_SENSORS) EEPROM_WRITE(runout.enabled[e]);
LOOP_L_N(e, NUM_RUNOUT_SENSORS) EEPROM_WRITE(runout.runout_distance(e));
LOOP_L_N(e, NUM_RUNOUT_SENSORS) EEPROM_WRITE(runout.mode[e]);
}
#endif
//
// Global Leveling
@@ -1707,30 +1700,28 @@ void MarlinSettings::postprocess() {
//
// Filament Runout Sensor
//
#if HAS_FILAMENT_SENSOR
{
_FIELD_TEST(runout_enabled);
int8_t runout_enabled[NRS];
float runout_distance_mm[NRS];
uint8_t runout_mode[NRS];
bool runout_enabled[NUM_RUNOUT_SENSORS];
float runout_distance_mm[NUM_RUNOUT_SENSORS];
RunoutMode runout_mode[NUM_RUNOUT_SENSORS];
LOOP_S_L_N(e, 0, NRS) EEPROM_READ(runout_enabled[e]);
LOOP_S_L_N(e, 0, NRS) EEPROM_READ(runout_distance_mm[e]);
LOOP_S_L_N(e, 0, NRS) EEPROM_READ(runout_mode[e]);
EEPROM_READ(runout_enabled);
EEPROM_READ(runout_distance_mm);
EEPROM_READ(runout_mode);
#if HAS_FILAMENT_SENSOR
if (!validating) {
LOOP_S_L_N(e, 0, NRS) {
if (runout_enabled[e] >= 0) {
runout.enabled[e] = (runout_enabled[e] > 0);
runout.set_runout_distance(runout_distance_mm[e], e);
runout.mode[e] = runout_mode[e];
}
}
runout.reset();
if (!validating) {
LOOP_S_L_N(e, 0, NUM_RUNOUT_SENSORS) {
runout.enabled[e] = runout_enabled[e];
runout.set_runout_distance(runout_distance_mm[e], e);
runout.mode[e] = runout_mode[e];
}
#endif
runout.reset();
}
}
#endif
//
// Global Leveling
@@ -2797,12 +2788,12 @@ void MarlinSettings::reset() {
constexpr bool fred[] = FIL_RUNOUT_ENABLED;
constexpr uint8_t frm[] = FIL_RUNOUT_MODE;
constexpr float frd[] = FIL_RUNOUT_DISTANCE_MM;
static_assert(COUNT(fred) == NRS, "FIL_RUNOUT_ENABLED must have NUM_RUNOUT_SENSORS values.");
static_assert(COUNT(frm) == NRS, "FIL_RUNOUT_MODE must have NUM_RUNOUT_SENSORS values.");
static_assert(COUNT(frd) == NRS, "FIL_RUNOUT_DISTANCE_MM must have NUM_RUNOUT_SENSORS values.");
static_assert(COUNT(fred) == NUM_RUNOUT_SENSORS, "FIL_RUNOUT_ENABLED must have NUM_RUNOUT_SENSORS values.");
static_assert(COUNT(frm) == NUM_RUNOUT_SENSORS, "FIL_RUNOUT_MODE must have NUM_RUNOUT_SENSORS values.");
static_assert(COUNT(frd) == NUM_RUNOUT_SENSORS, "FIL_RUNOUT_DISTANCE_MM must have NUM_RUNOUT_SENSORS values.");
COPY(runout.enabled, fred);
COPY(runout.mode, frm);
LOOP_L_N(e, NRS) runout.set_runout_distance(frd[e], e);
LOOP_L_N(e, NUM_RUNOUT_SENSORS) runout.set_runout_distance(frd[e], e);
runout.reset();
#endif