Browse Source

Merge pull request #4779 from thinkyhead/rc_cleanups_1

Minor code cleanup, tweak M109/M190
Scott Lahteine 9 years ago
parent
commit
2e8fd70fb1
4 changed files with 42 additions and 43 deletions
  1. 6
    6
      Marlin/Marlin.h
  2. 29
    30
      Marlin/Marlin_main.cpp
  3. 6
    6
      Marlin/planner.cpp
  4. 1
    1
      Marlin/temperature.cpp

+ 6
- 6
Marlin/Marlin.h View File

342
 #endif
342
 #endif
343
 
343
 
344
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
344
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
345
-  extern float filament_width_nominal;  //holds the theoretical filament diameter i.e., 3.00 or 1.75
346
-  extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
347
-  extern float filament_width_meas; //holds the filament diameter as accurately measured
348
-  extern int8_t measurement_delay[];  //ring buffer to delay measurement
349
-  extern int filwidth_delay_index1, filwidth_delay_index2;  //ring buffer index. used by planner, temperature, and main code
350
-  extern int meas_delay_cm; //delay distance
345
+  extern bool filament_sensor;         // Flag that filament sensor readings should control extrusion
346
+  extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
347
+               filament_width_meas;    // Measured filament diameter
348
+  extern int8_t measurement_delay[];   // Ring buffer to delay measurement
349
+  extern int filwidth_delay_index[2];  // Ring buffer indexes. Used by planner, temperature, and main code
350
+  extern int meas_delay_cm;            // Delay distance
351
 #endif
351
 #endif
352
 
352
 
353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)
353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)

+ 29
- 30
Marlin/Marlin_main.cpp View File

500
 #endif
500
 #endif
501
 
501
 
502
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
502
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
503
-  //Variables for Filament Sensor input
504
-  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
505
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
503
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
506
-  float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
507
-  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement  store extruder factor after subtracting 100
508
-  int filwidth_delay_index1 = 0;  //index into ring buffer
509
-  int filwidth_delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
504
+  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA,  // Nominal filament width. Change with M404
505
+        filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA;    // Measured filament diameter
506
+  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
507
+  int filwidth_delay_index[2] = { 0, -1 };  // Indexes into ring buffer
510
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
508
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
511
 #endif
509
 #endif
512
 
510
 
555
   #define KEEPALIVE_STATE(n) ;
553
   #define KEEPALIVE_STATE(n) ;
556
 #endif // HOST_KEEPALIVE_FEATURE
554
 #endif // HOST_KEEPALIVE_FEATURE
557
 
555
 
