Browse Source

Apply three more commits

Scott Lahteine 9 years ago
parent
commit
ccddc280be

+ 10
- 6
Marlin/Marlin.h View File

31
 #define TEST(n,b) (((n)&BIT(b))!=0)
31
 #define TEST(n,b) (((n)&BIT(b))!=0)
32
 #define RADIANS(d) ((d)*M_PI/180.0)
32
 #define RADIANS(d) ((d)*M_PI/180.0)
33
 #define DEGREES(r) ((d)*180.0/M_PI)
33
 #define DEGREES(r) ((d)*180.0/M_PI)
34
+#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
35
+#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
36
+
37
+typedef unsigned long millis_t;
34
 
38
 
35
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
39
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
36
 #ifndef analogInputToDigitalPin
40
 #ifndef analogInputToDigitalPin
223
 inline bool IsRunning() { return  Running; }
227
 inline bool IsRunning() { return  Running; }
224
 inline bool IsStopped() { return !Running; }
228
 inline bool IsStopped() { return !Running; }
225
 
229
 
226
-bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
227
-void enquecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
230
+bool enqueuecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
231
+void enqueuecommands_P(const char *cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
228
 
232
 
229
 void prepare_arc_move(char isclockwise);
233
 void prepare_arc_move(char isclockwise);
230
 void clamp_to_software_endstops(float target[3]);
234
 void clamp_to_software_endstops(float target[3]);
231
 
235
 
232
-extern unsigned long previous_millis_cmd;
233
-inline void refresh_cmd_timeout() { previous_millis_cmd = millis(); }
236
+extern millis_t previous_cmd_ms;
237
+inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
234
 
238
 
235
 #ifdef FAST_PWM_FAN
239
 #ifdef FAST_PWM_FAN
236
   void setPwmFrequency(uint8_t pin, int val);
240
   void setPwmFrequency(uint8_t pin, int val);
305
   extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
309
   extern float retract_recover_length, retract_recover_length_swap, retract_recover_feedrate;
306
 #endif
310
 #endif
307
 
311
 
308
-extern unsigned long starttime;
309
-extern unsigned long stoptime;
312
+extern millis_t starttime;
313
+extern millis_t stoptime;
310
 
314
 
311
 // Handling multiple extruders pins
315
 // Handling multiple extruders pins
312
 extern uint8_t active_extruder;
316
 extern uint8_t active_extruder;

+ 202
- 243
Marlin/Marlin_main.cpp View File

244
 const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
244
 const char* queued_commands_P= NULL; /* pointer to the current line in the active sequence of commands, or NULL when none */
245
 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
245
 const int sensitive_pins[] = SENSITIVE_PINS; ///< Sensitive pin list for M42
246
 // Inactivity shutdown
246
 // Inactivity shutdown
247
-unsigned long previous_millis_cmd = 0;
248
-static unsigned long max_inactive_time = 0;
249
-static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l;
250
-unsigned long starttime = 0; ///< Print job start time
251
-unsigned long stoptime = 0;  ///< Print job stop time
247
+millis_t previous_cmd_ms = 0;
248
+static millis_t max_inactive_time = 0;
249
+static millis_t stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME * 1000L;
250
+millis_t starttime = 0; ///< Print job start time
251
+millis_t stoptime = 0;  ///< Print job stop time
252
 static uint8_t target_extruder;
252
 static uint8_t target_extruder;
253
 bool CooldownNoWait = true;
253
 bool CooldownNoWait = true;
254
 bool target_direction;
254
 bool target_direction;
425
   char c;
425
   char c;
426
   while((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command
426
   while((c = cmd[i]) && c != '\n') i++; // find the end of this gcode command
427
   cmd[i] = '\0';
427
   cmd[i] = '\0';
428
-  if (enquecommand(cmd)) {        // buffer was not full (else we will retry later)
428
+  if (enqueuecommand(cmd)) {        // buffer was not full (else we will retry later)
429
     if (c)
429
     if (c)
430
       queued_commands_P += i + 1; // move to next command
430
       queued_commands_P += i + 1; // move to next command
431
     else
431
     else
437
 //Record one or many commands to run from program memory.
437
 //Record one or many commands to run from program memory.
438
 //Aborts the current queue, if any.
438
 //Aborts the current queue, if any.
439
 //Note: drain_queued_commands_P() must be called repeatedly to drain the commands afterwards
439
 //Note: drain_queued_commands_P() must be called repeatedly to drain the commands afterwards
440
-void enquecommands_P(const char* pgcode) {
440
+void enqueuecommands_P(const char* pgcode) {
441
     queued_commands_P = pgcode;
441
     queued_commands_P = pgcode;
442
     drain_queued_commands_P(); // first command executed asap (when possible)
442
     drain_queued_commands_P(); // first command executed asap (when possible)
443
 }
443
 }
446
 //that is really done in a non-safe way.
446
 //that is really done in a non-safe way.
447
 //needs overworking someday
447
 //needs overworking someday
448
 //Returns false if it failed to do so
448
 //Returns false if it failed to do so
449
-bool enquecommand(const char *cmd)
449
+bool enqueuecommand(const char *cmd)
450
 {
450
 {
451
   if(*cmd==';')
451
   if(*cmd==';')
452
     return false;
452
     return false;
666
   lcd_update();
666
   lcd_update();
667
 }
667
 }
668
 
668
 
669
-void get_command()
670
-{
671
-  if (drain_queued_commands_P()) // priority is given to non-serial commands
672
-    return;
669
+void get_command() {
670
+
671
+  if (drain_queued_commands_P()) return; // priority is given to non-serial commands
673
   
672
   
674
-  while( MYSERIAL.available() > 0  && buflen < BUFSIZE) {
673
+  while (MYSERIAL.available() > 0 && buflen < BUFSIZE) {
675
     serial_char = MYSERIAL.read();
674
     serial_char = MYSERIAL.read();
676
-    if(serial_char == '\n' ||
677
-       serial_char == '\r' ||
678
-       serial_count >= (MAX_CMD_SIZE - 1) )
679
-    {
675
+    if (serial_char == '\n' || serial_char == '\r' ||
676
+       serial_count >= (MAX_CMD_SIZE - 1)
677
+    ) {
680
       // end of line == end of comment
678
       // end of line == end of comment
681
       comment_mode = false;
679
       comment_mode = false;
682
 
680
 
683
-      if(!serial_count) {
684
-        // short cut for empty lines
685
-        return;
686
-      }
687
-      cmdbuffer[bufindw][serial_count] = 0; //terminate string
681
+      if (!serial_count) return; // shortcut for empty lines
682
+
683
+      cmdbuffer[bufindw][serial_count] = 0; // terminate string
684
+
688
       #ifdef SDSUPPORT
685
       #ifdef SDSUPPORT
689
-      fromsd[bufindw] = false;
690
-      #endif //!SDSUPPORT
691
-      if(strchr(cmdbuffer[bufindw], 'N') != NULL)
692
-      {
686
+        fromsd[bufindw] = false;
687
+      #endif
688
+
689
+      if (strchr(cmdbuffer[bufindw], 'N') != NULL) {
693
         strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
690
         strchr_pointer = strchr(cmdbuffer[bufindw], 'N');
694
         gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
691
         gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
695
-        if(gcode_N != gcode_LastN+1 && (strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) ) {
692
+        if (gcode_N != gcode_LastN + 1 && strstr_P(cmdbuffer[bufindw], PSTR("M110")) == NULL) {
696
           SERIAL_ERROR_START;
693
           SERIAL_ERROR_START;
697
           SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
694
           SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
698
           SERIAL_ERRORLN(gcode_LastN);
695
           SERIAL_ERRORLN(gcode_LastN);
702
           return;
699
           return;
703
         }
700
         }
704
 
701
 
705
-        if(strchr(cmdbuffer[bufindw], '*') != NULL)
706
-        {
702
+        if (strchr(cmdbuffer[bufindw], '*') != NULL) {
707
           byte checksum = 0;
703
           byte checksum = 0;
708
           byte count = 0;
704
           byte count = 0;
709
-          while(cmdbuffer[bufindw][count] != '*') checksum = checksum^cmdbuffer[bufindw][count++];
705
+          while (cmdbuffer[bufindw][count] != '*') checksum ^= cmdbuffer[bufindw][count++];
710
           strchr_pointer = strchr(cmdbuffer[bufindw], '*');
706
           strchr_pointer = strchr(cmdbuffer[bufindw], '*');
711
 
707
 
712
-          if(strtol(strchr_pointer + 1, NULL, 10) != checksum) {
708
+          if (strtol(strchr_pointer + 1, NULL, 10) != checksum) {
713
             SERIAL_ERROR_START;
709
             SERIAL_ERROR_START;
714
             SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
710
             SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
715
             SERIAL_ERRORLN(gcode_LastN);
711
             SERIAL_ERRORLN(gcode_LastN);
719
           }
715
           }
720
           //if no errors, continue parsing
716
           //if no errors, continue parsing
721
         }
717
         }
722
-        else
723
-        {
718
+        else {
724
           SERIAL_ERROR_START;
719
           SERIAL_ERROR_START;
725
           SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
720
           SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
726
           SERIAL_ERRORLN(gcode_LastN);
721
           SERIAL_ERRORLN(gcode_LastN);
732
         gcode_LastN = gcode_N;
727
         gcode_LastN = gcode_N;
733
         //if no errors, continue parsing
728
         //if no errors, continue parsing
734
       }
729
       }
735
-      else  // if we don't receive 'N' but still see '*'
736
-      {
737
-        if((strchr(cmdbuffer[bufindw], '*') != NULL))
738
-        {
730
+      else {  // if we don't receive 'N' but still see '*'
731
+        if ((strchr(cmdbuffer[bufindw], '*') != NULL)) {
739
           SERIAL_ERROR_START;
732
           SERIAL_ERROR_START;
740
           SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
733
           SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
741
           SERIAL_ERRORLN(gcode_LastN);
734
           SERIAL_ERRORLN(gcode_LastN);
743
           return;
736
           return;
744
         }
737
         }
745
       }
738
       }
746
-      if((strchr(cmdbuffer[bufindw], 'G') != NULL)){
739
+
740
+      if (strchr(cmdbuffer[bufindw], 'G') != NULL) {
747
         strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
741
         strchr_pointer = strchr(cmdbuffer[bufindw], 'G');
748
-        switch(strtol(strchr_pointer + 1, NULL, 10)){
749
-        case 0:
750
-        case 1:
751
-        case 2:
752
-        case 3:
753
-          if (IsStopped()) {
754
-            SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
755
-            LCD_MESSAGEPGM(MSG_STOPPED);
756
-          }
757
-          break;
758
-        default:
759
-          break;
742
+        switch (strtol(strchr_pointer + 1, NULL, 10)) {
743
+          case 0:
744
+          case 1:
745
+          case 2:
746
+          case 3:
747
+            if (IsStopped()) {
748
+              SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
749
+              LCD_MESSAGEPGM(MSG_STOPPED);
750
+            }
751
+            break;
752
+          default:
753
+            break;
760
         }
754
         }
761
-
762
       }
755
       }
763
 
756
 
764
-      //If command was e-stop process now
765
-      if(strcmp(cmdbuffer[bufindw], "M112") == 0)
766
-        kill();
757
+      // If command was e-stop process now
758
+      if (strcmp(cmdbuffer[bufindw], "M112") == 0) kill();
767
 
759
 
768
-      bufindw = (bufindw + 1)%BUFSIZE;
760
+      bufindw = (bufindw + 1) % BUFSIZE;
769
       buflen += 1;
761
       buflen += 1;
770
 
762
 
771
       serial_count = 0; //clear buffer
763
       serial_count = 0; //clear buffer
772
     }
764
     }
773
-    else if(serial_char == '\\') {  //Handle escapes
774
-       
775
-        if(MYSERIAL.available() > 0  && buflen < BUFSIZE) {
776
-            // if we have one more character, copy it over
777
-            serial_char = MYSERIAL.read();
778
-            cmdbuffer[bufindw][serial_count++] = serial_char;
779
-        }
780
-
781
-        //otherwise do nothing        
765
+    else if (serial_char == '\\') {  // Handle escapes
766
+      if (MYSERIAL.available() > 0  && buflen < BUFSIZE) {
767
+        // if we have one more character, copy it over
768
+        serial_char = MYSERIAL.read();
769
+        cmdbuffer[bufindw][serial_count++] = serial_char;
770
+      }
771
+      // otherwise do nothing
782
     }
772
     }
783
     else { // its not a newline, carriage return or escape char
773
     else { // its not a newline, carriage return or escape char
784
-        if(serial_char == ';') comment_mode = true;
785
-        if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
774
+      if (serial_char == ';') comment_mode = true;
775
+      if (!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
786
     }
776
     }
787
   }
777
   }
788
-  #ifdef SDSUPPORT
789
-  if(!card.sdprinting || serial_count!=0){
790
-    return;
791
-  }
792
 
778
 
793
-  //'#' stops reading from SD to the buffer prematurely, so procedural macro calls are possible
794
-  // if it occurs, stop_buffering is triggered and the buffer is ran dry.
795
-  // this character _can_ occur in serial com, due to checksums. however, no checksums are used in SD printing
796
-
797
-  static bool stop_buffering=false;
798
-  if(buflen==0) stop_buffering=false;
799
-
800
-  while( !card.eof()  && buflen < BUFSIZE && !stop_buffering) {
801
-    int16_t n=card.get();
802
-    serial_char = (char)n;
803
-    if(serial_char == '\n' ||
804
-       serial_char == '\r' ||
805
-       (serial_char == '#' && comment_mode == false) ||
806
-       (serial_char == ':' && comment_mode == false) ||
807
-       serial_count >= (MAX_CMD_SIZE - 1)||n==-1)
808
-    {
809
-      if(card.eof()){
810
-        SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
811
-        stoptime=millis();
812
-        char time[30];
813
-        unsigned long t=(stoptime-starttime)/1000;
814
-        int hours, minutes;
815
-        minutes=(t/60)%60;
816
-        hours=t/60/60;
817
-        sprintf_P(time, PSTR("%i "MSG_END_HOUR" %i "MSG_END_MINUTE),hours, minutes);
818
-        SERIAL_ECHO_START;
819
-        SERIAL_ECHOLN(time);
820
-        lcd_setstatus(time, true);
821
-        card.printingHasFinished();
822
-        card.checkautostart(true);
779
+  #ifdef SDSUPPORT
823
 
780
 
824
-      }
825
-      if(serial_char=='#')
826
-        stop_buffering=true;
781
+    if (!card.sdprinting || serial_count) return;
782
+
783
+    // '#' stops reading from SD to the buffer prematurely, so procedural macro calls are possible
784
+    // if it occurs, stop_buffering is triggered and the buffer is ran dry.
785
+    // this character _can_ occur in serial com, due to checksums. however, no checksums are used in SD printing
786
+
787
+    static bool stop_buffering = false;
788
+    if (buflen == 0) stop_buffering = false;
789
+
790
+    while (!card.eof() && buflen < BUFSIZE && !stop_buffering) {
791
+      int16_t n = card.get();
792
+      serial_char = (char)n;
793
+      if (serial_char == '\n' || serial_char == '\r' ||
794
+          ((serial_char == '#' || serial_char == ':') && !comment_mode) ||
795
+          serial_count >= (MAX_CMD_SIZE - 1) || n == -1
796
+      ) {
797
+        if (card.eof()) {
798
+          SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED);
799
+          stoptime = millis();
800
+          char time[30];
801
+          millis_t t = (stoptime - starttime) / 1000;
802
+          int hours = t / 60 / 60, minutes = (t / 60) % 60;
803
+          sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
804
+          SERIAL_ECHO_START;
805
+          SERIAL_ECHOLN(time);
806
+          lcd_setstatus(time, true);
807
+          card.printingHasFinished();
808
+          card.checkautostart(true);
809
+        }
810
+        if (serial_char == '#') stop_buffering = true;
827
 
811
 
828
-      if(!serial_count)
829
-      {
830
-        comment_mode = false; //for new command
831
-        return; //if empty line
832
-      }
833
-      cmdbuffer[bufindw][serial_count] = 0; //terminate string
834
-//      if(!comment_mode){
812
+        if (!serial_count) {
813
+          comment_mode = false; //for new command
814
+          return; //if empty line
815
+        }
816
+        cmdbuffer[bufindw][serial_count] = 0; //terminate string
817
+        // if (!comment_mode) {
835
         fromsd[bufindw] = true;
818
         fromsd[bufindw] = true;
836
         buflen += 1;
819
         buflen += 1;
837
         bufindw = (bufindw + 1)%BUFSIZE;
820
         bufindw = (bufindw + 1)%BUFSIZE;
838
-//      }
839
-      comment_mode = false; //for new command
840
-      serial_count = 0; //clear buffer
841
-    }
842
-    else
843
-    {
844
-      if(serial_char == ';') comment_mode = true;
845
-      if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
821
+        // }
822
+        comment_mode = false; //for new command
823
+        serial_count = 0; //clear buffer
824
+      }
825
+      else {
826
+        if (serial_char == ';') comment_mode = true;
827
+        if (!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
828
+      }
846
     }
829
     }
847
-  }
848
-
849
-  #endif //SDSUPPORT
850
 
830
 
831
+  #endif // SDSUPPORT
851
 }
832
 }
852
 
833
 
853
 float code_has_value() {
834
 float code_has_value() {
923
   static float inactive_extruder_x_pos = X2_MAX_POS; // used in mode 0 & 1
904
   static float inactive_extruder_x_pos = X2_MAX_POS; // used in mode 0 & 1
924
   static bool active_extruder_parked = false; // used in mode 1 & 2
905
   static bool active_extruder_parked = false; // used in mode 1 & 2
925
   static float raised_parked_position[NUM_AXIS]; // used in mode 1
906
   static float raised_parked_position[NUM_AXIS]; // used in mode 1
926
-  static unsigned long delayed_move_time = 0; // used in mode 1
907
+  static millis_t delayed_move_time = 0; // used in mode 1
927
   static float duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
908
   static float duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
928
   static float duplicate_extruder_temp_offset = 0; // used in mode 2
909
   static float duplicate_extruder_temp_offset = 0; // used in mode 2
929
   bool extruder_duplication_enabled = false; // used in mode 2
910
   bool extruder_duplication_enabled = false; // used in mode 2
1111
       // move down slowly until you find the bed
1092
       // move down slowly until you find the bed
1112
       feedrate = homing_feedrate[Z_AXIS] / 4;
1093
       feedrate = homing_feedrate[Z_AXIS] / 4;
1113
       destination[Z_AXIS] = -10;
1094
       destination[Z_AXIS] = -10;
1114
-      prepare_move_raw();
1095
+      prepare_move_raw(); // this will also set_current_to_destination
1115
       st_synchronize();
1096
       st_synchronize();
1116
       endstops_hit_on_purpose(); // clear endstop hit flags
1097
       endstops_hit_on_purpose(); // clear endstop hit flags
1117
       
1098
       
1157
   }
1138
   }
1158
 
1139
 
1159
   /**
1140
   /**
1160
-   * 
1141
+   *  Plan a move to (X, Y, Z) and set the current_position
1142
+   *  The final current_position may not be the one that was requested
1161
    */
1143
    */
1162
   static void do_blocking_move_to(float x, float y, float z) {
1144
   static void do_blocking_move_to(float x, float y, float z) {
1163
     float oldFeedRate = feedrate;
1145
     float oldFeedRate = feedrate;
1169
       destination[X_AXIS] = x;
1151
       destination[X_AXIS] = x;
1170
       destination[Y_AXIS] = y;
1152
       destination[Y_AXIS] = y;
1171
       destination[Z_AXIS] = z;
1153
       destination[Z_AXIS] = z;
1172
-      prepare_move_raw();
1154
+      prepare_move_raw(); // this will also set_current_to_destination
1173
       st_synchronize();
1155
       st_synchronize();
1174
 
1156
 
1175
     #else
1157
     #else
1233
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_X;
1215
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_X;
1234
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Y;
1216
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Y;
1235
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Z;
1217
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_DEPLOY_Z;
1236
-      prepare_move_raw();
1218
+      prepare_move_raw(); // this will also set_current_to_destination
1237
 
1219
 
1238
       // Home X to touch the belt
1220
       // Home X to touch the belt
1239
       feedrate = homing_feedrate[X_AXIS]/10;
1221
       feedrate = homing_feedrate[X_AXIS]/10;
1240
       destination[X_AXIS] = 0;
1222
       destination[X_AXIS] = 0;
1241
-      prepare_move_raw();
1223
+      prepare_move_raw(); // this will also set_current_to_destination
1242
       
1224
       
1243
       // Home Y for safety
1225
       // Home Y for safety
1244
       feedrate = homing_feedrate[X_AXIS]/2;
1226
       feedrate = homing_feedrate[X_AXIS]/2;
1245
       destination[Y_AXIS] = 0;
1227
       destination[Y_AXIS] = 0;
1246
-      prepare_move_raw();
1228
+      prepare_move_raw(); // this will also set_current_to_destination
1247
       
1229
       
1248
       st_synchronize();
1230
       st_synchronize();
1249
 
1231
 
1275
       if (servo_endstops[Z_AXIS] >= 0) {
1257
       if (servo_endstops[Z_AXIS] >= 0) {
1276
 
1258
 
1277
         #if Z_RAISE_AFTER_PROBING > 0
1259
         #if Z_RAISE_AFTER_PROBING > 0
1278
-          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING);
1260
+          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1279
           st_synchronize();
1261
           st_synchronize();
1280
         #endif
1262
         #endif
1281
 
1263
 
1296
       // Move up for safety
1278
       // Move up for safety
1297
       feedrate = homing_feedrate[X_AXIS];
1279
       feedrate = homing_feedrate[X_AXIS];
1298
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING;
1280
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING;
1299
-      prepare_move_raw();
1281
+      prepare_move_raw(); // this will also set_current_to_destination
1300
 
1282
 
1301
       // Move to the start position to initiate retraction
1283
       // Move to the start position to initiate retraction
1302
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_X;
1284
       destination[X_AXIS] = Z_PROBE_ALLEN_KEY_STOW_X;
1303
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Y;
1285
       destination[Y_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Y;
1304
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Z;
1286
       destination[Z_AXIS] = Z_PROBE_ALLEN_KEY_STOW_Z;
1305
-      prepare_move_raw();
1287
+      prepare_move_raw(); // this will also set_current_to_destination
1306
 
1288
 
1307
       // Move the nozzle down to push the probe into retracted position
1289
       // Move the nozzle down to push the probe into retracted position
1308
       feedrate = homing_feedrate[Z_AXIS]/10;
1290
       feedrate = homing_feedrate[Z_AXIS]/10;
1309
       destination[Z_AXIS] = current_position[Z_AXIS] - Z_PROBE_ALLEN_KEY_STOW_DEPTH;
1291
       destination[Z_AXIS] = current_position[Z_AXIS] - Z_PROBE_ALLEN_KEY_STOW_DEPTH;
1310
-      prepare_move_raw();
1292
+      prepare_move_raw(); // this will also set_current_to_destination
1311
       
1293
       
1312
       // Move up for safety
1294
       // Move up for safety
1313
       feedrate = homing_feedrate[Z_AXIS]/2;
1295
       feedrate = homing_feedrate[Z_AXIS]/2;
1314
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_PROBE_ALLEN_KEY_STOW_DEPTH * 2;
1296
       destination[Z_AXIS] = current_position[Z_AXIS] + Z_PROBE_ALLEN_KEY_STOW_DEPTH * 2;
1315
-      prepare_move_raw();
1297
+      prepare_move_raw(); // this will also set_current_to_destination
1316
       
1298
       
1317
       // Home XY for safety
1299
       // Home XY for safety
1318
       feedrate = homing_feedrate[X_AXIS]/2;
1300
       feedrate = homing_feedrate[X_AXIS]/2;
1319
       destination[X_AXIS] = 0;
1301
       destination[X_AXIS] = 0;
1320
       destination[Y_AXIS] = 0;
1302
       destination[Y_AXIS] = 0;
1321
-      prepare_move_raw();
1303
+      prepare_move_raw(); // this will also set_current_to_destination
1322
       
1304
       
1323
       st_synchronize();
1305
       st_synchronize();
1324
 
1306
 
1352
   // Probe bed height at position (x,y), returns the measured z value
1334
   // Probe bed height at position (x,y), returns the measured z value
1353
   static float probe_pt(float x, float y, float z_before, ProbeAction retract_action=ProbeDeployAndStow, int verbose_level=1) {
1335
   static float probe_pt(float x, float y, float z_before, ProbeAction retract_action=ProbeDeployAndStow, int verbose_level=1) {
1354
     // move to right place
1336
     // move to right place
1355
-    do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1356
-    do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1337
+    do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before); // this also updates current_position
1338
+    do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]); // this also updates current_position
1357
 
1339
 
1358
     #if !defined(Z_PROBE_SLED) && !defined(Z_PROBE_ALLEN_KEY)
1340
     #if !defined(Z_PROBE_SLED) && !defined(Z_PROBE_ALLEN_KEY)
1359
       if (retract_action & ProbeDeploy) deploy_z_probe();
1341
       if (retract_action & ProbeDeploy) deploy_z_probe();
1364
 
1346
 
1365
     #if Z_RAISE_BETWEEN_PROBINGS > 0
1347
     #if Z_RAISE_BETWEEN_PROBINGS > 0
1366
       if (retract_action == ProbeStay) {
1348
       if (retract_action == ProbeStay) {
1367
-        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1349
+        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS); // this also updates current_position
1368
         st_synchronize();
1350
         st_synchronize();
1369
       }
1351
       }
1370
     #endif
1352
     #endif
1643
     }
1625
     }
1644
 
1626
 
1645
     if (dock) {
1627
     if (dock) {
1646
-      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]);
1628
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]); // this also updates current_position
1647
       digitalWrite(SERVO0_PIN, LOW); // turn off magnet
1629
       digitalWrite(SERVO0_PIN, LOW); // turn off magnet
1648
     } else {
1630
     } else {
1649
       float z_loc = current_position[Z_AXIS];
1631
       float z_loc = current_position[Z_AXIS];
1650
       if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING;
1632
       if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING;
1651
-      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
1633
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc); // this also updates current_position
1652
       digitalWrite(SERVO0_PIN, HIGH); // turn on magnet
1634
       digitalWrite(SERVO0_PIN, HIGH); // turn on magnet
1653
     }
1635
     }
1654
   }
1636
   }
1700
  * G4: Dwell S<seconds> or P<milliseconds>
1682
  * G4: Dwell S<seconds> or P<milliseconds>
1701
  */
1683
  */
1702
 inline void gcode_G4() {
1684
 inline void gcode_G4() {
1703
-  unsigned long codenum = 0;
1685
+  millis_t codenum = 0;
1704
 
1686
 
1705
   LCD_MESSAGEPGM(MSG_DWELL);
1687
   LCD_MESSAGEPGM(MSG_DWELL);
1706
 
1688
 
1709
 
1691
 
1710
   st_synchronize();
1692
   st_synchronize();
1711
   refresh_cmd_timeout();
1693
   refresh_cmd_timeout();
1712
-  codenum += previous_millis_cmd;  // keep track of when we started waiting
1694
+  codenum += previous_cmd_ms;  // keep track of when we started waiting
1713
   while (millis() < codenum) {
1695
   while (millis() < codenum) {
1714
     manage_heater();
1696
     manage_heater();
1715
     manage_inactivity();
1697
     manage_inactivity();
2096
       case MeshStart:
2078
       case MeshStart:
2097
         mbl.reset();
2079
         mbl.reset();
2098
         probe_point = 0;
2080
         probe_point = 0;
2099
-        enquecommands_P(PSTR("G28\nG29 S2"));
2081
+        enqueuecommands_P(PSTR("G28\nG29 S2"));
2100
         break;
2082
         break;
2101
 
2083
 
2102
       case MeshNext:
2084
       case MeshNext:
2135
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2117
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
2136
           probe_point = -1;
2118
           probe_point = -1;
2137
           mbl.active = 1;
2119
           mbl.active = 1;
2138
-          enquecommands_P(PSTR("G28"));
2120
+          enqueuecommands_P(PSTR("G28"));
2139
         }
2121
         }
2140
         break;
2122
         break;
2141
 
2123
 
2517
     #endif
2499
     #endif
2518
 
2500
 
2519
     #ifdef Z_PROBE_END_SCRIPT
2501
     #ifdef Z_PROBE_END_SCRIPT
2520
-      enquecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2502
+      enqueuecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2521
       st_synchronize();
2503
       st_synchronize();
2522
     #endif
2504
     #endif
2523
   }
2505
   }
2579
   inline void gcode_M0_M1() {
2561
   inline void gcode_M0_M1() {
2580
     char *src = strchr_pointer + 2;
2562
     char *src = strchr_pointer + 2;
2581
 
2563
 
2582
-    unsigned long codenum = 0;
2564
+    millis_t codenum = 0;
2583
     bool hasP = false, hasS = false;
2565
     bool hasP = false, hasS = false;
2584
     if (code_seen('P')) {
2566
     if (code_seen('P')) {
2585
       codenum = code_value_short(); // milliseconds to wait
2567
       codenum = code_value_short(); // milliseconds to wait
2605
     st_synchronize();
2587
     st_synchronize();
2606
     refresh_cmd_timeout();
2588
     refresh_cmd_timeout();
2607
     if (codenum > 0) {
2589
     if (codenum > 0) {
2608
-      codenum += previous_millis_cmd;  // keep track of when we started waiting
2590
+      codenum += previous_cmd_ms;  // keep track of when we started waiting
2609
       while(millis() < codenum && !lcd_clicked()) {
2591
       while(millis() < codenum && !lcd_clicked()) {
2610
         manage_heater();
2592
         manage_heater();
2611
         manage_inactivity();
2593
         manage_inactivity();
2747
  */
2729
  */
2748
 inline void gcode_M31() {
2730
 inline void gcode_M31() {
2749
   stoptime = millis();
2731
   stoptime = millis();
2750
-  unsigned long t = (stoptime - starttime) / 1000;
2732
+  millis_t t = (stoptime - starttime) / 1000;
2751
   int min = t / 60, sec = t % 60;
2733
   int min = t / 60, sec = t % 60;
2752
   char time[30];
2734
   char time[30];
2753
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
2735
   sprintf_P(time, PSTR("%i min, %i sec"), min, sec);
2980
     if (deploy_probe_for_each_reading) stow_z_probe();
2962
     if (deploy_probe_for_each_reading) stow_z_probe();
2981
 
2963
 
2982
     for (uint8_t n=0; n < n_samples; n++) {
2964
     for (uint8_t n=0; n < n_samples; n++) {
2983
-
2984
-      do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location
2965
+      // Make sure we are at the probe location
2966
+      do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // this also updates current_position
2985
 
2967
 
2986
       if (n_legs) {
2968
       if (n_legs) {
2987
-        unsigned long ms = millis();
2969
+        millis_t ms = millis();
2988
         double radius = ms % (X_MAX_LENGTH / 4),       // limit how far out to go
2970
         double radius = ms % (X_MAX_LENGTH / 4),       // limit how far out to go
2989
                theta = RADIANS(ms % 360L);
2971
                theta = RADIANS(ms % 360L);
2990
         float dir = (ms & 0x0001) ? 1 : -1;            // clockwise or counter clockwise
2972
         float dir = (ms & 0x0001) ? 1 : -1;            // clockwise or counter clockwise
3011
             SERIAL_EOL;
2993
             SERIAL_EOL;
3012
           }
2994
           }
3013
 
2995
 
3014
-          do_blocking_move_to(X_current, Y_current, Z_current);
2996
+          do_blocking_move_to(X_current, Y_current, Z_current); // this also updates current_position
3015
 
2997
 
3016
         } // n_legs loop
2998
         } // n_legs loop
3017
 
2999
 
3018
-        do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location
3000
+        // Go back to the probe location
3001
+        do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // this also updates current_position
3019
 
3002
 
3020
       } // n_legs
3003
       } // n_legs
3021
 
3004
 
3221
 
3204
 
3222
   setWatch();
3205
   setWatch();
3223
 
3206
 
3224
-  unsigned long timetemp = millis();
3207
+  millis_t temp_ms = millis();
3225
 
3208
 
3226
   /* See if we are heating up or cooling down */
3209
   /* See if we are heating up or cooling down */
3227
   target_direction = isHeatingHotend(target_extruder); // true if heating, false if cooling
3210
   target_direction = isHeatingHotend(target_extruder); // true if heating, false if cooling
3229
   cancel_heatup = false;
3212
   cancel_heatup = false;
3230
 
3213
 
3231
   #ifdef TEMP_RESIDENCY_TIME
3214
   #ifdef TEMP_RESIDENCY_TIME
3232
-    long residencyStart = -1;
3215
+    long residency_start_ms = -1;
3233
     /* continue to loop until we have reached the target temp
3216
     /* continue to loop until we have reached the target temp
3234
       _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
3217
       _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
3235
-    while((!cancel_heatup)&&((residencyStart == -1) ||
3236
-          (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL)))) )
3218
+    while((!cancel_heatup)&&((residency_start_ms == -1) ||
3219
+          (residency_start_ms >= 0 && (((unsigned int) (millis() - residency_start_ms)) < (TEMP_RESIDENCY_TIME * 1000UL)))) )
3237
   #else
3220
   #else
3238
     while ( target_direction ? (isHeatingHotend(target_extruder)) : (isCoolingHotend(target_extruder)&&(CooldownNoWait==false)) )
3221
     while ( target_direction ? (isHeatingHotend(target_extruder)) : (isCoolingHotend(target_extruder)&&(CooldownNoWait==false)) )
3239
   #endif //TEMP_RESIDENCY_TIME
3222
   #endif //TEMP_RESIDENCY_TIME
3240
 
3223
 
3241
     { // while loop
3224
     { // while loop
3242
-      if (millis() > timetemp + 1000UL) { //Print temp & remaining time every 1s while waiting
3225
+      if (millis() > temp_ms + 1000UL) { //Print temp & remaining time every 1s while waiting
3243
         SERIAL_PROTOCOLPGM("T:");
3226
         SERIAL_PROTOCOLPGM("T:");
3244
         SERIAL_PROTOCOL_F(degHotend(target_extruder),1);
3227
         SERIAL_PROTOCOL_F(degHotend(target_extruder),1);
3245
         SERIAL_PROTOCOLPGM(" E:");
3228
         SERIAL_PROTOCOLPGM(" E:");
3246
         SERIAL_PROTOCOL((int)target_extruder);
3229
         SERIAL_PROTOCOL((int)target_extruder);
3247
         #ifdef TEMP_RESIDENCY_TIME
3230
         #ifdef TEMP_RESIDENCY_TIME
3248
           SERIAL_PROTOCOLPGM(" W:");
3231
           SERIAL_PROTOCOLPGM(" W:");
3249
-          if (residencyStart > -1) {
3250
-            timetemp = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residencyStart)) / 1000UL;
3251
-            SERIAL_PROTOCOLLN( timetemp );
3232
+          if (residency_start_ms > -1) {
3233
+            temp_ms = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residency_start_ms)) / 1000UL;
3234
+            SERIAL_PROTOCOLLN(temp_ms);
3252
           }
3235
           }
3253
           else {
3236
           else {
3254
             SERIAL_PROTOCOLLNPGM("?");
3237
             SERIAL_PROTOCOLLNPGM("?");
3256
         #else
3239
         #else
3257
           SERIAL_EOL;
3240
           SERIAL_EOL;
3258
         #endif
3241
         #endif
3259
-        timetemp = millis();
3242
+        temp_ms = millis();
3260
       }
3243
       }
3261
       manage_heater();
3244
       manage_heater();
3262
       manage_inactivity();
3245
       manage_inactivity();
3264
       #ifdef TEMP_RESIDENCY_TIME
3247
       #ifdef TEMP_RESIDENCY_TIME
3265
         // start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
3248
         // start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
3266
         // or when current temp falls outside the hysteresis after target temp was reached
3249
         // or when current temp falls outside the hysteresis after target temp was reached
3267
-        if ((residencyStart == -1 &&  target_direction && (degHotend(target_extruder) >= (degTargetHotend(target_extruder)-TEMP_WINDOW))) ||
3268
-            (residencyStart == -1 && !target_direction && (degHotend(target_extruder) <= (degTargetHotend(target_extruder)+TEMP_WINDOW))) ||
3269
-            (residencyStart > -1 && labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > TEMP_HYSTERESIS) )
3250
+        if ((residency_start_ms == -1 &&  target_direction && (degHotend(target_extruder) >= (degTargetHotend(target_extruder)-TEMP_WINDOW))) ||
3251
+            (residency_start_ms == -1 && !target_direction && (degHotend(target_extruder) <= (degTargetHotend(target_extruder)+TEMP_WINDOW))) ||
3252
+            (residency_start_ms > -1 && labs(degHotend(target_extruder) - degTargetHotend(target_extruder)) > TEMP_HYSTERESIS) )
3270
         {
3253
         {
3271
-          residencyStart = millis();
3254
+          residency_start_ms = millis();
3272
         }
3255
         }
3273
       #endif //TEMP_RESIDENCY_TIME
3256
       #endif //TEMP_RESIDENCY_TIME
3274
     }
3257
     }
3275
 
3258
 
3276
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
3259
   LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
3277
   refresh_cmd_timeout();
3260
   refresh_cmd_timeout();
3278
-  starttime = previous_millis_cmd;
3261
+  starttime = previous_cmd_ms;
3279
 }
3262
 }
3280
 
3263
 
3281
 #if HAS_TEMP_BED
3264
 #if HAS_TEMP_BED
3290
     if (CooldownNoWait || code_seen('R'))
3273
     if (CooldownNoWait || code_seen('R'))
3291
       setTargetBed(code_value());
3274
       setTargetBed(code_value());
3292
 
3275
 
3293
-    unsigned long timetemp = millis();
3276
+    millis_t temp_ms = millis();
3294
     
3277
     
3295
     cancel_heatup = false;
3278
     cancel_heatup = false;
3296
     target_direction = isHeatingBed(); // true if heating, false if cooling
3279
     target_direction = isHeatingBed(); // true if heating, false if cooling
3297
 
3280
 
3298
     while ( (target_direction)&&(!cancel_heatup) ? (isHeatingBed()) : (isCoolingBed()&&(CooldownNoWait==false)) ) {
3281
     while ( (target_direction)&&(!cancel_heatup) ? (isHeatingBed()) : (isCoolingBed()&&(CooldownNoWait==false)) ) {
3299
-      unsigned long ms = millis();
3300
-      if (ms > timetemp + 1000UL) { //Print Temp Reading every 1 second while heating up.
3301
-        timetemp = ms;
3282
+      millis_t ms = millis();
3283
+      if (ms > temp_ms + 1000UL) { //Print Temp Reading every 1 second while heating up.
3284
+        temp_ms = ms;
3302
         float tt = degHotend(active_extruder);
3285
         float tt = degHotend(active_extruder);
3303
         SERIAL_PROTOCOLPGM("T:");
3286
         SERIAL_PROTOCOLPGM("T:");
3304
         SERIAL_PROTOCOL(tt);
3287
         SERIAL_PROTOCOL(tt);
3974
 
3957
 
3975
 #endif // NUM_SERVOS > 0
3958
 #endif // NUM_SERVOS > 0
3976
 
3959
 
3977
-#if defined(LARGE_FLASH) && (BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))
3960
+#if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
3978
 
3961
 
3979
   /**
3962
   /**
3980
    * M300: Play beep sound S<frequency Hz> P<duration ms>
3963
    * M300: Play beep sound S<frequency Hz> P<duration ms>
3981
    */
3964
    */
3982
   inline void gcode_M300() {
3965
   inline void gcode_M300() {
3983
-    int beepS = code_seen('S') ? code_value() : 110;
3984
-    int beepP = code_seen('P') ? code_value() : 1000;
3966
+    uint16_t beepS = code_seen('S') ? code_value_short() : 110;
3967
+    uint32_t beepP = code_seen('P') ? code_value_long() : 1000;
3985
     if (beepS > 0) {
3968
     if (beepS > 0) {
3986
       #if BEEPER > 0
3969
       #if BEEPER > 0
3987
         tone(BEEPER, beepS);
3970
         tone(BEEPER, beepS);
3998
     }
3981
     }
3999
   }
3982
   }
4000
 
3983
 
4001
-#endif // LARGE_FLASH && (BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER)
3984
+#endif // BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER
4002
 
3985
 
4003
 #ifdef PIDTEMP
3986
 #ifdef PIDTEMP
4004
 
3987
 
4472
     LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
4455
     LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
4473
     uint8_t cnt = 0;
4456
     uint8_t cnt = 0;
4474
     while (!lcd_clicked()) {
4457
     while (!lcd_clicked()) {
4475
-      cnt++;
4458
+      if (++cnt == 0) lcd_quick_feedback(); // every 256th frame till the lcd is clicked
4476
       manage_heater();
4459
       manage_heater();
4477
       manage_inactivity(true);
4460
       manage_inactivity(true);
4478
       lcd_update();
4461
       lcd_update();
4479
-      if (cnt == 0) {
4480
-        #if BEEPER > 0
4481
-          OUT_WRITE(BEEPER,HIGH);
4482
-          delay(3);
4483
-          WRITE(BEEPER,LOW);
4484
-          delay(3);
4485
-        #else
4486
-          #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS)
4487
-            lcd_buzz(1000/6, 100);
4488
-          #else
4489
-            lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
4490
-          #endif
4491
-        #endif
4492
-      }
4493
     } // while(!lcd_clicked)
4462
     } // while(!lcd_clicked)
4494
 
4463
 
4495
     //return to normal
4464
     //return to normal
5078
           break;
5047
           break;
5079
       #endif // NUM_SERVOS > 0
5048
       #endif // NUM_SERVOS > 0
5080
 
5049
 
5081
-      #if defined(LARGE_FLASH) && (BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))
5050
+      #if BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER)
5082
         case 300: // M300 - Play beep tone
5051
         case 300: // M300 - Play beep tone
5083
           gcode_M300();
5052
           gcode_M300();
5084
           break;
5053
           break;
5085
-      #endif // LARGE_FLASH && (BEEPER>0 || ULTRALCD || LCD_USE_I2C_BUZZER)
5054
+      #endif // BEEPER > 0 || ULTRALCD || LCD_USE_I2C_BUZZER
5086
 
5055
 
5087
       #ifdef PIDTEMP
5056
       #ifdef PIDTEMP
5088
         case 301: // M301
5057
         case 301: // M301
5289
   offset[1] = code_seen('J') ? code_value() : 0;
5258
   offset[1] = code_seen('J') ? code_value() : 0;
5290
 }
5259
 }
5291
 
5260
 
5292
-void clamp_to_software_endstops(float target[3])
5293
-{
5261
+void clamp_to_software_endstops(float target[3]) {
5294
   if (min_software_endstops) {
5262
   if (min_software_endstops) {
5295
-    if (target[X_AXIS] < min_pos[X_AXIS]) target[X_AXIS] = min_pos[X_AXIS];
5296
-    if (target[Y_AXIS] < min_pos[Y_AXIS]) target[Y_AXIS] = min_pos[Y_AXIS];
5263
+    NOLESS(target[X_AXIS], min_pos[X_AXIS]);
5264
+    NOLESS(target[Y_AXIS], min_pos[Y_AXIS]);
5297
     
5265
     
5298
     float negative_z_offset = 0;
5266
     float negative_z_offset = 0;
5299
     #ifdef ENABLE_AUTO_BED_LEVELING
5267
     #ifdef ENABLE_AUTO_BED_LEVELING
5300
-      if (Z_PROBE_OFFSET_FROM_EXTRUDER < 0) negative_z_offset = negative_z_offset + Z_PROBE_OFFSET_FROM_EXTRUDER;
5301
-      if (home_offset[Z_AXIS] < 0) negative_z_offset = negative_z_offset + home_offset[Z_AXIS];
5268
+      if (Z_PROBE_OFFSET_FROM_EXTRUDER < 0) negative_z_offset += Z_PROBE_OFFSET_FROM_EXTRUDER;
5269
+      if (home_offset[Z_AXIS] < 0) negative_z_offset += home_offset[Z_AXIS];
5302
     #endif
5270
     #endif
5303
-    
5304
-    if (target[Z_AXIS] < min_pos[Z_AXIS]+negative_z_offset) target[Z_AXIS] = min_pos[Z_AXIS]+negative_z_offset;
5271
+    NOLESS(target[Z_AXIS], min_pos[Z_AXIS] + negative_z_offset);
5305
   }
5272
   }
5306
 
5273
 
5307
   if (max_software_endstops) {
5274
   if (max_software_endstops) {
5308
-    if (target[X_AXIS] > max_pos[X_AXIS]) target[X_AXIS] = max_pos[X_AXIS];
5309
-    if (target[Y_AXIS] > max_pos[Y_AXIS]) target[Y_AXIS] = max_pos[Y_AXIS];
5310
-    if (target[Z_AXIS] > max_pos[Z_AXIS]) target[Z_AXIS] = max_pos[Z_AXIS];
5275
+    NOMORE(target[X_AXIS], max_pos[X_AXIS]);
5276
+    NOMORE(target[Y_AXIS], max_pos[Y_AXIS]);
5277
+    NOMORE(target[Z_AXIS], max_pos[Z_AXIS]);
5311
   }
5278
   }
5312
 }
5279
 }
5313
 
5280
 
5522
       //SERIAL_ECHOPGM("delta[Y_AXIS]="); SERIAL_ECHOLN(delta[Y_AXIS]);
5489
       //SERIAL_ECHOPGM("delta[Y_AXIS]="); SERIAL_ECHOLN(delta[Y_AXIS]);
5523
       //SERIAL_ECHOPGM("delta[Z_AXIS]="); SERIAL_ECHOLN(delta[Z_AXIS]);
5490
       //SERIAL_ECHOPGM("delta[Z_AXIS]="); SERIAL_ECHOLN(delta[Z_AXIS]);
5524
 
5491
 
5525
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5492
+      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate/60*feedmultiply/100.0, active_extruder);
5526
     }
5493
     }
5527
 
5494
 
5528
   #endif // SCARA
5495
   #endif // SCARA
5549
       #ifdef ENABLE_AUTO_BED_LEVELING
5516
       #ifdef ENABLE_AUTO_BED_LEVELING
5550
         adjust_delta(destination);
5517
         adjust_delta(destination);
5551
       #endif
5518
       #endif
5552
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
5519
+      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], feedrate/60*feedmultiply/100.0, active_extruder);
5553
     }
5520
     }
