Add logic for calibration process to app
Signed-off-by: Severin Kaderli <severin@kaderli.dev>
This commit is contained in:
parent
7f0c6bea20
commit
4f19c761a0
4 changed files with 39 additions and 2 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
package dev.kaderli.magsend
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.hardware.Sensor
|
||||||
|
import android.hardware.SensorEventListener
|
||||||
|
import android.hardware.SensorManager
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
abstract class BaseSensorActivity : BaseActivity(), SensorEventListener {
|
||||||
|
private lateinit var sensorManager: SensorManager;
|
||||||
|
private lateinit var sensor: Sensor;
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||||
|
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||||
|
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI);
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
|
||||||
|
}
|
|
@ -1,7 +1,23 @@
|
||||||
package dev.kaderli.magsend
|
package dev.kaderli.magsend
|
||||||
|
|
||||||
class CalibrationActivity : BaseActivity() {
|
import android.hardware.SensorEvent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.TextView
|
||||||
|
|
||||||
|
class CalibrationActivity : BaseSensorActivity() {
|
||||||
|
private lateinit var calibrationValue: TextView
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
calibrationValue = findViewById(R.id.calibrationValue)
|
||||||
|
calibrationValue.text = getString(R.string.calibration_value, 0f)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getLayoutId(): Int {
|
override fun getLayoutId(): Int {
|
||||||
return R.layout.activity_calibration
|
return R.layout.activity_calibration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onSensorChanged(event: SensorEvent) {
|
||||||
|
calibrationValue.text = getString(R.string.calibration_value, event.values[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/component_spacing"
|
android:layout_marginTop="@dimen/component_spacing"
|
||||||
android:text="82µT "
|
|
||||||
android:textSize="48sp"
|
android:textSize="48sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
|
@ -10,4 +10,5 @@
|
||||||
<string name="restart_button_label">Restart</string>
|
<string name="restart_button_label">Restart</string>
|
||||||
<string name="calibration_activity_label">Calibration</string>
|
<string name="calibration_activity_label">Calibration</string>
|
||||||
<string name="receive_activity_label">Receive</string>
|
<string name="receive_activity_label">Receive</string>
|
||||||
|
<string name="calibration_value">%1$.2f µT</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Reference in a new issue