pimoroni / EnviroPlus-FeatherWing

CircuitPython library for the Enviro+ FeatherWing
https://shop.pimoroni.com/products/enviro-plus-featherwing
MIT License
10 stars 11 forks source link

gas.py has a problem with gas.cleanup() called first. #7

Closed dglaude closed 4 years ago

dglaude commented 4 years ago

Running this simple code:

from pimoroni_envirowing import gas

gas.cleanup()

Trigger the following output:

main.py output: Traceback (most recent call last): File "main.py", line 3, in File "pimoroni_envirowing/gas.py", line 50, in cleanup NameError: name 'enable' is not defined

This is actually what the demo code is doing:

from pimoroni_envirowing import gas
import time
while True:
    try:
        print(gas.read_all())
        time.sleep(0.1)
    finally:
        gas.cleanup()

At least if the first call to gas.read_all() fail with an exception.

Gadgetoid commented 4 years ago

Looks like enable should be defined in the top of the script as enable = None. In fact I'd probably refactor that to enable_pin.

Then a check for if enable_pin is not None: in cleanup() should suffice.

There's always the trap the exception method, too, but in cases like this I definitely prefer the former.

Gadgetoid commented 4 years ago

This is- with any luck- fixed in #10