diff --git a/CHANGELOG.txt b/CHANGELOG.txt deleted file mode 100644 index baf326b..0000000 --- a/CHANGELOG.txt +++ /dev/null @@ -1,10 +0,0 @@ -0.0.2 ------ - -* Added `get_altitude` method -* Corrected pressure to hPa - -0.0.1 ------ - -* Initial Release diff --git a/Makefile b/Makefile index ee7b766..49996eb 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,21 @@ +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 , 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 @@ -15,6 +23,19 @@ install: 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 @@ -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/* diff --git a/library/CHANGELOG.txt b/library/CHANGELOG.txt index baf326b..69b085f 100644 --- a/library/CHANGELOG.txt +++ b/library/CHANGELOG.txt @@ -1,3 +1,8 @@ +0.0.3 +----- + +* Migrate to i2cdevice>=0.0.6 set/get API + 0.0.2 ----- diff --git a/library/bmp280/__init__.py b/library/bmp280/__init__.py index c342a06..d90a624 100644 --- a/library/bmp280/__init__.py +++ b/library/bmp280/__init__.py @@ -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 @@ -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 @@ -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() diff --git a/library/setup.py b/library/setup.py index f37c1dd..fc40f70 100755 --- a/library/setup.py +++ b/library/setup.py @@ -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""", @@ -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'] ) diff --git a/library/tox.ini b/library/tox.ini index e53234d..c3a18ec 100644 --- a/library/tox.ini +++ b/library/tox.ini @@ -11,7 +11,7 @@ deps = mock pytest>=3.1 pytest-cov - + [testenv:qa] commands = flake8 --ignore E501