triviOS/ui/main/templates/home.html

221 lines
11 KiB
HTML
Raw Normal View History

2023-09-11 08:07:53 +02:00
{% extends "base.html" %}
2023-09-11 09:59:25 +02:00
{% block title %} Home Manager {% endblock title%}
2023-09-11 08:07:53 +02:00
{% block content %}
2023-09-12 23:51:16 +02:00
<style>
img {
max-width: 100%;
object-fit: cover;
}
</style>
2023-09-13 18:38:24 +02:00
<script>
2023-09-13 23:41:34 +02:00
function place_blank(x, y, w, h) {
var canvas = document.getElementById("miCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#ffffff"; // Color blanco
ctx.fillRect(x, y, w, h);
}
function toggle_leds(led, x, y, w, h) {
var image = new Image();
2023-09-13 18:38:24 +02:00
$.get("/led/"+ led +"/", function (data) {
console.log(data);
if (led < 6 && led > 0) {
2023-09-13 22:44:31 +02:00
if (data == "off"){
$("#but"+led).text("Turn off "+led)
2023-09-13 23:41:34 +02:00
place_blank(x, y, w, h);
image.src = "https://www.freepngimg.com/thumb/light/78155-icons-light-idea-computer-lighting-incandescent-bulb.png";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, x, y, w, h); // (imagen, x, y)
};
} else {
$("#but"+led).text("Turn on "+led)
place_blank(x, y, w, h);
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, x, y, w, h); // (imagen, x, y)
};
2023-09-13 22:44:31 +02:00
}
2023-09-13 18:38:24 +02:00
}
});
}
function take_photo() {
$.get("/photo/", function (data) {
2023-09-13 23:41:34 +02:00
$("#photo").attr("src", "static/photo.jpg?rand="+Math.random());
2023-09-13 18:38:24 +02:00
});
}
2023-09-13 22:44:31 +02:00
function button_painter(pin, x, y, w, h) {
var canvas = document.getElementById("miCanvas");
var ctx = canvas.getContext("2d");
$.get("/button/"+pin, function (data) {
if (data == 1) {
ctx.strokeStyle = "#FFFFFF"; // Color blanco
console.log("Abriendo puerta " + pin)
} else {
ctx.strokeStyle = "#FF0000"; // Color negro
console.log("Cerrando puerta " + pin)
}
ctx.strokeRect(x, y, w, h); // Puerta
});
}
// Establecer la cantidad de segundos (en milisegundos) entre cada ejecución
var segundos = 2; // Cambia a la cantidad de segundos deseada
// Llamar a la función cada X segundos
setInterval(button_painter, segundos * 1000, 7, 300, 100, 1, 75);
setInterval(button_painter, segundos * 1000, 8, 350, 4, 100, 1);
setInterval(button_painter, segundos * 1000, 9, 350, 596, 100, 1);
setInterval(button_painter, segundos * 1000, 10, 500, 400, 1, 75);
2023-09-13 18:38:24 +02:00
</script>
2023-09-12 23:51:16 +02:00
2023-09-11 09:59:25 +02:00
{% if user.is_authenticated %}
2023-09-13 18:38:24 +02:00
<div class="jumbotron justify-content-center align-items-center">
2023-09-13 23:41:34 +02:00
<button id="but6" class="btn btn-primary btn-lg" onclick="toggle_leds(6, 0, 0, 0, 0);">Turn on all</button>
<button id="but0" class="btn btn-primary btn-lg" onclick="toggle_leds(0, 0, 0, 0, 0);">Turn off all</button>
<button id="but1" class="btn btn-primary btn-lg" onclick="toggle_leds(1, 20, 80, 100, 100);">Turn on 1</button>
<button id="but2" class="btn btn-primary btn-lg" onclick="toggle_leds(2, 50, 400, 100, 100);">Turn on 2</button>
<button id="but3" class="btn btn-primary btn-lg" onclick="toggle_leds(3, 350, 50, 100, 100);">Turn on 3</button>
<button id="but4" class="btn btn-primary btn-lg" onclick="toggle_leds(4, 500, 400, 100, 100);">Turn on 4</button>
<button id="but5" class="btn btn-primary btn-lg" onclick="toggle_leds(5, 350, 400, 100, 100);">Turn on 5</button>
2023-09-13 18:38:24 +02:00
</div>
<div class="jumbotron" width="800" height="600">
<canvas id="miCanvas" class="mx-auto" width="800" height="600"></canvas>
<!-- {% load static %}
<img src="{% static '1.jpg' %}" alt="My image"> -->
2023-09-12 23:51:16 +02:00
</div>
2023-09-13 18:38:24 +02:00
2023-09-12 23:51:16 +02:00
<div class="jumbotron">
2023-09-13 18:38:24 +02:00
<button class="btn btn-primary btn-lg btn-block" onclick="take_photo();">Take photo</button>
<p></p>
2023-09-13 21:01:49 +02:00
<img id="photo" src="{% static 'photo.jpg' %}">
2023-09-11 09:59:25 +02:00
</div>
{% else %}
2023-09-12 23:51:16 +02:00
<div class="jumbotron">
<p class="lead">You are not logged in</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="{% url 'login' %}" role="button">Log In</a>
</p>
</div>
2023-09-11 09:59:25 +02:00
{% endif %}
2023-09-12 23:51:16 +02:00
2023-09-13 18:38:24 +02:00
<script>
// Obtener el elemento canvas y su contexto
var canvas = document.getElementById("miCanvas");
var ctx = canvas.getContext("2d");
// Dibujar la casa (un rectángulo)
ctx.fillStyle = "#ffffff"; // Color amarillo
ctx.fillRect(0, 0, 800, 600); // (x, y, ancho, alto)
// // Dibujar las habitaciones (rectángulos dentro de la casa)
// ctx.fillStyle = "#ffffff"; // Color blanco
// ctx.fillRect(0, 0, 300, 300); // Cuarto 1
// ctx.fillRect(500, 300, 300, 300); // Cuarto 2
// // ctx.fillRect(70, 190, 260, 110); // Sala y cocina
// Dibujar las divisiones de las habitaciones
ctx.strokeStyle = "#000000"; // Color negro
ctx.lineWidth = 10
ctx.strokeRect(0, 0, 300, 300); // Cuarto 1
ctx.strokeRect(500, 300, 300, 300); // Cuarto 2
ctx.strokeRect(5, 5, 790, 590); // Casa
// ctx.strokeRect(70, 190, 260, 110); // Sala y cocina
// Etiquetas de las habitaciones
ctx.fillStyle = "#000000"; // Color negro
ctx.font = "30px Arial";
ctx.fillText("Cuarto 1", 100, 150);
ctx.fillText("Cuarto 2", 600, 450);
ctx.fillText("Sala", 200, 450);
ctx.fillText("Cocina", 600, 150);
2023-09-13 22:44:31 +02:00
ctx.strokeStyle = "#FF0000"; // Color negro
ctx.strokeRect(300, 100, 1, 75); // Puerta 1
ctx.strokeRect(350, 4, 100, 1); // Puerta trasera
ctx.strokeRect(350, 596, 100, 1); // Puerta tdelanteearasera
ctx.strokeRect(500, 400, 1, 75); // Puerta 2
2023-09-13 18:38:24 +02:00
2023-09-13 23:41:34 +02:00
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 20, 80, 100, 100); // (imagen, x, y)
};
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 500, 400, 100, 100); // (imagen, x, y)
};
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 50, 400, 100, 100); // (imagen, x, y)
};
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 50, 400, 100, 100); // (imagen, x, y)
};
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 350, 400, 100, 100); // (imagen, x, y)
};
var image = new Image();
image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";image.src = "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.pngmart.com%2Ffiles%2F7%2FLight-Bulb-PNG-Picture.png&f=1&nofb=1&ipt=afac257c7b6ce4e6c1fda1b32c1775c687841d1c138e1257f3f821cbff14c5e0&ipo=images";
// Esperar a que la imagen se cargue antes de dibujarla
image.onload = function () {
ctx.drawImage(image, 350, 50, 100, 100); // (imagen, x, y)
};
2023-09-13 18:38:24 +02:00
</script>
2023-09-12 23:51:16 +02:00
2023-09-11 08:07:53 +02:00
{% endblock content %}