Attention!

Attention!

Note that this documents only the first revision of the touchpad. The second revision (October 2005 powerbooks) is supported in appletouch as well, while the third revision (Macbook Pro) isn't supported yet because the device reports actual HID events, but these are low resolution and not too useful.

The touchpad claims to be a HID device but doesn't really send HID events as far as I can tell, but rather its own transfers.

transferred data

The trackpad continually transfers an 81 byte block via a USB interrupt transfer.

button

The last byte of the transferred 81 bytes indicates the button status, it is 0x01 if the button is pressed, 0x00 otherwise.

touch

The other 80 bytes are split into two 40 byte sections, the latter always being zerofilled. The following discusses the first 40 byte block of the transfer.

Let me introduce the following mapping function (written in python notation):

```def map(bytenumber):
return bytenumber % 5, bytenumber/5
```

Then, in X direction, the touchpad has first the sensors with first component being even, in lexical order:

```(2,0),(2,1),(2,2),....,(2,7),(4,0),...(4,7)
```

Same in Y direction with the first components 1 and 3. I'll refer to them as X through X and Y through Y.

Those values with first component 0 seem to signify some other level that only covers the left part of the touchpad in X direction, but are less sensitive. I haven't used them.

Now, all these values seem to be potentials, but only their change is interesting.

So now consider the following function:

```def accu(current_vector, old_vector, accu_vector):
# current_vector is either X or Y
# old_vector is None if no old values are known,
# otherwise a set of old values
# we change accu_vector which must have length 16, all initialised to 0
if old_vector is None:
for i in range(16): old_vector[i] = current_vector[i]
return
for i in range(16):
tmp = old_vector[i] - current_vector[i]
if tmp > 127: tmp -= 256
if tmp < -127: tmp += 256
accu_vector[i] -= tmp
```

In the normal state, accu_vector will be 0, and only fluctuate slightly due to the touchpad characteristics. When you touch it though, these values increase depending on where the finger is in X and Y directions. That can be used to track the position of the finger. We used an approach that calculates the finger position by weighing:

```half_weight = sum(accu_vector)
pos = None
i = 0
acc = 0
if half_weight > threshold/2: # get rid of fluctuations
while acc + accu_vector[i] < half_weight:
acc += accu_vector[i]
i += 1
val = i + (half_weight - acc)/(0.0+accu_vector[i]) # weigh inside one of the 16 areas
# val contains None if no finger or the current position
```

This snippet calculates the finger position for one direction.

Now this this you can implement pretty much everything you need. I recommend threshold = 20, but we're thinking of a different way to detect the finger. Also, multiple fingers are reported correctly, if there are two fingers on the touchpad you don't know on which of the 4 positions they are (unless this data is sent and we haven't seen it yet).

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink

Unknown target name: "/driver".