Skip to content

Commit

Permalink
tools:iio: adjust coding style
Browse files Browse the repository at this point in the history
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: Hartmut Knaack <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
Hartmut Knaack authored and jic23 committed Jun 13, 2015
1 parent 4f3ca89 commit 7663a4a
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 82 deletions.
46 changes: 27 additions & 19 deletions tools/iio/generic_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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);
}

Expand All @@ -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:
Expand All @@ -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);

Expand Down
13 changes: 8 additions & 5 deletions tools/iio/iio_event_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*
* Usage:
* iio_event_monitor <device_name>
*
*/

#include <unistd.h>
Expand Down Expand Up @@ -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;
}

Expand All @@ -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");
}

Expand All @@ -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;
Expand Down
Loading

0 comments on commit 7663a4a

Please sign in to comment.