joydump.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 1996-2001 Vojtech Pavlik
  3. */
  4. /*
  5. * This is just a very simple driver that can dump the data
  6. * out of the joystick port into the syslog ...
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * Should you need to contact me, the author, you can do so either by
  24. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  25. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  26. */
  27. #include <linux/module.h>
  28. #include <linux/gameport.h>
  29. #include <linux/kernel.h>
  30. #include <linux/delay.h>
  31. #include <linux/slab.h>
  32. #define DRIVER_DESC "Gameport data dumper module"
  33. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  34. MODULE_DESCRIPTION(DRIVER_DESC);
  35. MODULE_LICENSE("GPL");
  36. #define BUF_SIZE 256
  37. struct joydump {
  38. unsigned int time;
  39. unsigned char data;
  40. };
  41. static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
  42. {
  43. struct joydump *buf; /* all entries */
  44. struct joydump *dump, *prev; /* one entry each */
  45. int axes[4], buttons;
  46. int i, j, t, timeout;
  47. unsigned long flags;
  48. unsigned char u;
  49. printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
  50. printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
  51. printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
  52. if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
  53. printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
  54. if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
  55. printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
  56. printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
  57. return -ENODEV;
  58. }
  59. gameport_cooked_read(gameport, axes, &buttons);
  60. for (i = 0; i < 4; i++)
  61. printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
  62. printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
  63. printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
  64. }
  65. timeout = gameport_time(gameport, 10000); /* 10 ms */
  66. buf = kmalloc(BUF_SIZE * sizeof(struct joydump), GFP_KERNEL);
  67. if (!buf) {
  68. printk(KERN_INFO "joydump: no memory for testing\n");
  69. goto jd_end;
  70. }
  71. dump = buf;
  72. t = 0;
  73. i = 1;
  74. local_irq_save(flags);
  75. u = gameport_read(gameport);
  76. dump->data = u;
  77. dump->time = t;
  78. dump++;
  79. gameport_trigger(gameport);
  80. while (i < BUF_SIZE && t < timeout) {
  81. dump->data = gameport_read(gameport);
  82. if (dump->data ^ u) {
  83. u = dump->data;
  84. dump->time = t;
  85. i++;
  86. dump++;
  87. }
  88. t++;
  89. }
  90. local_irq_restore(flags);
  91. /*
  92. * Dump data.
  93. */
  94. t = i;
  95. dump = buf;
  96. prev = dump;
  97. printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
  98. printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
  99. for (j = 7; j >= 0; j--)
  100. printk("%d", (dump->data >> j) & 1);
  101. printk(" |\n");
  102. dump++;
  103. for (i = 1; i < t; i++, dump++, prev++) {
  104. printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
  105. i, dump->time - prev->time);
  106. for (j = 7; j >= 0; j--)
  107. printk("%d", (dump->data >> j) & 1);
  108. printk(" |\n");
  109. }
  110. kfree(buf);
  111. jd_end:
  112. printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
  113. return 0;
  114. }
  115. static void joydump_disconnect(struct gameport *gameport)
  116. {
  117. gameport_close(gameport);
  118. }
  119. static struct gameport_driver joydump_drv = {
  120. .driver = {
  121. .name = "joydump",
  122. },
  123. .description = DRIVER_DESC,
  124. .connect = joydump_connect,
  125. .disconnect = joydump_disconnect,
  126. };
  127. module_gameport_driver(joydump_drv);