Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // HEADER CONFIG FILE
- $interface = "rfcomm0"; // Your serial interface, witout /dev/
- exec("sudo chmod 777 /dev/".$interface);
- if (!file_exists('/dev/'.$interface)) die($interface.' not found');
- elseif (isset($_GET['send'])) {
- exec('sudo printf \'\\x'.$_GET['send'].'\' > /dev/'.$interface);
- }
- else {
- ?>
- <!DOCTYPE html>
- <html><head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <meta charset="UTF-8">
- <title>Voiture</title>
- <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/animatecss/0.1/animate.min.css" />
- <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
- <style>
- * {
- padding: 0;
- margin: 0;
- }
- body {
- background-color: #eee;
- padding-top: 80px;
- font-family: "Arial";
- width: 500px;
- margin: auto;
- }
- </style>
- </head>
- <body>
- <div id="header" class="animated bounceInDown">
- <h1>BeWii Controller</h1>
- </div>
- <div id="content">
- <p>Car ready !</p>
- <p>Z/Q/S/D control</p>
- <p><b id="nb">0</b> events</p>
- </div>
- <script>
- function data(cmd) {
- $.get("?send="+cmd);
- $("#nb").html(parseInt($("#nb").html())+1);
- }
- function up(stop) {
- if (stop) data('00');
- else data('01')
- }
- function down(stop) {
- if (stop) data('02');
- else data('03')
- }
- function left(stop) {
- if (stop) data('04');
- else data('05')
- }
- function right(stop) {
- if (stop) data('06');
- else data('07')
- }
- $(document).keydown(function(event) {
- var key=event.which;
- if (key==90) upevent = setInterval(up(),2500);
- if (key==83) downevent = setInterval(down(),2500);
- if (key==81) leftevent = setInterval(left(),2500);
- if (key==68) rightevent = setInterval(right(),2500);
- });
- $(document).keyup(function(event) {
- var key=event.which;
- if (key==90) {
- clearInterval(upevent);
- up(1);
- }
- if (key==83) {
- clearInterval(downevent);
- down(1);
- }
- if (key==81) {
- clearInterval(leftevent);
- left(1);
- }
- if (key==68) {
- clearInterval(rightevent);
- right(1);
- }
- });
- </script>
- </body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement