Skip to content

Commit 4aff107

Browse files
committed
πŸ§‘β€πŸ’» Use "enum class"
1 parent d0e110d commit 4aff107

File tree

11 files changed

+36
-38
lines changed

11 files changed

+36
-38
lines changed

β€ŽMarlin/src/MarlinCore.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263

264264
PGMSTR(M112_KILL_STR, "M112 Shutdown");
265265

266-
MarlinState marlin_state = MF_INITIALIZING;
266+
MarlinState marlin_state = MarlinState::MF_INITIALIZING;
267267

268268
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
269269
bool wait_for_heatup = false;
@@ -377,8 +377,8 @@ void startOrResumeJob() {
377377
}
378378

379379
inline void finishSDPrinting() {
380-
if (queue.enqueue_one(F("M1001"))) { // Keep trying until it gets queued
381-
marlin_state = MF_RUNNING; // Signal to stop trying
380+
if (queue.enqueue_one(F("M1001"))) { // Keep trying until it gets queued
381+
marlin_state = MarlinState::MF_RUNNING; // Signal to stop trying
382382
TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine());
383383
TERN_(DGUS_LCD_UI_MKS, screen.sdPrintingFinished());
384384
}
@@ -773,7 +773,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
773773
TERN_(MAX7219_DEBUG, max7219.idle_tasks());
774774

775775
// Return if setup() isn't completed
776-
if (marlin_state == MF_INITIALIZING) goto IDLE_DONE;
776+
if (marlin_state == MarlinState::MF_INITIALIZING) goto IDLE_DONE;
777777

778778
// TODO: Still causing errors
779779
TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(active_extruder, true));
@@ -959,7 +959,7 @@ void stop() {
959959
SERIAL_ERROR_MSG(STR_ERR_STOPPED);
960960
LCD_MESSAGE(MSG_STOPPED);
961961
safe_delay(350); // allow enough time for messages to get out before stopping
962-
marlin_state = MF_STOPPED;
962+
marlin_state = MarlinState::MF_STOPPED;
963963
}
964964
}
965965

