fix: toast tekst ingekort, settings balk volledig klikbaar, version-check fallback voor oude ESP firmware
This commit is contained in:
parent
1499d840ce
commit
57ef68fcab
2 changed files with 27 additions and 20 deletions
|
|
@ -288,11 +288,13 @@ class BleRelayManager(
|
|||
if (versionChar != null) {
|
||||
val ok = gatt.readCharacteristic(versionChar)
|
||||
if (!ok) {
|
||||
Log.w(TAG, "readCharacteristic(VERSION) returned false, skipping version check")
|
||||
Log.w(TAG, "readCharacteristic(VERSION) returned false, treating as no version")
|
||||
handler.post { callbacks.onFirmwareVersion("", appVersion) }
|
||||
handler.post { callbacks.onStatusChanged(BleStatus.Connected) }
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "VERSION characteristic not found, skipping version check")
|
||||
Log.d(TAG, "VERSION characteristic not found on ESP (old firmware)")
|
||||
handler.post { callbacks.onFirmwareVersion("", appVersion) }
|
||||
handler.post { callbacks.onStatusChanged(BleStatus.Connected) }
|
||||
}
|
||||
} else {
|
||||
|
|
@ -301,14 +303,16 @@ class BleRelayManager(
|
|||
handler.post { callbacks.onStatusChanged(BleStatus.WrongDevice) }
|
||||
gatt.disconnect()
|
||||
}
|
||||
} else if (characteristic.uuid == VERSION_UUID && status == BluetoothGatt.GATT_SUCCESS) {
|
||||
val version = String(value, Charsets.UTF_8).trim()
|
||||
espVersion = version
|
||||
Log.d(TAG, "ESP firmware version: $version, app bundled: $appVersion")
|
||||
handler.post { callbacks.onFirmwareVersion(version, appVersion) }
|
||||
handler.post { callbacks.onStatusChanged(BleStatus.Connected) }
|
||||
} else if (characteristic.uuid == VERSION_UUID) {
|
||||
Log.w(TAG, "Version read failed (status=$status), using Connected anyway")
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
val version = String(value, Charsets.UTF_8).trim()
|
||||
espVersion = version
|
||||
Log.d(TAG, "ESP firmware version: $version, app bundled: $appVersion")
|
||||
handler.post { callbacks.onFirmwareVersion(version, appVersion) }
|
||||
} else {
|
||||
Log.w(TAG, "Version read failed (status=$status), treating as no version")
|
||||
handler.post { callbacks.onFirmwareVersion("", appVersion) }
|
||||
}
|
||||
handler.post { callbacks.onStatusChanged(BleStatus.Connected) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import android.widget.Button
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
@ -97,9 +96,9 @@ class MainActivity : AppCompatActivity(), BleCallbacks {
|
|||
statusText = findViewById(R.id.statusText)
|
||||
relay1Button = findViewById(R.id.relay1Button)
|
||||
relay2Button = findViewById(R.id.relay2Button)
|
||||
val settingsButton = findViewById<ImageButton>(R.id.settingsButton)
|
||||
val settingsContainer = findViewById<android.view.View>(R.id.settingsContainer)
|
||||
|
||||
settingsButton.setOnClickListener {
|
||||
settingsContainer.setOnClickListener {
|
||||
startActivityForResult(Intent(this, SettingsActivity::class.java), REQUEST_SETTINGS)
|
||||
}
|
||||
setupRelayButton()
|
||||
|
|
@ -222,7 +221,7 @@ class MainActivity : AppCompatActivity(), BleCallbacks {
|
|||
}
|
||||
|
||||
override fun onFirmwareVersion(espVersion: String, appVersion: String) {
|
||||
if (espVersion != appVersion) {
|
||||
if (espVersion.isEmpty() || espVersion != appVersion) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, getString(R.string.ota_update_available), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue