chore: migrate to local (#23)
All checks were successful
continuous-integration/drone/push Build is passing

* Add Drone CI configuration
* Change URLs
* Remove Gitlab CI configuration

Reviewed-on: #23
Co-authored-by: James Harton <james@harton.nz>
Co-committed-by: James Harton <james@harton.nz>
This commit is contained in:
James Harton 2024-02-14 15:52:35 +13:00 committed by James Harton
parent 4658c6d13d
commit 16e91d3c47
10 changed files with 507 additions and 194 deletions

383
.drone.yml Normal file
View file

@ -0,0 +1,383 @@
kind: pipeline
type: docker
name: build
steps:
- name: restore ASDF cache
image: meltwater/drone-cache
pull: "always"
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
mount:
- .asdf
- name: restore build cache
image: meltwater/drone-cache
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
settings:
restore: true
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}'
mount:
- deps
- _build
- .hex
- .mix
- .rebar3
- name: install dependencies
image: harton.dev/james/asdf_container:latest
pull: "always"
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
ASDF_DIR: /root/.asdf
depends_on:
- restore ASDF cache
- restore build cache
commands:
- asdf_install
- rm -rf .asdf/downloads
- . $ASDF_DIR/asdf.sh
- mix local.hex --if-missing --force
- mix local.rebar --if-missing --force
- mix deps.get
- mix deps.compile
- mix dialyzer --plt
- name: store ASDF cache
image: meltwater/drone-cache
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
depends_on:
- install dependencies
settings:
rebuild: true
override: false
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'asdf-{{ os }}-{{ arch }}-{{ checksum ".tool-versions" }}'
mount:
- .asdf
- name: store build cache
image: meltwater/drone-cache
environment:
AWS_ACCESS_KEY_ID:
from_secret: ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: SECRET_ACCESS_KEY
AWS_PLUGIN_PATH_STYLE: true
depends_on:
- install dependencies
settings:
rebuild: true
override: false
endpoint:
from_secret: S3_ENDPOINT
bucket:
from_secret: CACHE_BUCKET
region: us-east-1
path-style: true
cache_key: 'elixir-{{ checksum "mix.lock" }}-{{ checksum ".tool-versions" }}'
mount:
- deps
- _build
- .hex
- .mix
- .rebar3
- name: mix compile
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- install dependencies
commands:
- asdf mix compile --warnings-as-errors
- name: mix test
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix test
- name: mix credo
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix credo --strict
- name: mix dialyzer
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix dialyzer
- name: mix hex.audit
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix hex.audit
- name: mix format
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix format --check-formatted
- name: mix deps.unlock
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix deps.unlock --check-unused
- name: mix doctor
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- asdf mix doctor --full
- name: mix git_ops.check_message
image: harton.dev/james/asdf_container:latest
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
depends_on:
- mix compile
commands:
- git log -1 --format=%s > .last_commit_message
- asdf mix git_ops.check_message .last_commit_message
- name: mix git_ops.release
image: harton.dev/james/asdf_container:latest
when:
branch:
- main
event:
exclude:
- pull_request
depends_on:
- mix test
- mix credo
- mix dialyzer
- mix hex.audit
- mix format
- mix deps.unlock
- mix doctor
- mix git_ops.check_message
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
ASDF_DIR: /root/.asdf
DRONE_TOKEN:
from_secret: DRONE_TOKEN
commands:
- git fetch --tags
- . $ASDF_DIR/asdf.sh
- mix git_ops.project_info --format=shell > before.env
- mix git_ops.release --yes --no-major || true
- mix git_ops.project_info --format=shell > after.env
- . ./before.env
- export OLD_APP_VERSION=$${APP_VERSION}
- . ./after.env
- export NEW_APP_VERSION=$${APP_VERSION}
- if [ "v$${OLD_APP_VERSION}" != "v$${NEW_APP_VERSION}" ]; then
- export GIT_URL=$(echo $DRONE_GIT_HTTP_URL | sed -e "s/:\\/\\//:\\/\\/$DRONE_REPO_OWNER:$DRONE_TOKEN@/")
- git push $${GIT_URL} "HEAD:${DRONE_COMMIT_REF}" "refs/tags/v$${NEW_APP_VERSION}"
- fi
- name: build artifacts
image: harton.dev/james/asdf_container:latest
when:
event:
- tag
refs:
include:
- refs/tags/v*
depends_on:
- mix test
- mix credo
- mix dialyzer
- mix hex.audit
- mix format
- mix deps.unlock
- mix doctor
- mix git_ops.check_message
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
ASDF_DIR: /root/.asdf
commands:
- . $ASDF_DIR/asdf.sh
- mix git_ops.project_info --format=shell > app.env
- . ./app.env
- mkdir artifacts
- mix hex.build -o "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar"
- gzip "artifacts/$${APP_NAME}-$${APP_VERSION}-pkg.tar"
- mix docs
- tar zcvf "artifacts/$${APP_NAME}-$${APP_VERSION}-docs.tar.gz" doc/
- git tag -l --format='%(contents:subject)' v$${APP_VERSION} > tag_subject
- git tag -l --format='%(contents:body)' v$${APP_VERSION} > tag_body
- name: gitea release
image: plugins/gitea-release
when:
event:
- tag
refs:
include:
- refs/tags/v*
depends_on:
- build artifacts
settings:
api_key:
from_secret: DRONE_TOKEN
base_url: https://harton.dev
files: artifacts/*.tar.gz
checksum: sha256
title: tag_subject
note: tag_body
- name: docs release
when:
event:
- tag
refs:
include:
- refs/tags/v*
image: minio/mc
environment:
S3_ENDPOINT:
from_secret: S3_ENDPOINT
ACCESS_KEY:
from_secret: ACCESS_KEY_ID
SECRET_KEY:
from_secret: SECRET_ACCESS_KEY
depends_on:
- build artifacts
commands:
- mc alias set store $${S3_ENDPOINT} $${ACCESS_KEY} $${SECRET_KEY}
- mc mb -p store/docs.harton.nz
- mc anonymous set download store/docs.harton.nz
- mc mirror --overwrite doc/ store/docs.harton.nz/$${DRONE_REPO}/$${DRONE_TAG}
- mc mirror --overwrite doc/ store/docs.harton.nz/$${DRONE_REPO}
- name: hex release
image: harton.dev/james/asdf_container:latest
when:
event:
- tag
refs:
include:
- refs/tags/v*
depends_on:
- build artifacts
environment:
MIX_ENV: test
HEX_HOME: /drone/src/.hex
MIX_HOME: /drone/src/.mix
REBAR_BASE_DIR: /drone/src/.rebar3
ASDF_DATA_DIR: /drone/src/.asdf
ASDF_DIR: /root/.asdf
HEX_API_KEY:
from_secret: HEX_API_KEY
commands:
- . $ASDF_DIR/asdf.sh
- mix hex.publish --yes

View file

@ -1,139 +0,0 @@
stages:
- build
- test
- release
variables:
MIX_ENV: "test"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/"
HEX_HOME: "$CI_PROJECT_DIR/.hex"
MIX_HOME: "$CI_PROJECT_DIR/.mix"
build:
image: elixir:latest
stage: build
cache:
key: "$CI_JOB_NAME"
paths:
- deps
- _build
- .hex
- .mix
script:
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix deps.compile
- mix git_ops.project_info -f dotenv > project_info.env
artifacts:
paths:
- _build/
- deps/
- .hex
- .mix
reports:
dotenv: project_info.env
test:
image: elixir:latest
dependencies:
- build
stage: test
script:
- mix test
credo:
image: elixir:latest
dependencies:
- build
stage: test
script:
- mix credo
audit:
image: elixir:latest
dependencies:
- build
stage: test
script:
- mix hex.audit
format:
image: elixir:latest
dependencies:
- build
stage: test
script:
- mix format --check-formatted
pages:
image: elixir:latest
dependencies:
- build
stage: release
script:
- mix docs -o public
artifacts:
paths:
- public
only:
- main
git_ops:
image: elixir:latest
dependencies:
- build
stage: release
only:
refs:
- main
except:
variables:
- $CI_COMMIT_MESSAGE =~ /chore\:\ release version/
script:
- |
export OLD_APP_VERSION=$APP_VERSION
mkdir -p artifacts
git config --global user.name "Gitlab Runner for ${GITLAB_USER_NAME}"
git config --global user.email "${GITLAB_USER_EMAIL}"
mix git_ops.release --yes || true
mix git_ops.project_info -f shell > artifacts/env
source artifacts/env
if [ "v${OLD_APP_VERSION}" != "v${APP_VERSION}" ]; then
mix hex.build -o "artifacts/${APP_NAME}-${APP_VERSION}.tar"
gzip "artifacts/${APP_NAME}-${APP_VERSION}.tar"
mix docs && tar zcvf "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" doc/
curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz"
curl --header "JOB_TOKEN: ${CI_JOB_TOKEN}" --upload-file "artifacts/${APP_NAME}-${APP_VERSION}-docs.tar.gz" "${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz"
git push "https://project_${CI_PROJECT_ID}_bot:${RELEASE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git" "HEAD:${CI_COMMIT_REF_NAME}" "refs/tags/v${APP_VERSION}"
fi
artifacts:
paths:
- artifacts/*
release-gitlab:
image: registry.gitlab.com/gitlab-org/release-cli:latest
dependencies:
- build
stage: release
only:
- tags
- /^v\d+\.\d+\.\d+(-\w+)?$/
script:
- release-cli create \
--name "Release ${APP_NAME} ${APP_VERSION}" \
--description "./CHANGELOG.md" \
--tag-name "v${APP_VERSION}" \
--assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}.tar.gz\"}" \
--assets-link "{\"name\":\"${APP_NAME}-${APP_VERSION}-docs.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/${APP_NAME}/${APP_VERSION}/${APP_NAME}-${APP_VERSION}-docs.tar.gz\"}"
release-hex:
image: elixir:latest
dependencies:
- build
stage: release
only:
- tags
- /^v\d+\.\d+\.\d+(-\w+)?$/
script:
- mix hex.publish --yes

2
.tool-versions Normal file
View file

@ -0,0 +1,2 @@
erlang 26.2.2
elixir 1.16.1

View file

@ -5,14 +5,10 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v1.0.0](https://gitlab.com/jimsy/mpl3115a2/compare/v0.3.0...v1.0.0) (2023-01-16)
## [v1.0.0](https://harton.dev/james/mpl3115a2/compare/v0.3.0...v1.0.0) (2023-01-16)
### Breaking Changes:
* Relicense to HL3-FULL.
## [v0.3.0](https://gitlab.com/jimsy/mpl3115a2/compare/v0.3.0...v0.3.0) (2020-12-28)
- Relicense to HL3-FULL.
## [v0.3.0](https://harton.dev/james/mpl3115a2/compare/v0.3.0...v0.3.0) (2020-12-28)

View file

@ -1,11 +1,11 @@
# MPL3115A2
[![pipeline status](https://gitlab.com/jimsy/mpl3115a2/badges/main/pipeline.svg)](https://gitlab.com/jimsy/mpl3115a2/commits/main)
[![Build Status](https://drone.harton.dev/api/badges/james/mpl3115a2/status.svg)](https://drone.harton.dev/james/mpl3115a2)
[![Hex.pm](https://img.shields.io/hexpm/v/mpl3115a2.svg)](https://hex.pm/packages/mpl3115a2)
[![Hippocratic License HL3-FULL](https://img.shields.io/static/v1?label=Hippocratic%20License&message=HL3-FULL&labelColor=5e2751&color=bc8c3d)](https://firstdonoharm.dev/version/3/0/full.html)
Elixir driver for the MPL3115A2 barometric pressure, altitude and temperature
sensor. I'm using [Adafruit's breakout](https://www.adafruit.com/product/1893).
sensor. I'm using [Adafruit's breakout](https://www.adafruit.com/product/1893).
## Usage
@ -14,13 +14,13 @@ Add your device to your config like so:
config :mpl3115a2,
devices: [%{bus: "i2c-1", address: 0x60}]
And start your application. Your devices will be reset with defaults and you
will be able to take temperature and pressure or altitude readings. See
And start your application. Your devices will be reset with defaults and you
will be able to take temperature and pressure or altitude readings. See
`MPL3115A2.Commands.initialize!/1` for more details on the default
initialization.
This device is capable of much more advanced usage than the `MPL3115A2.Device`
module makes use of. It was all that I needed at the time. For advanced usage
module makes use of. It was all that I needed at the time. For advanced usage
you can use the `MPL3115A2.Commands` and `MPL3115A2.Registers` modules directly.
Feel free to send PR's.
@ -41,6 +41,12 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/mpl3115a2](https://hexdocs.pm/mpl3115a2).
## Github Mirror
This repository is mirrored [on Github](https://github.com/jimsynz/mpl3115a2)
from it's primary location [on my Forejo instance](https://harton.dev/james/mpl3115a2).
Feel free to raise issues and open PRs on Github.
## License
This software is licensed under the terms of the
@ -48,7 +54,7 @@ This software is licensed under the terms of the
this package for the terms.
This license actively proscribes this software being used by and for some
industries, countries and activities. If your usage of this software doesn't
industries, countries and activities. If your usage of this software doesn't
comply with the terms of this license, then [contact me](mailto:james@harton.nz)
with the details of your use-case to organise the purchase of a license - the
cost of which may include a donation to a suitable charity or NGO.

View file

@ -6,7 +6,7 @@ config :mpl3115a2,
config :git_ops,
mix_project: Mix.Project.get!(),
changelog_file: "CHANGELOG.md",
repository_url: "https://gitlab.com/jimsy/mpl3115a2",
repository_url: "https://harton.dev/james/mpl3115a2",
manage_mix_version?: true,
manage_readme_version: "README.md",
version_tag_prefix: "v"

View file

@ -4,7 +4,7 @@ defmodule MPL3115A2 do
@behaviour Wafer.Conn
alias MPL3115A2.Registers
alias Wafer.Conn
use Bitwise
import Bitwise
import Wafer.Twiddles
@moduledoc """
@ -533,8 +533,13 @@ defmodule MPL3115A2 do
Default value: `false`.
"""
@spec data_ready_event_mode(t, boolean) :: {:ok, t} | {:error, reason :: any}
def data_ready_event_mode(%MPL3115A2{conn: conn} = dev, value) when is_boolean(value) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 2, value)),
def data_ready_event_mode(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 2)),
do: {:ok, %{dev | conn: conn}}
end
def data_ready_event_mode(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &clear_bit(&1, 2)),
do: {:ok, %{dev | conn: conn}}
end
@ -557,9 +562,13 @@ defmodule MPL3115A2 do
Default value: `false`.
"""
@spec pressure_altitude_event_flag_enable(t, boolean) :: {:ok, t} | {:error, reason :: any}
def pressure_altitude_event_flag_enable(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 1, value)),
def pressure_altitude_event_flag_enable(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 1)),
do: {:ok, %{dev | conn: conn}}
end
def pressure_altitude_event_flag_enable(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &clear_bit(&1, 1)),
do: {:ok, %{dev | conn: conn}}
end
@ -582,8 +591,13 @@ defmodule MPL3115A2 do
Default value: `false`.
"""
@spec temperature_event_flag_enable(t, boolean) :: {:ok, t} | {:error, reason :: any}
def temperature_event_flag_enable(%MPL3115A2{conn: conn} = dev, value) when is_boolean(value) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 0, value)),
def temperature_event_flag_enable(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &set_bit(&1, 0)),
do: {:ok, %{dev | conn: conn}}
end
def temperature_event_flag_enable(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_pt_data_cfg(conn, &clear_bit(&1, 0)),
do: {:ok, %{dev | conn: conn}}
end
@ -606,7 +620,7 @@ defmodule MPL3115A2 do
"""
@spec barometric_pressure_input(t, pressure) :: {:ok, pressure} | {:error, reason :: any}
def barometric_pressure_input(%MPL3115A2{conn: conn} = dev, pascals) do
data = div(pascals, 2)
data = pascals |> trunc() |> div(2)
msb = data >>> 8 &&& 0xFF
lsb = data &&& 0xFF
@ -640,6 +654,7 @@ defmodule MPL3115A2 do
"""
@spec pressure_or_altitude_target(t, pressure | altitude) :: {:ok, t} | {:error, reason :: any}
def pressure_or_altitude_target(%MPL3115A2{conn: conn} = dev, pressure_or_altitude) do
pressure_or_altitude = trunc(pressure_or_altitude)
msb = pressure_or_altitude >>> 8 &&& 0xFF
lsb = pressure_or_altitude &&& 0xFF
@ -661,6 +676,8 @@ defmodule MPL3115A2 do
"""
@spec temperature_target(t, temperature) :: {:ok, t} | {:error, reason :: any}
def temperature_target(%MPL3115A2{conn: conn} = dev, temperature) do
temperature = trunc(temperature)
with {:ok, conn} <- Registers.write_t_tgt(conn, <<temperature &&& 0xFF>>),
do: {:ok, %{dev | conn: conn}}
end
@ -686,6 +703,8 @@ defmodule MPL3115A2 do
"""
@spec pressure_altitude_window(t, pressure | altitude) :: {:ok, t} | {:error, reason :: any}
def pressure_altitude_window(%MPL3115A2{conn: conn} = dev, pressure_or_altitude) do
pressure_or_altitude = trunc(pressure_or_altitude)
msb = pressure_or_altitude >>> 8 &&& 0xFF
lsb = pressure_or_altitude &&& 0xFF
@ -707,6 +726,8 @@ defmodule MPL3115A2 do
"""
@spec temperature_window(t, temperature) :: {:ok, t} | {:error, reason :: any}
def temperature_window(%MPL3115A2{conn: conn} = dev, temperature) do
temperature = trunc(temperature)
with {:ok, conn} <- Registers.write_t_wnd(conn, <<temperature &&& 0xFF>>),
do: {:ok, %{dev | conn: conn}}
end
@ -902,6 +923,7 @@ defmodule MPL3115A2 do
value =
value
|> :math.sqrt()
|> trunc()
|> band(0x3)
with {:ok, conn} <-
@ -957,8 +979,13 @@ defmodule MPL3115A2 do
other interrupts are disabled.
"""
@spec raw_output(t, boolean) :: {:ok, t} | {:error, reason :: any}
def raw_output(%MPL3115A2{conn: conn} = dev, value) when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg1(conn, &set_bit(&1, 6, value)),
def raw_output(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg1(conn, &set_bit(&1, 6)),
do: {:ok, %{dev | conn: conn}}
end
def raw_output(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg1(conn, &clear_bit(&1, 6)),
do: {:ok, %{dev | conn: conn}}
end
@ -1012,6 +1039,7 @@ defmodule MPL3115A2 do
value =
value
|> :math.sqrt()
|> trunc()
with {:ok, conn} <-
Registers.update_ctrl_reg2(conn, fn <<data>> ->
@ -1249,8 +1277,13 @@ defmodule MPL3115A2 do
Defaults to `false`.
"""
@spec interrupt_enable_data_ready(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_data_ready(%MPL3115A2{conn: conn} = dev, value) when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 7, value)),
def interrupt_enable_data_ready(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 7)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_data_ready(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 7)),
do: {:ok, %{dev | conn: conn}}
end
@ -1277,8 +1310,13 @@ defmodule MPL3115A2 do
true: FIFO interrupt enabled
"""
@spec interrupt_enable_fifo(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_fifo(%MPL3115A2{conn: conn} = dev, value) when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 6, value)),
def interrupt_enable_fifo(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 6)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_fifo(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 6)),
do: {:ok, %{dev | conn: conn}}
end
@ -1305,9 +1343,13 @@ defmodule MPL3115A2 do
true: Pressure window interrupt enabled
"""
@spec interrupt_enable_pressure_window(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_pressure_window(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 5, value)),
def interrupt_enable_pressure_window(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 5)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_pressure_window(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 5)),
do: {:ok, %{dev | conn: conn}}
end
@ -1336,9 +1378,13 @@ defmodule MPL3115A2 do
true: Temperature window interrupt enabled
"""
@spec interrupt_enable_temperature_window(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_temperature_window(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 4, value)),
def interrupt_enable_temperature_window(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 4)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_temperature_window(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 4)),
do: {:ok, %{dev | conn: conn}}
end
@ -1365,9 +1411,13 @@ defmodule MPL3115A2 do
true: Pressure Threshold interrupt enabled
"""
@spec interrupt_enable_pressure_threshold(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_pressure_threshold(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 3, value)),
def interrupt_enable_pressure_threshold(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 3)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_pressure_threshold(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 3)),
do: {:ok, %{dev | conn: conn}}
end
@ -1394,9 +1444,13 @@ defmodule MPL3115A2 do
true: Temperature Threshold interrupt enabled
"""
@spec interrupt_enable_temperature_threshold(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_temperature_threshold(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 2, value)),
def interrupt_enable_temperature_threshold(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 2)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_temperature_threshold(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 2)),
do: {:ok, %{dev | conn: conn}}
end
@ -1423,9 +1477,13 @@ defmodule MPL3115A2 do
true: Pressure Change interrupt enabled
"""
@spec interrupt_enable_pressure_change(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_pressure_change(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 1, value)),
def interrupt_enable_pressure_change(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 1)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_pressure_change(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 1)),
do: {:ok, %{dev | conn: conn}}
end
@ -1452,9 +1510,13 @@ defmodule MPL3115A2 do
true: Temperature Change interrupt enabled
"""
@spec interrupt_enable_temperature_change(t, boolean) :: {:ok, t} | {:error, reason :: any}
def interrupt_enable_temperature_change(%MPL3115A2{conn: conn} = dev, value)
when is_boolean(value) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 0, value)),
def interrupt_enable_temperature_change(%MPL3115A2{conn: conn} = dev, true) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &set_bit(&1, 0)),
do: {:ok, %{dev | conn: conn}}
end
def interrupt_enable_temperature_change(%MPL3115A2{conn: conn} = dev, false) do
with {:ok, conn} <- Registers.update_ctrl_reg4(conn, &clear_bit(&1, 0)),
do: {:ok, %{dev | conn: conn}}
end
@ -1770,7 +1832,7 @@ defmodule MPL3115A2 do
do: {:ok, whole + fractional / 16.0}
defp to_pressure(
<<whole::unsigned-integer-size(18), fractional::unsigned-integer-size(2), _::size(2)>>
<<whole::unsigned-integer-size(18), fractional::unsigned-integer-size(2), _::size(4)>>
),
do: {:ok, whole + fractional / 4.0}

View file

@ -27,7 +27,7 @@ defmodule MPL3115A2.MixProject do
maintainers: ["James Harton <james@harton.nz>"],
licenses: ["HL3-FULL"],
links: %{
"Source" => "https://gitlab.com/jimsy/mpl3115a2"
"Source" => "https://harton.dev/james/mpl3115a2"
}
]
end
@ -37,9 +37,11 @@ defmodule MPL3115A2.MixProject do
[
{:circuits_i2c, "~> 2.0", optional: true},
{:credo, "~> 1.6", only: ~w[dev test]a, runtime: false},
{:earmark, "~> 1.4", only: ~w[dev test]a},
{:dialyxir, "~> 1.4", only: ~w[dev test]a, runtime: false},
{:doctor, "~> 0.21", only: ~w[dev test]a, runtime: false},
{:earmark, "~> 1.4", only: ~w[dev test]a, runtime: false},
{:elixir_ale, "~> 1.2", optional: true},
{:ex_doc, "~> 0.30", only: ~w[dev test]a},
{:ex_doc, "~> 0.30", only: ~w[dev test]a, runtime: false},
{:git_ops, "~> 2.4", only: ~w[dev test]a, runtime: false},
{:mimic, "~> 1.5", only: :test},
{:wafer, "~> 1.0"}

View file

@ -2,10 +2,14 @@
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"circuits_i2c": {:hex, :circuits_i2c, "2.0.0", "8343b12879189f844835abeaf31a36c5626b8ace58413a582794fdfe60c2dc0e", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "06eccd33b36bcedf41730cac8da58e359967ea63a2cd899cea58c2a138634cc4"},
"credo": {:hex, :credo, "1.6.1", "7dc76dcdb764a4316c1596804c48eada9fff44bd4b733a91ccbf0c0f368be61e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "698607fb5993720c7e93d2d8e76f2175bba024de964e160e2f7151ef3ab82ac5"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"},
"earmark": {:hex, :earmark, "1.4.19", "3854a17305c880cc46305af15fb1630568d23a709aba21aaa996ced082fc29d7", [:mix], [{:earmark_parser, ">= 1.4.18", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "d5a8c9f9e37159a8fdd3ea8437fb4e229eaf56d5129b9a011dc4780a4872079d"},
"earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"},
"elixir_ale": {:hex, :elixir_ale, "1.2.1", "07ac2f17a0191b8bd3b0df6b526c7f699a3a4d690c9def573fcb5824eef24d98", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "bfb099137500a3b8c4a1750cf07f2d704897ef9feac3412064bf9edc7d74193c"},
"elixir_make": {:hex, :elixir_make, "0.7.7", "7128c60c2476019ed978210c245badf08b03dbec4f24d05790ef791da11aa17c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5bc19fff950fad52bbe5f211b12db9ec82c6b34a9647da0c2224b8b8464c7e6c"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.0", "ed94bf5183f559d2f825e4f866cc0eab277bbb17da76aff40f8e0f149656943e", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "6743fe46704fe27e2f2558faa61f00e5356528768807badb2092d38476d6dac2"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},

View file

@ -1,3 +0,0 @@
{
"extends": ["gitlab>jimsy/renovate"]
}