mirror of
https://github.com/kidoman/embd
synced 2024-10-31 23:38:44 +01:00
PR changes
This commit is contained in:
parent
b26f74efe8
commit
578a009880
@ -22,7 +22,6 @@ func main() {
|
|||||||
|
|
||||||
isl := isl29125.New(isl29125.DefaultConfig, bus)
|
isl := isl29125.New(isl29125.DefaultConfig, bus)
|
||||||
defer isl.Close()
|
defer isl.Close()
|
||||||
isl.Init()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
r, err := isl.Reading()
|
r, err := isl.Reading()
|
||||||
|
@ -113,6 +113,7 @@ type ISL29125 struct {
|
|||||||
quit chan bool
|
quit chan bool
|
||||||
|
|
||||||
mode uint8
|
mode uint8
|
||||||
|
initialized bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns an ISL29125 for a given config.
|
// New returns an ISL29125 for a given config.
|
||||||
@ -121,7 +122,12 @@ func New(config uint8, bus embd.I2CBus) *ISL29125 {
|
|||||||
return &ISL29125{Bus: bus, Poll: pollDelay, mode: config}
|
return &ISL29125{Bus: bus, Poll: pollDelay, mode: config}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ISL29125) Init() error {
|
// Setup initializes the sensor.
|
||||||
|
func (i *ISL29125) setup() error {
|
||||||
|
|
||||||
|
if i.initialized {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// verify that i2c device is reachable on specified bus and that it reports back the correct ID
|
// verify that i2c device is reachable on specified bus and that it reports back the correct ID
|
||||||
id, err := i.Bus.ReadByteFromReg(SensorAddr, RegisterDeviceID)
|
id, err := i.Bus.ReadByteFromReg(SensorAddr, RegisterDeviceID)
|
||||||
@ -169,11 +175,15 @@ func (i *ISL29125) Init() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i.initialized = true
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ISL29125) getReading() (*Reading, error) {
|
func (i *ISL29125) getReading() (*Reading, error) {
|
||||||
|
if err := i.setup(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
glog.V(1).Info("Getting reading")
|
glog.V(1).Info("Getting reading")
|
||||||
red, err := i.Bus.ReadWordFromReg(SensorAddr, RegisterRedLow)
|
red, err := i.Bus.ReadWordFromReg(SensorAddr, RegisterRedLow)
|
||||||
|
Loading…
Reference in New Issue
Block a user