diff --git a/ui/main/admin.py b/ui/main/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/ui/main/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/ui/main/forms.py b/ui/main/forms.py deleted file mode 100644 index 7a3fea3..0000000 --- a/ui/main/forms.py +++ /dev/null @@ -1,21 +0,0 @@ -from django import forms - -class Lights(forms.Form): - required_css_class = "list-group-item" - - MODES = [ - ('0', 'Apagar todo'), - ('1', 'Encender todo'), - ('2', 'Sala'), - ('3', 'Pasillo'), - ('4', 'Cocina'), - ('5', 'Cuarto 1'), - ('6', 'Cuarto 2'), - - ] - light = forms.ChoiceField( - widget=forms.RadioSelect, - choices=MODES, - label="Select lights to modify" - ) - \ No newline at end of file diff --git a/ui/main/models.py b/ui/main/models.py deleted file mode 100644 index 71a8362..0000000 --- a/ui/main/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/ui/main/static/1.jpg b/ui/main/static/1.jpg deleted file mode 100644 index 32de50e..0000000 Binary files a/ui/main/static/1.jpg and /dev/null differ diff --git a/ui/main/static/2.jpg b/ui/main/static/2.jpg deleted file mode 100644 index b454832..0000000 Binary files a/ui/main/static/2.jpg and /dev/null differ diff --git a/ui/main/static/3.jpg b/ui/main/static/3.jpg deleted file mode 100644 index b5bc07c..0000000 Binary files a/ui/main/static/3.jpg and /dev/null differ diff --git a/ui/main/templates/base.html b/ui/main/templates/base.html index 8a19203..541dfdb 100644 --- a/ui/main/templates/base.html +++ b/ui/main/templates/base.html @@ -39,18 +39,18 @@ {% endif %} + {% block content %}{% endblock %} - + - + - diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index 53f031e..f723ba4 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -8,20 +8,44 @@ object-fit: cover; } + {% if user.is_authenticated %} -
-
- {% csrf_token %} - - -
+ +
+ + + + + + +
+
+ + +
+
- {% load static %} - My image + +

+ My image
{% else %}
@@ -32,5 +56,49 @@
{% endif %} + + {% endblock content %} \ No newline at end of file diff --git a/ui/main/tests.py b/ui/main/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/ui/main/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/ui/main/urls.py b/ui/main/urls.py index 3d14910..6a4ce80 100644 --- a/ui/main/urls.py +++ b/ui/main/urls.py @@ -1,7 +1,9 @@ from django.urls import path -from .views import home +from .views import home, led, take_photo urlpatterns = [ - path('', home, name='home'), + path("", home, name="home"), + path("led//", led, name="leds"), + path("photo/", take_photo), ] diff --git a/ui/main/views.py b/ui/main/views.py index 81d489e..94722ff 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -1,21 +1,45 @@ from django.shortcuts import render -from .forms import Lights +from django.http import HttpResponse import ctypes -# Create your views here. +# 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") +leds_state = { + 1: False, + 2: False, + 3: False, + 4: False, + 5: False, +} def home(request): - if request.method == "POST": - form = Lights(request.POST) - if form.is_valid(): - opt = form.cleaned_data.get("light") - light_up_all() - return render(request, "home.html", {"form": form, "image": f"{opt}.jpg"}) - return render(request, "home.html", {"form": Lights(), "image": "1.jpg"}) + return render(request, "home.html") -def light_up_all(): - print(f"INIT: {pin_control.init_gpio()}") - print(f"ALL_PINS: {pin_control.turn_on_all_pins()}") \ No newline at end of file +def take_photo(request): + print("PRINTING PHOTO") + return HttpResponse("Ok") + + +def led(request, led): + if request.method == "GET": + if led == 0: return turn_off_all() + if led == 6: return turn_on_all() + state = leds_state.get(led) + if state is not None: return toggle_led(led, state) + print("UNKNOWN LED") + return HttpResponse("Ok") + +def turn_off_all(): + print("TURN OFF ALL") + return HttpResponse("Ok") + +def turn_on_all(): + print("TURN ON ALL") + return HttpResponse("Ok") + +def toggle_led(led, state) : + print(f"NEW_STATE ({led}): {not state}") + leds_state[led] = not state + return HttpResponse(f"Turn on {led}" if state else f"Turn off {led}") \ No newline at end of file