Skip to content

Commit

Permalink
Merge 257991c into 8fb321b
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Mar 18, 2024
2 parents 8fb321b + 257991c commit d45140d
Show file tree
Hide file tree
Showing 46 changed files with 718 additions and 1,163 deletions.
File renamed without changes.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: Python ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9', '3.10', '3.11']

env:
RELEASE_FILE: ${{ github.event.repository.name }}-${{ github.event.release.tag_name || github.sha }}-py${{ matrix.python }}

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install Dependencies
run: |
make dev-deps
- name: Build Packages
run: |
make build
- name: Upload Packages
uses: actions/upload-artifact@v4
with:
name: ${{ env.RELEASE_FILE }}
path: dist/
39 changes: 39 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: QA

on:
pull_request:
push:
branches:
- main

jobs:
test:
name: linting & spelling
runs-on: ubuntu-latest
env:
TERM: xterm-256color

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python '3,11'
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install Dependencies
run: |
make dev-deps
- name: Run Quality Assurance
run: |
make qa
- name: Run Code Checks
run: |
make check
- name: Run Bash Code Checks
run: |
make shellcheck
26 changes: 15 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
name: Python Tests
name: Tests

on:
pull_request:
push:
branches:
- master
- main

jobs:
test:
name: Python ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
matrix:
python: [2.7, 3.5, 3.7, 3.9]
python: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install Dependencies
run: |
python -m pip install --upgrade setuptools tox
make dev-deps
- name: Run Tests
working-directory: library
run: |
tox -e py
make pytest
- name: Coverage
if: ${{ matrix.python == '3.9' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: library
run: |
python -m pip install coveralls
coveralls --service github
if: ${{ matrix.python == '3.9' }}
coveralls --service=github
File renamed without changes.
91 changes: 42 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,70 +1,63 @@
LIBRARY_VERSION=$(shell grep version library/setup.cfg | awk -F" = " '{print $$2}')
LIBRARY_NAME=$(shell grep name library/setup.cfg | awk -F" = " '{print $$2}')
LIBRARY_NAME := $(shell hatch project metadata name 2> /dev/null)
LIBRARY_VERSION := $(shell hatch version 2> /dev/null)

.PHONY: usage install uninstall
.PHONY: usage install uninstall check pytest qa build-deps check tag wheel sdist clean dist testdeploy deploy
usage:
ifdef LIBRARY_NAME
@echo "Library: ${LIBRARY_NAME}"
@echo "Version: ${LIBRARY_VERSION}\n"
else
@echo "WARNING: You should 'make dev-deps'\n"
endif
@echo "Usage: make <target>, where target is one of:\n"
@echo "install: install the library locally from source"
@echo "uninstall: uninstall the local library"
@echo "check: peform basic integrity checks on the codebase"
@echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt"
@echo "python-wheels: build python .whl files for distribution"
@echo "python-sdist: build python source distribution"
@echo "python-clean: clean python build and dist directories"
@echo "python-dist: build all python distribution files"
@echo "python-testdeploy: build all and deploy to test PyPi"
@echo "tag: tag the repository with the current version"
@echo "install: install the library locally from source"
@echo "uninstall: uninstall the local library"
@echo "dev-deps: install Python dev dependencies"
@echo "check: perform basic integrity checks on the codebase"
@echo "qa: run linting and package QA"
@echo "pytest: run Python test fixtures"
@echo "clean: clean Python build and dist directories"
@echo "build: build Python distribution files"
@echo "testdeploy: build and upload to test PyPi"
@echo "deploy: build and upload to PyPi"
@echo "tag: tag the repository with the current version\n"

install:
./install.sh
./install.sh --unstable

uninstall:
./uninstall.sh

check:
@echo "Checking for trailing whitespace"
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=packaging --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
@echo "Checking for DOS line-endings"
@! grep -IlUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
@echo "Checking library/CHANGELOG.txt"
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
@cat library/${LIBRARY_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"

tag:
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
dev-deps:
python3 -m pip install -r requirements-dev.txt
sudo apt install dos2unix shellcheck

python-readme: library/README.md
check:
@bash check.sh

python-license: library/LICENSE.txt
shellcheck:
shellcheck *.sh

library/README.md: README.md library/CHANGELOG.txt
cp README.md library/README.md
printf "\n# Changelog\n" >> library/README.md
cat library/CHANGELOG.txt >> library/README.md
qa:
tox -e qa

library/LICENSE.txt: LICENSE
cp LICENSE library/LICENSE.txt
pytest:
tox -e py

python-wheels: python-readme python-license
cd library; python3 setup.py bdist_wheel
cd library; python setup.py bdist_wheel
nopost:
@bash check.sh --nopost

python-sdist: python-readme python-license
cd library; python setup.py sdist
tag:
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"

python-clean:
-rm -r library/dist
-rm -r library/build
-rm -r library/*.egg-info
build: check
@hatch build

python-dist: python-clean python-wheels python-sdist
ls library/dist
clean:
-rm -r dist

python-testdeploy: python-dist
twine upload --repository-url https://test.pypi.org/legacy/ library/dist/*
testdeploy: build
twine upload --repository testpypi dist/*

python-deploy: check python-dist
twine upload library/dist/*
deploy: nopost build
twine upload dist/*
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# BME68x
# BME680

[![Build Status](https://travis-ci.org/pimoroni/bme680-python.svg?branch=master)](https://travis-ci.org/pimoroni/bme680-python)
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/bme680-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/bme680-python?branch=master)
[![Build Status](https://img.shields.io/github/actions/workflow/status/pimoroni/bme680-python/test.yml?branch=main)](https://github.com/pimoroni/bme680-python/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/bme680-python/badge.svg?branch=main)](https://coveralls.io/github/pimoroni/bme680-python?branch=main)
[![PyPi Package](https://img.shields.io/pypi/v/bme680.svg)](https://pypi.python.org/pypi/bme680)
[![Python Versions](https://img.shields.io/pypi/pyversions/bme680.svg)](https://pypi.python.org/pypi/bme680)

BME68x is a series of state-of-the-art environmental sensors that let you measure temperature, pressure, humidity and indoor air quality.
https://shop.pimoroni.com/products/bme680

This library is designed to work with the following products:

* BME680 Breakout - https://shop.pimoroni.com/products/bme680
* BME688 4-in-1 Air Quality Breakout - https://shop.pimoroni.com/products/bme688-breakout
The state-of-the-art BME680 breakout lets you measure temperature, pressure, humidity, and indoor air quality.

## Installing

### Full install (recommended):

We've created an easy installation script that will install all pre-requisites and get your BME68x
We've created an easy installation script that will install all pre-requisites and get your BME680
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
on your Raspberry Pi desktop, as illustrated below:

Expand All @@ -25,35 +22,31 @@ on your Raspberry Pi desktop, as illustrated below:
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:

```bash
curl https://get.pimoroni.com/bme680 | bash
git clone https://github.com/pimoroni/bme680-python
cd bme680-python
./install.sh
```

### Manual install:
### Development:

#### Library install for Python 3:
If you want to contribute, or like living on the edge of your seat by having the latest code, you can install the development version like so:

```bash
sudo pip3 install bme680
git clone https://github.com/pimoroni/bme680-python
cd bme680-python
./install.sh --unstable
```

#### Library install for Python 2:
In all cases you will have to enable the i2c bus:

```bash
sudo pip2 install bme680
```

### Development:

If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run:

```bash
sudo python3 setup.py install
sudo raspi-config nonint do_i2c 0
```
(or `sudo python setup.py install` whichever your primary Python environment may be)

In all cases you will have to have I2C enabled (`sudo raspi-config`, under 'Interfacing Options').

## Documentation & Support

* Guides and tutorials - https://learn.pimoroni.com/bme680-breakout
* Get help - http://forums.pimoroni.com/c/support



10 changes: 5 additions & 5 deletions library/bme680/__init__.py → bme680/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""BME680 Temperature, Pressure, Humidity & Gas Sensor."""
from .constants import lookupTable1, lookupTable2
from .constants import BME680Data
from . import constants
import math
import time

from . import constants
from .constants import BME680Data, lookupTable1, lookupTable2

__version__ = '1.1.1'


Expand Down Expand Up @@ -39,8 +39,8 @@ def __init__(self, i2c_addr=constants.I2C_ADDR_PRIMARY, i2c_device=None):
self.i2c_addr = i2c_addr
self._i2c = i2c_device
if self._i2c is None:
import smbus
self._i2c = smbus.SMBus(1)
import smbus2
self._i2c = smbus2.SMBus(1)

try:
self.chip_id = self._get_regs(constants.CHIP_ID_ADDR, 1)
Expand Down
6 changes: 3 additions & 3 deletions library/bme680/constants.py → bme680/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@

def bytes_to_word(msb, lsb, bits=16, signed=False):
"""Convert a most and least significant byte into a word."""
# TODO: Reimpliment with struct
# TODO: Reimplement with struct
word = (msb << 8) | lsb
if signed:
word = twos_comp(word, bits)
Expand All @@ -248,7 +248,7 @@ def bytes_to_word(msb, lsb, bits=16, signed=False):

def twos_comp(val, bits=16):
"""Convert two bytes into a two's compliment signed word."""
# TODO: Reimpliment with struct
# TODO: Reimplement with struct
if val & (1 << (bits - 1)) != 0:
val = val - (1 << bits)
return val
Expand Down Expand Up @@ -312,7 +312,7 @@ def __init__(self): # noqa D107
self.range_sw_err = None

def set_from_array(self, calibration):
"""Set paramaters from an array of bytes."""
"""Set parameters from an array of bytes."""
# Temperature related coefficients
self.par_t1 = bytes_to_word(calibration[T1_MSB_REG], calibration[T1_LSB_REG])
self.par_t2 = bytes_to_word(calibration[T2_MSB_REG], calibration[T2_LSB_REG], bits=16, signed=True)
Expand Down

0 comments on commit d45140d

Please sign in to comment.