Skip to content

Commit 011174a

Browse files
authored
Merge pull request #25 from tekktrik/dev/fix-pylint
Fix pylint
2 parents 11a8942 + ce08972 commit 011174a

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

examples/ina260_latch.py

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,41 @@
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+
f"Current: {ina260.current:.2f} mA, "
38+
f"Voltage: {ina260.voltage:.2f} V, "
39+
f"Power: {ina260.power:.2f} mW"
5940
)
41+
42+
# supposing meanwhile the alert limit was exceeded, setting an higher limit
43+
# and clear the ALERT
44+
# 0x0100 x 1,25 mA = 320 mA as alert limit
45+
ina260.alert_limit = 0x0100
46+
47+
# alert function flag bit should be true if alert threshold was exceeded
48+
print("Alert function flag: ", ina260.alert_function_flag)
49+
50+
# in latch mode, reading the register clears the ALERT & alert function flag
51+
print("MASK register:", ina260.mask_enable)
52+
53+
# reset the whole chip and wait 2 sec
54+
ina260.reset_bit = True
55+
time.sleep(2)
56+
print("MASK_REGISTER check, must be 0x0000 after reset:", ina260.mask_enable)

0 commit comments

Comments
 (0)