triviOS/ui/main/views.py

21 lines
653 B
Python

from django.shortcuts import render
from .forms import Lights
import ctypes
# Create your views here.
pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so")
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"})
def light_up_all():
print(f"INIT: {pin_control.init_gpio()}")
print(f"ALL_PINS: {pin_control.turn_on_all_pins()}")