Skip to content

Commit

Permalink
Merge pull request #465 from analogdevicesinc/rgetz-fix-iio-monitor
Browse files Browse the repository at this point in the history
fix iio monitor
  • Loading branch information
dNechita authored Apr 28, 2020
2 parents a7433eb + 7f0bcd0 commit 7ca7557
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
#include <iio.h>
#endif

#ifdef _MSC_BUILD
#define inline __inline
#define iio_snprintf sprintf_s
#else
#define iio_snprintf snprintf
#endif

#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)

#define RED 020u
Expand Down Expand Up @@ -177,7 +184,7 @@ static void * read_thd(void *d)

werase(right);

sprintf(buf, "</B>Device selected: </%u>%s<!%u><!B>",
iio_snprintf(buf, sizeof(buf), "</B>Device selected: </%u>%s<!%u><!B>",
RED, name, RED);
str = char2Chtype(buf, &len, &align);
writeChtype(right, 2, line, str, HORIZONTAL, 0, len);
Expand All @@ -200,14 +207,14 @@ static void * read_thd(void *d)
name = id;
unit = id_to_unit(id);

sprintf(buf, "</%u></B>%s<!B><!%u>",
iio_snprintf(buf, sizeof(buf), "</%u></B>%s<!B><!%u>",
BLUE, name, BLUE);
str = char2Chtype(buf, &len, &align);
writeChtype(right, 2, line, str,
HORIZONTAL, 0, len);
freeChtype(str);

sprintf(buf, "</%u></B>%.3lf %s<!B><!%u>",
iio_snprintf(buf, sizeof(buf), "</%u></B>%.3lf %s<!B><!%u>",
YELLOW, get_channel_value(chn), unit,
YELLOW);
str = char2Chtype(buf, &len, &align);
Expand Down Expand Up @@ -362,7 +369,7 @@ static void show_main_screen(struct iio_context *ctx)
const char *name = iio_device_get_name(dev);
if (!name)
name = iio_device_get_id(dev);
sprintf(buf, "</B> %s", name);
iio_snprintf(buf, sizeof(buf), "</B> %s", name);
dev_names[i] = strdup(buf);
if (!dev_names[i])
goto dev_name_err;
Expand Down Expand Up @@ -391,6 +398,8 @@ static void show_main_screen(struct iio_context *ctx)
free(dev_names);
destroyCDKScreen(screen);

return;

dev_name_err:
for (i = 0; i < nb_devices; i++) {
if (dev_names[i])
Expand Down

0 comments on commit 7ca7557

Please sign in to comment.