NAME

Device::Chip::TSL256x - chip driver for TSL256x

SYNOPSIS

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;

DESCRIPTION

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.

ACCESSORS

The following methods documented in an await expression return Future instances.

read_config

$config = await $chip->read_config;

Returns a 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

change_config

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 Manual bit.

enable_agc

$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.

read_id

$id = await $chip->read_id;

Returns the chip's ID register value.

read_data0

read_data1

$data0 = await $chip->read_data0;

$data1 = await $chip->read_data1;

Reads the current values of the ADC channels.

read_data

( $data0, $data1 ) = await $chip->read_data;

Read the current values of both ADC channels in a single I²C transaction.

METHODS

power

await $chip->power( $on );

Enables or disables the main power control bits in the CONTROL register.

read_lux

$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 $data0 and $data1 channel values. The controlling code may wish to use these to adjust the gain if required.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>