joydump.c 4.4 KB

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