Skip to content

Fix pylint #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 36 additions & 39 deletions examples/ina260_latch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,41 @@
# catch exception on init, no INA260 chip found
print(r_e)
raise r_e
else:
# set overcurrent limit flag and threshold value
# 0x0008 x 1,25 mA = 10 mA as alert limit
ina260.alert_limit = 0x0008

# alert pin is asserted, can be check with gpiozero
ina260.overcurrent_limit = True

# keep the flag high until MASK_ENABLE register will be read
ina260.alert_latch_enable = True

ina260.mode = Mode.CONTINUOUS

# set higher conversion time and wait its value before each read
ina260.current_conversion_time = ConversionTime.TIME_8_244_ms
for _ in enumerate(range(5)):
time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time))
print(
"Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
% (ina260.current, ina260.voltage, ina260.power)
)

# supposing meanwhile the alert limit was exceeded, setting an higher limit
# and clear the ALERT
# 0x0100 x 1,25 mA = 320 mA as alert limit
ina260.alert_limit = 0x0100

# alert function flag bit should be true if alert threshold was exceeded
print("Alert function flag: {}".format(ina260.alert_function_flag))

# in latch mode, reading the register clears the ALERT & alert function flag
print("MASK register: {}".format(ina260.mask_enable))

# reset the whole chip and wait 2 sec
ina260.reset_bit = True
time.sleep(2)

# set overcurrent limit flag and threshold value
# 0x0008 x 1,25 mA = 10 mA as alert limit
ina260.alert_limit = 0x0008

# alert pin is asserted, can be check with gpiozero
ina260.overcurrent_limit = True

# keep the flag high until MASK_ENABLE register will be read
ina260.alert_latch_enable = True

ina260.mode = Mode.CONTINUOUS

# set higher conversion time and wait its value before each read
ina260.current_conversion_time = ConversionTime.TIME_8_244_ms
for _ in enumerate(range(5)):
time.sleep(ConversionTime.get_seconds(ina260.current_conversion_time))
print(
"MASK_REGISTER check, must be 0x0000 after reset: {}".format(
ina260.mask_enable
)
f"Current: {ina260.current:.2f} mA, "
f"Voltage: {ina260.voltage:.2f} V, "
f"Power: {ina260.power:.2f} mW"
)

# supposing meanwhile the alert limit was exceeded, setting an higher limit
# and clear the ALERT
# 0x0100 x 1,25 mA = 320 mA as alert limit
ina260.alert_limit = 0x0100

# alert function flag bit should be true if alert threshold was exceeded
print("Alert function flag: ", ina260.alert_function_flag)

# in latch mode, reading the register clears the ALERT & alert function flag
print("MASK register:", ina260.mask_enable)

# reset the whole chip and wait 2 sec
ina260.reset_bit = True
time.sleep(2)
print("MASK_REGISTER check, must be 0x0000 after reset:", ina260.mask_enable)