From f7bec3f891e45edc932bb790dd82b23335d60522 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sun, 26 Feb 2017 14:07:11 -0600 Subject: [PATCH] forgot to update the chip pro detection in Utilties, removed overlay stuff from makefile, cleaned up readme --- CHANGELOG.rst | 5 ++ CHIP_IO/Utilities.py | 110 +++++++++++++++++++++++++------------------ Makefile | 1 - README.rst | 28 ++++++----- debian/changelog | 8 ++++ setup.py | 2 +- source/constants.c | 2 +- 7 files changed, 95 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 00411ce..241d2a3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +0.5.2 +--- +* Updating Utilties to determine CHIP Pro better +* Updating the README to fix things + 0.5.0 --- * CHIP Pro Support diff --git a/CHIP_IO/Utilities.py b/CHIP_IO/Utilities.py index 3bbff6d..f513677 100644 --- a/CHIP_IO/Utilities.py +++ b/CHIP_IO/Utilities.py @@ -43,53 +43,66 @@ def toggle_debug(): # Set the 1.8V-pin on the CHIP U13-header to given voltage # Return False on error def set_1v8_pin_voltage(voltage): - if not isinstance(voltage, int) and not isinstance(voltage, float): - 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 not is_chip_pro(): + if not isinstance(voltage, int) and not isinstance(voltage, float): + return False + if voltage < 1.8 or voltage > 3.3: + return False 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 + 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 + else: + print("Set 1.8V Pin Voltage not supported on the CHIP Pro") # Get the voltage the 1.8V-pin on the CHIP U13-header has been configured as # Return False on error def get_1v8_pin_voltage(): - p=subprocess.Popen(["/usr/sbin/i2cget", "-f", "-y", "0", "0x34", "0x90"], stdout=subprocess.PIPE) - output=p.communicate()[0].decode("utf-8").strip() - #Not configured as an output - if output != "0x03": + if not is_chip_pro(): + p=subprocess.Popen(["/usr/sbin/i2cget", "-f", "-y", "0", "0x34", "0x90"], stdout=subprocess.PIPE) + 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("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 + print("Current 1.8V Pin voltage: {0}".format(voltage)) + return voltage + else: + print("Get 1.8V Pin Voltage not supported on the CHIP Pro") # Enable 1.8V Pin on CHIP U13 Header def enable_1v8_pin(): - set_1v8_pin_voltage(1.8) + if not is_chip_pro(): + set_1v8_pin_voltage(1.8) + else: + print("Enable 1.8V Pin not supported on the CHIP Pro") # 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) - # Then we have to write 0x07 to AXP-209 Register 0x90 - subprocess.call('/usr/sbin/i2cset -f -y 0 0x34 0x90 0x07', shell=True) + + if not is_chip_pro(): + 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) + # Then we have to write 0x07 to AXP-209 Register 0x90 + subprocess.call('/usr/sbin/i2cset -f -y 0 0x34 0x90 0x07', shell=True) + else: + print("Disable 1.8V Pin not supported on the CHIP Pro") # Unexport All def unexport_all(): @@ -107,18 +120,25 @@ def unexport_all(): def is_chip_pro(): isgr8 = False if DEBUG: - print("Determining if computer has R8 or GR8 SOC") + print("Determining if computer is CHIP or CHIP Pro") - files = glob.glob("/boot/*.dtb") - for f in files: - if "gr8" in f.lower(): - isgr8 = True - if DEBUG: - print("Found gr8 SOC") - break + # GET FIRST LINE FROM /proc/meminfo + f = open("/proc/meminfo","r") + fline = f.readline() + f.close() - if DEBUG and not isgr8: - print("Found r8 SOC") + # FIGURE OUT OUR TOTAL MEMORY SIZE + parts = fline.split() + mem = float(parts[1]) / 1024 + if mem > 380: + isgr8 = False + if DEBUG: + print("found CHIP!") + else: + isgr8 = True + if DEBUG: + print("found CHIP Pro!") + # Return isgr8 return isgr8 diff --git a/Makefile b/Makefile index ad62a72..147a3bb 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ clean: rm -rf CHIP_IO.* build dist rm -f *.pyo *.pyc rm -f *.egg - rm -f overlays/*.pyo overlays/*.pyc rm -rf __pycache__ rm -rf debian/python-chip-io* rm -rf debian/python3-chip-io* diff --git a/README.rst b/README.rst index e8a8948..ae14212 100644 --- a/README.rst +++ b/README.rst @@ -2,19 +2,12 @@ CHIP_IO ============================ A CHIP GPIO library -NOTE: Now requires the custom DTC to install the library - -Manual:: +Manual Installation:: For Python2.7:: sudo apt-get update sudo apt-get install git build-essential python-dev python-pip flex bison chip-dt-overlays -y - git clone https://github.com/atenart/dtc.git - cd dtc - make - sudo make install PREFIX=/usr - cd .. git clone git://github.com/xtacocorex/CHIP_IO.git cd CHIP_IO sudo python setup.py install @@ -24,16 +17,25 @@ For Python3:: sudo apt-get update sudo apt-get install git build-essential python3-dev python3-pip flex bison chip-dt-overlays -y - git clone https://github.com/atenart/dtc.git - cd dtc - make - sudo make install PREFIX=/usr - cd .. git clone git://github.com/xtacocorex/CHIP_IO.git cd CHIP_IO sudo python3 setup.py install cd .. +PyPi Installation:: + +For Python2.7:: + + sudo apt-get update + sudo apt-get install git build-essential python-dev python-pip flex bison chip-dt-overlays -y + sudo pip install CHIP-IO + +For Python3:: + + sudo apt-get update + sudo apt-get install git build-essential python3-dev python3-pip flex bison chip-dt-overlays -y + sudo pip3 install CHIP-IO + **Usage** Using the library is very similar to the excellent RPi.GPIO library used on the Raspberry Pi. Below are some examples. diff --git a/debian/changelog b/debian/changelog index a7d0873..d200864 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +chip-io (0.5.2-1) unstable; urgency=low + + * Updating Utilities to determine CHIP Pro better + * Updating Utilities to only run CHIP appropriate code on the CHIP and not CHIP Pro + * Updated README + + -- Robert Wolterman Sun, 26 Feb 2017 13:56:00 -0600 + chip-io (0.5.0-1) unstable; urgency=low * CHIP Pro support for PWM1, reduced GPIO capability diff --git a/setup.py b/setup.py index d61e047..9e531e6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.5.0', + version = '0.5.2', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/constants.c b/source/constants.c index 10424d6..8939154 100644 --- a/source/constants.c +++ b/source/constants.c @@ -85,6 +85,6 @@ void define_constants(PyObject *module) bcm = Py_BuildValue("i", BCM); PyModule_AddObject(module, "BCM", bcm); - version = Py_BuildValue("s", "0.5.0"); + version = Py_BuildValue("s", "0.5.2"); PyModule_AddObject(module, "VERSION", version); }