120 lines
3.8 KiB
Python
120 lines
3.8 KiB
Python
import RPi.GPIO as GPIO
|
|
from flask import Flask, render_template, request
|
|
import threading
|
|
import time
|
|
import pigpio
|
|
|
|
pi = pigpio.pi()
|
|
|
|
from src.einstellungen import *
|
|
from src.schrittmotor import motor, motor_bewegen
|
|
|
|
kamera_server = Flask(__name__)
|
|
|
|
# Set each pin as an output and make it low:
|
|
for pin in pins_out:
|
|
pi.set_mode(pins_out[pin]['nr'], pigpio.OUTPUT)
|
|
pi.write(pins_out[pin]['nr'], 1)
|
|
#GPIO.setup(pins_out[pin]['nr'], GPIO.OUT)
|
|
#GPIO.output(pins_out[pin]['nr'], GPIO.HIGH)
|
|
|
|
for pin in pins_in:
|
|
pi.set_mode(pins_in[pin]['nr'], pigpio.INPUT)
|
|
#GPIO.setup(pins_in[pin]['nr'], GPIO.IN)
|
|
|
|
#GPIO.output(pins_out['kamera']['nr'], GPIO.LOW)
|
|
pi.write(pins_out['kamera']['nr'], 0)
|
|
|
|
m1 = motor('drehen', m1_a1, m1_b1, m1_a2, m1_b2, m1_t1, m1_t2, m1_te, m1_es, 1, 180)
|
|
m2 = motor('kippen', m2_a1, m2_b1, m2_a2, m2_b2, m2_t1, m2_t2, m2_te, m2_es, 1, 90)
|
|
m3 = motor('zoom', m3_a1, m3_b1, m3_a2, m3_b2, m3_t1, m3_t2, m3_te, m3_es, 0, 40)
|
|
|
|
m1.start()
|
|
m2.start()
|
|
m3.start()
|
|
|
|
m1.eichen()
|
|
m2.eichen()
|
|
m3.eichen()
|
|
|
|
#m1.vorwaerts(100)
|
|
#m1.stop()
|
|
#m2.stop()
|
|
|
|
@kamera_server.route("/")
|
|
def main():
|
|
# For each pin, read the pin state and store it in the pins dictionary:
|
|
for pin in pins_out:
|
|
#pins_out[pin]['state'] = GPIO.input(pins_out[pin]['nr'])
|
|
pins_out[pin]['state'] = pi.read(pins_out[pin]['nr'])
|
|
for pin in pins_in:
|
|
#pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr'])
|
|
pins_in[pin]['state'] = pi.read(pins_in[pin]['nr'])
|
|
|
|
# Put the pin dictionary into the template data dictionary:
|
|
templateData = {
|
|
'pins' : pins_out,
|
|
'pins_in' : pins_in
|
|
}
|
|
# Pass the template data into the template main.html and return it to the user
|
|
return render_template('main.html', **templateData)
|
|
|
|
# The function below is executed when someone requests a URL with the pin number and action in it:
|
|
@kamera_server.route("/<changePin>/<action>")
|
|
def action(changePin, action):
|
|
# Convert the pin from the URL into an integer:
|
|
|
|
# Get the device name for the pin being changed:
|
|
deviceName = pins_out[changePin]['name']
|
|
changePin = pins_out[changePin]['nr']
|
|
# If the action part of the URL is "on," execute the code indented below:
|
|
if action == "on":
|
|
# Set the pin high:
|
|
#GPIO.output(changePin, GPIO.HIGH)
|
|
pi.write(changePin, 1)
|
|
# Save the status message to be passed into the template:
|
|
message = "Turned " + deviceName + " on."
|
|
if action == "off":
|
|
#GPIO.output(changePin, GPIO.LOW)
|
|
pi.write(changePin, GPIO.LOW)
|
|
message = "Turned " + deviceName + " off."
|
|
|
|
# For each pin, read the pin state and store it in the pins dictionary:
|
|
for pin in pins_out:
|
|
#pins_out[pin]['state'] = GPIO.input(pins_out[pin]['nr'])
|
|
pins_out[pin]['state'] = pi.read(pins_out[pin]['nr'])
|
|
for pin in pins_in:
|
|
#pins_in[pin]['state'] = GPIO.input(pins_in[pin]['nr'])
|
|
pins_in[pin]['state'] = pi.read(pins_in[pin]['nr'])
|
|
|
|
# Along with the pin dictionary, put the message into the template data dictionary:
|
|
templateData = {
|
|
'pins' : pins_out,
|
|
'pins_in' : pins_in
|
|
}
|
|
|
|
return render_template('main.html', **templateData)
|
|
|
|
@kamera_server.route("/position/<drehen>/<pos1>/<kippen>/<pos2>/<zoom>/<pos3>")
|
|
def motor_test(drehen, pos1, kippen, pos2, zoom, pos3):
|
|
if drehen == "drehen":
|
|
#m1.gehe_zu(int(position))
|
|
th1 = motor_bewegen(m1, (int(pos1)))
|
|
#th1.join()
|
|
|
|
if kippen == "kippen":
|
|
#m1.gehe_zu(int(position))
|
|
th2 = motor_bewegen(m2, (int(pos2)))
|
|
#th2.join()
|
|
|
|
if zoom == "zoom":
|
|
#m1.gehe_zu(int(position))
|
|
th3 = motor_bewegen(m3, (int(pos3)))
|
|
#th3.join()
|
|
|
|
return 'Drehen: ' + str(m1.pos) + ', Kippen: ' + str(m2.pos) + ', Zoom: ' + str(m3.pos)
|
|
|
|
if __name__ == "__main__":
|
|
kamera_server.run(host='0.0.0.0')
|
|
|