# `SHT4X`
[🔗](https://github.com/elixir-sensors/sht4x/blob/v0.3.3/lib/sht4x.ex#L7)

Use Sensirion SHT4X humidity and temperature sensors in Elixir

# `compensation_callback`

```elixir
@type compensation_callback() :: (SHT4X.Measurement.t() -&gt; SHT4X.Measurement.t())
```

Compensation callback function

# `option`

```elixir
@type option() ::
  {:debug, GenServer.debug()}
  | {:name, GenServer.name()}
  | {:timeout, timeout()}
  | {:spawn_opt, [Process.spawn_opt()]}
  | {:hibernate_after, timeout()}
  | {:bus_name, binary()}
  | {:retries, pos_integer()}
  | {:compensation_callback, compensation_callback()}
  | {:measurement_interval, pos_integer()}
  | {:repeatability, :low | :medium | :high}
  | {:stale_threshold, pos_integer()}
```

SHT4X GenServer start_link options

* `:name` - a name for the GenServer
* `:bus_name` - which I2C bus to use (e.g., `"i2c-1"`)
* `:retries` - the number of retries before failing (defaults to 2 retries)
* `:compensation_callback` - a function that takes in a `SHT4X.Measurement.t()` and returns a potentially modified `SHT4X.Measurement.t()`
* `:measurement_interval` - how often data will be read from the sensor (defaults to 5_000 ms)
* `:repeatability` - accuracy of the requested sensor read (`:low`, `:medium`, or `:high`)
* `:stale_threshold` - number of milliseconds a sample can remain the current sample before it is marked stale
* Also accepts all other standard `GenServer` start_link options

# `options`

```elixir
@type options() :: [option()]
```

# `quality`

```elixir
@type quality() :: :fresh | :stale | :unusable | :converging
```

How "fresh" is the sample we fetched from the sensor's GenServer?

In the event that the sensor fails to report back a measurement during a polling interval, we re-use the last sample.
If this continues to happen over a time period that exceeds the `:stale_threshold`, we mark the re-used "current" sample as stale.

The possible values can be:
- `:fresh` - This is a recent sample. See the `:stale_threshold`.
- `:stale` - This is an old sample that should be used with caution.
- `:unusable` - This is a default sample when no measurements are available, or, the sensor is giving know bad values (see: https://github.com/elixir-sensors/sht4x/issues/29)
- `:converging` - This is optionally set by the temperature compensation algorithm to indicate that it was recently restarted without historic state information and needs more time to give accurate values

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_sample`

```elixir
@spec get_sample(GenServer.server()) :: SHT4X.Measurement.t()
```

Fetches the latest sample from the sensor's GenServer

This does not cause an on-demand read from the sensor. Check the `:quality`
field for a quick assessment of how much to trust the measurement.

# `serial_number`

```elixir
@spec serial_number(GenServer.server()) :: {:ok, 0..4_294_967_295} | {:error, any()}
```

Return the sensor's serial number

# `soft_reset`

```elixir
@spec soft_reset(GenServer.server()) :: :ok | {:error, any()}
```

Send a soft reset command to the sensor

# `start_link`

```elixir
@spec start_link(options()) :: GenServer.on_start()
```

Start a new GenServer for interacting with a SHT4X.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
