Browse Source

Merge pull request #7 from gudnimg/gudni-PR2

Save some memory by using memset and inlined memcpy
Alex Voinea 2 years ago
parent
commit
d69b8daa72

+ 13 - 7
Firmware/Marlin.h

@@ -275,6 +275,17 @@ FORCE_INLINE unsigned long millis_nc() {
 void setPwmFrequency(uint8_t pin, int val);
 void setPwmFrequency(uint8_t pin, int val);
 #endif
 #endif
 
 
+enum class HeatingStatus : uint8_t
+{
+    NO_HEATING = 0,
+    EXTRUDER_HEATING = 1,
+    EXTRUDER_HEATING_COMPLETE = 2,
+    BED_HEATING = 3,
+    BED_HEATING_COMPLETE = 4,
+};
+
+extern HeatingStatus heating_status;
+
 extern bool fans_check_enabled;
 extern bool fans_check_enabled;
 extern float homing_feedrate[];
 extern float homing_feedrate[];
 extern uint8_t axis_relative_modes;
 extern uint8_t axis_relative_modes;
@@ -319,18 +330,13 @@ extern int bowden_length[4];
 extern bool is_usb_printing;
 extern bool is_usb_printing;
 extern bool homing_flag;
 extern bool homing_flag;
 extern bool loading_flag;
 extern bool loading_flag;
-extern unsigned int usb_printing_counter;
-
-extern unsigned long kicktime;
-
+extern uint8_t usb_printing_counter;
 extern unsigned long total_filament_used;
 extern unsigned long total_filament_used;
 void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time);
 void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time);
-extern unsigned int heating_status;
 extern unsigned int status_number;
 extern unsigned int status_number;
-extern unsigned int heating_status_counter;
+extern uint8_t heating_status_counter;
 extern char snmm_filaments_used;
 extern char snmm_filaments_used;
 extern unsigned long PingTime;
 extern unsigned long PingTime;
-extern unsigned long NcTime;
 extern bool no_response;
 extern bool no_response;
 extern uint8_t important_status;
 extern uint8_t important_status;
 extern uint8_t saved_filament_type;
 extern uint8_t saved_filament_type;

+ 42 - 62
Firmware/Marlin_main.cpp

@@ -161,7 +161,6 @@ CardReader card;
 #endif
 #endif
 
 
 unsigned long PingTime = _millis();
 unsigned long PingTime = _millis();
-unsigned long NcTime;
 
 
 uint8_t mbl_z_probe_nr = 3; //numer of Z measurements for each point in mesh bed leveling calibration
 uint8_t mbl_z_probe_nr = 3; //numer of Z measurements for each point in mesh bed leveling calibration
 
 
@@ -196,9 +195,7 @@ int bowden_length[4] = {385, 385, 385, 385};
 bool is_usb_printing = false;
 bool is_usb_printing = false;
 bool homing_flag = false;
 bool homing_flag = false;
 
 
-unsigned long kicktime = _millis()+100000;
-
-unsigned int  usb_printing_counter;
+uint8_t usb_printing_counter;
 
 
 int8_t lcd_change_fil_state = 0;
 int8_t lcd_change_fil_state = 0;
 
 
@@ -206,7 +203,7 @@ unsigned long pause_time = 0;
 unsigned long start_pause_print = _millis();
 unsigned long start_pause_print = _millis();
 unsigned long t_fan_rising_edge = _millis();
 unsigned long t_fan_rising_edge = _millis();
 LongTimer safetyTimer;
 LongTimer safetyTimer;
-static LongTimer crashDetTimer;
+static ShortTimer crashDetTimer;
 
 
 //unsigned long load_filament_time;
 //unsigned long load_filament_time;
 
 
@@ -220,8 +217,8 @@ bool prusa_sd_card_upload = false;
 unsigned int status_number = 0;
 unsigned int status_number = 0;
 
 
 unsigned long total_filament_used;
 unsigned long total_filament_used;
-unsigned int heating_status;
-unsigned int heating_status_counter;
+HeatingStatus heating_status;
+uint8_t heating_status_counter;
 bool loading_flag = false;
 bool loading_flag = false;
 
 
 #define XY_NO_RESTORE_FLAG (mesh_bed_leveling_flag || homing_flag)
 #define XY_NO_RESTORE_FLAG (mesh_bed_leveling_flag || homing_flag)
@@ -357,14 +354,14 @@ const int8_t sensitive_pins[] PROGMEM = SENSITIVE_PINS; // Sensitive pin list fo
 //static float bt = 0;
 //static float bt = 0;
 
 
 //Inactivity shutdown variables
 //Inactivity shutdown variables
-static unsigned long previous_millis_cmd = 0;
+static LongTimer previous_millis_cmd;
 unsigned long max_inactive_time = 0;
 unsigned long max_inactive_time = 0;
 static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l;
 static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l;
 static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*60*1000ul;
 static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*60*1000ul;
 
 
 unsigned long starttime=0;
 unsigned long starttime=0;
 unsigned long stoptime=0;
 unsigned long stoptime=0;
-unsigned long _usb_timer = 0;
+ShortTimer _usb_timer;
 
 
 bool Stopped=false;
 bool Stopped=false;
 
 
@@ -1894,11 +1891,11 @@ void loop()
 {
 {
 	KEEPALIVE_STATE(NOT_BUSY);
 	KEEPALIVE_STATE(NOT_BUSY);
 
 
-	if ((usb_printing_counter > 0) && ((_millis()-_usb_timer) > 1000))
+	if ((usb_printing_counter > 0) && _usb_timer.expired(1000))
 	{
 	{
 		is_usb_printing = true;
 		is_usb_printing = true;
 		usb_printing_counter--;
 		usb_printing_counter--;
-		_usb_timer = _millis();
+		_usb_timer.start(); // reset timer
 	}
 	}
 	if (usb_printing_counter == 0)
 	if (usb_printing_counter == 0)
 	{
 	{
@@ -2060,7 +2057,7 @@ static int setup_for_endstop_move(bool enable_endstops_now = true) {
     saved_feedrate = feedrate;
     saved_feedrate = feedrate;
     int l_feedmultiply = feedmultiply;
     int l_feedmultiply = feedmultiply;
     feedmultiply = 100;
     feedmultiply = 100;
-    previous_millis_cmd = _millis();
+    previous_millis_cmd.start();
     
     
     enable_endstops(enable_endstops_now);
     enable_endstops(enable_endstops_now);
     return l_feedmultiply;
     return l_feedmultiply;
@@ -2074,7 +2071,7 @@ static void clean_up_after_endstop_move(int original_feedmultiply) {
     
     
     feedrate = saved_feedrate;
     feedrate = saved_feedrate;
     feedmultiply = original_feedmultiply;
     feedmultiply = original_feedmultiply;
-    previous_millis_cmd = _millis();
+    previous_millis_cmd.start();
 }
 }
 
 
 
 
@@ -2518,7 +2515,7 @@ void home_xy()
 
 
 void refresh_cmd_timeout(void)
 void refresh_cmd_timeout(void)
 {
 {
-  previous_millis_cmd = _millis();
+  previous_millis_cmd.start();
 }
 }
 
 
 #ifdef FWRETRACT
 #ifdef FWRETRACT
@@ -2820,14 +2817,9 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon
       if (home_z)
       if (home_z)
         babystep_undo();
         babystep_undo();
 
 
-      saved_feedrate = feedrate;
-      int l_feedmultiply = feedmultiply;
-      feedmultiply = 100;
-      previous_millis_cmd = _millis();
-
-      enable_endstops(true);
+      int l_feedmultiply = setup_for_endstop_move();
 
 
-      memcpy(destination, current_position, sizeof(destination));
+      set_destination_to_current();
       feedrate = 0.0;
       feedrate = 0.0;
 
 
       #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
       #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
@@ -3000,13 +2992,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon
       // contains the machine coordinates.
       // contains the machine coordinates.
       plan_set_position_curposXYZE();
       plan_set_position_curposXYZE();
 
 
-      #ifdef ENDSTOPS_ONLY_FOR_HOMING
-        enable_endstops(false);
-      #endif
-
-      feedrate = saved_feedrate;
-      feedmultiply = l_feedmultiply;
-      previous_millis_cmd = _millis();
+      clean_up_after_endstop_move(l_feedmultiply);
       endstops_hit_on_purpose();
       endstops_hit_on_purpose();
 #ifndef MESH_BED_LEVELING
 #ifndef MESH_BED_LEVELING
 //-// Oct 2019 :: this part of code is (from) now probably un-compilable
 //-// Oct 2019 :: this part of code is (from) now probably un-compilable
@@ -3121,7 +3107,7 @@ static void gcode_G80()
 #endif //PINDA_THERMISTOR
 #endif //PINDA_THERMISTOR
     // Save custom message state, set a new custom message state to display: Calibrating point 9.
     // Save custom message state, set a new custom message state to display: Calibrating point 9.
     CustomMsg custom_message_type_old = custom_message_type;
     CustomMsg custom_message_type_old = custom_message_type;
-    unsigned int custom_message_state_old = custom_message_state;
+    uint8_t custom_message_state_old = custom_message_state;
     custom_message_type = CustomMsg::MeshBedLeveling;
     custom_message_type = CustomMsg::MeshBedLeveling;
     custom_message_state = (nMeasPoints * nMeasPoints) + 10;
     custom_message_state = (nMeasPoints * nMeasPoints) + 10;
     lcd_update(1);
     lcd_update(1);
@@ -3850,7 +3836,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
     plan_set_e_position(lastpos[E_AXIS]);
     plan_set_e_position(lastpos[E_AXIS]);
 
 
     memcpy(current_position, lastpos, sizeof(lastpos));
     memcpy(current_position, lastpos, sizeof(lastpos));
-    memcpy(destination, current_position, sizeof(current_position));
+    set_destination_to_current();
 
 
     //Recover feed rate
     //Recover feed rate
     feedmultiply = feedmultiplyBckp;
     feedmultiply = feedmultiplyBckp;
@@ -4359,7 +4345,7 @@ void process_commands()
         }
         }
         lcd_ignore_click();				//call lcd_ignore_click also for else ???
         lcd_ignore_click();				//call lcd_ignore_click also for else ???
         st_synchronize();
         st_synchronize();
-        previous_millis_cmd = _millis();
+        previous_millis_cmd.start();
         if (codenum > 0 ) {
         if (codenum > 0 ) {
             codenum += _millis();  // keep track of when we started waiting
             codenum += _millis();  // keep track of when we started waiting
             KEEPALIVE_STATE(PAUSED_FOR_USER);
             KEEPALIVE_STATE(PAUSED_FOR_USER);
@@ -4493,7 +4479,7 @@ void process_commands()
     
     
     Set of internal PRUSA commands
     Set of internal PRUSA commands
     #### Usage
     #### Usage
-         PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ]
+         PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | FR ]
     
     
     #### Parameters
     #### Parameters
       - `Ping` 
       - `Ping` 
@@ -4511,7 +4497,6 @@ void process_commands()
       - `Rev`- Prints filament size, elelectronics, nozzle type
       - `Rev`- Prints filament size, elelectronics, nozzle type
       - `Lang` - Reset the language
       - `Lang` - Reset the language
       - `Lz` 
       - `Lz` 
-      - `Beat` - Kick farm link timer
       - `FR` - Full factory reset
       - `FR` - Full factory reset
       - `nozzle set <diameter>` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4`
       - `nozzle set <diameter>` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4`
       - `nozzle D<diameter>` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4`
       - `nozzle D<diameter>` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4`
@@ -4601,10 +4586,6 @@ void process_commands()
 	} else if(code_seen_P(PSTR("Lz"))) { // PRUSA Lz
 	} else if(code_seen_P(PSTR("Lz"))) { // PRUSA Lz
       eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)),0);
       eeprom_update_word(reinterpret_cast<uint16_t *>(&(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)),0);
 
 
