()
Creates pygame window and graph drawing workers for each sensor.
Creates pygame window and graph drawing workers for each sensor.
Creates pygame window and graph drawing workers for each sensor .
def main():
    """
    Creates pygame window and graph drawing workers for each sensor.
    """
    global gheight
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    graphers = []
    recordings = []
    recording = False
    record_packets = []
    updated = False
    cursor_x, cursor_y = 400, 300
    fullscreen = False
    with Emotiv(display_output=False) as emotiv:
        for name in 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' '):
            graphers.append(Grapher(screen, name, len(graphers), emotiv.old_model))
        while emotiv.running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    emotiv.close()
                    return
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        emotiv.close()
                        return
                    elif event.key == pygame.K_f:
                        if fullscreen:
                            screen = pygame.display.set_mode((800, 600))
                            fullscreen = False
                        else:
                            screen = pygame.display.set_mode((800, 600), FULLSCREEN, 16)
                            fullscreen = True
                    elif event.key == pygame.K_r:
                        if not recording:
                            record_packets = []
                            recording = True
                        else:
                            recording = False
                            recordings.append(list(record_packets))
                            record_packets = None
            packets_in_queue = 0
            try:
                while packets_in_queue < 8:
                    packet = emotiv.dequeue()

                    if packet is not None:
                        if type(packet) != EmotivExtraPacket:
                            if abs(packet.sensors['X']['value']) > 1:
                                cursor_x = max(0, min(cursor_x, 800))
                                cursor_x -= packet.sensors['X']['value']
                            if abs(packet.sensors['Y']['value']) > 1:
                                cursor_y += packet.sensors['Y']['value']
                                cursor_y = max(0, min(cursor_y, 600))
                            map(lambda x: x.update(packet), graphers)
                            if recording:
                                record_packets.append(packet)
                            updated = True
                            packets_in_queue += 1
                    time.sleep(0.001)
            except Exception as ex:
                print("EmotivRender DequeuePlotError ", sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2],
                      " : ", ex)

            if updated:
                screen.fill((75, 75, 75))
                map(lambda x: x.draw(), graphers)
                pygame.draw.rect(screen, (255, 255, 255), (cursor_x - 5, cursor_y - 5, 10, 10), 0)
                pygame.display.flip()
                updated = False
def main ( ) : global gheight pygame . init ( ) screen = pygame . display . set_mode ( ( 800 , 600 ) ) graphers = [ ] recordings = [ ] recording = False record_packets = [ ] updated = False cursor_x , cursor_y = 400 , 300 fullscreen = False with Emotiv ( display_output = False ) as emotiv : for name in 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4' . split ( ' ' ) : graphers . append ( Grapher ( screen , name , len ( graphers ) , emotiv . old_model ) ) while emotiv . running : for event in pygame . event . get ( ) : if event . type == pygame . QUIT : emotiv . close ( ) return if event . type == pygame . KEYDOWN : if event . key == pygame . K_ESCAPE : emotiv . close ( ) return elif event . key == pygame . K_f : if fullscreen : screen = pygame . display . set_mode ( ( 800 , 600 ) ) fullscreen = False else : screen = pygame . display . set_mode ( ( 800 , 600 ) , FULLSCREEN , 16 ) fullscreen = True elif event . key == pygame . K_r : if not recording : record_packets = [ ] recording = True else : recording = False recordings . append ( list ( record_packets ) ) record_packets = None packets_in_queue = 0 try : while packets_in_queue < 8 : packet = emotiv . dequeue ( ) if packet is not None : if type ( packet ) != EmotivExtraPacket : if abs ( packet . sensors [ 'X' ] [ 'value' ] ) > 1 : cursor_x = max ( 0 , min ( cursor_x , 800 ) ) cursor_x -= packet . sensors [ 'X' ] [ 'value' ] if abs ( packet . sensors [ 'Y' ] [ 'value' ] ) > 1 : cursor_y += packet . sensors [ 'Y' ] [ 'value' ] cursor_y = max ( 0 , min ( cursor_y , 600 ) ) map ( lambda x : x . update ( packet ) , graphers ) if recording : record_packets . append ( packet ) updated = True packets_in_queue += 1 time . sleep ( 0.001 ) except Exception as ex : print ( "EmotivRender DequeuePlotError " , sys . exc_info ( ) [ 0 ] , sys . exc_info ( ) [ 1 ] , sys . exc_info ( ) [ 2 ] , " : " , ex ) if updated : screen . fill ( ( 75 , 75 , 75 ) ) map ( lambda x : x . draw ( ) , graphers ) pygame . draw . rect ( screen , ( 255 , 255 , 255 ) , ( cursor_x - 5 , cursor_y - 5 , 10 , 10 ) , 0 ) pygame . display . flip ( ) updated = False