diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index d25b345c..ab927424 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -152,7 +152,6 @@ #define Z_HOME_RETRACT_MM 2 //#define QUICK_HOME //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially. -#define AXIS_RELATIVE_MODES {0, 0, 0, 0} #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step). Toshiba steppers are 4x slower, but Prusa3D does not use those. //By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step. #define INVERT_X_STEP_PIN 0 diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 7a1b85a2..fb70dfed 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -294,7 +294,7 @@ void setPwmFrequency(uint8_t pin, int val); extern bool fans_check_enabled; extern float homing_feedrate[]; -extern bool axis_relative_modes[]; +extern uint8_t axis_relative_modes; extern float feedrate; extern int feedmultiply; extern int extrudemultiply; // Sets extrude multiply factor (in percent) for all extruders diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 24491c87..e4e40cfb 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -179,9 +179,13 @@ float default_retraction = DEFAULT_RETRACTION; float homing_feedrate[] = HOMING_FEEDRATE; -// Currently only the extruder axis may be switched to a relative mode. -// Other axes are always absolute or relative based on the common relative_mode flag. -bool axis_relative_modes[] = AXIS_RELATIVE_MODES; + +//Although this flag and many others like this could be represented with a struct/bitfield for each axis (more readable and efficient code), the implementation +//would not be standard across all platforms. That being said, the code will continue to use bitmasks for independent axis. +//Moreover, according to C/C++ standard, the ordering of bits is platform/compiler dependent and the compiler is allowed to align the bits arbitrarily, +//thus bit operations like shifting and masking may stop working and will be very hard to fix. +uint8_t axis_relative_modes = 0; + int feedmultiply=100; //100->1 200->2 int extrudemultiply=100; //100->1 200->2 int extruder_multiply[EXTRUDERS] = {100 @@ -5376,21 +5380,19 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G90 - Switch off relative mode G90: Set to Absolute Positioning - All coordinates from now on are absolute relative to the origin of the machine. E axis is also switched to absolute mode. + All coordinates from now on are absolute relative to the origin of the machine. E axis is left intact. */ case 90: { - for(uint8_t i = 0; i != NUM_AXIS; ++i) - axis_relative_modes[i] = false; + axis_relative_modes &= ~(X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK); } break; /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning - All coordinates from now on are relative to the last position. E axis is also switched to relative mode. + All coordinates from now on are relative to the last position. E axis is left intact. */ case 91: { - for(uint8_t i = 0; i != NUM_AXIS; ++i) - axis_relative_modes[i] = true; + axis_relative_modes |= X_AXIS_MASK | Y_AXIS_MASK | Z_AXIS_MASK; } break; @@ -6567,7 +6569,7 @@ Sigma_Exit: Makes the extruder interpret extrusion as absolute positions. */ case 82: - axis_relative_modes[E_AXIS] = false; + axis_relative_modes &= ~E_AXIS_MASK; break; /*! @@ -6575,7 +6577,7 @@ Sigma_Exit: Makes the extruder interpret extrusion values as relative positions. */ case 83: - axis_relative_modes[E_AXIS] = true; + axis_relative_modes |= E_AXIS_MASK; break; /*! @@ -9216,7 +9218,7 @@ void get_coordinates() for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { - bool relative = axis_relative_modes[i]; + bool relative = axis_relative_modes & (1 << i); destination[i] = (float)code_value(); if (i == E_AXIS) { float emult = extruder_multiplier[active_extruder]; @@ -10644,7 +10646,7 @@ void uvlo_() // Store the print E position before we lose track eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); - eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); + eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, (axis_relative_modes & E_AXIS_MASK)?0:1); // Clean the input command queue, inhibit serial processing using saved_printing cmdqueue_reset(); @@ -11233,7 +11235,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) saved_feedmultiply2 = feedmultiply; //save feedmultiply saved_active_extruder = active_extruder; //save active_extruder saved_extruder_temperature = degTargetHotend(active_extruder); - saved_extruder_relative_mode = axis_relative_modes[E_AXIS]; + saved_extruder_relative_mode = axis_relative_modes & E_AXIS_MASK; saved_fanSpeed = fanSpeed; cmdqueue_reset(); //empty cmdqueue card.sdprinting = false; @@ -11315,7 +11317,7 @@ void restore_print_from_ram_and_continue(float e_move) wait_for_heater(_millis(), saved_active_extruder); heating_status = 2; } - axis_relative_modes[E_AXIS] = saved_extruder_relative_mode; + axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK; float e = saved_pos[E_AXIS] - e_move; plan_set_e_position(e); diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 85beeb61..08b775c4 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -796,8 +796,8 @@ void mmu_load_to_nozzle() { st_synchronize(); - bool saved_e_relative_mode = axis_relative_modes[E_AXIS]; - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true; + const bool saved_e_relative_mode = axis_relative_modes & E_AXIS_MASK; + if (!saved_e_relative_mode) axis_relative_modes |= E_AXIS_MASK; if (ir_sensor_detected) { current_position[E_AXIS] += 3.0f; @@ -821,7 +821,7 @@ void mmu_load_to_nozzle() feedrate = 871; plan_buffer_line_curposXYZE(feedrate / 60, active_extruder); st_synchronize(); - if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = false; + if (!saved_e_relative_mode) axis_relative_modes &= ~E_AXIS_MASK; } void mmu_M600_wait_and_beep() { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 632e503e..daf9f017 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7369,10 +7369,7 @@ void lcd_print_stop() planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination. - axis_relative_modes[X_AXIS] = false; - axis_relative_modes[Y_AXIS] = false; - axis_relative_modes[Z_AXIS] = false; - axis_relative_modes[E_AXIS] = true; + axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario. }