21
21
import android .os .ParcelUuid ;
22
22
import android .support .annotation .NonNull ;
23
23
import android .support .annotation .Nullable ;
24
- import android .text .TextUtils ;
25
24
import android .util .Log ;
26
25
27
26
import java .nio .charset .StandardCharsets ;
@@ -87,6 +86,7 @@ public final class BleMidiPeripheralProvider {
87
86
88
87
private OnMidiDeviceAttachedListener midiDeviceAttachedListener ;
89
88
private OnMidiDeviceDetachedListener midiDeviceDetachedListener ;
89
+ private boolean autoStartDevice = true ;
90
90
91
91
private String manufacturer = "kshoji.jp" ;
92
92
private String deviceName = "BLE MIDI" ;
@@ -359,7 +359,7 @@ public void onConnectionStateChange(BluetoothDevice device, int status, int newS
359
359
if (midiInputDevice != null ) {
360
360
midiInputDevicesMap .remove (deviceAddress );
361
361
362
- (( InternalMidiInputDevice ) midiInputDevice ). stop ();
362
+ midiInputDevice . terminate ();
363
363
midiInputDevice .setOnMidiInputEventListener (null );
364
364
if (midiDeviceDetachedListener != null ) {
365
365
midiDeviceDetachedListener .onMidiInputDeviceDetached (midiInputDevice );
@@ -397,10 +397,12 @@ public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, i
397
397
} else {
398
398
switch (BleUuidUtils .toShortValue (characteristicUuid )) {
399
399
case MODEL_NUMBER :
400
- gattServer .sendResponse (device , requestId , BluetoothGatt .GATT_SUCCESS , 0 , deviceName .getBytes (StandardCharsets .UTF_8 ));
400
+ // the running device's MODEL
401
+ gattServer .sendResponse (device , requestId , BluetoothGatt .GATT_SUCCESS , 0 , Build .MODEL .substring (0 , Math .min (Build .MODEL .length (), 20 )).getBytes (StandardCharsets .UTF_8 ));
401
402
break ;
402
403
case MANUFACTURER_NAME :
403
- gattServer .sendResponse (device , requestId , BluetoothGatt .GATT_SUCCESS , 0 , manufacturer .getBytes (StandardCharsets .UTF_8 ));
404
+ // the running device's MANUFACTURER
405
+ gattServer .sendResponse (device , requestId , BluetoothGatt .GATT_SUCCESS , 0 , Build .MANUFACTURER .substring (0 , Math .min (Build .MANUFACTURER .length (), 20 )).getBytes (StandardCharsets .UTF_8 ));
404
406
break ;
405
407
default :
406
408
// send empty
@@ -487,6 +489,11 @@ private void connectMidiDevice(@NonNull BluetoothDevice device) {
487
489
midiDeviceAttachedListener .onMidiInputDeviceAttached (midiInputDevice );
488
490
midiDeviceAttachedListener .onMidiOutputDeviceAttached (midiOutputDevice );
489
491
}
492
+
493
+ if (autoStartDevice ) {
494
+ midiInputDevice .start ();
495
+ midiOutputDevice .start ();
496
+ }
490
497
}
491
498
492
499
/**
@@ -565,6 +572,14 @@ public void setDeviceName(@NonNull String deviceName) {
565
572
}
566
573
}
567
574
575
+ /**
576
+ * Sets MidiInputDevice to start automatically at being connected
577
+ * @param enable true to enable, default: true
578
+ */
579
+ public void setAutoStartDevice (boolean enable ) {
580
+ autoStartDevice = enable ;
581
+ }
582
+
568
583
/**
569
584
* {@link jp.kshoji.blemidi.device.MidiInputDevice} for Peripheral
570
585
*
@@ -586,13 +601,30 @@ public InternalMidiInputDevice(@NonNull BluetoothDevice bluetoothDevice) {
586
601
this .bluetoothDevice = bluetoothDevice ;
587
602
}
588
603
604
+ /**
605
+ * Starts parser's thread
606
+ */
607
+ @ Override
608
+ public void start () {
609
+ midiParser .start ();
610
+ }
611
+
589
612
/**
590
613
* Stops parser's thread
591
614
*/
592
- void stop () {
615
+ @ Override
616
+ public void stop () {
593
617
midiParser .stop ();
594
618
}
595
619
620
+ /**
621
+ * Terminates parser's thread
622
+ */
623
+ @ Override
624
+ public void terminate () {
625
+ midiParser .terminate ();
626
+ }
627
+
596
628
@ Override
597
629
public void setOnMidiInputEventListener (OnMidiInputEventListener midiInputEventListener ) {
598
630
midiParser .setMidiInputEventListener (midiInputEventListener );
@@ -601,10 +633,19 @@ public void setOnMidiInputEventListener(OnMidiInputEventListener midiInputEventL
601
633
@ NonNull
602
634
@ Override
603
635
public String getDeviceName () throws SecurityException {
604
- if (TextUtils .isEmpty (bluetoothDevice .getName ())) {
605
- return bluetoothDevice .getAddress ();
606
- }
607
- return bluetoothDevice .getName ();
636
+ return "" ;
637
+ }
638
+
639
+ @ NonNull
640
+ @ Override
641
+ public String getManufacturer () {
642
+ return "" ;
643
+ }
644
+
645
+ @ NonNull
646
+ @ Override
647
+ public String getModel () {
648
+ return "" ;
608
649
}
609
650
610
651
private void incomingData (@ NonNull byte [] data ) {
@@ -650,10 +691,19 @@ public InternalMidiOutputDevice(@NonNull final BluetoothDevice bluetoothDevice,
650
691
@ NonNull
651
692
@ Override
652
693
public String getDeviceName () throws SecurityException {
653
- if (TextUtils .isEmpty (bluetoothDevice .getName ())) {
654
- return bluetoothDevice .getAddress ();
655
- }
656
- return bluetoothDevice .getName ();
694
+ return "" ;
695
+ }
696
+
697
+ @ NonNull
698
+ @ Override
699
+ public String getManufacturer () {
700
+ return "" ;
701
+ }
702
+
703
+ @ NonNull
704
+ @ Override
705
+ public String getModel () {
706
+ return "" ;
657
707
}
658
708
659
709
@ Override
0 commit comments