diff --git a/flake.nix b/flake.nix index fca20df..92bbdc6 100644 --- a/flake.nix +++ b/flake.nix @@ -1,19 +1,102 @@ { - 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; - crossSystem = import ./triviOS/cross.nix; - overlays = [ (import ./triviOS/overlay.nix) ]; + + 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"; + }; + }; }; in { - formatter.${system} = pkgs.pkgsBuildBuild.nixpkgs-fmt; + packages.${crossSystem} = pkgs; nixosConfigurations.triviOS = nixpkgs.lib.nixosSystem { inherit pkgs; @@ -21,6 +104,6 @@ modules = [ ./triviOS ]; }; - packages.${crossSystem} = pkgs; + formatter.${system} = pkgs.pkgsBuildBuild.nixpkgs-fmt; }; } diff --git a/triviOS/cross.nix b/triviOS/cross.nix deleted file mode 100644 index 0e95a42..0000000 --- a/triviOS/cross.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - 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"; - }; -} diff --git a/triviOS/overlay.nix b/triviOS/overlay.nix deleted file mode 100644 index 7f3821f..0000000 --- a/triviOS/overlay.nix +++ /dev/null @@ -1,46 +0,0 @@ -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 { }; -} diff --git a/triviOS/web.nix b/triviOS/web.nix index 4e01c6e..758931d 100644 --- a/triviOS/web.nix +++ b/triviOS/web.nix @@ -11,7 +11,7 @@ default = true; locations = { - "/static/".alias = "/run/nginx/static/"; + "/static/".alias = "/tmp/static/"; "/".extraConfig = '' uwsgi_pass unix://${config.services.uwsgi.runDir}/uwsgi.sock; @@ -37,7 +37,6 @@ udev.extraRules = '' KERNEL=="gpiochip*", GROUP="uwsgi", MODE="660" - KERNEL=="video*", GROUP="uwsgi", MODE="660" ''; }; } diff --git a/ui/homemanager/settings.py b/ui/homemanager/settings.py index 2b82d6f..e9f95c7 100644 --- a/ui/homemanager/settings.py +++ b/ui/homemanager/settings.py @@ -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("/run/nginx").resolve() +DATA_DIR = Path("/tmp").resolve() # Quick-start development settings - unsuitable for production diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index cb58bc2..8befc22 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -9,203 +9,32 @@ } {% if user.is_authenticated %}
- - - - - - - + + + + + + +
@@ -253,78 +82,22 @@ // Etiquetas de las habitaciones ctx.fillStyle = "#000000"; // Color negro ctx.font = "30px Arial"; - ctx.fillText("Cuarto 1", 150, 150); + ctx.fillText("Cuarto 1", 100, 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 - ctx.strokeRect(350, 4, 100, 1); // Puerta trasera - ctx.strokeRect(350, 596, 100, 1); // Puerta tdelanteearasera + var imagen = new Image(); - 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"; + // 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" // Esperar a que la imagen se cargue antes de dibujarla - image.onload = function () { - ctx.drawImage(image, 20, 80, 100, 100); // (imagen, x, y) + imagen.onload = function () { + // Dibujar la imagen en el canvas + ctx.drawImage(imagen, 20, 100, 80, 80); // (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) - }; - - - - diff --git a/ui/main/urls.py b/ui/main/urls.py index 89818c9..6a4ce80 100644 --- a/ui/main/urls.py +++ b/ui/main/urls.py @@ -1,10 +1,9 @@ from django.urls import path -from .views import home, led, take_photo, button_detect +from .views import home, led, take_photo urlpatterns = [ path("", home, name="home"), path("led//", led, name="leds"), path("photo/", take_photo), - path("button//", button_detect), ] diff --git a/ui/main/views.py b/ui/main/views.py index 653195d..be8770c 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -18,11 +18,7 @@ leds_gpio = { 2: 6, 3: 13, 4: 19, - 5: 26, - 7: 21, - 8: 20, - 9: 16, - 10: 12, + 5: 26 } def home(request): @@ -30,7 +26,7 @@ def home(request): def take_photo(request): - pin_control.capture_image(b'/run/nginx/static/photo.jpg') + capture_image("/tmp/static/photo.jpg") return HttpResponse("Ok") @@ -44,13 +40,11 @@ def led(request, led): return HttpResponse("Ok") def turn_off_all(): - for pin in leds_gpio.values(): - pin_control.turn_off_pin(pin) + print("TURN OFF ALL") return HttpResponse("Ok") def turn_on_all(): - for pin in leds_gpio.values(): - pin_control.turn_on_pin(pin) + print("TURN ON ALL") return HttpResponse("Ok") def toggle_led(led, turn_on): @@ -60,8 +54,4 @@ def toggle_led(led, turn_on): 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])) + return HttpResponse(f"Turn on {led}" if turn_on else f"Turn off {led}") \ No newline at end of file