Re: Re: [PATCH v3] hwmon: (sht4x): add heater support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I've been thinking on how to approach the problem of NACKs received
from the sensor while the heater is on but I haven't found
a perfectly satisfying solution either. This is due to the fact that
the device does not provide any way to check if the heater is on/off.

1. I guess that the simplest possible approach would involve sleeping
in `heater_enable_store()`:
  
  ssize_t heater_enable_store() {
    ...
    mutex_lock(data->lock);
    ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
    msleep(...) /* for >100 or >1000 ms */
    mutex_unlock(data->lock);
    ...
  }

This way, the user would have to wait for the heating to complete in
order to read RH or temperature measurement. However, I find this
solution unacceptable since it's completely unnecessary for the user
to wait for the heating to complete.

2. A better solution could be possibly to use a wait queue in order
to defer the job of enabling the heater:

  struct sht4x_data {
    ...
    struct work_struct* heater_work; /* This would be initialized
                                        with the handler described
                                        below */
  }

The task of sending the "heater_enable" command and sleeping would be
performed by the worker function:

  static void heater_enable_handler(struct work_struct *work) {
    ...
    mutex_lock(data->lock);
    ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
    msleep(...) /* for >100 or >1000 ms */
    mutex_unlock(data->lock);
    ...
  }

And that above mentioned work would be scheduled
in `heater_enable_store()`:

  ssize_t heater_enable_store() {
    ...
    schedule_work(data->heater_work);
    ...
  }

I think that this approach with work queue is better since the user
doesn't have to wait for the heating to complete and the RH or
temperature measurements can also be retrieved without the NACK error
(even though the user still may have to wait for the heater to be
off), since the `data->lock` mutex is used to guard both measurement
reads from the sensor and the heating in `heater_enable_handler`.

I'm worried though about the situation where the user writes 1 to
"heater_enable" while it's already enabled. Since the `work_struct`
is already on the queue, the `heater_enable_store` would return an
error and I see no easy solution to this for now.

Regards,
Antoni Pokusinski




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux