-
Notifications
You must be signed in to change notification settings - Fork 5
/
mptest.py
82 lines (57 loc) · 1.38 KB
/
mptest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# # # # #
# CONSTANTS
DUMMY = False
RES = (640,480)
# # # # #
# IMPORTS
# external
import pygame
# custom
if not DUMMY:
from libmpdev import MP150
# # # # #
# STARTUP
# initialize PyGame
pygame.init()
# create a new display
disp = pygame.display.set_mode(RES, pygame.RESIZABLE)
# font to display text
font = pygame.font.Font(pygame.font.get_default_font(), 24)
# start communication with the squeezies
if not DUMMY:
mp = MP150()
# # # # #
# RUN
# run until quited
quited = False
while not quited:
# start recording
if not DUMMY:
mp.start_recording()
# get new squeezie sample
if not DUMMY:
sample = mp.sample()
else:
sample = 'dummymode'
# render text
textsurf = font.render("sample = %.3f, %.3f, %.3f" % (sample[0], sample[1], sample[2]), False, (255,255,255))
blitpos = (int(RES[0]/2 - textsurf.get_width()/2), int(RES[1]/2 - textsurf.get_height()/2))
# blit text to display
disp.fill((0,0,0))
disp.blit(textsurf, blitpos)
# update display
pygame.display.flip()
# check if there was any keyboard input
for event in pygame.event.get(pygame.KEYDOWN):
if pygame.key.name(event.key) == 'escape':
quited = True
# start recording
if not DUMMY:
mp.stop_recording()
# # # # #
# CLOSE
# close connection to MP150
if not DUMMY:
mp.close()
# close the display
pygame.display.quit()