Skip to content

Commit d18ae60

Browse files
committed
Linted per pre-commit
1 parent 11a8942 commit d18ae60

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

examples/ina260_latch.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,42 @@
1616
# catch exception on init, no INA260 chip found
1717
print(r_e)
1818
raise r_e
19-
else:
20-
# set overcurrent limit flag and threshold value
21-
# 0x0008 x 1,25 mA = 10 mA as alert limit
22-
ina260.alert_limit = 0x0008
23-
24-
# alert pin is asserted, can be check with gpiozero
25-
ina260.overcurrent_limit = True
26-
27-
# keep the flag high until MASK_ENABLE register will be read
28-
ina260.alert_latch_enable = True
29-
30-
ina260.mode = Mode.CONTINUOUS
31-
32-
# set higher conversion time and wait its value before each read
33-
ina260.current_conversion_time = ConversionTime.TIME_8_244_ms
34-
for _ in enumerate(range(5)):
35-
time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time))
36-
print(
37-
"Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
38-
% (ina260.current, ina260.voltage, ina260.power)
39-
)
40-
41-
# supposing meanwhile the alert limit was exceeded, setting an higher limit
42-
# and clear the ALERT
43-
# 0x0100 x 1,25 mA = 320 mA as alert limit
44-
ina260.alert_limit = 0x0100
45-
46-
# alert function flag bit should be true if alert threshold was exceeded
47-
print("Alert function flag: {}".format(ina260.alert_function_flag))
48-
49-
# in latch mode, reading the register clears the ALERT & alert function flag
50-
print("MASK register: {}".format(ina260.mask_enable))
51-
52-
# reset the whole chip and wait 2 sec
53-
ina260.reset_bit = True
54-
time.sleep(2)
19+
20+
# set overcurrent limit flag and threshold value
21+
# 0x0008 x 1,25 mA = 10 mA as alert limit
22+
ina260.alert_limit = 0x0008
23+
24+
# alert pin is asserted, can be check with gpiozero
25+
ina260.overcurrent_limit = True
26+
27+
# keep the flag high until MASK_ENABLE register will be read
28+
ina260.alert_latch_enable = True
29+
30+
ina260.mode = Mode.CONTINUOUS
31+
32+
# set higher conversion time and wait its value before each read
33+
ina260.current_conversion_time = ConversionTime.TIME_8_244_ms
34+
for _ in enumerate(range(5)):
35+
time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time))
5536
print(
56-
"MASK_REGISTER check, must be 0x0000 after reset: {}".format(
57-
ina260.mask_enable
58-
)
37+
"Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
38+
% (ina260.current, ina260.voltage, ina260.power)
5939
)
40+
41+
# supposing meanwhile the alert limit was exceeded, setting an higher limit
42+
# and clear the ALERT
43+
# 0x0100 x 1,25 mA = 320 mA as alert limit
44+
ina260.alert_limit = 0x0100
45+
46+
# alert function flag bit should be true if alert threshold was exceeded
47+
print("Alert function flag: {}".format(ina260.alert_function_flag))
48+
49+
# in latch mode, reading the register clears the ALERT & alert function flag
50+
print("MASK register: {}".format(ina260.mask_enable))
51+
52+
# reset the whole chip and wait 2 sec
53+
ina260.reset_bit = True
54+
time.sleep(2)
55+
print(
56+
"MASK_REGISTER check, must be 0x0000 after reset: {}".format(ina260.mask_enable)
57+
)

0 commit comments

Comments
 (0)