ソースを参照

replace some bools

this PR replaces some bools with one char. this will safe 3 bytes and should also be sometimes a little bit faster.
Wurstnase 10年前
コミット
b55f32f8a1
2個のファイルの変更12行の追加12行の削除
  1. 2
    0
      Marlin/Marlin.h
  2. 10
    12
      Marlin/stepper.cpp

+ 2
- 0
Marlin/Marlin.h ファイルの表示

195
  */
195
  */
196
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
196
 enum AxisEnum {X_AXIS=0, Y_AXIS=1, A_AXIS=0, B_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
197
 
197
 
198
+enum EndstopEnum {X_MIN=0, Y_MIN=1, Z_MIN=2, Z_PROBE=3, X_MAX=4, Y_MAX=5, Z_MAX=6};
199
+
198
 void enable_all_steppers();
200
 void enable_all_steppers();
199
 void disable_all_steppers();
201
 void disable_all_steppers();
200
 
202
 

+ 10
- 12
Marlin/stepper.cpp ファイルの表示

73
 
73
 
74
 volatile long endstops_trigsteps[3] = { 0 };
74
 volatile long endstops_trigsteps[3] = { 0 };
75
 volatile long endstops_stepsTotal, endstops_stepsDone;
75
 volatile long endstops_stepsTotal, endstops_stepsDone;
76
-static volatile bool endstop_x_hit = false;
77
-static volatile bool endstop_y_hit = false;
78
-static volatile bool endstop_z_hit = false;
79
-static volatile bool endstop_z_probe_hit = false; // Leaving this in even if Z_PROBE_ENDSTOP isn't defined, keeps code below cleaner. #ifdef it and usage below to save space.
76
+static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value
80
 
77
 
81
 #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
78
 #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
82
   bool abort_on_endstop_hit = false;
79
   bool abort_on_endstop_hit = false;
264
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~BIT(OCIE1A)
261
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~BIT(OCIE1A)
265
 
262
 
266
 void endstops_hit_on_purpose() {
263
 void endstops_hit_on_purpose() {
267
-  endstop_x_hit = endstop_y_hit = endstop_z_hit = endstop_z_probe_hit = false; // #ifdef endstop_z_probe_hit = to save space if needed.
264
+  endstop_hit_bits = 0;
268
 }
265
 }
269
 
266
 
270
 void checkHitEndstops() {
267
 void checkHitEndstops() {
271
-  if (endstop_x_hit || endstop_y_hit || endstop_z_hit || endstop_z_probe_hit) { // #ifdef || endstop_z_probe_hit to save space if needed.
268
+  if (endstop_hit_bits) { // #ifdef || endstop_z_probe_hit to save space if needed.
272
     SERIAL_ECHO_START;
269
     SERIAL_ECHO_START;
273
     SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
270
     SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
274
-    if (endstop_x_hit) {
271
+    if (endstop_hit_bits & BIT(X_MIN)) {
275
       SERIAL_ECHOPAIR(" X:", (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
272
       SERIAL_ECHOPAIR(" X:", (float)endstops_trigsteps[X_AXIS] / axis_steps_per_unit[X_AXIS]);
276
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "X");
273
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "X");
277
     }
274
     }
278
-    if (endstop_y_hit) {
275
+    if (endstop_hit_bits & BIT(Y_MIN)) {
279
       SERIAL_ECHOPAIR(" Y:", (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
276
       SERIAL_ECHOPAIR(" Y:", (float)endstops_trigsteps[Y_AXIS] / axis_steps_per_unit[Y_AXIS]);
280
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Y");
277
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Y");
281
     }
278
     }
282
-    if (endstop_z_hit) {
279
+    if (endstop_hit_bits & BIT(Z_MIN)) {
283
       SERIAL_ECHOPAIR(" Z:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
280
       SERIAL_ECHOPAIR(" Z:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
284
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z");
281
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z");
285
     }
282
     }
286
     #ifdef Z_PROBE_ENDSTOP
283
     #ifdef Z_PROBE_ENDSTOP
287
-    if (endstop_z_probe_hit) {
284
+    if (endstop_hit_bits & BIT(Z_PROBE)) {
288
       SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
285
       SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
289
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
286
       LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
290
     }
287
     }
468
     #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
465
     #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
469
     #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
466
     #define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
470
     #define _AXIS(AXIS) AXIS ##_AXIS
467
     #define _AXIS(AXIS) AXIS ##_AXIS
471
-    #define _ENDSTOP_HIT(axis) endstop_## axis ##_hit
468
+    #define _HIT_BIT(AXIS) AXIS ##_MIN
469
+    #define _ENDSTOP_HIT(AXIS) endstop_hit_bits |= BIT(_HIT_BIT(AXIS))
472
 
470
 
473
     #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
471
     #define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
474
       bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
472
       bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
475
       if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
473
       if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
476
         endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
474
         endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
477
-        _ENDSTOP_HIT(axis) = true; \
475
+          _ENDSTOP_HIT(AXIS); \
478
         step_events_completed = current_block->step_event_count; \
476
         step_events_completed = current_block->step_event_count; \
479
       } \
477
       } \
480
       _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
478
       _OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);

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