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()}") leds_state = { 1: False, 2: False, 3: False, 4: False, 5: False, } def home(request): return render(request, "home.html") 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}")