1

I want to use an optical mouse with the Raspberry PI for indoor positioning for which I want to capture raw mouse data and calculate position from it. This is what I have right now (in Ruby)

File.open("/dev/input/by-id/usb-15d9_USB_OPTICAL_MOUSE-mouse") do |f|
  loop do
    p f.read(16)
  end
end

I can't make sense of the output. It would be of great help if any of you pointed me to a resource explaining how this file is supposed to be interpreted and/or how I can calculate position or displacement from it.

I cannot use xdotool or Xlib because the Raspberry PI won't be running any windowing system.

prajwaldp
  • 178
  • 1
  • 14

1 Answers1

0
DPI = 1000.0
MOUSE_FILE = ""

# Read mouse device file
File.open(MOUSE_FILE) do |f|
  loop do
    _button, dx, dy =  f.read(3).unpack('Ccc')

    x += dx
    y += dy

    puts "#{x * 2.5 / DPI}, #{y * 2.5 / DPI}"
  end
end
prajwaldp
  • 178
  • 1
  • 14