linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Cercueil, Paul" <Paul.Cercueil@analog.com>
To: "lars@metafoo.de" <lars@metafoo.de>,
	"geert@linux-m68k.org" <geert@linux-m68k.org>
Cc: "linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH libiio] iio-monitor: Add support for current and power
Date: Wed, 21 Dec 2016 17:04:41 +0000	[thread overview]
Message-ID: <1482339881.2295.1.camel@analog.com> (raw)
In-Reply-To: <1482329419-12442-1-git-send-email-geert@linux-m68k.org>

[-- Attachment #1: Type: text/plain, Size: 2349 bytes --]

Hi,
Le mercredi 21 décembre 2016 à 15:10 +0100, Geert Uytterhoeven a
écrit :
> Currently iio-monitor supports temperature and voltage values only.
> Everything else is treated like a voltage.
> 
> Add support for common values like current and power.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
>  examples/iio-monitor.c | 31 +++++++++++++++++++++++++++----
>  1 file changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/examples/iio-monitor.c b/examples/iio-monitor.c
> index 558c0f33a36ef7b9..b508049fdb5dfc3f 100644
> --- a/examples/iio-monitor.c
> +++ b/examples/iio-monitor.c
> @@ -93,6 +93,29 @@ static double get_channel_value(struct iio_channel
> *chn)
>  	return val / 1000.0;
>  }
>  
> +static struct {
> +	const char *id;
> +	const char *unit;
> +} map[] = {
> +	{ "current",	"A" },
> +	{ "power",	"W" },
> +	{ "temp",	"°C" },
> +	{ "voltage",	"V" },
> +	{ 0, },
> +};
> +
> +static const char *id_to_unit(const char *id)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; map[i].id; i++) {
> +		if (!strncmp(id, map[i].id, strlen(map[i].id)))
> +			return map[i].unit;
> +	}
> +
> +	return "";
> +}
> +
>  static void * read_thd(void *d)
>  {
>  	struct iio_context *ctx = d;
> @@ -131,7 +154,7 @@ static void * read_thd(void *d)
>  		nb_channels = iio_device_get_channels_count(dev);
>  		for (i = 0; i < nb_channels; i++) {
>  			const char *id;
> -			bool is_temp = false;
> +			const char *unit;
>  			struct iio_channel *chn =
>  				iio_device_get_channel(dev, i);
>  			if (!is_valid_channel(chn))
> @@ -142,7 +165,7 @@ static void * read_thd(void *d)
>  			id = iio_channel_get_id(chn);
>  			if (!name)
>  				name = id;
> -			is_temp = !strncmp(id, "temp", 4);
> +			unit = id_to_unit(id);
>  
>  			sprintf(buf, "</%u></B>%s<!B><!%u>",
>  					BLUE, name, BLUE);
> @@ -152,8 +175,8 @@ static void * read_thd(void *d)
>  			freeChtype(str);
>  
>  			sprintf(buf, "</%u></B>%.3lf %s<!B><!%u>",
> -					YELLOW,
> get_channel_value(chn),
> -					is_temp ? "°C" : "V",
> YELLOW);
> +					YELLOW,
> get_channel_value(chn), unit,
> +					YELLOW);
>  			str = char2Chtype(buf, &len, &align);
>  			writeChtype(right, col / 2, line++,
>  					str, HORIZONTAL, 0, len);

Applied. Thanks!

-Paul

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2016-12-21 17:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21 14:10 [PATCH libiio] iio-monitor: Add support for current and power Geert Uytterhoeven
2016-12-21 17:04 ` Cercueil, Paul [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482339881.2295.1.camel@analog.com \
    --to=paul.cercueil@analog.com \
    --cc=geert@linux-m68k.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).