Browse Source

Add COUNT macro and apply

Scott Lahteine 9 years ago
parent
commit
278aa15301

+ 2
- 2
Marlin/Marlin_main.cpp View File

@@ -3047,7 +3047,7 @@ inline void gcode_M42() {
3047 3047
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3048 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 3051
       if (sensitive_pins[i] == pin_number) {
3052 3052
         pin_number = -1;
3053 3053
         break;
@@ -4192,7 +4192,7 @@ inline void gcode_M226() {
4192 4192
 
4193 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 4196
         if (sensitive_pins[i] == pin_number) {
4197 4197
           pin_number = -1;
4198 4198
           break;

+ 3
- 1
Marlin/Sd2PinMap.h View File

@@ -19,6 +19,8 @@
19 19
  */
20 20
 // Warning this file was generated by a program.
21 21
 #include "Marlin.h"
22
+#include "macros.h"
23
+
22 24
 #ifdef SDSUPPORT
23 25
 
24 26
 #ifndef Sd2PinMap_h
@@ -385,7 +387,7 @@ static const pin_map_t digitalPinMap[] = {
385 387
 #error unknown chip
386 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 392
 uint8_t badPinNumber(void)
391 393
   __attribute__((error("Pin number is too large or not a constant")));

+ 1
- 1
Marlin/configuration_store.cpp View File

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

+ 1
- 1
Marlin/digipot_mcp4451.cpp View File

@@ -50,7 +50,7 @@ void digipot_i2c_init() {
50 50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
51 51
   Wire.begin();
52 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 54
     digipot_i2c_set_current(i, digipot_motor_current[i]);
55 55
   }
56 56
 }

+ 2
- 0
Marlin/macros.h View File

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

+ 1
- 1
Marlin/stepper.cpp View File

@@ -1249,7 +1249,7 @@ void microstep_init() {
1249 1249
     pinMode(E0_MS1_PIN,OUTPUT);
1250 1250
     pinMode(E0_MS2_PIN,OUTPUT);
1251 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 1253
       microstep_mode(i, microstep_modes[i]);
1254 1254
   #endif
1255 1255
 }

+ 6
- 5
Marlin/thermistortables.h View File

@@ -2,6 +2,7 @@
2 2
 #define THERMISTORTABLES_H_
3 3
 
4 4
 #include "Marlin.h"
5
+#include "macros.h"
5 6
 
6 7
 #define OVERSAMPLENR 16
7 8
 
@@ -1123,7 +1124,7 @@ const short temptable_1047[][2] PROGMEM = {
1123 1124
 
1124 1125
 #ifdef THERMISTORHEATER_0
1125 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 1128
 #else
1128 1129
 # ifdef HEATER_0_USES_THERMISTOR
1129 1130
 #  error No heater 0 thermistor table specified
@@ -1146,7 +1147,7 @@ const short temptable_1047[][2] PROGMEM = {
1146 1147
 
1147 1148
 #ifdef THERMISTORHEATER_1
1148 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 1151
 #else
1151 1152
 # ifdef HEATER_1_USES_THERMISTOR
1152 1153
 #  error No heater 1 thermistor table specified
@@ -1169,7 +1170,7 @@ const short temptable_1047[][2] PROGMEM = {
1169 1170
 
1170 1171
 #ifdef THERMISTORHEATER_2
1171 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 1174
 #else
1174 1175
 # ifdef HEATER_2_USES_THERMISTOR
1175 1176
 #  error No heater 2 thermistor table specified
@@ -1192,7 +1193,7 @@ const short temptable_1047[][2] PROGMEM = {
1192 1193
 
1193 1194
 #ifdef THERMISTORHEATER_3
1194 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 1197
 #else
1197 1198
 # ifdef HEATER_3_USES_THERMISTOR
1198 1199
 #  error No heater 3 thermistor table specified
@@ -1215,7 +1216,7 @@ const short temptable_1047[][2] PROGMEM = {
1215 1216
 
1216 1217
 #ifdef THERMISTORBED
1217 1218
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
-# define BEDTEMPTABLE_LEN (sizeof(BEDTEMPTABLE)/sizeof(*BEDTEMPTABLE))
1219
+# define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
1219 1220
 #else
1220 1221
 # ifdef BED_USES_THERMISTOR
1221 1222
 #  error No bed thermistor table specified

Loading…
Cancel
Save