Getting raw data from a USB mouse in Linux using Python

If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got me started. Once I beautify my multiple-mouse code I will be posting it here as well. Without further ado :

mouse = file('/dev/input/mouse0')
while True:
    status, dx, dy = tuple(ord(c) for c in mouse.read(3))

    def to_signed(n):
        return n - ((0x80 & n) << 1)

    dx = to_signed(dx)
    dy = to_signed(dy)
    print "%#02x %d %d" % (status, dx, dy)

I hope this just made your day!

Fork me on GitHub

Changing size of array in C programming language

It’s been a long time since I coded in C. I needed to change the size of an array within the program. At first I just simply tried;

int ab=10;
int array[ab];

And surprisingly it didn’t work. (I mean it works in C++ and C#)
Anyway I was thinking of ways on how to do this thought of using malloc() however I really didn’t know how hence I did some Google’ing around. And found this neat piece of code.

int *resize_array(int *a, size_t new_size)
{
  int *save;

  save = realloc(a, new_size);
  if (save == NULL) {
    fprintf(stderr, "Memory exhausted\n");
    exit(EXIT_FAILURE);
  }
  return save;
}

int *user_old_array; // the array
int new_array_size=10;
user_old_array = malloc(initial_array_size * sizeof *user_old_array); //resized array

Quite neat isn’t it. I thought I should probably write this somewhere so I won’t forget. Hence the post.

Enjoy!

Setting up a CVS server for the BlackBox project

Following the previous posts in this category you will notice that I was using Sourceforge.net as the code hosting. We had to change that because we really didn’t want to share every bit of code. ( A big sorry to open source developers. I am truly a sell out. ) So had to set up CVS server. Never done that before. Should probably add it to my CV. Anyways to business.

How to set up a CVS server using SSH :

Continue reading

Installing Ångström Linux on BeagleBoard

We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted BeagleBoard Beginners wiki just too much!!

You see we learned that we should NOT set any environment variables while using demo u-boot image which was downloaded from here. In fact what we did is we created our own Ångström image (from Ångström site) and simply installed that to our Linux partition of our SDHC card. And it worked beautifully. Though I must say first boot is a drag, very very slow.

Continue reading