|
57 | 57 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
58 | 58 | # THE SOFTWARE.
|
59 | 59 |
|
60 |
| -import adafruit_mpr121 |
61 |
| -import board |
62 |
| -import busio |
63 | 60 | import logging
|
64 | 61 | import subprocess
|
65 | 62 | import time
|
| 63 | +import board |
| 64 | +import busio |
66 | 65 | import uinput
|
| 66 | +import adafruit_mpr121 |
67 | 67 |
|
68 | 68 | # Define mapping of capacitive touch pin presses to keyboard button presses.
|
| 69 | + |
| 70 | +# Each line here should define a dict entry that maps the capacitive touch |
| 71 | +# input number to an appropriate key press. |
| 72 | +# |
| 73 | +# For reference the list of possible uinput.KEY_* values you can specify is |
| 74 | +# defined in linux/input.h: |
| 75 | +# http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8 |
| 76 | +# |
| 77 | +# Make sure a cap touch input is defined only once or else the program will |
| 78 | +# fail to run! |
| 79 | + |
69 | 80 | KEY_MAPPING = {
|
70 |
| - 0: uinput.KEY_UP, # Each line here should define a dict entry |
71 |
| - 1: uinput.KEY_DOWN, # that maps the capacitive touch input number |
72 |
| - 2: uinput.KEY_LEFT, # to an appropriate key press. |
73 |
| - 3: uinput.KEY_RIGHT, # |
74 |
| - 4: uinput.KEY_B, # For reference the list of possible uinput.KEY_* |
75 |
| - 5: uinput.KEY_A, # values you can specify is defined in linux/input.h: |
76 |
| - 6: uinput.KEY_ENTER, # http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8 |
77 |
| - 7: uinput.KEY_SPACE, # |
78 |
| - } # Make sure a cap touch input is defined only |
79 |
| - # once or else the program will fail to run! |
| 81 | + 0: uinput.KEY_UP, |
| 82 | + 1: uinput.KEY_DOWN, |
| 83 | + 2: uinput.KEY_LEFT, |
| 84 | + 3: uinput.KEY_RIGHT, |
| 85 | + 4: uinput.KEY_B, |
| 86 | + 5: uinput.KEY_A, |
| 87 | + 6: uinput.KEY_ENTER, |
| 88 | + 7: uinput.KEY_SPACE, |
| 89 | +} |
80 | 90 |
|
| 91 | +# Sleep this long between polling for events: |
81 | 92 | EVENT_WAIT_SLEEP_SECONDS = 0.25
|
82 | 93 |
|
83 | 94 | # Uncomment to enable debug message logging (might slow down key detection).
|
|
103 | 114 | # Call is_touched and pass it then number of the input. If it's touched
|
104 | 115 | # it will return True, otherwise it will return False.
|
105 | 116 | if mpr121[pin].value:
|
106 |
| - logging.debug('Input {0} touched!'.format(pin)) |
107 |
| - logging.debug('Key: {}'.format(key)) |
| 117 | + logging.debug('Input %i touched!', pin) |
| 118 | + logging.debug('Key: %s', key) |
108 | 119 | device.emit_click(key)
|
109 | 120 | time.sleep(EVENT_WAIT_SLEEP_SECONDS) # Small delay to keep from spamming output messages.
|
0 commit comments