Skip to content

Commit

Permalink
chore(src/modules): use INFO macro instead of raw printf.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 4, 2023
1 parent d113789 commit f94977e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/modules/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

#include <commons.h>

#ifndef NDEBUG
#define INFO(fmt, ...) printf(fmt, ##__VA_ARGS__);
#else
#define INFO(fmt, ...)
#endif

/* Sensor->name must match its enumeration stringified value */
#define _SENSORS \
X(ALS) \
Expand Down
28 changes: 14 additions & 14 deletions src/modules/sensors/als.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static struct udev_monitor *mon;
static double iio_poll_capture(struct als_device *als, double *pct, const int num_captures, int interval) {
const char *syspath = udev_device_get_syspath(als->dev);

printf("[IIO-POLL] Start capture: '%s' syspath.\n", syspath);
INFO("[IIO-POLL] Start capture: '%s' syspath.\n", syspath);

// Load scale value
const char *val = NULL;
Expand All @@ -40,19 +40,19 @@ static double iio_poll_capture(struct als_device *als, double *pct, const int nu
scale = atof(val);
}
}
printf("[IIO-POLL] Loaded scale: %f.\n", scale);
INFO("[IIO-POLL] Loaded scale: %f.\n", scale);


int ctr = 0;
for (int i = 0; i < num_captures; i++) {
struct udev_device *non_cached_dev = udev_device_new_from_syspath(udev, syspath);
val = udev_device_get_sysattr_value(non_cached_dev, als->attr_name[ALS_IIO_POLL]);
printf("[IIO-POLL] Read: %s.\n", val);
INFO("[IIO-POLL] Read: %s.\n", val);
if (val) {
double illuminance = atof(val) * scale;
ctr++;
pct[i] = compute_value(illuminance);
printf("[IIO-POLL] Pct[%d] = %lf\n", i, pct[i]);
INFO("[IIO-POLL] Pct[%d] = %lf\n", i, pct[i]);
}
udev_device_unref(non_cached_dev);
usleep(interval * 1000);
Expand All @@ -64,7 +64,7 @@ static double iio_buffer_capture(struct als_device *als, double *pct, const int
int ctr = 0;

const char *sysname = udev_device_get_sysname(als->dev);
printf("[IIO-BUF] Start capture: '%s' sysname.\n", sysname);
INFO("[IIO-BUF] Start capture: '%s' sysname.\n", sysname);


/* Getting local iio device context */
Expand All @@ -80,7 +80,7 @@ static double iio_buffer_capture(struct als_device *als, double *pct, const int
return ctr;
}

printf("[IIO-BUF] Found device.\n");
INFO("[IIO-BUF] Found device.\n");

// Compute channel name from attribute ("illuminance" or "intensity_both")
char *name = strrchr(als->attr_name[ALS_IIO_BUFFER], '/') + 1; // "scan_elements/in_illuminance_en" -> "in_illuminance_en"
Expand All @@ -89,7 +89,7 @@ static double iio_buffer_capture(struct als_device *als, double *pct, const int
char channel_name[64];
snprintf(channel_name, strlen(name) - strlen(ptr) + 1, "%s", name); // "illuminance_en" -> "illuminance"

printf("[IIO-BUF] Channel name: '%s'.\n", channel_name);
INFO("[IIO-BUF] Channel name: '%s'.\n", channel_name);

struct iio_channel *ch = iio_device_find_channel(dev, channel_name, false);
if (!ch) {
Expand All @@ -112,7 +112,7 @@ static double iio_buffer_capture(struct als_device *als, double *pct, const int
return ctr;
}

printf("[IIO-BUF] Creating buffer.\n");
INFO("[IIO-BUF] Creating buffer.\n");
struct iio_buffer *rxbuf = iio_device_create_buffer(dev, 1, false);
if (!rxbuf) {
fprintf(stderr, "Failed to allocated buffer: %m\n");
Expand All @@ -130,22 +130,22 @@ static double iio_buffer_capture(struct als_device *als, double *pct, const int
scale = fmt->scale;
}

printf("[IIO-BUF] Data fmt: bits: %d | signed: %d | len: %d | rep: %d | scale: %f | has_scale: %d | shift: %d.\n",
INFO("[IIO-BUF] Data fmt: bits: %d | signed: %d | len: %d | rep: %d | scale: %f | has_scale: %d | shift: %d.\n",
fmt->bits, fmt->is_signed, fmt->length, fmt->repeat, fmt->scale, fmt->with_scale, fmt->shift);

const size_t read_size = fmt->bits / 8;
for (int i = 0; i < num_captures; i++) {
int ret = iio_buffer_refill(rxbuf);
printf("[IIO-BUF] Refill ret: %d/%ld\n", ret, read_size);
INFO("[IIO-BUF] Refill ret: %d/%ld\n", ret, read_size);
if (ret == read_size) {
int64_t val = 0;
if (ret == read_size) {
iio_channel_read(ch, rxbuf, &val, read_size);
printf("[IIO-BUF] Read %ld\n", val);
INFO("[IIO-BUF] Read %ld\n", val);
double illuminance = (double)val * scale;
ctr++;
pct[i] = compute_value(illuminance);
printf("[IIO-BUF] Pct[%d] = %lf\n", i, pct[i]);
INFO("[IIO-BUF] Pct[%d] = %lf\n", i, pct[i]);
}
}
usleep(interval * 1000);
Expand All @@ -165,7 +165,7 @@ static bool validate_dev(void *dev) {
als->attr_name[ALS_IIO_BUFFER] = ill_buff_names[i];
als->capture[ALS_IIO_BUFFER] = iio_buffer_capture;
valid = true;
printf("Buffer available, using '%s' sysattr\n", ill_buff_names[i]);
INFO("Buffer available, using '%s' sysattr\n", ill_buff_names[i]);
break;
}
}
Expand All @@ -175,7 +175,7 @@ static bool validate_dev(void *dev) {
als->attr_name[ALS_IIO_POLL] = ill_poll_names[i];
als->capture[ALS_IIO_POLL] = iio_poll_capture;
valid = true;
printf("Poll available, using '%s' sysattr\n", ill_poll_names[i]);
INFO("Poll available, using '%s' sysattr\n", ill_poll_names[i]);
break;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/modules/sensors/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
#include <module/map.h>
#include <udev.h>

#ifndef NDEBUG
#define INFO(fmt, ...) printf(fmt, ##__VA_ARGS__);
#else
#define INFO(fmt, ...)
#endif

#define CAMERA_NAME "Camera"
#define CAMERA_SUBSYSTEM "video4linux"
#define CAMERA_CAPTURE_PROP_NAME "ID_V4L_CAPABILITIES"
Expand Down

0 comments on commit f94977e

Please sign in to comment.