tsl2591

package
v0.0.0-...-f368eb9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TSL2591_VISIBLE      byte = 2 ///< channel 0 - channel 1
	TSL2591_INFRARED     byte = 1 ///< channel 1
	TSL2591_FULLSPECTRUM byte = 0 ///< channel 0

	TSL2591_ADDR        uint16 = 0x29 ///< Default I2C address
	TSL2591_COMMAND_BIT byte   = 0xA0 ///< 1010 0000: bits 7 and 5 for 'command normal'

	TSL2591_WORD_BIT  byte = 0x20 ///< 1 = read/write word rather than byte
	TSL2591_BLOCK_BIT byte = 0x10 ///< 1 = using block read/write

	TSL2591_ENABLE_POWEROFF byte = 0x00 ///< Flag for ENABLE register to disable
	TSL2591_ENABLE_POWERON  byte = 0x01 ///< Flag for ENABLE register to enable
	TSL2591_ENABLE_AEN      byte = 0x02 ///< ALS Enable. This field activates ALS function. Writing a one activates the ALS. Writing a zero disables the ALS.
	TSL2591_ENABLE_AIEN     byte = 0x10 ///< ALS Interrupt Enable. When asserted permits ALS interrupts to be generated, subject to the persist filter.
	TSL2591_ENABLE_NPIEN    byte = 0x80 ///< No Persist Interrupt Enable. When asserted NP Threshold conditions will generate an interrupt, bypassing the persist filter

	TSL2591_LUX_DF    float64 = 408.0 ///< Lux cooefficient
	TSL2591_LUX_COEFB float64 = 1.64  ///< CH0 coefficient
	TSL2591_LUX_COEFC float64 = 0.59  ///< CH1 coefficient A
	TSL2591_LUX_COEFD float64 = 0.86  ///< CH2 coefficient B
)
View Source
const (
	TSL2591_REGISTER_ENABLE            byte = 0x00 // Enable register
	TSL2591_REGISTER_CONTROL           byte = 0x01 // Control register
	TSL2591_REGISTER_THRESHOLD_AILTL   byte = 0x04 // ALS low threshold lower byte
	TSL2591_REGISTER_THRESHOLD_AILTH   byte = 0x05 // ALS low threshold upper byte
	TSL2591_REGISTER_THRESHOLD_AIHTL   byte = 0x06 // ALS high threshold lower byte
	TSL2591_REGISTER_THRESHOLD_AIHTH   byte = 0x07 // ALS high threshold upper byte
	TSL2591_REGISTER_THRESHOLD_NPAILTL byte = 0x08 // No Persist ALS low threshold lower byte
	TSL2591_REGISTER_THRESHOLD_NPAILTH byte = 0x09 // No Persist ALS low threshold higher byte
	TSL2591_REGISTER_THRESHOLD_NPAIHTL byte = 0x0A // No Persist ALS high threshold lower byte
	TSL2591_REGISTER_THRESHOLD_NPAIHTH byte = 0x0B // No Persist ALS high threshold higher byte
	TSL2591_REGISTER_PERSIST_FILTER    byte = 0x0C // Interrupt persistence filter
	TSL2591_REGISTER_PACKAGE_PID       byte = 0x11 // Package Identification
	TSL2591_REGISTER_DEVICE_ID         byte = 0x12 // Device Identification
	TSL2591_REGISTER_DEVICE_STATUS     byte = 0x13 // Internal Status
	TSL2591_REGISTER_CHAN0_LOW         byte = 0x14 // Channel 0 data, low byte
	TSL2591_REGISTER_CHAN0_HIGH        byte = 0x15 // Channel 0 data, high byte
	TSL2591_REGISTER_CHAN1_LOW         byte = 0x16 // Channel 1 data, low byte
	TSL2591_REGISTER_CHAN1_HIGH        byte = 0x17 // Channel 1 data, high byte
)

TSL2591 Register map

View Source
const (
	TSL2591_INTEGRATIONTIME_100MS byte = 0x00 // 100 millis
	TSL2591_INTEGRATIONTIME_200MS byte = 0x01 // 200 millis
	TSL2591_INTEGRATIONTIME_300MS byte = 0x02 // 300 millis
	TSL2591_INTEGRATIONTIME_400MS byte = 0x03 // 400 millis
	TSL2591_INTEGRATIONTIME_500MS byte = 0x04 // 500 millis
	TSL2591_INTEGRATIONTIME_600MS byte = 0x05 // 600 millis
)

Constants for adjusting the sensor integration timing

View Source
const (
	TSL2591_GAIN_LOW  byte = 0x00 /// low gain (1x)
	TSL2591_GAIN_MED  byte = 0x10 /// medium gain (25x)
	TSL2591_GAIN_HIGH byte = 0x20 /// medium gain (428x)
	TSL2591_GAIN_MAX  byte = 0x30 /// max gain (9876x)
)

Constants for adjusting the sensor gain

Variables

This section is empty.

Functions

func GainToString

func GainToString(value byte) string

func GetNormalizedOutput

func GetNormalizedOutput(spectrumType byte, ch0, ch1 uint16) float64

Returns the normalized output for a given spectrum type

func IntegrationTimeToString

func IntegrationTimeToString(value byte) string

Types

type TSL2591

type TSL2591 struct {
	Enabled bool
	Timing  byte
	Gain    byte
	Device  *i2c.Device
	*sync.Mutex
}

func NewTSL2591

func NewTSL2591(gain byte, timing byte, path string) (*TSL2591, error)

Connect to a TSL2591 via I2C protocol & set gain/timing

func (*TSL2591) CalculateLux

func (tsl *TSL2591) CalculateLux(ch0, ch1 uint16) (float64, error)

func (*TSL2591) Disable

func (tsl *TSL2591) Disable() error

Disable the sensor

func (*TSL2591) Enable

func (tsl *TSL2591) Enable() error

Enable the sensor

func (*TSL2591) GetFullLuminosity

func (tsl *TSL2591) GetFullLuminosity() (uint16, uint16, error)

Read from the light sensor's channels

func (*TSL2591) SetGain

func (tsl *TSL2591) SetGain(gain byte) error

Set the gain for the sensor

func (*TSL2591) SetOptimalGain

func (tsl *TSL2591) SetOptimalGain() error

func (*TSL2591) SetTiming

func (tsl *TSL2591) SetTiming(timing byte) error

Set the integration timing for the sensor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL