* [PATCH v2] tools: iio: Add single-byte case for generic_buffer
@ 2015-07-03 9:57 Tiberiu Breana
2015-07-04 13:38 ` Hartmut Knaack
2015-07-05 9:01 ` Hartmut Knaack
0 siblings, 2 replies; 4+ messages in thread
From: Tiberiu Breana @ 2015-07-03 9:57 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron
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>
---
v2: added the print1byte function to apply the channel shift and
address both signed and unsigned cases.
---
tools/iio/generic_buffer.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index fc362d2..0e73723 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)
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 */
@@ -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]);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] tools: iio: Add single-byte case for generic_buffer
2015-07-03 9:57 [PATCH v2] tools: iio: Add single-byte case for generic_buffer Tiberiu Breana
@ 2015-07-04 13:38 ` Hartmut Knaack
2015-07-05 11:27 ` Jonathan Cameron
2015-07-05 9:01 ` Hartmut Knaack
1 sibling, 1 reply; 4+ messages in thread
From: Hartmut Knaack @ 2015-07-04 13:38 UTC (permalink / raw)
To: Tiberiu Breana, linux-iio; +Cc: Jonathan Cameron
Tiberiu Breana schrieb am 03.07.2015 um 11:57:
> 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>
> ---
> v2: added the print1byte function to apply the channel shift and
> address both signed and unsigned cases.
> ---
> tools/iio/generic_buffer.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
> index fc362d2..0e73723 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)
> 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 */
> @@ -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 */
Not sure though how long we should keep that comment. ^^^^^
I probably had more reason to get rid of it during my rework.
> + case 1:
> + print1byte(*(uint8_t *)(data + channels[k].location),
> + &channels[k]);
> + break;
> case 2:
> print2byte(*(uint16_t *)(data + channels[k].location),
> &channels[k]);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] tools: iio: Add single-byte case for generic_buffer
2015-07-03 9:57 [PATCH v2] tools: iio: Add single-byte case for generic_buffer Tiberiu Breana
2015-07-04 13:38 ` Hartmut Knaack
@ 2015-07-05 9:01 ` Hartmut Knaack
1 sibling, 0 replies; 4+ messages in thread
From: Hartmut Knaack @ 2015-07-05 9:01 UTC (permalink / raw)
To: Tiberiu Breana, linux-iio; +Cc: Jonathan Cameron
Resending to see if vger.kernel.org is up again.
Tiberiu Breana schrieb am 03.07.2015 um 11:57:
> 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>
> ---
> v2: added the print1byte function to apply the channel shift and
> address both signed and unsigned cases.
> ---
> tools/iio/generic_buffer.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
> index fc362d2..0e73723 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)
> 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 */
> @@ -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 */
Not sure though how long we should keep that comment. ^^^^^
I probably had more reason to get rid of it during my rework.
> + case 1:
> + print1byte(*(uint8_t *)(data + channels[k].location),
> + &channels[k]);
> + break;
> case 2:
> print2byte(*(uint16_t *)(data + channels[k].location),
> &channels[k]);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] tools: iio: Add single-byte case for generic_buffer
2015-07-04 13:38 ` Hartmut Knaack
@ 2015-07-05 11:27 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2015-07-05 11:27 UTC (permalink / raw)
To: Hartmut Knaack, Tiberiu Breana, linux-iio
On 04/07/15 14:38, Hartmut Knaack wrote:
> Tiberiu Breana schrieb am 03.07.2015 um 11:57:
>> 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>
Applied to the togreg branch of iio.git.
Thanks,
Jonathan
>> ---
>> v2: added the print1byte function to apply the channel shift and
>> address both signed and unsigned cases.
>> ---
>> tools/iio/generic_buffer.c | 21 +++++++++++++++++++++
>> 1 file changed, 21 insertions(+)
>>
>> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
>> index fc362d2..0e73723 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)
>> 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 */
>> @@ -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 */
>
> Not sure though how long we should keep that comment. ^^^^^
> I probably had more reason to get rid of it during my rework.
>
>> + case 1:
>> + print1byte(*(uint8_t *)(data + channels[k].location),
>> + &channels[k]);
>> + break;
>> case 2:
>> print2byte(*(uint16_t *)(data + channels[k].location),
>> &channels[k]);
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-07-05 11:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-03 9:57 [PATCH v2] tools: iio: Add single-byte case for generic_buffer Tiberiu Breana
2015-07-04 13:38 ` Hartmut Knaack
2015-07-05 11:27 ` Jonathan Cameron
2015-07-05 9:01 ` Hartmut Knaack
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.