5554
 
5521
 
5555
   #endif // DELTA
5522
   #endif // DELTA
5573
           // (so it can be used as the start of the next non-travel move)
5540
           // (so it can be used as the start of the next non-travel move)
5574
           if (delayed_move_time != 0xFFFFFFFFUL) {
5541
           if (delayed_move_time != 0xFFFFFFFFUL) {
5575
             set_current_to_destination();
5542
             set_current_to_destination();
5576
-            if (destination[Z_AXIS] > raised_parked_position[Z_AXIS]) raised_parked_position[Z_AXIS] = destination[Z_AXIS];
5543
+            NOLESS(raised_parked_position[Z_AXIS], destination[Z_AXIS]);
5577
             delayed_move_time = millis();
5544
             delayed_move_time = millis();
5578
             return;
5545
             return;
5579
           }
5546
           }
5621
 
5588
 
5622
 #if HAS_CONTROLLERFAN
5589
 #if HAS_CONTROLLERFAN
5623
 
5590
 
5624
-unsigned long lastMotor = 0; // Last time a motor was turned on
5625
-unsigned long lastMotorCheck = 0; // Last time the state was checked
5591
+millis_t lastMotor = 0; // Last time a motor was turned on
5592
+millis_t lastMotorCheck = 0; // Last time the state was checked
5626
 
