View Source HTS221.Server (hts221 v1.1.0)

Server for setting up and using the HTS221

When controlling the HTS221 there are few setup steps and other checks you may want to do. Also, to keep the transport layer working often times this will call for a GenServer. This server is meant to provide common functionality around setup and an expose a higher level API for application use.

This process can be added to your supervision tree.

def MyApp do
  use Application

  def start(_type, _args) do
    children = [
      ... children ...
      {HTS221.Server, transport: {HTS221.Transport.I2C, [bus_name: "i2c-1"]}
      ... children ...
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start(children, opts)
  end
end

If you a custom transport implementation then the :transport argument to this server will look different.

If the HTS221 is not detected this server will log that it was not found and return :ignore on the GenServer.init/1 callback. This is useful if your FW will run on devices with different hardware attached and don't want the device availability to crash your application supervisor.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Read the humidity level

Read the temperature value

Get the transport the server is using

Link to this section Types

Specs

arg() ::
  {:transport,
   HTS221.Transport.impl() | {HTS221.Transport.impl(), [HTS221.Transport.arg()]}}
  | {:name, name()}

Arguments to the HTS221.Server

  • :transport - the transport implementation module and optional arguments
  • :name - this is a named GenServer that either uses what you pass in or HTS221.Server

Specs

name() :: any()

Specs

temperature_opt() :: {:scale, HTS221.scale()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

humidity(name()) :: {:ok, float()} | {:error, any()}

Read the humidity level

This is measured in percent.

Specs

start_link([arg()]) :: GenServer.on_start()
Link to this function

temperature(server, opts \\ [])

View Source

Specs

temperature(name(), [temperature_opt()]) :: {:ok, float()} | {:error, any()}

Read the temperature value

By default this is read in celsius you can the :scale option to change the unit the temperature is measured in. See HTS221.scale() for more information.

Specs

transport(name()) :: HTS221.Transport.t()

Get the transport the server is using

This is useful if you need to debug the registers using the functions in HTS221 module.