-	} else if(code_seen_P(PSTR("Beat"))) { // PRUSA Beat
-        // Kick farm link timer
-        kicktime = _millis();
-
     } else if(code_seen_P(PSTR("FR"))) { // PRUSA FR
     } else if(code_seen_P(PSTR("FR"))) { // PRUSA FR
         // Factory full reset
         // Factory full reset
         factory_reset(0);
         factory_reset(0);
@@ -4987,7 +4968,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
 	  if(codenum != 0) LCD_MESSAGERPGM(_n("Sleep..."));////MSG_DWELL
 	  if(codenum != 0) LCD_MESSAGERPGM(_n("Sleep..."));////MSG_DWELL
       st_synchronize();
       st_synchronize();
       codenum += _millis();  // keep track of when we started waiting
       codenum += _millis();  // keep track of when we started waiting
-      previous_millis_cmd = _millis();
+      previous_millis_cmd.start();
       while(_millis() < codenum) {
       while(_millis() < codenum) {
         manage_heater();
         manage_heater();
         manage_inactivity();
         manage_inactivity();
@@ -5644,8 +5625,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
                 SERIAL_PROTOCOLPGM("\nZ search height: ");
                 SERIAL_PROTOCOLPGM("\nZ search height: ");
                 SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH);
                 SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH);
                 SERIAL_PROTOCOLLNPGM("\nMeasured points:");
                 SERIAL_PROTOCOLLNPGM("\nMeasured points:");
-                for (int y = MESH_NUM_Y_POINTS-1; y >= 0; y--) {
-                    for (int x = 0; x < MESH_NUM_X_POINTS; x++) {
+                for (uint8_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) {
+                    for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) {
                         SERIAL_PROTOCOLPGM("  ");
                         SERIAL_PROTOCOLPGM("  ");
                         SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
                         SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5);
                     }
                     }
@@ -6684,7 +6665,7 @@ Sigma_Exit:
         break;
         break;
       }
       }
       LCD_MESSAGERPGM(_T(MSG_HEATING));
       LCD_MESSAGERPGM(_T(MSG_HEATING));
-	  heating_status = 1;
+	  heating_status = HeatingStatus::EXTRUDER_HEATING;
 	  if (farm_mode) { prusa_statistics(1); };
 	  if (farm_mode) { prusa_statistics(1); };
 
 
 #ifdef AUTOTEMP
 #ifdef AUTOTEMP
@@ -6718,11 +6699,11 @@ Sigma_Exit:
 
 
         LCD_MESSAGERPGM(_T(MSG_HEATING_COMPLETE));
         LCD_MESSAGERPGM(_T(MSG_HEATING_COMPLETE));
 		KEEPALIVE_STATE(IN_HANDLER);
 		KEEPALIVE_STATE(IN_HANDLER);
-		heating_status = 2;
+		heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE;
 		if (farm_mode) { prusa_statistics(2); };
 		if (farm_mode) { prusa_statistics(2); };
         
         
         //starttime=_millis();
         //starttime=_millis();
-        previous_millis_cmd = _millis();
+        previous_millis_cmd.start();
       }
       }
       break;
       break;
 
 
@@ -6744,7 +6725,7 @@ Sigma_Exit:
     {
     {
         bool CooldownNoWait = false;
         bool CooldownNoWait = false;
         LCD_MESSAGERPGM(_T(MSG_BED_HEATING));
         LCD_MESSAGERPGM(_T(MSG_BED_HEATING));
-		heating_status = 3;
+		heating_status = HeatingStatus::BED_HEATING;
 		if (farm_mode) { prusa_statistics(1); };
 		if (farm_mode) { prusa_statistics(1); };
         if (code_seen('S')) 
         if (code_seen('S')) 
 		{
 		{
@@ -6784,9 +6765,9 @@ Sigma_Exit:
         }
         }
         LCD_MESSAGERPGM(_T(MSG_BED_DONE));
         LCD_MESSAGERPGM(_T(MSG_BED_DONE));
 		KEEPALIVE_STATE(IN_HANDLER);
 		KEEPALIVE_STATE(IN_HANDLER);
-		heating_status = 4;
+		heating_status = HeatingStatus::BED_HEATING_COMPLETE;
 
 
-        previous_millis_cmd = _millis();
+        previous_millis_cmd.start();
     }
     }
     #endif
     #endif
         break;
         break;
@@ -9115,7 +9096,7 @@ Sigma_Exit:
 #if EXTRUDERS > 1
 #if EXTRUDERS > 1
                   if (tmp_extruder != active_extruder) {
                   if (tmp_extruder != active_extruder) {
                       // Save current position to return to after applying extruder offset
                       // Save current position to return to after applying extruder offset
-                      memcpy(destination, current_position, sizeof(destination));
+                      set_destination_to_current();
                       // Offset extruder (only by XY)
                       // Offset extruder (only by XY)
                       int i;
                       int i;
                       for (i = 0; i < 2; i++) {
                       for (i = 0; i < 2; i++) {
@@ -9565,7 +9546,7 @@ void FlushSerialRequestResend()
 // Execution of a command from a SD card will not be confirmed.
 // Execution of a command from a SD card will not be confirmed.
 void ClearToSend()
 void ClearToSend()
 {
 {
-	previous_millis_cmd = _millis();
+	previous_millis_cmd.start();
 	if (buflen && ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR)))
 	if (buflen && ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR)))
 		SERIAL_PROTOCOLLNRPGM(MSG_OK);
 		SERIAL_PROTOCOLLNRPGM(MSG_OK);
 }
 }
@@ -9741,7 +9722,7 @@ void mesh_plan_buffer_line(const float &x, const float &y, const float &z, const
 void prepare_move()
 void prepare_move()
 {
 {
   clamp_to_software_endstops(destination);
   clamp_to_software_endstops(destination);
-  previous_millis_cmd = _millis();
+  previous_millis_cmd.start();
 
 
   // Do not use feedmultiply for E or Z only moves
   // Do not use feedmultiply for E or Z only moves
   if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
   if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
@@ -9767,10 +9748,9 @@ void prepare_arc_move(char isclockwise) {
   // As far as the parser is concerned, the position is now == target. In reality the
   // As far as the parser is concerned, the position is now == target. In reality the
   // motion control system might still be processing the action and the real tool position
   // motion control system might still be processing the action and the real tool position
   // in any intermediate location.
   // in any intermediate location.
-  for(int8_t i=0; i < NUM_AXIS; i++) {
-    current_position[i] = destination[i];
-  }
-  previous_millis_cmd = _millis();
+  set_current_to_destination();
+
+  previous_millis_cmd.start();
 }
 }
 
 
 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
 #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1
@@ -10027,11 +10007,11 @@ if(0)
         get_command();
         get_command();
     }
     }
 
 
