diff --git a/tests/driver_ltc4150/Makefile b/tests/driver_ltc4150/Makefile index b891f0b130858c1bf53030d2efaee3754a5df61f..69e41df12e267c4ba7778305f43a9504be09d0a8 100644 --- a/tests/driver_ltc4150/Makefile +++ b/tests/driver_ltc4150/Makefile @@ -6,3 +6,7 @@ USEMODULE += fmt USEMODULE += ltc4150 include $(RIOTBASE)/Makefile.include + +ifneq (,$(filter $(BOARD),msb-430 msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1)) + CFLAGS += -DNO_FPUTS +endif diff --git a/tests/driver_ltc4150/main.c b/tests/driver_ltc4150/main.c index 12ced98827a9799f39f8c2fe258d3cbb6a91c0a5..a539c78ae246082cfaf0de8ba86a102464b3ad99 100644 --- a/tests/driver_ltc4150/main.c +++ b/tests/driver_ltc4150/main.c @@ -62,6 +62,22 @@ static void *recorder_data[] = { #include "ltc4150_params.h" +/** + * @brief Like `puts()`, but do not append a newline + * + * Normally I would just use `fputs(str, stdout)` directly, but the msp430 + * toolchain lacks `fputs()`. This wrapper allows to add a less efficient + * fallback to printf() + */ +static inline void puts_no_nl(const char *s) +{ +#ifndef NO_FPUTS + fputs(s, stdout); +#else + printf("%s", s); +#endif +} + /** * @brief Callback function to reset/initialize the recorder data */ @@ -142,11 +158,11 @@ static void print_spaces(size_t number) { static const char *spaces = " "; while (number > 16) { - fputs(spaces, stdout); + puts_no_nl(spaces); number -= 16; } - fputs(spaces + 16 - number, stdout); + puts_no_nl(spaces + 16 - number); } /** @@ -164,7 +180,7 @@ static void print_col_u32(uint32_t number, size_t width) if (width > slen) { print_spaces(width - slen); } - fputs(sbuf, stdout); + puts_no_nl(sbuf); } /** @@ -188,7 +204,7 @@ static void print_col_i32(int32_t number, size_t width) if (width > slen) { print_spaces(width - slen); } - fputs(sbuf, stdout); + puts_no_nl(sbuf); } /** @@ -204,7 +220,7 @@ static void print_current(int32_t current, size_t width) sbuf[0] = '.'; sbuf[1] = '0' + current % 10; sbuf[2] = '\0'; - fputs(sbuf, stdout); + puts_no_nl(sbuf); } int main(void) @@ -220,7 +236,7 @@ int main(void) ltc4150_pulses2c(<c4150, &ten_uc_per_pulse, NULL, 10000, 0); if (retval) { - fputs("Failed to initialize LTC4150 driver:", stdout); + puts_no_nl("Failed to initialize LTC4150 driver:"); switch (retval) { case -EINVAL: puts("Invalid parameter"); @@ -291,11 +307,11 @@ int main(void) puts("ltc4150_charge() failed!"); return -1; } - fputs("| ", stdout); + puts_no_nl("| "); print_col_u32(charged, 13); - fputs(" | ", stdout); + puts_no_nl(" | "); print_col_u32(discharged, 13); - fputs(" | ", stdout); + puts_no_nl(" | "); /* Get & print avg current */ if (ltc4150_avg_current(<c4150, &avg_current)) { @@ -303,7 +319,7 @@ int main(void) return -1; } print_current(avg_current, 7); - fputs(" | ", stdout); + puts_no_nl(" | "); /* Get & print last minute current */ if (ltc4150_last_minute_charge(<c4150, &last_minute_data, @@ -315,7 +331,7 @@ int main(void) current = (int32_t)discharged - (int32_t)charged; current /= 60; print_col_i32(current, 11); - fputs(" | ", stdout); + puts_no_nl(" | "); /* Calculate & print the current between the last two pulses */ current = (int32_t)((test_data.now_usec - test_data.last_usec) / MS_PER_SEC);