From a60d427dd48a4b5f71a701aa44a745fb7b6c3c52 Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 13:11:35 -0600 Subject: [PATCH 1/9] hotfix camera function --- ui/main/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui/main/views.py b/ui/main/views.py index be8770c..c1d3996 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -26,7 +26,7 @@ def home(request): def take_photo(request): - capture_image("/tmp/static/photo.jpg") + pin_control.capture_image("/tmp/static/photo.jpg") return HttpResponse("Ok") @@ -40,11 +40,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_on_pin(pin) return HttpResponse("Ok") def turn_on_all(): - print("TURN ON ALL") + for pin in leds_gpio.values(): + pin_control.turn_off_pin(pin) return HttpResponse("Ok") def toggle_led(led, turn_on): From 5dd773ad95cb7c1dafc9993a8c6959d7ef650a9d Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 13 Sep 2023 13:26:07 -0600 Subject: [PATCH 2/9] trivios: refactor flake --- flake.nix | 95 +++------------------------------------------ triviOS/cross.nix | 36 +++++++++++++++++ triviOS/overlay.nix | 46 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 89 deletions(-) create mode 100644 triviOS/cross.nix create mode 100644 triviOS/overlay.nix 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 { }; +} From 41180c6ace811f14e5f85a558b32bae37e6e408b Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 13 Sep 2023 13:29:44 -0600 Subject: [PATCH 3/9] trivios: add udev rules for /dev/video0 --- triviOS/web.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/triviOS/web.nix b/triviOS/web.nix index 758931d..8bc104e 100644 --- a/triviOS/web.nix +++ b/triviOS/web.nix @@ -37,6 +37,7 @@ udev.extraRules = '' KERNEL=="gpiochip*", GROUP="uwsgi", MODE="660" + KERNEL=="video*", GROUP="uwsgi", MODE="660" ''; }; } From 9f827ecb555c9d175883bc5ec784f18ace187a8c Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 13:36:06 -0600 Subject: [PATCH 4/9] chagen path camera --- ui/main/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/main/views.py b/ui/main/views.py index c1d3996..d40eba1 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -26,7 +26,7 @@ def home(request): def take_photo(request): - pin_control.capture_image("/tmp/static/photo.jpg") + pin_control.capture_image(b'/tmp/static/photo.jpg') return HttpResponse("Ok") @@ -41,12 +41,12 @@ def led(request, led): def turn_off_all(): for pin in leds_gpio.values(): - pin_control.turn_on_pin(pin) + pin_control.turn_off_pin(pin) return HttpResponse("Ok") def turn_on_all(): for pin in leds_gpio.values(): - pin_control.turn_off_pin(pin) + pin_control.turn_on_pin(pin) return HttpResponse("Ok") def toggle_led(led, turn_on): @@ -56,4 +56,4 @@ 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(f"Turn off {led}" if turn_on else f"Turn on {led}") \ No newline at end of file From 933add2211d779167d6d3f6d85c2944241fe095e Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 14:07:26 -0600 Subject: [PATCH 5/9] change data location --- triviOS/web.nix | 2 +- ui/homemanager/settings.py | 2 +- ui/main/views.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/triviOS/web.nix b/triviOS/web.nix index 8bc104e..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; 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/views.py b/ui/main/views.py index d40eba1..316054f 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -26,7 +26,7 @@ def home(request): def take_photo(request): - pin_control.capture_image(b'/tmp/static/photo.jpg') + pin_control.capture_image(b'/run/nginx/static/photo.jpg') return HttpResponse("Ok") @@ -56,4 +56,4 @@ def toggle_led(led, turn_on): else: pin_control.turn_on_pin(gpio_pin) leds_state[led] = not turn_on - return HttpResponse(f"Turn off {led}" if turn_on else f"Turn on {led}") \ No newline at end of file + return HttpResponse("on" if turn_on else f"Turn on {led}") \ No newline at end of file From b6c6060a89f50b2d0c40f7b933ecedd2c4fa1f46 Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 14:44:31 -0600 Subject: [PATCH 6/9] add button interface --- ui/main/templates/home.html | 55 +++++++++++++++++++++++++++++++------ ui/main/urls.py | 3 +- ui/main/views.py | 12 ++++++-- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index 8befc22..f5d7062 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -13,7 +13,9 @@ $.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) + } } }); } @@ -23,6 +25,34 @@ $("#photo").attr("src", "static/photo.jpg?"+d.getTime()); }); } + + + 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); + {% if user.is_authenticated %} @@ -87,17 +117,24 @@ 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 - // 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) - }; + // var imagen = new Image(); + + // // 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 + // imagen.onload = function () { + // // Dibujar la imagen en el canvas + // ctx.drawImage(imagen, 20, 100, 80, 80); // (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 316054f..50f94fa 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): @@ -56,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("on" if turn_on else f"Turn on {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])) \ No newline at end of file From f6392a43b2d09d5c65ce13647bd7e47f4e0eb950 Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 15:41:34 -0600 Subject: [PATCH 7/9] add leds indicators --- ui/main/templates/home.html | 114 ++++++++++++++++++++++++++++++------ 1 file changed, 97 insertions(+), 17 deletions(-) diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index f5d7062..5c5bb8f 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -9,12 +9,43 @@ } From 87260d709d1cfb22e4720980cf5423ee389ea377 Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 16:00:29 -0600 Subject: [PATCH 8/9] add leds all indicators --- ui/main/templates/home.html | 116 +++++++++++++++++++++++++++++++++++- ui/main/views.py | 25 ++++---- 2 files changed, 126 insertions(+), 15 deletions(-) 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 From 42627646fdd7e4f205c68bf6a14120181cbc5670 Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Wed, 13 Sep 2023 16:02:57 -0600 Subject: [PATCH 9/9] add leds all indicators --- ui/main/views.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ui/main/views.py b/ui/main/views.py index 1166104..653195d 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,25 +44,24 @@ 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])) - return HttpResponse(1) \ No newline at end of file + return HttpResponse(pin_control.probe_pin(leds_gpio[pin]))