#
# hello.mag.45.py
#
# receive and display magnetic field 
#    hello.mag.45.py serial_port
#
# Neil Gershenfeld 11/3/13
# (c) Massachusetts Institute of Technology 2013
#
# This work may be reproduced, modified, distributed,
# performed, and displayed for any purpose. Copyright is
# retained and must be preserved. The work is provided
# as is; no warranty is provided, and users accept all 
# liability.
#

from Tkinter import *
from single_node import virtualMachine
import time

WINDOW = 600 # window size



def idle(parent,canvas):
   canvas.update()
   parent.after_idle(idle,parent,canvas)

def demoMove():
	#stage.xNode.loadProgram('../../../086-005/086-005a.hex')
	#stage.xNode.setMotorCurrent(1)

	stage.xNode.setVelocityRequest(18)	

	#f = open('path.csv','r')
	#supercoords = []
	#for line in f.readlines():
	#	supernum = float(line)
	#	supercoords.append([supernum])
	supercoords = [[40],[20],[10],[0]]   
	#supercoords = [[6],[12],[18],[24],[30],[6],[12],[18],[24],[30]] 



	for coords in supercoords:
		stage.move(coords, 0)
		status = stage.xAxisNode.spinStatusRequest()
		while status['stepsRemaining'] > 0:
			time.sleep(0.01)
			status = stage.xAxisNode.spinStatusRequest()	


#
# set up GUI
#
root = Tk()
root.title('1337 machine interface (q to exit)')
root.bind('q','exit')
canvas = Canvas(root, width=WINDOW, height=.25*WINDOW, background='white')
canvas.create_text(.1*WINDOW,.125*WINDOW,text="Stirring!",font=("Helvetica", 24),tags="text",fill="#0000b0")
stirButton = Button(root, text ="LETS START STIRRING!", command = demoMove)
exitButton = Button(root, text ="Done!", command = exit)
canvas.pack()
stirButton.pack()
exitButton.pack()

stage = virtualMachine(persistenceFile = "test.vmp")
#
# start idle loop
#
root.after(100,idle,root,canvas)
root.mainloop()
