Device::Chip::MPL3115A2 - chip driver for a MPL3115A2
Device::Chip::MPL3115A2
use Device::Chip::MPL3115A2; use Future::AsyncAwait; my $chip = Device::Chip::MPL3115A2->new; await $chip->mount( Device::Chip::Adapter::...->new ); printf "Current pressure is %.2f kPa\n", await $chip->read_pressure;
This Device::Chip subclass provides specific communication to a Freescale Semiconductor MPL3115A2 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.
await
$config = await $chip->read_config;
Returns a HASH reference of the contents of control registers CTRL_REG1 to CTRL_REG3, using fields named from the data sheet.
HASH
CTRL_REG1
CTRL_REG3
SBYB => "STANDBY" | "ACTIVE" OST => 0 | 1 RST => 0 | 1 OS => 1 | 2 | 4 | ... | 64 | 128 RAW => 0 | 1 ALT => 0 | 1 ST => 1 | 2 | 4 | ... | 16384 | 32768 ALARM_SEL => 0 | 1 LOAD_OUTPUT => 0 | 1 IPOL1 => 0 | 1 PP_OD1 => 0 | 1 IPOL2 => 0 | 1 PP_OD2 => 0 | 1
await $chip->change_config( %changes );
Writes updates to the control registers CTRL_REG1 to CTRL_REG3. This will be performed as a read-modify-write operation, so any fields not given as arguments to this method will retain their current values.
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 OST and RST bits.
OST
RST
$pressure = await $chip->get_sealevel_pressure; await $chip->set_sealevel_pressure( $pressure );
Read or write the barometric pressure calibration register which is used to convert pressure to altitude when the chip is in altimeter mode, in Pascals. The default value is 101,326 Pa.
$pressure = await $chip->read_pressure;
Returns the value of the OUT_P_* registers, suitably converted into Pascals. (The chip must be in barometer mode and must not be in RAW mode for the conversion to work).
OUT_P_*
RAW
$altitude = await $chip->read_altitude;
Returns the value of the OUT_P_* registers, suitably converted into metres. (The chip must be in altimeter mode and must not be in RAW mode for the conversion to work).
$temperature = await $chip->read_temperature;
Returns the value of the OUT_T_* registers, suitable converted into degrees C. (The chip must not be in RAW mode for the conversion to work).
OUT_T_*
$pressure = await $chip->read_min_pressure; $pressure = await $chip->read_max_pressure;
Returns the values of the P_MIN and P_MAX registers, suitably converted into Pascals.
P_MIN
P_MAX
await $chip->clear_min_pressure; await $chip->clear_max_pressure;
Clear the P_MIN or P_MAX registers, resetting them to start again from the next measurement.
$altitude = await $chip->read_min_altitude; $altitude = await $chip->read_max_altitude;
Returns the values of the P_MIN and P_MAX registers, suitably converted into metres.
await $chip->clear_min_altitude; await $chip->clear_max_altitude;
$temperature = await $chip->read_min_temperature; $temperature = await $chip->read_max_temperature;
Returns the values of the T_MIN and T_MAX registers, suitably converted into metres.
T_MIN
T_MAX
await $chip->clear_min_temperature; await $chip->clear_max_temperature;
Clear the T_MIN or T_MAX registers, resetting them to start again from the next measurement.
await $chip->check_id;
Reads the WHO_AM_I register and checks for a valid ID result. The returned future fails if the expected result is not received.
WHO_AM_I
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.
await $chip->oneshot;
A convenient wrapper around start_oneshot and busywait_oneshot.
start_oneshot
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip::MPL3115A2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::MPL3115A2
CPAN shell
perl -MCPAN -e shell install Device::Chip::MPL3115A2
For more information on module installation, please visit the detailed CPAN module installation guide.