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 =
MeshProtos.RadioConfig.parseFrom(service.radioConfig)
model.myNodeInfo.value = service.myNodeInfo
updateNodesFromDevice()
// 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 shouldUpdate: Boolean // this device has old firmware
) : Parcelable {
/** A human readable description of the software/hardware version */
val firmwareString: String get() = "$model $region/$firmwareVersion"
constructor(parcel: Parcel) : this(
parcel.readInt(),
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.mesh.IMeshService
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MyNodeInfo
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
@ -64,6 +65,9 @@ class UIViewModel(app: Application) : AndroidViewModel(app), Logging {
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
}
/// hardware info about our local device
val myNodeInfo = object : MutableLiveData<MyNodeInfo>(null) {}
override fun onCleared() {
super.onCleared()
debug("ViewModel cleared")

Wyświetl plik

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

Wyświetl plik

@ -311,11 +311,35 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
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 ->
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) {
debug("did IME action")
val n = usernameEditText.text.toString().trim()

Wyświetl plik

@ -45,9 +45,9 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
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_constraintTop_toBottomOf="@+id/usernameView" />
@ -117,5 +117,14 @@
app:layout_constraintStart_toStartOf="parent"
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>

Wyświetl plik

@ -54,4 +54,8 @@
<string name="device_sleeping">Device sleeping</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="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>