5593
 
5627
 void controllerFan() {
5594
 void controllerFan() {
5628
-  uint32_t ms = millis();
5595
+  millis_t ms = millis();
5629
   if (ms >= lastMotorCheck + 2500) { // Not a time critical function, so we only check every 2500ms
5596
   if (ms >= lastMotorCheck + 2500) { // Not a time critical function, so we only check every 2500ms
5630
     lastMotorCheck = ms;
5597
     lastMotorCheck = ms;
5631
     if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
5598
     if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
5732
 #endif
5699
 #endif
5733
 
5700
 
5734
 #ifdef TEMP_STAT_LEDS
5701
 #ifdef TEMP_STAT_LEDS
5735
-static bool blue_led = false;
5736
-static bool red_led = false;
5737
-static uint32_t stat_update = 0;
5738
-
5739
-void handle_status_leds(void) {
5740
-  float max_temp = 0.0;
5741
-  if(millis() > stat_update) {
5742
-    stat_update += 500; // Update every 0.5s
5743
-    for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder) {
5744
-       max_temp = max(max_temp, degHotend(cur_extruder));
5745
-       max_temp = max(max_temp, degTargetHotend(cur_extruder));
5746
-    }
5747
-    #if HAS_TEMP_BED
5748
-      max_temp = max(max_temp, degTargetBed());
5749
-      max_temp = max(max_temp, degBed());
5750
-    #endif
5751
-    if((max_temp > 55.0) && (red_led == false)) {
5752
-      digitalWrite(STAT_LED_RED, 1);
5753
-      digitalWrite(STAT_LED_BLUE, 0);
5754
-      red_led = true;
5755
-      blue_led = false;
5756
-    }
5757
-    if((max_temp < 54.0) && (blue_led == false)) {
5758
-      digitalWrite(STAT_LED_RED, 0);
5759
-      digitalWrite(STAT_LED_BLUE, 1);
5760
-      red_led = false;
5761
-      blue_led = true;
5702
+
5703
+  static bool red_led = false;
5704
+  static millis_t next_status_led_update_ms = 0;
5705
+
5706
+  void handle_status_leds(void) {
5707
+    float max_temp = 0.0;
5708
+    if (millis() > next_status_led_update_ms) {
5709
+      next_status_led_update_ms += 500; // Update every 0.5s
5710
+      for (int8_t cur_extruder = 0; cur_extruder < EXTRUDERS; ++cur_extruder)
5711
+         max_temp = max(max(max_temp, degHotend(cur_extruder)), degTargetHotend(cur_extruder));
5712
+      #if HAS_TEMP_BED
5713
+        max_temp = max(max(max_temp, degTargetBed()), degBed());
5714
+      #endif
5715
+      bool new_led = (max_temp > 55.0) ? true : (max_temp < 54.0) ? false : red_led;
5716
+      if (new_led != red_led) {
5717
+        red_led = new_led;
5718
+        digitalWrite(STAT_LED_RED, new_led ? HIGH : LOW);
5719
+        digitalWrite(STAT_LED_BLUE, new_led ? LOW : HIGH);
5720
+      }
5762
     }
5721
     }
5763
   }
5722
   }
5764
-}
5723
+
5765
 #endif
5724
 #endif
5766
 
5725
 
5767
 void enable_all_steppers() {
5726
 void enable_all_steppers() {
5805
 
5764
 
5806
   if (buflen < BUFSIZE - 1) get_command();
5765
   if (buflen < BUFSIZE - 1) get_command();
5807
 
5766
 
5808
-  unsigned long ms = millis();
5767
+  millis_t ms = millis();
5809
 
5768
 
5810
-  if (max_inactive_time && ms > previous_millis_cmd + max_inactive_time) kill();
5769
+  if (max_inactive_time && ms > previous_cmd_ms + max_inactive_time) kill();
5811
 
5770
 
5812
-  if (stepper_inactive_time && ms > previous_millis_cmd + stepper_inactive_time
5771
+  if (stepper_inactive_time && ms > previous_cmd_ms + stepper_inactive_time
5813
       && !ignore_stepper_queue && !blocks_queued())
5772
       && !ignore_stepper_queue && !blocks_queued())
5814
     disable_all_steppers();
5773
     disable_all_steppers();
5815
 
5774
 
5845
     const int HOME_DEBOUNCE_DELAY = 750;
5804
     const int HOME_DEBOUNCE_DELAY = 750;
5846
     if (!READ(HOME_PIN)) {
5805
     if (!READ(HOME_PIN)) {
5847
       if (!homeDebounceCount) {
5806
       if (!homeDebounceCount) {
5848
-        enquecommands_P(PSTR("G28"));
5807
+        enqueuecommands_P(PSTR("G28"));
5849
         LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
5808
         LCD_ALERTMESSAGEPGM(MSG_AUTO_HOME);
5850
       }
5809
       }
5851
       if (homeDebounceCount < HOME_DEBOUNCE_DELAY)
5810
       if (homeDebounceCount < HOME_DEBOUNCE_DELAY)
5860
   #endif
5819
   #endif
5861
 
5820
 
5862
   #ifdef EXTRUDER_RUNOUT_PREVENT
5821
   #ifdef EXTRUDER_RUNOUT_PREVENT
5863
-    if (ms > previous_millis_cmd + EXTRUDER_RUNOUT_SECONDS * 1000)
5822
+    if (ms > previous_cmd_ms + EXTRUDER_RUNOUT_SECONDS * 1000)
5864
     if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
5823
     if (degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) {
5865
       bool oldstatus;
5824
       bool oldstatus;
5866
       switch(active_extruder) {
5825
       switch(active_extruder) {
5894
       current_position[E_AXIS] = oldepos;
5853
       current_position[E_AXIS] = oldepos;
5895
       destination[E_AXIS] = oldedes;
5854
       destination[E_AXIS] = oldedes;
5896
       plan_set_e_position(oldepos);
5855
       plan_set_e_position(oldepos);
5897
-      previous_millis_cmd = ms; // refresh_cmd_timeout()
5856
+      previous_cmd_ms = ms; // refresh_cmd_timeout()
5898
       st_synchronize();
5857
       st_synchronize();
5899
       switch(active_extruder) {
5858
       switch(active_extruder) {
5900
         case 0:
5859
         case 0:
5964
    {
5923
    {
5965
       if filrunoutEnqued == false {
5924
       if filrunoutEnqued == false {
5966
          filrunoutEnqued = true;
5925
          filrunoutEnqued = true;
5967
-         enquecommand("M600");
5926
+         enqueuecommand("M600");
5968
       }
5927
       }
5969
    }
5928
    }
5970
 #endif
5929
 #endif

+ 5
- 5
Marlin/cardreader.cpp View File

25
     OUT_WRITE(SDPOWER, HIGH);
25
     OUT_WRITE(SDPOWER, HIGH);
26
   #endif //SDPOWER
26
   #endif //SDPOWER
27
 
27
 
28
-  autostart_atmillis = millis() + 5000;
28
+  next_autostart_ms = millis() + 5000;
29
 }
29
 }
30
 
30
 
31
 char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
31
 char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
397
 }
397
 }
398
 
398
 
399
 void CardReader::checkautostart(bool force) {
399
 void CardReader::checkautostart(bool force) {
400
-  if (!force && (!autostart_stilltocheck || autostart_atmillis < millis()))
400
+  if (!force && (!autostart_stilltocheck || next_autostart_ms < millis()))
401
     return;
401
     return;
402
 
402
 
403
   autostart_stilltocheck = false;
403
   autostart_stilltocheck = false;
421
     if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
421
     if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
422
       char cmd[30];
422
       char cmd[30];
423
       sprintf_P(cmd, PSTR("M23 %s"), autoname);
423
       sprintf_P(cmd, PSTR("M23 %s"), autoname);
424
-      enquecommand(cmd);
425
-      enquecommands_P(PSTR("M24"));
424
+      enqueuecommand(cmd);
425
+      enqueuecommands_P(PSTR("M24"));
426
       found = true;
426
       found = true;
427
     }
427
     }
428
   }
428
   }
508
     sdprinting = false;
508
     sdprinting = false;
509
     if (SD_FINISHED_STEPPERRELEASE) {
509
     if (SD_FINISHED_STEPPERRELEASE) {
510
       //finishAndDisableSteppers();
510
       //finishAndDisableSteppers();
511
-      enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
511
+      enqueuecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
512
     }
512
     }
513
     autotempShutdown();
513
     autotempShutdown();
514
   }
514
   }

+ 1
- 1
Marlin/cardreader.h View File

62
   uint32_t filespos[SD_PROCEDURE_DEPTH];
62
   uint32_t filespos[SD_PROCEDURE_DEPTH];
63
   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
63
   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
64
   uint32_t filesize;
64
   uint32_t filesize;
65
-  unsigned long autostart_atmillis;
65
+  millis_t next_autostart_ms;
66
   uint32_t sdpos;
66
   uint32_t sdpos;
67
 
67
 
68
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
68
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

350
   #ifndef FILAMENT_LCD_DISPLAY
350
   #ifndef FILAMENT_LCD_DISPLAY
351
     lcd_print(lcd_status_message);
351
     lcd_print(lcd_status_message);
352
   #else
352
   #else
353
-    if (millis() < message_millis + 5000) {  //Display both Status message line and Filament display on the last line
353
+    if (millis() < previous_lcd_status_ms + 5000) {  //Display both Status message line and Filament display on the last line
354
       lcd_print(lcd_status_message);
354
       lcd_print(lcd_status_message);
355
     }
355
     }
356
     else {
356
     else {

+ 1
- 3
Marlin/example_configurations/Hephestos/Configuration.h View File

58
 
58
 
59
 // The following define selects which electronics board you have.
59
 // The following define selects which electronics board you have.
60
 // Please choose the name from boards.h that matches your setup
60
 // Please choose the name from boards.h that matches your setup
61
-#ifndef MOTHERBOARD
62
-  #define MOTHERBOARD BOARD_HEPHESTOS
63
-#endif
61
+#define MOTHERBOARD BOARD_HEPHESTOS
64
 
62
 
65
 // Optional custom name for your RepStrap or other custom machine
63
 // Optional custom name for your RepStrap or other custom machine
66
 // Displayed in the LCD "Ready" message
64
 // Displayed in the LCD "Ready" message

+ 1
- 3
Marlin/example_configurations/WITBOX/Configuration.h View File

58
 
58
 
59
 // The following define selects which electronics board you have.
59
 // The following define selects which electronics board you have.
60
 // Please choose the name from boards.h that matches your setup
60
 // Please choose the name from boards.h that matches your setup
61
-#ifndef MOTHERBOARD
62
-  #define MOTHERBOARD BOARD_WITBOX
63
-#endif
61
+#define MOTHERBOARD BOARD_WITBOX
64
 
62
 
65
 // Optional custom name for your RepStrap or other custom machine
63
 // Optional custom name for your RepStrap or other custom machine
66
 // Displayed in the LCD "Ready" message
64
 // Displayed in the LCD "Ready" message

+ 14
- 12
Marlin/planner.cpp View File

60
 
60
 
61
 #ifdef MESH_BED_LEVELING
61
 #ifdef MESH_BED_LEVELING
62
   #include "mesh_bed_leveling.h"
62
   #include "mesh_bed_leveling.h"
63
-#endif  // MESH_BED_LEVELING
63
+#endif
64
 
64
 
65
 //===========================================================================
65
 //===========================================================================
66
 //============================= public variables ============================
66
 //============================= public variables ============================
67
 //===========================================================================
67
 //===========================================================================
68
 
68
 
69
-unsigned long minsegmenttime;
69
+millis_t minsegmenttime;
70
 float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
70
 float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
71
 float axis_steps_per_unit[NUM_AXIS];
71
 float axis_steps_per_unit[NUM_AXIS];
72
 unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
72
 unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
159
   unsigned long final_rate = ceil(block->nominal_rate * exit_factor); // (step/min)
159
   unsigned long final_rate = ceil(block->nominal_rate * exit_factor); // (step/min)
160
 
160
 
161
   // Limit minimal step rate (Otherwise the timer will overflow.)
161
   // Limit minimal step rate (Otherwise the timer will overflow.)
162
-  if (initial_rate < 120) initial_rate = 120;
163
-  if (final_rate < 120) final_rate = 120;
162
+  NOLESS(initial_rate, 120);
163
+  NOLESS(final_rate, 120);
164
 
164
 
165
   long acceleration = block->acceleration_st;
165
   long acceleration = block->acceleration_st;
166
   int32_t accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, acceleration));
166
   int32_t accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, acceleration));
382
     }
382
     }
383
 
383
 
384
     float t = autotemp_min + high * autotemp_factor;
384
     float t = autotemp_min + high * autotemp_factor;
385
-    if (t < autotemp_min) t = autotemp_min;
386
-    if (t > autotemp_max) t = autotemp_max;
387
-    if (oldt > t) t = AUTOTEMP_OLDWEIGHT * oldt + (1 - AUTOTEMP_OLDWEIGHT) * t;
385
+    t = constrain(t, autotemp_min, autotemp_max);
386
+    if (oldt > t) {
387
+      t *= (1 - AUTOTEMP_OLDWEIGHT);
388
+      t += AUTOTEMP_OLDWEIGHT * oldt;
389
+    }
388
     oldt = t;
390
     oldt = t;
389
     setTargetHotend0(t);
391
     setTargetHotend0(t);
390
   }
392
   }
426
 
428
 
427
   #if HAS_FAN
429
   #if HAS_FAN
428
     #ifdef FAN_KICKSTART_TIME
430
     #ifdef FAN_KICKSTART_TIME
429
-      static unsigned long fan_kick_end;
431
+      static millis_t fan_kick_end;
430
       if (tail_fan_speed) {
432
       if (tail_fan_speed) {
431
         if (fan_kick_end == 0) {
433
         if (fan_kick_end == 0) {
432
           // Just starting up fan - run at full power.
434
           // Just starting up fan - run at full power.
651
     }
653
     }
652
   }
654
   }
653
 
655
 
654
-  if (block->steps[E_AXIS]) {
655
-    if (feed_rate < minimumfeedrate) feed_rate = minimumfeedrate;
656
-  }
657
-  else if (feed_rate < mintravelfeedrate) feed_rate = mintravelfeedrate;
656
+  if (block->steps[E_AXIS])
657
+    NOLESS(feed_rate, minimumfeedrate);
658
+  else
659
+    NOLESS(feed_rate, mintravelfeedrate);
658
 
660
 
659
   /**
661
   /**
660
    * This part of the code calculates the total length of the movement. 
662
    * This part of the code calculates the total length of the movement. 

+ 1
- 1
Marlin/planner.h View File

115
 
115
 
116
 void plan_set_e_position(const float &e);
116
 void plan_set_e_position(const float &e);
117
 
117
 
118
-extern unsigned long minsegmenttime;
118
+extern millis_t minsegmenttime;
119
 extern float max_feedrate[NUM_AXIS]; // set the max speeds
119
 extern float max_feedrate[NUM_AXIS]; // set the max speeds
120
 extern float axis_steps_per_unit[NUM_AXIS];
120
 extern float axis_steps_per_unit[NUM_AXIS];
121
 extern unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
121
 extern unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software

+ 3
- 3
Marlin/stepper.cpp View File

400
     current_block = NULL;
400
     current_block = NULL;
401
     plan_discard_current_block();
401
     plan_discard_current_block();
402
     #ifdef SD_FINISHED_RELEASECOMMAND
402
     #ifdef SD_FINISHED_RELEASECOMMAND
403
-      if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enquecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
403
+      if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueuecommands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
404
     #endif
404
     #endif
405
     cleaning_buffer_counter--;
405
     cleaning_buffer_counter--;
406
     OCR1A = 200;
406
     OCR1A = 200;
718
     // Calculate new timer value
718
     // Calculate new timer value
719
     unsigned short timer;
719
     unsigned short timer;
720
     unsigned short step_rate;
720
     unsigned short step_rate;
721
-    if (step_events_completed <= (unsigned long int)current_block->accelerate_until) {
721
+    if (step_events_completed <= (unsigned long)current_block->accelerate_until) {
722
 
722
 
723
       MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
723
       MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
724
       acc_step_rate += current_block->initial_rate;
724
       acc_step_rate += current_block->initial_rate;
742
 
742
 
743
       #endif
743
       #endif
744
     }
744
     }
745
-    else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
745
+    else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
746
       MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
746
       MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
747
 
747
 
748
       if (step_rate > acc_step_rate) { // Check step_rate stays positive
748
       if (step_rate > acc_step_rate) { // Check step_rate stays positive

+ 24
- 24
Marlin/temperature.cpp View File

77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
77
 #define HAS_BED_THERMAL_PROTECTION (defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 && TEMP_SENSOR_BED != 0)
78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
78
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
79
   enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
79
   enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
80
-  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
80
+  void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
81
   #if HAS_HEATER_THERMAL_PROTECTION
81
   #if HAS_HEATER_THERMAL_PROTECTION
82
     static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
82
     static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
83
-    static unsigned long thermal_runaway_timer[4]; // = {0,0,0,0};
83
+    static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
84
   #endif
84
   #endif
85
   #if HAS_BED_THERMAL_PROTECTION
85
   #if HAS_BED_THERMAL_PROTECTION
86
     static TRState thermal_runaway_bed_state_machine = TRReset;
86
     static TRState thermal_runaway_bed_state_machine = TRReset;
87
-    static unsigned long thermal_runaway_bed_timer;
87
+    static millis_t thermal_runaway_bed_timer;
88
   #endif
88
   #endif
89
 #endif
89
 #endif
90
 
90
 
118
   static float temp_iState_min_bed;
118
   static float temp_iState_min_bed;
119
   static float temp_iState_max_bed;
119
   static float temp_iState_max_bed;
120
 #else //PIDTEMPBED
120
 #else //PIDTEMPBED
121
-  static unsigned long  previous_millis_bed_heater;
121
+  static millis_t  previous_bed_check_ms;
122
 #endif //PIDTEMPBED
122
 #endif //PIDTEMPBED
123
   static unsigned char soft_pwm[EXTRUDERS];
123
   static unsigned char soft_pwm[EXTRUDERS];
124
 
124
 
126
   static unsigned char soft_pwm_fan;
126
   static unsigned char soft_pwm_fan;
127
 #endif
127
 #endif
128
 #if HAS_AUTO_FAN
128
 #if HAS_AUTO_FAN
129
-  static unsigned long extruder_autofan_last_check;
129
+  static millis_t previous_auto_fan_check_ms;
130
 #endif  
130
 #endif  
131
 
131
 
132
 #ifdef PIDTEMP
132
 #ifdef PIDTEMP
171
 
171
 
172
 #ifdef WATCH_TEMP_PERIOD
172
 #ifdef WATCH_TEMP_PERIOD
173
   int watch_start_temp[EXTRUDERS] = { 0 };
173
   int watch_start_temp[EXTRUDERS] = { 0 };
174
-  unsigned long watchmillis[EXTRUDERS] = { 0 };
174
+  millis_t watchmillis[EXTRUDERS] = { 0 };
175
 #endif //WATCH_TEMP_PERIOD
175
 #endif //WATCH_TEMP_PERIOD
176
 
176
 
177
 #ifndef SOFT_PWM_SCALE
177
 #ifndef SOFT_PWM_SCALE
196
   int cycles = 0;
196
   int cycles = 0;
197
   bool heating = true;
197
   bool heating = true;
198
 
198
 
199
-  unsigned long temp_millis = millis(), t1 = temp_millis, t2 = temp_millis;
199
+  millis_t temp_ms = millis(), t1 = temp_ms, t2 = temp_ms;
200
   long t_high = 0, t_low = 0;
200
   long t_high = 0, t_low = 0;
201
 
201
 
202
   long bias, d;
202
   long bias, d;
205
   float max = 0, min = 10000;
205
   float max = 0, min = 10000;
206
 
206
 
207
   #if HAS_AUTO_FAN
207
   #if HAS_AUTO_FAN
208
-        unsigned long extruder_autofan_last_check = temp_millis;
208
+    millis_t previous_auto_fan_check_ms = temp_ms;
209
   #endif
209
   #endif
210
 
210
 
211
   if (extruder >= EXTRUDERS
211
   if (extruder >= EXTRUDERS
229
   // PID Tuning loop
229
   // PID Tuning loop
230
   for (;;) {
230
   for (;;) {
231
 
231
 
232
-    unsigned long ms = millis();
232
+    millis_t ms = millis();
233
 
233
 
234
     if (temp_meas_ready) { // temp sample ready
234
     if (temp_meas_ready) { // temp sample ready
235
       updateTemperaturesFromRawValues();
235
       updateTemperaturesFromRawValues();
240
       min = min(min, input);
240
       min = min(min, input);
241
 
241
 
242
       #if HAS_AUTO_FAN
242
       #if HAS_AUTO_FAN
243
-        if (ms > extruder_autofan_last_check + 2500) {
243
+        if (ms > previous_auto_fan_check_ms + 2500) {
244
           checkExtruderAutoFans();
244
           checkExtruderAutoFans();
245
-          extruder_autofan_last_check = ms;
245
+          previous_auto_fan_check_ms = ms;
246
         }
246
         }
247
       #endif
247
       #endif
248
 
248
 
317
       return;
317
       return;
318
     }
318
     }
319
     // Every 2 seconds...
319
     // Every 2 seconds...
320
-    if (ms > temp_millis + 2000) {
320
+    if (ms > temp_ms + 2000) {
321
       int p;
321
       int p;
322
       if (extruder < 0) {
322
       if (extruder < 0) {
323
         p = soft_pwm_bed;
323
         p = soft_pwm_bed;
332
       SERIAL_PROTOCOLPGM(MSG_AT);
332
       SERIAL_PROTOCOLPGM(MSG_AT);
333
       SERIAL_PROTOCOLLN(p);
333
       SERIAL_PROTOCOLLN(p);
334
 
334
 
335
-      temp_millis = ms;
335
+      temp_ms = ms;
336
     } // every 2 seconds
336
     } // every 2 seconds
337
     // Over 2 minutes?
337
     // Over 2 minutes?
338
     if (((ms - t1) + (ms - t2)) > (10L*60L*1000L*2L)) {
338
     if (((ms - t1) + (ms - t2)) > (10L*60L*1000L*2L)) {
592
   #endif //HEATER_0_USES_MAX6675
592
   #endif //HEATER_0_USES_MAX6675
593
 
593
 
594
   #if defined(WATCH_TEMP_PERIOD) || !defined(PIDTEMPBED) || HAS_AUTO_FAN
594
   #if defined(WATCH_TEMP_PERIOD) || !defined(PIDTEMPBED) || HAS_AUTO_FAN
595
-    unsigned long ms = millis();
595
+    millis_t ms = millis();
596
   #endif
596
   #endif
597
 
597
 
598
   // Loop through all extruders
598
   // Loop through all extruders
631
   } // Extruders Loop
631
   } // Extruders Loop
632
 
632
 
633
   #if HAS_AUTO_FAN
633
   #if HAS_AUTO_FAN
634
-    if (ms > extruder_autofan_last_check + 2500) { // only need to check fan state very infrequently
634
+    if (ms > previous_auto_fan_check_ms + 2500) { // only need to check fan state very infrequently
635
       checkExtruderAutoFans();
635
       checkExtruderAutoFans();
636
-      extruder_autofan_last_check = ms;
636
+      previous_auto_fan_check_ms = ms;
637
     }
637
     }
638
   #endif       
638
   #endif       
639
   
639
   
640
   #ifndef PIDTEMPBED
640
   #ifndef PIDTEMPBED
641
-    if (ms < previous_millis_bed_heater + BED_CHECK_INTERVAL) return;
642
-    previous_millis_bed_heater = ms;
641
+    if (ms < previous_bed_check_ms + BED_CHECK_INTERVAL) return;
642
+    previous_bed_check_ms = ms;
643
   #endif //PIDTEMPBED
643
   #endif //PIDTEMPBED
644
 
644
 
645
   #if TEMP_SENSOR_BED != 0
645
   #if TEMP_SENSOR_BED != 0
992
 
992
 
993
 void setWatch() {
993
 void setWatch() {
994
   #ifdef WATCH_TEMP_PERIOD
994
   #ifdef WATCH_TEMP_PERIOD
995
-    unsigned long ms = millis();
995
+    millis_t ms = millis();
996
     for (int e = 0; e < EXTRUDERS; e++) {
996
     for (int e = 0; e < EXTRUDERS; e++) {
997
       if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) {
997
       if (degHotend(e) < degTargetHotend(e) - (WATCH_TEMP_INCREASE * 2)) {
998
         watch_start_temp[e] = degHotend(e);
998
         watch_start_temp[e] = degHotend(e);
1004
 
1004
 
1005
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1005
 #if HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
1006
 
1006
 
1007
-  void thermal_runaway_protection(TRState *state, unsigned long *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1007
+  void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
1008
 
1008
 
1009
     static float tr_target_temperature[EXTRUDERS+1] = { 0.0 };
1009
     static float tr_target_temperature[EXTRUDERS+1] = { 0.0 };
1010
 
1010
 
1109
 
1109
 
1110
 #ifdef HEATER_0_USES_MAX6675
1110
 #ifdef HEATER_0_USES_MAX6675
1111
   #define MAX6675_HEAT_INTERVAL 250u
1111
   #define MAX6675_HEAT_INTERVAL 250u
1112
-  unsigned long max6675_previous_millis = MAX6675_HEAT_INTERVAL;
1112
+  millis_t previous_max6675_ms = MAX6675_HEAT_INTERVAL;
1113
   int max6675_temp = 2000;
1113
   int max6675_temp = 2000;
1114
 
1114
 
1115
   static int read_max6675() {
1115
   static int read_max6675() {
1116
 
1116
 
1117
-    unsigned long ms = millis();
1118
-    if (ms < max6675_previous_millis + MAX6675_HEAT_INTERVAL)
1117
+    millis_t ms = millis();
1118
+    if (ms < previous_max6675_ms + MAX6675_HEAT_INTERVAL)
1119
       return max6675_temp;
1119
       return max6675_temp;
1120
     
1120
     
1121
-    max6675_previous_millis = ms;
1121
+    previous_max6675_ms = ms;
1122
     max6675_temp = 0;
1122
     max6675_temp = 0;
1123
 
1123
 
1124
     #ifdef PRR
1124
     #ifdef PRR

+ 39
- 34
Marlin/ultralcd.cpp View File

22
 int absPreheatFanSpeed;
22
 int absPreheatFanSpeed;
23
 
23
 
24
 #ifdef FILAMENT_LCD_DISPLAY
24
 #ifdef FILAMENT_LCD_DISPLAY
25
-  unsigned long message_millis = 0;
25
+  millis_t previous_lcd_status_ms = 0;
26
 #endif
26
 #endif
27
 
27
 
28
 /* !Configuration settings */
