Documentation ¶
Overview ¶
Package tsl2591 interacts with TSL2591 lux sensors
Heavily inspired by https://github.com/mstahl/tsl2591 and https://github.com/adafruit/Adafruit_TSL2591_Library/ as well as https://github.com/adafruit/Adafruit_TSL2591_Library/blob/master/Adafruit_TSL2591.cpp
Index ¶
- Constants
- Variables
- type Gain
- type IntegrationTime
- type Opts
- type Persist
- type TSL2591
- func (tsl *TSL2591) Disable() error
- func (tsl *TSL2591) Enable() error
- func (tsl *TSL2591) FullSpectrum() (uint32, error)
- func (tsl *TSL2591) Infrared() (uint16, error)
- func (tsl *TSL2591) Lux() (float64, error)
- func (tsl *TSL2591) RawLuminosity() (uint16, uint16, error)
- func (tsl *TSL2591) SetGain(gain Gain) error
- func (tsl *TSL2591) SetTiming(timing IntegrationTime) error
- func (tsl *TSL2591) Visible() (uint32, error)
- type UnexpectedDeviceIDError
Constants ¶
const ( // FullSpectrum is channel 0 FullSpectrum byte = 0 // Infrared is channel 1 Infrared byte = 1 // Visible is FullSpectrum minus Infrared, i.e. channel 0 - channel 1 Visible byte = 2 // Addr is the default I2C address for the TSL2591 Addr uint16 = 0x29 // Device ID of the TSL2591 chip DeviceID byte = 0x50 // CommandBits is 1010 0000 - sets bits 7 and 5 to indicate 'command normal' CommandBit byte = 0xa0 // ClearInt command for 'Clear ALS and no persist ALS interrupt' ClearInt byte = 0xe7 // TestInt command for 'Interrupt set - forces an interrupt' TestInt byte = 0xe4 // WordBit to read/write word rather than byte WordBit byte = 0x20 // BlockBit to block read/write BlockBit byte = 0x10 // EnablePowerOff to set 'enable' register to disabled EnablePowerOff byte = 0x00 // EnablePowerOn to set 'enable' register to enabled EnablePowerOn byte = 0x01 // EnableAEN commands the ALS function. 1 enables, 0 disables EnableAEN byte = 0x02 // EnableAIEN permits ALS interrupts to be generated, subject to the persist filter EnableAIEN byte = 0x10 // EnableNPIEN commands that NP Threshold conditions will generate an interrupt, bypassing the persist filter EnableNPIEN byte = 0x80 // LuxDF is the Lux cooefficient LuxDF float64 = 408.0 // LuxCoefB is the channel0 coefficient LuxCoefB float64 = 1.64 // LuxCoefC is channel1 coefficient A LuxCoefC float64 = 0.59 // LuxCoefD is channel2 coefficient B LuxCoefD float64 = 0.86 // MaxCount100ms sensor count MaxCount100ms uint16 = 0x8fff // MaxCount sensor count MaxCount uint16 = 0xffff )
General purpose constants
const ( // RegisterEnable is the enable register RegisterEnable byte = 0x00 // RegisterControl is the control register RegisterControl byte = 0x01 // RegisterThresholdAILTL is the ALS low threshold lower byte RegisterThresholdAILTL byte = 0x04 // RegisterThresholdAILTH is the ALS low threshold upper byte RegisterThresholdAILTH byte = 0x05 // RegisterThresholdAIHTL is the ALS high threshold lower byte RegisterThresholdAIHTL byte = 0x06 // RegisterThresholdAIHTH is the ALS high threshold upper byte RegisterThresholdAIHTH byte = 0x07 // RegisterThresholdNPAILTL is the no-persist ALS low threshold lower byte RegisterThresholdNPAILTL byte = 0x08 // RegisterThresholdNPAILTH is the no-persist ALS low threshold higher byte RegisterThresholdNPAILTH byte = 0x09 // RegisterThresholdNPAIHTL is the no-persist ALS high threshold lower byte RegisterThresholdNPAIHTL byte = 0x0a // RegisterThresholdNPAIHTH is the no-persist ALS high threshold higher byte RegisterThresholdNPAIHTH byte = 0x0b // RegisterPersistFilter is the interrupt persistence filter RegisterPersistFilter byte = 0x0c // RegisterPackagePID is for package identification RegisterPackagePID byte = 0x11 // RegisterDeviceID is for device identification RegisterDeviceID byte = 0x12 // RegisterDeviceStatus is for internal status RegisterDeviceStatus byte = 0x13 // RegisterChan0Low is channel 0 data, low byte RegisterChan0Low byte = 0x14 // RegisterChan0High is channel 0 data, high byte RegisterChan0High byte = 0x15 // RegisterChan1Low is channel 1 data, low byte RegisterChan1Low byte = 0x16 // RegisterChan1High is channel 1 data, high byte RegisterChan1High byte = 0x17 )
Register maps
Variables ¶
var ErrOverflow = errors.New("overflow reading light channels")
Functions ¶
This section is empty.
Types ¶
type IntegrationTime ¶
type IntegrationTime byte
const ( // IntegrationTime100MS is 100 millis IntegrationTime100MS IntegrationTime = 0x00 // IntegrationTime200MS is 200 millis IntegrationTime200MS IntegrationTime = 0x01 // IntegrationTime300MS is 300 millis IntegrationTime300MS IntegrationTime = 0x02 // IntegrationTime400MS is 400 millis IntegrationTime400MS IntegrationTime = 0x03 // IntegrationTime500MS is 500 millis IntegrationTime500MS IntegrationTime = 0x04 // IntegrationTime600MS is 600 millis IntegrationTime600MS IntegrationTime = 0x05 )
Constants for sensor integration timing
type Opts ¶
type Opts struct { // Bus name, alias or its number. // See https://pkg.go.dev/periph.io/x/conn/v3/i2c/i2creg#Open for more info. Bus string Gain Gain Timing IntegrationTime }
Opts holds various configuration options for the sensor
func DefaultOptions ¶
func DefaultOptions() *Opts
type Persist ¶
type Persist byte
const ( // PersistEvery is every ALS cycle generates an interrupt PersistEvery Persist = 0x00 // PersistAny for any value outside of threshold range PersistAny Persist = 0x01 // Persist2 for 2 consecutive values out of range Persist2 Persist = 0x02 // Persist3 for 3 consecutive values out of range Persist3 Persist = 0x03 // Persist5 for 5 consecutive values out of range Persist5 Persist = 0x04 // Persist10 for 10 consecutive values out of range Persist10 Persist = 0x05 // Persist15 for 15 consecutive values out of range Persist15 Persist = 0x06 // Persist20 for 20 consecutive values out of range Persist20 Persist = 0x07 // Persist25 for 25 consecutive values out of range Persist25 Persist = 0x08 // Persist30 for 30 consecutive values out of range Persist30 Persist = 0x09 // Persist35 for 35 consecutive values out of range Persist35 Persist = 0x0a // Persist40 for 40 consecutive values out of range Persist40 Persist = 0x0b // Persist45 for 45 consecutive values out of range Persist45 Persist = 0x0c // Persist50 for 50 consecutive values out of range Persist50 Persist = 0x0d // Persist55 for 55 consecutive values out of range Persist55 Persist = 0x0e // Persist60 for 60 consecutive values out of range Persist60 Persist = 0x0f )
Constants for adjusting the persistence filter
type TSL2591 ¶
type TSL2591 struct {
// contains filtered or unexported fields
}
TSL2591 holds board setup detail
func NewTSL2591 ¶
NewTSL2591 sets up a TSL2591 chip via the I2C protocol, sets its gain and timing attributes, and returns an error if any occurred in that process or if the TSL2591 was not found
func (*TSL2591) FullSpectrum ¶
FullSpectrum returns the full spectrum value
func (*TSL2591) RawLuminosity ¶
RawLuminosity reads from the sensor
func (*TSL2591) SetTiming ¶
func (tsl *TSL2591) SetTiming(timing IntegrationTime) error
SetTiming sets TSL2591 timing. Chip is enabled, timing set, then disabled
type UnexpectedDeviceIDError ¶
func (UnexpectedDeviceIDError) Error ¶
func (e UnexpectedDeviceIDError) Error() string