Skip to content

Commit 4733e0b

Browse files
committed
Replace PIN macro by "constexpr"
1 parent bca24a7 commit 4733e0b

File tree

3 files changed

+48
-56
lines changed

3 files changed

+48
-56
lines changed

include/pins.h

+19-27
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#include <HardwareSerial.h>
66

77
//******************** Pins Undefined
8-
#define PIN_10 10
9-
#define PIN_11 11
8+
constexpr size_t PIN_10 = 10;
9+
constexpr size_t PIN_11 = 11;
1010

1111
//******************** Pins UART - Serial
12+
/* Do we need this ?
1213
#undef SOC_RX0
1314
#define SOC_RX0 44
1415
#undef SOC_TX0
@@ -18,44 +19,35 @@
1819
#define RX1 18
1920
#undef TX1
2021
#define TX1 17
21-
22+
*/
2223
//******************** Pins Motors - Drivers
23-
#define stepPinM1 7
24-
#define dirPinM1 6
24+
constexpr size_t PIN_STEP_M1 = 7;
25+
constexpr size_t PIN_DIR_M1 = 6;
2526

26-
#define stepPinM2 5
27-
#define dirPinM2 4
27+
constexpr size_t PIN_STEP_M2 = 5;
28+
constexpr size_t PIN_DIR_M2 = 4;
2829

29-
#define stepPinM3 2
30-
#define dirPinM3 1
30+
constexpr size_t PIN_STEP_M3 = 2;
31+
constexpr size_t PIN_DIR_M3 = 1;
3132

32-
#define EN_MCU 3
33+
constexpr size_t PIN_EN_MCU = 3;
3334

3435
//******************** Pins TwoWire I²C - Otos
36+
/*
3537
#undef SDA
3638
#define SDA 8
3739
#undef SCL
3840
#define SCL 9
39-
41+
*/
4042
//******************** Pins LED - RGB
41-
#define PIN_RGB_LED 38
42-
#define WS2812_LED 12
43-
44-
#ifdef RGB_BUILTIN
45-
#undef RGB_BUILTIN
46-
#endif
47-
#define RGB_BUILTIN PIN_RGB_LED
48-
49-
#ifdef RGB_BRIGHTNESS
50-
#undef RGB_BRIGHTNESS
51-
#endif
52-
#define RGB_BRIGHTNESS 64
43+
constexpr size_t PIN_RGB_LED = 38;
44+
constexpr size_t PIN_WS2812_LED = 12;
5345

5446
//******************** Pins IN
55-
#define MODE_PIN 14
56-
#define TEAM_PIN 13
57-
#define BAU_PIN 15
58-
#define START_PIN 16
47+
constexpr size_t PIN_MODE = 14;
48+
constexpr size_t PIN_TEAM = 13;
49+
constexpr size_t PIN_BAU = 15;
50+
constexpr size_t PIN_START = 16;
5951

6052

6153
#endif

src/Motor.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ void Motor::Initialisation(MotorBaseType _motorBaseType, float _centerToWheel)
1212
centerToWheel = _centerToWheel;
1313

1414
// Sets the two pins as Outputs
15-
pinMode(stepPinM1, OUTPUT);
16-
pinMode(dirPinM1, OUTPUT);
17-
digitalWrite(stepPinM1, LOW);
18-
digitalWrite(dirPinM1, LOW);
15+
pinMode(PIN_STEP_M1, OUTPUT);
16+
pinMode(PIN_DIR_M1, OUTPUT);
17+
digitalWrite(PIN_STEP_M1, LOW);
18+
digitalWrite(PIN_DIR_M1, LOW);
1919

20-
pinMode(stepPinM2, OUTPUT);
21-
pinMode(dirPinM2, OUTPUT);
22-
digitalWrite(stepPinM2, LOW);
23-
digitalWrite(dirPinM2, LOW);
20+
pinMode(PIN_STEP_M2, OUTPUT);
21+
pinMode(PIN_DIR_M2, OUTPUT);
22+
digitalWrite(PIN_STEP_M2, LOW);
23+
digitalWrite(PIN_DIR_M2, LOW);
2424

2525
if (motorBaseType == OMNIDIRECTIONAL_3_MOTORS)
2626
{
27-
pinMode(stepPinM3, OUTPUT);
28-
pinMode(dirPinM3, OUTPUT);
29-
digitalWrite(stepPinM3, LOW);
30-
digitalWrite(dirPinM3, LOW);
27+
pinMode(PIN_STEP_M3, OUTPUT);
28+
pinMode(PIN_DIR_M3, OUTPUT);
29+
digitalWrite(PIN_STEP_M3, LOW);
30+
digitalWrite(PIN_DIR_M3, LOW);
3131
}
3232
print("Starting ESP32_FAST_PWM: ");
3333
println(ESP32_FAST_PWM_VERSION);
3434

