arduinowiflynodebot/client.app/Contents/Resources/app.nw/index.html

111 lines
3.5 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Client</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
background-color: rgb(237, 237, 237);
border-top: 1px solid rgb(105, 105, 105);
text-align: center;
}
.man {
text-align: left;
margin: 0 auto;
width: 520px;
}
</style>
</head>
<body>
<pre class="man">
____ _ _ _
Arduino / ___| (_) ___ _ __ | |_
Bot | | | | |/ _ \ '_ \| __|
| |___| | | __/ | | | |_
\____|_|_|\___|_| |_|\__|
By Ambrose Chua
Powered by NodeJS, node-webkit,
Arduino and WiFly.
Code under WTFPL.
</pre>
<script src="jquery-2.1.0.min.js"></script>
<script>
var keymap = require("./keymap.js");
var gui = require('nw.gui');
gui.Window.get().showDevTools();
var net = require("net");
var socket = new net.Socket();
socket.setEncoding("utf8");
var keymap;
var soc = socket.connect(44, "169.254.1.1", function () {
soc.on("data", function (data) {
console.log(data);
});
console.log("yay");
$(document).ready(function () {
// $.ajax({
// url: 'keymap.json',
// dataType: 'json',
// success: function (response) {
// keymap = response;
// console.log(keymap);
$(window).on("keydown", function (e) {
// TODO: Add speed control.
if (e.which == keymap.KEYCODES["w"]) {
soc.write("w");
}
else if (e.which == keymap.KEYCODES["s"]) {
soc.write("s");
}
else if (e.which == keymap.KEYCODES["a"]) {
soc.write("a");
}
else if (e.which == keymap.KEYCODES["d"]) {
soc.write("d");
}
else if (e.which == keymap.KEYCODES["q"]) {
soc.write("q");
}
else if (e.which == keymap.KEYCODES["e"]) {
soc.write("e");
}
});
$(window).on("keyup", function (e) {
if (e.which == keymap.KEYCODES["w"] || e.which == keymap.KEYCODES["s"] || e.which == keymap.KEYCODES["a"] || e.which == keymap.KEYCODES["d"] || e.which == keymap.KEYCODES["q"] || e.which == keymap.KEYCODES["e"]) {
soc.write("n");
}
// if (e.which == 71) {
// soc.write("n");
// }
// else if (e.which == 72) {
// soc.write("n");
// }
});
// }
// });
});
});
</script>
</body>
</html>