Device-Chip-MPL3115A2
view release on metacpan or search on metacpan
Reads the WHO_AM_I register and checks for a valid ID result. The
returned future fails if the expected result is not received.
start_oneshot
await $chip->start_oneshot;
Sets the OST bit of CTRL_REG1 to start a one-shot measurement when in
standby mode. After calling this method you will need to use
busywait_oneshot to wait for the measurement to finish, or rely somehow
on the interrupts.
busywait_oneshot
await $chip->busywait_oneshot;
Repeatedly reads the OST bit of CTRL_REG1 until it becomes clear.
oneshot
await $chip->oneshot;
A convenient wrapper around start_oneshot and busywait_oneshot.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
lib/Device/Chip/MPL3115A2.pm view on Meta::CPAN
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; });
}
t/03trigger.t view on Meta::CPAN
# TODO: This only needs to read one of the bytes in practice
$adapter->expect_write_then_read( "\x26", 3 )
->will_done( "\x00\x00\x00" );
$adapter->expect_write( "\x26" . "\x02" );
await $chip->start_oneshot;
$adapter->check_and_clear( '$chip->start_oneshot' );
}
# busywait_oneshot
{
$adapter->expect_write_then_read( "\x26", 1 )
->will_done( "\x02" );
$adapter->expect_write_then_read( "\x26", 1 )
->will_done( "\x02" );
$adapter->expect_write_then_read( "\x26", 1 )
->will_done( "\x00" );
await $chip->busywait_oneshot;
$adapter->check_and_clear( '$chip->busywait_oneshot' );
}
# oneshot
{
# CTRLREG is cached so no re-read here
$adapter->expect_write( "\x26" . "\x02" );
$adapter->expect_write_then_read( "\x26", 1 )
->will_done( "\x02" );
$adapter->expect_write_then_read( "\x26", 1 )
->will_done( "\x02" );
( run in 0.508 second using v1.01-cache-2.11-cpan-87723dcf8b7 )