View Source VCNL4040.DeviceConfig (VCNL4040 v0.1.7)

Module for managing device configuration.

Typically applied during VCNL4040.start_link/1 or with VCNL4040.set_device_config/2.

There are some utility functions but much of the API-surface is based on the naming conventions in the datasheet.

Examples

iex> import VCNL4040.DeviceConfig
iex> new() |> update!(:als_conf, als_it: 320)
%VCNL4040.DeviceConfig{config: %{
    als_conf: %{
      als_it: 320,
      als_int_en: false,
      als_pers: 1,
      als_sd: true
    }
  },
  registers: %{
    als_conf: <<129>>
  }
}

Summary

Functions

Ambient Light Sensor configuration.

Convenience for starting Ambient Light Sensor functionality.

Sets high threshold for Ambient Light Sensor interrupt.

Sets low threshold for Ambient Light Sensor interrupt.

Sets high threshold for Ambient Light Sensor interrupt.

Sets low threshold for Ambient Light Sensor interrupt.

Get all writable registers, ready for I2C writing.

Output a binary appropriate for writing to I2C.

Merges the second configuration onto the first.

Create a new blank DeviceConfig.

Proximity sensor configuration, part 1.

Proximity sensor configuration, part 2

Proximity sensor configuration, part 3

Convenience for starting Proximity Sensor without interrupts.

Proximity sensor - More Settings?

This will set a DeviceConfig register based on the output of a register function.

This will granularly update a DeviceConfig.

Types

@type t() :: %VCNL4040.DeviceConfig{config: map(), registers: map()}

Functions

Link to this function

als_conf(kv \\ [], d \\ nil)

View Source
@spec als_conf(
  %{
    als_it: 80 | 160 | 320 | 640,
    als_pers: 1 | 2 | 4 | 8,
    als_int_en: boolean(),
    als_sd: boolean()
  }
  | [{atom(), term()}],
  map() | nil
) :: {:als_conf, binary(), map()}

Ambient Light Sensor configuration.

Returns a tuple tagged by field with binary and config map.

Link to this function

als_for_polling(integration_time_ms \\ 80, persistence_times \\ 1)

View Source

Convenience for starting Ambient Light Sensor functionality.

No interrupts configured.

Link to this function

als_thdh(high \\ 0, _ \\ nil)

View Source
@spec als_thdh(high :: non_neg_integer(), default :: non_neg_integer() | nil) ::
  {:als_thdh, binary(), non_neg_integer()}

Sets high threshold for Ambient Light Sensor interrupt.

Returns a tuple tagged by field with binary and value.

Link to this function

als_thdl(low \\ 0, _ \\ nil)

View Source
@spec als_thdl(high :: non_neg_integer(), default :: non_neg_integer() | nil) ::
  {:als_thdl, binary(), non_neg_integer()}

Sets low threshold for Ambient Light Sensor interrupt.

Returns a tuple tagged by field with binary and value.

Link to this function

als_threshold_high(high \\ 0)

View Source
@spec als_threshold_high(high :: non_neg_integer()) ::
  {:als_thdh, binary(), non_neg_integer()}

Sets high threshold for Ambient Light Sensor interrupt.

Alias for als_thdh with better name.

Returns a tuple tagged by field with binary and value.

Link to this function

als_threshold_low(low \\ 0)

View Source
@spec als_threshold_low(low :: non_neg_integer()) ::
  {:als_thdl, binary(), non_neg_integer()}

Sets low threshold for Ambient Light Sensor interrupt.

Alias for als_thdl with better name.

Returns a tuple tagged by field with binary and value.

Link to this function

als_with_interrupts(low_threshold, high_threshold, integration_time_ms \\ 80, persistence_times \\ 1)

View Source

Convenience for starting Ambient Light Sensor functionality.

Configures interrupts with thresholds.

Link to this function

get_all_registers_for_i2c(c)

View Source

Get all writable registers, ready for I2C writing.

Link to this function

get_register_for_i2c(c, label)

View Source

Output a binary appropriate for writing to I2C.

Label is a writable register as an atom, example: :als_conf or :ps_conf2

Return value includes 8-bit address prefixed to the payload.

Link to this macro

is_threshold(value)

View Source (macro)

Merges the second configuration onto the first.

