-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathble.kv
512 lines (452 loc) · 14.5 KB
/
ble.kv
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#:set color_x (1, 0, 0, 1)
#:set color_y (0, 1, 0, 1)
#:set color_z (0, 0, 1, 1)
#:set bgcolor (0/255., 23/255., 33/255., 1)
#:set red (1, 0, 0, 1)
#:set white (1, 1, 1, 1)
#:set line '48dp'
#:set small_line '32dp'
#:set larger_line '46dp'
#:import chain itertools.chain
#:import sp kivy.metrics.sp
#:import platform kivy.utils.platform
#:set twiz_address_width .30
#:set twiz_id_width .15
#:set twiz_power_width .15
#:set twiz_activate_width .15
#:set twiz_visu_width .15
#:set config_ip_width .2
#:set config_port_width .1
#:set config_address_width .2
#:set config_content_width .2
#:set config_delete_width .1
#:set config_sensor_width .1
#:set config_active_width .1
#:set config_event_type_width .3
#:set config_midi_channel_width .15
#:set config_event_id_width .15
#:set config_event_value_width .15
TabbedPanel:
canvas.before:
Color:
rgba: bgcolor
Rectangle:
pos: self.pos
size: self.size
do_default_tab: False
ScanPanel:
id: scan
DevicesPanel:
id: visu
Logs:
SettingsTab:
About:
<SettingsTab@TabbedPanelItem>:
text: 'Settings'
GridLayout:
cols: 2
Label:
text: 'automatically display discovered modules'
Switch:
active: app.auto_display
on_active: app.auto_display = self.active
Label:
text: 'automatically activate known modules when detected'
Switch:
active: app.auto_activate
on_active: app.auto_activate = self.active
Label:
text: 'use queue to smooth events on osx (adds a delay)'
Switch:
active: app.osx_queue_fix
on_active:
app.osx_queue_fix = self.active
disabled: platform != 'macosx'
Label:
text: 'hide devices after N seconds of inactivity (0 for never)'
Slider:
id: slider_timeout
step: 1
min: 0
max: 120
value: app.display_timeout
on_value: app.display_timeout = self.value
Label:
size: self.texture_size
center_x: slider_timeout.center_x
y: slider_timeout.y
text: '{}'.format(app.display_timeout or 'never')
Label:
text: 'use nexus 4/7 fix (android only)'
Switch:
active: app.nexus4_fix
on_active:
app.nexus4_fix = self.active
disabled: platform != 'android'
<About@TabbedPanelItem>:
text: 'About'
Image:
id: logo
source: 'data/Logo vertical.png'
<Logs@TabbedPanelItem>:
text: 'logs'
Label:
text: app.error_log
text_size: self.width, None
size_hint_y: None
height: self.texture_size[1]
<ScanPanel@TabbedPanelItem>:
text: 'scan'
BoxLayout:
orientation: 'vertical'
BoxLayout:
size_hint_y: None
height: small_line
Button:
text: 'auto refresh'
ConfigTextInput:
hint_text: 'device name filter'
text: app.device_filter
on_text: app.device_filter = self.text
GridLayout:
id: grid
cols: 1
size_hint_y: None
height: self.minimum_height
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_height
BoxLayout:
size_hint_y: None
height: line
Label:
text: 'id'
size_hint_x: twiz_id_width
Label:
text: 'power'
size_hint_x: twiz_power_width
Label:
text: 'send'
size_hint_x: twiz_activate_width
Label:
text: 'visu'
size_hint_x: twiz_visu_width
ScrollView:
size_hint_y: None
height: results.height
GridLayout:
id: results
size_hint_y: None
height: self.minimum_height
cols: 1
Widget:
<DevicesPanel@TabbedPanelItem>:
text: 'visu'
ScrollView:
GridLayout:
cols: 1
id: content
size_hint_y: None
height: self.minimum_height
<GraphZone>:
avgsize: 100
size_hint_y: None
height: self.minimum_height
cols: 1
GridLayout:
size_hint_y: None
height: self.minimum_height
rows: 1
pos_hint: {'center': (.5, .5)}
GridLayout:
size_hint: None, None
size: self.minimum_size
cols: 4
Label:
text: root.device.name if root.device else ''
text_size: self.width, None
font_size: 12
Label:
color: color_x
text: 'x'
size_hint: None, None
size: '48sp', '48sp'
Label:
color: color_y
text: 'y'
size_hint: None, None
size: self.texture_size
size: '48sp', '48sp'
Label:
color: color_z
text: 'z'
size_hint: None, None
size: self.texture_size
size: '48sp', '48sp'
ToggleButton:
text: 'euler'
group: 'grid-%s' % (root.device.name if root.device else '')
allow_no_selection: False
size_hint: None, None
size: self.texture_size
size: '48sp', '48sp'
on_press: root.focus = 'euler'
state: 'down' if root.focus == 'euler' else 'normal'
Label:
text: '%s' % round(sum(root.device.rx[-root.avgsize:])/root.avgsize * 360. / 0xffff, 2) if root.device else ''
Label:
text: '%s' % round(sum(root.device.ry[-root.avgsize:])/root.avgsize * 360. / 0xffff, 2) if root.device else ''
Label:
text: '%s' % round(sum(root.device.rz[-root.avgsize:])/root.avgsize * 360. / 0xffff, 2) if root.device else ''
ToggleButton:
text: 'accel'
group: 'grid-%s' % (root.device.name if root.device else '')
allow_no_selection: False
size_hint: None, None
size: self.texture_size
size: '48sp', '48sp'
on_press: root.focus = 'accelero'
state: 'down' if root.focus == 'accelero' else 'normal'
Label:
text: '%s' % round(sum(root.device.ax[-root.avgsize:])/root.avgsize * 4. / 0xffff, 2) if root.device else ''
Label:
text: '%s' % round(sum(root.device.ay[-root.avgsize:])/root.avgsize * 4. / 0xffff, 2) if root.device else ''
Label:
text: '%s' % round(sum(root.device.az[-root.avgsize:])/root.avgsize * 4. / 0xffff, 2) if root.device else ''
Graph:
device: root.device
focus: root.focus
<Graph>:
focus: ''
line_x: {'euler': root.device.rx, 'accelero': root.device.ax}[root.focus] if root.device else [0]
line_y: {'euler': root.device.ry, 'accelero': root.device.ay}[root.focus] if root.device else [0]
line_z: {'euler': root.device.rz, 'accelero': root.device.az}[root.focus] if root.device else [0]
data_len: max(map(len, (self.line_x, self.line_y, self.line_z)))
max_value: 0x7fff
min_value: -0x8000
canvas:
Color:
rgba: color_x
Line:
points:
list(chain(*[
(root.x + x * self.width / root.data_len,
self.y + self.height * (y - self.min_value) / (root.max_value - root.min_value))
for x, y in enumerate(root.line_x)
])) if root.data_len and root.max_value and root.line_x else ()
Color:
rgba: color_y
Line:
points:
list(chain(*[
(root.x + x * self.width / root.data_len,
self.y + self.height * (y - self.min_value) / (root.max_value - root.min_value))
for x, y in enumerate(root.line_y)
])) if root.data_len and root.max_value and root.line_y else ()
Color:
rgba: color_z
Line:
points:
list(chain(*[
(root.x + x * self.width / root.data_len,
self.y + self.height * (y - self.min_value) / (root.max_value - root.min_value))
for x, y in enumerate(root.line_z)
])) if root.data_len and root.max_value and root.line_z else ()
<ObjectView>:
size_hint_y: None
height: min(self.minimum_height, sp(300))
cols: 2
GridLayout:
cols: 1
size_hint_y: None
height: self.minimum_size[1]
GraphZone:
device: root.device
GridLayout:
cols: 1 if app.root.width < app.root.height else 2
id: grid
size_hint_y: None
height: max(self.minimum_height, 1)
GridLayout:
id: config
cols: 1
size_hint_y: None
size_hint_x: 1.6 if grid.cols == 2 else 1
height: self.minimum_height
OscConfig:
id: osconfig
device: root.device
height: self.minimum_height
View:
canvas.before:
Color:
rgba: 1, 1, 1, 1
scene: 'cube.obj'
display_all: True
obj_scale: 3.0
cam_rotation:
(
root.device.rx[-1] * 360. / 0xffff,
root.device.ry[-1] * 360. / 0xffff,
root.device.rz[-1] * 360. / 0xffff
)
cam_translation: 0, 0, -8
light_sources:
{
x: ([float(y) * 10 - 5 for y in bin(x)[2:].rjust(3, '0')] + [1.0])
for x in range(8)
}
<ConfigPanel>:
cols: 1
size_hint_y: None
height: self.minimum_height
<MidiConfig>:
GridLayout:
rows: 1
size_hint_y: None
height: line
Label:
text: 'sensor'
size_hint_x: config_sensor_width
Label:
text: 'active'
size_hint_x: config_active_width
Label:
text: 'event type'
size_hint_x: config_event_type_width
Label:
text: 'channel'
text_size: self.size
size_hint_x: config_midi_channel_width
Label:
text: 'event id'
size_hint_x: config_event_id_width
Label:
text: 'event value'
size_hint_x: config_event_value_width
GridLayout:
cols: 1
id: content
size_hint_y: None
height: self.minimum_height
<MidiSensorLine>:
size_hint_y: None
height: small_line
Label:
text: root.sensor
size_hint_x: None
width: config_sensor_width
CheckBox:
active: root.active
on_active: root.active = self.active
size_hint_x: None
width: config_active_width
Spinner:
text: root.signal
values: ('Note On', 'Note Off', 'Note Aftertouch', 'Controller')
on_text: root.signal = self.text
size_hint_x: None
width: config_event_type_width
Spinner:
text: root.chan
values: ('%s' % x for x in range(16))
on_text: root.chan = self.text
size_hint_x: None
width: config_midi_channel_width
hint_text: '0-127'
ConfigTextInput:
text: root.event_id
on_text_validate: root.event_id = self.text
size_hint_x: None
width: config_event_id_width
hint_text: '0-127 or v'
ConfigTextInput:
text: root.event_value
on_text_validate: root.event_value = self.text
size_hint_x: None
width: config_event_value_width
hint_text: '0-127 or v'
<OscConfig>:
GridLayout:
rows: 1
size_hint_y: None
height: '48sp'
Label:
text: 'ip'
size_hint_x: config_ip_width
Label:
text: 'port'
size_hint_x: config_port_width
Label:
text: 'address'
size_hint_x: config_address_width
Label:
text: 'content'
size_hint_x: config_content_width
Label:
text: 'delete'
size_hint_x: config_delete_width
GridLayout:
cols: 1
id: content
size_hint_y: None
height: self.minimum_height
Button:
text: '+'
size_hint_y: None
height: small_line
visible: len(content.children) < 6
opacity: 1 if self.visible else 0
disabled: not self.visible
on_press: root.add_line()
<OscConfigLine>:
size_hint_y: None
height: small_line
ConfigTextInput:
text: root.ip
on_text: root.ip = self.text
size_hint_x: config_ip_width
ConfigTextInput:
text: root.port
on_text: root.port = self.text
size_hint_x: config_port_width
background_color: white if self.text .isdigit() else red # don't remove the space!
ConfigTextInput:
text: root.address
on_text: root.address = self.text
size_hint_x: config_address_width
background_color: white if self.text .startswith('/') else red # don't remove the space!
Button:
text: root.content
on_text: root.content = self.text
size_hint_x: config_content_width
on_press: app.open_content_dropdown(self)
Button:
text: 'x'
on_press: root.config.remove_line(root)
size_hint_x: config_delete_width
<TwizDevice>:
size_hint_y: None
height: line
BoxLayout:
pos_hint: {'center': (.5, .5)}
Label:
text: root.name
size_hint_x: twiz_id_width
Label:
text: '%sdb' % root.power
size_hint_x: twiz_power_width
CheckBox:
active: root.active
on_active: root.active = self.active
size_hint_x: twiz_activate_width
CheckBox:
active: root.display
on_active: root.display = self.active
size_hint_x: twiz_visu_width
<ScrollView>:
scroll_timeout: 150
scroll_distance: 10
<ConfigTextInput@TextInput>:
multiline: False