Skip to content

Commit 090130c

Browse files
jilaypandyakartben
authored andcommitted
samples: stepper: drop newline characters from LOGs
remove unnecessary newline characters from LOGs introduce logging in tmc50xx sample Signed-off-by: Jilay Pandya <[email protected]>
1 parent 8de6705 commit 090130c

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

samples/drivers/stepper/generic/src/main.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <zephyr/kernel.h>
1111

1212
#include <zephyr/logging/log.h>
13-
LOG_MODULE_REGISTER(stepper, CONFIG_STEPPER_LOG_LEVEL);
13+
LOG_MODULE_REGISTER(stepper_generic, CONFIG_STEPPER_LOG_LEVEL);
1414

1515
static const struct device *stepper = DEVICE_DT_GET(DT_ALIAS(stepper));
1616

@@ -64,12 +64,12 @@ INPUT_CALLBACK_DEFINE(NULL, button_pressed, NULL);
6464

6565
int main(void)
6666
{
67-
LOG_INF("Starting generic stepper sample\n");
67+
LOG_INF("Starting generic stepper sample");
6868
if (!device_is_ready(stepper)) {
69-
LOG_ERR("Device %s is not ready\n", stepper->name);
69+
LOG_ERR("Device %s is not ready", stepper->name);
7070
return -ENODEV;
7171
}
72-
LOG_DBG("stepper is %p, name is %s\n", stepper, stepper->name);
72+
LOG_DBG("stepper is %p, name is %s", stepper, stepper->name);
7373

7474
stepper_set_event_callback(stepper, stepper_callback, NULL);
7575
stepper_set_reference_position(stepper, 0);
@@ -80,33 +80,35 @@ int main(void)
8080
switch (atomic_get(&stepper_mode)) {
8181
case STEPPER_MODE_ENABLE:
8282
stepper_enable(stepper);
83-
LOG_INF("mode: enable\n");
84-
break;
85-
case STEPPER_MODE_STOP:
86-
stepper_stop(stepper);
87-
LOG_INF("mode: stop\n");
88-
break;
89-
case STEPPER_MODE_ROTATE_CW:
90-
stepper_run(stepper, STEPPER_DIRECTION_POSITIVE);
91-
LOG_INF("mode: rotate cw\n");
92-
break;
93-
case STEPPER_MODE_ROTATE_CCW:
94-
stepper_run(stepper, STEPPER_DIRECTION_NEGATIVE);
95-
LOG_INF("mode: rotate ccw\n");
83+
LOG_INF("mode: enable");
9684
break;
9785
case STEPPER_MODE_PING_PONG_RELATIVE:
9886
ping_pong_target_position *= -1;
9987
stepper_move_by(stepper, ping_pong_target_position);
100-
LOG_INF("mode: ping pong relative\n");
88+
LOG_INF("mode: ping pong relative");
10189
break;
10290
case STEPPER_MODE_PING_PONG_ABSOLUTE:
10391
ping_pong_target_position *= -1;
10492
stepper_move_to(stepper, ping_pong_target_position);
105-
LOG_INF("mode: ping pong absolute\n");
93+
LOG_INF("mode: ping pong absolute");
94+
break;
95+
case STEPPER_MODE_ROTATE_CW:
96+
stepper_run(stepper, STEPPER_DIRECTION_POSITIVE);
97+
LOG_INF("mode: rotate cw");
98+
break;
99+
case STEPPER_MODE_ROTATE_CCW:
100+
stepper_run(stepper, STEPPER_DIRECTION_NEGATIVE);
101+
LOG_INF("mode: rotate ccw");
102+
break;
103+
case STEPPER_MODE_STOP:
104+
stepper_stop(stepper);
105+
LOG_INF("mode: stop");
106106
break;
107107
case STEPPER_MODE_DISABLE:
108108
stepper_disable(stepper);
109-
LOG_INF("mode: disable\n");
109+
LOG_INF("mode: disable");
110+
break;
111+
default:
110112
break;
111113
}
112114
}
@@ -119,7 +121,7 @@ static void monitor_thread(void)
119121
int32_t actual_position;
120122

121123
stepper_get_actual_position(stepper, &actual_position);
122-
LOG_DBG("Actual position: %d\n", actual_position);
124+
LOG_DBG("Actual position: %d", actual_position);
123125
k_sleep(K_MSEC(CONFIG_MONITOR_THREAD_TIMEOUT_MS));
124126
}
125127
}

samples/drivers/stepper/tmc50xx/src/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <zephyr/kernel.h>
1010
#include <zephyr/drivers/stepper/stepper_trinamic.h>
1111

12+
#include <zephyr/logging/log.h>
13+
LOG_MODULE_REGISTER(stepper_tmc50xx, CONFIG_STEPPER_LOG_LEVEL);
14+
1215
const struct device *stepper = DEVICE_DT_GET(DT_ALIAS(stepper));
1316

1417
int32_t ping_pong_target_position = CONFIG_STEPS_PER_REV * CONFIG_PING_PONG_N_REV *
@@ -29,12 +32,12 @@ void stepper_callback(const struct device *dev, const enum stepper_event event,
2932

3033
int main(void)
3134
{
32-
printf("Starting tmc50xx stepper sample\n");
35+
LOG_INF("Starting tmc50xx stepper sample");
3336
if (!device_is_ready(stepper)) {
34-
printf("Device %s is not ready\n", stepper->name);
37+
LOG_ERR("Device %s is not ready", stepper->name);
3538
return -ENODEV;
3639
}
37-
printf("stepper is %p, name is %s\n", stepper, stepper->name);
40+
LOG_DBG("stepper is %p, name is %s", stepper, stepper->name);
3841

3942
stepper_set_event_callback(stepper, stepper_callback, NULL);
4043
stepper_enable(stepper);

0 commit comments

Comments
 (0)