View Source VCNL4040 (VCNL4040 v0.1.7)
GenServer-based driver module for ambient light and proximity sensor combo.
See datasheet: https://www.vishay.com/docs/84274/vcnl4040.pdf Implementation notes: https://www.vishay.com/docs/84307/designingvcnl4040.pdf
Summary
Functions
Returns a specification to start this module under a supervisor.
Tell the driver to shut down open resources and exit.
Tell the driver to shut down open resources and exit.
Returns the current reading from the ambient light sensor
Returns the current filtered reading from the ambient light sensor.
Returns the current VCNL4040.DeviceConfig
struct.
Returns the current VCNL4040.DeviceConfig
struct.
Returns the current reading from the ambient light sensor.
Returns the current reading from the ambient light sensor.
Returns true if the combo prox/light sensor is present and matches the expected device ID.
Returns true if the combo prox/light sensor is present and matches the expected device ID.
Sets a new VCNL4040.DeviceConfig
and applies it to the hardware.
Sets a new VCNL4040.DeviceConfig
and applies it to the hardware.
Start the ambient light/proximity sensor driver
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec close() :: :ok
Tell the driver to shut down open resources and exit.
This assumes you registered your GenServer with name: VCNL4040
.
Returns :ok
@spec close(GenServer.server()) :: :ok
Tell the driver to shut down open resources and exit.
Returns :ok
@spec get_ambient_light(:filtered | :lux | :raw | :direct) :: number() | {:error, :no_sensor | :timeout | :noproc}
Returns the current reading from the ambient light sensor
This assumes you registered your GenServer with name: VCNL4040
.
The type
argument can be:
:filtered
- converted to lux and the median of the samples in the buffer, avoiding outliers.:lux
- latest read, converted to lux.:raw
- latest read, straight from the sensor. If you have some weird use for it.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec get_ambient_light(GenServer.server(), :filtered | :lux | :raw | :direct) :: number() | {:error, :no_sensor | :timeout | :noproc}
Returns the current filtered reading from the ambient light sensor.
The type
argument can be:
:filtered
- converted to lux and the median of the samples in the buffer, avoiding outliers.:lux
- latest read, converted to lux.:raw
- latest read, straight from the sensor. If you have some weird use for it.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec get_device_config() :: map() | {:error, :no_sensor | :timeout | :noproc}
Returns the current VCNL4040.DeviceConfig
struct.
This assumes you registered your GenServer with name: VCNL4040
.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec get_device_config(GenServer.server()) :: map() | {:error, :no_sensor | :timeout | :noproc}
Returns the current VCNL4040.DeviceConfig
struct.
This assumes you registered your GenServer with name: VCNL4040
.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
Returns the current reading from the ambient light sensor.
This assumes you registered your GenServer with name: VCNL4040
.
The type
argument can be:
:filtered
- converted to lux and the median of the samples in the buffer, avoiding outliers.:raw
- latest read, straight from the sensor. If you have some weird use for it.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
Returns the current reading from the ambient light sensor.
The type
argument can be:
:filtered
- converted to lux and the median of the samples in the buffer, avoiding outliers.:raw
- latest read, straight from the sensor. If you have some weird use for it.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec sensor_present?() :: boolean()
Returns true if the combo prox/light sensor is present and matches the expected device ID.
This assumes you registered your GenServer with name: VCNL4040
.
Returns a boolean indicating whether the sensor is present.
@spec sensor_present?(GenServer.server()) :: boolean()
Returns true if the combo prox/light sensor is present and matches the expected device ID.
@spec set_device_config(VCNL4040.DeviceConfig.t()) :: :ok | {:error, :no_sensor | :timeout | :noproc}
Sets a new VCNL4040.DeviceConfig
and applies it to the hardware.
This assumes you registered your GenServer with name: VCNL4040
.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec set_device_config(GenServer.server(), VCNL4040.DeviceConfig.t()) :: :ok | {:error, :no_sensor | :timeout | :noproc}
Sets a new VCNL4040.DeviceConfig
and applies it to the hardware.
Returns :timeout
or :noproc
if the GenServer times out or isn't running.
@spec start_link(keyword()) :: GenServer.on_start()
Start the ambient light/proximity sensor driver
Options:
:name
- regular GenServer registration name, makes public API functions more convenient if only using one sensor.:i2c_bus
- defaults to"i2c-0"
:notify_pid
- PID to notify on every sample pulled. Default: nil:device_config
- defaults to turning on ambient light sensor and proximity sensor for polling. Pass your ownDeviceConfig
to modify.:interrupt_pin
- required to enable interrupt-driven sensing, requires the hardware connection for GPIO INT pin set up:poll_interval
- millisecond interval for polling sensors. Set tonil
to disable. Default: 1000 (1 second):buffer_samples
- size of the internal circular buffer for filtered readings. Default: 9:als_enable?
- enable the Ambient Light Sensor immediately. Default: true (not hardware default):als_integration_time
- integration time for Ambient Light Sensor. Default: 80:ps_enable?
- enable the Proximity Sensor immediately. Default: true (not hardware default):ps_integration_time
- integration time for Proximity Sensor. Default: :t1 (weirdo time units, see data sheet?):log_samples?
- always print sample collection to log. Default: false:als_interrupt_tolerance
- enables automatic following of light level using interrupts. Default: nil