usbmouse.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include "minilisp.h"
  3. #include "alloc.h"
  4. #include "stream.h"
  5. #include "compiler_new.h"
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. static int mouse_dx;
  9. static int mouse_dy;
  10. static int mouse_buttons;
  11. void uspi_mouse_handler(unsigned buttons, int dx, int dy)
  12. {
  13. //printf("[uspi-mouse] dx: %d dy: %d buttons: %d\r\n",dx,dy,buttons);
  14. mouse_dx += dx;
  15. mouse_dy += dy;
  16. mouse_buttons = buttons;
  17. }
  18. Cell* usbmouse_open(Cell* cpath) {
  19. if (!cpath || cpath->tag!=TAG_STR) {
  20. printf("[usbmouse] open error: non-string path given\r\n");
  21. return alloc_nil();
  22. }
  23. return alloc_int(1);
  24. }
  25. Cell* usbmouse_read(Cell* stream) {
  26. Cell* res = alloc_cons(alloc_cons(alloc_int(mouse_dx),alloc_int(mouse_dy)),alloc_int(mouse_buttons));
  27. mouse_dx = 0;
  28. mouse_dy = 0;
  29. return res;
  30. }
  31. Cell* usbmouse_write(Cell* arg) {
  32. // could be used to control LEDs
  33. return NULL;
  34. }
  35. Cell* usbmouse_mmap(Cell* arg) {
  36. return alloc_nil();
  37. }
  38. void mount_mouse() {
  39. fs_mount_builtin("/mouse", usbmouse_open, usbmouse_read, usbmouse_write, 0, usbmouse_mmap);
  40. }