我将Java和Kotlin用于没有经验的个人项目,我可能会帮助您使用这个项目。我想要做的是从Estimote信标中读取遥测数据(温度,压力,光照水平)。我已经设法放了&将值更新为textviews。
现在我想获得IF条件(稍后我会尝试保存并将它们上传到Firebase数据库)。基本上我想检查其中一个遥测值是高于还是低于双数。例如。如果亮度低于6勒克斯,写下"少于6!",如果更多"超过6;"
val scanner = EstimoteBluetoothScannerFactory(applicationContext).getSimpleScanner()
val scanHandler = scanner.estimoteTelemetryFullScan()
.withBalancedPowerMode()
.withOnPacketFoundAction {
var temperature: TextView = findViewById<TextView>(R.id.temperature)
temperature.setText("Temperature: ${it.temperatureInCelsiusDegrees}")
var magnetometer: TextView = findViewById<TextView>(R.id.magnetometer)
magnetometer.setText("Magnetometer: ${it.magnetometer}")
var pressure: TextView = findViewById<TextView>(R.id.pressure)
pressure.setText("Pressure: ${it.pressure}")
var ambientLight: TextView = findViewById<TextView>(R.id.ambientLight)
ambientLight.setText("Ambient Light: ${it.ambientLightInLux}")
var motionState: TextView = findViewById<TextView>(R.id.motionState)
motionState.setText("Motion State: ${it.motionState}")
}
.start()
if(ambientLight > 6) {
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("More than 6!")
}else{
var checkLight: TextView = findViewById<TextView>(R.id.checkLight)
checkLight.setText("Less than 6!")
}
此代码不会更新textview值