ソースを参照

HOMEAXIS: make into a function

Replace the large macro HOMEAXIS with a function.  This avoids the
compiler generating three copies of largely identical code.  The
saving is 724 bytes of program memory.

We make use of XYZ_CONSTS_FROM_CONFIG to provide convenient
array-shaped access to MAX_LENGTH, HOME_RETRACT_MM and HOME_DIR.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Ian Jackson 12年前
コミット
1dba212e18
1個のファイルの変更36行の追加25行の削除
  1. 36
    25
      Marlin/Marlin.pde

+ 36
- 25
Marlin/Marlin.pde ファイルの表示

@@ -557,6 +557,7 @@ bool code_seen(char code)
557 557
 	{ return pgm_read_##reader##_near(p); }
558 558
 
559 559
 DEFINE_PGM_READ_ANY(float,       float);
560
+DEFINE_PGM_READ_ANY(signed char, byte);
560 561
 
561 562
 #define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG)	\
562 563
 static const PROGMEM type array##_P[3] =		\
@@ -567,6 +568,9 @@ static inline type array(int axis)			\
567 568
 XYZ_CONSTS_FROM_CONFIG(float, base_min_pos,    MIN_POS);
568 569
 XYZ_CONSTS_FROM_CONFIG(float, base_max_pos,    MAX_POS);
569 570
 XYZ_CONSTS_FROM_CONFIG(float, base_home_pos,   HOME_POS);
571
+XYZ_CONSTS_FROM_CONFIG(float, max_length,      MAX_LENGTH);
572
+XYZ_CONSTS_FROM_CONFIG(float, home_retract_mm, HOME_RETRACT_MM);
573
+XYZ_CONSTS_FROM_CONFIG(signed char, home_dir,  HOME_DIR);
570 574
 
571 575
 static void axis_is_at_home(int axis) {
572 576
   current_position[axis] = base_home_pos(axis) + add_homeing[axis];
@@ -574,32 +578,39 @@ static void axis_is_at_home(int axis) {
574 578
   max_pos[axis] =          base_max_pos(axis) + add_homeing[axis];
575 579
 }
576 580
 
577
-#define HOMEAXIS(LETTER) \
578
-  if ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))\
579
-    { \
580
-    current_position[LETTER##_AXIS] = 0; \
581
-    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
582
-    destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
583
-    feedrate = homing_feedrate[LETTER##_AXIS]; \
584
-    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
585
-    st_synchronize();\
586
-    \
587
-    current_position[LETTER##_AXIS] = 0;\
588
-    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
589
-    destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
590
-    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
591
-    st_synchronize();\
592
-    \
593
-    destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
594
-    feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
595
-    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
596
-    st_synchronize();\
597
-    \
598
-    axis_is_at_home(LETTER##_AXIS);					\
599
-    destination[LETTER##_AXIS] = current_position[LETTER##_AXIS]; \
600
-    feedrate = 0.0;\
601
-    endstops_hit_on_purpose();\
581
+static void homeaxis(int axis) {
582
+#define HOMEAXIS_DO(LETTER) \
583
+  ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
584
+
585
+  if (axis==X_AXIS ? HOMEAXIS_DO(X) :
586
+      axis==Y_AXIS ? HOMEAXIS_DO(Y) :
587
+      axis==Z_AXIS ? HOMEAXIS_DO(Z) :
588
+      0) {
589
+    current_position[axis] = 0;
590
+    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
591
+    destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
592
+    feedrate = homing_feedrate[axis];
593
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
594
+    st_synchronize();
595
+   
596
+    current_position[axis] = 0;
597
+    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
598
+    destination[axis] = -home_retract_mm(axis) * home_dir(axis);
599
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
600
+    st_synchronize();
601
+   
602
+    destination[axis] = 2*home_retract_mm(axis) * home_dir(axis);
603
+    feedrate = homing_feedrate[axis]/2 ; 
604
+    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
605
+    st_synchronize();
606
+   
607
+    axis_is_at_home(axis);					
608
+    destination[axis] = current_position[axis];
609
+    feedrate = 0.0;
610
+    endstops_hit_on_purpose();
602 611
   }
612
+}
613
+#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
603 614
 
604 615
 void process_commands()
605 616
 {

読み込み中…
キャンセル
保存