mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +03:00
python_examples: Reformatted, self-checking, executable
* Moved body of each python example to main. This allows for basic load module testing for CI * General cleanup of python modules (crlf/tabs/prints/etc) * Chmod'ed to 755 to allow running examples without specifying the python interpreter * Added ctest for loading python2/3 modules * Added jniclasscode pragma for java swig interface files. * Updated check_examplenames.py module to check all languages vs. a cxx example name * Added tests for checking python module and test loading * Added 'make test' to travis-ci run (run ctests) * Print a more meaningful message when not building cxx docs into python modules * Updated check_clean.py to only check java wrapper files * ENABLED ctests for UPM * Deleted using_carrays.py python example - this is covered by other examples Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
80
examples/python/at42qt1070.py
Normal file → Executable file
80
examples/python/at42qt1070.py
Normal file → Executable file
@ -24,56 +24,56 @@
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_at42qt1070 as upmAt42qt1070
|
||||
|
||||
# functions
|
||||
def printButtons(touchObj):
|
||||
buttonPressed = False
|
||||
buttons = touchObj.getButtons()
|
||||
def main():
|
||||
# functions
|
||||
def printButtons(touchObj):
|
||||
buttonPressed = False
|
||||
buttons = touchObj.getButtons()
|
||||
|
||||
sys.stdout.write("Buttons Pressed: ")
|
||||
for i in range(7):
|
||||
if (buttons & (1 << i)):
|
||||
sys.stdout.write(str(i) + " ")
|
||||
buttonPressed = True
|
||||
sys.stdout.write("Buttons Pressed: ")
|
||||
for i in range(7):
|
||||
if (buttons & (1 << i)):
|
||||
sys.stdout.write(str(i) + " ")
|
||||
buttonPressed = True
|
||||
|
||||
if (not buttonPressed):
|
||||
sys.stdout.write("None")
|
||||
if (not buttonPressed):
|
||||
sys.stdout.write("None")
|
||||
|
||||
print " "
|
||||
print " "
|
||||
|
||||
if (touchObj.isCalibrating()):
|
||||
print "Calibration is occurring."
|
||||
if (touchObj.isCalibrating()):
|
||||
print "Calibration is occurring."
|
||||
|
||||
if (touchObj.isOverflowed()):
|
||||
print "Overflow was detected."
|
||||
if (touchObj.isOverflowed()):
|
||||
print "Overflow was detected."
|
||||
|
||||
# Global code that runs on startup
|
||||
|
||||
# Global code that runs on startup
|
||||
I2C_BUS = upmAt42qt1070.AT42QT1070_I2C_BUS
|
||||
DEFAULT_I2C_ADDR = upmAt42qt1070.AT42QT1070_DEFAULT_I2C_ADDR
|
||||
|
||||
I2C_BUS = upmAt42qt1070.AT42QT1070_I2C_BUS
|
||||
DEFAULT_I2C_ADDR = upmAt42qt1070.AT42QT1070_DEFAULT_I2C_ADDR
|
||||
# Instantiate an AT42QT1070 on I2C bus 0
|
||||
myTouchSensor = upmAt42qt1070.AT42QT1070(I2C_BUS,
|
||||
DEFAULT_I2C_ADDR)
|
||||
|
||||
# Instantiate an AT42QT1070 on I2C bus 0
|
||||
myTouchSensor = upmAt42qt1070.AT42QT1070(I2C_BUS,
|
||||
DEFAULT_I2C_ADDR)
|
||||
# Exit handlers
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Exit handlers
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
# This function lets you run code on exit, including functions from myTouchSensor
|
||||
atexit.register(exitHandler)
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
# Print the button being touched every 0.1 seconds
|
||||
while(1):
|
||||
myTouchSensor.updateState()
|
||||
printButtons(myTouchSensor)
|
||||
time.sleep(.1)
|
||||
|
||||
|
||||
# This function lets you run code on exit, including functions from myTouchSensor
|
||||
atexit.register(exitHandler)
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
|
||||
# Print the button being touched every 0.1 seconds
|
||||
while(1):
|
||||
myTouchSensor.updateState()
|
||||
printButtons(myTouchSensor)
|
||||
time.sleep(.1)
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user