teaching machines

CS 352 Lecture 30 – Mouse

November 18, 2016 by . Filed under cs352, fall 2016, lectures.

Dear students,

Today we’re going to do something a little different. I don’t think me lecturing is the best way for you to learn, but I don’t think there’s enough time in a semester to do much better. I am always looking for ways to step back and let you more actively participate. Today, we will experiment with one such way.

Your task is to reverse engineer a standard mouse protocol. I will provide this little background information:

One of the tenets of the “UNIX way” is to standardize all interactions with input and output devices by treating them as files. For example, when you plug in an input peripheral, it appears in the /dev/input directory. The contents of this directory are called device files.

Your job as a class is to figure out what’s happening with the mouse from within a C program.

See you next class!


P.S. It’s Haiku Friday!

He was too touchy
And he pushed all my buttons!
Things just didn’t click

P.P.S. Here’s the code we wrote together…


#include <stdio.h>
#include <stdint.h>

int main(int argc, char** argv) {
  FILE* mouseFile = fopen("/dev/input/mouse0", "r+");
  while (1) {
    int8_t c = fgetc(mouseFile);
    printf ("%d\n", c);