3535
// pin, frequency = 500 Hz, dutyCycle = 0 %, choose channel with independent timer, resolution to go up to desire frequency
36-
stepper1 = new ESP32_FAST_PWM(stepPinM1, 500, 0, 2, BIT_RESOLUTION);
36+
stepper1 = new ESP32_FAST_PWM(PIN_STEP_M1, 500, 0, 2, BIT_RESOLUTION);
3737

38-
stepper2 = new ESP32_FAST_PWM(stepPinM2, 500, 0, 4, BIT_RESOLUTION);
38+
stepper2 = new ESP32_FAST_PWM(PIN_STEP_M2, 500, 0, 4, BIT_RESOLUTION);
3939
if (motorBaseType == OMNIDIRECTIONAL_3_MOTORS)
4040
{
41-
stepper3 = new ESP32_FAST_PWM(stepPinM3, 500, 0, 6, BIT_RESOLUTION);
41+
stepper3 = new ESP32_FAST_PWM(PIN_STEP_M3, 500, 0, 6, BIT_RESOLUTION);
4242
}
4343
}
4444

@@ -137,7 +137,7 @@ void Motor::SetMotorSpeed(int motor_ID, float speed_mms)
137137
else
138138
{
139139
// Set the frequency of the PWM output and a duty cycle of 50%
140-
digitalWrite(dirPinM1, direction);
140+
digitalWrite(PIN_DIR_M1, direction);
141141
stepper1->setPWM(freq, 50);
142142
}
143143
}
@@ -150,7 +150,7 @@ void Motor::SetMotorSpeed(int motor_ID, float speed_mms)
150150
else
151151
{
152152
// Set the frequency of the PWM output and a duty cycle of 50%
153-
digitalWrite(dirPinM2, direction);
153+
digitalWrite(PIN_DIR_M2, direction);
154154
stepper2->setPWM(freq, 50);
155155
}
156156
}
@@ -163,7 +163,7 @@ void Motor::SetMotorSpeed(int motor_ID, float speed_mms)
163163
else
164164
{
165165
// Set the frequency of the PWM output and a duty cycle of 50%
166-
digitalWrite(dirPinM3, direction);
166+
digitalWrite(PIN_DIR_M3, direction);
167167
stepper3->setPWM(freq, 50);
168168
}
169169
}
@@ -183,7 +183,7 @@ float Motor::GetMotorSpeed(int motor_ID)
183183
{
184184
if (stepper1->getActualDutyCycle() == 0)
185185
return 0;
186-
direction = digitalRead(dirPinM1);
186+
direction = digitalRead(PIN_DIR_M1);
187187
if (direction)
188188
return stepper1->getActualFreq() * MM_PER_STEP_MOTOR;
189189
else
@@ -193,7 +193,7 @@ float Motor::GetMotorSpeed(int motor_ID)
193193
{
194194
if (stepper1->getActualDutyCycle() == 0)
195195
return 0;
196-
direction = digitalRead(dirPinM2);
196+
direction = digitalRead(PIN_DIR_M2);
197197
if (direction)
198198
return stepper2->getActualFreq() * MM_PER_STEP_MOTOR;
199199
else
@@ -203,7 +203,7 @@ float Motor::GetMotorSpeed(int motor_ID)
203203
{
204204
if (stepper1->getActualDutyCycle() == 0)
205205
return 0;
206-
direction = digitalRead(dirPinM3);
206+
direction = digitalRead(PIN_DIR_M3);
207207
if (direction)
208208
return stepper3->getActualFreq() * MM_PER_STEP_MOTOR;
209209
else

src/main.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ void setup()
4646
println("Robot Holonome Firmware");
4747

4848
// Init IHM
49-
pinMode(MODE_PIN, INPUT);
50-
pinMode(TEAM_PIN, INPUT);
51-
pinMode(BAU_PIN, INPUT);
52-
pinMode(START_PIN, INPUT);
49+
pinMode(PIN_MODE, INPUT);
50+
pinMode(PIN_TEAM, INPUT);
51+
pinMode(PIN_BAU, INPUT);
52+
pinMode(PIN_START, INPUT);
5353

5454
// TODO : boucle de lecture dans la loop de démarrage
55-
digitalRead(MODE_PIN) == LOW ? mode = Mode::Match : mode = Mode::Test;
56-
digitalRead(TEAM_PIN) == LOW ? team = Team::Jaune : team = Team::Bleue;
55+
digitalRead(PIN_MODE) == LOW ? mode = Mode::Match : mode = Mode::Test;
56+
digitalRead(PIN_TEAM) == LOW ? team = Team::Jaune : team = Team::Bleue;
5757

58-
led_builtin.Initialisation(1, RGB_BUILTIN);
59-
//led_ring.Initialisation(36, WS2812_LED);
58+
led_builtin.Initialisation(1, PIN_RGB_LED);
59+
//led_ring.Initialisation(36, PIN_WS2812_LED);
6060

6161
// Init sensors
6262
otos.Initialisation();

0 commit comments

Comments
 (0)