• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2# Author: Zion Orent <zorent@ics.com>
3# Copyright (c) 2015 Intel Corporation.
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sublicense, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24import time, sys, signal, atexit
25import pyupm_at42qt1070 as upmAt42qt1070
26
27# functions
28def printButtons(touchObj):
29	buttonPressed = False
30	buttons = touchObj.getButtons()
31
32	sys.stdout.write("Buttons Pressed: ")
33	for i in range(7):
34		if (buttons & (1 << i)):
35			sys.stdout.write(str(i) + " ")
36			buttonPressed = True
37
38	if (not buttonPressed):
39		sys.stdout.write("None")
40
41	print " "
42
43	if (touchObj.isCalibrating()):
44		print "Calibration is occurring."
45
46	if (touchObj.isOverflowed()):
47		print "Overflow was detected."
48
49
50# Global code that runs on startup
51
52I2C_BUS = upmAt42qt1070.AT42QT1070_I2C_BUS
53DEFAULT_I2C_ADDR = upmAt42qt1070.AT42QT1070_DEFAULT_I2C_ADDR
54
55# Instantiate an AT42QT1070 on I2C bus 0
56myTouchSensor = upmAt42qt1070.AT42QT1070(I2C_BUS,
57                                         DEFAULT_I2C_ADDR)
58
59
60# Exit handlers
61def SIGINTHandler(signum, frame):
62	raise SystemExit
63
64def exitHandler():
65	print "Exiting"
66	sys.exit(0)
67
68
69# This function lets you run code on exit, including functions from myTouchSensor
70atexit.register(exitHandler)
71# This function stops python from printing a stacktrace when you hit control-C
72signal.signal(signal.SIGINT, SIGINTHandler)
73
74
75# Print the button being touched every 0.1 seconds
76while(1):
77	myTouchSensor.updateState()
78	printButtons(myTouchSensor)
79	time.sleep(.1)
80