28
 /* !Configuration settings */
77
     static void lcd_level_bed();
77
     static void lcd_level_bed();
78
   #endif
78
   #endif
79
 
79
 
80
-  static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
81
-
82
   /* Different types of actions that can be used in menu items. */
80
   /* Different types of actions that can be used in menu items. */
83
   static void menu_action_back(menuFunc_t data);
81
   static void menu_action_back(menuFunc_t data);
84
   static void menu_action_submenu(menuFunc_t data);
82
   static void menu_action_submenu(menuFunc_t data);
220
     volatile uint8_t slow_buttons; // Bits of the pressed buttons.
218
     volatile uint8_t slow_buttons; // Bits of the pressed buttons.
221
   #endif
219
   #endif
222
   uint8_t currentMenuViewOffset;              /* scroll offset in the current menu */
220
   uint8_t currentMenuViewOffset;              /* scroll offset in the current menu */
223
-  uint32_t blocking_enc;
221
+  millis_t next_button_update_ms;
224
   uint8_t lastEncoderBits;
222
   uint8_t lastEncoderBits;
225
   uint32_t encoderPosition;
223
   uint32_t encoderPosition;
226
   #if (SDCARDDETECT > 0)
224
   #if (SDCARDDETECT > 0)
230
 #endif // ULTIPANEL
228
 #endif // ULTIPANEL
231
 
229
 
232
 menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
230
 menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
233
-uint32_t lcd_next_update_millis;
231
+millis_t next_lcd_update_ms;
234
 uint8_t lcd_status_update_delay;
232
 uint8_t lcd_status_update_delay;
235
 bool ignore_click = false;
233
 bool ignore_click = false;
236
 bool wait_for_unclick;
234
 bool wait_for_unclick;
267
 	encoderRateMultiplierEnabled = false;
265
 	encoderRateMultiplierEnabled = false;
268
 
266
 
269
   #ifdef LCD_PROGRESS_BAR
267
   #ifdef LCD_PROGRESS_BAR
270
-    unsigned long ms = millis();
268
+    millis_t ms = millis();
271
     #ifndef PROGRESS_MSG_ONCE
269
     #ifndef PROGRESS_MSG_ONCE
272
       if (ms > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
270
       if (ms > progressBarTick + PROGRESS_BAR_MSG_TIME + PROGRESS_BAR_BAR_TIME) {
273
         progressBarTick = ms;
271
         progressBarTick = ms;
324
         #endif
322
         #endif
325
       );
323
       );
326
       #ifdef FILAMENT_LCD_DISPLAY
324
       #ifdef FILAMENT_LCD_DISPLAY
327
-        message_millis = millis();  // get status message to show up for a while
325
+        previous_lcd_status_ms = millis();  // get status message to show up for a while
328
       #endif
326
       #endif
329
     }
327
     }
330
 
328
 
433
   plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
431
   plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
434
 
432
 
435
   // Audio feedback
433
   // Audio feedback
436
-  enquecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
434
+  enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
437
   lcd_return_to_status();
435
   lcd_return_to_status();
438
 }
436
 }
439
 
437
 
1114
     lcd_move_y();
1112
     lcd_move_y();
1115
   }
1113
   }
1116
   static void reprapworld_keypad_move_home() {
1114
   static void reprapworld_keypad_move_home() {
1117
-    enquecommands_P((PSTR("G28"))); // move all axis home
1115
+    enqueuecommands_P((PSTR("G28"))); // move all axis home
1118
   }
1116
   }
1119
 #endif //REPRAPWORLD_KEYPAD
1117
 #endif //REPRAPWORLD_KEYPAD
1120
 
1118
 
1121
 /** End of menus **/
1119
 /** End of menus **/
1122
 
1120
 
1123
-static void lcd_quick_feedback() {
1121
+void lcd_quick_feedback() {
1124
   lcdDrawUpdate = 2;
1122
   lcdDrawUpdate = 2;
1125
-  blocking_enc = millis() + 500;
1123
+  next_button_update_ms = millis() + 500;
1126
     
1124
     
1127
   #ifdef LCD_USE_I2C_BUZZER
1125
   #ifdef LCD_USE_I2C_BUZZER
1128
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1126
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1140
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1138
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1141
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1139
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1142
     #endif
1140
     #endif
1143
-    const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2;
1144
-    int i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000;
1141
+    const uint16_t delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2;
1142
+    uint16_t i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000;
1145
     while (i--) {
1143
     while (i--) {
1146
       WRITE(BEEPER,HIGH);
1144
       WRITE(BEEPER,HIGH);
1147
       delayMicroseconds(delay);
1145
       delayMicroseconds(delay);
1148
       WRITE(BEEPER,LOW);
1146
       WRITE(BEEPER,LOW);
1149
       delayMicroseconds(delay);
1147
       delayMicroseconds(delay);
1150
     }
1148
     }
1151
-    const int j = max(10000 - LCD_FEEDBACK_FREQUENCY_DURATION_MS * 1000, 0);
1149
+    const uint16_t j = max(10000 - LCD_FEEDBACK_FREQUENCY_DURATION_MS * 1000, 0);
1152
     if (j) delayMicroseconds(j);
1150
     if (j) delayMicroseconds(j);
1153
   #endif
1151
   #endif
1154
 }
1152
 }
1156
 /** Menu action functions **/
1154
 /** Menu action functions **/
1157
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1155
 static void menu_action_back(menuFunc_t data) { lcd_goto_menu(data); }
1158
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1156
 static void menu_action_submenu(menuFunc_t data) { lcd_goto_menu(data); }
1159
-static void menu_action_gcode(const char* pgcode) { enquecommands_P(pgcode); }
1157
+static void menu_action_gcode(const char* pgcode) { enqueuecommands_P(pgcode); }
1160
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1158
 static void menu_action_function(menuFunc_t data) { (*data)(); }
1161
 static void menu_action_sdfile(const char* filename, char* longFilename) {
1159
 static void menu_action_sdfile(const char* filename, char* longFilename) {
1162
   char cmd[30];
1160
   char cmd[30];
1163
   char* c;
1161
   char* c;
1164
   sprintf_P(cmd, PSTR("M23 %s"), filename);
1162
   sprintf_P(cmd, PSTR("M23 %s"), filename);
1165
   for(c = &cmd[4]; *c; c++) *c = tolower(*c);
1163
   for(c = &cmd[4]; *c; c++) *c = tolower(*c);
1166
-  enquecommand(cmd);
1167
-  enquecommands_P(PSTR("M24"));
1164
+  enqueuecommand(cmd);
1165
+  enqueuecommands_P(PSTR("M24"));
1168
   lcd_return_to_status();
1166
   lcd_return_to_status();
1169
 }
1167
 }
1170
 static void menu_action_sddirectory(const char* filename, char* longFilename) {
1168
 static void menu_action_sddirectory(const char* filename, char* longFilename) {
1252
 
1250
 
1253
 void lcd_update() {
1251
 void lcd_update() {
1254
   #ifdef ULTIPANEL
1252
   #ifdef ULTIPANEL
1255
-    static unsigned long timeoutToStatus = 0;
1253
+    static millis_t return_to_status_ms = 0;
1256
   #endif
1254
   #endif
1257
 
1255
 
1258
   #ifdef LCD_HAS_SLOW_BUTTONS
1256
   #ifdef LCD_HAS_SLOW_BUTTONS
1282
     }
1280
     }
1283
   #endif//CARDINSERTED
1281
   #endif//CARDINSERTED
1284
   
1282
   
1285
-  uint32_t ms = millis();
1286
-  if (ms > lcd_next_update_millis) {
1283
+  millis_t ms = millis();
1284
+  if (ms > next_lcd_update_ms) {
1287
 
1285
 
1288
     #ifdef ULTIPANEL
1286
     #ifdef ULTIPANEL
1289
 
1287
 
1335
           encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
1333
           encoderPosition += (encoderDiff * encoderMultiplier) / ENCODER_PULSES_PER_STEP;
1336
           encoderDiff = 0;
1334
           encoderDiff = 0;
1337
         }
1335
         }
1338
-        timeoutToStatus = ms + LCD_TIMEOUT_TO_STATUS;
1336
+        return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS;
1339
         lcdDrawUpdate = 1;
1337
         lcdDrawUpdate = 1;
1340
       }
1338
       }
