mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 12:53:22 +00:00
Reworked a lot of error handling.
This commit is contained in:
96
test/.ropeproject/config.py
Normal file
96
test/.ropeproject/config.py
Normal file
@ -0,0 +1,96 @@
|
||||
# The default ``config.py``
|
||||
|
||||
|
||||
def set_prefs(prefs):
|
||||
"""This function is called before opening the project"""
|
||||
|
||||
# Specify which files and folders to ignore in the project.
|
||||
# Changes to ignored resources are not added to the history and
|
||||
# VCSs. Also they are not returned in `Project.get_files()`.
|
||||
# Note that ``?`` and ``*`` match all characters but slashes.
|
||||
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
|
||||
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
|
||||
# '.svn': matches 'pkg/.svn' and all of its children
|
||||
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
|
||||
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
|
||||
prefs['ignored_resources'] = [
|
||||
'*.pyc', '*~', '.ropeproject', '.hg', '.svn', '_svn', '.git',
|
||||
'.tox', '.env', 'node_modules', 'bower_components']
|
||||
|
||||
# Specifies which files should be considered python files. It is
|
||||
# useful when you have scripts inside your project. Only files
|
||||
# ending with ``.py`` are considered to be python files by
|
||||
# default.
|
||||
#prefs['python_files'] = ['*.py']
|
||||
|
||||
# Custom source folders: By default rope searches the project
|
||||
# for finding source folders (folders that should be searched
|
||||
# for finding modules). You can add paths to that list. Note
|
||||
# that rope guesses project source folders correctly most of the
|
||||
# time; use this if you have any problems.
|
||||
# The folders should be relative to project root and use '/' for
|
||||
# separating folders regardless of the platform rope is running on.
|
||||
# 'src/my_source_folder' for instance.
|
||||
#prefs.add('source_folders', 'src')
|
||||
|
||||
# You can extend python path for looking up modules
|
||||
#prefs.add('python_path', '~/python/')
|
||||
|
||||
# Should rope save object information or not.
|
||||
prefs['save_objectdb'] = True
|
||||
prefs['compress_objectdb'] = False
|
||||
|
||||
# If `True`, rope analyzes each module when it is being saved.
|
||||
prefs['automatic_soa'] = True
|
||||
# The depth of calls to follow in static object analysis
|
||||
prefs['soa_followed_calls'] = 0
|
||||
|
||||
# If `False` when running modules or unit tests "dynamic object
|
||||
# analysis" is turned off. This makes them much faster.
|
||||
prefs['perform_doa'] = True
|
||||
|
||||
# Rope can check the validity of its object DB when running.
|
||||
prefs['validate_objectdb'] = True
|
||||
|
||||
# How many undos to hold?
|
||||
prefs['max_history_items'] = 32
|
||||
|
||||
# Shows whether to save history across sessions.
|
||||
prefs['save_history'] = True
|
||||
prefs['compress_history'] = False
|
||||
|
||||
# Set the number spaces used for indenting. According to
|
||||
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
|
||||
# unit-tests use 4 spaces it is more reliable, too.
|
||||
prefs['indent_size'] = 4
|
||||
|
||||
# Builtin and c-extension modules that are allowed to be imported
|
||||
# and inspected by rope.
|
||||
prefs['extension_modules'] = []
|
||||
|
||||
# Add all standard c-extensions to extension_modules list.
|
||||
prefs['import_dynload_stdmods'] = True
|
||||
|
||||
# If `True` modules with syntax errors are considered to be empty.
|
||||
# The default value is `False`; When `False` syntax errors raise
|
||||
# `rope.base.exceptions.ModuleSyntaxError` exception.
|
||||
prefs['ignore_syntax_errors'] = False
|
||||
|
||||
# If `True`, rope ignores unresolvable imports. Otherwise, they
|
||||
# appear in the importing namespace.
|
||||
prefs['ignore_bad_imports'] = False
|
||||
|
||||
# If `True`, rope will transform a comma list of imports into
|
||||
# multiple separate import statements when organizing
|
||||
# imports.
|
||||
prefs['split_imports'] = False
|
||||
|
||||
# If `True`, rope will sort imports alphabetically by module name
|
||||
# instead of alphabetically by import statement, with from imports
|
||||
# after normal imports.
|
||||
prefs['sort_imports_alphabetically'] = False
|
||||
|
||||
|
||||
def project_opened(project):
|
||||
"""This function is called after opening the project"""
|
||||
# Do whatever you like here!
|
2
test/.ropeproject/globalnames
Normal file
2
test/.ropeproject/globalnames
Normal file
@ -0,0 +1,2 @@
|
||||
<EFBFBD>}q(Utest_softpwm_setup]q(Uteardown_moduleqUTestSoftpwmSetupqeUtest_gpio_output]q(hUTestGPIOOutputqeUtest_pwm_setup]q(hUTestPwmSetupqeUtest_gpio_setup]q (hU TestSetupq
|
||||
eUtest_gpio_input]q(hU
|
1
test/.ropeproject/history
Normal file
1
test/.ropeproject/history
Normal file
@ -0,0 +1 @@
|
||||
<EFBFBD>]q(]q]qe.
|
5
test/.ropeproject/objectdb
Normal file
5
test/.ropeproject/objectdb
Normal file
@ -0,0 +1,5 @@
|
||||
<EFBFBD>}qUS/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py}q(U
|
||||
Thread._blockcrope.base.oi.memorydb
|
||||
ScopeInfo
|
||||
q)<29>q}qUinstanceqUdefinedqUS/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyUThreadq<08><><EFBFBD>hhUS/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.pyU
|
||||
_Conditionq <09><>s}q
|
@ -1,27 +1,49 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import CHIP_IO.GPIO as GPIO
|
||||
import time, os, threading
|
||||
import time
|
||||
import threading
|
||||
|
||||
num_callbacks = 0
|
||||
|
||||
|
||||
def myfuncallback(channel):
|
||||
global num_callbacks
|
||||
num_callbacks += 1
|
||||
print "CALLBACK LIKE DRAKE IN HOTLINE BLING"
|
||||
|
||||
|
||||
|
||||
loopfunction_exit = False
|
||||
|
||||
|
||||
def loopfunction():
|
||||
print "LOOP FUNCTION"
|
||||
for i in xrange(20):
|
||||
for i in xrange(4):
|
||||
if loopfunction_exit:
|
||||
break
|
||||
if i % 2:
|
||||
print "SETTING CSID0 LOW"
|
||||
GPIO.output("CSID0",GPIO.LOW)
|
||||
print "SETTING CSID0 LOW (i=", i, ")"
|
||||
GPIO.output("CSID0", GPIO.LOW)
|
||||
else:
|
||||
print "SETTING CSID0 HIGH"
|
||||
GPIO.output("CSID0",GPIO.HIGH)
|
||||
print "SETTING CSID0 HIGH (i=", i, ")"
|
||||
GPIO.output("CSID0", GPIO.HIGH)
|
||||
print "SLEEPING"
|
||||
time.sleep(1)
|
||||
|
||||
print "SETUP XIO-P0"
|
||||
GPIO.setup("XIO-P0", GPIO.IN)
|
||||
|
||||
print "SETUP CSID0"
|
||||
|
||||
GPIO.selftest(0)
|
||||
|
||||
GPIO.setup("XIO-P0", GPIO.IN)
|
||||
GPIO.setup("CSID0", GPIO.OUT, initial=GPIO.HIGH)
|
||||
assert(GPIO.input("XIO-P0") == GPIO.HIGH)
|
||||
GPIO.cleanup()
|
||||
|
||||
GPIO.setup("XIO-P0", GPIO.IN)
|
||||
GPIO.setup("CSID0", GPIO.OUT, initial=GPIO.LOW)
|
||||
assert(GPIO.input("XIO-P0") == GPIO.LOW)
|
||||
GPIO.cleanup()
|
||||
|
||||
GPIO.setup("XIO-P0", GPIO.IN)
|
||||
GPIO.setup("CSID0", GPIO.OUT)
|
||||
|
||||
# VERIFY SIMPLE FUNCTIONALITY
|
||||
@ -29,51 +51,57 @@ print "VERIFY SIMPLE FUNCTIONALITY"
|
||||
|
||||
print "READING XIO-PI"
|
||||
GPIO.output("CSID0", GPIO.HIGH)
|
||||
print "HIGH", GPIO.input("XIO-P0")
|
||||
assert(GPIO.input("XIO-P0") == GPIO.HIGH)
|
||||
|
||||
GPIO.output("CSID0", GPIO.LOW)
|
||||
print "LOW", GPIO.input("XIO-P0")
|
||||
assert(GPIO.input("XIO-P0") == GPIO.LOW)
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - AP-EINT1
|
||||
print "SETTING UP EDGE DETECTION ON AP-EINT1"
|
||||
GPIO.setup("AP-EINT1", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT1",GPIO.FALLING)
|
||||
print "adding event detect"
|
||||
GPIO.add_event_detect("AP-EINT1", GPIO.RISING)
|
||||
|
||||
print "VERIFYING EDGE DETECT"
|
||||
f = open("/sys/class/gpio/gpio193/edge","r")
|
||||
f = open("/sys/class/gpio/gpio193/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
print "EDGE: %s" % edge
|
||||
print "edge='", edge, "'"
|
||||
assert(edge == "rising\n")
|
||||
GPIO.remove_event_detect("AP-EINT1")
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - AP-EINT3
|
||||
print "SETTING UP EDGE DETECTION ON AP-EINT3"
|
||||
GPIO.setup("AP-EINT3", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT3",GPIO.FALLING)
|
||||
GPIO.add_event_detect("AP-EINT3", GPIO.BOTH)
|
||||
|
||||
print "VERIFYING EDGE DETECT"
|
||||
f = open("/sys/class/gpio/gpio35/edge","r")
|
||||
f = open("/sys/class/gpio/gpio35/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
print "EDGE: %s" % edge
|
||||
assert(edge == "both\n")
|
||||
GPIO.remove_event_detect("AP-EINT3")
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - EXPANDED GPIO
|
||||
print "SETTING UP EDGE DETECTION ON XIO-P0"
|
||||
GPIO.add_event_detect("XIO-P0",GPIO.FALLING,myfuncallback)
|
||||
GPIO.add_event_detect("XIO-P0", GPIO.FALLING, myfuncallback)
|
||||
|
||||
print "VERIFYING EDGE DETECT"
|
||||
f = open("/sys/class/gpio/gpio408/edge","r")
|
||||
f = open("/sys/class/gpio/gpio408/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
print "EDGE: %s" % edge
|
||||
assert(edge == "falling\n")
|
||||
|
||||
# LOOP WRITING ON CSID0 TO HOPEFULLY GET CALLBACK TO WORK
|
||||
print "WAITING FOR CALLBACKS"
|
||||
loopfunction()
|
||||
print "num_callbacks=", num_callbacks
|
||||
|
||||
print "PRESS CONTROL-C TO EXIT IF SCRIPT GETS STUCK"
|
||||
GPIO.remove_event_detect("XIO-P0")
|
||||
@ -82,18 +110,30 @@ try:
|
||||
t = threading.Thread(target=loopfunction)
|
||||
t.start()
|
||||
print "WAITING FOR EDGE"
|
||||
GPIO.wait_for_edge("XIO-P0",GPIO.FALLING)
|
||||
GPIO.wait_for_edge("XIO-P0", GPIO.FALLING)
|
||||
print "WE'VE FALLEN LIKE COOLIO'S CAREER"
|
||||
print "ATTEMPTING TO CANCEL THE TIMER"
|
||||
t.cancel()
|
||||
except:
|
||||
pass
|
||||
|
||||
print "Exit thread"
|
||||
loopfunction_exit = True
|
||||
t.join() # Wait till the thread exits.
|
||||
GPIO.remove_event_detect("XIO-P0")
|
||||
|
||||
print "TESTING ERRORS THROWN WHEN SPECIFYING EDGE DETECTION ON UNAUTHORIZED GPIO"
|
||||
GPIO.setup("CSID1",GPIO.IN)
|
||||
GPIO.add_event_detect("CSID1",GPIO.FALLING,myfuncallback)
|
||||
GPIO.setup("CSID1", GPIO.IN)
|
||||
try:
|
||||
GPIO.add_event_detect("CSID1", GPIO.FALLING, myfuncallback)
|
||||
print "Oops, it did not throw an exception! BUG!!!"
|
||||
except:
|
||||
pass
|
||||
|
||||
print "TESTING ERRORS THROWN WHEN WRITING TO A GPIO WITH NO DIRECTION"
|
||||
try:
|
||||
GPIO.output("CSID1", GPIO.LOW)
|
||||
print "Oops, it did not throw an exception! BUG!!!"
|
||||
except:
|
||||
pass
|
||||
|
||||
print "CLEANUP"
|
||||
GPIO.remove_event_detect("XIO-P0")
|
||||
GPIO.cleanup()
|
||||
|
||||
|
Reference in New Issue
Block a user