Merge pull request #104 from geeksville/dev

fixes for nrf52 and remove google play dependency
This commit is contained in:
Kevin Hester 2020-07-17 11:56:45 -07:00 committed by GitHub
commit 43e3a6c157
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 49 deletions

View file

@ -17,8 +17,8 @@ android {
applicationId "com.geeksville.mesh"
minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works)
targetSdkVersion 29
versionCode 10793 // format is Mmmss (where M is 1+the numeric major number
versionName "0.7.93"
versionCode 10795 // format is Mmmss (where M is 1+the numeric major number
versionName "0.7.95"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
@ -95,7 +95,7 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.2.5'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta7'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta8'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

View file

@ -4,6 +4,14 @@
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="GoogleAppIndexingWarning">
<!-- If a device is missing a GPS - we will still be able to work though , must be before uses-permission-->
<uses-feature
android:name="android.hardware.location"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<!-- per https://github.com/journeyapps/zxing-android-embedded to force support for build 22 -->
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
@ -50,7 +58,7 @@
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
android:required="false" />
<!-- For the modern BLE scanning API -->
<uses-feature

View file

@ -191,6 +191,10 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
*/
private var isFirstSend = true
// NRF52 targets do not need the nasty force refresh hack that ESP32 needs (because they keep their
// BLE handles stable. So turn the hack off for these devices. FIXME - find a better way to know that the board is NRF52 based
private var needForceRefresh = !address.startsWith("FD:10:04")
init {
// Note: this call does no comms, it just creates the device object (even if the
// device is off/not connected)
@ -400,8 +404,6 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
}
}
private var needForceRefresh = true
private fun onConnect(connRes: Result<Unit>) {
// This callback is invoked after we are connected

View file

@ -183,54 +183,59 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
// if that device later disconnects remove it as a candidate
override fun onScanResult(callbackType: Int, result: ScanResult) {
val addr = result.device.address
val fullAddr = "x$addr" // full address with the bluetooh prefix
// prevent logspam because weill get get lots of redundant scan results
val isBonded = result.device.bondState == BluetoothDevice.BOND_BONDED
val oldDevs = devices.value!!
val oldEntry = oldDevs[fullAddr]
if (oldEntry == null || oldEntry.bonded != isBonded) { // Don't spam the GUI with endless updates for non changing nodes
if ((result.device.name?.startsWith("Mesh") ?: false)) {
val addr = result.device.address
val fullAddr = "x$addr" // full address with the bluetooh prefix
// prevent logspam because weill get get lots of redundant scan results
val isBonded = result.device.bondState == BluetoothDevice.BOND_BONDED
val oldDevs = devices.value!!
val oldEntry = oldDevs[fullAddr]
if (oldEntry == null || oldEntry.bonded != isBonded) { // Don't spam the GUI with endless updates for non changing nodes
val skipBogus = try {
// Note Soyes XS has a buggy BLE scan implementation and returns devices we didn't ask for. So we check to see if the
// last two chars of the name matches the last two of the address - if not we skip it
val skipBogus = try {
// Note Soyes XS has a buggy BLE scan implementation and returns devices we didn't ask for. So we check to see if the
// last two chars of the name matches the last two of the address - if not we skip it
// Note: the address is always two more than the hex string we show in the name
// Note: the address is always two more than the hex string we show in the name
// nasty parsing of a string that ends with ab:45 as four hex digits
val lastAddr = (addr.substring(
addr.length - 5,
addr.length - 3
) + addr.substring(addr.length - 2)).toInt(16)
// nasty parsing of a string that ends with ab:45 as four hex digits
val lastAddr = (addr.substring(
addr.length - 5,
addr.length - 3
) + addr.substring(addr.length - 2)).toInt(16)
val lastName =
result.device.name.substring(result.device.name.length - 4).toInt(16)
val lastName =
result.device.name.substring(result.device.name.length - 4).toInt(16)
(lastAddr - 2) != lastName
} catch (ex: Throwable) {
false // If we fail parsing anything, don't do this nasty hack
}
// ESP32 macaddr are two higher than the reported device name
// NRF52 macaddrs match the portion used in the string
// either would be acceptable
(lastAddr - 2) != lastName && lastAddr != lastName
} catch (ex: Throwable) {
false // If we fail parsing anything, don't do this nasty hack
}
if (skipBogus)
errormsg("Skipping bogus BLE entry $result")
else {
val entry = DeviceListEntry(
result.device.name
?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code?
fullAddr,
isBonded
)
debug("onScanResult ${entry}")
// If nothing was selected, by default select the first valid thing we see
val activity =
GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down
if (selectedAddress == null && entry.bonded && activity != null)
changeScanSelection(
activity,
fullAddr
if (skipBogus)
errormsg("Skipping bogus BLE entry $result")
else {
val entry = DeviceListEntry(
result.device.name
?: "unnamed-$addr", // autobug: some devices might not have a name, if someone is running really old device code?
fullAddr,
isBonded
)
addDevice(entry) // Add/replace entry
debug("onScanResult ${entry}")
// If nothing was selected, by default select the first valid thing we see
val activity =
GeeksvilleApplication.currentActivity as MainActivity? // Can be null if app is shutting down
if (selectedAddress == null && entry.bonded && activity != null)
changeScanSelection(
activity,
fullAddr
)
addDevice(entry) // Add/replace entry
}
}
}
}
@ -313,6 +318,8 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
// filter and only accept devices that have our service
val filter =
ScanFilter.Builder()
// Note: NRF52 doesn't put the service in the avertizement, so we can't filter by service here
// Instead we check in the callback
.setServiceUuid(ParcelUuid(BluetoothInterface.BTM_SERVICE_UUID))
.build()

View file

@ -12,7 +12,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:contentDescription="Text messages"
android:contentDescription="@string/text_messages"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View file

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="A list of nodes in the mesh">
android:contentDescription="@string/a_list_of_nodes_in_the_mesh">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/nodeListView"

View file

@ -71,4 +71,6 @@
<string name="meshtastic_service_notifications">Meshtastic Service Notifications</string>
<string name="location_disabled_warning">You must turn on location services in Android Settings</string>
<string name="about">About</string>
<string name="a_list_of_nodes_in_the_mesh">A list of nodes in the mesh</string>
<string name="text_messages">Text messages</string>
</resources>