Switch to Wafer.
This commit is contained in:
parent
3a5e044326
commit
5001dfded6
16
LICENSE
Normal file
16
LICENSE
Normal file
|
@ -0,0 +1,16 @@
|
|||
Copyright 2020 James Harton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
* No Harm: The software may not be used by anyone for systems or activities that actively and knowingly endanger, harm, or otherwise threaten the physical, mental, economic, or general well-being of other individuals or groups, in violation of the United Nations Universal Declaration of Human Rights (https://www.un.org/en/universal-declaration-human-rights/).
|
||||
|
||||
* Services: If the Software is used to provide a service to others, the licensee shall, as a condition of use, require those others not to use the service in any way that violates the No Harm clause above.
|
||||
|
||||
* Enforceability: If any portion or provision of this License shall to any extent be declared illegal or unenforceable by a court of competent jurisdiction, then the remainder of this License, or the application of such portion or provision in circumstances other than those as to which it is so declared illegal or unenforceable, shall not be affected thereby, and each portion and provision of this Agreement shall be valid and enforceable to the fullest extent permitted by law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
This Hippocratic License is an Ethical Source license (https://ethicalsource.dev) derived from the MIT License, amended to limit the impact of the unethical use of open source software.
|
||||
|
1802
lib/mpl3115a2.ex
1802
lib/mpl3115a2.ex
File diff suppressed because it is too large
Load diff
|
@ -1,23 +0,0 @@
|
|||
defmodule MPL3115A2.Application do
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
# for more information on OTP Applications
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
{Registry, keys: :unique, name: MPL3115A2.Registry}
|
||||
]
|
||||
|
||||
devices =
|
||||
:mpl3115a2
|
||||
|> Application.get_env(:devices, [])
|
||||
|> Enum.map(&{MPL3115A2.Device, &1})
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
# for other strategies and supported options
|
||||
opts = [strategy: :one_for_one, name: MPL3115A2.Supervisor]
|
||||
Supervisor.start_link(children ++ devices, opts)
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load diff
|
@ -1,234 +0,0 @@
|
|||
defmodule MPL3115A2.Device do
|
||||
alias MPL3115A2.{Device, Commands}
|
||||
alias ElixirALE.I2C
|
||||
use GenServer
|
||||
require Logger
|
||||
|
||||
@moduledoc """
|
||||
A process which manages the MPL3115A2 peripheral.
|
||||
"""
|
||||
|
||||
@type device_name :: any
|
||||
@type altitude :: non_neg_integer()
|
||||
@type pressure :: non_neg_integer()
|
||||
@type temperature :: number
|
||||
|
||||
@doc """
|
||||
Returns true of there is pressure or temperature data ready for reading.
|
||||
"""
|
||||
@spec pressure_or_temperature_data_ready?(pid | device_name) :: boolean
|
||||
def pressure_or_temperature_data_ready?(pid) when is_pid(pid),
|
||||
do: GenServer.call(pid, :pressure_or_temperature_data_ready?)
|
||||
|
||||
def pressure_or_temperature_data_ready?(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:pressure_or_temperature_data_ready?
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns true of there is pressure data ready for reading.
|
||||
"""
|
||||
@spec pressure_data_available?(pid | device_name) :: boolean
|
||||
def pressure_data_available?(pid) when is_pid(pid),
|
||||
do: GenServer.call(pid, :pressure_data_available?)
|
||||
|
||||
def pressure_data_available?(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:pressure_data_available?
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns true of there is temperature data ready for reading.
|
||||
"""
|
||||
@spec temperature_data_available?(pid | device_name) :: boolean
|
||||
def temperature_data_available?(pid) when is_pid(pid),
|
||||
do: GenServer.call(pid, :temperature_data_available?)
|
||||
|
||||
def temperature_data_available?(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:temperature_data_available?
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the current altutude (in meters).
|
||||
"""
|
||||
@spec altitude(pid | device_name) :: altitude
|
||||
def altitude(pid) when is_pid(pid), do: GenServer.call(pid, :altitude)
|
||||
|
||||
def altitude(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:altitude
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the current barometric pressure (in Pascals).
|
||||
"""
|
||||
@spec pressure(pid | device_name) :: pressure
|
||||
def pressure(pid) when is_pid(pid), do: GenServer.call(pid, :pressure)
|
||||
|
||||
def pressure(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:pressure
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the current temperature (in ℃)
|
||||
"""
|
||||
@spec temperature(pid | device_name) :: temperature
|
||||
def temperature(pid) when is_pid(pid), do: GenServer.call(pid, :temperature)
|
||||
|
||||
def temperature(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:temperature
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the change in altitude since the last sample (in meters).
|
||||
"""
|
||||
@spec altitude_delta(pid | device_name) :: altitude
|
||||
def altitude_delta(pid) when is_pid(pid), do: GenServer.call(pid, :altitude_delta)
|
||||
|
||||
def altitude_delta(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:altitude_delta
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the change in pressure since the last sample (in Pascals).
|
||||
"""
|
||||
@spec pressure_delta(pid | device_name) :: pressure
|
||||
def pressure_delta(pid) when is_pid(pid), do: GenServer.call(pid, :pressure_delta)
|
||||
|
||||
def pressure_delta(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:pressure_delta
|
||||
)
|
||||
|
||||
@doc """
|
||||
Returns the change in temperature since the last sample (in ℃)
|
||||
"""
|
||||
@spec temperature_delta(pid | device_name) :: temperature
|
||||
def temperature_delta(pid) when is_pid(pid), do: GenServer.call(pid, :temperature_delta)
|
||||
|
||||
def temperature_delta(device_name),
|
||||
do:
|
||||
GenServer.call(
|
||||
{:via, Registry, {MPL3115A2.Registry, device_name}},
|
||||
:temperature_delta
|
||||
)
|
||||
|
||||
@doc """
|
||||
Execute an arbitrary function with the PID of the I2C connection.
|
||||
"""
|
||||
@spec execute(pid | device_name, (pid -> any)) :: any
|
||||
def execute(pid, function) when is_pid(pid) and is_function(function, 1),
|
||||
do: GenServer.call(pid, {:execute, function})
|
||||
|
||||
def execute(device_name, function) when is_function(function, 1),
|
||||
do: GenServer.call({:via, Registry, {MPL3115A2.Registry, device_name}}, {:execute, function})
|
||||
|
||||
@doc false
|
||||
def start_link(config), do: GenServer.start_link(Device, config)
|
||||
|
||||
@impl true
|
||||
def init(%{bus: bus, address: address} = state) do
|
||||
name = device_name(state)
|
||||
|
||||
{:ok, _} = Registry.register(MPL3115A2.Registry, name, self())
|
||||
Process.flag(:trap_exit, true)
|
||||
|
||||
Logger.info("Connecting to MPL3115A2 device on #{inspect(name)}")
|
||||
|
||||
{:ok, pid} = I2C.start_link(bus, address)
|
||||
|
||||
with 0xC4 <- Commands.who_am_i(pid),
|
||||
:ok <- Commands.initialize!(pid, state) do
|
||||
state =
|
||||
state
|
||||
|> Map.merge(%{name: name, i2c: pid})
|
||||
|
||||
{:ok, state}
|
||||
else
|
||||
i when is_integer(i) ->
|
||||
{:stop, "Device responded incorrectly to WHO_AM_I command with #{inspect(i)}"}
|
||||
|
||||
{:error, message} ->
|
||||
{:stop, message}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def terminate(_reason, %{i2c: pid, name: name}) do
|
||||
Logger.info("Disconnecting from MPL3115A2 device on #{inspect(name)}")
|
||||
I2C.release(pid)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call(:pressure_or_temperature_data_ready?, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.pressure_or_temperature_data_ready(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:pressure_data_available?, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.pressure_data_available(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:temperature_data_available?, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.temperature_data_available(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:altitude, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.altitude(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:temperature, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.temperature(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:pressure, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.pressure(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:altitude_delta, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.altitude_delta(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:temperature_delta, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.temperature_delta(pid), state}
|
||||
end
|
||||
|
||||
def handle_call(:pressure_delta, _from, %{i2c: pid} = state) do
|
||||
{:reply, Commands.pressure_delta(pid), state}
|
||||
end
|
||||
|
||||
def handle_call({:execute, function}, _from, %{i2c: pid} = state) do
|
||||
{:reply, function.(pid), state}
|
||||
end
|
||||
|
||||
@doc false
|
||||
def child_spec(config) do
|
||||
%{
|
||||
id: {MPL3115A2.Device, device_name(config)},
|
||||
start: {MPL3115A2.Device, :start_link, [config]},
|
||||
restart: :transient
|
||||
}
|
||||
end
|
||||
|
||||
defp device_name(%{bus: bus, address: address} = config),
|
||||
do: Map.get(config, :name, {bus, address})
|
||||
end
|
|
@ -1,317 +1,55 @@
|
|||
defmodule MPL3115A2.Registers do
|
||||
use Bitwise
|
||||
alias ElixirALE.I2C
|
||||
use Wafer.Registers
|
||||
|
||||
@moduledoc """
|
||||
This module provides a wrapper around the MPL3115A2 registers
|
||||
described in Freescale's data sheet.
|
||||
|
||||
Don't access these directly unless you know what you're doing.
|
||||
It's better to use the `Commands` module instead.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
STATUS register; 0x00; 1 byte, RO
|
||||
"""
|
||||
def status(pid), do: read_register(pid, 0)
|
||||
|
||||
@doc """
|
||||
OUT_P_MSB register; 0x01, 1 byte, RO
|
||||
OUT_P_CSB register; 0x02, 1 byte, RO
|
||||
OUT_P_LSB register; 0x03, 1 byte, RO
|
||||
"""
|
||||
def pressure_data_out(pid) do
|
||||
with msb <- read_register(pid, 1),
|
||||
csb <- read_register(pid, 2),
|
||||
lsb <- read_register(pid, 3),
|
||||
do: msb <> csb <> lsb
|
||||
end
|
||||
|
||||
@doc """
|
||||
OUT_T_MSB register; 0x04, 1 byte, RO
|
||||
OUT_T_LSB register; 0x05, 1 byte, RO
|
||||
"""
|
||||
def temperature_data_out(pid) do
|
||||
with msb <- read_register(pid, 4),
|
||||
lsb <- read_register(pid, 5),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
@doc """
|
||||
DR_STATUS register; 0x06, 1 byte, RO
|
||||
"""
|
||||
def data_ready_status(pid), do: read_register(pid, 6)
|
||||
|
||||
@doc """
|
||||
OUT_P_DELTA_MSB register; 0x07, 1 byte, RO
|
||||
OUT_P_DELTA_CSB register; 0x08, 1 byte, RO
|
||||
OUT_P_DELTA_LSB register; 0x09, 1 byte, RO
|
||||
"""
|
||||
def pressure_data_out_delta(pid) do
|
||||
with msb <- read_register(pid, 7),
|
||||
csb <- read_register(pid, 8),
|
||||
lsb <- read_register(pid, 9),
|
||||
do: msb <> csb <> lsb
|
||||
end
|
||||
|
||||
@doc """
|
||||
OUT_T_DELTA_MSB register; 0x0a, 1 byte, RO
|
||||
OUT_T_DELTA_LSB register; 0x0b, 1 byte, RO
|
||||
"""
|
||||
def temperature_data_out_delta(pid) do
|
||||
with msb <- read_register(pid, 0xA),
|
||||
lsb <- read_register(pid, 0xB),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
@doc """
|
||||
WHO_AM_I register; 0x0c, 1 byte, RO
|
||||
"""
|
||||
def who_am_i(pid), do: read_register(pid, 0xC)
|
||||
|
||||
@doc """
|
||||
F_STATUS register; 0x0d, 1 byte, RO
|
||||
"""
|
||||
def fifo_status(pid), do: read_register(pid, 0xD)
|
||||
|
||||
@doc """
|
||||
F_DATA register; 0x0e, 1 byte, RO
|
||||
"""
|
||||
def fifo_data_access(pid), do: read_register(pid, 0xE)
|
||||
|
||||
@doc """
|
||||
F_SETUP register; 0x0f, 1 byte, RW
|
||||
"""
|
||||
def fifo_setup(pid), do: read_register(pid, 0xF)
|
||||
def fifo_setup(pid, value), do: write_register(pid, 0xF, value)
|
||||
|
||||
@doc """
|
||||
TIME_DLY register; 0x10, 1 byte, RO
|
||||
"""
|
||||
def time_delay(pid), do: read_register(pid, 0x10)
|
||||
|
||||
@doc """
|
||||
SYSMOD register; 0x11, 1 byte, RO
|
||||
"""
|
||||
def system_mode(pid), do: read_register(pid, 0x11)
|
||||
|
||||
@doc """
|
||||
INT_SOURCE register; 0x12, 1 byte, RO
|
||||
"""
|
||||
def interrupt_source(pid), do: read_register(pid, 0x12)
|
||||
|
||||
@doc """
|
||||
PT_DATA_CFG register; 0x13, 1 byte, RW
|
||||
"""
|
||||
def pt_data_configuration(pid), do: read_register(pid, 0x13)
|
||||
def pt_data_configuration(pid, value), do: write_register(pid, 0x13, value)
|
||||
|
||||
@doc """
|
||||
BAR_IN_MSB register; 0x14, 1 byte, RW
|
||||
BAR_IN_LSB register; 0x15, 1 byte, RW
|
||||
"""
|
||||
def barometric_input(pid) do
|
||||
with msb <- read_register(pid, 0x14),
|
||||
lsb <- read_register(pid, 0x15),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
def barometric_input(pid, value) do
|
||||
msb = value >>> 8 &&& 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x14, msb),
|
||||
:ok <- write_register(pid, 0x15, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
P_TGT_MSB register; 0x16, 1 byte, RW
|
||||
P_TGT_LSB register; 0x17, 1 byte, RW
|
||||
"""
|
||||
def pressure_target(pid) do
|
||||
with msb <- read_register(pid, 0x16),
|
||||
lsb <- read_register(pid, 0x17),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
def pressure_target(pid, value) do
|
||||
msb = value >>> 8 &&& 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x16, msb),
|
||||
:ok <- write_register(pid, 0x17, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
T_TGT register; 0x18, 1 byte, RO
|
||||
"""
|
||||
def temperature_target(pid), do: read_register(pid, 0x18)
|
||||
def temperature_target(pid, value), do: write_register(pid, 0x18, value)
|
||||
|
||||
@doc """
|
||||
P_WND_MSB register; 0x19, 1 byte, RW
|
||||
P_WND_LSB register; 0x1a, 1 byte, RW
|
||||
"""
|
||||
def pressure_altitude_window(pid) do
|
||||
with msb <- read_register(pid, 0x19),
|
||||
lsb <- read_register(pid, 0x1A),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
def pressure_altitude_window(pid, value) do
|
||||
msb = value >>> 8 &&& 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x19, msb),
|
||||
:ok <- write_register(pid, 0x1A, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
T_WND register; 0x1b, 1 byte, RW
|
||||
"""
|
||||
def temperature_window(pid), do: read_register(pid, 0x1B)
|
||||
def temperature_window(pid, value), do: write_register(pid, 0x1B, value)
|
||||
|
||||
@doc """
|
||||
P_MIN_MSB register; 0x1c, 1 byte, RW
|
||||
P_MIN_CSB register; 0x1d, 1 byte, RW
|
||||
P_MIN_LSB register; 0x1e, 1 byte, RW
|
||||
"""
|
||||
def minimum_pressure_data(pid) do
|
||||
with msb <- read_register(pid, 0x1C),
|
||||
csb <- read_register(pid, 0x1D),
|
||||
lsb <- read_register(pid, 0x1E),
|
||||
do: msb <> csb <> lsb
|
||||
end
|
||||
|
||||
def minimum_pressure_data(pid, value) do
|
||||
msb = value >>> 16 &&& 0xFF
|
||||
csb = value >>> 8 &&& 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x1C, msb),
|
||||
:ok <- write_register(pid, 0x1D, csb),
|
||||
:ok <- write_register(pid, 0x1E, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
T_MIN_MSB register; 0x1f, 1 byte, RW
|
||||
T_MIN_LSB register; 0x20, 1 byte, RW
|
||||
"""
|
||||
def minimum_temperature_data(pid) do
|
||||
with msb <- read_register(pid, 0x1F),
|
||||
lsb <- read_register(pid, 0x20),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
def minimum_temperature_data(pid, value) do
|
||||
msb = value >>> 8 && 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x1F, msb),
|
||||
:ok <- write_register(pid, 0x20, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
P_MAX_MSB register, 0x21, 1 byte, RW
|
||||
P_MAX_CSB register, 0x22, 1 byte, RW
|
||||
P_MAX_LSB register, 0x23, 1 byte, RW
|
||||
"""
|
||||
def maximum_pressure_data(pid) do
|
||||
with msb <- read_register(pid, 0x21),
|
||||
csb <- read_register(pid, 0x22),
|
||||
lsb <- read_register(pid, 0x23),
|
||||
do: msb <> csb <> lsb
|
||||
end
|
||||
|
||||
def maximum_pressure_data(pid, value) do
|
||||
msb = value >>> 16 &&& 0xFF
|
||||
csb = value >>> 8 &&& 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x21, msb),
|
||||
:ok <- write_register(pid, 0x22, csb),
|
||||
:ok <- write_register(pid, 0x23, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
T_MAX_MSB register; 0x24, 1 byte, RW
|
||||
T_MAX_LSB register; 0x25, 1 byte, RW
|
||||
"""
|
||||
def maximum_temperature_data(pid) do
|
||||
with msb <- read_register(pid, 0x24),
|
||||
lsb <- read_register(pid, 0x25),
|
||||
do: msb <> lsb
|
||||
end
|
||||
|
||||
def maximum_temperature_data(pid, value) do
|
||||
msb = value >>> 8 && 0xFF
|
||||
lsb = value &&& 0xFF
|
||||
|
||||
with :ok <- write_register(pid, 0x24, msb),
|
||||
:ok <- write_register(pid, 0x25, lsb),
|
||||
do: :ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
CTRL_REG1 register; 1 byte, 0x26, RW
|
||||
"""
|
||||
def control_register1(pid), do: read_register(pid, 0x26)
|
||||
def control_register1(pid, value), do: write_register(pid, 0x26, value)
|
||||
|
||||
@doc """
|
||||
CTRL_REG2 register; 1 byte, 0x27, RW
|
||||
"""
|
||||
def control_register2(pid), do: read_register(pid, 0x27)
|
||||
def control_register2(pid, value), do: write_register(pid, 0x27, value)
|
||||
|
||||
@doc """
|
||||
CTRL_REG3 register; 1 byte, 0x28, RW
|
||||
"""
|
||||
def control_register3(pid), do: read_register(pid, 0x28)
|
||||
def control_register3(pid, value), do: write_register(pid, 0x28, value)
|
||||
|
||||
@doc """
|
||||
CTRL_REG4 register; 1 byte, 0x29, RW
|
||||
"""
|
||||
def control_register4(pid), do: read_register(pid, 0x29)
|
||||
def control_register4(pid, value), do: write_register(pid, 0x29, value)
|
||||
|
||||
@doc """
|
||||
CTRL_REG5 register; 1 byte, 0x2a, RW
|
||||
"""
|
||||
def control_register5(pid), do: read_register(pid, 0x2A)
|
||||
def control_register5(pid, value), do: write_register(pid, 0x2A, value)
|
||||
|
||||
@doc """
|
||||
OFF_P register; 1 byte, 0x2b, RW
|
||||
"""
|
||||
def pressure_data_user_offset(pid), do: read_register(pid, 0x2B)
|
||||
def pressure_data_user_offset(pid, value), do: write_register(pid, 0x2B, value)
|
||||
|
||||
@doc """
|
||||
OFF_T register; 1 byte, 0x2c, RW
|
||||
"""
|
||||
def temperature_data_user_offset(pid), do: read_register(pid, 0x2C)
|
||||
def temperature_data_user_offset(pid, value), do: write_register(pid, 0x2C, value)
|
||||
|
||||
@doc """
|
||||
OFF_H register; 1 byte, 0x2d, RW
|
||||
"""
|
||||
def altitude_data_user_offset(pid), do: read_register(pid, 0x2D)
|
||||
def altitude_data_user_offset(pid, value), do: write_register(pid, 0x2D, value)
|
||||
|
||||
defp read_register(pid, register) do
|
||||
I2C.write_read(pid, <<register>>, 1)
|
||||
end
|
||||
|
||||
defp write_register(pid, register, value) do
|
||||
I2C.write(pid, <<register, value>>)
|
||||
end
|
||||
defregister(:status, 0x00, :ro, 1)
|
||||
defregister(:out_p_msb, 0x01, :ro, 1)
|
||||
defregister(:out_p_csb, 0x02, :ro, 1)
|
||||
defregister(:out_p_lsb, 0x03, :ro, 1)
|
||||
defregister(:out_t_msb, 0x04, :ro, 1)
|
||||
defregister(:out_t_lsb, 0x05, :ro, 1)
|
||||
defregister(:dr_status, 0x06, :ro, 1)
|
||||
defregister(:out_p_delta_msb, 0x07, :ro, 1)
|
||||
defregister(:out_p_delta_csb, 0x08, :ro, 1)
|
||||
defregister(:out_p_delta_lsb, 0x09, :ro, 1)
|
||||
defregister(:out_t_delta_msb, 0x0A, :ro, 1)
|
||||
defregister(:out_t_delta_lsb, 0x0B, :ro, 1)
|
||||
defregister(:who_am_i, 0x0C, :ro, 1)
|
||||
defregister(:f_status, 0x0D, :ro, 1)
|
||||
defregister(:f_data, 0x0E, :ro, 1)
|
||||
defregister(:f_setup, 0x0F, :rw, 1)
|
||||
defregister(:time_dly, 0x10, :ro, 1)
|
||||
defregister(:sysmod, 0x11, :ro, 1)
|
||||
defregister(:int_source, 0x12, :ro, 1)
|
||||
defregister(:pt_data_cfg, 0x13, :rw, 1)
|
||||
defregister(:bar_in_msb, 0x14, :rw, 1)
|
||||
defregister(:bar_in_lsb, 0x15, :rw, 1)
|
||||
defregister(:p_tgt_msb, 0x16, :rw, 1)
|
||||
defregister(:p_tgt_lsb, 0x17, :rw, 1)
|
||||
defregister(:t_tgt, 0x18, :rw, 1)
|
||||
defregister(:p_wnd_msb, 0x19, :rw, 1)
|
||||
defregister(:p_wnd_lsb, 0x1A, :rw, 1)
|
||||
defregister(:t_wnd, 0x1B, :rw, 1)
|
||||
defregister(:p_min_msb, 0x1C, :rw, 1)
|
||||
defregister(:p_min_csb, 0x1D, :rw, 1)
|
||||
defregister(:p_min_lsb, 0x1E, :rw, 1)
|
||||
defregister(:t_min_msb, 0x1F, :rw, 1)
|
||||
defregister(:t_min_lsb, 0x20, :rw, 1)
|
||||
defregister(:p_max_msb, 0x21, :rw, 1)
|
||||
defregister(:p_max_csb, 0x22, :rw, 1)
|
||||
defregister(:p_max_lsb, 0x23, :rw, 1)
|
||||
defregister(:t_max_msb, 0x24, :rw, 1)
|
||||
defregister(:t_max_lsb, 0x25, :rw, 1)
|
||||
defregister(:ctrl_reg1, 0x26, :rw, 1)
|
||||
defregister(:ctrl_reg2, 0x27, :rw, 1)
|
||||
defregister(:ctrl_reg3, 0x28, :rw, 1)
|
||||
defregister(:ctrl_reg4, 0x29, :rw, 1)
|
||||
defregister(:ctrl_reg5, 0x2A, :rw, 1)
|
||||
defregister(:off_p, 0x2B, :rw, 1)
|
||||
defregister(:off_t, 0x2C, :rw, 1)
|
||||
defregister(:off_h, 0x2D, :rw, 1)
|
||||
end
|
||||
|
|
14
mix.exs
14
mix.exs
|
@ -16,15 +16,14 @@ defmodule MPL3115A2.MixProject do
|
|||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger],
|
||||
mod: {MPL3115A2.Application, []}
|
||||
extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
def package do
|
||||
[
|
||||
maintainers: ["James Harton <james@automat.nz>"],
|
||||
licenses: ["MIT"],
|
||||
licenses: ["Hippocratic"],
|
||||
links: %{
|
||||
"Source" => "https://gitlab.com/jimsy/mpl3115a2"
|
||||
}
|
||||
|
@ -34,8 +33,13 @@ defmodule MPL3115A2.MixProject do
|
|||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{:elixir_ale, "~> 1.2"},
|
||||
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
|
||||
{:circuits_i2c, "~> 0.3", optional: true},
|
||||
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
|
||||
{:earmark, ">= 0.0.0", only: [:dev, :test]},
|
||||
{:elixir_ale, "~> 1.2", optional: true},
|
||||
{:ex_doc, ">= 0.0.0", only: [:dev, :test]},
|
||||
{:mimic, "~> 1.1", only: :test},
|
||||
{:wafer, "~> 0.1"}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
6
mix.lock
6
mix.lock
|
@ -1,9 +1,15 @@
|
|||
%{
|
||||
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
|
||||
"circuits_i2c": {:hex, :circuits_i2c, "0.3.6", "348b8de3cf1ade6c4b92ad7c9de7068df1af0d441df341d7d126d53671924f64", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"credo": {:hex, :credo, "1.1.5", "caec7a3cadd2e58609d7ee25b3931b129e739e070539ad1a0cd7efeeb47014f4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"earmark": {:hex, :earmark, "1.4.1", "07bb382826ee8d08d575a1981f971ed41bd5d7e86b917fd012a93c51b5d28727", [:mix], [], "hexpm"},
|
||||
"elixir_ale": {:hex, :elixir_ale, "1.2.1", "07ac2f17a0191b8bd3b0df6b526c7f699a3a4d690c9def573fcb5824eef24d98", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"mimic": {:hex, :mimic, "1.1.3", "3bad83d5271b4faa7bbfef587417a6605cbbc802a353395d446a1e5f46fe7115", [:mix], [], "hexpm"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"},
|
||||
"wafer": {:hex, :wafer, "0.1.0", "8ca31024770f77ff1457a5ae413ae0158e9a713bd8c65aeeb0d7426ca36439e2", [:mix], [{:circuits_gpio, "~> 0.4", [hex: :circuits_gpio, repo: "hexpm", optional: true]}, {:circuits_i2c, "~> 0.3", [hex: :circuits_i2c, repo: "hexpm", optional: true]}, {:circuits_spi, "~> 0.1", [hex: :circuits_spi, repo: "hexpm", optional: true]}, {:elixir_ale, "~> 1.2", [hex: :elixir_ale, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
defmodule MPL3115A2Test do
|
||||
use ExUnit.Case
|
||||
doctest MPL3115A2
|
||||
|
||||
test "greets the world" do
|
||||
assert MPL3115A2.hello() == :world
|
||||
end
|
||||
end
|
4
test/mpl3115a2_test.exs
Normal file
4
test/mpl3115a2_test.exs
Normal file
|
@ -0,0 +1,4 @@
|
|||
defmodule MPL3115A2Test do
|
||||
use ExUnit.Case
|
||||
doctest MPL3115A2
|
||||
end
|
Loading…
Reference in a new issue