diff --git a/flake.nix b/flake.nix
index 92bbdc6..fca20df 100644
--- a/flake.nix
+++ b/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;
};
}
diff --git a/triviOS/cross.nix b/triviOS/cross.nix
new file mode 100644
index 0000000..0e95a42
--- /dev/null
+++ b/triviOS/cross.nix
@@ -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";
+ };
+}
diff --git a/triviOS/overlay.nix b/triviOS/overlay.nix
new file mode 100644
index 0000000..7f3821f
--- /dev/null
+++ b/triviOS/overlay.nix
@@ -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 { };
+}
diff --git a/triviOS/web.nix b/triviOS/web.nix
index 758931d..4e01c6e 100644
--- a/triviOS/web.nix
+++ b/triviOS/web.nix
@@ -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"
'';
};
}
diff --git a/ui/homemanager/settings.py b/ui/homemanager/settings.py
index e9f95c7..2b82d6f 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("/tmp").resolve()
+DATA_DIR = Path("/run/nginx").resolve()
# Quick-start development settings - unsuitable for production
diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html
index 8befc22..cb58bc2 100644
--- a/ui/main/templates/home.html
+++ b/ui/main/templates/home.html
@@ -9,32 +9,203 @@
}
{% if user.is_authenticated %}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -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)
+ };
+
+
+
+
diff --git a/ui/main/urls.py b/ui/main/urls.py
index 6a4ce80..89818c9 100644
--- a/ui/main/urls.py
+++ b/ui/main/urls.py
@@ -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//", led, name="leds"),
path("photo/", take_photo),
+ path("button//", button_detect),
]
diff --git a/ui/main/views.py b/ui/main/views.py
index be8770c..653195d 100644
--- a/ui/main/views.py
+++ b/ui/main/views.py
@@ -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}")
\ No newline at end of file
+ return HttpResponse("on" if turn_on else "off")
+
+
+def button_detect(request, pin):
+ return HttpResponse(pin_control.probe_pin(leds_gpio[pin]))