38
38
39
39
# Register Definitions
40
40
CONFIGURATION = 0x00
41
- SHUNTVOLTAGE_CH1 = 0x01
42
- BUSVOLTAGE_CH1 = 0x02
43
- SHUNTVOLTAGE_CH2 = 0x03
44
- BUSVOLTAGE_CH2 = 0x04
45
- SHUNTVOLTAGE_CH3 = 0x05
46
- BUSVOLTAGE_CH3 = 0x06
47
- CRITICAL_ALERT_LIMIT_CH1 = 0x07
48
- WARNING_ALERT_LIMIT_CH1 = 0x08
49
- CRITICAL_ALERT_LIMIT_CH2 = 0x09
50
- WARNING_ALERT_LIMIT_CH2 = 0x0A
51
- CRITICAL_ALERT_LIMIT_CH3 = 0x0B
52
- WARNING_ALERT_LIMIT_CH3 = 0x0C
41
+ SHUNTVOLTAGE_REGS = [0x01 , 0x03 , 0x05 ]
42
+ BUSTVOLTAGE_REGS = [0x02 , 0x04 , 0x06 ]
43
+ CRITICAL_ALERT_LIMIT_REGS = [0x07 , 0x09 , 0x0B ]
44
+ WARNING_ALERT_LIMIT_REGS = [0x08 , 0x0A , 0x0C ]
53
45
SHUNTVOLTAGE_SUM = 0x0D
54
46
SHUNTVOLTAGE_SUM_LIMIT = 0x0E
55
47
MASK_ENABLE = 0x0F
@@ -170,7 +162,7 @@ def enable(self) -> None:
170
162
@property
171
163
def bus_voltage (self ) -> float :
172
164
"""Bus voltage in volts."""
173
- reg_address = [ BUSVOLTAGE_CH1 , BUSVOLTAGE_CH2 , BUSVOLTAGE_CH3 ] [self ._channel ]
165
+ reg_address = BUSVOLTAGE_REGS [self ._channel ]
174
166
result = self ._device ._read_register (reg_address , 2 )
175
167
raw_value = int .from_bytes (result , "big" )
176
168
voltage = (raw_value >> 3 ) * 8e-3
@@ -179,9 +171,7 @@ def bus_voltage(self) -> float:
179
171
@property
180
172
def shunt_voltage (self ) -> float :
181
173
"""Shunt voltage in millivolts."""
182
- reg_address = [SHUNTVOLTAGE_CH1 , SHUNTVOLTAGE_CH2 , SHUNTVOLTAGE_CH3 ][
183
- self ._channel
184
- ]
174
+ reg_address = SHUNTVOLTAGE_REGS [self ._channel ]
185
175
result = self ._device ._read_register (reg_address , 2 )
186
176
raw_value = int .from_bytes (result , "big" )
187
177
raw_value = (
@@ -217,15 +207,15 @@ def critical_alert_threshold(self) -> float:
217
207
Returns:
218
208
float: The current critical alert threshold in amperes.
219
209
"""
220
- reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self ._channel
210
+ reg_addr = CRITICAL_ALERT_LIMIT_REGS [ self ._channel ]
221
211
result = self ._device ._read_register (reg_addr , 2 )
222
212
threshold = int .from_bytes (result , "big" )
223
213
return (threshold >> 3 ) * 40e-6 / self ._shunt_resistance
224
214
225
215
@critical_alert_threshold .setter
226
216
def critical_alert_threshold (self , current : float ) -> None :
227
217
threshold = int (current * self ._shunt_resistance / 40e-6 * 8 )
228
- reg_addr = CRITICAL_ALERT_LIMIT_CH1 + 2 * self ._channel
218
+ reg_addr = CRITICAL_ALERT_LIMIT_REGS [ self ._channel ]
229
219
threshold_bytes = threshold .to_bytes (2 , "big" )
230
220
self ._device ._write_register (reg_addr , threshold_bytes )
231
221
@@ -236,15 +226,15 @@ def warning_alert_threshold(self) -> float:
236
226
Returns:
237
227
float: The current warning alert threshold in amperes.
238
228
"""
239
- reg_addr = WARNING_ALERT_LIMIT_CH1 + self ._channel
229
+ reg_addr = WARNING_ALERT_LIMIT_REGS [ self ._channel ]
240
230
result = self ._device ._read_register (reg_addr , 2 )
241
231
threshold = int .from_bytes (result , "big" )
242
232
return threshold / (self ._shunt_resistance * 8 )
243
233
244
234
@warning_alert_threshold .setter
245
235
def warning_alert_threshold (self , current : float ) -> None :
246
236
threshold = int (current * self ._shunt_resistance * 8 )
247
- reg_addr = WARNING_ALERT_LIMIT_CH1 + self ._channel
237
+ reg_addr = WARNING_ALERT_LIMIT_REGS [ self ._channel ]
248
238
threshold_bytes = threshold .to_bytes (2 , "big" )
249
239
self ._device ._write_register (reg_addr , threshold_bytes )
250
240
0 commit comments