This commit is contained in:
+6
-12
@@ -18,26 +18,20 @@ class AccelChartManager(private val chart: LineChart) {
|
||||
private val yEntries = mutableListOf<Entry>()
|
||||
private val zEntries = mutableListOf<Entry>()
|
||||
|
||||
private val xDataSet: LineDataSet
|
||||
private val yDataSet: LineDataSet
|
||||
private val zDataSet: LineDataSet
|
||||
private val xDataSet = createDataSet("X", Color.RED)
|
||||
private val yDataSet = createDataSet("Y", Color.GREEN)
|
||||
private val zDataSet = createDataSet("Z", Color.BLUE)
|
||||
|
||||
private var index = 0
|
||||
|
||||
init {
|
||||
try {
|
||||
setupChart()
|
||||
xDataSet = createDataSet("X", Color.RED)
|
||||
yDataSet = createDataSet("Y", Color.GREEN)
|
||||
zDataSet = createDataSet("Z", Color.BLUE)
|
||||
|
||||
} catch (_: Exception) { }
|
||||
try {
|
||||
val lineData = LineData(xDataSet, yDataSet, zDataSet)
|
||||
chart.data = lineData
|
||||
} catch (_: Exception) {
|
||||
xDataSet = createDataSet("X", Color.RED)
|
||||
yDataSet = createDataSet("Y", Color.GREEN)
|
||||
zDataSet = createDataSet("Z", Color.BLUE)
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,26 +18,20 @@ class GyroChartManager(private val chart: LineChart) {
|
||||
private val yEntries = mutableListOf<Entry>()
|
||||
private val zEntries = mutableListOf<Entry>()
|
||||
|
||||
private val xDataSet: LineDataSet
|
||||
private val yDataSet: LineDataSet
|
||||
private val zDataSet: LineDataSet
|
||||
private val xDataSet = createDataSet("X", Color.RED)
|
||||
private val yDataSet = createDataSet("Y", Color.GREEN)
|
||||
private val zDataSet = createDataSet("Z", Color.BLUE)
|
||||
|
||||
private var index = 0
|
||||
|
||||
init {
|
||||
try {
|
||||
setupChart()
|
||||
xDataSet = createDataSet("X", Color.RED)
|
||||
yDataSet = createDataSet("Y", Color.GREEN)
|
||||
zDataSet = createDataSet("Z", Color.BLUE)
|
||||
|
||||
} catch (_: Exception) { }
|
||||
try {
|
||||
val lineData = LineData(xDataSet, yDataSet, zDataSet)
|
||||
chart.data = lineData
|
||||
} catch (_: Exception) {
|
||||
xDataSet = createDataSet("X", Color.RED)
|
||||
yDataSet = createDataSet("Y", Color.GREEN)
|
||||
zDataSet = createDataSet("Z", Color.BLUE)
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
|
||||
private fun setupChart() {
|
||||
|
||||
+9
-14
@@ -16,28 +16,23 @@ class MagnetometerBarManager(private val chart: BarChart) {
|
||||
private val colors = listOf(Color.RED, Color.GREEN, Color.BLUE)
|
||||
private val labels = listOf("X", "Y", "Z")
|
||||
|
||||
private val dataSet: BarDataSet
|
||||
private val dataSet = BarDataSet(mutableListOf(), "Magnetometer (µT)").apply {
|
||||
setColors(colors)
|
||||
setDrawValues(true)
|
||||
valueTextColor = Color.WHITE
|
||||
valueTextSize = 12f
|
||||
}
|
||||
|
||||
init {
|
||||
try {
|
||||
setupChart()
|
||||
dataSet = BarDataSet(mutableListOf(), "Magnetometer (µT)").apply {
|
||||
setColors(colors)
|
||||
setDrawValues(true)
|
||||
valueTextColor = Color.WHITE
|
||||
valueTextSize = 12f
|
||||
}
|
||||
|
||||
} catch (_: Exception) { }
|
||||
try {
|
||||
val barData = BarData(dataSet).apply {
|
||||
barWidth = 0.6f
|
||||
}
|
||||
chart.data = barData
|
||||
} catch (_: Exception) {
|
||||
// Chart init after view detach — will be recreated on next view creation
|
||||
dataSet = BarDataSet(mutableListOf(), "").apply {
|
||||
setColors(colors)
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
|
||||
private fun setupChart() {
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@ import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.senstools.data.datasource.DataCollectionService
|
||||
import com.senstools.databinding.FragmentDashboardBinding
|
||||
import com.senstools.domain.ekf.EKFAttitude
|
||||
import com.senstools.domain.model.AttitudeData
|
||||
import com.senstools.domain.repository.DataRepository
|
||||
import com.senstools.presentation.ui.charts.AccelChartManager
|
||||
import com.senstools.presentation.ui.charts.GyroChartManager
|
||||
@@ -155,7 +156,8 @@ class DashboardFragment : Fragment() {
|
||||
|
||||
// Guard against stale timestamps causing EKF divergence
|
||||
val now = System.currentTimeMillis()
|
||||
if (sensor.timestamp > 0L && kotlin.math.abs(sensor.timestamp - now) > 10000L) {
|
||||
val tsDiff = if (sensor.timestamp > now) sensor.timestamp - now else now - sensor.timestamp
|
||||
if (sensor.timestamp > 0L && tsDiff > 10000L) {
|
||||
// Timestamp too far in the future or past, reset EKF
|
||||
ekfAttitude.reset()
|
||||
ekfInitialized = false
|
||||
|
||||
Reference in New Issue
Block a user