Device-Chip-MPL3115A2
view release on metacpan or search on metacpan
lib/Device/Chip/MPL3115A2.pm view on Meta::CPAN
=head2 read_max_temperature
$temperature = await $chip->read_min_temperature;
$temperature = await $chip->read_max_temperature;
Returns the values of the C<T_MIN> and C<T_MAX> registers, suitably converted
into metres.
=head2 clear_min_temperature
=head2 clear_max_temperature
await $chip->clear_min_temperature;
await $chip->clear_max_temperature;
Clear the C<T_MIN> or C<T_MAX> registers, resetting them to start again from
the next measurement.
=cut
async method read_min_temperature () { return await $self->_mplread_t( REG_T_MIN_MSB ) }
async method read_max_temperature () { return await $self->_mplread_t( REG_T_MAX_MSB ) }
async method clear_min_temperature () { return await $self->write_reg( REG_T_MIN_MSB, "\x00\x00" ) }
async method clear_max_temperature () { return await $self->write_reg( REG_T_MAX_MSB, "\x00\x00" ) }
=head1 METHODS
=cut
=head2 check_id
await $chip->check_id;
Reads the C<WHO_AM_I> register and checks for a valid ID result. The returned
future fails if the expected result is not received.
=cut
async method check_id ()
{
my $val = await $self->read_reg( REG_WHO_AM_I, 1 );
my $id = unpack "C", $val;
$id == WHO_AM_I_ID or
die sprintf "Incorrect response from WHO_AM_I register (got %02X, expected %02X)\n",
$id, WHO_AM_I_ID;
return $self;
}
=head2 start_oneshot
await $chip->start_oneshot;
Sets the C<OST> bit of C<CTRL_REG1> to start a one-shot measurement when in
standby mode. After calling this method you will need to use
C<busywait_oneshot> to wait for the measurement to finish, or rely somehow on
the interrupts.
=cut
async method start_oneshot ()
{
my $bytes = await $self->_cached_read_ctrlreg;
my $ctrl_reg1 = substr( $bytes, 0, 1 ) | "\x02"; # Set OST bit
await $self->write_reg( REG_CTRL_REG1, $ctrl_reg1 );
}
=head2 busywait_oneshot
await $chip->busywait_oneshot;
Repeatedly reads the C<OST> bit of C<CTRL_REG1> until it becomes clear.
=cut
async method busywait_oneshot ()
{
while(1) {
my $ctrl_reg1 = await $self->read_reg( REG_CTRL_REG1, 1 );
last if not( ord( $ctrl_reg1 ) & 0x02 );
}
}
=head2 oneshot
await $chip->oneshot;
A convenient wrapper around C<start_oneshot> and C<busywait_oneshot>.
=cut
async method oneshot ()
{
await $self->start_oneshot;
await $self->busywait_oneshot;
}
field $_pending_trigger;
method _next_trigger
{
return $_pending_trigger //=
$self->oneshot->on_ready(sub { undef $_pending_trigger; });
}
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
( run in 1.644 second using v1.01-cache-2.11-cpan-39bf76dae61 )