Exemplo n.º 1
0
                        help='number of video frames per stimulus bit',
                        default=1)
    parser.add_argument('--fullscreen',
                        action='store_true',
                        help='run in fullscreen mode')
    #parser.add_option('-m','--matrix',action='store',dest='symbols',help='file with the set of symbols to display',default=None)
    args = parser.parse_args()

    nCal = args.ncal
    nPred = args.npred
    stimFile = args.stimfile
    framesperbit = args.framesperbit
    fullscreen = args.fullscreen

    # N.B. init the noise-tag first, so asks for the IP
    nt = Noisetag(stimFile=stimFile)
    if args.host is not None:
        nt.connect(args.host, queryifhostnotfound=False)

    # init the graphics system
    initPyglet(fullscreen=fullscreen)

    # the logical arrangement of the display matrix
    symbols = [['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j'],
               ['k', 'l', 'm', 'n', 'o'], ['p', 'q', 'r', 's', 't'],
               ['u', 'v', 'w', 'x', 'y']]
    # make the screen manager object which manages the app state
    ss = ExptScreenManager(window,
                           nt,
                           symbols,
                           nCal=nCal,
Exemplo n.º 2
0
        segidx = window.objIDs.index(objID)
        seg    = window.segements[segidx]
        # set the light to this color, by matching the hue.
        if hue_bridge : 
            try : 
                lights=hue_bridge.lights()
                for k,v in lights.items():
                    if v['state']['reachable'] :
                        hue_bridge.lights[k]('state',bri=128,hue=int(65535*seg.theta/(2*math.pi)))
            except :
                print("couldnt talk to the hue!") 


if __name__=='__main__':
    # N.B. init the noisetag first so asks for decoder IP
    noisetag=Noisetag()
    # auto connect to the decoder
    noisetag.connect()

    config = pyglet.gl.Config(double_buffer=True)
    window = DrawWindow(noisetag,width=1024,height=768,vsync=True,config=config)
    window.init_pie(nsegements=10)

    # set the current noise-tagging state
    noisetag.setActiveObjIDs(window.objIDs)
    noisetag.startExpt(nCal=10,nPred=20,
                       cueduration=2,calduration=4,predduration=20,
                       feedbackduration=4)

    # Initialize the connection to the hue light
    try :
Exemplo n.º 3
0
import types


def timedflip(self):
    '''pseudo method type which records the timestamp for window flips'''
    type(self).flip(self)  # call the 'real' flip method...
    self.lastfliptime = nt.getTimeStamp()


# define a trival selection handler
def selectionHandler(objID):
    print("Selected: %d" % (objID))


# Initialize the noise-tagging connection
nt = Noisetag()
nt.connect(timeout_ms=5000)
nt.addSelectionHandler(selectionHandler)
# tell the noisetag framework to run a full : calibrate->prediction sequence
nt.setnumActiveObjIDs(2)
nt.startExpt(nCal=2, nPred=10, duration=4)

# Initialize the drawing window
# make a default window, with fixed size for simplicty, and vsync for timing
config = pyglet.gl.Config(double_buffer=True)
window = pyglet.window.Window(width=640, height=480, vsync=True, config=config)

# Setup the flip-time recording for this window
window.flip = types.MethodType(timedflip, window)
window.lastfliptime = None
                lights = hue_bridge.lights()
                for k, v in lights.items():
                    if v['state']['reachable']:
                        hue_bridge.lights[k]('state',
                                             bri=128,
                                             hue=int(65535 * seg.theta /
                                                     (2 * math.pi)))
            except:
                print("couldnt talk to the hue!")


if __name__ == '__main__':
    #config = pyglet.gl.Config(double_buffer=True)
    window = DrawWindow()  #vsync=True,config=config)
    window.init_pie(nsegements=10)
    noisetag = Noisetag()
    noisetag.startExpt(window.objIDs,
                       nCal=1,
                       nPred=100,
                       cueduration=4,
                       duration=10,
                       feedbackduration=4)
    window.setNoisetag(noisetag)

    # Initialize the connection to the hue light
    from qhue import Bridge
    bridgeip = "192.168.253.100"
    username = "******"
    hue_bridge = Bridge(bridgeip, username)
    # register selection handler
    noisetag.addSelectionHandler(selectionHandler)
Exemplo n.º 5
0
from mindaffectBCI.noisetag import Noisetag
nt = Noisetag()

import pyglet
# make a default window, with fixed size for simplicty
window = pyglet.window.Window(width=640, height=480)


# define a simple 2-squares drawing function
def draw_squares(col1, col2):
    # draw square 1: @100,190 , width=100, height=100
    x = 100
    y = 190
    w = 100
    h = 100
    pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
                         ('v2f', (x, y, x + w, y, x + w, y + h, x, y + h)),
                         ('c3f', (col1) * 4))
    # draw square 2: @440,100
    x = 640 - 100 - 100
    pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
                         ('v2f', (x, y, x + w, y, x + w, y + h, x, y + h)),
                         ('c3f', (col2) * 4))