-  if( (_millis() - previous_millis_cmd) >  max_inactive_time )
+  if(previous_millis_cmd.expired(max_inactive_time))
     if(max_inactive_time)
     if(max_inactive_time)
       kill(_n("Inactivity Shutdown"), 4);
       kill(_n("Inactivity Shutdown"), 4);
   if(stepper_inactive_time)  {
   if(stepper_inactive_time)  {
-    if( (_millis() - previous_millis_cmd) >  stepper_inactive_time )
+    if(previous_millis_cmd.expired(stepper_inactive_time))
     {
     {
       if(blocks_queued() == false && ignore_stepper_queue == false) {
       if(blocks_queued() == false && ignore_stepper_queue == false) {
         disable_x();
         disable_x();
@@ -10078,7 +10058,7 @@ if(0)
     controllerFan(); //Check if fan should be turned on to cool stepper drivers down
     controllerFan(); //Check if fan should be turned on to cool stepper drivers down
   #endif
   #endif
   #ifdef EXTRUDER_RUNOUT_PREVENT
   #ifdef EXTRUDER_RUNOUT_PREVENT
-    if( (_millis() - previous_millis_cmd) >  EXTRUDER_RUNOUT_SECONDS*1000 )
+    if(previous_millis_cmd.expired(EXTRUDER_RUNOUT_SECONDS*1000))
     if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
     if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
     {
     {
      bool oldstatus=READ(E0_ENABLE_PIN);
      bool oldstatus=READ(E0_ENABLE_PIN);
@@ -10091,7 +10071,7 @@ if(0)
      current_position[E_AXIS]=oldepos;
      current_position[E_AXIS]=oldepos;
      destination[E_AXIS]=oldedes;
      destination[E_AXIS]=oldedes;
      plan_set_e_position(oldepos);
      plan_set_e_position(oldepos);
-     previous_millis_cmd=_millis();
+     previous_millis_cmd.start();
      st_synchronize();
      st_synchronize();
      WRITE(E0_ENABLE_PIN,oldstatus);
      WRITE(E0_ENABLE_PIN,oldstatus);
     }
     }
@@ -11442,7 +11422,7 @@ bool recover_machine_state_after_power_panic()
   // 5) Set the physical positions from the logical positions using the world2machine transformation
   // 5) Set the physical positions from the logical positions using the world2machine transformation
   // This is only done to inizialize Z/E axes with physical locations, since X/Y are unknown.
   // This is only done to inizialize Z/E axes with physical locations, since X/Y are unknown.
   clamp_to_software_endstops(current_position);
   clamp_to_software_endstops(current_position);
-  memcpy(destination, current_position, sizeof(destination));
+  set_destination_to_current();
   plan_set_position_curposXYZE();
   plan_set_position_curposXYZE();
   SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
   SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
   print_world_coordinates();
   print_world_coordinates();
@@ -11775,7 +11755,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
 		plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS] + z_move, saved_pos[E_AXIS] + e_move, homing_feedrate[Z_AXIS], active_extruder);
 		plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS] + z_move, saved_pos[E_AXIS] + e_move, homing_feedrate[Z_AXIS], active_extruder);
     st_synchronize(); //wait moving
     st_synchronize(); //wait moving
     memcpy(current_position, saved_pos, sizeof(saved_pos));
     memcpy(current_position, saved_pos, sizeof(saved_pos));
-    memcpy(destination, current_position, sizeof(destination));
+    set_destination_to_current();
 #endif
 #endif
     waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack
     waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack
   }
   }
@@ -11807,9 +11787,9 @@ void restore_print_from_ram_and_continue(float e_move)
 	if (degTargetHotend(saved_active_extruder) != saved_extruder_temperature)
 	if (degTargetHotend(saved_active_extruder) != saved_extruder_temperature)
 	{
 	{
 		setTargetHotendSafe(saved_extruder_temperature, saved_active_extruder);
 		setTargetHotendSafe(saved_extruder_temperature, saved_active_extruder);
-		heating_status = 1;
+		heating_status = HeatingStatus::EXTRUDER_HEATING;
 		wait_for_heater(_millis(), saved_active_extruder);
 		wait_for_heater(_millis(), saved_active_extruder);
-		heating_status = 2;
+		heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE;
 	}
 	}
 	axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK;
 	axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK;
 	float e = saved_pos[E_AXIS] - e_move;
 	float e = saved_pos[E_AXIS] - e_move;
@@ -11843,7 +11823,7 @@ void restore_print_from_ram_and_continue(float e_move)
 	feedmultiply = saved_feedmultiply2;
 	feedmultiply = saved_feedmultiply2;
 
 
 	memcpy(current_position, saved_pos, sizeof(saved_pos));
 	memcpy(current_position, saved_pos, sizeof(saved_pos));
-	memcpy(destination, current_position, sizeof(destination));
+	set_destination_to_current();
 	if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing
 	if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing
 		card.setIndex(saved_sdpos);
 		card.setIndex(saved_sdpos);
 		sdpos_atomic = saved_sdpos;
 		sdpos_atomic = saved_sdpos;

+ 2 - 2
Firmware/Sd2Card.h

