Skip to content

Commit cea4a31

Browse files
committed
interrupts working
1 parent 812d4e9 commit cea4a31

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

adafruit_pct2075.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@
4949

5050
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
5151
from adafruit_register.i2c_bits import ROBits, RWBits
52-
from adafruit_register.i2c_bit import RWBit, ROBit
52+
from adafruit_register.i2c_bit import RWBit, ROBit
5353
import adafruit_bus_device.i2c_device as i2cdevice
54-
55-
PCT2075_DEFAULT_ADDRESS = 0x48
5654
__version__ = "0.0.0-auto.0"
5755
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCT2075.git"
5856

@@ -68,19 +66,27 @@ class Mode:
6866
INTERRUPT = 1
6967
COMPARITOR = 0
7068

69+
class FaultCount:
70+
FAULT_1 = 0
71+
FAULT_2 = 1
72+
FAULT_4 = 3
73+
FAULT_6 = 4
74+
75+
7176
class PCT2075:
7277

7378
def __init__(self, i2c_bus, address=PCT2075_DEFAULT_ADDRESS):
7479
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
7580

7681
_temperature = ROUnaryStruct(PCT2075_REGISTER_TEMP, ">h")
77-
mode = RWBit(PCT2075_REGISTER_CONFIG, 1, 1)
82+
mode = RWBit(PCT2075_REGISTER_CONFIG, 1, register_width=1)
7883

7984
shutdown = RWBit(PCT2075_REGISTER_CONFIG, 0, 1)
80-
_fault_queue_length = RWBits(2, PCT2075_REGISTER_CONFIG, 5, 1)
85+
_fault_queue_length = RWBits(2, PCT2075_REGISTER_CONFIG, 5, register_width=1)
8186
_high_temperature_threshold = UnaryStruct(PCT2075_REGISTER_TOS, ">h")
82-
_temp_hysteresis = UnaryStruct(PCT2075_REGISTER_TOS, ">h")
83-
_idle_time = RWBits(5, PCT2075_REGISTER_TIDLE, 0, 1)
87+
_temp_hysteresis = UnaryStruct(PCT2075_REGISTER_THYST, ">h")
88+
_idle_time = RWBits(5, PCT2075_REGISTER_TIDLE, 0, register_width=1)
89+
high_temp_active_low = RWBit(PCT2075_REGISTER_CONFIG, 2, register_width=1)
8490

8591
@property
8692
def temperature(self):
@@ -89,18 +95,27 @@ def temperature(self):
8995

9096
@property
9197
def high_temperature_threshold(self):
92-
return (self._high_temperature_threshold >> 7)
98+
return (self._high_temperature_threshold >> 7) * 0.5
9399

94100
@high_temperature_threshold.setter
95101
def high_temperature_threshold(self, value):
96-
self._high_temp_threshold = (value <<7)
102+
self._high_temperature_threshold = (int(value * 2) << 7)
97103

98104
@property
99-
def temperatur_hysteresis(self):
100-
return (self._temp_hysteresis >> 7)
101-
102-
@temperatur_hysteresis.setter
103-
def temperatur_hysteresis(self, value):
104-
self._temp_hysteresis = (value << 7)
105+
def temperature_hysteresis(self):
106+
return (self._temp_hysteresis >> 7) * 0.5
105107

108+
@temperature_hysteresis.setter
109+
def temperature_hysteresis(self, value):
110+
# TODO: check that hyst is < threshold
111+
self._temp_hysteresis = (int(value * 2) << 7)
106112

113+
@property
114+
def faults_to_alert(self):
115+
return self._fault_queue_length
116+
117+
@faults_to_alert.setter
118+
def faults_to_alert(self, value):
119+
if value > 4 or value < 1:
120+
raise ValueError("faults_to_alert must be an adafruit_pct2075.FaultCount")
121+
self._fault_queue_length = value

0 commit comments

Comments
 (0)