Device::Chip::TSL256x - chip driver for TSL256x
use Device::Chip::TSL256x; use Future::AsyncAwait; my $chip = Device::Chip::TSL256x->new; await $chip->mount( Device::Chip::Adapter::...->new ); await $chip->power(1); sleep 1; # Wait for one integration cycle printf "Current ambient light level is %.2f lux\n", scalar await $chip->read_lux;
This Device::Chip subclass provides specific communication to a TAOS TSL2560 or TSL2561 attached to a computer via an I²C adapter.
The reader is presumed to be familiar with the general operation of this chip; the documentation here will not attempt to explain or define chip-specific concepts or features, only the use of this module to access them.
The following methods documented in an
await expression return Future instances.
$config = await $chip->read_config;
HASH reference of the contents of control and timing registers, using fields named from the data sheet.
POWER => OFF | ON GAIN => 1 | 16 INTEG => 13ms | 101ms | 402ms
Additionally, the following keys are provided calculated from those, as a convenience.
integ_msec => 13.7 | 101 | 402
await $chip->change_config( %changes );
Writes updates to the control and timing registers.
Note that this method will ignore the
integ_msec convenience value.
Note that these two methods use a cache of configuration bytes to make subsequent modifications more efficient. This cache will not respect the "one-shot" nature of the
$chip->enable_agc( $agc )
Accessor for the internal gain-control algorithm. If enabled, the
GAIN configuration will be automatically controlled to switch between high- and low-level settings.
$id = await $chip->read_id;
Returns the chip's ID register value.
$data0 = await $chip->read_data0; $data1 = await $chip->read_data1;
Reads the current values of the ADC channels.
( $data0, $data1 ) = await $chip->read_data;
Read the current values of both ADC channels in a single I²C transaction.
await $chip->power( $on );
Enables or disables the main power control bits in the
$lux = await $chip->read_lux; ( $lux, $data0, $data1 ) = await $chip->read_lux;
Reads the two data registers then performs the appropriate scaling calculations to return a floating-point number that approximates the light level in Lux.
Currently this conversion code presumes the contants for the T, FN and CL chip types.
In list context, also returns the raw
$data1 channel values. The controlling code may wish to use these to adjust the gain if required.
Paul Evans <firstname.lastname@example.org>