5

I'd like to build a RaspberryPi-based device that can communicate with my Linux laptop over USB (don't think it matters, but I'll be using a custom made USB dongle that has an FTDI chip on it, and my laptop will have the FTDI drivers installed on it).

I'd like to rig my device with a simple control stick and a simple keyboard, and what I'd like to do is control my laptop's mouse and keyboard through this device. So:

  • Mouse Example:
    • I move the controller connected to the RPi
    • RPi converts this into some kind of command/input event
    • RPi sends this command/input event to the USB/FTDI dongle plugged into my laptop
    • USB/FTDI dongle sends command/input to FTDI device drivers
    • Somehow (???) the mouse (correctly) moves on my laptops screen
  • Keyboard Example
    • I type a key on the keyboard connected to the RPi
    • RPi converts this into some kind of command/input event
    • RPi sends this command/input event to the USB/FTDI dongle plugged into my laptop
    • USB/FTDI dongle sends command/input to FTDI device drivers
    • Somehow (???) the OS receives this command/input and handles it appropriately; for example if an app is open on the screen and a particular textfield has focus, the key will show up inside of it, etc.

I can handle everything up to the FTDI drivers receiving the command/input, but where I'm lost is how I can get those drivers to "talk" to whatever part of Linux that is responsible for moving the mouse or handling keystrokes. Any ideas?


I assume I need to write some native C code that will:

  1. Read from the serial port (where commands/inputs from the RPi will be sent)
  2. Translate the data on that port into a structured command (MOVE_MOUSE_10_PIXELS_LEFT, KEYSTROKE_A, KEYSTROKE_H, etc.)
  3. Somehow communicate to the Linux OS and tell it to handle such a command. In the case of a MOVE_MOUSE_* command, this means telling Linux to actually move the mouse coordinates on the screen. In the case of a KEY_* command, this means telling Linux to act as if a user had typed that key right there on the laptop's keyboard.

I'm simply unsure of how to accomplish Step #3 above.

smeeb
  • 4,820
  • 10
  • 30
  • 49

1 Answers1

1

I have such a setup with Altera DE2 FPGA with C and assembly code writing to uart0 and I use minicom in Linux Ubuntu on another computer to read the data from the FPGA. You have to figure out how interrupts work with you system and how serial communication is done. I did it in C and assembly, but you can check how it is donoe in python

Niklas Rosencrantz
  • 8,008
  • 17
  • 56
  • 95
  • 1
    Thanks @Programmer 400 (+1), a few followup questions if you dont' mind: **(1)** I assume `uart0` is a serial port on your Linux machine, and *not* the Altera FPGA? **(2)** What things does your assembly code do? What is it responsible for? **(3)** What things does your C code do, and what is it responsible for? **Again**, I'm not too concerned about pumping my inputs into the laptop's serial port (I can handle this no problem), but where I'm hung up on is communicating with the Linux OS and telling it to move the mouse or handle a keystroke, etc. Thanks again! – smeeb Apr 29 '16 at 09:45
  • 1
    And *much* more importantly @Programmer 400, **(4)** how does your code (C and/or assembler) actually tell Linux what to do?!? What Linux libraries are you working with to move the mouse and handle keystrokes? – smeeb Apr 29 '16 at 09:56
  • @smeeb Interrupts can do anything and everything. If you study interrupts and have an interrupt service routine you'll also learn how to make a context switch. You can read about this in the book "[Operating Systems](http://www.amazon.com/Modern-Operating-Systems-Andrew-Tanenbaum/dp/013359162X)" by Andrew Tanenbaum. – Niklas Rosencrantz Apr 29 '16 at 10:01
  • @smeeb When a keystroke is pressed or the mouse is moved, your code can listen for such a hardware interrupt. This is the most effective method to handle keystrokes and mouse. – Niklas Rosencrantz Apr 29 '16 at 10:03