mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-05 06:33:52 -04:00
Display battery level of remote nodes #64
This commit is contained in:
@@ -28,7 +28,8 @@ data class Position(
|
||||
val latitude: Double,
|
||||
val longitude: Double,
|
||||
val altitude: Int,
|
||||
val time: Int = currentTime() // default to current time in secs
|
||||
val time: Int = currentTime(), // default to current time in secs
|
||||
val batteryPctLevel: Int
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
/// Convert to a double representation of degrees
|
||||
@@ -45,7 +46,8 @@ data class Position(
|
||||
degD(p.latitudeI),
|
||||
degD(p.longitudeI),
|
||||
p.altitude,
|
||||
if (p.time != 0) p.time else defaultTime
|
||||
if (p.time != 0) p.time else defaultTime,
|
||||
p.batteryLevel
|
||||
)
|
||||
|
||||
/// @return distance in meters to some other node (or null if unknown)
|
||||
@@ -71,6 +73,8 @@ data class NodeInfo(
|
||||
/// Return the last time we've seen this node in secs since 1970
|
||||
val lastSeen get() = position?.time ?: 0
|
||||
|
||||
val batteryPctLevel get() = position?.batteryPctLevel
|
||||
|
||||
/**
|
||||
* true if the device was heard from recently
|
||||
*
|
||||
|
||||
@@ -10,12 +10,14 @@ import com.geeksville.mesh.Position
|
||||
/// NodeDB lives inside the UIViewModel, but it needs a backpointer to reach the service
|
||||
class NodeDB(private val ui: UIViewModel) {
|
||||
private val testPositions = arrayOf(
|
||||
Position(32.776665, -96.796989, 35), // dallas
|
||||
Position(32.960758, -96.733521, 35), // richardson
|
||||
Position(32.776665, -96.796989, 35, 123, 40), // dallas
|
||||
Position(32.960758, -96.733521, 35, 456, 50), // richardson
|
||||
Position(
|
||||
32.912901,
|
||||
-96.781776,
|
||||
35
|
||||
35,
|
||||
789,
|
||||
60
|
||||
) // north dallas
|
||||
)
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val nodeNameView = itemView.nodeNameView
|
||||
val distance_view = itemView.distance_view
|
||||
val batteryPctView = itemView.batteryPercentageView
|
||||
}
|
||||
|
||||
private val nodesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
|
||||
@@ -106,6 +107,16 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
||||
} else {
|
||||
holder.distance_view.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
val battery = n.batteryPctLevel
|
||||
if (battery != null)
|
||||
{
|
||||
holder.batteryPctView.text = "$battery%"
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.batteryPctView.text = "?"
|
||||
}
|
||||
}
|
||||
|
||||
private var nodes = arrayOf<NodeInfo>()
|
||||
|
||||
Reference in New Issue
Block a user