Merge pull request #1912 from mkbel/use_enum_class_2

Use enum classes to save FLASH, unify naming convention
This commit is contained in:
DRracer 2019-06-13 15:12:08 +02:00 committed by GitHub
commit ec2f194350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 316 additions and 314 deletions

2
Firmware/Marlin.h Normal file → Executable file
View File

@ -392,7 +392,7 @@ extern bool wizard_active; //autoload temporarily disabled during wizard
extern LongTimer safetyTimer;
#define PRINT_PERCENT_DONE_INIT 0xff
#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CUSTOM_MSG_TYPE_TEMCAL) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved)
#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || card.paused || mmu_print_saved)
//! Beware - mcode_in_progress is set as soon as the command gets really processed,
//! which is not the same as posting the M600 command into the command queue
//! There can be a considerable lag between posting M600 and its real processing which might result

View File

@ -3159,7 +3159,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
#endif //IR_SENSOR
lcd_setstatuspgm(_T(WELCOME_MSG));
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
}
//! @brief Rise Z if too low to avoid blob/jam before filament loading
@ -3183,7 +3183,7 @@ void gcode_M701()
else
{
enable_z();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
custom_message_type = CustomMsg::FilamentLoading;
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_start(40);
@ -3213,7 +3213,7 @@ void gcode_M701()
lcd_setstatuspgm(_T(WELCOME_MSG));
disable_z();
loading_flag = false;
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_stop();
@ -4228,7 +4228,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
// setTargetHotend(200, 0);
setTargetBed(70 + (start_temp - 30));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL;
custom_message_type = CustomMsg::TempCal;
custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
@ -4330,7 +4330,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
break;
}
puts_P(_N("PINDA probe calibration start"));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL;
custom_message_type = CustomMsg::TempCal;
custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[X_AXIS] = PINDA_PREHEAT_X;
@ -4398,7 +4398,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
}
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
puts_P(_N("Temperature calibration done."));
@ -4458,7 +4458,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
// We don't know where we are! HOME!
// Push the commands to the front of the message queue in the reverse order!
// There shall be always enough space reserved for these commands.
if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) {
if (lcd_commands_type != LcdCommands::StopPrint) {
repeatcommand_front(); // repeat G80 with all its parameters
enquecommand_front_P((PSTR("G28 W0")));
}
@ -4498,7 +4498,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
if (temp_comp_start)
if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) {
if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) {
if (lcd_commands_type != LcdCommands::StopPrint) {
temp_compensation_start();
run = true;
repeatcommand_front(); // repeat G80 with all its parameters
@ -4510,14 +4510,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
break;
}
run = false;
if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) {
if (lcd_commands_type == LcdCommands::StopPrint) {
mesh_bed_leveling_flag = false;
break;
}
// Save custom message state, set a new custom message state to display: Calibrating point 9.
unsigned int custom_message_type_old = custom_message_type;
CustomMsg custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL;
custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (nMeasPoints * nMeasPoints) + 10;
lcd_update(1);
@ -4717,7 +4717,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
enable_z_endstop(bState);
} while (st_get_position_mm(Z_AXIS) > MESH_HOME_Z_SEARCH); // i.e. Z-leveling not o.k.
// plan_set_z_position(MESH_HOME_Z_SEARCH); // is not necessary ('do-while' loop always ends at the expected Z-position)
custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery
custom_message_type=CustomMsg::Status; // display / status-line recovery
lcd_update_enable(true); // display / status-line recovery
gcode_G28(true, true, true); // X & Y & Z-homing (must be after individual Z-homing (problem with spool-holder)!)
repeatcommand_front(); // re-run (i.e. of "G80")
@ -7729,9 +7729,9 @@ bool bInhibitFlag;
#ifdef IR_SENSOR
bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active
#endif // IR_SENSOR
if ((mcode_in_progress != 600) && (eFilamentAction != e_FILAMENT_ACTION_autoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active
if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active
{
if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL) && !wizard_active)
if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && !wizard_active)
{
if (fsensor_check_autoload())
{
@ -7755,7 +7755,7 @@ if(0)
show_preheat_nozzle_warning();
lcd_update_enable(true);
*/
eFilamentAction=e_FILAMENT_ACTION_autoLoad;
eFilamentAction=FilamentAction::AutoLoad;
bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP)
{
@ -8246,7 +8246,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi
unsigned int custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL;
custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (x_points_num * y_points_num) + 10;
lcd_update(1);
@ -8444,7 +8444,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
}
unsigned int custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL;
custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (x_points_num * y_points_num) + 10;
lcd_update(1);
@ -8594,7 +8594,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
void temp_compensation_start() {
custom_message_type = CUSTOM_MSG_TYPE_TEMPRE;
custom_message_type = CustomMsg::TempCompPreheat;
custom_message_state = PINDA_HEAT_T + 1;
lcd_update(2);
if (degHotend(active_extruder) > EXTRUDE_MINTEMP) {
@ -8615,7 +8615,7 @@ void temp_compensation_start() {
if (custom_message_state == 99 || custom_message_state == 9) lcd_update(2); //force whole display redraw if number of digits changed
else lcd_update(1);
}
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
custom_message_state = 0;
}

2
Firmware/cmdqueue.cpp Normal file → Executable file
View File

@ -598,7 +598,7 @@ void get_command()
if (farm_mode)
{
prusa_statistics(6);
lcd_commands_type = LCD_COMMAND_FARM_MODE_CONFIRM;
lcd_commands_type = LcdCommands::FarmModeConfirm;
}
}

24
Firmware/mmu.cpp Normal file → Executable file
View File

@ -1076,7 +1076,7 @@ if(0)
extr_unload();
}
else {
eFilamentAction=e_FILAMENT_ACTION_mmuUnLoad;
eFilamentAction=FilamentAction::MmuUnLoad;
bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP)
{
@ -1372,13 +1372,13 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
mmu_load_to_nozzle();
load_filament_final_feed();
st_synchronize();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
lcd_return_to_status();
lcd_update_enable(true);
lcd_load_filament_color_check();
lcd_setstatuspgm(_T(WELCOME_MSG));
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
}
else
{
@ -1511,20 +1511,20 @@ void mmu_continue_loading(bool blocking)
enum class Ls : uint_least8_t
{
enter,
retry,
unload,
Enter,
Retry,
Unload,
};
Ls state = Ls::enter;
Ls state = Ls::Enter;
while (PIN_GET(IR_SENSOR_PIN) != 0)
{
switch (state)
{
case Ls::enter:
case Ls::Enter:
increment_load_fail();
// no break
case Ls::retry:
case Ls::Retry:
#ifdef MMU_HAS_CUTTER
if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
{
@ -1535,9 +1535,9 @@ void mmu_continue_loading(bool blocking)
mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE);
load_more();
state = Ls::unload;
state = Ls::Unload;
break;
case Ls::unload:
case Ls::Unload:
stop_and_save_print_to_ram(0, 0);
//lift z
@ -1562,7 +1562,7 @@ void mmu_continue_loading(bool blocking)
{
marlin_wait_for_click();
restore_print_from_ram_and_continue(0);
state = Ls::retry;
state = Ls::Retry;
}
else
{

View File

@ -2053,8 +2053,8 @@ void check_max_temp()
struct alert_automaton_mintemp {
private:
enum { ALERT_AUTOMATON_SPEED_DIV = 5 };
enum class States : uint8_t { INIT = 0, TEMP_ABOVE_MINTEMP, SHOW_PLEASE_RESTART, SHOW_MINTEMP };
States state = States::INIT;
enum class States : uint8_t { Init = 0, TempAboveMintemp, ShowPleaseRestart, ShowMintemp };
States state = States::Init;
uint8_t repeat = ALERT_AUTOMATON_SPEED_DIV;
void substep(States next_state){
@ -2073,26 +2073,26 @@ public:
static const char m2[] PROGMEM = "MINTEMP fixed";
static const char m1[] PROGMEM = "Please restart";
switch(state){
case States::INIT: // initial state - check hysteresis
case States::Init: // initial state - check hysteresis
if( current_temp > mintemp ){
state = States::TEMP_ABOVE_MINTEMP;
state = States::TempAboveMintemp;
}
// otherwise keep the Err MINTEMP alert message on the display,
// i.e. do not transfer to state 1
break;
case States::TEMP_ABOVE_MINTEMP: // the temperature has risen above the hysteresis check
case States::TempAboveMintemp: // the temperature has risen above the hysteresis check
lcd_setalertstatuspgm(m2);
substep(States::SHOW_MINTEMP);
substep(States::ShowMintemp);
last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED;
break;
case States::SHOW_PLEASE_RESTART: // displaying "Please restart"
case States::ShowPleaseRestart: // displaying "Please restart"
lcd_updatestatuspgm(m1);
substep(States::SHOW_MINTEMP);
substep(States::ShowMintemp);
last_alert_sent_to_lcd = LCDALERT_PLEASERESTART;
break;
case States::SHOW_MINTEMP: // displaying "MINTEMP fixed"
case States::ShowMintemp: // displaying "MINTEMP fixed"
lcd_updatestatuspgm(m2);
substep(States::SHOW_PLEASE_RESTART);
substep(States::ShowPleaseRestart);
last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED;
break;
}

File diff suppressed because it is too large Load Diff

View File

@ -89,31 +89,37 @@ extern void lcd_diag_show_end_stops();
// To be used in lcd_commands_type.
#define LCD_COMMAND_IDLE 0
#define LCD_COMMAND_LOAD_FILAMENT 1
#define LCD_COMMAND_STOP_PRINT 2
#define LCD_COMMAND_FARM_MODE_CONFIRM 4
#define LCD_COMMAND_LONG_PAUSE 5
#define LCD_COMMAND_PID_EXTRUDER 7
#define LCD_COMMAND_V2_CAL 8
enum class LcdCommands : uint_least8_t
{
Idle,
LoadFilament,
StopPrint,
FarmModeConfirm,
LongPause,
PidExtruder,
Layer1Cal,
};
extern uint8_t lcd_commands_type;
extern LcdCommands lcd_commands_type;
extern int8_t FSensorStateMenu;
#define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable
#define CUSTOM_MSG_TYPE_MESHBL 1 // Mesh bed leveling in progress
#define CUSTOM_MSG_TYPE_F_LOAD 2 // Loading filament in progress
#define CUSTOM_MSG_TYPE_PIDCAL 3 // PID tuning in progress
#define CUSTOM_MSG_TYPE_TEMCAL 4 // PINDA temp calibration
#define CUSTOM_MSG_TYPE_TEMPRE 5 // Temp compensation preheat
enum class CustomMsg : uint_least8_t
{
Status, //!< status message from lcd_status_message variable
MeshBedLeveling, //!< Mesh bed leveling in progress
FilamentLoading, //!< Loading filament in progress
PidCal, //!< PID tuning in progress
TempCal, //!< PINDA temperature calibration
TempCompPreheat, //!< Temperature compensation preheat
};
extern unsigned int custom_message_type;
extern CustomMsg custom_message_type;
extern unsigned int custom_message_state;
extern uint8_t farm_mode;
extern int farm_no;
extern int farm_timer;
extern int farm_status;
extern uint8_t farm_status;
#ifdef TMC2130
#define SILENT_MODE_NORMAL 0
@ -145,18 +151,19 @@ void extr_unload_used();
#endif //SNMM
void extr_unload();
typedef enum
enum class FilamentAction : uint_least8_t
{
e_FILAMENT_ACTION_none, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state)
e_FILAMENT_ACTION_Load,
e_FILAMENT_ACTION_autoLoad,
e_FILAMENT_ACTION_unLoad,
e_FILAMENT_ACTION_mmuLoad,
e_FILAMENT_ACTION_mmuUnLoad,
e_FILAMENT_ACTION_mmuEject,
e_FILAMENT_ACTION_mmuCut
} eFILAMENT_ACTION;
extern eFILAMENT_ACTION eFilamentAction;
None, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state)
Load,
AutoLoad,
UnLoad,
MmuLoad,
MmuUnLoad,
MmuEject,
MmuCut,
};
extern FilamentAction eFilamentAction;
extern bool bFilamentFirstRun;
extern bool bFilamentPreheatState;
extern bool bFilamentAction;