@@ -1646,7 +1646,7 @@ void setup() {
16461646
SETUP_RUN(ftMotion.init());
16471647
#endif
16481648

1649-
marlin_state = MF_RUNNING;
1649+
marlin_state = MarlinState::MF_RUNNING;
16501650

16511651
#ifdef STARTUP_TUNE
16521652
// Play a short startup tune before continuing.
@@ -1678,7 +1678,7 @@ void loop() {
16781678

16791679
#if HAS_MEDIA
16801680
if (card.flag.abort_sd_printing) abortSDPrinting();
1681-
if (marlin_state == MF_SD_COMPLETE) finishSDPrinting();
1681+
if (marlin_state == MarlinState::MF_SD_COMPLETE) finishSDPrinting();
16821682
#endif
16831683

16841684
queue.advance();

β€ŽMarlin/src/MarlinCore.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void kill(FSTR_P const lcd_error=nullptr, FSTR_P const lcd_component=nullptr, co
4242
void minkill(const bool steppers_off=false);
4343

4444
// Global State of the firmware
45-
enum MarlinState : uint8_t {
45+
enum class MarlinState : uint8_t {
4646
MF_INITIALIZING = 0,
4747
MF_STOPPED,
4848
MF_KILLED,
@@ -53,8 +53,8 @@ enum MarlinState : uint8_t {
5353
};
5454

5555
extern MarlinState marlin_state;
56-
inline bool IsRunning() { return marlin_state >= MF_RUNNING; }
57-
inline bool IsStopped() { return marlin_state == MF_STOPPED; }
56+
inline bool IsRunning() { return marlin_state >= MarlinState::MF_RUNNING; }
57+
inline bool IsStopped() { return marlin_state == MarlinState::MF_STOPPED; }
5858

5959
bool printingIsActive();
6060
bool printJobOngoing();

β€ŽMarlin/src/gcode/control/M999.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* existing command buffer.
3737
*/
3838
void GcodeSuite::M999() {
39-
marlin_state = MF_RUNNING;
39+
marlin_state = MarlinState::MF_RUNNING;
4040
ui.reset_alert_level();
4141

4242
if (parser.boolval('S')) return;

β€ŽMarlin/src/lcd/extui/mks_ui/draw_printing.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void setProBarRate() {
294294
lv_label_set_text(bar1ValueText, public_buf_l);
295295
lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);
296296

297-
if (marlin_state == MF_SD_COMPLETE) {
297+
if (marlin_state == MarlinState::MF_SD_COMPLETE) {
298298
if (once_flag == 0) {
299299
stop_print_time();
300300

@@ -309,7 +309,7 @@ void setProBarRate() {
309309
if (gCfgItems.finish_power_off) {
310310
gcode.process_subcommands_now(F("M1001"));
311311
queue.inject(F("M81"));
312-
marlin_state = MF_RUNNING;
312+
marlin_state = MarlinState::MF_RUNNING;
313313
}
314314
#endif
315315
}

β€ŽMarlin/src/lcd/extui/mks_ui/draw_ui.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void GUI_RefreshPage() {
766766
disp_print_time();
767767
disp_fan_Zpos();
768768
}
769-
if (printing_rate_update_flag || marlin_state == MF_SD_COMPLETE) {
769+
if (printing_rate_update_flag || marlin_state == MarlinState::MF_SD_COMPLETE) {
770770
printing_rate_update_flag = false;
771771
if (!gcode_preview_over) setProBarRate();
772772
}

β€ŽMarlin/src/lcd/extui/ui_api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ namespace ExtUI {
12191219
void onSurviveInKilled() {
12201220
thermalManager.disable_all_heaters();
12211221
flags.printer_killed = 0;
1222-
marlin_state = MF_RUNNING;
1222+
marlin_state = MarlinState::MF_RUNNING;
12231223
//SERIAL_ECHOLNPGM("survived at: ", millis());
12241224
}
12251225

β€ŽMarlin/src/module/motion.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void report_current_position_projected() {
257257
AutoReporter<PositionReport> position_auto_reporter;
258258
#endif
259259

260-
#if ANY(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
260+
#if ENABLED(REALTIME_REPORTING_COMMANDS)
261261

262262
M_StateEnum M_State_grbl = M_INIT;
263263

@@ -299,18 +299,18 @@ void report_current_position_projected() {
299299
*/
300300
M_StateEnum grbl_state_for_marlin_state() {
301301
switch (marlin_state) {
302-
case MF_INITIALIZING: return M_INIT;
303-
case MF_SD_COMPLETE: return M_ALARM;
304-
case MF_WAITING: return M_IDLE;
305-
case MF_STOPPED: return M_END;
306-
case MF_RUNNING: return M_RUNNING;
307-
case MF_PAUSED: return M_HOLD;
308-
case MF_KILLED: return M_ERROR;
309-
default: return M_IDLE;
302+
case MarlinState::MF_INITIALIZING: return M_INIT;
303+
case MarlinState::MF_SD_COMPLETE: return M_ALARM;
304+
case MarlinState::MF_WAITING: return M_IDLE;
305+
case MarlinState::MF_STOPPED: return M_END;
306+
case MarlinState::MF_RUNNING: return M_RUNNING;
307+
case MarlinState::MF_PAUSED: return M_HOLD;
308+
case MarlinState::MF_KILLED: return M_ERROR;
309+
default: return M_IDLE;
310310
}
311311
}
312312

313-
#endif
313+
#endif // REALTIME_REPORTING_COMMANDS
314314

315315
#if IS_KINEMATIC
316316

β€ŽMarlin/src/module/motion.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void report_current_position_projected();
272272
extern AutoReporter<PositionReport> position_auto_reporter;
273273
#endif
274274

275-
#if ANY(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
275+
#if ENABLED(REALTIME_REPORTING_COMMANDS)
276276
#define HAS_GRBL_STATE 1
277277
/**
278278
* Machine states for GRBL or TinyG
@@ -305,11 +305,9 @@ void report_current_position_projected();
305305
}
306306
#endif
307307

308-
#if ENABLED(REALTIME_REPORTING_COMMANDS)
309-
void quickpause_stepper();
310-
void quickresume_stepper();
311-
#endif
312-
#endif
308+
void quickpause_stepper();
309+
void quickresume_stepper();
310+
#endif // REALTIME_REPORTING_COMMANDS
313311

314312
float get_move_distance(const xyze_pos_t &diff OPTARG(HAS_ROTATIONAL_AXES, bool &is_cartesian_move));
315313

β€ŽMarlin/src/module/planner.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const_float_t
799799
// Removing code to constrain values produces judder in direction-switching moves because the
800800
// current discrete stepping math diverges from physical motion under constant acceleration
801801
// when acceleration_steps_per_s2 is large compared to initial/final_rate.
802-
NOLESS(initial_rate, long(MINIMAL_STEP_RATE));
803-
NOLESS(final_rate, long(MINIMAL_STEP_RATE));
802+
NOLESS(initial_rate, uint32_t(MINIMAL_STEP_RATE));
803+
NOLESS(final_rate, uint32_t(MINIMAL_STEP_RATE));
804804
NOMORE(initial_rate, block->nominal_rate); // NOTE: The nominal rate may be less than MINIMAL_STEP_RATE!
805805
NOMORE(final_rate, block->nominal_rate);
806806

β€ŽMarlin/src/module/temperature.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {
14301430
//
14311431

14321432
inline void loud_kill(FSTR_P const lcd_msg, const heater_id_t heater_id) {
1433-
marlin_state = MF_KILLED;
1433+
marlin_state = MarlinState::MF_KILLED;
14341434
thermalManager.disable_all_heaters();
14351435
#if HAS_BEEPER
14361436
for (uint8_t i = 20; i--;) {
@@ -2077,7 +2077,7 @@ void Temperature::mintemp_error(const heater_id_t heater_id OPTARG(ERR_INCLUDE_T
20772077
* - Update the heated bed PID output value
20782078
*/
20792079
void Temperature::task() {
2080-
if (marlin_state == MF_INITIALIZING) return hal.watchdog_refresh(); // If Marlin isn't started, at least reset the watchdog!
2080+
if (marlin_state == MarlinState::MF_INITIALIZING) return hal.watchdog_refresh(); // If Marlin isn't started, at least reset the watchdog!
20812081

20822082
static bool no_reentry = false; // Prevent recursion
20832083
if (no_reentry) return;

β€ŽMarlin/src/sd/cardreader.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void CardReader::mount() {
497497
cdroot();
498498
else {
499499
#if ANY(HAS_SD_DETECT, USB_FLASH_DRIVE_SUPPORT)
500-
if (marlin_state != MF_INITIALIZING) LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL);
500+
if (marlin_state != MarlinState::MF_INITIALIZING) LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL);
501501
#endif
502502
}
503503

@@ -1412,8 +1412,8 @@ void CardReader::fileHasFinished() {
14121412

14131413
endFilePrintNow(TERN_(SD_RESORT, true));
14141414

1415-
flag.sdprintdone = true; // Stop getting bytes from the SD card
1416-
marlin_state = MF_SD_COMPLETE; // Tell Marlin to enqueue M1001 soon
1415+
flag.sdprintdone = true; // Stop getting bytes from the SD card
1416+
marlin_state = MarlinState::MF_SD_COMPLETE; // Tell Marlin to enqueue M1001 soon
14171417
}
14181418

14191419
#if ENABLED(AUTO_REPORT_SD_STATUS)

0 commit comments

Comments
Β (0)