Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions CHANGELOG.txt

This file was deleted.

28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
LIBRARY_VERSION=$(shell cat library/setup.py | grep version | awk -F"'" '{print $$2}')
LIBRARY_NAME=$(shell cat library/setup.py | grep name | awk -F"'" '{print $$2}')

.PHONY: usage install uninstall
usage:
@echo "Library: ${LIBRARY_NAME}"
@echo "Version: ${LIBRARY_VERSION}\n"
@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.rst from README.md"
@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-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"

install:
./install.sh

uninstall:
./uninstall.sh

check:
@echo "Checking for trailing whitespace"
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
@echo "Checking for DOS line-endings"
@! grep -IUrn --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}"

python-readme: library/README.rst

python-license: library/LICENSE.txt
Expand All @@ -40,5 +61,8 @@ python-clean:
python-dist: python-clean python-wheels python-sdist
ls library/dist

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

python-deploy: check python-dist
twine upload library/dist/*
Expand Down
5 changes: 5 additions & 0 deletions library/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.0.3
-----

* Migrate to i2cdevice>=0.0.6 set/get API

0.0.2
-----

Expand Down
59 changes: 28 additions & 31 deletions library/bmp280/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from i2cdevice.adapter import LookupAdapter, Adapter
import struct


__version__ = '0.0.3'

CHIP_ID = 0x58
I2C_ADDRESS_GND = 0x76
I2C_ADDRESS_VCC = 0x77
Expand Down Expand Up @@ -40,6 +43,15 @@ def __init__(self):

self.temperature_fine = 0

def set_from_namedtuple(self, value):
# Iterate through a tuple supplied by i2cdevice
# and copy its values into the class attributes
for key in self.__dict__.keys():
try:
setattr(self, key, getattr(value, key))
except AttributeError:
pass

def compensate_temperature(self, raw_temperature):
var1 = (raw_temperature / 16384.0 - self.dig_t1 / 1024.0) * self.dig_t2
var2 = raw_temperature / 131072.0 - self.dig_t1 / 8192.0
Expand Down Expand Up @@ -142,45 +154,30 @@ def setup(self):
self._bmp280.select_address(self._i2c_addr)

try:
if self._bmp280.CHIP_ID.get_id() != CHIP_ID:
raise RuntimeError("Unable to find bmp280 on 0x{:02x}, CHIP_ID returned {:02x}".format(self._i2c_addr, self._bmp280.CHIP_ID.get_id()))
chip = self._bmp280.get('CHIP_ID')
if chip.id != CHIP_ID:
raise RuntimeError("Unable to find bmp280 on 0x{:02x}, CHIP_ID returned {:02x}".format(self._i2c_addr, chip.id))
except IOError:
raise RuntimeError("Unable to find bmp280 on 0x{:02x}, IOError".format(self._i2c_addr))

with self._bmp280.CTRL_MEAS as CTRL_MEAS:
CTRL_MEAS.set_mode('normal')
CTRL_MEAS.set_osrs_t(16)
CTRL_MEAS.set_osrs_p(16)
CTRL_MEAS.write()

with self._bmp280.CONFIG as CONFIG:
CONFIG.set_t_sb(500)
CONFIG.set_filter(2)
CONFIG.write()

with self._bmp280.CALIBRATION as CALIBRATION:
self.calibration.dig_t1 = CALIBRATION.get_dig_t1()
self.calibration.dig_t2 = CALIBRATION.get_dig_t2()
self.calibration.dig_t3 = CALIBRATION.get_dig_t3()

self.calibration.dig_p1 = CALIBRATION.get_dig_p1()
self.calibration.dig_p2 = CALIBRATION.get_dig_p2()
self.calibration.dig_p3 = CALIBRATION.get_dig_p3()
self.calibration.dig_p4 = CALIBRATION.get_dig_p4()
self.calibration.dig_p5 = CALIBRATION.get_dig_p5()
self.calibration.dig_p6 = CALIBRATION.get_dig_p6()
self.calibration.dig_p7 = CALIBRATION.get_dig_p7()
self.calibration.dig_p8 = CALIBRATION.get_dig_p8()
self.calibration.dig_p9 = CALIBRATION.get_dig_p9()
self._bmp280.set('CTRL_MEAS',
mode='normal',
osrs_t=16,
osrs_p=16)

self._bmp280.set('CONFIG',
t_sb=500,
filter=2)

self.calibration.set_from_namedtuple(self._bmp280.get('CALIBRATION'))

def update_sensor(self):
self.setup()

raw_temperature = self._bmp280.DATA.get_temperature()
raw_pressure = self._bmp280.DATA.get_pressure()
raw = self._bmp280.get('DATA')

self.temperature = self.calibration.compensate_temperature(raw_temperature)
self.pressure = self.calibration.compensate_pressure(raw_pressure) / 100.0
self.temperature = self.calibration.compensate_temperature(raw.temperature)
self.pressure = self.calibration.compensate_pressure(raw.pressure) / 100.0

def get_temperature(self):
self.update_sensor()
Expand Down
4 changes: 2 additions & 2 deletions library/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

setup(
name='bmp280',
version='0.0.2',
version='0.0.3',
author='Philip Howard',
author_email='phil@pimoroni.com',
description="""Python library for the BMP280 temperature and pressure sensor""",
Expand All @@ -49,5 +49,5 @@
url='http://www.pimoroni.com',
classifiers=classifiers,
packages=['bmp280'],
install_requires=['i2cdevice>=0.0.4']
install_requires=['i2cdevice>=0.0.6']
)
2 changes: 1 addition & 1 deletion library/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps =
mock
pytest>=3.1
pytest-cov

[testenv:qa]
commands =
flake8 --ignore E501
Expand Down