Posted By

wearetherock on 09/11/09


Tagged

perl xml-rpc wiimote


Versions (?)

Send Wiimote Signal Through XML-RPC


 / Published in: Perl
 

  1. use Linux::Input::Wiimote;
  2.  
  3. require RPC::XML;
  4. require RPC::XML::Client;
  5.  
  6.  
  7. print "remote control ...\n";
  8.  
  9. my $cli = RPC::XML::Client->new("http://localhost:9191");
  10. my $wii = new Linux::Input::Wiimote;
  11.  
  12. ##############################
  13. sub get_device_id {
  14. my $dev = $wii->wiimote_discover();
  15. print $dev;
  16. if ($dev eq 0){
  17.  
  18. print "Not found device, exit now\n";
  19. #exit(0);
  20. }else{ print "Found dev $dev"; }
  21. return $dev;
  22. }
  23.  
  24. ##############################
  25. my $dev = 0;
  26. while ($dev eq 0){
  27. print "Press 1+2 ...\n";
  28. $dev = get_device_id();
  29. }
  30.  
  31. $wii->wiimote_connect("00:1$dev");
  32.  
  33. while (1){
  34. $wii->wiimote_update();
  35. my $keys = "RELEASE";
  36. if($wii->get_wiimote_keys_down && $wii->get_wiimote_keys_b){
  37. $keys = "B-DOWN";
  38. }elsif ($wii->get_wiimote_keys_up && $wii->get_wiimote_keys_b){
  39. $keys = "B-UP";
  40. }elsif ($wii->get_wiimote_keys_left && $wii->get_wiimote_keys_b){
  41. $keys = "B-LEFT";
  42. }elsif ($wii->get_wiimote_keys_right && $wii->get_wiimote_keys_b){
  43. $keys = "B-RIGHT";
  44. }elsif ($wii->get_wiimote_keys_a && $wii->get_wiimote_keys_b){
  45. $keys = "B-A";
  46. }elsif($wii->get_wiimote_keys_down()){
  47. $keys = "DOWN";
  48. }elsif ($wii->get_wiimote_keys_right()){
  49. $keys = "RIGHT";
  50. }elsif ($wii->get_wiimote_keys_up()){
  51. $keys = "UP";
  52. }elsif ($wii->get_wiimote_keys_left()){
  53. $keys = "LEFT";
  54. }elsif ($wii->get_wiimote_keys_a()){
  55. $keys = "A";
  56. }elsif ($wii->get_wiimote_keys_b()){
  57. $keys = "B";
  58. }elsif ($wii->get_wiimote_keys_1()){
  59. $keys = "1";
  60. }elsif ($wii->get_wiimote_keys_2()){
  61. $key = "2";
  62. }elsif ($wii->get_wiimote_keys_home()){
  63. $keys = "HOME";
  64. }elsif ($wii->get_wiimote_keys_minus()){
  65. $keys = "MINUS";
  66. }elsif ($wii->get_wiimote_keys_plus()){
  67. $keys = "PLUS";
  68. }else {
  69. $keys = "RELEASE";
  70. }
  71.  
  72. #print $keys;
  73. print "wearetherock ok $keys\n";
  74. $cli->send_request("updateState", $keys);
  75. }

Report this snippet  

You need to login to post a comment.