Compare commits
10 commits
37f8d5883a
...
42627646fd
Author | SHA1 | Date | |
---|---|---|---|
Alejandro Diaz | 42627646fd | ||
Alejandro Diaz | 87260d709d | ||
Alejandro Diaz | f6392a43b2 | ||
Alejandro Diaz | b6c6060a89 | ||
Alejandro Diaz | 933add2211 | ||
Alejandro Diaz | 5dc5a79f29 | ||
Alejandro Diaz | 9f827ecb55 | ||
41180c6ace | |||
5dd773ad95 | |||
Alejandro Diaz | a60d427dd4 |
95
flake.nix
95
flake.nix
|
@ -1,102 +1,19 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
|
||||
};
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
crossSystem = "aarch64-linux";
|
||||
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
|
||||
overlays = [
|
||||
(self: super: {
|
||||
systemd = super.systemd.override {
|
||||
pname = "systemd-minimal";
|
||||
withAcl = false;
|
||||
withAnalyze = false;
|
||||
withApparmor = false;
|
||||
withAudit = false;
|
||||
withCompression = false;
|
||||
withCoredump = false;
|
||||
withCryptsetup = false;
|
||||
withDocumentation = false;
|
||||
withEfi = false;
|
||||
withFido2 = false;
|
||||
withHostnamed = false;
|
||||
withHomed = false;
|
||||
withImportd = false;
|
||||
withLibBPF = false;
|
||||
withLibidn2 = false;
|
||||
withLocaled = false;
|
||||
withMachined = false;
|
||||
withNetworkd = false;
|
||||
withNss = false;
|
||||
withOomd = false;
|
||||
withPCRE2 = false;
|
||||
withPolkit = false;
|
||||
withPortabled = false;
|
||||
withRemote = false;
|
||||
withResolved = false;
|
||||
withShellCompletions = false;
|
||||
withTimedated = false;
|
||||
withTimesyncd = false;
|
||||
withTpm2Tss = false;
|
||||
withUserDb = false;
|
||||
# This is necessary for any installation
|
||||
# withPam = false;
|
||||
# withHwdb = false;
|
||||
# withLogind = false;
|
||||
};
|
||||
|
||||
libaom = super.libaom.override {
|
||||
enableButteraugli = false;
|
||||
};
|
||||
|
||||
pin_control = self.callPackage ./pin_control { };
|
||||
})
|
||||
];
|
||||
|
||||
crossSystem = {
|
||||
gcc.cpu = "cortex-a53";
|
||||
config = "aarch64-unknown-linux-gnu";
|
||||
linux-kernel = {
|
||||
DTB = true;
|
||||
autoModules = true;
|
||||
baseConfig = "defconfig";
|
||||
|
||||
extraConfig = ''
|
||||
# Raspberry Pi 3 stuff. Not needed for s >= 4.10.
|
||||
ARCH_BCM2835 y
|
||||
BCM2835_MBOX y
|
||||
BCM2835_WDT y
|
||||
RASPBERRYPI_FIRMWARE y
|
||||
RASPBERRYPI_POWER y
|
||||
SERIAL_8250_BCM2835AUX y
|
||||
SERIAL_8250_EXTENDED y
|
||||
SERIAL_8250_SHARE_IRQ y
|
||||
|
||||
# Cavium ThunderX stuff.
|
||||
PCI_HOST_THUNDER_ECAM y
|
||||
|
||||
# Nvidia Tegra stuff.
|
||||
PCI_TEGRA y
|
||||
|
||||
# The default (=y) forces us to have the XHCI firmware available in initrd,
|
||||
# which our initrd builder can't currently do easily.
|
||||
USB_XHCI_TEGRA m
|
||||
'';
|
||||
|
||||
name = "aarch64-multiplatform";
|
||||
preferBuiltin = true;
|
||||
target = "Image";
|
||||
};
|
||||
};
|
||||
crossSystem = import ./triviOS/cross.nix;
|
||||
overlays = [ (import ./triviOS/overlay.nix) ];
|
||||
};
|
||||
in
|
||||
{
|
||||
packages.${crossSystem} = pkgs;
|
||||
formatter.${system} = pkgs.pkgsBuildBuild.nixpkgs-fmt;
|
||||
|
||||
nixosConfigurations.triviOS = nixpkgs.lib.nixosSystem {
|
||||
inherit pkgs;
|
||||
|
@ -104,6 +21,6 @@
|
|||
modules = [ ./triviOS ];
|
||||
};
|
||||
|
||||
formatter.${system} = pkgs.pkgsBuildBuild.nixpkgs-fmt;
|
||||
packages.${crossSystem} = pkgs;
|
||||
};
|
||||
}
|
||||
|
|
36
triviOS/cross.nix
Normal file
36
triviOS/cross.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
config = "aarch64-unknown-linux-gnu";
|
||||
gcc.cpu = "cortex-a53";
|
||||
|
||||
linux-kernel = {
|
||||
DTB = true;
|
||||
autoModules = true;
|
||||
baseConfig = "defconfig";
|
||||
|
||||
extraConfig = ''
|
||||
# Raspberry Pi 3 stuff. Not needed for s >= 4.10.
|
||||
ARCH_BCM2835 y
|
||||
BCM2835_MBOX y
|
||||
BCM2835_WDT y
|
||||
RASPBERRYPI_FIRMWARE y
|
||||
RASPBERRYPI_POWER y
|
||||
SERIAL_8250_BCM2835AUX y
|
||||
SERIAL_8250_EXTENDED y
|
||||
SERIAL_8250_SHARE_IRQ y
|
||||
|
||||
# Cavium ThunderX stuff.
|
||||
PCI_HOST_THUNDER_ECAM y
|
||||
|
||||
# Nvidia Tegra stuff.
|
||||
PCI_TEGRA y
|
||||
|
||||
# The default (=y) forces us to have the XHCI firmware available in initrd,
|
||||
# which our initrd builder can't currently do easily.
|
||||
USB_XHCI_TEGRA m
|
||||
'';
|
||||
|
||||
name = "aarch64-multiplatform";
|
||||
preferBuiltin = true;
|
||||
target = "Image";
|
||||
};
|
||||
}
|
46
triviOS/overlay.nix
Normal file
46
triviOS/overlay.nix
Normal file
|
@ -0,0 +1,46 @@
|
|||
self: super: {
|
||||
systemd = super.systemd.override {
|
||||
pname = "systemd-minimal";
|
||||
withAcl = false;
|
||||
withAnalyze = false;
|
||||
withApparmor = false;
|
||||
withAudit = false;
|
||||
withCompression = false;
|
||||
withCoredump = false;
|
||||
withCryptsetup = false;
|
||||
withDocumentation = false;
|
||||
withEfi = false;
|
||||
withFido2 = false;
|
||||
withHostnamed = false;
|
||||
withHomed = false;
|
||||
withImportd = false;
|
||||
withLibBPF = false;
|
||||
withLibidn2 = false;
|
||||
withLocaled = false;
|
||||
withMachined = false;
|
||||
withNetworkd = false;
|
||||
withNss = false;
|
||||
withOomd = false;
|
||||
withPCRE2 = false;
|
||||
withPolkit = false;
|
||||
withPortabled = false;
|
||||
withRemote = false;
|
||||
withResolved = false;
|
||||
withShellCompletions = false;
|
||||
withTimedated = false;
|
||||
withTimesyncd = false;
|
||||
withTpm2Tss = false;
|
||||
withUserDb = false;
|
||||
|
||||
# Se implican y son necesarios:
|
||||
# withPam = true;
|
||||
# withHwdb = true;
|
||||
# withLogind = true;
|
||||
};
|
||||
|
||||
libaom = super.libaom.override {
|
||||
enableButteraugli = false;
|
||||
};
|
||||
|
||||
pin_control = self.callPackage ../pin_control { };
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
default = true;
|
||||
|
||||
locations = {
|
||||
"/static/".alias = "/tmp/static/";
|
||||
"/static/".alias = "/run/nginx/static/";
|
||||
|
||||
"/".extraConfig = ''
|
||||
uwsgi_pass unix://${config.services.uwsgi.runDir}/uwsgi.sock;
|
||||
|
@ -37,6 +37,7 @@
|
|||
|
||||
udev.extraRules = ''
|
||||
KERNEL=="gpiochip*", GROUP="uwsgi", MODE="660"
|
||||
KERNEL=="video*", GROUP="uwsgi", MODE="660"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ from pathlib import Path
|
|||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
DATA_DIR = Path("/tmp").resolve()
|
||||
DATA_DIR = Path("/run/nginx").resolve()
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
|
|
|
@ -9,32 +9,203 @@
|
|||
}
|
||||
</style>
|
||||
<script>
|
||||
function toggle_leds(led) {
|
||||
|
||||
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) {
|
||||
|
||||
$.get("/led/"+ led +"/", function (data) {
|
||||
console.log(data);
|
||||
if (led < 6 && led > 0) {
|
||||
$("#but"+led).text(data);
|
||||
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
|
||||
image.onload = function () {
|
||||
ctx.drawImage(image, x, y, w, h); // (imagen, x, y)
|
||||
};
|
||||
|
||||
} 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
|
||||
image.onload = function () {
|
||||
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)
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function take_photo() {
|
||||
$.get("/photo/", function (data) {
|
||||
$("#photo").attr("src", "static/photo.jpg?"+d.getTime());
|
||||
$("#photo").attr("src", "static/photo.jpg?rand="+Math.random());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
</script>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
|
||||
<div class="jumbotron justify-content-center align-items-center">
|
||||
<button id="but6" class="btn btn-primary btn-lg" onclick="toggle_leds(6);">Turn on all</button>
|
||||
<button id="but0" class="btn btn-primary btn-lg" onclick="toggle_leds(0);">Turn off all</button>
|
||||
<button id="but1" class="btn btn-primary btn-lg" onclick="toggle_leds(1);">Turn on 1</button>
|
||||
<button id="but2" class="btn btn-primary btn-lg" onclick="toggle_leds(2);">Turn on 2</button>
|
||||
<button id="but3" class="btn btn-primary btn-lg" onclick="toggle_leds(3);">Turn on 3</button>
|
||||
<button id="but4" class="btn btn-primary btn-lg" onclick="toggle_leds(4);">Turn on 4</button>
|
||||
<button id="but5" class="btn btn-primary btn-lg" onclick="toggle_leds(5);">Turn on 5</button>
|
||||
<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>
|
||||
</div>
|
||||
<div class="jumbotron" width="800" height="600">
|
||||
<canvas id="miCanvas" class="mx-auto" width="800" height="600"></canvas>
|
||||
|
@ -82,22 +253,78 @@
|
|||
// 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);
|
||||
|
||||
ctx.strokeStyle = "#FF0000"; // Color negro
|
||||
ctx.strokeRect(300, 100, 1, 75); // Puerta 1
|
||||
|
||||
var imagen = new Image();
|
||||
ctx.strokeRect(350, 4, 100, 1); // Puerta trasera
|
||||
ctx.strokeRect(350, 596, 100, 1); // Puerta tdelanteearasera
|
||||
|
||||
// Definir la ruta de la imagen que deseas cargar
|
||||
imagen.src = "https://www.freepngimg.com/thumb/light/78155-icons-light-idea-computer-lighting-incandescent-bulb.png"
|
||||
ctx.strokeRect(500, 400, 1, 75); // Puerta 2
|
||||
|
||||
|
||||
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
|
||||
imagen.onload = function () {
|
||||
// Dibujar la imagen en el canvas
|
||||
ctx.drawImage(imagen, 20, 100, 80, 80); // (imagen, x, y)
|
||||
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)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
from django.urls import path
|
||||
|
||||
from .views import home, led, take_photo
|
||||
from .views import home, led, take_photo, button_detect
|
||||
|
||||
urlpatterns = [
|
||||
path("", home, name="home"),
|
||||
path("led/<int:led>/", led, name="leds"),
|
||||
path("photo/", take_photo),
|
||||
path("button/<int:pin>/", button_detect),
|
||||
]
|
||||
|
|
|
@ -18,7 +18,11 @@ leds_gpio = {
|
|||
2: 6,
|
||||
3: 13,
|
||||
4: 19,
|
||||
5: 26
|
||||
5: 26,
|
||||
7: 21,
|
||||
8: 20,
|
||||
9: 16,
|
||||
10: 12,
|
||||
}
|
||||
|
||||
def home(request):
|
||||
|
@ -26,7 +30,7 @@ def home(request):
|
|||
|
||||
|
||||
def take_photo(request):
|
||||
capture_image("/tmp/static/photo.jpg")
|
||||
pin_control.capture_image(b'/run/nginx/static/photo.jpg')
|
||||
return HttpResponse("Ok")
|
||||
|
||||
|
||||
|
@ -40,11 +44,13 @@ def led(request, led):
|
|||
return HttpResponse("Ok")
|
||||
|
||||
def turn_off_all():
|
||||
print("TURN OFF ALL")
|
||||
for pin in leds_gpio.values():
|
||||
pin_control.turn_off_pin(pin)
|
||||
return HttpResponse("Ok")
|
||||
|
||||
def turn_on_all():
|
||||
print("TURN ON ALL")
|
||||
for pin in leds_gpio.values():
|
||||
pin_control.turn_on_pin(pin)
|
||||
return HttpResponse("Ok")
|
||||
|
||||
def toggle_led(led, turn_on):
|
||||
|
@ -54,4 +60,8 @@ def toggle_led(led, turn_on):
|
|||
else:
|
||||
pin_control.turn_on_pin(gpio_pin)
|
||||
leds_state[led] = not turn_on
|
||||
return HttpResponse(f"Turn on {led}" if turn_on else f"Turn off {led}")
|
||||
return HttpResponse("on" if turn_on else "off")
|
||||
|
||||
|
||||
def button_detect(request, pin):
|
||||
return HttpResponse(pin_control.probe_pin(leds_gpio[pin]))
|
||||
|
|
Loading…
Reference in a new issue