コード例 #1
0
ファイル: pulse.py プロジェクト: axc494/smile
    def _callback(self):
        # we've started
        self._started = True

        # send the code
        global have_parallel
        if have_parallel:
            # send the port code and time it
            try:
                # Create a parallel port object (locks it exclusively)
                self._pport = parallel.Parallel(port=self._port)

                start_time = clock.now()
                self._pport.setData(self._code_num)
                end_time = clock.now()
            except:  # eventually figure out which errors to catch
                sys.stderr.write("\nWARNING: The parallel module could not send pulses,\n" + 
                                 "\tso no sync pulsing will be generated.\n\n")
                have_parallel = False
                self._pport = None
                self._pulse_on = None
                self._pulse_off = None
                self._ended = True
                clock.schedule(self.leave)
                clock.schedule(self.finalize)
                return

            # set the pulse time
            time_err = (end_time - start_time)/2.
            self._pulse_on = event_time(start_time+time_err,
                                        time_err)

            # schedule leaving (as soon as this method is done)
            clock.schedule(self.leave)

            # schedule the off time
            if self._width > 0.0:
                # we're gonna turn off ourselves
                clock.schedule(self._pulse_off_callback,
                               event_time=self._pulse_on['time']+self._width)
            else:
                # we're gonna leave it
                self._pulse_off = None

                # clean up/ close the port
                self._pport = None

                # so we can finalize now, too
                clock.schedule(self.finalize)
                self._ended = True

        else:
            # we can leave and finalize now
            self._pulse_on = None
            self._pulse_off = None
            self._ended = True
            clock.schedule(self.leave)
            clock.schedule(self.finalize)
コード例 #2
0
ファイル: pulse.py プロジェクト: chadillac2313/smile
    def _pulse_off_callback(self, dt):
        # turn off the code
        start_time = now()
        self._pport.setData(0)
        end_time = now()

        # clean up / close the port
        self._pport = None

        # set the pulse time
        time_err = (end_time - start_time) / 2.
        self.pulse_end_time = event_time(start_time + time_err, time_err)
コード例 #3
0
ファイル: pulse.py プロジェクト: mjgilles/smile
    def _pulse_off_callback(self, dt):
        # turn off the code
        start_time = now()
        self._pport.setData(0)
        end_time = now()

        # clean up / close the port
        self._pport = None

        # set the pulse time
        time_err = (end_time - start_time)/2.
        self.pulse_end_time = event_time(start_time+time_err,
                                         time_err)
コード例 #4
0
    def blocking_flip(self):
        # TODO: use sync events instead!
        EventLoop.window.dispatch('on_flip')

        # draw a transparent point
        glVertexAttribPointer(0, 2, GL_INT, GL_FALSE, 0,
                              "\x00\x00\x00\x0a\x00\x00\x00\x0a")  # Position
        glVertexAttrib4f(3, 0.0, 0.0, 0.0, 0.0)  # Color
        glDrawArrays(GL_POINTS, 0, 1)

        # wait for flip and point to draw
        glFinish()

        # record the time immediately
        self.last_flip = event_time(clock.now(), 0.0)
        return self.last_flip
コード例 #5
0
ファイル: pulse.py プロジェクト: axc494/smile
    def _pulse_off_callback(self):
        # turn off the code
        start_time = clock.now()
        self._pport.setData(0)
        end_time = clock.now()

        # clean up / close the port
        self._pport = None

        # set the pulse time
        time_err = (end_time - start_time)/2.
        self._pulse_off = event_time(start_time+time_err,
                                     time_err)

        # let's schedule finalizing
        self._ended = True
        clock.schedule(self.finalize)
コード例 #6
0
ファイル: pulse.py プロジェクト: stahl191/smile
    def _pulse_off_callback(self):
        # turn off the code
        if self._sync_style == "parallel":
            start_time = clock.now()
            self._sport.setData(0)
            end_time = clock.now()
        else:
            start_time = clock.now()
            self._sport.setData("0")
            end_time = clock.now()
        # clean up / close the port
        self._sport = None

        # set the pulse time
        time_err = (end_time - start_time) / 2.
        self._pulse_off = event_time(start_time + time_err, time_err)

        # let's schedule finalizing
        self._ended = True
        clock.schedule(self.finalize)
