Compare commits
3 Commits
3080005928
...
070c7228c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 070c7228c3 | |||
| b6bd946d9a | |||
| 6cdf83a3cc |
@ -21,7 +21,6 @@ import com.github.mikephil.charting.data.LineDataSet
|
|||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
@ -51,6 +50,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private lateinit var tempCircle: TextView
|
private lateinit var tempCircle: TextView
|
||||||
private lateinit var humCircle: TextView
|
private lateinit var humCircle: TextView
|
||||||
|
|
||||||
|
private var startTime: Long = 0L
|
||||||
|
|
||||||
private val isTesting = true
|
private val isTesting = true
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -139,6 +140,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
bluetoothSocket?.inputStream ?: return
|
bluetoothSocket?.inputStream ?: return
|
||||||
}
|
}
|
||||||
val reader = BufferedReader(InputStreamReader(inputStream))
|
val reader = BufferedReader(InputStreamReader(inputStream))
|
||||||
|
startTime = System.currentTimeMillis()
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
@ -152,7 +154,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val hum = parts[1].toFloatOrNull()
|
val hum = parts[1].toFloatOrNull()
|
||||||
|
|
||||||
if (temp != null && hum != null) {
|
if (temp != null && hum != null) {
|
||||||
val reading = SensorReading(System.currentTimeMillis(), temp, hum)
|
val reading = SensorReading(
|
||||||
|
secSinceStart = (System.currentTimeMillis() - startTime) / 1000,
|
||||||
|
temperature = temp,
|
||||||
|
humidity = hum
|
||||||
|
)
|
||||||
sensorHistory.add(reading)
|
sensorHistory.add(reading)
|
||||||
Log.d(tag, "Store: $reading")
|
Log.d(tag, "Store: $reading")
|
||||||
|
|
||||||
@ -186,9 +192,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
position = XAxis.XAxisPosition.BOTTOM
|
position = XAxis.XAxisPosition.BOTTOM
|
||||||
valueFormatter = object : ValueFormatter() {
|
valueFormatter = object : ValueFormatter() {
|
||||||
override fun getFormattedValue(value: Float): String? {
|
override fun getFormattedValue(value: Float): String? {
|
||||||
val time = Date(value.toLong())
|
return "${value.toInt()}s"
|
||||||
val format = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
|
||||||
return format.format(time)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
granularity = 1f
|
granularity = 1f
|
||||||
@ -235,8 +239,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tempChart.data = LineData(tempSet)
|
tempChart.data = LineData(tempSet)
|
||||||
humChart.data = LineData(humSet)
|
tempChart.notifyDataSetChanged()
|
||||||
tempChart.invalidate()
|
tempChart.invalidate()
|
||||||
|
|
||||||
|
humChart.data = LineData(humSet)
|
||||||
|
humChart.notifyDataSetChanged()
|
||||||
humChart.invalidate()
|
humChart.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user