@@ -160,9 +160,9 @@ class Sd2Card {
   /**
   /**
    * \return error code for last error. See Sd2Card.h for a list of error codes.
    * \return error code for last error. See Sd2Card.h for a list of error codes.
    */
    */
-  int errorCode() const {return errorCode_;}
+  uint8_t errorCode() const {return errorCode_;}
   /** \return error data for last error. */
   /** \return error data for last error. */
-  int errorData() const {return status_;}
+  uint8_t errorData() const {return status_;}
   /**
   /**
    * Initialize an SD flash memory card with default clock rate and chip
    * Initialize an SD flash memory card with default clock rate and chip
    * select pin.  See sd2Card::init(uint8_t sckRateID).
    * select pin.  See sd2Card::init(uint8_t sckRateID).

+ 2 - 3
Firmware/cardreader.cpp

@@ -25,7 +25,6 @@ CardReader::CardReader()
    cardOK = false;
    cardOK = false;
    saving = false;
    saving = false;
    logging = false;
    logging = false;
-   autostart_atmillis=0;
    workDirDepth = 0;
    workDirDepth = 0;
    file_subcall_ctr=0;
    file_subcall_ctr=0;
    memset(workDirParents, 0, sizeof(workDirParents));
    memset(workDirParents, 0, sizeof(workDirParents));
@@ -39,7 +38,7 @@ CardReader::CardReader()
     WRITE(SDPOWER,HIGH);
     WRITE(SDPOWER,HIGH);
   #endif //SDPOWER
   #endif //SDPOWER
   
   
-  autostart_atmillis=_millis()+5000;
+  autostart_atmillis.start(); // reset timer
 }
 }
 
 
 char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
 char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
@@ -619,7 +618,7 @@ void CardReader::checkautostart(bool force)
   {
   {
     if(!autostart_stilltocheck)
     if(!autostart_stilltocheck)
       return;
       return;
-    if(autostart_atmillis<_millis())
+    if(autostart_atmillis.expired(5000))
       return;
       return;
   }
   }
   autostart_stilltocheck=false;
   autostart_stilltocheck=false;

+ 1 - 1
Firmware/cardreader.h

@@ -130,7 +130,7 @@ private:
   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
   uint32_t filesize;
   uint32_t filesize;
   //int16_t n;
   //int16_t n;
-  unsigned long autostart_atmillis;
+  ShortTimer autostart_atmillis;
   uint32_t sdpos ;
   uint32_t sdpos ;
 
 
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.

+ 2 - 3
Firmware/cmdqueue.cpp

@@ -443,7 +443,7 @@ void get_command()
 				  char *p = cmdbuffer+bufindw+CMDHDRSIZE;
 				  char *p = cmdbuffer+bufindw+CMDHDRSIZE;
 				  while (p != strchr_pointer)
 				  while (p != strchr_pointer)
 					  checksum = checksum^(*p++);
 					  checksum = checksum^(*p++);
-				  if (int(strtol(strchr_pointer+1, NULL, 10)) != int(checksum)) {
+				  if (code_value_short() != (int16_t)checksum) {
 					  SERIAL_ERROR_START;
 					  SERIAL_ERROR_START;
 					  SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH
 					  SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH
 					  SERIAL_ERRORLN(gcode_LastN);
 					  SERIAL_ERRORLN(gcode_LastN);
@@ -486,8 +486,7 @@ void get_command()
                       is_usb_printing = true;
                       is_usb_printing = true;
               }
               }
             if (Stopped == true) {
             if (Stopped == true) {
-                int gcode = strtol(strchr_pointer+1, NULL, 10);
-                if (gcode >= 0 && gcode <= 3) {
+                if (code_value_uint8() <= 3) {
                     SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED);
                     SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED);
                     LCD_MESSAGERPGM(_T(MSG_STOPPED));
                     LCD_MESSAGERPGM(_T(MSG_STOPPED));
                 }
                 }

+ 1 - 1
Firmware/lcd.cpp

@@ -331,7 +331,7 @@ void lcd_no_autoscroll(void)
 
 
 void lcd_set_cursor(uint8_t col, uint8_t row)
 void lcd_set_cursor(uint8_t col, uint8_t row)
 {
 {
-	int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
+	uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
 	if (row >= LCD_HEIGHT)
 	if (row >= LCD_HEIGHT)
 		row = LCD_HEIGHT - 1;    // we count rows starting w/0
 		row = LCD_HEIGHT - 1;    // we count rows starting w/0
 	lcd_currline = row;  
 	lcd_currline = row;  

+ 1 - 3
Firmware/menu.cpp

@@ -152,9 +152,7 @@ void menu_submenu_no_reset(menu_func_t submenu)
 
 
 uint8_t menu_item_ret(void)
 uint8_t menu_item_ret(void)
 {
 {
-	lcd_beeper_quick_feedback();
-	lcd_draw_update = 2;
-	lcd_button_pressed = false;
+	lcd_quick_feedback();
 	return 1;
 	return 1;
 }
 }
 
 

+ 1 - 1
Firmware/mesh_bed_calibration.cpp

@@ -2852,7 +2852,7 @@ bool sample_mesh_and_store_reference()
         current_position[Y_AXIS] = BED_Y0;
         current_position[Y_AXIS] = BED_Y0;
         world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
         world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
         go_to_current(homing_feedrate[X_AXIS]/60);
         go_to_current(homing_feedrate[X_AXIS]/60);
-        memcpy(destination, current_position, sizeof(destination));
+        set_destination_to_current();
         enable_endstops(true);
         enable_endstops(true);
         homeaxis(Z_AXIS);
         homeaxis(Z_AXIS);
 
 

+ 14 - 14
Firmware/mmu.cpp

@@ -70,14 +70,14 @@ uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN;
 uint8_t tmp_extruder = MMU_FILAMENT_UNKNOWN;
 uint8_t tmp_extruder = MMU_FILAMENT_UNKNOWN;
 
 
 int8_t mmu_finda = -1;
 int8_t mmu_finda = -1;
-uint32_t mmu_last_finda_response = 0;
 
 
 int16_t mmu_version = -1;
 int16_t mmu_version = -1;
 
 
 int16_t mmu_buildnr = -1;
 int16_t mmu_buildnr = -1;
 
 
-uint32_t mmu_last_request = 0;
-uint32_t mmu_last_response = 0;
+ShortTimer mmu_last_request;
+ShortTimer mmu_last_response;
+ShortTimer mmu_last_finda_response;
 
 
 MmuCmd mmu_last_cmd = MmuCmd::None;
 MmuCmd mmu_last_cmd = MmuCmd::None;
 uint16_t mmu_power_failures = 0;
 uint16_t mmu_power_failures = 0;
@@ -113,7 +113,7 @@ int mmu_puts_P(const char* str)
 {
 {
 	mmu_clr_rx_buf();                          //clear rx buffer
 	mmu_clr_rx_buf();                          //clear rx buffer
     int r = fputs_P(str, uart2io);             //send command
     int r = fputs_P(str, uart2io);             //send command
-	mmu_last_request = _millis();
+	mmu_last_request.start();
 	return r;
 	return r;
 }
 }
 
 
@@ -125,7 +125,7 @@ int mmu_printf_P(const char* format, ...)
 	mmu_clr_rx_buf();                          //clear rx buffer
 	mmu_clr_rx_buf();                          //clear rx buffer
 	int r = vfprintf_P(uart2io, format, args); //send command
 	int r = vfprintf_P(uart2io, format, args); //send command
 	va_end(args);
 	va_end(args);
-	mmu_last_request = _millis();
+	mmu_last_request.start();
 	return r;
 	return r;
 }
 }
 
 
@@ -133,7 +133,7 @@ int mmu_printf_P(const char* format, ...)
 int8_t mmu_rx_ok(void)
 int8_t mmu_rx_ok(void)
 {
 {
 	int8_t res = uart2_rx_str_P(PSTR("ok\n"));
 	int8_t res = uart2_rx_str_P(PSTR("ok\n"));
-	if (res == 1) mmu_last_response = _millis();
+	if (res == 1) mmu_last_response.start();
 	return res;
 	return res;
 }
 }
 
 
@@ -141,7 +141,7 @@ int8_t mmu_rx_ok(void)
 int8_t mmu_rx_start(void)
 int8_t mmu_rx_start(void)
 {
 {
 	int8_t res = uart2_rx_str_P(PSTR("start\n"));
 	int8_t res = uart2_rx_str_P(PSTR("start\n"));
-	if (res == 1) mmu_last_response = _millis();
+	if (res == 1) mmu_last_response.start();
 	return res;
 	return res;
 }
 }
 
 
@@ -265,7 +265,7 @@ void mmu_loop(void)
 		if (mmu_rx_ok() > 0)
 		if (mmu_rx_ok() > 0)
 		{
 		{
 			fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
 			fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
-			mmu_last_finda_response = _millis();
+			mmu_last_finda_response.start();
 			FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
 			FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
 			puts_P(PSTR("MMU - ENABLED"));
 			puts_P(PSTR("MMU - ENABLED"));
 			mmu_enabled = true;
 			mmu_enabled = true;
@@ -350,7 +350,7 @@ void mmu_loop(void)
 				mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU);
 				mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU);
 				mmu_state = S::SwitchMode;
 				mmu_state = S::SwitchMode;
 		}
 		}
-		else if ((mmu_last_response + 300) < _millis()) //request every 300ms
+		else if (mmu_last_response.expired(300)) //request every 300ms
 		{
 		{
 #ifndef IR_SENSOR
 #ifndef IR_SENSOR
 			if(check_for_ir_sensor()) ir_sensor_detected = true;
 			if(check_for_ir_sensor()) ir_sensor_detected = true;
@@ -378,7 +378,7 @@ void mmu_loop(void)
 		if (mmu_rx_ok() > 0)
 		if (mmu_rx_ok() > 0)
 		{
 		{
 			fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
 			fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer
-			mmu_last_finda_response = _millis();
+			mmu_last_finda_response.start();
 			FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
 			FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda);
 			//printf_P(PSTR("Eact: %d\n"), int(e_active()));
 			//printf_P(PSTR("Eact: %d\n"), int(e_active()));
 			if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) {
 			if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) {
@@ -398,7 +398,7 @@ void mmu_loop(void)
 			if (mmu_cmd == MmuCmd::None)
 			if (mmu_cmd == MmuCmd::None)
 				mmu_ready = true;
 				mmu_ready = true;
 		}
 		}
-		else if ((mmu_last_request + MMU_P0_TIMEOUT) < _millis())
+		else if (mmu_last_request.expired(MMU_P0_TIMEOUT))
 		{ //resend request after timeout (30s)
 		{ //resend request after timeout (30s)
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}
@@ -424,7 +424,7 @@ void mmu_loop(void)
 			mmu_ready = true;
 			mmu_ready = true;
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}
-		else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
+		else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
 		{ //resend request after timeout (5 min)
 		{ //resend request after timeout (5 min)
 			if (mmu_last_cmd != MmuCmd::None)
 			if (mmu_last_cmd != MmuCmd::None)
 			{
 			{
@@ -467,7 +467,7 @@ void mmu_loop(void)
 			mmu_ready = true;
 			mmu_ready = true;
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}
-		else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
+		else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
 		{ //timeout 45 s
 		{ //timeout 45 s
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}
@@ -479,7 +479,7 @@ void mmu_loop(void)
 			eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU);
 			eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU);
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}
-		else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis())
+		else if (mmu_last_request.expired(MMU_CMD_TIMEOUT))
 		{ //timeout 45 s
 		{ //timeout 45 s
 			mmu_state = S::Idle;
 			mmu_state = S::Idle;
 		}
 		}

+ 2 - 1
Firmware/mmu.h

@@ -4,6 +4,7 @@
 #define MMU_H
 #define MMU_H
 
 
 #include <inttypes.h>
 #include <inttypes.h>
+#include "Timer.h"
 
 
 
 
 extern bool mmu_enabled;
 extern bool mmu_enabled;
@@ -14,7 +15,7 @@ extern uint8_t mmu_extruder;
 extern uint8_t tmp_extruder;
 extern uint8_t tmp_extruder;
 
 
 extern int8_t mmu_finda;
 extern int8_t mmu_finda;
-extern uint32_t mmu_last_finda_response;
+extern ShortTimer mmu_last_finda_response;
 extern bool ir_sensor_detected;
 extern bool ir_sensor_detected;
 
 
 extern int16_t mmu_version;
 extern int16_t mmu_version;

+ 3 - 12
Firmware/planner.cpp

@@ -459,10 +459,7 @@ void plan_init() {
   #ifdef LIN_ADVANCE
   #ifdef LIN_ADVANCE
   memset(position_float, 0, sizeof(position_float)); // clear position
   memset(position_float, 0, sizeof(position_float)); // clear position
   #endif
   #endif
-  previous_speed[0] = 0.0;
-  previous_speed[1] = 0.0;
-  previous_speed[2] = 0.0;
-  previous_speed[3] = 0.0;
+  memset(previous_speed, 0, sizeof(previous_speed));
   previous_nominal_speed = 0.0;
   previous_nominal_speed = 0.0;
   plan_reset_next_e_queue = false;
   plan_reset_next_e_queue = false;
   plan_reset_next_e_sched = false;
   plan_reset_next_e_sched = false;
@@ -678,10 +675,7 @@ void planner_abort_hard()
 #endif
 #endif
     // Resets planner junction speeds. Assumes start from rest.
     // Resets planner junction speeds. Assumes start from rest.
     previous_nominal_speed = 0.0;
     previous_nominal_speed = 0.0;
-    previous_speed[0] = 0.0;
-    previous_speed[1] = 0.0;
-    previous_speed[2] = 0.0;
-    previous_speed[3] = 0.0;
+    memset(previous_speed, 0, sizeof(previous_speed));
 
 
     plan_reset_next_e_queue = false;
     plan_reset_next_e_queue = false;
     plan_reset_next_e_sched = false;
     plan_reset_next_e_sched = false;
@@ -1412,10 +1406,7 @@ void plan_set_position(float x, float y, float z, const float &e)
   #endif
   #endif
   st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]);
   st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]);
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
-  previous_speed[0] = 0.0;
-  previous_speed[1] = 0.0;
-  previous_speed[2] = 0.0;
-  previous_speed[3] = 0.0;
+  memset(previous_speed, 0, sizeof(previous_speed));
 }
 }
 
 
 // Only useful in the bed leveling routine, when the mesh bed leveling is off.
 // Only useful in the bed leveling routine, when the mesh bed leveling is off.

+ 2 - 2
Firmware/temperature.cpp

@@ -615,7 +615,7 @@ void fanSpeedError(unsigned char _fan) {
 	if (get_message_level() != 0 && isPrintPaused) return;
 	if (get_message_level() != 0 && isPrintPaused) return;
 	//to ensure that target temp. is not set to zero in case that we are resuming print
 	//to ensure that target temp. is not set to zero in case that we are resuming print
 	if (card.sdprinting || is_usb_printing) {
 	if (card.sdprinting || is_usb_printing) {
-		if (heating_status != 0) {
+		if (heating_status != HeatingStatus::NO_HEATING) {
 			lcd_print_stop();
 			lcd_print_stop();
 		}
 		}
 		else {
 		else {
@@ -625,7 +625,7 @@ void fanSpeedError(unsigned char _fan) {
 	else {
 	else {
 		// SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? is_usb_printing would be true in that case, so there is no need for this.
 		// SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? is_usb_printing would be true in that case, so there is no need for this.
 		setTargetHotend0(0);
 		setTargetHotend0(0);
-        heating_status = 0;
+        heating_status = HeatingStatus::NO_HEATING;
         fan_check_error = EFCE_REPORTED;
         fan_check_error = EFCE_REPORTED;
 	}
 	}
 	switch (_fan) {
 	switch (_fan) {

+ 1 - 1
Firmware/temperature.h

@@ -168,7 +168,7 @@ static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder)
 // Doesn't save FLASH when not inlined.
 // Doesn't save FLASH when not inlined.
 static inline void setAllTargetHotends(const float &celsius)
 static inline void setAllTargetHotends(const float &celsius)
 {
 {
-    for(int i=0;i<EXTRUDERS;i++) setTargetHotend(celsius,i);
+    for(uint8_t i = 0; i < EXTRUDERS; i++) setTargetHotend(celsius, i);
 }
 }
 
 
 FORCE_INLINE void setTargetBed(const float &celsius) {  
 FORCE_INLINE void setTargetBed(const float &celsius) {  

+ 21 - 32
Firmware/ultralcd.cpp

@@ -55,7 +55,7 @@
 
 
 
 
 int clock_interval = 0;
 int clock_interval = 0;
-
+static ShortTimer NcTime;
 static void lcd_sd_updir();
 static void lcd_sd_updir();
 static void lcd_mesh_bed_leveling_settings();
 static void lcd_mesh_bed_leveling_settings();
 #ifdef LCD_BL_PIN
 #ifdef LCD_BL_PIN
@@ -78,16 +78,15 @@ LcdCommands lcd_commands_type = LcdCommands::Idle;
 static uint8_t lcd_commands_step = 0;
 static uint8_t lcd_commands_step = 0;
 
 
 CustomMsg custom_message_type = CustomMsg::Status;
 CustomMsg custom_message_type = CustomMsg::Status;
-unsigned int custom_message_state = 0;
-
+uint8_t custom_message_state = 0;
 
 
 bool isPrintPaused = false;
 bool isPrintPaused = false;
 uint8_t farm_mode = 0;
 uint8_t farm_mode = 0;
-int farm_timer = 8;
+uint8_t farm_timer = 8;
 uint8_t farm_status = 0;
 uint8_t farm_status = 0;
 bool printer_connected = true;
 bool printer_connected = true;
 
 
-unsigned long display_time; //just timer for showing pid finished message on lcd;
+static ShortTimer display_time; //just timer for showing pid finished message on lcd;
 float pid_temp = DEFAULT_PID_TEMP;
 float pid_temp = DEFAULT_PID_TEMP;
 
 
 static bool forceMenuExpire = false;
 static bool forceMenuExpire = false;
@@ -458,7 +457,7 @@ void lcdui_print_percent_done(void)
 	const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N("   "));
 	const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N("   "));
 	char per[4];
 	char per[4];
 	bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
 	bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT));
-	if (!num || heating_status) // either not printing or heating
+	if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating
 	{
 	{
 		const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
 		const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet));
 		const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
 		const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR);
@@ -575,7 +574,7 @@ void lcdui_print_time(void)
 //! @Brief Print status line on status screen
 //! @Brief Print status line on status screen
 void lcdui_print_status_line(void)
 void lcdui_print_status_line(void)
 {
 {
-    if (heating_status) { // If heating flag, show progress of heating
+    if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating
         heating_status_counter++;
         heating_status_counter++;
         if (heating_status_counter > 13) {
         if (heating_status_counter > 13) {
             heating_status_counter = 0;
             heating_status_counter = 0;
@@ -583,24 +582,24 @@ void lcdui_print_status_line(void)
         lcd_set_cursor(7, 3);
         lcd_set_cursor(7, 3);
         lcd_space(13);
         lcd_space(13);
 
 
-        for (unsigned int dots = 0; dots < heating_status_counter; dots++) {
+        for (uint8_t dots = 0; dots < heating_status_counter; dots++) {
             lcd_putc_at(7 + dots, 3, '.');
             lcd_putc_at(7 + dots, 3, '.');
         }
         }
         switch (heating_status) {
         switch (heating_status) {
-        case 1:
+        case HeatingStatus::EXTRUDER_HEATING:
             lcd_puts_at_P(0, 3, _T(MSG_HEATING));
             lcd_puts_at_P(0, 3, _T(MSG_HEATING));
             break;
             break;
-        case 2:
+        case HeatingStatus::EXTRUDER_HEATING_COMPLETE:
             lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
             lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE));
-            heating_status = 0;
+            heating_status = HeatingStatus::NO_HEATING;
             heating_status_counter = 0;
             heating_status_counter = 0;
             break;
             break;
-        case 3:
+        case HeatingStatus::BED_HEATING:
             lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
             lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING));
             break;
             break;
-        case 4:
+        case HeatingStatus::BED_HEATING_COMPLETE:
             lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
             lcd_puts_at_P(0, 3, _T(MSG_BED_DONE));
-            heating_status = 0;
+            heating_status = HeatingStatus::NO_HEATING;
             heating_status_counter = 0;
             heating_status_counter = 0;
             break;
             break;
         default:
         default:
@@ -1344,10 +1343,10 @@ void lcd_commands()
 			else {
 			else {
 				SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
 				SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
 			}
 			}
-			display_time = _millis();
+			display_time.start();
 			lcd_commands_step = 1;
 			lcd_commands_step = 1;
 		}
 		}
-		if ((lcd_commands_step == 1) && ((_millis()- display_time)>2000)) { //calibration finished message
+		if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message
 			lcd_setstatuspgm(_T(WELCOME_MSG));
 			lcd_setstatuspgm(_T(WELCOME_MSG));
 			custom_message_type = CustomMsg::Status;
 			custom_message_type = CustomMsg::Status;
 			pid_temp = DEFAULT_PID_TEMP;
 			pid_temp = DEFAULT_PID_TEMP;
@@ -1385,8 +1384,6 @@ void lcd_pause_usb_print()
     SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE);
     SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE);
 }
 }
 
 
-
-float move_menu_scale;
 static void lcd_move_menu_axis();
 static void lcd_move_menu_axis();
 
 
 
 
@@ -2763,7 +2760,7 @@ static void _lcd_move(const char *name, uint8_t axis, int min, int max)
 		refresh_cmd_timeout();
 		refresh_cmd_timeout();
 		if (! planner_queue_full())
 		if (! planner_queue_full())
 		{
 		{
-			current_position[axis] += float((int)lcd_encoder) * move_menu_scale;
+			current_position[axis] += float((int)lcd_encoder);
 			if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
 			if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
 			if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
 			if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
 			lcd_encoder = 0;
 			lcd_encoder = 0;
@@ -2791,7 +2788,7 @@ void lcd_move_e()
 			refresh_cmd_timeout();
 			refresh_cmd_timeout();
 			if (! planner_queue_full())
 			if (! planner_queue_full())
 			{
 			{
-				current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale;
+				current_position[E_AXIS] += float((int)lcd_encoder);
 				lcd_encoder = 0;
 				lcd_encoder = 0;
 				plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
 				plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60);
 				lcd_draw_update = 1;
 				lcd_draw_update = 1;
@@ -3839,7 +3836,7 @@ static void lcd_show_sensors_state()
 	uint8_t idler_state = STATE_NA;
 	uint8_t idler_state = STATE_NA;
 
 
 	pinda_state = READ(Z_MIN_PIN);
 	pinda_state = READ(Z_MIN_PIN);
-	if (mmu_enabled && ((_millis() - mmu_last_finda_response) < 1000ul) )
+	if (mmu_enabled && mmu_last_finda_response.expired(1000))
 	{
 	{
 		finda_state = mmu_finda;
 		finda_state = mmu_finda;
 	}
 	}
@@ -4235,13 +4232,6 @@ void lcd_move_menu_axis()
 	MENU_END();
 	MENU_END();
 }
 }
 
 
-static void lcd_move_menu_1mm()
-{
-  move_menu_scale = 1.0;
-  lcd_move_menu_axis();
-}
-
-
 void EEPROM_save(int pos, uint8_t* value, uint8_t size)
 void EEPROM_save(int pos, uint8_t* value, uint8_t size)
 {
 {
   do
   do
@@ -5672,7 +5662,7 @@ static void lcd_settings_menu()
 
 
 	if (!PRINTER_ACTIVE || isPrintPaused)
 	if (!PRINTER_ACTIVE || isPrintPaused)
     {
     {
-	    MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=18
+	    MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18
 	    MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
 	    MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18
     }
     }
 
 
@@ -8705,10 +8695,10 @@ void lcd_printer_connected() {
 }
 }
 
 
 static void lcd_send_status() {
 static void lcd_send_status() {
-	if (farm_mode && no_response && ((_millis() - NcTime) > (NC_TIME * 1000))) {
+	if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
 		//send important status messages periodicaly
 		//send important status messages periodicaly
 		prusa_statistics(important_status, saved_filament_type);
 		prusa_statistics(important_status, saved_filament_type);
-		NcTime = _millis();
+		NcTime.start();
 #ifdef FARM_CONNECT_MESSAGE
 #ifdef FARM_CONNECT_MESSAGE
 		lcd_connect_printer();
 		lcd_connect_printer();
 #endif //FARM_CONNECT_MESSAGE
 #endif //FARM_CONNECT_MESSAGE
@@ -8880,7 +8870,6 @@ void menu_lcd_longpress_func(void)
 #endif
 #endif
         || menu_menu == lcd_support_menu
         || menu_menu == lcd_support_menu
         ){
         ){
-            move_menu_scale = 1.0;
             menu_submenu(lcd_move_z);
             menu_submenu(lcd_move_z);
         } else {
         } else {
             // otherwise consume the long press as normal click
             // otherwise consume the long press as normal click

+ 1 - 3
Firmware/ultralcd.h

@@ -121,11 +121,9 @@ enum class CustomMsg : uint_least8_t
 };
 };
 
 
 extern CustomMsg custom_message_type;
 extern CustomMsg custom_message_type;
-extern unsigned int custom_message_state;
+extern uint8_t custom_message_state;
 
 
 extern uint8_t farm_mode;
 extern uint8_t farm_mode;
-extern int farm_timer;
-extern uint8_t farm_status;
 
 
 extern bool UserECoolEnabled();
 extern bool UserECoolEnabled();
 extern bool FarmOrUserECool();
 extern bool FarmOrUserECool();