Skip to content

Commit

Permalink
tools: iio: Add single-byte case for generic_buffer
Browse files Browse the repository at this point in the history
Some sensors export data in an 8-bit format.
Add a single-byte case for the generic_buffer tool so that
these sensors' buffer data can be visualized.

Signed-off-by: Tiberiu Breana <[email protected]>
Reviewed-by: Hartmut Knaack <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
btiberiu authored and jic23 committed Jul 5, 2015
1 parent 12ebb05 commit e8d0927
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tools/iio/generic_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
return bytes;
}

void print1byte(uint8_t input, struct iio_channel_info *info)
{
/*
* Shift before conversion to avoid sign extension
* of left aligned data
*/
input >>= info->shift;
input &= info->mask;
if (info->is_signed) {
int8_t val = (int8_t)(input << (8 - info->bits_used)) >>
(8 - info->bits_used);
printf("%05f ", ((float)val + info->offset) * info->scale);
} else {
printf("%05f ", ((float)input + info->offset) * info->scale);
}
}

void print2byte(uint16_t input, struct iio_channel_info *info)
{
/* First swap if incorrect endian */
Expand Down Expand Up @@ -152,6 +169,10 @@ void process_scan(char *data,
for (k = 0; k < num_channels; k++)
switch (channels[k].bytes) {
/* only a few cases implemented so far */
case 1:
print1byte(*(uint8_t *)(data + channels[k].location),
&channels[k]);
break;
case 2:
print2byte(*(uint16_t *)(data + channels[k].location),
&channels[k]);
Expand Down

0 comments on commit e8d0927

Please sign in to comment.