Can somebody test my new Trackpad library?

Could somebody test this for me? Think it'll only work for synaptic trackpads.
Thanks!

http://www.arduino.cc/playground/Main/Trackpad

You need the PS2 library too.
http://www.arduino.cc/playground/ComponentLib/Ps2mouse

Hi,

It works here with my 135227-001 Synaptic trackpad!
This was great for me since I needed absolute position readings.

however, Im getting the x, y, z, w readings, but how do I read the buttons?

cheers!
gorgon

Hi gorgon,
that's not actually supported by the library, but I can show you how to add it.

You're going to need to edit the Trackpad.cpp and Trackpad.h files in the library. First add some bools to the packet_t definition in Trackpad.h for leftButtonDown and rightButtonDown.

Then take a look at figure 3-19 on page 42 of this document http://www.synaptics.com/sites/default/files/ACF126.pdf?q=decaf/utilities/ACF126.pdf

That's the format of the data that comes back from the trackpad. The right and left buttons are at bits 1 and 0 of the first byte. There are also up/down buttons if your trackpad has them.

Look at Trackpad.cpp, Trackpad::getNewPacket(). This is where the data is decoded.

To get the data out, a little bitwise arithmetic is required. I can't test this, since I don't have a trackpad to hand, but I think adding this at line 110 should work:

packet.leftButtonDown = p1 & 0x01;
packet.rightButtonDown = (p1 & 0x02) >> 1;

Let me know how you get on! If it works, it would be great for everyone if you posted a new version with the new features.

Joe

Thank you! Worked just like that, and I have never really gotten my fingers into C or C++ or whatever code that was before :smiley:

I put the modified library on the wiki (Arduino Playground - Trackpad) as I cant find a way to attach it here.

I have another question, please excuse me if its a bit of a noob question not specific to your lib. How can I make the code in Trackpad_print.pde only send out values when they change? There are probably standards for doing this so I only need where to look for answers maybe.

again, thanks for the nice lib!
g

Awesome, it's great that somebody is using this code- I never finished my project (that seems to be my problem, I never finish any projects).

To only output values when they change you need to keep a copy of the previous packet and compare these values. First write a function to compare two previous packets. You have to do this member-by-member in C I think.

bool packetsEqual(packet_t * p1, packet_t * p2) {
      return (p1->x == p2->x &&
            p1->y == p2->y &&
            p1->z == p2->z &&
            p1->w == p2->w
            );
}

You should add your new button variables to the above function.

Then, in loop(), you need to add storage for the old packet, then add the check for differences, then copy the current packet so that it is stored for comparison the next time around.

void loop()
{
      static packet_t oldPacket;
      packet_t * packet;
      packet = t.getNewPacket();
      
      if(!packetsEqual(&oldPacket, packet)) {
            DUMP(packet->x);
            DUMP(packet->y);
            DUMP(packet->z);
            DUMP(packet->w);

            Serial.print("\n");
#if ANSI_TERMINAL
            Serial.print(0x1B,BYTE);
            Serial.print("[H");
#endif
            Serial.print("\n");
            // copy the current packet
            oldPacket = *packet;
      }
}

There you go! I haven't run any of this code so there may be errors in it, but hopefully you can see the gist. If you're wondering, the static keyword means the variable is not destroyed when the loop() function exits, and the * and & characters are pointer dereference and address operators. If you're new to C and C++, you might need to do a little reading to understand what this means.

Joe

Thank you Joe!! Im heading off to the mountains to do some work without internet now so I'll tell you how its come out in a weeks time.

cheers!
g

Hi Joe, just to say that it worked fine! This saves a lot of cpu on my pc.

Next step for me is to find an other touchpad. I got one really cheap off ebay and its really overly sensitive. I can have my finger 0.5cm over it and it still gets a signal somehow.

Thanks! :slight_smile:

Hi,
now I'm trying to expand to using two touchpads, but I'm having a problem differentiating between the values of the two. I made a try in the code below but SuperCollider, which Im using to interpret the values, is sometimes mixing them up. By dumping "first" and "second" before the values from the respective touchpad I route the coming values in SuperCollider to control two different objects..

What would be ideal is to be able to send a DUMP with a different name than "packet->x", like "packet->x2" (or a name I write) for the second touchpad, then I can easily grab it in SuperCollider.

so, this is how my loop{} looks now:

void loop()
{
      static packet_t oldPacket;
      static packet_t oldPacket2;
      packet_t * packet;
      packet = t.getNewPacket();

      if(!packetsEqual(&oldPacket, packet)) {
            DUMP("first");
            DUMP(packet->x);
            DUMP(packet->y);
            //DUMP(packet->z);
            //DUMP(packet->w);
            DUMP(packet->leftButtonDown);
            DUMP(packet->rightButtonDown);

            Serial.print("\n");
#if ANSI_TERMINAL
            Serial.print(0x1B,BYTE);
            Serial.print("[H");
#endif
            Serial.print("\n");
            // copy the current packet
            oldPacket = *packet;
      }

      packet = t2.getNewPacket();

      if(!packetsEqual(&oldPacket2, packet)) {
                DUMP("second");
            DUMP(packet->x);
            DUMP(packet->y);
            //DUMP(packet->z);
            //DUMP(packet->w);
            DUMP(packet->leftButtonDown);
            DUMP(packet->rightButtonDown);

            Serial.print("\n");
#if ANSI_TERMINAL
            Serial.print(0x1B,BYTE);
            Serial.print("[H");
#endif
            Serial.print("\n");
            // copy the current packet
            oldPacket2 = *packet;
      }
}

cheers!
g