summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorTiberiu Breana <tiberiu.a.breana@intel.com>2015-07-03 05:57:36 -0400
committerJonathan Cameron <jic23@kernel.org>2015-07-05 07:27:33 -0400
commite8d0927a19f11cebc4381f5f0cac8fa37154b08a (patch)
treefc886523ad9fa8c15674d3b24309cd686aa4b7ad /tools/iio
parent12ebb05246338aa9cdee51da50f57237352b3f64 (diff)
tools: iio: Add single-byte case for generic_buffer
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 <tiberiu.a.breana@intel.com> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/generic_buffer.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index fc362d2ff983..0e737238ca74 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -61,6 +61,23 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
61 return bytes; 61 return bytes;
62} 62}
63 63
64void print1byte(uint8_t input, struct iio_channel_info *info)
65{
66 /*
67 * Shift before conversion to avoid sign extension
68 * of left aligned data
69 */
70 input >>= info->shift;
71 input &= info->mask;
72 if (info->is_signed) {
73 int8_t val = (int8_t)(input << (8 - info->bits_used)) >>
74 (8 - info->bits_used);
75 printf("%05f ", ((float)val + info->offset) * info->scale);
76 } else {
77 printf("%05f ", ((float)input + info->offset) * info->scale);
78 }
79}
80
64void print2byte(uint16_t input, struct iio_channel_info *info) 81void print2byte(uint16_t input, struct iio_channel_info *info)
65{ 82{
66 /* First swap if incorrect endian */ 83 /* First swap if incorrect endian */
@@ -152,6 +169,10 @@ void process_scan(char *data,
152 for (k = 0; k < num_channels; k++) 169 for (k = 0; k < num_channels; k++)
153 switch (channels[k].bytes) { 170 switch (channels[k].bytes) {
154 /* only a few cases implemented so far */ 171 /* only a few cases implemented so far */
172 case 1:
173 print1byte(*(uint8_t *)(data + channels[k].location),
174 &channels[k]);
175 break;
155 case 2: 176 case 2:
156 print2byte(*(uint16_t *)(data + channels[k].location), 177 print2byte(*(uint16_t *)(data + channels[k].location),
157 &channels[k]); 178 &channels[k]);