项目作者: aweCodeMan

项目描述 :
TSL2591 (light sensor) driver for Android things
高级语言: Kotlin
项目地址: git://github.com/aweCodeMan/driver_tsl2591.git
创建时间: 2018-04-04T08:59:22Z
项目社区:https://github.com/aweCodeMan/driver_tsl2591

开源协议:MIT License

下载


TSL2591 driver for Android things

This driver supports Adafruit TSL2591 light sensor. It is based on the TSL2591 Arduino library, but modified for Android Things and Kotlin.

NOTE: the driver is not production ready. There is no guarantee of correctness, completeness or robustness.

How to use

Sample usage

  1. // Connecting to the sensor
  2. // NOTE: the sensor is always at address 0x29
  3. val device = PeripheralManager.getInstance().openI2cDevice("I2C1", 0x29);
  4. val sensor = TSL2591(device)
  5. // For low light conditions you can set the integration time as well as gain
  6. sensor.time = TSL.TSL2591_INTEGRATIONTIME_400MS
  7. sensor.gain = TSL.TSL2591_GAIN_HIGH
  8. // Before using, remember to power on the sensor, because it starts off unpowered
  9. sensor.powerOn()
  10. // To receive lux readings, just subscribe to the observable
  11. // NOTE: the first few values might not be the most accurate
  12. sensor.getLux().subscribe { lux -> Log.d("TSL2591", "Lux:$lux") }
  13. // Once you complete your readings, you have to power off the device and close the connection
  14. sensor.powerOff()
  15. sensor.close()