Simplify menu items, use enum

This commit is contained in:
Scott Lahteine
2022-03-26 18:54:02 -05:00
parent 489b75ae3c
commit 6741f5182d
5 changed files with 31 additions and 24 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_ACTIVE_LOW,
RM_ACTIVE_HIGH,
RM_MOTION_SENSOR = 7
};
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_ACTIVE_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 -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_ACTIVE_HIGH; }
void set_runout_mode_low(const uint8_t e) { runout.mode[e] = RM_ACTIVE_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);
+4 -4
View File
@@ -583,15 +583,15 @@ 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 state = runout.out_state(i - 1);
SERIAL_ECHOPGM(STR_FILAMENT);
if (i > 1) SERIAL_CHAR(' ', '0' + i);
SERIAL_ECHOPGM(": ");
if (rm == 0)
if (rm == RM_NONE)
SERIAL_ECHOLNPGM("DISABLED");
else if (rm == 7) {
else if (rm == RM_MOTION_SENSOR) {
SERIAL_ECHOPGM("MOTION : ");
print_es_state(extDigitalRead(pin) == state);
}