firmware update button is kinda in

pull/40/head
geeksville 2020-05-13 17:00:23 -07:00
rodzic a3aa6dc5b6
commit c1388d6bad
7 zmienionych plików z 71 dodań i 22 usunięć

Wyświetl plik

@ -544,6 +544,8 @@ class MainActivity : AppCompatActivity(), Logging,
model.radioConfig.value = model.radioConfig.value =
MeshProtos.RadioConfig.parseFrom(service.radioConfig) MeshProtos.RadioConfig.parseFrom(service.radioConfig)
model.myNodeInfo.value = service.myNodeInfo
updateNodesFromDevice() updateNodesFromDevice()
// we have a connection to our device now, do the channel change // we have a connection to our device now, do the channel change

Wyświetl plik

@ -15,6 +15,9 @@ data class MyNodeInfo(
val couldUpdate: Boolean, // this application contains a software load we _could_ install if you want val couldUpdate: Boolean, // this application contains a software load we _could_ install if you want
val shouldUpdate: Boolean // this device has old firmware val shouldUpdate: Boolean // this device has old firmware
) : Parcelable { ) : Parcelable {
/** A human readable description of the software/hardware version */
val firmwareString: String get() = "$model $region/$firmwareVersion"
constructor(parcel: Parcel) : this( constructor(parcel: Parcel) : this(
parcel.readInt(), parcel.readInt(),
parcel.readByte() != 0.toByte(), parcel.readByte() != 0.toByte(),

Wyświetl plik

@ -12,6 +12,7 @@ import com.geeksville.android.BuildUtils.isEmulator
import com.geeksville.android.Logging import com.geeksville.android.Logging
import com.geeksville.mesh.IMeshService import com.geeksville.mesh.IMeshService
import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MyNodeInfo
import com.geeksville.mesh.service.MeshService import com.geeksville.mesh.service.MeshService
/// Given a human name, strip out the first letter of the first three words and return that as the initials for /// Given a human name, strip out the first letter of the first three words and return that as the initials for
@ -64,6 +65,9 @@ class UIViewModel(app: Application) : AndroidViewModel(app), Logging {
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) { val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
} }
/// hardware info about our local device
val myNodeInfo = object : MutableLiveData<MyNodeInfo>(null) {}
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
debug("ViewModel cleared") debug("ViewModel cleared")

Wyświetl plik

@ -853,6 +853,7 @@ class MeshService : Service(), Logging {
) )
handleMyInfo(myInfo) handleMyInfo(myInfo)
myNodeInfo = newMyNodeInfo // Apply the changes from handleMyInfo right now
radioConfig = MeshProtos.RadioConfig.parseFrom(connectedRadio.readRadioConfig()) radioConfig = MeshProtos.RadioConfig.parseFrom(connectedRadio.readRadioConfig())
@ -1132,6 +1133,8 @@ class MeshService : Service(), Logging {
private fun handleMyInfo(myInfo: MeshProtos.MyNodeInfo) { private fun handleMyInfo(myInfo: MeshProtos.MyNodeInfo) {
setFirmwareUpdateFilename(myInfo)
val mi = with(myInfo) { val mi = with(myInfo) {
MyNodeInfo( MyNodeInfo(
myNodeNum, myNodeNum,
@ -1139,8 +1142,8 @@ class MeshService : Service(), Logging {
region, region,
hwModel, hwModel,
firmwareVersion, firmwareVersion,
false, firmwareUpdateFilename != null,
false SoftwareUpdateService.shouldUpdate(this@MeshService, firmwareVersion)
) )
} }
@ -1284,27 +1287,27 @@ class MeshService : Service(), Logging {
} }
var firmwareUpdateFilename: String? = null
/*** /***
* Return the filename we will install on the device * Return the filename we will install on the device
*/ */
val firmwareUpdateFilename: String? fun setFirmwareUpdateFilename(info: MeshProtos.MyNodeInfo) {
get() = firmwareUpdateFilename = try {
try { if (info.region != null && info.firmwareVersion != null && info.hwModel != null)
myNodeInfo?.let {
if (it.region != null && it.firmwareVersion != null && it.model != null)
SoftwareUpdateService.getUpdateFilename( SoftwareUpdateService.getUpdateFilename(
this, this,
it.region, info.region,
it.firmwareVersion, info.firmwareVersion,
it.model info.hwModel
) )
else else
null null
}
} catch (ex: Exception) { } catch (ex: Exception) {
errormsg("Unable to update", ex) errormsg("Unable to update", ex)
null null
} }
}
private fun doFirmwareUpdate() { private fun doFirmwareUpdate() {
// Run in the IO thread // Run in the IO thread

Wyświetl plik

@ -311,11 +311,35 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
usernameEditText.setText(name) usernameEditText.setText(name)
}) })
// Only let user edit their name while connected to a radio // Only let user edit their name or set software update while connected to a radio
model.isConnected.observe(viewLifecycleOwner, Observer { connected -> model.isConnected.observe(viewLifecycleOwner, Observer { connected ->
usernameView.isEnabled = connected == MeshService.ConnectionState.CONNECTED usernameView.isEnabled = connected == MeshService.ConnectionState.CONNECTED
// If actively connected possibly let the user update firmware
val info = model.myNodeInfo.value
if (connected == MeshService.ConnectionState.CONNECTED && info != null && info.couldUpdate) {
updateFirmwareButton.visibility = View.VISIBLE
} else {
updateFirmwareButton.visibility = View.GONE
}
when (connected) {
MeshService.ConnectionState.CONNECTED -> {
val fwStr = info?.firmwareString ?: ""
scanStatusText.text = getString(R.string.connected_to).format(fwStr)
}
MeshService.ConnectionState.DISCONNECTED ->
scanStatusText.text = getString(R.string.not_connected)
MeshService.ConnectionState.DEVICE_SLEEP ->
scanStatusText.text = getString(R.string.connected_sleeping)
}
}) })
updateFirmwareButton.setOnClickListener {
debug("User started firmware update")
}
usernameEditText.on(EditorInfo.IME_ACTION_DONE) { usernameEditText.on(EditorInfo.IME_ACTION_DONE) {
debug("did IME action") debug("did IME action")
val n = usernameEditText.text.toString().trim() val n = usernameEditText.text.toString().trim()

Wyświetl plik

@ -45,9 +45,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="8dp"
android:text="@string/looking_for_meshtastic_devices" android:text="@string/looking_for_meshtastic_devices"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toStartOf="@+id/updateFirmwareButton"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/usernameView" /> app:layout_constraintTop_toBottomOf="@+id/usernameView" />
@ -117,5 +117,14 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scanStatusText" /> app:layout_constraintTop_toBottomOf="@+id/scanStatusText" />
<Button
android:id="@+id/updateFirmwareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/update_firmware"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/scanStatusText" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Wyświetl plik

@ -54,4 +54,8 @@
<string name="device_sleeping">Device sleeping</string> <string name="device_sleeping">Device sleeping</string>
<string name="connected_count">Connected: %s of %s online</string> <string name="connected_count">Connected: %s of %s online</string>
<string name="list_of_nodes">A list of nodes in the network</string> <string name="list_of_nodes">A list of nodes in the network</string>
<string name="update_firmware">Update Firmware</string>
<string name="connected_to">Connected to radio (%s)</string>
<string name="not_connected">Not connected, select radio below</string>
<string name="connected_sleeping">Connected to radio, but it is sleeping</string>
</resources> </resources>