diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index 5c5bb8f..cb58bc2 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -22,14 +22,14 @@ function toggle_leds(led, x, y, w, h) { - var image = new Image(); - $.get("/led/"+ led +"/", function (data) { console.log(data); if (led < 6 && led > 0) { if (data == "off"){ $("#but"+led).text("Turn off "+led) + var image = new Image(); + 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 @@ -40,6 +40,8 @@ } else { $("#but"+led).text("Turn on "+led) + var image = new Image(); + 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 @@ -47,6 +49,114 @@ ctx.drawImage(image, x, y, w, h); // (imagen, x, y) }; } + } else if (led == 6){ + + place_blank(20, 80, 100, 100); + place_blank(500, 400, 100, 100); + place_blank(50, 400, 100, 100); + place_blank(350, 400, 100, 100); + place_blank(350, 50, 100, 100); + + var image = new Image(); + + var src = "https://www.freepngimg.com/thumb/light/78155-icons-light-idea-computer-lighting-incandescent-bulb.png"; + + image.src = src; + + // 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 = src; + + // 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 = src; + + // 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 = src; + + // 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 = src; + + // Esperar a que la imagen se cargue antes de dibujarla + image.onload = function () { + ctx.drawImage(image, 350, 50, 100, 100); // (imagen, x, y) + }; + + } else if (led == 0){ + place_blank(20, 80, 100, 100); + place_blank(500, 400, 100, 100); + place_blank(50, 400, 100, 100); + place_blank(350, 400, 100, 100); + place_blank(350, 50, 100, 100); + + var image = new Image(); + + var 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"; + + image.src = src; + + // 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 = src; + + // 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 = src; + + // 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 = src; + + // 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 = src; + + // Esperar a que la imagen se cargue antes de dibujarla + image.onload = function () { + ctx.drawImage(image, 350, 50, 100, 100); // (imagen, x, y) + }; } }); } @@ -143,7 +253,7 @@ // Etiquetas de las habitaciones ctx.fillStyle = "#000000"; // Color negro ctx.font = "30px Arial"; - ctx.fillText("Cuarto 1", 100, 150); + ctx.fillText("Cuarto 1", 150, 150); ctx.fillText("Cuarto 2", 600, 450); ctx.fillText("Sala", 200, 450); ctx.fillText("Cocina", 600, 150); diff --git a/ui/main/views.py b/ui/main/views.py index 50f94fa..1166104 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -2,8 +2,8 @@ from django.shortcuts import render from django.http import HttpResponse import ctypes -pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so") -print(f"INIT: {pin_control.init_gpio()}") +# pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so") +# print(f"INIT: {pin_control.init_gpio()}") leds_state = { 1: False, @@ -30,7 +30,7 @@ def home(request): def take_photo(request): - pin_control.capture_image(b'/run/nginx/static/photo.jpg') + # pin_control.capture_image(b'/run/nginx/static/photo.jpg') return HttpResponse("Ok") @@ -44,24 +44,25 @@ def led(request, led): return HttpResponse("Ok") def turn_off_all(): - for pin in leds_gpio.values(): - pin_control.turn_off_pin(pin) + # for pin in leds_gpio.values(): + # pin_control.turn_off_pin(pin) return HttpResponse("Ok") def turn_on_all(): - for pin in leds_gpio.values(): - pin_control.turn_on_pin(pin) + # for pin in leds_gpio.values(): + # pin_control.turn_on_pin(pin) return HttpResponse("Ok") def toggle_led(led, turn_on): gpio_pin = leds_gpio[led] - if turn_on: - pin_control.turn_off_pin(gpio_pin) - else: - pin_control.turn_on_pin(gpio_pin) + # if turn_on: + # pin_control.turn_off_pin(gpio_pin) + # else: + # pin_control.turn_on_pin(gpio_pin) leds_state[led] = not turn_on return HttpResponse("on" if turn_on else "off") def button_detect(request, pin): - return HttpResponse(pin_control.probe_pin(leds_gpio[pin])) \ No newline at end of file + # return HttpResponse(pin_control.probe_pin(leds_gpio[pin])) + return HttpResponse(1) \ No newline at end of file