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.
Convenience for starting Ambient Light Sensor functionality.
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?
Convenience for starting Proximity Sensor with interrupts.
This will set a DeviceConfig register based on the output of a register function.
This will granularly update a DeviceConfig.
Types
Functions
@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.
als_for_polling(integration_time_ms \\ 80, persistence_times \\ 1)
View SourceConvenience for starting Ambient Light Sensor functionality.
No interrupts configured.
@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.
@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.
@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.
@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.
als_with_interrupts(low_threshold, high_threshold, integration_time_ms \\ 80, persistence_times \\ 1)
View SourceConvenience for starting Ambient Light Sensor functionality.
Configures interrupts with thresholds.
Get all writable registers, ready for I2C writing.
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.
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.
@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.
@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.
@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.
ps_for_polling(duty_cycle \\ 40, persistance_times \\ 1, integration_time \\ :t1)
View SourceConvenience for starting Proximity Sensor without interrupts.
@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.
ps_with_interrupts(low_threshold, high_threshold, interrupts \\ :both, duty_cycle \\ 40, persistance_times \\ 1, integration_time \\ :t1)
View SourceConvenience 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>>
}
}