kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
wip adding channelset
rodzic
31a106039b
commit
0743feadc4
|
@ -71,18 +71,26 @@ interface IMeshService {
|
|||
*/
|
||||
List<NodeInfo> getNodes();
|
||||
|
||||
/// This method is only intended for use in our GUI, so the user can set radio options
|
||||
/// It returns a RadioConfig protobuf.
|
||||
byte []getRadioConfig();
|
||||
|
||||
/// Return an list of MeshPacket protobuf (byte arrays) which were received while your client app was offline (recent messages only).
|
||||
/// Also includes any messages we have sent recently (useful for finding current message status)
|
||||
List<DataPacket> getOldMessages();
|
||||
|
||||
/// This method is only intended for use in our GUI, so the user can set radio options
|
||||
/// It returns a RadioConfig protobuf.
|
||||
byte []getRadioConfig();
|
||||
|
||||
/// This method is only intended for use in our GUI, so the user can set radio options
|
||||
/// It sets a RadioConfig protobuf
|
||||
void setRadioConfig(in byte []payload);
|
||||
|
||||
/// This method is only intended for use in our GUI, so the user can set radio options
|
||||
/// It returns a ChannelSet protobuf.
|
||||
byte []getChannels();
|
||||
|
||||
/// This method is only intended for use in our GUI, so the user can set radio options
|
||||
/// It sets a ChannelSet protobuf
|
||||
void setChannels(in byte []payload);
|
||||
|
||||
/**
|
||||
Is the packet radio currently connected to the phone? Returns a ConnectionState string.
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.AppOnlyProtos
|
||||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
|
@ -69,15 +70,6 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Return the current channel info
|
||||
*/
|
||||
fun getChannel(c: MeshProtos.RadioConfig?): Channel? {
|
||||
val channel = c?.channelSettings?.let { Channel(it) }
|
||||
|
||||
return channel
|
||||
}
|
||||
|
||||
fun getPreferences(context: Context): SharedPreferences =
|
||||
context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
@ -101,6 +93,9 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
val radioConfig = object : MutableLiveData<MeshProtos.RadioConfig?>(null) {
|
||||
}
|
||||
|
||||
val channels = object : MutableLiveData<AppOnlyProtos.ChannelSet?>(null) {
|
||||
}
|
||||
|
||||
var positionBroadcastSecs: Int?
|
||||
get() {
|
||||
radioConfig.value?.preferences?.let {
|
||||
|
@ -155,15 +150,31 @@ class UIViewModel(private val app: Application) : AndroidViewModel(app), Logging
|
|||
debug("ViewModel cleared")
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the primary channel info
|
||||
*/
|
||||
val primaryChannel: ChannelSet? get() {
|
||||
return channels.value?.let { it ->
|
||||
Channel(it.getSettings(0))
|
||||
}
|
||||
}
|
||||
/// Set the radio config (also updates our saved copy in preferences)
|
||||
fun setRadioConfig(c: MeshProtos.RadioConfig) {
|
||||
private fun setRadioConfig(c: MeshProtos.RadioConfig) {
|
||||
debug("Setting new radio config!")
|
||||
meshService?.radioConfig = c.toByteArray()
|
||||
radioConfig.value =
|
||||
c // Must be done after calling the service, so we will will properly throw if the service failed (and therefore not cache invalid new settings)
|
||||
}
|
||||
|
||||
/// Set the radio config (also updates our saved copy in preferences)
|
||||
private fun setChannels(c: AppOnlyProtos.ChannelSet) {
|
||||
debug("Setting new channels!")
|
||||
meshService?.channels = c.toByteArray()
|
||||
channels.value =
|
||||
c // Must be done after calling the service, so we will will properly throw if the service failed (and therefore not cache invalid new settings)
|
||||
|
||||
getPreferences(context).edit(commit = true) {
|
||||
this.putString("channel-url", getChannel(c)!!.getChannelUrl().toString())
|
||||
this.putString("channel-url", primaryChannel!!.getChannelUrl().toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1604,6 +1604,10 @@ class MeshService : Service(), Logging {
|
|||
this@MeshService.setRadioConfig(payload)
|
||||
}
|
||||
|
||||
override fun getChannels(): ByteArray {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getNodes(): MutableList<NodeInfo> = toRemoteExceptions {
|
||||
val r = nodeDBbyID.values.toMutableList()
|
||||
info("in getOnline, count=${r.size}")
|
||||
|
|
Ładowanie…
Reference in New Issue