Commit 7663a4aa authored by Hartmut Knaack's avatar Hartmut Knaack Committed by Jonathan Cameron

tools:iio: adjust coding style

Fix various coding style issues, including:
  * have spaces around operators
  * indentation
  * consolidate parameters in same line
  * required braces
  * adjust/drop comments
  * multiline comment style
  * delete unnecessary empty lines
  * add empty lines to visualize logial code blocks
  * typos
Signed-off-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 4f3ca893
......@@ -51,11 +51,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
if (bytes % channels[i].bytes == 0)
channels[i].location = bytes;
else
channels[i].location = bytes - bytes%channels[i].bytes
+ channels[i].bytes;
channels[i].location = bytes - bytes % channels[i].bytes
+ channels[i].bytes;
bytes = channels[i].location + channels[i].bytes;
i++;
}
return bytes;
}
......@@ -136,9 +138,9 @@ void print8byte(uint64_t input, struct iio_channel_info *info)
/**
* process_scan() - print out the values in SI units
* @data: pointer to the start of the scan
* @channels: information about the channels. Note
* size_from_channelarray must have been called first to fill the
* location offsets.
* @channels: information about the channels.
* Note: size_from_channelarray must have been called first
* to fill the location offsets.
* @num_channels: number of channels
**/
void process_scan(char *data,
......@@ -213,6 +215,7 @@ int main(int argc, char **argv)
num_loops = strtoul(optarg, &dummy, 10);
if (errno)
return -errno;
break;
case 'e':
noevents = 1;
......@@ -225,6 +228,7 @@ int main(int argc, char **argv)
buf_len = strtoul(optarg, &dummy, 10);
if (errno)
return -errno;
break;
case 'n':
device_name = optarg;
......@@ -257,6 +261,7 @@ int main(int argc, char **argv)
printf("Failed to find the %s\n", device_name);
return dev_num;
}
printf("iio device number being used is %d\n", dev_num);
ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
......@@ -285,9 +290,11 @@ int main(int argc, char **argv)
ret = trig_num;
goto error_free_triggername;
}
printf("iio trigger number being used is %d\n", trig_num);
} else
} else {
printf("trigger-less mode selected\n");
}
/*
* Parse the files in scan_elements to identify what channels are
......@@ -314,8 +321,10 @@ int main(int argc, char **argv)
if (!notrigger) {
printf("%s %s\n", dev_dir_name, trigger_name);
/* Set the device trigger to be the data ready trigger found
* above */
/*
* Set the device trigger to be the data ready trigger found
* above
*/
ret = write_sysfs_string_and_verify("trigger/current_trigger",
dev_dir_name,
trigger_name);
......@@ -334,8 +343,9 @@ int main(int argc, char **argv)
ret = write_sysfs_int("enable", buf_dir_name, 1);
if (ret < 0)
goto error_free_buf_dir_name;
scan_size = size_from_channelarray(channels, num_channels);
data = malloc(scan_size*buf_len);
data = malloc(scan_size * buf_len);
if (!data) {
ret = -ENOMEM;
goto error_free_buf_dir_name;
......@@ -349,13 +359,12 @@ int main(int argc, char **argv)
/* Attempt to open non blocking the access dev */
fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
if (fp == -1) { /* If it isn't there make the node */
if (fp == -1) { /* TODO: If it isn't there make the node */
ret = -errno;
printf("Failed to open %s\n", buffer_access);
goto error_free_buffer_access;
}
/* Wait for events 10 times */
for (j = 0; j < num_loops; j++) {
if (!noevents) {
struct pollfd pfd = {
......@@ -372,25 +381,22 @@ int main(int argc, char **argv)
}
toread = buf_len;
} else {
usleep(timedelay);
toread = 64;
}
read_size = read(fp,
data,
toread*scan_size);
read_size = read(fp, data, toread * scan_size);
if (read_size < 0) {
if (errno == EAGAIN) {
printf("nothing available\n");
continue;
} else
} else {
break;
}
}
for (i = 0; i < read_size/scan_size; i++)
process_scan(data + scan_size*i,
channels,
for (i = 0; i < read_size / scan_size; i++)
process_scan(data + scan_size * i, channels,
num_channels);
}
......@@ -409,6 +415,7 @@ int main(int argc, char **argv)
error_close_buffer_access:
if (close(fp) == -1)
perror("Failed to close buffer");
error_free_buffer_access:
free(buffer_access);
error_free_data:
......@@ -424,6 +431,7 @@ int main(int argc, char **argv)
error_free_triggername:
if (datardytrigger)
free(trigger_name);
error_free_dev_dir_name:
free(dev_dir_name);
......
......@@ -13,7 +13,6 @@
*
* Usage:
* iio_event_monitor <device_name>
*
*/
#include <unistd.h>
......@@ -209,7 +208,8 @@ static void print_event(struct iio_event_data *event)
if (!event_is_known(event)) {
printf("Unknown event: time: %lld, id: %llx\n",
event->timestamp, event->id);
event->timestamp, event->id);
return;
}
......@@ -229,6 +229,7 @@ static void print_event(struct iio_event_data *event)
if (dir != IIO_EV_DIR_NONE)
printf(", direction: %s", iio_ev_dir_text[dir]);
printf("\n");
}
......@@ -251,14 +252,16 @@ int main(int argc, char **argv)
dev_num = find_type_by_name(device_name, "iio:device");
if (dev_num >= 0) {
printf("Found IIO device with name %s with device number %d\n",
device_name, dev_num);
device_name, dev_num);
ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
if (ret < 0) {
return -ENOMEM;
}
} else {
/* If we can't find a IIO device by name assume device_name is a
IIO chrdev */
/*
* If we can't find an IIO device by name assume device_name is
* an IIO chrdev
*/
chrdev_name = strdup(device_name);
if (!chrdev_name)
return -ENOMEM;
......
This diff is collapsed.
......@@ -51,17 +51,16 @@ struct iio_channel_info {
};
int iioutils_break_up_name(const char *full_name, char **generic_name);
int iioutils_get_type(unsigned *is_signed, unsigned *bytes,
unsigned *bits_used, unsigned *shift,
uint64_t *mask, unsigned *be,
const char *device_dir, const char *name,
const char *generic_name);
int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
unsigned *shift, uint64_t *mask, unsigned *be,
const char *device_dir, const char *name,
const char *generic_name);
int iioutils_get_param_float(float *output, const char *param_name,
const char *device_dir, const char *name,
const char *generic_name);
const char *device_dir, const char *name,
const char *generic_name);
void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt);
int build_channel_array(const char *device_dir,
struct iio_channel_info **ci_array, int *counter);
struct iio_channel_info **ci_array, int *counter);
int find_type_by_name(const char *name, const char *type);
int write_sysfs_int(const char *filename, const char *basedir, int val);
int write_sysfs_int_and_verify(const char *filename, const char *basedir,
......
......@@ -20,7 +20,6 @@
#include <sys/dir.h>
#include "iio_utils.h"
static enum verbosity {
VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */
VERBLEVEL_SENSORS, /* 1 lists sensors */
......@@ -29,17 +28,16 @@ static enum verbosity {
const char *type_device = "iio:device";
const char *type_trigger = "trigger";
static inline int check_prefix(const char *str, const char *prefix)
{
return strlen(str) > strlen(prefix) &&
strncmp(str, prefix, strlen(prefix)) == 0;
strncmp(str, prefix, strlen(prefix)) == 0;
}
static inline int check_postfix(const char *str, const char *postfix)
{
return strlen(str) > strlen(postfix) &&
strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
}
static int dump_channels(const char *dev_dir_name)
......@@ -50,11 +48,11 @@ static int dump_channels(const char *dev_dir_name)
dp = opendir(dev_dir_name);
if (dp == NULL)
return -errno;
while (ent = readdir(dp), ent != NULL)
if (check_prefix(ent->d_name, "in_") &&
check_postfix(ent->d_name, "_raw")) {
check_postfix(ent->d_name, "_raw"))
printf(" %-10s\n", ent->d_name);
}
return (closedir(dp) == -1) ? -errno : 0;
}
......@@ -69,6 +67,7 @@ static int dump_one_device(const char *dev_dir_name)
"%i", &dev_idx);
if (retval != 1)
return -EINVAL;
retval = read_sysfs_string("name", dev_dir_name, name);
if (retval)
return retval;
......@@ -77,6 +76,7 @@ static int dump_one_device(const char *dev_dir_name)
if (verblevel >= VERBLEVEL_SENSORS)
return dump_channels(dev_dir_name);
return 0;
}
......@@ -90,11 +90,13 @@ static int dump_one_trigger(const char *dev_dir_name)
"%i", &dev_idx);
if (retval != 1)
return -EINVAL;
retval = read_sysfs_string("name", dev_dir_name, name);
if (retval)
return retval;
printf("Trigger %03d: %s\n", dev_idx, name);
return 0;
}
......@@ -151,6 +153,7 @@ static int dump_devices(void)
free(dev_dir_name);
}
}
return (closedir(dp) == -1) ? -errno : 0;
error_close_dir:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment