Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from flask import Flask, request,render_template
- from random import shuffle,choice
- from time import sleep
- from pygal.style import DarkSolarizedStyle
- import serial
- import pygal
- app = Flask(__name__)
- try:
- try: # crie um serial na porta ACM0
- ser = serial.Serial("/dev/ttyACM0",9600)
- except: # crie um serial na porta ACM1
- ser = serial.Serial("/dev/ttyACM1",9600)
- except:
- status = False
- def gera_grafico(direita,esquerda,frente):
- bar_chart = pygal.HorizontalBar(width=1200,height=400,style=DarkSolarizedStyle)
- bar_chart.title = "Sensor UltraSom HC-04"
- bar_chart.add('Direita', direita)
- bar_chart.add('Esquanerda',esquerda)
- bar_chart.add('Frente', frente)
- chart = bar_chart.render(is_unicode=True)
- return chart
- def update_values():
- while True:
- sleep(0.1)
- rd = range(100)
- shuffle(rd)
- return gera_grafico(choice(rd),choice(rd),choice(rd))
- def processos():
- cpu = range(10)
- ram = range(10)
- processos_execucao = range (10)
- return [cpu,ram,processos_execucao]
- @app.route("/")
- def home():
- return render_template("index.html")
- @app.route("/controle",methods=["GET","POST"]) # controle do robo manualmente
- def controle():
- if request.method == "POST":
- if request.form['submit'] == "RUN":
- print "RUN ROBOT"
- # send comand RUN to robot
- if status:
- ser.write("w")
- else:
- print "No Send comand "
- elif request.form['submit'] == "BACK":
- print 'RUN BACK'
- # send comand BACK to robot
- if status:
- ser.write("s")
- else:
- print "No Send comand "
- elif request.form['submit'] == "LEFT":
- print "RUN LEFT"
- # send comand LEFT to robot
- if status:
- ser.write("a")
- else:
- print "No Send comand "
- elif request.form['submit'] == "RIGHT":
- print "RUN RIGHT"
- # send comand LEFT to robot
- if status:
- ser.write("d")
- else:
- print "No Send comand "
- elif request.form['submit'] == "STOP":
- print "STOP ROBOT"
- # send comand LEFT to robot
- if status:
- ser.write("p")
- else:
- print "No Send comand "
- return render_template('controle.html')
- @app.route("/graficos",methods=["GET","POST"])
- def graficos():
- return render_template('graficos.html',chart=update_values())
- @app.route("/processos")
- def processos():
- return render_template('processos.html')
- @app.route("/camera")
- def camera():
- return render_template('camera.html')
- if __name__ == "__main__":
- app.run(host="0.0.0.0",port=80,debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement