Browse Source

Add COUNT macro and apply

Scott Lahteine 10 years ago
parent
commit
278aa15301

+ 2
- 2
Marlin/Marlin_main.cpp View File

3047
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3047
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3048
       pin_number = code_value_short();
3048
       pin_number = code_value_short();
3049
 
3049
 
3050
-    for (int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins) / sizeof(*sensitive_pins)); i++) {
3050
+    for (int8_t i = 0; i < COUNT(sensitive_pins); i++) {
3051
       if (sensitive_pins[i] == pin_number) {
3051
       if (sensitive_pins[i] == pin_number) {
3052
         pin_number = -1;
3052
         pin_number = -1;
3053
         break;
3053
         break;
4192
 
4192
 
4193
     if (pin_state >= -1 && pin_state <= 1) {
4193
     if (pin_state >= -1 && pin_state <= 1) {
4194
 
4194
 
4195
-      for (int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) {
4195
+      for (int8_t i = 0; i < COUNT(sensitive_pins); i++) {
4196
         if (sensitive_pins[i] == pin_number) {
4196
         if (sensitive_pins[i] == pin_number) {
4197
           pin_number = -1;
4197
           pin_number = -1;
4198
           break;
4198
           break;

+ 3
- 1
Marlin/Sd2PinMap.h View File

19
  */
19
  */
20
 // Warning this file was generated by a program.
20
 // Warning this file was generated by a program.
21
 #include "Marlin.h"
21
 #include "Marlin.h"
22
+#include "macros.h"
23
+
22
 #ifdef SDSUPPORT
24
 #ifdef SDSUPPORT
23
 
25
 
24
 #ifndef Sd2PinMap_h
26
 #ifndef Sd2PinMap_h
385
 #error unknown chip
387
 #error unknown chip
386
 #endif  // defined(__AVR_ATmega1280__)
388
 #endif  // defined(__AVR_ATmega1280__)
387
 //------------------------------------------------------------------------------
389
 //------------------------------------------------------------------------------
388
-static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
390
+static const uint8_t digitalPinCount = COUNT(digitalPinMap);
389
 
391
 
390
 uint8_t badPinNumber(void)
392
 uint8_t badPinNumber(void)
391
   __attribute__((error("Pin number is too large or not a constant")));
393
   __attribute__((error("Pin number is too large or not a constant")));

+ 1
- 1
Marlin/configuration_store.cpp View File

475
     max_feedrate[i] = tmp2[i];
475
     max_feedrate[i] = tmp2[i];
476
     max_acceleration_units_per_sq_second[i] = tmp3[i];
476
     max_acceleration_units_per_sq_second[i] = tmp3[i];
477
     #ifdef SCARA
477
     #ifdef SCARA
478
-      if (i < sizeof(axis_scaling) / sizeof(*axis_scaling))
478
+      if (i < COUNT(axis_scaling))
479
         axis_scaling[i] = 1;
479
         axis_scaling[i] = 1;
480
     #endif
480
     #endif
481
   }
481
   }

+ 1
- 1
Marlin/digipot_mcp4451.cpp View File

50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
51
   Wire.begin();
51
   Wire.begin();
52
   // setup initial currents as defined in Configuration_adv.h
52
   // setup initial currents as defined in Configuration_adv.h
53
-  for(int i = 0; i <= sizeof(digipot_motor_current) / sizeof(float); i++) {
53
+  for(int i = 0; i < COUNT(digipot_motor_current); i++) {
54
     digipot_i2c_set_current(i, digipot_motor_current[i]);
54
     digipot_i2c_set_current(i, digipot_motor_current[i]);
55
   }
55
   }
56
 }
56
 }

+ 2
- 0
Marlin/macros.h View File

22
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
22
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
23
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
23
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
24
 
24
 
25
+#define COUNT(a) (sizeof(a)/sizeof(*a))
26
+
25
 #endif //__MACROS_H
27
 #endif //__MACROS_H

+ 1
- 1
Marlin/stepper.cpp View File

1249
     pinMode(E0_MS1_PIN,OUTPUT);
1249
     pinMode(E0_MS1_PIN,OUTPUT);
1250
     pinMode(E0_MS2_PIN,OUTPUT);
1250
     pinMode(E0_MS2_PIN,OUTPUT);
1251
     const uint8_t microstep_modes[] = MICROSTEP_MODES;
1251
     const uint8_t microstep_modes[] = MICROSTEP_MODES;
1252
-    for (uint16_t i = 0; i < sizeof(microstep_modes) / sizeof(microstep_modes[0]); i++)
1252
+    for (uint16_t i = 0; i < COUNT(microstep_modes); i++)
1253
       microstep_mode(i, microstep_modes[i]);
1253
       microstep_mode(i, microstep_modes[i]);
1254
   #endif
1254
   #endif
1255
 }
1255
 }

+ 6
- 5
Marlin/thermistortables.h View File

2
 #define THERMISTORTABLES_H_
2
 #define THERMISTORTABLES_H_
3
 
3
 
4
 #include "Marlin.h"
4
 #include "Marlin.h"
5
+#include "macros.h"
5
 
6
 
6
 #define OVERSAMPLENR 16
7
 #define OVERSAMPLENR 16
7
 
8
 
1123
 
1124
 
1124
 #ifdef THERMISTORHEATER_0
1125
 #ifdef THERMISTORHEATER_0
1125
 # define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
1126
 # define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
1126
-# define HEATER_0_TEMPTABLE_LEN (sizeof(HEATER_0_TEMPTABLE)/sizeof(*HEATER_0_TEMPTABLE))
1127
+# define HEATER_0_TEMPTABLE_LEN COUNT(HEATER_0_TEMPTABLE)
1127
 #else
1128
 #else
1128
 # ifdef HEATER_0_USES_THERMISTOR
1129
 # ifdef HEATER_0_USES_THERMISTOR
1129
 #  error No heater 0 thermistor table specified
1130
 #  error No heater 0 thermistor table specified
1146
 
1147
 
1147
 #ifdef THERMISTORHEATER_1
1148
 #ifdef THERMISTORHEATER_1
1148
 # define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
1149
 # define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
1149
-# define HEATER_1_TEMPTABLE_LEN (sizeof(HEATER_1_TEMPTABLE)/sizeof(*HEATER_1_TEMPTABLE))
1150
+# define HEATER_1_TEMPTABLE_LEN COUNT(HEATER_1_TEMPTABLE)
1150
 #else
1151
 #else
1151
 # ifdef HEATER_1_USES_THERMISTOR
1152
 # ifdef HEATER_1_USES_THERMISTOR
1152
 #  error No heater 1 thermistor table specified
1153
 #  error No heater 1 thermistor table specified
1169
 
1170
 
1170
 #ifdef THERMISTORHEATER_2
1171
 #ifdef THERMISTORHEATER_2
1171
 # define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
1172
 # define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
1172
-# define HEATER_2_TEMPTABLE_LEN (sizeof(HEATER_2_TEMPTABLE)/sizeof(*HEATER_2_TEMPTABLE))
1173
+# define HEATER_2_TEMPTABLE_LEN COUNT(HEATER_2_TEMPTABLE)
1173
 #else
1174
 #else
1174
 # ifdef HEATER_2_USES_THERMISTOR
1175
 # ifdef HEATER_2_USES_THERMISTOR
1175
 #  error No heater 2 thermistor table specified
1176
 #  error No heater 2 thermistor table specified
1192
 
1193
 
1193
 #ifdef THERMISTORHEATER_3
1194
 #ifdef THERMISTORHEATER_3
1194
 # define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
1195
 # define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
1195
-# define HEATER_3_TEMPTABLE_LEN (sizeof(HEATER_3_TEMPTABLE)/sizeof(*HEATER_3_TEMPTABLE))
1196
+# define HEATER_3_TEMPTABLE_LEN COUNT(HEATER_3_TEMPTABLE)
1196
 #else
1197
 #else
1197
 # ifdef HEATER_3_USES_THERMISTOR
1198
 # ifdef HEATER_3_USES_THERMISTOR
1198
 #  error No heater 3 thermistor table specified
1199
 #  error No heater 3 thermistor table specified
1215
 
1216
 
1216
 #ifdef THERMISTORBED
1217
 #ifdef THERMISTORBED
1217
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
-# define BEDTEMPTABLE_LEN (sizeof(BEDTEMPTABLE)/sizeof(*BEDTEMPTABLE))
1219
+# define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
1219
 #else
1220
 #else
1220
 # ifdef BED_USES_THERMISTOR
1221
 # ifdef BED_USES_THERMISTOR
1221
 #  error No bed thermistor table specified
1222
 #  error No bed thermistor table specified

Loading…
Cancel
Save