This will override configuration at a sub-register or register level. It can be used to combine your settings for als_conf and ps_conf1 but not two different als_conf registers. The second one will win.

Create a new blank DeviceConfig.

A blank configuration will produce default values when used.

The defaults for this device include that both the Ambient Light Sensor and the Proximity Sensor are "shut down" aka turned off.

Link to this function

ps_canc(value \\ 0, _ \\ nil)

View Source
Link to this function

ps_cancellation(value \\ 0)

View Source
Link to this function

ps_conf1(kv \\ [], d \\ nil)

View Source
@spec ps_conf1(
  %{
    ps_duty: 40 | 80 | 160 | 320,
    ps_pers: 1 | 2 | 3 | 4,
    ps_it: :t1 | :t1_5 | :t2 | :t2_5 | :t3 | :t3_5 | :t4 | :t8,
    ps_sd: boolean()
  }
  | [{atom(), term()}],
  map() | nil
) :: {:ps_conf1, binary(), map()}

Proximity sensor configuration, part 1.

Duty cycle is 1/40, 1/80, 1/160, 1/320.

Returns a tuple tagged by field with binary and config map.

Link to this function

ps_conf2(kv \\ [], d \\ nil)

View Source
@spec ps_conf2(
  %{ps_hd: 12 | 16, ps_int: :disable | :close | :away | :both}
  | [{atom(), term()}],
  map() | nil
) :: {:ps_conf2, binary(), map()}

Proximity sensor configuration, part 2

Returns a tuple tagged by field with binary and config map.

Link to this function

ps_conf3(kv \\ [], d \\ nil)

View Source
@spec ps_conf3(
  %{
    ps_mps: 1 | 2 | 4 | 8,
    ps_smart_pers: boolean(),
    ps_af: boolean(),
    ps_trig: boolean(),
    ps_sc_en: boolean()
  }
  | [{atom(), term()}],
  map() | nil
) :: {:ps_conf3, binary(), map()}

Proximity sensor configuration, part 3

Returns a tuple tagged by field with binary and config map.

Link to this function

ps_for_polling(duty_cycle \\ 40, persistance_times \\ 1, integration_time \\ :t1)

View Source

Convenience for starting Proximity Sensor without interrupts.

Link to this function

ps_ms(kv \\ [], d \\ nil)

View Source
@spec ps_ms(
  %{
    white_en: boolean(),
    ps_ms: :normal | :detection,
    led_i: 50 | 75 | 100 | 120 | 140 | 160 | 180 | 200
  }
  | [{atom(), term()}],
  map() | nil
) :: {:ps_ms, binary(), map()}

Proximity sensor - More Settings?

ps_ms means detection logic mode, it will disable ALS interrupts.

Returns a tuple tagged by field with binary and config map.

Link to this function

ps_thdh(high \\ 0, _ \\ nil)

View Source
Link to this function

ps_thdl(low \\ 0, _ \\ nil)

View Source
Link to this function

ps_threshold_high(high \\ 0)

View Source
Link to this function

ps_threshold_low(low \\ 0)

View Source
Link to this function

ps_with_interrupts(low_threshold, high_threshold, interrupts \\ :both, duty_cycle \\ 40, persistance_times \\ 1, integration_time \\ :t1)

View Source

Convenience for starting Proximity Sensor with interrupts.

This will set a DeviceConfig register based on the output of a register function.

Returns the updated DeviceConfig struct.

Example

iex> import VCNL4040.DeviceConfig
iex> new() |> set!(als_conf(als_it: 320))
%VCNL4040.DeviceConfig{config: %{
    als_conf: %{
      als_it: 320,
      als_int_en: false,
      als_pers: 1,
      als_sd: true
    }
  },
  registers: %{
    als_conf: <<129>>
  }
}

This will granularly update a DeviceConfig.

Returns the updated DeviceConfig struct.

Example

iex> import VCNL4040.DeviceConfig
iex> new() |> update!(:als_conf, als_it: 320) |> update!(:als_conf, als_pers: 2)
%VCNL4040.DeviceConfig{config: %{
    als_conf: %{
      als_it: 320,
      als_int_en: false,
      als_pers: 1,
      als_sd: true
    }
  },
  registers: %{
    als_conf: <<129>>
  }
}