triviOS/ui/main/views.py

21 lines
653 B
Python
Raw Normal View History

2023-09-11 08:07:53 +02:00
from django.shortcuts import render
2023-09-12 23:51:16 +02:00
from .forms import Lights
import ctypes
2023-09-11 08:07:53 +02:00
# Create your views here.
2023-09-11 09:59:25 +02:00
2023-09-13 04:09:04 +02:00
pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so")
2023-09-12 23:51:16 +02:00
2023-09-11 09:59:25 +02:00
def home(request):
2023-09-12 23:51:16 +02:00
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"})
2023-09-11 09:59:25 +02:00
2023-09-12 23:51:16 +02:00
def light_up_all():
print(f"INIT: {pin_control.init_gpio()}")
print(f"ALL_PINS: {pin_control.turn_on_all_pins()}")