Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evsluzh committed Mar 18, 2018
1 parent 7a1b32c commit 415d5ab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/src/main/java/corpglory/android/accelerometer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ class MainActivity : AppCompatActivity(), AccelerometerEventListener {
}

override fun onStateReceived(state: AccelerometerState) {
val result = "vals " +
"k0=${state.x.format(2).replaceFirst(",", ".")}" +
",k1=${state.y.format(2).replaceFirst(",", ".")}" +
",k2=${state.z.format(2).replaceFirst(",", ".")}" +
val text = "x=${state.x.format(3).replaceFirst(",", ".")}\n" +
"y=${state.y.format(3).replaceFirst(",", ".")}\n" +
"z=${state.z.format(3).replaceFirst(",", ".")}"
outView.text = text

val message = "vals " +
"x=${state.x.format(3).replaceFirst(",", ".")}" +
",y=${state.y.format(3).replaceFirst(",", ".")}" +
",z=${state.z.format(3).replaceFirst(",", ".")}" +
" ${state.time}\n"

outView.text = result
database?.sendMsg(result)
database?.sendMsg(message)
}

fun Double.format(digits: Int) = java.lang.String.format("%.${digits}f", this)
Expand Down

0 comments on commit 415d5ab

Please sign in to comment.