# dictionary mapping from stimulus-state to colors
state2color = {
    0: (.2, .2, .2),  # off=grey
    1: (1, 1, 1),  # on=white
    2: (0, 1, 0),  # cue=green
    3: (0, 0, 1)
Exemplo n.º 6
0
    def setup_noisetag(self):
        """Sets up a Noisetag object to communicate with the Utopia server."""
        noisetag = Noisetag(stimFile=self.user_config.get('stimfile', None),
                            clientid='smart_keyboard')

        return noisetag
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mindaffectBCI.noisetag import Noisetag, sumstats
nt = Noisetag()
nt.connect(timeout_ms=5000)

import pyglet
# make a default window, with fixed size for simplicty
window = pyglet.window.Window(width=640, height=480)


# define a simple 2-squares drawing function
def draw_squares(col1, col2):
    # draw square 1: @100,190 , width=100, height=100
    x = 100
    y = 190
    w = 100
    h = 100
    pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,
Exemplo n.º 8
0
    last_key_press = symbols


def on_text(text):
    global last_text
    last_text = text


if __name__ == "__main__":
    import sys
    argv = sys.argv
    nCal = int(argv[1]) if len(argv) > 1 else 10
    nPred = int(argv[2]) if len(argv) > 2 else 10

    # N.B. init the noise-tag first, so asks for the IP
    nt = Noisetag()

    # init the graphics system
    initPyglet()

    # the logical arrangement of the display matrix
    symbols = [['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j'],
               ['k', 'l', 'm', 'n', 'o'], ['p', 'q', 'r', 's', 't'],
               ['u', 'v', 'w', 'x', 'y']]
    # make the screen manager object which manages the app state
    ss = ExptScreenManager(window, nt, symbols, nCal=nCal, nPred=nPred)

    # set per-frame callback to the draw function
    if drawrate > 0:
        # slow down for debugging
        pyglet.clock.schedule_interval(draw, drawrate)
Exemplo n.º 9
0

if __name__ == "__main__":
    # init the graphics system
    initPyglet()
    nframe = 0
    # the logical arrangement of the display matrix
    symbols = [['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j'],
               ['k', 'l', 'm', 'n', 'o'], ['p', 'q', 'r', 's', 't'],
               ['u', 'v', 'w', 'x', 'y']]
    nsymb = sum([len(x) for x in symbols])
    # N.B. objIDs must be unique and >0 and <255
    objIDs = list(range(1, nsymb + 1))

    # make the calibration screen
    calnoisetag = Noisetag()
    calnoisetag.startCalibration(objIDs, nTrials=1, numframes=4 / isi)
    calibrationScreen = SelectionGridScreen(window, symbols, calnoisetag)
    # make the prediction screen - different noise-tag mode.
    prednoisetag = Noisetag()
    prednoisetag.startPrediction(objIDs, nTrials=10, numframes=10 / isi)
    predictionScreen = SelectionGridScreen(window, symbols, prednoisetag)
    print(prednoisetag)

    # make a screen stack to show the sequence of screens:
    #   instruct, calibration, instruct, prediction, instruct
    ss = ScreenStack(window)
    # N.B. use pushback so order is order of execution
    ss.pushback(
        InstructionScreen(window,
                          "Welcome Instruction\n\nkey to continue",