-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functionality to set preferred PHY and to read the set PHY (#840)
- Loading branch information
1 parent
60b99f2
commit e9e45cc
Showing
21 changed files
with
913 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
rxandroidble/src/main/java/com/polidea/rxandroidble2/PhyPair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.polidea.rxandroidble2; | ||
|
||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* The interface used for results of {@link RxBleConnection#readPhy()} and {@link RxBleConnection#setPreferredPhy(Set, Set, RxBlePhyOption)} | ||
*/ | ||
public interface PhyPair { | ||
|
||
@NonNull | ||
RxBlePhy getTxPhy(); | ||
|
||
@NonNull | ||
RxBlePhy getRxPhy(); | ||
|
||
int hashCode(); | ||
|
||
boolean equals(@Nullable Object obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
rxandroidble/src/main/java/com/polidea/rxandroidble2/RxBlePhy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.polidea.rxandroidble2; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
|
||
import com.polidea.rxandroidble2.internal.RxBlePhyImpl; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* The interface used in {@link Set} for requesting PHY when calling {@link RxBleConnection#setPreferredPhy(Set, Set, RxBlePhyOption)} and | ||
* inside {@link PhyPair} as results of {@link RxBleConnection#readPhy()} and | ||
* {@link RxBleConnection#setPreferredPhy(Set, Set, RxBlePhyOption)} | ||
*/ | ||
public interface RxBlePhy { | ||
|
||
/** | ||
* Bluetooth LE 1M PHY. | ||
*/ | ||
RxBlePhy PHY_1M = RxBlePhyImpl.PHY_1M; | ||
|
||
/** | ||
* Bluetooth LE 2M PHY. | ||
*/ | ||
RxBlePhy PHY_2M = RxBlePhyImpl.PHY_2M; | ||
|
||
/** | ||
* Bluetooth LE Coded PHY. | ||
*/ | ||
RxBlePhy PHY_CODED = RxBlePhyImpl.PHY_CODED; | ||
|
||
/** | ||
* Corresponds to e.g. {@link BluetoothDevice#PHY_LE_CODED_MASK} | ||
*/ | ||
int getMask(); | ||
|
||
/** | ||
* Corresponds to e.g. {@link BluetoothDevice#PHY_LE_CODED} | ||
*/ | ||
int getValue(); | ||
} |
29 changes: 29 additions & 0 deletions
29
rxandroidble/src/main/java/com/polidea/rxandroidble2/RxBlePhyOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.polidea.rxandroidble2; | ||
|
||
import com.polidea.rxandroidble2.internal.RxBlePhyOptionImpl; | ||
|
||
/** | ||
* Coding to be used when transmitting on the LE Coded PHY. | ||
*/ | ||
public interface RxBlePhyOption { | ||
/** | ||
* No preferred coding. | ||
*/ | ||
RxBlePhyOption PHY_OPTION_NO_PREFERRED = RxBlePhyOptionImpl.PHY_OPTION_NO_PREFERRED; | ||
|
||
/** | ||
* Prefer the S=2 coding. | ||
*/ | ||
RxBlePhyOption PHY_OPTION_S2 = RxBlePhyOptionImpl.PHY_OPTION_S2; | ||
|
||
/** | ||
* Prefer the S=8 coding. | ||
*/ | ||
RxBlePhyOption PHY_OPTION_S8 = RxBlePhyOptionImpl.PHY_OPTION_S8; | ||
|
||
/** | ||
* | ||
* @return integer value representing PHY option, e.g. {@link android.bluetooth.BluetoothDevice#PHY_OPTION_S2} | ||
*/ | ||
int getValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
rxandroidble/src/main/java/com/polidea/rxandroidble2/internal/PhyPairImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.polidea.rxandroidble2.internal; | ||
|
||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.polidea.rxandroidble2.PhyPair; | ||
import com.polidea.rxandroidble2.RxBlePhy; | ||
|
||
import java.util.Objects; | ||
|
||
public class PhyPairImpl implements PhyPair { | ||
public final RxBlePhy txPhy; | ||
public final RxBlePhy rxPhy; | ||
|
||
public PhyPairImpl(@NonNull final RxBlePhy txPhy, @NonNull final RxBlePhy rxPhy) { | ||
this.txPhy = txPhy; | ||
this.rxPhy = rxPhy; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public RxBlePhy getTxPhy() { | ||
return txPhy; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public RxBlePhy getRxPhy() { | ||
return rxPhy; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(rxPhy, txPhy); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if (obj == this) return true; | ||
if (!(obj instanceof PhyPair)) return false; | ||
PhyPair phyPair = (PhyPair) obj; | ||
return txPhy.equals(phyPair.getTxPhy()) && rxPhy.equals(phyPair.getRxPhy()); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String toString() { | ||
return "PhyPair{" | ||
+ "txPhy=" + txPhy | ||
+ ", rxPhy=" + rxPhy | ||
+ '}'; | ||
} | ||
} |
Oops, something went wrong.