49
49
50
50
from adafruit_register .i2c_struct import ROUnaryStruct , UnaryStruct
51
51
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
53
53
import adafruit_bus_device .i2c_device as i2cdevice
54
-
55
- PCT2075_DEFAULT_ADDRESS = 0x48
56
54
__version__ = "0.0.0-auto.0"
57
55
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCT2075.git"
58
56
@@ -68,19 +66,27 @@ class Mode:
68
66
INTERRUPT = 1
69
67
COMPARITOR = 0
70
68
69
+ class FaultCount :
70
+ FAULT_1 = 0
71
+ FAULT_2 = 1
72
+ FAULT_4 = 3
73
+ FAULT_6 = 4
74
+
75
+
71
76
class PCT2075 :
72
77
73
78
def __init__ (self , i2c_bus , address = PCT2075_DEFAULT_ADDRESS ):
74
79
self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
75
80
76
81
_temperature = ROUnaryStruct (PCT2075_REGISTER_TEMP , ">h" )
77
- mode = RWBit (PCT2075_REGISTER_CONFIG , 1 , 1 )
82
+ mode = RWBit (PCT2075_REGISTER_CONFIG , 1 , register_width = 1 )
78
83
79
84
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 )
81
86
_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 )
84
90
85
91
@property
86
92
def temperature (self ):
@@ -89,18 +95,27 @@ def temperature(self):
89
95
90
96
@property
91
97
def high_temperature_threshold (self ):
92
- return (self ._high_temperature_threshold >> 7 )
98
+ return (self ._high_temperature_threshold >> 7 ) * 0.5
93
99
94
100
@high_temperature_threshold .setter
95
101
def high_temperature_threshold (self , value ):
96
- self ._high_temp_threshold = (value << 7 )
102
+ self ._high_temperature_threshold = (int ( value * 2 ) << 7 )
97
103
98
104
@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
105
107
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 )
106
112
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