Esempio n. 1
0
def main_phidget():
    import threading

    from zmq.utils.win32 import allow_interrupt
    from flyvr.common.build_arg_parser import build_argparser, parse_options

    parser = build_argparser()
    parser.add_argument(
        "--debug_led",
        type=int,
        help="flash this LED upon IPC messages (should not be 3,4,5)",
        default=None)

    options = parse_options(parser.parse_args(), parser)

    # silly little dance to make ZMQ blocking read ctrl-c killable by running the entire
    # thing in a thread and waiting on an event instead

    quit_evt = threading.Event()

    def ctrlc(*args):
        quit_evt.set()

    t = threading.Thread(target=run_phidget_io, args=(options, ), daemon=True)
    t.start()

    with allow_interrupt(action=ctrlc):
        try:
            quit_evt.wait()
        except KeyboardInterrupt:
            pass
Esempio n. 2
0
def main_sound_server():
    import yaml
    import os.path

    from flyvr.common.build_arg_parser import build_argparser, parse_options
    from flyvr.audio.util import plot_playlist
    from zmq.utils.win32 import allow_interrupt

    parser = build_argparser()
    parser.add_argument('--print-devices',
                        action='store_true',
                        help='print available audio devices')
    parser.add_argument('--convert-playlist',
                        help='convert a stimulus playlist to new format')
    parser.add_argument('--paused', action='store_true', help='start paused')
    parser.add_argument('--plot',
                        action='store_true',
                        help='plot the stimulus playlist')

    options = parse_options(parser.parse_args(), parser)

    if options.plot:
        setup_logging(options)

        if not options.playlist.get('audio'):
            return parser.error('Config file contains no audio playlist')

        plot_playlist(options, 'audio')

        return parser.exit(0)

    if options.convert_playlist:
        src = options.convert_playlist
        if os.path.isfile(src):
            pl = AudioStimPlaylist.from_legacy_filename(src)
            dest = options.convert_playlist + '.yml'
            with open(dest, 'wt') as f:
                yaml.dump({'playlist': {'audio': pl.describe()}}, f)

            return parser.exit(0, message='Wrote %s' % dest)

        else:
            return parser.error('Could not find %s' % src)

    if options.print_devices:
        SoundServer.list_supported_asio_output_devices()
        return parser.exit(0)

    quit_evt = threading.Event()

    # noinspection PyUnusedLocal
    def ctrlc(*args):
        quit_evt.set()

    with allow_interrupt(action=ctrlc):
        run_sound_server(options, quit_evt)
Esempio n. 3
0
def main_video_server():
    from flyvr.common.build_arg_parser import build_argparser, parse_options

    parser = build_argparser()
    parser.add_argument('--play-item', help='Play this item from the playlist',
                        metavar='IDENTIFIER')
    parser.add_argument('--play-stimulus', help='Play this stimulus only (no playlist is loaded). '
                                                'useful for testing',
                        choices=[c.NAME for c in STIMS])
    parser.add_argument('--paused', action='store_true', help='start paused')
    options = parse_options(parser.parse_args(), parser)

    run_video_server(options)
Esempio n. 4
0
def main_io():
    from flyvr.common.build_arg_parser import build_argparser, parse_options, setup_logging
    from flyvr.audio.util import plot_playlist

    parser = build_argparser()
    parser.add_argument('--plot',
                        action='store_true',
                        help='plot the stimulus playlist')
    options = parse_options(parser.parse_args(), parser)

    if options.plot:
        setup_logging(options)

        if not options.playlist.get('daq'):
            return parser.error('Config file contains no daq playlist')

        plot_playlist(options, 'daq')

        return parser.exit(0)

    run_io(options)
Esempio n. 5
0
def main_experiment():
    from flyvr.common.build_arg_parser import build_argparser, parse_options, setup_experiment, setup_logging

    parser = build_argparser()
    parser.add_argument(
        '--force',
        action='store_true',
        help='force/fake iterate at 200fps even if no tracking data '
        'is present (for testing)')

    options = parse_options(parser.parse_args(), parser)
    setup_logging(options)

    setup_experiment(options)
    if not options.experiment:
        parser.error("No experiment specified")

    # noinspection PyProtectedMember
    options.experiment._set_shared_state(
        SharedState(options=options, logger=None))

    # noinspection PyProtectedMember
    options.experiment._log_describe()
    do_loop(options.experiment, 1 / 200., options.force)