Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Use "enum class"
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 5, 2024
1 parent d0e110d commit 4aff107
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 38 deletions.
14 changes: 7 additions & 7 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@

PGMSTR(M112_KILL_STR, "M112 Shutdown");

MarlinState marlin_state = MF_INITIALIZING;
MarlinState marlin_state = MarlinState::MF_INITIALIZING;

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

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

// Return if setup() isn't completed
if (marlin_state == MF_INITIALIZING) goto IDLE_DONE;
if (marlin_state == MarlinState::MF_INITIALIZING) goto IDLE_DONE;

// TODO: Still causing errors
TERN_(TOOL_SENSOR, (void)check_tool_sensor_stats(active_extruder, true));
Expand Down Expand Up @@ -959,7 +959,7 @@ void stop() {
SERIAL_ERROR_MSG(STR_ERR_STOPPED);
LCD_MESSAGE(MSG_STOPPED);
safe_delay(350); // allow enough time for messages to get out before stopping
marlin_state = MF_STOPPED;
marlin_state = MarlinState::MF_STOPPED;
}
}

Expand Down Expand Up @@ -1646,7 +1646,7 @@ void setup() {
SETUP_RUN(ftMotion.init());
#endif

marlin_state = MF_RUNNING;
marlin_state = MarlinState::MF_RUNNING;

#ifdef STARTUP_TUNE
// Play a short startup tune before continuing.
Expand Down Expand Up @@ -1678,7 +1678,7 @@ void loop() {

#if HAS_MEDIA
if (card.flag.abort_sd_printing) abortSDPrinting();
if (marlin_state == MF_SD_COMPLETE) finishSDPrinting();
if (marlin_state == MarlinState::MF_SD_COMPLETE) finishSDPrinting();
#endif

queue.advance();
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void kill(FSTR_P const lcd_error=nullptr, FSTR_P const lcd_component=nullptr, co
void minkill(const bool steppers_off=false);

// Global State of the firmware
enum MarlinState : uint8_t {
enum class MarlinState : uint8_t {
MF_INITIALIZING = 0,
MF_STOPPED,
MF_KILLED,
Expand All @@ -53,8 +53,8 @@ enum MarlinState : uint8_t {
};

extern MarlinState marlin_state;
inline bool IsRunning() { return marlin_state >= MF_RUNNING; }
inline bool IsStopped() { return marlin_state == MF_STOPPED; }
inline bool IsRunning() { return marlin_state >= MarlinState::MF_RUNNING; }
inline bool IsStopped() { return marlin_state == MarlinState::MF_STOPPED; }

bool printingIsActive();
bool printJobOngoing();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M999.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* existing command buffer.
*/
void GcodeSuite::M999() {
marlin_state = MF_RUNNING;
marlin_state = MarlinState::MF_RUNNING;
ui.reset_alert_level();

if (parser.boolval('S')) return;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/mks_ui/draw_printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void setProBarRate() {
lv_label_set_text(bar1ValueText, public_buf_l);
lv_obj_align(bar1ValueText, bar1, LV_ALIGN_CENTER, 0, 0);

if (marlin_state == MF_SD_COMPLETE) {
if (marlin_state == MarlinState::MF_SD_COMPLETE) {
if (once_flag == 0) {
stop_print_time();

Expand All @@ -309,7 +309,7 @@ void setProBarRate() {
if (gCfgItems.finish_power_off) {
gcode.process_subcommands_now(F("M1001"));
queue.inject(F("M81"));
marlin_state = MF_RUNNING;
marlin_state = MarlinState::MF_RUNNING;
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void GUI_RefreshPage() {
disp_print_time();
disp_fan_Zpos();
}
if (printing_rate_update_flag || marlin_state == MF_SD_COMPLETE) {
if (printing_rate_update_flag || marlin_state == MarlinState::MF_SD_COMPLETE) {
printing_rate_update_flag = false;
if (!gcode_preview_over) setProBarRate();
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ namespace ExtUI {
void onSurviveInKilled() {
thermalManager.disable_all_heaters();
flags.printer_killed = 0;
marlin_state = MF_RUNNING;
marlin_state = MarlinState::MF_RUNNING;
//SERIAL_ECHOLNPGM("survived at: ", millis());
}

Expand Down
20 changes: 10 additions & 10 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void report_current_position_projected() {
AutoReporter<PositionReport> position_auto_reporter;
#endif

#if ANY(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
#if ENABLED(REALTIME_REPORTING_COMMANDS)

M_StateEnum M_State_grbl = M_INIT;

Expand Down Expand Up @@ -299,18 +299,18 @@ void report_current_position_projected() {
*/
M_StateEnum grbl_state_for_marlin_state() {
switch (marlin_state) {
case MF_INITIALIZING: return M_INIT;
case MF_SD_COMPLETE: return M_ALARM;
case MF_WAITING: return M_IDLE;
case MF_STOPPED: return M_END;
case MF_RUNNING: return M_RUNNING;
case MF_PAUSED: return M_HOLD;
case MF_KILLED: return M_ERROR;
default: return M_IDLE;
case MarlinState::MF_INITIALIZING: return M_INIT;
case MarlinState::MF_SD_COMPLETE: return M_ALARM;
case MarlinState::MF_WAITING: return M_IDLE;
case MarlinState::MF_STOPPED: return M_END;
case MarlinState::MF_RUNNING: return M_RUNNING;
case MarlinState::MF_PAUSED: return M_HOLD;
case MarlinState::MF_KILLED: return M_ERROR;
default: return M_IDLE;
}
}

#endif
#endif // REALTIME_REPORTING_COMMANDS

#if IS_KINEMATIC

Expand Down
10 changes: 4 additions & 6 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void report_current_position_projected();
extern AutoReporter<PositionReport> position_auto_reporter;
#endif

#if ANY(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
#if ENABLED(REALTIME_REPORTING_COMMANDS)
#define HAS_GRBL_STATE 1
/**
* Machine states for GRBL or TinyG
Expand Down Expand Up @@ -305,11 +305,9 @@ void report_current_position_projected();
}
#endif

#if ENABLED(REALTIME_REPORTING_COMMANDS)
void quickpause_stepper();
void quickresume_stepper();
#endif
#endif
void quickpause_stepper();
void quickresume_stepper();
#endif // REALTIME_REPORTING_COMMANDS

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

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const_float_t
// Removing code to constrain values produces judder in direction-switching moves because the
// current discrete stepping math diverges from physical motion under constant acceleration
// when acceleration_steps_per_s2 is large compared to initial/final_rate.
NOLESS(initial_rate, long(MINIMAL_STEP_RATE));
NOLESS(final_rate, long(MINIMAL_STEP_RATE));
NOLESS(initial_rate, uint32_t(MINIMAL_STEP_RATE));
NOLESS(final_rate, uint32_t(MINIMAL_STEP_RATE));
NOMORE(initial_rate, block->nominal_rate); // NOTE: The nominal rate may be less than MINIMAL_STEP_RATE!
NOMORE(final_rate, block->nominal_rate);

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {
//

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

static bool no_reentry = false; // Prevent recursion
if (no_reentry) return;
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ void CardReader::mount() {
cdroot();
else {
#if ANY(HAS_SD_DETECT, USB_FLASH_DRIVE_SUPPORT)
if (marlin_state != MF_INITIALIZING) LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL);
if (marlin_state != MarlinState::MF_INITIALIZING) LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL);
#endif
}

Expand Down Expand Up @@ -1412,8 +1412,8 @@ void CardReader::fileHasFinished() {

endFilePrintNow(TERN_(SD_RESORT, true));

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

#if ENABLED(AUTO_REPORT_SD_STATUS)
Expand Down

0 comments on commit 4aff107

Please sign in to comment.