Skip to content

Commit

Permalink
vendoring TMP library
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 17, 2024
1 parent 0824171 commit d9024aa
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `unit()` can be used in mqtt fetch expressions. Example: `unit():stirring:target_rpm` is identical to `::stirring:target_rpm`. The latter can be seen as a shortened version of the former.
- experiment profiles can have a `description` in the `job` field (i.e. at the same level as `actions`).
- Updated Raspberry Pi OS image to 2024-07-04.
- Vendoring the TMP1075 library, which also fixes the RPi5 error.

#### Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def check_heater_pcb_temperature(self) -> None:
from pioreactor.utils.mock import MockTMP1075 as TMP1075
else:
try:
from TMP1075 import TMP1075 # type: ignore
from pioreactor.utils.temps import TMP1075 # type: ignore
except ImportError:
# leader-only is a worker?
self.logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/temperature_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
if whoami.is_testing_env():
from pioreactor.utils.mock import MockTMP1075 as TMP1075
else:
from TMP1075 import TMP1075 # type: ignore
from pioreactor.utils.temps import TMP1075 # type: ignore

self.heater_duty_cycle = 0.0
self.pwm = self.setup_pwm()
Expand Down
5 changes: 2 additions & 3 deletions pioreactor/utils/adcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# adc abstraction
from __future__ import annotations

import busio # type: ignore
from busio import I2C # type: ignore

from pioreactor import exc
from pioreactor import hardware
Expand Down Expand Up @@ -51,7 +51,6 @@ def __init__(self) -> None:
super().__init__()

from adafruit_ads1x15.analog_in import AnalogIn # type: ignore
from busio import I2C # type: ignore
from adafruit_ads1x15.ads1115 import ADS1115 as ADS # type: ignore

self.analog_in: dict[int, AnalogIn] = {}
Expand Down Expand Up @@ -94,7 +93,7 @@ def read_from_channel(self, channel: pt.AdcChannel) -> pt.AnalogValue:
class Pico_ADC(_ADC):
def __init__(self) -> None:
# set up i2c connection to hardware.ADC
self.i2c = busio.I2C(hardware.SCL, hardware.SDA)
self.i2c = I2C(hardware.SCL, hardware.SDA)

def read_from_channel(self, channel: pt.AdcChannel) -> pt.AnalogValue:
assert 0 <= channel <= 3
Expand Down
32 changes: 32 additions & 0 deletions pioreactor/utils/temps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from adafruit_bus_device.i2c_device import I2CDevice
from busio import I2C # type: ignore

from pioreactor import hardware


class TMP1075:
"""
Driver for the TI TMP1075 temperature sensor.
See datasheet: http://www.ti.com/lit/ds/symlink/tmp1075.pdf
"""

TEMP_REGISTER = bytearray([0x00])
CONFIG_REGISTER = bytearray([0x01])

def __init__(self, address: int = 0x4F):
comm_port = (I2C(hardware.SCL, hardware.SDA),)
self.i2c = I2CDevice(comm_port, address)

def get_temperature(self) -> float:
b = bytearray(2)
self.i2c.write_then_readinto(self.TEMP_REGISTER, b)
return ((b[0] << 4) + (b[1] >> 4)) * 0.0625

@property
def temperature(self):
"""alias for get_temperature"""
return self.get_temperature()
4 changes: 0 additions & 4 deletions pioreactor/whoami.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ def am_I_leader() -> bool:
return get_unit_name() == leader_hostname


def am_I_active_worker() -> bool:
return is_active(get_unit_name())


def am_I_a_worker() -> bool:
from pioreactor.pubsub import get_from_leader

Expand Down
1 change: 0 additions & 1 deletion requirements/requirements_worker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ pyftdi==0.55.4
pyserial==3.5
pyusb==1.2.1
rpi_hardware_pwm==0.2.1
TMP1075==0.2.1
typing_extensions==4.12.2
wheel==0.41.2
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"pyserial==3.5",
"pyusb==1.2.1",
"rpi_hardware_pwm==0.2.1",
"TMP1075==0.2.1",
"typing_extensions==4.12.2",
"wheel==0.41.2",
]
Expand Down

0 comments on commit d9024aa

Please sign in to comment.