forked from greenbamboos/RaspberryPi_NERV_Car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Start.py
47 lines (35 loc) · 870 Bytes
/
Start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, render_template, jsonify
import RPi.GPIO as GPIO
from NCode import NCar
import atexit
atexit.register(GPIO.cleanup)
app = Flask(__name__)
# 首页
@app.route("/")
def index():
return render_template('index.html')
# 驾驶
@app.route('/drive/<action>', methods=['GET'])
def drive(action):
if action == 'forward':
car.forward()
if action == 'backOff':
car.backOff()
if action == 'leftTurn':
car.leftTurn()
if action == 'rightTurn':
car.rightTurn()
if action == 'stop':
car.stop()
return jsonify({'success': 'ok'})
# 重置
@app.route('/reset', methods=['GET'])
def reset():
GPIO.cleanup()
return jsonify({'success': 'ok'})
car = NCar.NCar()
if __name__ == '__main__':
try:
app.run(host='0.0.0.0')
except Exception as e:
GPIO.cleanup()