[visionegg] flow control problems

  • From: Mikko Vähäsöyrinki <mikko@xxxxxxxxxxx>
  • To: <visionegg@xxxxxxxxxxxxx>
  • Date: Mon, 7 Nov 2005 18:56:10 -0800

Hi,

 

I?ve been spending some time with the Vision Egg and Python, but I?m still
totally confused with the logic used. I?m using latest packages listed at
the Vision Egg website and my OS are Win2k/XP.

 

My goal would be to a make simple programs based on the simpleServer/Client
demos that would show the image at the server when the pin14 is on at the
clients serial port. What I have done so far is to add a class for
controlling that pin to the DaqLPT (see below), which should return true or
false depending on the state of the pin. I changed the base_address to point
to the control registers.

 

Now here?s my first confusion. What should I get with: x=LPTTrigPin14(),
print x? It prints the object reference and not the return values, which I
think is part of my problems. How do I get the actual return value that I
could put to a variable for later use?

 

I have a program that is basically put together from the Textures and
Trigger_in demos (see below). It does the trick and triggers a go loop when
the pin 14 goes high. I have tried to modify it further to show the picture
while the pin 14 is high. What is the proper way to use flow control in this
problem? My idea was to define go_duration to (?forever?,) when the pin is
high and to (0, ?frames?) when pin is low. I tried to make a function that
would call the LPTTrigPin14, check its state and do stuff at each state, and
put this function to the FunctionController. Then I would have a while loop
with run_forever, where program would stay until the pin is activated, while
activated it would start the go that would run until the pin is switched off
etc. Well obviously I couldn?t get it working so I?m wondering if my idea
was wrong.

 

All help would be highly appreciated.

Cheers,

Mikko

 

class LPTTrigPin14(VisionEgg.FlowControl.Controller):

    def __init__(self,lpt_device=None):

        if not 'raw_lpt_module' in globals().keys():

            raise RuntimeError("LPT input not supported on this platform.")

        VisionEgg.FlowControl.Controller.__init__(self,

                                           return_type=ve_types.Integer,

 
eval_frequency=VisionEgg.FlowControl.Controller.EVERY_FRAME)

        # Initialize DAQ stuff:

        self.trigger_in_channel = LPTChannel(signal_type =
VisionEgg.Daq.Digital(),

                                             daq_mode =
VisionEgg.Daq.Immediate(),

                                             functionality = LPTInput())

        if lpt_device is None:

            self.device = LPTDevice()

        else:

            if not isinstance(lpt_device,LPTDevice):

                raise ValueError("lpt_device must be instance of
LPTDevice.")

            self.device = lpt_device

        self.device.add_channel(self.trigger_in_channel)

        self.mask = 2

 

    def during_go_eval(self):

        value =
self.trigger_in_channel.constant_parameters.functionality.get_data()

        return (value & self.mask)

        

    def between_go_eval(self):

        value =
self.trigger_in_channel.constant_parameters.functionality.get_data()

        return (value & self.mask)

 

 

#!/usr/bin/env python

"""Load a texture from a file."""

 

import VisionEgg

VisionEgg.start_default_logging(); VisionEgg.watch_exceptions()

import os

from VisionEgg.Core import *

from VisionEgg.FlowControl import Presentation, ConstantController,
FunctionController

import VisionEgg.Daq

from VisionEgg.DaqLPT import *

from VisionEgg.Textures import *

import pygame

from pygame.locals import *

 

filename =
os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,"data","Glasses.jpg")

texture = Texture(filename)

 

screen = get_default_screen()

 

# Create the instance of TextureStimulus

stimulus = TextureStimulus(texture = texture,

                           position =
(screen.size[0]/2.0,screen.size[1]/2.0),

                           anchor = 'center',

                           shrink_texture_ok=1)

 

viewport = Viewport(screen=screen,

                    stimuli=[stimulus])

 

p = Presentation(go_duration=('forever',),

                 trigger_go_if_armed=0, # wait for trigger

                 viewports=[viewport])

 

# Stimulus on controller

stimulus_on_controller =
ConstantController(during_go_value=1,between_go_value=0)

 

# Create a trigger input controller

trigger_in_controller = LPTTrigPin14()

 

 

# Add the trigger output controller to the presentation's list of
controllers

p.add_controller(stimulus,'on',stimulus_on_controller)

p.add_controller(p,'trigger_go_if_armed',trigger_in_controller)

 

def quit(dummy_arg=None):

    p.parameters.go_duration = (0,'frames')

 

def keydown(event):

    if event.key == pygame.locals.K_ESCAPE:

        quit()

 

p.parameters.handle_event_callbacks=[(pygame.locals.QUIT, quit),

                                     (pygame.locals.KEYDOWN, keydown)]

p.go()

pygame.quit()

 

Other related posts: