Skip to content

Commit aa3f35c

Browse files
committed
format code. update markdown file
1 parent ecff707 commit aa3f35c

23 files changed

+102
-87
lines changed

examples/Issue151/Issue151.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void loop() {
4747
while (stepper->isRunning()) {
4848
};
4949
#ifdef SIMULATOR
50-
// if result is Ok. Toggle port twice, otherwise once
50+
// if result is Ok. Toggle port twice, otherwise once
5151
#define PIN 10
5252
#define DIRPIN 7
5353
pinMode(DIRPIN, OUTPUT);

examples/Issue152/Issue152.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void loop() {
4747
while (stepper->isRunning()) {
4848
};
4949
#ifdef SIMULATOR
50-
// if result is Ok. Toggle port twice, otherwise once
50+
// if result is Ok. Toggle port twice, otherwise once
5151
#define PIN 10
5252
#define DIRPIN 7
5353
pinMode(DIRPIN, OUTPUT);

examples/Issue174/Issue174.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
long chirpTimeInitial = 0;
44

55
// Stepper Wiring
6-
//#define dirPinStepper 8 // This can be any output capable port pin.
7-
//#define stepPinStepper 9 // step pin must be pin 9, 10 or 11
6+
// #define dirPinStepper 8 // This can be any output capable port pin.
7+
// #define stepPinStepper 9 // step pin must be pin 9, 10 or 11
88

99
// Stepper Wiring
1010
#define dirPinStepper 19

examples/Issue250/Issue250.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#define stepPinStepper 9 // OC1A in case of AVR
1212

1313
// As in StepperDemo for Motor 1 on ESP32
14-
//#define dirPinStepper 18
15-
//#define enablePinStepper 26
16-
//#define stepPinStepper 19
14+
// #define dirPinStepper 18
15+
// #define enablePinStepper 26
16+
// #define stepPinStepper 19
1717

1818
FastAccelStepperEngine engine = FastAccelStepperEngine();
1919
FastAccelStepper *stepper = NULL;

examples/LinearAcceleration/LinearAcceleration.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "FastAccelStepper.h"
22

33
// As in StepperDemo for Motor 1 on AVR
4-
//#define dirPinStepper 5
5-
//#define enablePinStepper 6
6-
//#define stepPinStepper 9 // OC1A in case of AVR
4+
// #define dirPinStepper 5
5+
// #define enablePinStepper 6
6+
// #define stepPinStepper 9 // OC1A in case of AVR
77

88
// As in StepperDemo for Motor 1 on ESP32
99
#define dirPinStepper 18
@@ -20,7 +20,7 @@ void setup() {
2020

2121
#ifdef SUPPORT_SELECT_DRIVER_TYPE
2222
// The code below is only relevant for original esp32
23-
//#define TEST_DONT_CARE_RMT
23+
// #define TEST_DONT_CARE_RMT
2424
#ifdef TEST_DONT_CARE_RMT
2525
// here occupy first all mcpwm/pcnt modules, then uses rmt
2626
stepper = engine.stepperConnectToPin(19, DRIVER_DONT_CARE);

examples/Pulses/Pulses.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//
66

77
// As in StepperDemo for Motor 1 on AVR
8-
//#define dirPinStepper 5
9-
//#define enablePinStepper 6
10-
//#define stepPinStepper 9 // OC1A in case of AVR
8+
// #define dirPinStepper 5
9+
// #define enablePinStepper 6
10+
// #define stepPinStepper 9 // OC1A in case of AVR
1111

1212
// As in StepperDemo for Motor 7 on ESP32
1313
#define dirPinStepper 19

examples/StepperDemo/StepperDemo.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,7 @@ bool process_cmd(char *cmd) {
11611161
SerialInterface.println("ESP reset");
11621162
esp_task_wdt_init(1, true);
11631163
esp_task_wdt_add(NULL);
1164-
while (true)
1165-
;
1164+
while (true);
11661165
}
11671166
SerialInterface.println("ESP restart");
11681167
ESP.restart();

examples/UsageExample/UsageExample.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "FastAccelStepper.h"
22

33
// As in StepperDemo for Motor 1 on AVR
4-
//#define dirPinStepper 5
5-
//#define enablePinStepper 6
6-
//#define stepPinStepper 9 // OC1A in case of AVR
4+
// #define dirPinStepper 5
5+
// #define enablePinStepper 6
6+
// #define stepPinStepper 9 // OC1A in case of AVR
77

88
// As in StepperDemo for Motor 1 on ESP32
99
#define dirPinStepper 18

extras/doc/FastAccelStepper_API.md

+16
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ CPU core with this modified init()-call. ESP32 implementation detail: For
5555
values 0 and 1, xTaskCreatePinnedToCore() is used, or else xTaskCreate()
5656
```cpp
5757
void init(uint8_t cpu_core);
58+
#endif
5859
```
5960
### Creation of FastAccelStepper
6061
@@ -492,6 +493,21 @@ This only sets a flag and can be called from an interrupt !
492493
void stopMove();
493494
bool isStopping() { return _rg.isStopping(); }
494495
```
496+
### stepsToStop()
497+
This returns the current step value of the ramp.
498+
This equals the number of steps for a motor to
499+
reach the current position and speed from standstill
500+
and to come to standstill with deceleration if stopped
501+
immediately.
502+
This value is valid with or without linear acceleration
503+
being used.
504+
Primary use is to forecast possible stop position.
505+
The stop position is:
506+
getCurrentPosition() + stepsToStop()
507+
in case of a motor running in positive direction.
508+
```cpp
509+
uint32_t stepsToStop() { return _rg.stepsToStop(); }
510+
```
495511
### forceStop()
496512
Abruptly stop the running stepper without deceleration.
497513
This can be called from an interrupt !
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "FastAccelStepper.h"
22

33
// As in StepperDemo for Motor 1 on AVR
4-
//#define dirPinStepper 5
5-
//#define enablePinStepper 6
6-
//#define stepPinStepper 9 // OC1A in case of AVR
4+
// #define dirPinStepper 5
5+
// #define enablePinStepper 6
6+
// #define stepPinStepper 9 // OC1A in case of AVR
77

88
// As in StepperDemo for Motor 1 on ESP32
99
#define dirPinStepper 18
@@ -13,37 +13,36 @@
1313
FastAccelStepperEngine engine = FastAccelStepperEngine();
1414
FastAccelStepper *stepper = NULL;
1515

16-
1716
void setup() {
1817
printf("START\n");
19-
for (uint8_t i = 0;i < 10;i++) {
20-
printf("LOOP %d\n",i);
18+
for (uint8_t i = 0; i < 10; i++) {
19+
printf("LOOP %d\n", i);
2120
vTaskDelay(pdMS_TO_TICKS(500));
2221
esp_task_wdt_reset();
2322
}
2423

2524
engine.init(0);
2625

2726
printf("Engine initialized\n");
28-
for (uint8_t i = 0;i < 10;i++) {
29-
printf("LOOP %d\n",i);
27+
for (uint8_t i = 0; i < 10; i++) {
28+
printf("LOOP %d\n", i);
3029
vTaskDelay(pdMS_TO_TICKS(500));
3130
esp_task_wdt_reset();
3231
}
3332

3433
stepper = engine.stepperConnectToPin(stepPinStepper);
3534

3635
printf("Stepper connected\n");
37-
for (uint8_t i = 0;i < 10;i++) {
38-
printf("LOOP %d\n",i);
36+
for (uint8_t i = 0; i < 10; i++) {
37+
printf("LOOP %d\n", i);
3938
vTaskDelay(pdMS_TO_TICKS(500));
4039
esp_task_wdt_reset();
4140
}
4241

4342
if (stepper) {
44-
// stepper->setDirectionPin(dirPinStepper);
45-
// stepper->setEnablePin(enablePinStepper);
46-
// stepper->setAutoEnable(true);
43+
// stepper->setDirectionPin(dirPinStepper);
44+
// stepper->setEnablePin(enablePinStepper);
45+
// stepper->setAutoEnable(true);
4746

4847
// If auto enable/disable need delays, just add (one or both):
4948
// stepper->setDelayToEnable(50);
@@ -53,32 +52,31 @@ void setup() {
5352
stepper->setAcceleration(100);
5453
stepper->move(1000);
5554
printf("Stepper initialized\n");
56-
}
57-
else {
55+
} else {
5856
printf("No stepper\n");
5957
}
6058

61-
for (uint8_t i = 0;i < 10;i++) {
62-
printf("LOOP %d\n",i);
59+
for (uint8_t i = 0; i < 10; i++) {
60+
printf("LOOP %d\n", i);
6361
vTaskDelay(pdMS_TO_TICKS(500));
6462
esp_task_wdt_reset();
6563
}
6664
}
6765

6866
void loop() {
69-
while(stepper->isRunning()) {
70-
esp_task_wdt_reset();
71-
printf("pos=%d\n", stepper->getCurrentPosition());
72-
vTaskDelay(pdMS_TO_TICKS(500));
73-
}
74-
stepper->move(1000);
67+
while (stepper->isRunning()) {
68+
esp_task_wdt_reset();
69+
printf("pos=%d\n", stepper->getCurrentPosition());
70+
vTaskDelay(pdMS_TO_TICKS(500));
71+
}
72+
stepper->move(1000);
7573
}
7674

77-
extern "C" void app_main()
78-
{
75+
extern "C" void app_main() {
7976
setup();
80-
while(true) {
81-
loop();
77+
while (true) {
78+
loop();
8279
}
83-
// WARNING: if program reaches end of function app_main() the MCU will restart.
80+
// WARNING: if program reaches end of function app_main() the MCU will
81+
// restart.
8482
}

extras/tests/pc_based/test_07.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class FastAccelStepperTest {
105105
printf("Time coasting = %d\n", rc.time_coasting);
106106
test(rc.time_coasting < 46000000, "too much coasting");
107107

108-
printf("mid point @ %" PRIu64 " => total = %" PRIu64 ", total ticks = %" PRIu64 "\n",
108+
printf("mid point @ %" PRIu64 " => total = %" PRIu64
109+
", total ticks = %" PRIu64 "\n",
109110
mid_point_ticks, 2 * mid_point_ticks, rc.total_ticks);
110111
#define ALLOWED_ASYMMETRY 1000000L
111112
printf("%ld\n", ALLOWED_ASYMMETRY);

src/FastAccelStepper.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,7 @@ void FastAccelStepper::getCurrentSpeedInTicks(struct actual_ticks_s* speed,
764764
if (!valid) {
765765
if (_rg.isRampGeneratorActive()) {
766766
_rg.getCurrentSpeedInTicks(speed);
767-
}
768-
else {
767+
} else {
769768
speed->ticks = 0;
770769
}
771770
}

src/FastAccelStepper.h

-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ class FastAccelStepper {
530530
// in case of a motor running in positive direction.
531531
uint32_t stepsToStop() { return _rg.stepsToStop(); }
532532

533-
534533
// ### forceStop()
535534
// Abruptly stop the running stepper without deceleration.
536535
// This can be called from an interrupt !

src/PoorManFloat.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// XXXXXXXX:1XXXXXXXX
1919
// exponent mantissa
2020
//
21-
// The mantissa represents encodes 256..511 and interpreted as 1.0 to ~2.0.
21+
// The mantissa encodes 256..511 and interpreted as 1.0 to ~2.0.
2222
// The exponent uses an offset 128 to encode negative values and base 2
2323
//
2424
// 0x8000 => is 1
@@ -73,13 +73,13 @@
7373
// upm_float. Consequently, a purely logarithmic representation is completely
7474
// sufficient.
7575
//
76-
// As base for exp/log we will use 2 (not 10 or e). This way the exponent of an
76+
// As base for exp/log we will use 2 (not 10 or e). This way the exponent of an
7777
// upm float being 2^n needs no calculation, as log2(2^n) = n. Still the offset
7878
// by 128 needs to be considered
7979
//
8080
// The mantissa of an upm float with the leading 1 is in the range 1 <= m < 2.
8181
//
82-
// As log2(1) = 0 and log2(2) = 1 is at the corners identical to x + 1. So it is
82+
// As log2(1) = 0 and log2(2) = 1 is at the corners identical to x - 1. So it is
8383
// interesting to look at function f(x) = log2(x) - x + 1. This function is 0
8484
// for x at 1 and 2, positive over the range inbetween and reaches max value of
8585
// 0.08607 at x = 1.442695. This max value is at x = 1/ln(2)
@@ -161,7 +161,7 @@ uint8_t leading_zeros(uint8_t x) {
161161
}
162162
if ((x & 0x80) == 0) {
163163
res += 1;
164-
if ((x & 0x40) == 0) {
164+
if (x == 0) {
165165
res += 1;
166166
}
167167
}
@@ -200,6 +200,7 @@ pmf_logarithmic pmfl_from(uint8_t x) {
200200
res += offset >> 1;
201201
return res;
202202
}
203+
203204
pmf_logarithmic pmfl_from(uint16_t x) {
204205
uint8_t leading = leading_zeros(x >> 8);
205206
if (leading == 8) {

src/PoorManFloat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ inline pmf_logarithmic pmfl_pow_div_3(pmf_logarithmic x) {
4545
x += 1;
4646
return x / 2;
4747
}
48-
#define pmfl_pow_2_div_3(x) ((x)-pmfl_pow_div_3(x))
48+
#define pmfl_pow_2_div_3(x) ((x) - pmfl_pow_div_3(x))
4949
#define pmfl_pow_3_div_2(x) ((x) + (x) / 2)
5050

5151
pmf_logarithmic pmfl_square(pmf_logarithmic x);

src/RampConstAcceleration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void init_ramp_module() {
2323

2424
//*************************************************************************************************
2525

26-
//#define TRACE
26+
// #define TRACE
2727
#ifdef TRACE
2828
#define TRACE_OUTPUT(x) Serial.print(x)
2929
#else

src/StepperISR.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int8_t StepperQueue::addQueueEntry(const struct stepper_command_s* cmd,
5050
// :2:13432X:2:13248X:2:13072X:2:12896X:2:12736X:2:12584X:2:12432X:2:12280X:2:12128X:2:12000X:2:11872X:2:11744X:2:11616X:2:11488X:2:11384X:2:11264X:2:11152X:2:11048X:2:10944X:2:10840X:2:10736X:2:10656X:3:10512X:3:10384X:3:10248X:3:10120X:3:10008X:3:9888X:3:9784X:3:9680X:3:9576X:3:9472X:3:9368X:3:9280X:3:9176X:3:9096X:3:9008X:3:8928X:3:8840X:3:8760X:3:8688X:3:8600X:3:8528X:3:8464X:3:8392X:3:8328X:3:8256X:3:8192X:3:8124X:3:8060X:3:8008X:3:7944X:4:7864X:4:7792X:4:7720X:4:7648X:4:7584X:4:7512X:4:7452X:4:7384X:4:7324X
5151
// :4:7264X:4:7204X:4:7148X:4:7088X:4:7040X:4:6984X:4:6928X
5252

53-
//#define TRACE
53+
// #define TRACE
5454
#ifdef TRACE
5555
Serial.print(':');
5656
Serial.print(start ? "START" : "PUSH");

src/StepperISR_due.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "StepperISR.h"
2-
//#ifndef ARDUINO_ARCH_SAM
3-
//#define ARDUINO_ARCH_SAM
4-
//#endif
5-
//#define KEEP_SCORE
2+
// #ifndef ARDUINO_ARCH_SAM
3+
// #define ARDUINO_ARCH_SAM
4+
// #endif
5+
// #define KEEP_SCORE
66
#if defined(ARDUINO_ARCH_SAM)
77
const bool enabled = false;
88
uint32_t junk = 0;

src/StepperISR_esp32_mcpwm_pcnt.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// cannot be updated while timer is running => fix it to 0
88
#define TIMER_PRESCALER 0
99

10-
//#define TEST_PROBE 18
10+
// #define TEST_PROBE 18
1111

1212
// Here the associated mapping from queue to mcpwm/pcnt units
1313
//
@@ -534,7 +534,7 @@ void StepperQueue::startQueue_mcpwm_pcnt() {
534534
#ifndef __ESP32_IDF_V44__
535535
mcpwm->timer[timer].mode.start = 2; // 2=run continuous
536536
#else /* __ESP32_IDF_V44__ */
537-
mcpwm->timer[timer].timer_cfg1.timer_start = 2; // 2=run continuous
537+
mcpwm->timer[timer].timer_cfg1.timer_start = 2; // 2=run continuous
538538
#endif /* __ESP32_IDF_V44__ */
539539
}
540540
void StepperQueue::forceStop_mcpwm_pcnt() {
@@ -557,12 +557,12 @@ bool StepperQueue::isReadyForCommands_mcpwm_pcnt() {
557557
return false;
558558
}
559559
return true;
560-
//#ifndef __ESP32_IDF_V44__
561-
// return (mcpwm->timer[timer].mode.start != 2); // 2=run continuous
562-
//#else /* __ESP32_IDF_V44__ */
563-
// return (mcpwm->timer[timer].timer_cfg1.timer_start != 2); // 2=run
564-
// continuous
565-
//#endif /* __ESP32_IDF_V44__ */
560+
// #ifndef __ESP32_IDF_V44__
561+
// return (mcpwm->timer[timer].mode.start != 2); // 2=run continuous
562+
// #else /* __ESP32_IDF_V44__ */
563+
// return (mcpwm->timer[timer].timer_cfg1.timer_start != 2); // 2=run
564+
// continuous
565+
// #endif /* __ESP32_IDF_V44__ */
566566
}
567567
uint16_t StepperQueue::_getPerformedPulses_mcpwm_pcnt() {
568568
const struct mapping_s *mapping = (const struct mapping_s *)driver_data;

0 commit comments

Comments
 (0)