annotate service/shuttlepro/shuttlepro.py @ 331:a94f2a522d41

build and import updates for rdfdb, etc Ignore-this: 233cb2b31f03be51695f0fff40eecca7
author drewp@bigasterisk.com
date Mon, 19 Feb 2018 04:21:28 -0800
parents 57ae7dc0f417
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
1 #!/usr/bin/env python
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
2 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
3 # Copyright 2005 Free Software Foundation, Inc.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
4 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
5 # This file is part of GNU Radio
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
6 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
7 # GNU Radio is free software; you can redistribute it and/or modify
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
8 # it under the terms of the GNU General Public License as published by
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
9 # the Free Software Foundation; either version 3, or (at your option)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
10 # any later version.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
11 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
12 # GNU Radio is distributed in the hope that it will be useful,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
15 # GNU General Public License for more details.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
16 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
18 # along with GNU Radio; see the file COPYING. If not, write to
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
19 # the Free Software Foundation, Inc., 51 Franklin Street,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
20 # Boston, MA 02110-1301, USA.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
21 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
22
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
23 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
24 Handler for Griffin PowerMate, Contour ShuttlePro & ShuttleXpress USB knobs
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
25
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
26 modified by drewp@bigasterisk.com
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
27 """
126
a8e19321d63f rework shuttlepro's output statements
drewp@bigasterisk.com
parents: 125
diff changeset
28 import os, time, logging
43
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
29 import sys
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
30 import struct
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
31 import exceptions
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
32 import threading
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
33
126
a8e19321d63f rework shuttlepro's output statements
drewp@bigasterisk.com
parents: 125
diff changeset
34 logging.basicConfig(level=logging.INFO)
a8e19321d63f rework shuttlepro's output statements
drewp@bigasterisk.com
parents: 125
diff changeset
35 log = logging.getLogger()
43
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
36
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
37 def hexint(mask):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
38 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
39 Convert unsigned masks into signed ints.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
40
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
41 This allows us to use hex constants like 0xf0f0f0f2 when talking to
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
42 our hardware and not get screwed by them getting treated as python
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
43 longs.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
44 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
45 if mask >= 2**31:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
46 return int(mask-2**32)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
47 return mask
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
48 imported_ok = True
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
49
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
50 try:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
51 import select
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
52 import fcntl
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
53 except ImportError:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
54 imported_ok = False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
55
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
56
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
57 # First a little bit of background:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
58 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
59 # The Griffin PowerMate has
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
60 # * a single knob which rotates
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
61 # * a single button (pressing the knob)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
62 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
63 # The Contour ShuttleXpress (aka SpaceShuttle) has
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
64 # * "Jog Wheel" -- the knob (rotary encoder) on the inside
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
65 # * "Shuttle Ring" -- the spring loaded rubber covered ring
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
66 # * 5 buttons
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
67 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
68 # The Contour ShuttlePro has
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
69 # * "Jog Wheel" -- the knob (rotary encoder) on the inside
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
70 # * "Shuttle Ring" -- the spring loaded rubber covered ring
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
71 # * 13 buttons
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
72 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
73 # The Contour ShuttlePro V2 has
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
74 # *"Jog Wheel" -- the knob (rotary encoder) on the inside
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
75 # * "Shuttle Ring" -- the spring loaded rubber covered ring
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
76 # * 15 buttons
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
77
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
78 # We remap all the buttons on the devices so that they start at zero.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
79
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
80 # For the ShuttleXpress the buttons are 0 to 4 (left to right)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
81
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
82 # For the ShuttlePro, we number the buttons immediately above
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
83 # the ring 0 to 4 (left to right) so that they match our numbering
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
84 # on the ShuttleXpress. The top row is 5, 6, 7, 8. The first row below
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
85 # the ring is 9, 10, and the bottom row is 11, 12.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
86
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
87 # For the ShuttlePro V2, buttons 13 & 14 are to the
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
88 # left and right of the wheel respectively.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
89
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
90 # We generate 3 kinds of events:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
91 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
92 # button press/release (button_number, press/release)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
93 # knob rotation (relative_clicks) # typically -1, +1
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
94 # shuttle position (absolute_position) # -7,-6,...,0,...,6,7
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
95
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
96 # ----------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
97 # Our ID's for the devices:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
98 # Not to be confused with anything related to magic hardware numbers.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
99
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
100 ID_POWERMATE = 'powermate'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
101 ID_SHUTTLE_XPRESS = 'shuttle xpress'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
102 ID_SHUTTLE_PRO = 'shuttle pro'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
103 ID_SHUTTLE_PRO_V2 = 'shuttle pro v2'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
104
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
105 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
106 # format of messages that we read from /dev/input/event*
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
107 # See /usr/include/linux/input.h for more info
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
108 #
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
109 #struct input_event {
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
110 # struct timeval time; = {long seconds, long microseconds}
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
111 # unsigned short type;
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
112 # unsigned short code;
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
113 # unsigned int value;
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
114 #};
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
115
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
116 input_event_struct = "@llHHi"
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
117 input_event_size = struct.calcsize(input_event_struct)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
118
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
119 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
120 # input_event types
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
121 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
122
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
123 IET_SYN = 0x00 # aka RESET
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
124 IET_KEY = 0x01 # key or button press/release
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
125 IET_REL = 0x02 # relative movement (knob rotation)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
126 IET_ABS = 0x03 # absolute position (graphics pad, etc)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
127 IET_MSC = 0x04
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
128 IET_LED = 0x11
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
129 IET_SND = 0x12
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
130 IET_REP = 0x14
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
131 IET_FF = 0x15
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
132 IET_PWR = 0x16
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
133 IET_FF_STATUS = 0x17
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
134 IET_MAX = 0x1f
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
135
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
136 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
137 # input_event codes (there are a zillion of them, we only define a few)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
138 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
139
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
140 # these are valid for IET_KEY
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
141
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
142 IEC_BTN_0 = 0x100
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
143 IEC_BTN_1 = 0x101
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
144 IEC_BTN_2 = 0x102
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
145 IEC_BTN_3 = 0x103
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
146 IEC_BTN_4 = 0x104
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
147 IEC_BTN_5 = 0x105
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
148 IEC_BTN_6 = 0x106
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
149 IEC_BTN_7 = 0x107
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
150 IEC_BTN_8 = 0x108
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
151 IEC_BTN_9 = 0x109
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
152 IEC_BTN_10 = 0x10a
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
153 IEC_BTN_11 = 0x10b
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
154 IEC_BTN_12 = 0x10c
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
155 IEC_BTN_13 = 0x10d
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
156 IEC_BTN_14 = 0x10e
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
157 IEC_BTN_15 = 0x10f
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
158
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
159 # these are valid for IET_REL (Relative axes)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
160
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
161 IEC_REL_X = 0x00
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
162 IEC_REL_Y = 0x01
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
163 IEC_REL_Z = 0x02
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
164 IEC_REL_HWHEEL = 0x06
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
165 IEC_REL_DIAL = 0x07 # rotating the knob
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
166 IEC_REL_WHEEL = 0x08 # moving the shuttle ring
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
167 IEC_REL_MISC = 0x09
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
168 IEC_REL_MAX = 0x0f
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
169
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
170 # ------------------------------------------------------------------------
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
171
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
172 class powermate(object):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
173 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
174 Interface to Griffin PowerMate and Contour Shuttles
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
175 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
176 def __init__(self, filename=None, on_event=lambda ev: None):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
177 self.on_event = on_event
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
178 self.handle = -1
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
179 if not imported_ok:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
180 raise exceptions.RuntimeError, 'powermate not supported on this platform'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
181
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
182 if filename:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
183 if not self._open_device(filename):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
184 raise exceptions.RuntimeError, 'Unable to find powermate'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
185 else:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
186 ok = False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
187 for d in range(0, 16):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
188 if self._open_device("/dev/input/event%d" % d):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
189 ok = True
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
190 break
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
191 if not ok:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
192 raise exceptions.RuntimeError, 'Unable to find powermate'
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
193
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
194 def __del__(self):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
195 self.keep_running = False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
196 if self.handle >= 0:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
197 os.close(self.handle)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
198 self.handle = -1
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
199
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
200 def _open_device(self, filename):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
201 try:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
202 self.handle = os.open(filename, os.O_RDWR)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
203 if self.handle < 0:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
204 print "can't open file"
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
205 return False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
206
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
207 # read event device name
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
208 name = fcntl.ioctl(self.handle, hexint(0x80ff4506), chr(0) * 256)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
209 name = name.replace(chr(0), '')
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
210 print "%s name is %s" % (filename, name)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
211 # do we see anything we recognize?
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
212 if name == 'Griffin PowerMate' or name == 'Griffin SoundKnob':
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
213 self.id = ID_POWERMATE
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
214 self.mapper = _powermate_remapper()
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
215 elif name == 'CAVS SpaceShuttle A/V' or name == 'Contour Design ShuttleXpress':
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
216 self.id = ID_SHUTTLE_XPRESS
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
217 self.mapper = _contour_remapper()
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
218 elif name == 'Contour Design ShuttlePRO':
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
219 self.id = ID_SHUTTLE_PRO
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
220 self.mapper = _contour_remapper()
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
221 elif name == 'Contour Design ShuttlePRO v2':
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
222 self.id = ID_SHUTTLE_PRO_V2
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
223 self.mapper = _contour_remapper()
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
224 else:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
225 os.close(self.handle)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
226 self.handle = -1
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
227 return False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
228
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
229 # get exclusive control of the device, using ioctl EVIOCGRAB
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
230 # there may be an issue with this on non x86 platforms and if
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
231 # the _IOW,_IOC,... macros in <asm/ioctl.h> are changed
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
232 fcntl.ioctl(self.handle,hexint(0x40044590), 1)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
233 return True
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
234 except exceptions.OSError:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
235 return False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
236
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
237
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
238 def set_event_receiver(self, obj):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
239 self.event_receiver = obj
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
240
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
241
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
242 def set_led_state(self, static_brightness, pulse_speed=0,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
243 pulse_table=0, pulse_on_sleep=0, pulse_on_wake=0):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
244 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
245 What do these magic values mean...
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
246 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
247 if self.id != ID_POWERMATE:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
248 return False
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
249
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
250 static_brightness &= 0xff;
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
251 if pulse_speed < 0:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
252 pulse_speed = 0
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
253 if pulse_speed > 510:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
254 pulse_speed = 510
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
255 if pulse_table < 0:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
256 pulse_table = 0
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
257 if pulse_table > 2:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
258 pulse_table = 2
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
259 pulse_on_sleep = not not pulse_on_sleep # not not = convert to 0/1
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
260 pulse_on_wake = not not pulse_on_wake
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
261 magic = (static_brightness
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
262 | (pulse_speed << 8)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
263 | (pulse_table << 17)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
264 | (pulse_on_sleep << 19)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
265 | (pulse_on_wake << 20))
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
266 data = struct.pack(input_event_struct, 0, 0, 0x04, 0x01, magic)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
267 os.write(self.handle, data)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
268 return True
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
269
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
270 def read_next(self):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
271 s = os.read (self.handle, input_event_size)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
272 if not s:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
273 return
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
274
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
275 raw_input_event = struct.unpack(input_event_struct,s)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
276 sec, usec, type, code, val = self.mapper(raw_input_event)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
277
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
278 if type == IET_SYN: # ignore
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
279 pass
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
280 elif type == IET_MSC: # ignore (seems to be PowerMate reporting led brightness)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
281 pass
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
282 elif type == IET_REL and code == IEC_REL_DIAL:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
283 self.on_event({"dial":val})
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
284 elif type == IET_REL and code == IEC_REL_WHEEL:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
285 self.on_event({"shuttle":val})
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
286 elif type == IET_KEY:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
287 self.on_event({"key":{"button":code - IEC_BTN_0, "press":val}})
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
288 else:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
289 print "powermate: unrecognized event: type = 0x%x code = 0x%x val = %d" % (type, code, val)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
290
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
291
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
292 class _powermate_remapper(object):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
293 def __init__(self):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
294 pass
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
295 def __call__(self, event):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
296 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
297 Notice how nice and simple this is...
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
298 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
299 return event
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
300
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
301 class _contour_remapper(object):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
302 def __init__(self):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
303 self.prev = None
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
304 def __call__(self, event):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
305 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
306 ...and how screwed up this is
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
307 """
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
308 sec, usec, type, code, val = event
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
309 if type == IET_REL and code == IEC_REL_WHEEL:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
310 # === Shuttle ring ===
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
311 # First off, this really ought to be IET_ABS, not IET_REL!
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
312 # They never generate a zero value so you can't
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
313 # tell when the shuttle ring is back in the center.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
314 # We kludge around this by calling both -1 and 1 zero.
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
315 if val == -1 or val == 1:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
316 return (sec, usec, type, code, 0)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
317 return event
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
318
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
319 if type == IET_REL and code == IEC_REL_DIAL:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
320 # === Jog knob (rotary encoder) ===
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
321 # Dim wits got it wrong again! This one should return a
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
322 # a relative value, e.g., -1, +1. Instead they return
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
323 # a total that runs modulo 256 (almost!). For some
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
324 # reason they count like this 253, 254, 255, 1, 2, 3
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
325
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
326 if self.prev is None: # first time call
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
327 self.prev = val
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
328 return (sec, usec, IET_SYN, 0, 0) # will be ignored above
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
329
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
330 diff = val - self.prev
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
331 if diff == 0: # sometimes it just sends stuff...
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
332 return (sec, usec, IET_SYN, 0, 0) # will be ignored above
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
333
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
334 if abs(diff) > 100: # crossed into the twilight zone
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
335 if self.prev > val: # we've wrapped going forward
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
336 self.prev = val
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
337 return (sec, usec, type, code, +1)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
338 else: # we've wrapped going backward
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
339 self.prev = val
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
340 return (sec, usec, type, code, -1)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
341
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
342 self.prev = val
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
343 return (sec, usec, type, code, diff)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
344
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
345 if type == IET_KEY:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
346 # remap keys so that all 3 gadgets have buttons 0 to 4 in common
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
347 return (sec, usec, type,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
348 (IEC_BTN_5, IEC_BTN_6, IEC_BTN_7, IEC_BTN_8,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
349 IEC_BTN_0, IEC_BTN_1, IEC_BTN_2, IEC_BTN_3, IEC_BTN_4,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
350 IEC_BTN_9, IEC_BTN_10,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
351 IEC_BTN_11, IEC_BTN_12,
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
352 IEC_BTN_13, IEC_BTN_14)[code - IEC_BTN_0], val)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
353
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
354 return event
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
355
89
1c1fcb71e10a shuttlepro: some old changes
drewp@bigasterisk.com
parents: 43
diff changeset
356
43
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
357 if __name__ == '__main__':
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
358 def ev(what):
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
359 print 'ev', what
125
bcf20b7ede56 shuttlepro post your events to reasoning service
drewp@bigasterisk.com
parents: 89
diff changeset
360
43
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
361 p = powermate("/dev/input/by-id/usb-Contour_Design_ShuttlePRO-event-if00", ev)
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
362 while True:
6fbb05317eef adapt gnuradio shuttlepro code
drewp@bigasterisk.com
parents:
diff changeset
363 p.read_next()