Exemplo n.º 1
0
def run(profName=""):
    global settings
    global profile
    global inputFaker
    global bciDevice
    global current
    global keycodelistlabels
    global niaDirectFeedbackApp
    inputFaker = OutputManager.InputFaker()
    if inputFaker == -1:
        print "Import-Error: You need either Win32con (Windows) or XLib (Linux, Mac)"
    else:
        keycodelistlabels = sorted(
            ["Action: " + each for each in inputFaker.actions.keys()])
        profile = ProfileSettings()

        if (profName == ""):
            if len(sys.argv) == 2:
                profilefile = sys.argv[1]
                if os.path.exists(profilefile + ".feedback"):
                    workfile = open(profilefile + ".feedback", "r")
                    profile = pickle.load(workfile)
                    workfile.close()
                else:
                    print "no " + profilefile + ".feedback" + " file found"
                    selection = WXElements.selection(
                        "Select your Device",
                        InputManager.SupportedDevices.keys()[0],
                        InputManager.SupportedDevices.keys())
                    profile.deviceName = selection
            else:
                selection = WXElements.selection(
                    "Select your Device",
                    InputManager.SupportedDevices.keys()[0],
                    InputManager.SupportedDevices.keys())
                profile.deviceName = selection
        else:
            profilefile = profName
            if os.path.exists(profilefile + ".feedback"):
                workfile = open(profilefile + ".feedback", "r")
                profile = pickle.load(workfile)
                workfile.close()
            else:
                profile.profileName = profilefile
        bciDevice = InputManager.BCIDevice(profile.deviceName)
        current = Current_Data()
        niaDirectFeedbackApp = NiaDirectFeedbackApp()
        niaDirectFeedbackApp.MainLoop()
        bciDevice.quit()
Exemplo n.º 2
0
def run(profName=""):
    global profile
    global inputFaker
    global bciDevice
    global keycodelistlabels
    global current
    global fannToOutputApp
    global ann
    inputFaker = OutputManager.InputFaker()
    if inputFaker == -1:
        print "Import-Error: You need either Win32con (Windows) or XLib (Linux, Mac)"
    else:
        profilefile = "" 
        keycodelistlabels = sorted(["Action: "+each for each in inputFaker.actions.keys()])
        if (profName==""):
            if len(sys.argv)<2:
                path = os.getcwd()
                fileList = os.listdir(path)
                profileList = []
                for fileName in fileList:
                    if fileName[-7:] == "profile":
                        profileList.append(fileName[:-8])
                if len(profileList) > 0:
                    profilefile = str(WXElements.selection("Select your Profile",profileList[0], profileList))
                else:
                    print "Error: no profiles found"
            else:
                profilefile = sys.argv[1]
    
            if len(profilefile)==0:
                print "Error: no profile name given.\nExample: python nia-Triathlon-Player.py myProfile"
            else:
                if len(profilefile)==0:
                    profilefile = sys.argv[1] 
                profileLoaded = False
                netLoaded = False
                if os.path.exists(profilefile+".profile"):
                    workfile = open(profilefile+".profile", "r")
                    profile = pickle.load(workfile)
                    workfile.close()
                    profileLoaded = True
                else:
                    print "no "+profilefile+".profile"+" file found"
                ann = libfann.neural_net()
                if os.path.exists(profilefile+".net"):
                    ann.create_from_file(profilefile+".net")
                    netLoaded = True
                else:
                    print "no "+profilefile+".net"+" file found"
                if (profileLoaded and netLoaded):
                    bciDevice =  InputManager.BCIDevice(profile.deviceName)
                    current = Current_Data()
                    fannToOutputApp = FannToOutputApp()
                    fannToOutputApp.MainLoop()
                    bciDevice.quit()
                else:
                    print "Cannot start without .profile and .net files"
        else:
            profilefile=profName
            workfile = open(profilefile+".profile", "r")
            profile = pickle.load(workfile)
            workfile.close()
            ann = libfann.neural_net()
            ann.create_from_file(profilefile+".net")
            bciDevice =  InputManager.BCIDevice(profile.deviceName)
            current = Current_Data()
            fannToOutputApp = FannToOutputApp()
            fannToOutputApp.MainLoop()
            bciDevice.quit()