diff --git a/CHIP_IO/LRADC.py b/CHIP_IO/LRADC.py index d4ac8e4..af84b74 100644 --- a/CHIP_IO/LRADC.py +++ b/CHIP_IO/LRADC.py @@ -42,9 +42,12 @@ CURRENT_SAMPLE_RATE_FILE = "/in_voltage_sampling_frequency" RAW_VOLTAGE_CHAN0_FILE = "/in_voltage0_raw" RAW_VOLTAGE_CHAN1_FILE = "/in_voltage1_raw" -def enable_debug(): +def toggle_debug(): global DEBUG - DEBUG = True + if DEBUG: + DEBUG = False + else: + DEBUG = True def setup(rate=250): # First we determine if the device exists diff --git a/CHIP_IO/OverlayManager.py b/CHIP_IO/OverlayManager.py index b664e59..821cd51 100644 --- a/CHIP_IO/OverlayManager.py +++ b/CHIP_IO/OverlayManager.py @@ -52,9 +52,12 @@ _FOLDERS = { "CUST" : "chip-cust" } -def enable_debug(): +def toggle_debug(): global DEBUG - DEBUG = True + if DEBUG: + DEBUG = False + else: + DEBUG = True def get_spi_loaded(): """ diff --git a/CHIP_IO/Utilities.py b/CHIP_IO/Utilities.py index 4f6516e..f83bb9d 100644 --- a/CHIP_IO/Utilities.py +++ b/CHIP_IO/Utilities.py @@ -28,6 +28,16 @@ import subprocess import glob import re +# Global Variables +DEBUG = False + +def toggle_debug(): + global DEBUG + if DEBUG: + DEBUG = False + else: + DEBUG = True + # Set the 1.8V-pin on the CHIP U13-header to given voltage # Return False on error def set_1v8_pin_voltage(voltage): @@ -35,10 +45,16 @@ def set_1v8_pin_voltage(voltage): return False if voltage < 1.8 or voltage > 3.3: return False + if DEBUG: + print("Setting 1.8V Pin voltage: {0}".format(voltage)) voltage=int(round((voltage - 1.8) / 0.1)) << 4 if subprocess.call(["/usr/sbin/i2cset", "-f", "-y" ,"0", "0x34", "0x90", "0x03"]): + if DEBUG: + print("Pin enable command failed") return False if subprocess.call(["/usr/sbin/i2cset", "-f", "-y", "0", "0x34", "0x91", str(voltage)]): + if DEBUG: + print("Pin set voltage command failed") return False return True @@ -49,10 +65,14 @@ def get_1v8_pin_voltage(): output=p.communicate()[0].decode("utf-8").strip() #Not configured as an output if output != "0x03": + if DEBUG: + print("1.8V Pin is currently disabled") return False p=subprocess.Popen(["/usr/sbin/i2cget", "-f", "-y", "0", "0x34", "0x91"], stdout=subprocess.PIPE) output=p.communicate()[0].decode("utf-8").strip() voltage=round((int(output, 16) >> 4) * 0.1 + 1.8, 1) + if DEBUG: + print("Current 1.8V Pin voltage: {0}".format(voltage)) return voltage # Enable 1.8V Pin on CHIP U13 Header @@ -61,6 +81,8 @@ def enable_1v8_pin(): # Disable 1.8V Pin on CHIP U13 Header def disable_1v8_pin(): + if DEBUG: + print("Disabling the 1.8V Pin") # CANNOT USE I2C LIB AS WE NEED TO FORCE THE COMMAND DUE TO THE KERNEL OWNING THE DEVICE # First we have to write 0x05 to AXP-209 Register 0x91 subprocess.call('/usr/sbin/i2cset -f -y 0 0x34 0x91 0x05', shell=True) @@ -69,6 +91,8 @@ def disable_1v8_pin(): # Unexport All def unexport_all(): + if DEBUG: + print("Unexporting all the pins") gpios = glob.glob("/sys/class/gpio/gpio[0-9]*") for g in gpios: tmp = g.split("/") diff --git a/test/lradc_test.py b/test/lradc_test.py index 2b1552d..a948d36 100644 --- a/test/lradc_test.py +++ b/test/lradc_test.py @@ -4,7 +4,7 @@ import CHIP_IO.LRADC as ADC # == ENABLE DEBUG == print("ENABLING LRADC DEBUG OUTPUT") -ADC.enable_debug() +ADC.toggle_debug() # == SETUP == print("LRADC SETUP WITH SAMPLE RATE OF 125")