add pins interface
This commit is contained in:
parent
e841e69b47
commit
ee45d97a8b
|
@ -2,8 +2,8 @@ from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
# pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so")
|
pin_control = ctypes.CDLL("@pin_control@/lib/libpin_control.so")
|
||||||
# print(f"INIT: {pin_control.init_gpio()}")
|
print(f"INIT: {pin_control.init_gpio()}")
|
||||||
|
|
||||||
leds_state = {
|
leds_state = {
|
||||||
1: False,
|
1: False,
|
||||||
|
@ -13,6 +13,14 @@ leds_state = {
|
||||||
5: False,
|
5: False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leds_gpio = {
|
||||||
|
1: 5,
|
||||||
|
2: 6,
|
||||||
|
3: 13,
|
||||||
|
4: 19,
|
||||||
|
5: 26
|
||||||
|
}
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
return render(request, "home.html")
|
return render(request, "home.html")
|
||||||
|
|
||||||
|
@ -39,7 +47,11 @@ def turn_on_all():
|
||||||
print("TURN ON ALL")
|
print("TURN ON ALL")
|
||||||
return HttpResponse("Ok")
|
return HttpResponse("Ok")
|
||||||
|
|
||||||
def toggle_led(led, state) :
|
def toggle_led(led, turn_on):
|
||||||
print(f"NEW_STATE ({led}): {not state}")
|
gpio_pin = leds_gpio[led]
|
||||||
leds_state[led] = not state
|
if turn_on:
|
||||||
return HttpResponse(f"Turn on {led}" if state else f"Turn off {led}")
|
pin_control.turn_on_pin(gpio_pin)
|
||||||
|
else:
|
||||||
|
pin_control.turn_off_pin(gpio_pin)
|
||||||
|
leds_state[led] = not turn_on
|
||||||
|
return HttpResponse(f"Turn on {led}" if turn_on else f"Turn off {led}")
|
Loading…
Reference in a new issue