556
+#define DEFINE_PGM_READ_ANY(type, reader)       \
557
+  static inline type pgm_read_any(const type *p)  \
558
+  { return pgm_read_##reader##_near(p); }
559
+
560
+DEFINE_PGM_READ_ANY(float,       float);
561
+DEFINE_PGM_READ_ANY(signed char, byte);
562
+
563
+#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
564
+  static const PROGMEM type array##_P[XYZ] =        \
565
+      { X_##CONFIG, Y_##CONFIG, Z_##CONFIG };     \
566
+  static inline type array(int axis)          \
567
+  { return pgm_read_any(&array##_P[axis]); }
568
+
569
+XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,   MIN_POS);
570
+XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,   MAX_POS);
571
+XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,  HOME_POS);
572
+XYZ_CONSTS_FROM_CONFIG(float, max_length,     MAX_LENGTH);
573
+XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm,   HOME_BUMP_MM);
574
+XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
575
+
558
 /**
576
 /**
559
  * ***************************************************************************
577
  * ***************************************************************************
560
  * ******************************** FUNCTIONS ********************************
578
  * ******************************** FUNCTIONS ********************************
1406
   return false;
1424
   return false;
1407
 }
1425
 }
1408
 
1426
 
1409
-#define DEFINE_PGM_READ_ANY(type, reader)       \
1410
-  static inline type pgm_read_any(const type *p)  \
1411
-  { return pgm_read_##reader##_near(p); }
1412
-
1413
-DEFINE_PGM_READ_ANY(float,       float);
1414
-DEFINE_PGM_READ_ANY(signed char, byte);
1415
-
1416
-#define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \
1417
-  static const PROGMEM type array##_P[XYZ] =        \
1418
-      { X_##CONFIG, Y_##CONFIG, Z_##CONFIG };     \
1419
-  static inline type array(int axis)          \
1420
-  { return pgm_read_any(&array##_P[axis]); }
1421
-
1422
-XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,   MIN_POS);
1423
-XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,   MAX_POS);
1424
-XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,  HOME_POS);
1425
-XYZ_CONSTS_FROM_CONFIG(float, max_length,     MAX_LENGTH);
1426
-XYZ_CONSTS_FROM_CONFIG(float, home_bump_mm,   HOME_BUMP_MM);
1427
-XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
1428
-
1429
 #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
1427
 #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
1430
   bool extruder_duplication_enabled = false; // Used in Dual X mode 2
1428
   bool extruder_duplication_enabled = false; // Used in Dual X mode 2
1431
 #endif
1429
 #endif
4816
 
4814
 
4817
   } while (wait_for_heatup && TEMP_CONDITIONS);
4815
   } while (wait_for_heatup && TEMP_CONDITIONS);
4818
 
4816
 
4819
-  LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4817
+  if (wait_for_heatup) LCD_MESSAGEPGM(MSG_HEATING_COMPLETE);
4818
+
4820
   KEEPALIVE_STATE(IN_HANDLER);
4819
   KEEPALIVE_STATE(IN_HANDLER);
4821
 }
4820
 }
4822
 
4821
 
4934
 
4933
 
4935
     } while (wait_for_heatup && TEMP_BED_CONDITIONS);
4934
     } while (wait_for_heatup && TEMP_BED_CONDITIONS);
4936
 
4935
 
4937
-    LCD_MESSAGEPGM(MSG_BED_DONE);
4936
+    if (wait_for_heatup) LCD_MESSAGEPGM(MSG_BED_DONE);
4938
     KEEPALIVE_STATE(IN_HANDLER);
4937
     KEEPALIVE_STATE(IN_HANDLER);
4939
   }
4938
   }
4940
 
4939
 
6136
     if (code_seen('D')) meas_delay_cm = code_value_int();
6135
     if (code_seen('D')) meas_delay_cm = code_value_int();
6137
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
6136
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
6138
 
6137
 
6139
-    if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup
6138
+    if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
6140
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6139
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6141
 
6140
 
6142
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6141
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6143
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
6142
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
6144
 
6143
 
6145
-      filwidth_delay_index1 = filwidth_delay_index2 = 0;
6144
+      filwidth_delay_index[0] = filwidth_delay_index[1] = 0;
6146
     }
6145
     }
6147
 
6146
 
6148
     filament_sensor = true;
6147
     filament_sensor = true;

+ 6
- 6
Marlin/planner.cpp View File

868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
869
 
869
 
870
     //FMM update ring buffer used for delay with filament measurements
870
     //FMM update ring buffer used for delay with filament measurements
871
-    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index2 >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
871
+    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
872
 
872
 
873
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
873
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
874
 
874
 
883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
884
 
884
 
885
         // Convert into an index into the measurement array
885
         // Convert into an index into the measurement array
886
-        filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001);
886
+        filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001);
887
 
887
 
888
         // If the index has changed (must have gone forward)...
888
         // If the index has changed (must have gone forward)...
889
-        if (filwidth_delay_index1 != filwidth_delay_index2) {
889
+        if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
890
           filwidth_e_count = 0; // Reset the E movement counter
890
           filwidth_e_count = 0; // Reset the E movement counter
891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
892
           do {
892
           do {
893
-            filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
894
-            measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement
895
-          } while (filwidth_delay_index1 != filwidth_delay_index2);       // More slots to fill?
893
+            filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
894
+            measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
895
+          } while (filwidth_delay_index[0] != filwidth_delay_index[1]);       // More slots to fill?
896
         }
896
         }
897
       }
897
       }
898
     }
898
     }

+ 1
- 1
Marlin/temperature.cpp View File

755
   // Control the extruder rate based on the width sensor
755
   // Control the extruder rate based on the width sensor
756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
757
     if (filament_sensor) {
757
     if (filament_sensor) {
758
-      meas_shift_index = filwidth_delay_index1 - meas_delay_cm;
758
+      meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
759
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
759
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
760
 
760
 
761
       // Get the delayed info and add 100 to reconstitute to a percent of
761
       // Get the delayed info and add 100 to reconstitute to a percent of

Loading…
Cancel
Save