コード例 #7
0
ファイル: pulse.py プロジェクト: mjgilles/smile
    def _callback(self, dt):        
        # Convert code if necessary
        code = val(self.pulse_code)
        if type(code)==str:
            if code[0]=="S":
                # Use first 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
            elif code[0]=="R":
                # Use last 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
                ncode = ncode >> 4
            else:
                # Convert to an integer
                ncode = int(code)
        else:
            ncode = int(code)

        # send the code
        if have_parallel:
            # Create a parallel port object (locks it exclusively)
            self._pport = parallel.Parallel(port=self.pulse_port)

            # send the port code and time it
            start_time = now()
            self._pport.setData(ncode)
            end_time = now()

            # set the pulse time
            time_err = (end_time - start_time)/2.
            self.pulse_time = event_time(start_time+time_err,
                                         time_err)

            # schedule the off time
            clock.schedule_once(self._pulse_off_callback, val(self.pulse_duration))
コード例 #8
0
ファイル: pulse.py プロジェクト: chadillac2313/smile
    def _callback(self, dt):
        # Convert code if necessary
        code = val(self.pulse_code)
        if type(code) == str:
            if code[0] == "S":
                # Use first 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
            elif code[0] == "R":
                # Use last 4 bits
                ncode = int(code[1:])
                if ncode < 0 or ncode > 16: ncode = 15
                ncode = ncode >> 4
            else:
                # Convert to an integer
                ncode = int(code)
        else:
            ncode = int(code)

        # send the code
        if have_parallel:
            # Create a parallel port object (locks it exclusively)
            self._pport = parallel.Parallel(port=self.pulse_port)

            # send the port code and time it
            start_time = now()
            self._pport.setData(ncode)
            end_time = now()

            # set the pulse time
            time_err = (end_time - start_time) / 2.
            self.pulse_time = event_time(start_time + time_err, time_err)

            # schedule the off time
            clock.schedule_once(self._pulse_off_callback,
                                val(self.pulse_duration))
コード例 #9
0
ファイル: pulse.py プロジェクト: stahl191/smile
    def _callback(self):
        # we've started
        self._started = True
        # Pull in the global variables
        global PI
        global SI
        if PI or SI:
            # send the port code and time it
            try:
                if self._sync_style == "parallel":
                    # Create a parallel port object
                    # from the global variable (locks it exclusively)
                    self._sport = PI(address=self._port)
                    start_time = clock.now()
                    self._sport.setData(self._code_num)
                    end_time = clock.now()
                elif self._sync_style == "serial":
                    self._sport = SI(address=self._port)
                    start_time = clock.now()
                    self._sport.setData(self._code_num)
                    end_time = clock.now()
            except:  # eventually figure out which errors to catch
                sys.stderr.write(
                    "\nWARNING: The sync module could not send pulses,\n" +
                    "\tso no sync pulsing will be generated.\n\n")
                PI = None
                self._pport = None
                self._pulse_on = None
                self._pulse_off = None
                self._ended = True
                clock.schedule(self.leave)
                clock.schedule(self.finalize)
                return

            # set the pulse time
            time_err = (end_time - start_time) / 2.
            self._pulse_on = event_time(start_time + time_err, time_err)

            # schedule leaving (as soon as this method is done)
            clock.schedule(self.leave)

            # schedule the off time
            if self._width > 0.0:
                # we're gonna turn off ourselves
                clock.schedule(self._pulse_off_callback,
                               event_time=self._pulse_on['time'] + self._width)
            else:
                # we're gonna leave it
                self._pulse_off = None

                # clean up/ close the port
                self._sport = None

                # so we can finalize now, too
                clock.schedule(self.finalize)
                self._ended = True

        else:
            # we can leave and finalize now
            self._pulse_on = None
            self._pulse_off = None
            self._ended = True
            clock.schedule(self.leave)
            clock.schedule(self.finalize)
コード例 #10
0
    def _idle_callback(self, event_loop):
        # record the time range
        self._new_time = clock.now()
        time_err = (self._new_time - self._last_time) / 2.0
        self.event_time = event_time(self._last_time + time_err, time_err)

        # call any of our scheduled events that are ready
        clock.tick()

        # see if we're ready for video
        ready_for_video = ((self._new_time - self.last_flip["time"]) >=
                           (self.flip_interval - FLIP_TIME_MARGIN))

        # see if the kivy clock needs a tick
        # throttled by flip interval
        ready_for_kivy_tick = ready_for_video and (
            self._new_time - self._last_kivy_tick >= self.flip_interval)

        # prepare for every video to be drawn on the next flip
        need_draw = False
        for video in self.video_queue:
            if (not video.drawn
                    and ((self.pending_flip_time is None and self._new_time >=
                          (video.flip_time - (self.flip_interval / 2.0)))
                         or video.flip_time == self.pending_flip_time)):
                # prepare that video change
                video.update_cb()
                need_draw = True
                video.drawn = True

                # save the pending time so all other changes
                # for that time will also run
                self.pending_flip_time = video.flip_time
            else:
                # either none are ready or the remaining are
                # for a subsequent flip
                break

        # do a kivy tick if we're going to be drawing or enough time
        # has passed (see above)
        # but only tick and draw once before a flip
        do_kivy_tick = ready_for_kivy_tick or need_draw
        if do_kivy_tick:
            # tick the kivy clock
            _kivy_clock.tick()
            self._last_kivy_tick = self._new_time

        # dispatch input events
        event_loop.dispatch_input()

        # process the builder and check for kivy draws
        if do_kivy_tick:
            Builder.sync()
            _kivy_clock.tick_draw()
            Builder.sync()
            kivy_needs_draw = EventLoop.window.canvas.needs_redraw or need_draw
            # print (_kivy_clock.get_fps(),
            # _kivy_clock.get_rfps(), self._new_time)
        else:
            kivy_needs_draw = False

        # dispatch draw if necessary
        if kivy_needs_draw:
            EventLoop.window.dispatch('on_draw')

        # handle video and flips
        if ready_for_video:
            # we need flip if kivy needs one
            need_flip = kivy_needs_draw and self.pending_flip_time is None
            flip_time_callbacks = []
            for video in self.video_queue:
                if video.drawn and video.flip_time == self.pending_flip_time:
                    # a smile video change is ready, so we need flip
                    need_flip = True

                    # append the flip time callback
                    if video.flip_time_cb is not None:
                        flip_time_callbacks.append(video.flip_time_cb)

                    # mark that video as flipped (it's gonna be)
                    video.flipped = True
                else:
                    # no more of the videos could match, so break
                    break

            # remove any video change that's gonna be flipped
            while len(self.video_queue) and self.video_queue[0].flipped:
                del self.video_queue[0]

            # do flip if necessary
            if need_flip:
                # test if blocking or non-blocking flip
                # do a blocking if:
                # 1) Forcing a blocking flip_interval
                #   OR
                # 2) We have a specific flip callback request and we
                #      are not forcing a non-blocking flip
                if self.force_blocking_flip or \
                   (len(flip_time_callbacks) and
                    not self.force_nonblocking_flip):
                    # print "BLOCKING FLIP!"
                    self.blocking_flip()
                else:
                    # non-blocking flip
                    # print "FLIP!"
                    EventLoop.window.dispatch('on_flip')
                    self.last_flip = event_time(clock.now(), 0.0)

                # still may need to update flip_time_callbacks
                # even though they may be wrong for non-blocking flips
                for cb in flip_time_callbacks:
                    cb(self.last_flip)

                # tell refs that last_flip updated
                self.exp._screen._set_last_flip(self.last_flip)

                # no longer pending flip
                self.pending_flip_time = None

        # save the time
        self._last_time = self._new_time

        # exit if experiment done
        if not self.exp._root_executor._active:
            if self.exp._root_executor._enter_time:
                # stop if we're not active, but we have an enter time
                self.stop()

        # give time to other threads
        clock.usleep(IDLE_USLEEP)
コード例 #11
0
ファイル: audio.py プロジェクト: chadillac2313/smile
 def _callback(self, dt):
     # play the sound
     self._snd.out()
     self.sound_start = event_time(now())
コード例 #12
0
ファイル: audio.py プロジェクト: chadillac2313/smile
 def _callback(self, dt):
     self._fader.play()
     self.sound_start = event_time(now())
コード例 #13
0
ファイル: audio.py プロジェクト: eweich/smile
 def _callback(self, dt):
     # play the sound
     self._snd.out()
     self.sound_start = event_time(now())
コード例 #14
0
ファイル: audio.py プロジェクト: eweich/smile
 def _callback(self, dt):
     self._fader.play()
     self.sound_start = event_time(now())
コード例 #15
0
ファイル: audio.py プロジェクト: neurodebian/smile
 def _callback(self, dt):
     self._rec = pyo.Record(
         pyo.Input(), filename=self.filepath, chnls=2, fileformat=0,
         sampletype=1, buffering=16)
     self.rec_start = event_time(now())
     pyo.Clean_objects(self.duration, self._rec).start()