# Adrian Steinemann
# 29. Maerz 2009
# Blenderuebung.py
# Version 0.01
# Client Software to interoperate with ARDUINO Boards
# ---------------------------------------------------
import serial, sys, math

cont=GameLogic.getCurrentController()
own=cont.getOwner()

serialport='COM3'
baudrate=9600

def connection():
    try:
        GameLogic.ser=serial.Serial(serialport, baudrate)
        GameLogic.connected=1
        print 'connection established...'
               
    except:
        print 'connection failed...'

if hasattr(GameLogic, 'connected')==False:
    connection()

if hasattr(GameLogic, 'connected')==True and GameLogic.connected==1:
    GameLogic.data=GameLogic.ser.readline()
    GameLogic.Winkel=float(GameLogic.data)
    GameLogic.angle=((GameLogic.Winkel/1023.0)*3.1415)
    GameLogic.vect_angle=[0,math.cos(GameLogic.angle),math.sin(GameLogic.angle)]
    GameLogic.zAxis=2
    own.alignAxisToVect(GameLogic.vect_angle,GameLogic.zAxis)
else:
    print 'no connection available...'
    connection()
