Advertisement
lululombard

BeWii

Jun 2nd, 2014
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2. // HEADER CONFIG FILE
  3. $interface = "rfcomm0"; // Your serial interface, witout /dev/
  4. exec("sudo chmod 777 /dev/".$interface);
  5. if (!file_exists('/dev/'.$interface)) die($interface.' not found');
  6. elseif (isset($_GET['send'])) {
  7.     exec('sudo printf \'\\x'.$_GET['send'].'\' > /dev/'.$interface);
  8. }
  9. else {
  10. ?>
  11. <!DOCTYPE html>
  12. <html><head>
  13. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  14.     <meta charset="UTF-8">
  15.     <title>Voiture</title>
  16.     <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/animatecss/0.1/animate.min.css" />
  17.     <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
  18.     <style>
  19.     * {
  20.         padding: 0;
  21.         margin: 0;
  22.     }
  23.     body {
  24.         background-color: #eee;
  25.         padding-top: 80px;
  26.         font-family: "Arial";
  27.         width: 500px;
  28.         margin: auto;
  29.     }
  30.     </style>
  31. </head>
  32. <body>
  33.     <div id="header" class="animated bounceInDown">
  34.         <h1>BeWii Controller</h1>
  35.     </div>
  36.     <div id="content">
  37.     <p>Car ready !</p>
  38.     <p>Z/Q/S/D control</p>
  39.     <p><b id="nb">0</b> events</p>
  40.     </div>
  41. <script>
  42.     function data(cmd) {
  43.         $.get("?send="+cmd);
  44.         $("#nb").html(parseInt($("#nb").html())+1);
  45.     }
  46.     function up(stop) {
  47.         if (stop) data('00');
  48.         else data('01')
  49.     }
  50.     function down(stop) {
  51.         if (stop) data('02');
  52.         else data('03')
  53.     }
  54.     function left(stop) {
  55.         if (stop) data('04');
  56.         else data('05')
  57.     }
  58.     function right(stop) {
  59.         if (stop) data('06');
  60.         else data('07')
  61.     }
  62.     $(document).keydown(function(event) {
  63.         var key=event.which;
  64.         if (key==90) upevent = setInterval(up(),2500);
  65.         if (key==83) downevent = setInterval(down(),2500);
  66.         if (key==81) leftevent = setInterval(left(),2500);
  67.         if (key==68) rightevent = setInterval(right(),2500);
  68.     });
  69.     $(document).keyup(function(event) {
  70.         var key=event.which;
  71.         if (key==90) {
  72.             clearInterval(upevent);
  73.             up(1);
  74.         }
  75.         if (key==83) {
  76.             clearInterval(downevent);
  77.             down(1);
  78.         }
  79.         if (key==81) {
  80.             clearInterval(leftevent);
  81.             left(1);
  82.         }
  83.         if (key==68) {
  84.             clearInterval(rightevent);
  85.             right(1);
  86.         }
  87.     });
  88. </script>
  89. </body>
  90. </html>
  91. <?php
  92. }
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement