-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (35 loc) · 1.04 KB
/
app.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
48
49
50
51
52
53
from flask import Flask, request
from pyaxidraw import axidraw
import json
import time
app = Flask(__name__,
static_url_path='',
static_folder='static')
@app.route('/', methods=['GET'])
def hello_world():
return app.send_static_file('index.html')
@app.route('/', methods=['POST'])
def draw():
# x = int(request.form['x'])
# y = int(request.form['y'])
json = request.get_json()
print(json)
ad = axidraw.AxiDraw() # Initialize class
ad.interactive() # Enter interactive context
ad.connect() # Open serial port to AxiDraw
ad.options.units = 2 # Millimeters
ad.options.pen_pos_up = 30
ad.options.pen_pos_down = 60
ad.update()
ad.moveto(0,0)
ad.moveto(json[0][0],json[0][1])
for point in json:
time.sleep(0.1)
ad.lineto(point[0],point[1])
print(point)
print("Finished")
ad.penup()
ad.moveto(0,0)
# ad.pendown()
ad.disconnect() # Close serial port to AxiDraw
return "YAY"