1341
     #endif //ULTIPANEL
1339
     #endif //ULTIPANEL
1371
     #endif
1369
     #endif
1372
 
1370
 
1373
     #ifdef ULTIPANEL
1371
     #ifdef ULTIPANEL
1372
+
1373
+      // Return to Status Screen after a timeout
1374
       if (currentMenu != lcd_status_screen &&
1374
       if (currentMenu != lcd_status_screen &&
1375
-        #if defined(MANUAL_BED_LEVELING)
1376
-          currentMenu != _lcd_level_bed && 
1377
-          currentMenu != _lcd_level_bed_homing && 
1378
-        #endif  // MANUAL_BED_LEVELING
1379
-          millis() > timeoutToStatus) {
1375
+        #ifdef MANUAL_BED_LEVELING
1376
+          currentMenu != _lcd_level_bed &&
1377
+          currentMenu != _lcd_level_bed_homing &&
1378
+        #endif
1379
+        millis() > return_to_status_ms
1380
+      ) {
1380
         lcd_return_to_status();
1381
         lcd_return_to_status();
1381
         lcdDrawUpdate = 2;
1382
         lcdDrawUpdate = 2;
1382
       }
1383
       }
1383
-    #endif //ULTIPANEL
1384
+
1385
+    #endif // ULTIPANEL
1384
 
1386
 
1385
     if (lcdDrawUpdate == 2) lcd_implementation_clear();
1387
     if (lcdDrawUpdate == 2) lcd_implementation_clear();
1386
     if (lcdDrawUpdate) lcdDrawUpdate--;
1388
     if (lcdDrawUpdate) lcdDrawUpdate--;
1387
-    lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
1389
+    next_lcd_update_ms = millis() + LCD_UPDATE_INTERVAL;
1388
   }
1390
   }
1389
 }
1391
 }
1390
 
1392
 
1403
   lcdDrawUpdate = 2;
1405
   lcdDrawUpdate = 2;
1404
 
1406
 
1405
   #ifdef FILAMENT_LCD_DISPLAY
1407
   #ifdef FILAMENT_LCD_DISPLAY
1406
-    message_millis = millis();  //get status message to show up for a while
1408
+    previous_lcd_status_ms = millis();  //get status message to show up for a while
1407
   #endif
1409
   #endif
1408
 }
1410
 }
1409
 
1411
 
1473
     if (READ(BTN_EN1) == 0) newbutton |= EN_A;
1475
     if (READ(BTN_EN1) == 0) newbutton |= EN_A;
1474
     if (READ(BTN_EN2) == 0) newbutton |= EN_B;
1476
     if (READ(BTN_EN2) == 0) newbutton |= EN_B;
1475
     #if BTN_ENC > 0
1477
     #if BTN_ENC > 0
1476
-      if (millis() > blocking_enc && READ(BTN_ENC) == 0) newbutton |= EN_C;
1478
+      if (millis() > next_button_update_ms && READ(BTN_ENC) == 0) newbutton |= EN_C;
1477
     #endif
1479
     #endif
1478
     buttons = newbutton;
1480
     buttons = newbutton;
1479
     #ifdef LCD_HAS_SLOW_BUTTONS
1481
     #ifdef LCD_HAS_SLOW_BUTTONS
1797
       if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
1799
       if (max_software_endstops && current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS;
1798
       encoderPosition = 0;
1800
       encoderPosition = 0;
1799
       line_to_current();
1801
       line_to_current();
1800
-      lcdDrawUpdate = 1;
1802
+      lcdDrawUpdate = 2;
1801
     }
1803
     }
1802
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
1804
     if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Z"), ftostr43(current_position[Z_AXIS]));
1803
     static bool debounce_click = false;
1805
     static bool debounce_click = false;
1815
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1817
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1816
           line_to_current();
1818
           line_to_current();
1817
           mbl.active = 1;
1819
           mbl.active = 1;
1818
-          enquecommands_P(PSTR("G28"));
1820
+          enqueuecommands_P(PSTR("G28"));
1819
           lcd_return_to_status();
1821
           lcd_return_to_status();
1820
         } else {
1822
         } else {
1821
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1823
           current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1828
           current_position[X_AXIS] = mbl.get_x(ix);
1830
           current_position[X_AXIS] = mbl.get_x(ix);
1829
           current_position[Y_AXIS] = mbl.get_y(iy);
1831
           current_position[Y_AXIS] = mbl.get_y(iy);
1830
           line_to_current();
1832
           line_to_current();
1831
-          lcdDrawUpdate = 1;
1833
+          lcdDrawUpdate = 2;
1832
         }
1834
         }
1833
       }
1835
       }
1834
     } else {
1836
     } else {
1837
   }
1839
   }
1838
 
1840
 
1839
   static void _lcd_level_bed_homing() {
1841
   static void _lcd_level_bed_homing() {
1842
+    if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("XYZ"), "Homing");
1840
     if (axis_known_position[X_AXIS] &&
1843
     if (axis_known_position[X_AXIS] &&
1841
         axis_known_position[Y_AXIS] &&
1844
         axis_known_position[Y_AXIS] &&
1842
         axis_known_position[Z_AXIS]) {
1845
         axis_known_position[Z_AXIS]) {
1848
       _lcd_level_bed_position = 0;
1851
       _lcd_level_bed_position = 0;
1849
       lcd_goto_menu(_lcd_level_bed);
1852
       lcd_goto_menu(_lcd_level_bed);
1850
     }
1853
     }
1854
+    lcdDrawUpdate = 2;
1851
   }
1855
   }
1852
 
1856
 
1853
   static void lcd_level_bed() {
1857
   static void lcd_level_bed() {
1855
     axis_known_position[Y_AXIS] = false;
1859
     axis_known_position[Y_AXIS] = false;
1856
     axis_known_position[Z_AXIS] = false;
1860
     axis_known_position[Z_AXIS] = false;
1857
     mbl.reset();
1861
     mbl.reset();
1858
-    enquecommands_P(PSTR("G28"));
1862
+    enqueuecommands_P(PSTR("G28"));
1863
+    lcdDrawUpdate = 2;
1859
     lcd_goto_menu(_lcd_level_bed_homing);
1864
     lcd_goto_menu(_lcd_level_bed_homing);
1860
   }
1865
   }
1861
 
1866
 

+ 2
- 1
Marlin/ultralcd.h View File

49
   extern bool cancel_heatup;
49
   extern bool cancel_heatup;
50
   
50
   
51
   #ifdef FILAMENT_LCD_DISPLAY
51
   #ifdef FILAMENT_LCD_DISPLAY
52
-    extern unsigned long message_millis;
52
+    extern millis_t previous_lcd_status_ms;
53
   #endif
53
   #endif
54
 
54
 
55
   void lcd_buzz(long duration,uint16_t freq);
55
   void lcd_buzz(long duration,uint16_t freq);
56
+  void lcd_quick_feedback(); // Audible feedback for a button click - could also be visual
56
   bool lcd_clicked();
57
   bool lcd_clicked();
57
 
58
 
58
   void lcd_ignore_click(bool b=true);
59
   void lcd_ignore_click(bool b=true);

+ 36
- 37
Marlin/ultralcd_implementation_hitachi_HD44780.h View File

610
 
610
 
611
     // Show Filament Diameter and Volumetric Multiplier %
611
     // Show Filament Diameter and Volumetric Multiplier %
612
     // After allowing lcd_status_message to show for 5 seconds
612
     // After allowing lcd_status_message to show for 5 seconds
613
-    if (millis() >= message_millis + 5000) {
613
+    if (millis() >= previous_lcd_status_ms + 5000) {
614
       lcd_printPGM(PSTR("Dia "));
614
       lcd_printPGM(PSTR("Dia "));
615
       lcd.print(ftostr12ns(filament_width_meas));
615
       lcd.print(ftostr12ns(filament_width_meas));
616
       lcd_printPGM(PSTR(" V"));
616
       lcd_printPGM(PSTR(" V"));
724
 #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
724
 #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
725
 
725
 
726
 #ifdef LCD_HAS_STATUS_INDICATORS
726
 #ifdef LCD_HAS_STATUS_INDICATORS
727
-static void lcd_implementation_update_indicators()
728
-{
729
-  #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
730
-    //set the LEDS - referred to as backlights by the LiquidTWI2 library 
731
-    static uint8_t ledsprev = 0;
732
-    uint8_t leds = 0;
733
-    if (target_temperature_bed > 0) leds |= LED_A;
734
-    if (target_temperature[0] > 0) leds |= LED_B;
735
-    if (fanSpeed) leds |= LED_C;
736
-    #if EXTRUDERS > 1  
737
-      if (target_temperature[1] > 0) leds |= LED_C;
727
+
728
+  static void lcd_implementation_update_indicators() {
729
+    #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI)
730
+      //set the LEDS - referred to as backlights by the LiquidTWI2 library 
731
+      static uint8_t ledsprev = 0;
732
+      uint8_t leds = 0;
733
+      if (target_temperature_bed > 0) leds |= LED_A;
734
+      if (target_temperature[0] > 0) leds |= LED_B;
735
+      if (fanSpeed) leds |= LED_C;
736
+      #if EXTRUDERS > 1  
737
+        if (target_temperature[1] > 0) leds |= LED_C;
738
+      #endif
739
+      if (leds != ledsprev) {
740
+        lcd.setBacklight(leds);
741
+        ledsprev = leds;
742
+      }
738
     #endif
743
     #endif
739
-    if (leds != ledsprev) {
740
-      lcd.setBacklight(leds);
741
-      ledsprev = leds;
742
-    }
743
-  #endif
744
-}
745
-#endif
744
+  }
745
+
746
+#endif // LCD_HAS_STATUS_INDICATORS
746
 
747
 
747
 #ifdef LCD_HAS_SLOW_BUTTONS
748
 #ifdef LCD_HAS_SLOW_BUTTONS
748
-extern uint32_t blocking_enc;
749
 
749
 
750
-static uint8_t lcd_implementation_read_slow_buttons()
751
-{
752
-  #ifdef LCD_I2C_TYPE_MCP23017
753
-  uint8_t slow_buttons;
754
-    // Reading these buttons this is likely to be too slow to call inside interrupt context
755
-    // so they are called during normal lcd_update
756
-    slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET; 
757
-    #if defined(LCD_I2C_VIKI)
758
-    if(slow_buttons & (B_MI|B_RI)) { //LCD clicked
759
-       if(blocking_enc > millis()) {
760
-         slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
761
-       }
762
-    }
750
+  extern millis_t next_button_update_ms;
751
+
752
+  static uint8_t lcd_implementation_read_slow_buttons() {
753
+    #ifdef LCD_I2C_TYPE_MCP23017
754
+      uint8_t slow_buttons;
755
+      // Reading these buttons this is likely to be too slow to call inside interrupt context
756
+      // so they are called during normal lcd_update
757
+      slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET; 
758
+      #ifdef LCD_I2C_VIKI
759
+        if ((slow_buttons & (B_MI|B_RI)) && millis() < next_button_update_ms) // LCD clicked
760
+          slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
761
+      #endif
762
+      return slow_buttons;
763
     #endif
763
     #endif
764
-    return slow_buttons; 
765
-  #endif
766
-}
767
-#endif
764
+  }
765
+
766
+#endif // LCD_HAS_SLOW_BUTTONS
768
 
767
 
769
 #endif //__ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H
768
 #endif //__ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H

Loading…
Cancel
Save