@@ -44,9 +44,9 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
4444
4545 private static final int CHROMEBOOK_CONNECTION_CHECK_INTERVAL = 10000 ;
4646
47- static public final UUID steamControllerService = UUID .fromString ("100F6C32-1735-4313-B402-38567131E5F3" );
48- static public final UUID inputCharacteristic = UUID .fromString ("100F6C33-1735-4313-B402-38567131E5F3" );
49- static public final UUID reportCharacteristic = UUID .fromString ("100F6C34-1735-4313-B402-38567131E5F3" );
47+ static final UUID steamControllerService = UUID .fromString ("100F6C32-1735-4313-B402-38567131E5F3" );
48+ static final UUID inputCharacteristic = UUID .fromString ("100F6C33-1735-4313-B402-38567131E5F3" );
49+ static final UUID reportCharacteristic = UUID .fromString ("100F6C34-1735-4313-B402-38567131E5F3" );
5050 static private final byte [] enterValveMode = new byte [] { (byte )0xC0 , (byte )0x87 , 0x03 , 0x08 , 0x07 , 0x00 };
5151
5252 static class GattOperation {
@@ -156,30 +156,30 @@ static public GattOperation enableNotification(BluetoothGatt gatt, UUID uuid) {
156156 }
157157 }
158158
159- public HIDDeviceBLESteamController (HIDDeviceManager manager , BluetoothDevice device ) {
159+ HIDDeviceBLESteamController (HIDDeviceManager manager , BluetoothDevice device ) {
160160 mManager = manager ;
161161 mDevice = device ;
162162 mDeviceId = mManager .getDeviceIDForIdentifier (getIdentifier ());
163163 mIsRegistered = false ;
164- mIsChromebook = mManager . getContext (). getPackageManager (). hasSystemFeature ( "org.chromium.arc.device_management" );
164+ mIsChromebook = SDLActivity . isChromebook ( );
165165 mOperations = new LinkedList <GattOperation >();
166166 mHandler = new Handler (Looper .getMainLooper ());
167167
168168 mGatt = connectGatt ();
169169 // final HIDDeviceBLESteamController finalThis = this;
170170 // mHandler.postDelayed(new Runnable() {
171171 // @Override
172- // public void run() {
172+ // void run() {
173173 // finalThis.checkConnectionForChromebookIssue();
174174 // }
175175 // }, CHROMEBOOK_CONNECTION_CHECK_INTERVAL);
176176 }
177177
178- public String getIdentifier () {
178+ String getIdentifier () {
179179 return String .format ("SteamController.%s" , mDevice .getAddress ());
180180 }
181181
182- public BluetoothGatt getGatt () {
182+ BluetoothGatt getGatt () {
183183 return mGatt ;
184184 }
185185
@@ -219,7 +219,7 @@ protected int getConnectionState() {
219219 return btManager .getConnectionState (mDevice , BluetoothProfile .GATT );
220220 }
221221
222- public void reconnect () {
222+ void reconnect () {
223223
224224 if (getConnectionState () != BluetoothProfile .STATE_CONNECTED ) {
225225 mGatt .disconnect ();
@@ -401,12 +401,12 @@ private void enableNotification(UUID chrUuid) {
401401 queueGattOperation (op );
402402 }
403403
404- public void writeCharacteristic (UUID uuid , byte [] value ) {
404+ void writeCharacteristic (UUID uuid , byte [] value ) {
405405 GattOperation op = HIDDeviceBLESteamController .GattOperation .writeCharacteristic (mGatt , uuid , value );
406406 queueGattOperation (op );
407407 }
408408
409- public void readCharacteristic (UUID uuid ) {
409+ void readCharacteristic (UUID uuid ) {
410410 GattOperation op = HIDDeviceBLESteamController .GattOperation .readCharacteristic (mGatt , uuid );
411411 queueGattOperation (op );
412412 }
@@ -415,6 +415,7 @@ public void readCharacteristic(UUID uuid) {
415415 ////////////// BluetoothGattCallback overridden methods
416416 //////////////////////////////////////////////////////////////////////////////////////////////////////
417417
418+ @ Override
418419 public void onConnectionStateChange (BluetoothGatt g , int status , int newState ) {
419420 //Log.v(TAG, "onConnectionStateChange status=" + status + " newState=" + newState);
420421 mIsReconnecting = false ;
@@ -437,6 +438,7 @@ else if (newState == 0) {
437438 // Disconnection is handled in SteamLink using the ACTION_ACL_DISCONNECTED Intent.
438439 }
439440
441+ @ Override
440442 public void onServicesDiscovered (BluetoothGatt gatt , int status ) {
441443 //Log.v(TAG, "onServicesDiscovered status=" + status);
442444 if (status == 0 ) {
@@ -453,31 +455,34 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
453455 }
454456 }
455457
458+ @ Override
456459 public void onCharacteristicRead (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic , int status ) {
457460 //Log.v(TAG, "onCharacteristicRead status=" + status + " uuid=" + characteristic.getUuid());
458461
459462 if (characteristic .getUuid ().equals (reportCharacteristic ) && !mFrozen ) {
460- mManager .HIDDeviceFeatureReport (getId (), characteristic .getValue ());
463+ mManager .HIDDeviceReportResponse (getId (), characteristic .getValue ());
461464 }
462465
463466 finishCurrentGattOperation ();
464467 }
465468
469+ @ Override
466470 public void onCharacteristicWrite (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic , int status ) {
467471 //Log.v(TAG, "onCharacteristicWrite status=" + status + " uuid=" + characteristic.getUuid());
468472
469473 if (characteristic .getUuid ().equals (reportCharacteristic )) {
470474 // Only register controller with the native side once it has been fully configured
471475 if (!isRegistered ()) {
472476 Log .v (TAG , "Registering Steam Controller with ID: " + getId ());
473- mManager .HIDDeviceConnected (getId (), getIdentifier (), getVendorId (), getProductId (), getSerialNumber (), getVersion (), getManufacturerName (), getProductName (), 0 , 0 , 0 , 0 );
477+ mManager .HIDDeviceConnected (getId (), getIdentifier (), getVendorId (), getProductId (), getSerialNumber (), getVersion (), getManufacturerName (), getProductName (), 0 , 0 , 0 , 0 , true );
474478 setRegistered ();
475479 }
476480 }
477481
478482 finishCurrentGattOperation ();
479483 }
480484
485+ @ Override
481486 public void onCharacteristicChanged (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic ) {
482487 // Enable this for verbose logging of controller input reports
483488 //Log.v(TAG, "onCharacteristicChanged uuid=" + characteristic.getUuid() + " data=" + HexDump.dumpHexString(characteristic.getValue()));
@@ -487,10 +492,12 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
487492 }
488493 }
489494
495+ @ Override
490496 public void onDescriptorRead (BluetoothGatt gatt , BluetoothGattDescriptor descriptor , int status ) {
491497 //Log.v(TAG, "onDescriptorRead status=" + status);
492498 }
493499
500+ @ Override
494501 public void onDescriptorWrite (BluetoothGatt gatt , BluetoothGattDescriptor descriptor , int status ) {
495502 BluetoothGattCharacteristic chr = descriptor .getCharacteristic ();
496503 //Log.v(TAG, "onDescriptorWrite status=" + status + " uuid=" + chr.getUuid() + " descriptor=" + descriptor.getUuid());
@@ -508,14 +515,17 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
508515 finishCurrentGattOperation ();
509516 }
510517
518+ @ Override
511519 public void onReliableWriteCompleted (BluetoothGatt gatt , int status ) {
512520 //Log.v(TAG, "onReliableWriteCompleted status=" + status);
513521 }
514522
523+ @ Override
515524 public void onReadRemoteRssi (BluetoothGatt gatt , int rssi , int status ) {
516525 //Log.v(TAG, "onReadRemoteRssi status=" + status);
517526 }
518527
528+ @ Override
519529 public void onMtuChanged (BluetoothGatt gatt , int mtu , int status ) {
520530 //Log.v(TAG, "onMtuChanged status=" + status);
521531 }
@@ -575,50 +585,45 @@ public boolean open() {
575585 }
576586
577587 @ Override
578- public int sendFeatureReport (byte [] report ) {
588+ public int writeReport (byte [] report , boolean feature ) {
579589 if (!isRegistered ()) {
580- Log .e (TAG , "Attempted sendFeatureReport before Steam Controller is registered!" );
590+ Log .e (TAG , "Attempted writeReport before Steam Controller is registered!" );
581591 if (mIsConnected ) {
582592 probeService (this );
583593 }
584594 return -1 ;
585595 }
586596
587- // We need to skip the first byte, as that doesn't go over the air
588- byte [] actual_report = Arrays .copyOfRange (report , 1 , report .length - 1 );
589- //Log.v(TAG, "sendFeatureReport " + HexDump.dumpHexString(actual_report));
590- writeCharacteristic (reportCharacteristic , actual_report );
591- return report .length ;
592- }
593-
594- @ Override
595- public int sendOutputReport (byte [] report ) {
596- if (!isRegistered ()) {
597- Log .e (TAG , "Attempted sendOutputReport before Steam Controller is registered!" );
598- if (mIsConnected ) {
599- probeService (this );
600- }
601- return -1 ;
597+ if (feature ) {
598+ // We need to skip the first byte, as that doesn't go over the air
599+ byte [] actual_report = Arrays .copyOfRange (report , 1 , report .length - 1 );
600+ //Log.v(TAG, "writeFeatureReport " + HexDump.dumpHexString(actual_report));
601+ writeCharacteristic (reportCharacteristic , actual_report );
602+ return report .length ;
603+ } else {
604+ //Log.v(TAG, "writeOutputReport " + HexDump.dumpHexString(report));
605+ writeCharacteristic (reportCharacteristic , report );
606+ return report .length ;
602607 }
603-
604- //Log.v(TAG, "sendFeatureReport " + HexDump.dumpHexString(report));
605- writeCharacteristic (reportCharacteristic , report );
606- return report .length ;
607608 }
608609
609610 @ Override
610- public boolean getFeatureReport (byte [] report ) {
611+ public boolean readReport (byte [] report , boolean feature ) {
611612 if (!isRegistered ()) {
612- Log .e (TAG , "Attempted getFeatureReport before Steam Controller is registered!" );
613+ Log .e (TAG , "Attempted readReport before Steam Controller is registered!" );
613614 if (mIsConnected ) {
614615 probeService (this );
615616 }
616617 return false ;
617618 }
618619
619- //Log.v(TAG, "getFeatureReport");
620- readCharacteristic (reportCharacteristic );
621- return true ;
620+ if (feature ) {
621+ readCharacteristic (reportCharacteristic );
622+ return true ;
623+ } else {
624+ // Not implemented
625+ return false ;
626+ }
622627 }
623628
624629 @ Override
0 commit comments