{% extends "layout.html" %}
{% block body %}
<script type=text/javascript src="{{url_for('static', filename='jquery.min.js') }}"> </script>
<script type=text/javascript>
	
	function update() {
  		update_status();
    	window.setTimeout(update, 100000000);
	}
	
	$("document").ready(function(data) {
		update();
	});
	
	function move_right() {
		$.post("/right/20", function(data) {
  			update_status();
		});
	}
	
	function move_left() {
		$.post("/left/20", function(data) {
  			update_status();
		});
	}
	
	function move_down() {
		$.post("/down/20", function(data) {
  			update_status();
		});
	}
	
	function move_up() {
		$.post("{{url_for('move_up', amount="20")}}", function(data) {
			update_status();
		});
	}
	
	function fire() {
		$.post("/fire", function(data) {
			
		});
	}
	
	function stop_fire() {
		$.post("/stop_fire", function(data) {
			
		});
	}
	
	function update_status() {
		$.get("/status", function(data) {
				$('#status').html(data);
  			});
	}
	
</script>
  	<div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;">
            <h2>Hello in cannon controller, adjust angles!</h2>
            <p>Angles can be in range 0:255</p>
            <a  onclick="move_up()">Up</a>
            <a onclick="move_down()">Down</a>
            <a onclick="move_left()">Left</a>
            <a onclick="move_right()">Right</a>
            <p><a onclick="fire()">Fire!</a> <a onclick="stop_fire()">Stop</a></p>
            
            <h2>Status: </h2> <p id="status">{{data}}</p></div>
    </body>
    
{% endblock %}