From 578a00988096f90ad228384f6a784fbd5c624914 Mon Sep 17 00:00:00 2001 From: Ryan Cox Date: Tue, 25 Aug 2015 21:03:19 -0700 Subject: [PATCH] PR changes --- samples/isl29125.go | 1 - sensor/isl29125/isl29125.go | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/samples/isl29125.go b/samples/isl29125.go index 799a8e2..0603da1 100644 --- a/samples/isl29125.go +++ b/samples/isl29125.go @@ -22,7 +22,6 @@ func main() { isl := isl29125.New(isl29125.DefaultConfig, bus) defer isl.Close() - isl.Init() for { r, err := isl.Reading() diff --git a/sensor/isl29125/isl29125.go b/sensor/isl29125/isl29125.go index 03b5293..d682753 100644 --- a/sensor/isl29125/isl29125.go +++ b/sensor/isl29125/isl29125.go @@ -112,7 +112,8 @@ type ISL29125 struct { readings chan *Reading quit chan bool - mode uint8 + mode uint8 + initialized bool } // 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} } -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 id, err := i.Bus.ReadByteFromReg(SensorAddr, RegisterDeviceID) @@ -169,11 +175,15 @@ func (i *ISL29125) Init() error { return err } + i.initialized = true return nil } func (i *ISL29125) getReading() (*Reading, error) { + if err := i.setup(); err != nil { + return nil, err + } glog.V(1).Info("Getting reading") red, err := i.Bus.ReadWordFromReg(SensorAddr, RegisterRedLow)