From: Jonathan Cameron <jic23@kernel.org> To: Brian Masney <masneyb@onstation.org> Cc: devel@driverdev.osuosl.org, lars@metafoo.de, linux-iio@vger.kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Jon.Brenner@ams.com, pmeerw@pmeerw.net, knaack.h@gmx.de Subject: Re: [PATCH 04/11] staging: iio: tsl2x7x: simplify tsl2x7x_prox_cal() Date: Sat, 24 Mar 2018 13:35:32 +0000 [thread overview] Message-ID: <20180324133532.053d3a12@archlinux> (raw) In-Reply-To: <20180321102912.5130-5-masneyb@onstation.org> On Wed, 21 Mar 2018 06:29:05 -0400 Brian Masney <masneyb@onstation.org> wrote: > tsl2x7x_prox_cal() would set the interrupt flag, and reset the device to > start doing the calibration routine. However, this did not actually > affect the readings since they are polled. This patch drops the interrupt > code. > > This patch also drops the function tsl2x7x_prox_calculate() and removes > support for the standard deviation and min sample since those values > were not used. > > Driver was tested using a TSL2772 hooked up to a Raspberry Pi 2. I > performed the following testing at various distances: > > - Put hand in front of sensor and keep the sensor and hand stationary. > - Perform calibration routine. > - Run iio_event_monitor. > - Verify that a proximity event is triggered when my hand comes > anywhere between the sensor and where I performed the calibration > routine. > > Signed-off-by: Brian Masney <masneyb@onstation.org> Applied. Thanks, Jonathan > --- > drivers/staging/iio/light/tsl2x7x.c | 107 +++++------------------------------- > 1 file changed, 15 insertions(+), 92 deletions(-) > > diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c > index 9c929e273135..99230d9313e1 100644 > --- a/drivers/staging/iio/light/tsl2x7x.c > +++ b/drivers/staging/iio/light/tsl2x7x.c > @@ -149,13 +149,6 @@ struct tsl2x7x_als_info { > u16 lux; > }; > > -struct tsl2x7x_prox_stat { > - int min; > - int max; > - int mean; > - unsigned long stddev; > -}; > - > struct tsl2x7x_chip_info { > int chan_table_elements; > struct iio_chan_spec channel[4]; > @@ -771,106 +764,36 @@ static int tsl2x7x_invoke_change(struct iio_dev *indio_dev) > return ret; > } > > -static void tsl2x7x_prox_calculate(int *data, int length, > - struct tsl2x7x_prox_stat *stat) > -{ > - int i; > - int sample_sum; > - int tmp; > - > - if (!length) > - length = 1; > - > - sample_sum = 0; > - stat->min = INT_MAX; > - stat->max = INT_MIN; > - for (i = 0; i < length; i++) { > - sample_sum += data[i]; > - stat->min = min(stat->min, data[i]); > - stat->max = max(stat->max, data[i]); > - } > - > - stat->mean = sample_sum / length; > - sample_sum = 0; > - for (i = 0; i < length; i++) { > - tmp = data[i] - stat->mean; > - sample_sum += tmp * tmp; > - } > - stat->stddev = int_sqrt((long)sample_sum / length); > -} > - > -/** > - * tsl2x7x_prox_cal() - Calculates std. and sets thresholds. > - * @indio_dev: pointer to IIO device > - * > - * Calculates a standard deviation based on the samples, > - * and sets the threshold accordingly. > - */ > static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) > { > - int prox_history[MAX_SAMPLES_CAL + 1]; > - int i, ret; > - struct tsl2x7x_prox_stat prox_stat_data[2]; > - struct tsl2x7x_prox_stat *cal; > struct tsl2X7X_chip *chip = iio_priv(indio_dev); > - u8 tmp_irq_settings; > - u8 current_state = chip->tsl2x7x_chip_status; > - > - if (chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) { > - dev_err(&chip->client->dev, > - "max prox samples cal is too big: %d\n", > - chip->settings.prox_max_samples_cal); > - chip->settings.prox_max_samples_cal = MAX_SAMPLES_CAL; > - } > - > - /* have to stop to change settings */ > - ret = tsl2x7x_chip_off(indio_dev); > - if (ret < 0) > - return ret; > - > - /* Enable proximity detection save just in case prox not wanted yet*/ > - tmp_irq_settings = chip->settings.interrupts_en; > - chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL; > + int prox_history[MAX_SAMPLES_CAL + 1]; > + int i, ret, mean, max, sample_sum; > > - /*turn on device if not already on*/ > - ret = tsl2x7x_chip_on(indio_dev); > - if (ret < 0) > - return ret; > + if (chip->settings.prox_max_samples_cal < 1 || > + chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) > + return -EINVAL; > > - /*gather the samples*/ > for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { > usleep_range(15000, 17500); > ret = tsl2x7x_get_prox(indio_dev); > if (ret < 0) > return ret; > + > prox_history[i] = chip->prox_data; > - dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", > - i, chip->prox_data); > } > > - ret = tsl2x7x_chip_off(indio_dev); > - if (ret < 0) > - return ret; > - cal = &prox_stat_data[PROX_STAT_CAL]; > - tsl2x7x_prox_calculate(prox_history, > - chip->settings.prox_max_samples_cal, cal); > - chip->settings.prox_thres_high = (cal->max << 1) - cal->mean; > - > - dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n", > - cal->min, cal->mean, cal->max); > - dev_info(&chip->client->dev, > - "%s proximity threshold set to %d\n", > - chip->client->name, chip->settings.prox_thres_high); > - > - /* back to the way they were */ > - chip->settings.interrupts_en = tmp_irq_settings; > - if (current_state == TSL2X7X_CHIP_WORKING) { > - ret = tsl2x7x_chip_on(indio_dev); > - if (ret < 0) > - return ret; > + sample_sum = 0; > + max = INT_MIN; > + for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { > + sample_sum += prox_history[i]; > + max = max(max, prox_history[i]); > } > + mean = sample_sum / chip->settings.prox_max_samples_cal; > > - return 0; > + chip->settings.prox_thres_high = (max << 1) - mean; > + > + return tsl2x7x_invoke_change(indio_dev); > } > > static ssize_t _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23@kernel.org> To: Brian Masney <masneyb@onstation.org> Cc: linux-iio@vger.kernel.org, gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org, Jon.Brenner@ams.com Subject: Re: [PATCH 04/11] staging: iio: tsl2x7x: simplify tsl2x7x_prox_cal() Date: Sat, 24 Mar 2018 13:35:32 +0000 [thread overview] Message-ID: <20180324133532.053d3a12@archlinux> (raw) In-Reply-To: <20180321102912.5130-5-masneyb@onstation.org> On Wed, 21 Mar 2018 06:29:05 -0400 Brian Masney <masneyb@onstation.org> wrote: > tsl2x7x_prox_cal() would set the interrupt flag, and reset the device to > start doing the calibration routine. However, this did not actually > affect the readings since they are polled. This patch drops the interrupt > code. > > This patch also drops the function tsl2x7x_prox_calculate() and removes > support for the standard deviation and min sample since those values > were not used. > > Driver was tested using a TSL2772 hooked up to a Raspberry Pi 2. I > performed the following testing at various distances: > > - Put hand in front of sensor and keep the sensor and hand stationary. > - Perform calibration routine. > - Run iio_event_monitor. > - Verify that a proximity event is triggered when my hand comes > anywhere between the sensor and where I performed the calibration > routine. > > Signed-off-by: Brian Masney <masneyb@onstation.org> Applied. Thanks, Jonathan > --- > drivers/staging/iio/light/tsl2x7x.c | 107 +++++------------------------------- > 1 file changed, 15 insertions(+), 92 deletions(-) > > diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c > index 9c929e273135..99230d9313e1 100644 > --- a/drivers/staging/iio/light/tsl2x7x.c > +++ b/drivers/staging/iio/light/tsl2x7x.c > @@ -149,13 +149,6 @@ struct tsl2x7x_als_info { > u16 lux; > }; > > -struct tsl2x7x_prox_stat { > - int min; > - int max; > - int mean; > - unsigned long stddev; > -}; > - > struct tsl2x7x_chip_info { > int chan_table_elements; > struct iio_chan_spec channel[4]; > @@ -771,106 +764,36 @@ static int tsl2x7x_invoke_change(struct iio_dev *indio_dev) > return ret; > } > > -static void tsl2x7x_prox_calculate(int *data, int length, > - struct tsl2x7x_prox_stat *stat) > -{ > - int i; > - int sample_sum; > - int tmp; > - > - if (!length) > - length = 1; > - > - sample_sum = 0; > - stat->min = INT_MAX; > - stat->max = INT_MIN; > - for (i = 0; i < length; i++) { > - sample_sum += data[i]; > - stat->min = min(stat->min, data[i]); > - stat->max = max(stat->max, data[i]); > - } > - > - stat->mean = sample_sum / length; > - sample_sum = 0; > - for (i = 0; i < length; i++) { > - tmp = data[i] - stat->mean; > - sample_sum += tmp * tmp; > - } > - stat->stddev = int_sqrt((long)sample_sum / length); > -} > - > -/** > - * tsl2x7x_prox_cal() - Calculates std. and sets thresholds. > - * @indio_dev: pointer to IIO device > - * > - * Calculates a standard deviation based on the samples, > - * and sets the threshold accordingly. > - */ > static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) > { > - int prox_history[MAX_SAMPLES_CAL + 1]; > - int i, ret; > - struct tsl2x7x_prox_stat prox_stat_data[2]; > - struct tsl2x7x_prox_stat *cal; > struct tsl2X7X_chip *chip = iio_priv(indio_dev); > - u8 tmp_irq_settings; > - u8 current_state = chip->tsl2x7x_chip_status; > - > - if (chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) { > - dev_err(&chip->client->dev, > - "max prox samples cal is too big: %d\n", > - chip->settings.prox_max_samples_cal); > - chip->settings.prox_max_samples_cal = MAX_SAMPLES_CAL; > - } > - > - /* have to stop to change settings */ > - ret = tsl2x7x_chip_off(indio_dev); > - if (ret < 0) > - return ret; > - > - /* Enable proximity detection save just in case prox not wanted yet*/ > - tmp_irq_settings = chip->settings.interrupts_en; > - chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL; > + int prox_history[MAX_SAMPLES_CAL + 1]; > + int i, ret, mean, max, sample_sum; > > - /*turn on device if not already on*/ > - ret = tsl2x7x_chip_on(indio_dev); > - if (ret < 0) > - return ret; > + if (chip->settings.prox_max_samples_cal < 1 || > + chip->settings.prox_max_samples_cal > MAX_SAMPLES_CAL) > + return -EINVAL; > > - /*gather the samples*/ > for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { > usleep_range(15000, 17500); > ret = tsl2x7x_get_prox(indio_dev); > if (ret < 0) > return ret; > + > prox_history[i] = chip->prox_data; > - dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", > - i, chip->prox_data); > } > > - ret = tsl2x7x_chip_off(indio_dev); > - if (ret < 0) > - return ret; > - cal = &prox_stat_data[PROX_STAT_CAL]; > - tsl2x7x_prox_calculate(prox_history, > - chip->settings.prox_max_samples_cal, cal); > - chip->settings.prox_thres_high = (cal->max << 1) - cal->mean; > - > - dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n", > - cal->min, cal->mean, cal->max); > - dev_info(&chip->client->dev, > - "%s proximity threshold set to %d\n", > - chip->client->name, chip->settings.prox_thres_high); > - > - /* back to the way they were */ > - chip->settings.interrupts_en = tmp_irq_settings; > - if (current_state == TSL2X7X_CHIP_WORKING) { > - ret = tsl2x7x_chip_on(indio_dev); > - if (ret < 0) > - return ret; > + sample_sum = 0; > + max = INT_MIN; > + for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { > + sample_sum += prox_history[i]; > + max = max(max, prox_history[i]); > } > + mean = sample_sum / chip->settings.prox_max_samples_cal; > > - return 0; > + chip->settings.prox_thres_high = (max << 1) - mean; > + > + return tsl2x7x_invoke_change(indio_dev); > } > > static ssize_t
next prev parent reply other threads:[~2018-03-24 13:35 UTC|newest] Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-21 10:29 [PATCH 00/11] staging: iio: tsl2x7x: staging cleanups Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-21 10:29 ` [PATCH 01/11] staging: iio: tsl2x7x: remove unnecessary code Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:32 ` Jonathan Cameron 2018-03-24 13:32 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 02/11] staging: iio: tsl2x7x: correct interrupt handler trigger Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:33 ` Jonathan Cameron 2018-03-24 13:33 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 03/11] staging: iio: tsl2x7x: no need to clear interrupt flag when getting lux Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:34 ` Jonathan Cameron 2018-03-24 13:34 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 04/11] staging: iio: tsl2x7x: simplify tsl2x7x_prox_cal() Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:35 ` Jonathan Cameron [this message] 2018-03-24 13:35 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 05/11] staging: iio: tsl2x7x: split out als and prox interrupt settings Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:36 ` Jonathan Cameron 2018-03-24 13:36 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 06/11] staging: iio: tsl2x7x: make logging consistent and correct newlines Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:39 ` Jonathan Cameron 2018-03-24 13:39 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 07/11] staging: iio: tsl2x7x: split out als and prox persistence settings Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:40 ` Jonathan Cameron 2018-03-24 13:40 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 08/11] staging: iio: tsl2x7x: remove unused variables from tsl2x7x_get_lux() Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:41 ` Jonathan Cameron 2018-03-24 13:41 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 09/11] staging: iio: tsl2x7x: remove ch0 and ch1 " Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:42 ` Jonathan Cameron 2018-03-24 13:42 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 10/11] staging: iio: tsl2x7x: put local variables in reverse Christmas tree order Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:44 ` Jonathan Cameron 2018-03-24 13:44 ` Jonathan Cameron 2018-03-21 10:29 ` [PATCH 11/11] staging: iio: tsl2x7x: add copyright Brian Masney 2018-03-21 10:29 ` Brian Masney 2018-03-24 13:46 ` Jonathan Cameron 2018-03-24 13:46 ` Jonathan Cameron
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=20180324133532.053d3a12@archlinux \ --to=jic23@kernel.org \ --cc=Jon.Brenner@ams.com \ --cc=devel@driverdev.osuosl.org \ --cc=gregkh@linuxfoundation.org \ --cc=knaack.h@gmx.de \ --cc=lars@metafoo.de \ --cc=linux-iio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=masneyb@onstation.org \ --cc=pmeerw@pmeerw.net \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.