i2c: small refactor and increase test coverage for tsl2561
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
913ea01d3a
commit
4714568628
|
@ -418,15 +418,7 @@ func (d *TSL2561Driver) getData() (broadband uint16, ir uint16, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait x ms for ADC to complete
|
d.waitForADC()
|
||||||
switch d.integrationTime {
|
|
||||||
case TSL2561IntegrationTime13MS:
|
|
||||||
time.Sleep(15 * time.Millisecond)
|
|
||||||
case TSL2561IntegrationTime101MS:
|
|
||||||
time.Sleep(120 * time.Millisecond)
|
|
||||||
case TSL2561IntegrationTime402MS:
|
|
||||||
time.Sleep(450 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads a two byte value from channel 0 (visible + infrared)
|
// Reads a two byte value from channel 0 (visible + infrared)
|
||||||
broadband, err = d.connection.ReadWordData(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan0Low)
|
broadband, err = d.connection.ReadWordData(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan0Low)
|
||||||
|
@ -504,3 +496,15 @@ func (d *TSL2561Driver) getBM(ratio uint32) (b uint32, m uint32) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *TSL2561Driver) waitForADC() {
|
||||||
|
switch d.integrationTime {
|
||||||
|
case TSL2561IntegrationTime13MS:
|
||||||
|
time.Sleep(15 * time.Millisecond)
|
||||||
|
case TSL2561IntegrationTime101MS:
|
||||||
|
time.Sleep(120 * time.Millisecond)
|
||||||
|
case TSL2561IntegrationTime402MS:
|
||||||
|
time.Sleep(450 * time.Millisecond)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -242,6 +242,7 @@ func TestTSL2561getClipScaling13MS(t *testing.T) {
|
||||||
WithTSL2561AutoGain)
|
WithTSL2561AutoGain)
|
||||||
|
|
||||||
c, s := d.getClipScaling()
|
c, s := d.getClipScaling()
|
||||||
|
d.waitForADC()
|
||||||
gobottest.Assert(t, c, uint16(tsl2561Clipping13MS))
|
gobottest.Assert(t, c, uint16(tsl2561Clipping13MS))
|
||||||
gobottest.Assert(t, s, uint32(tsl2561LuxCHScaleTInt0))
|
gobottest.Assert(t, s, uint32(tsl2561LuxCHScaleTInt0))
|
||||||
}
|
}
|
||||||
|
@ -253,6 +254,7 @@ func TestTSL2561getClipScaling101MS(t *testing.T) {
|
||||||
WithTSL2561AutoGain)
|
WithTSL2561AutoGain)
|
||||||
|
|
||||||
c, s := d.getClipScaling()
|
c, s := d.getClipScaling()
|
||||||
|
d.waitForADC()
|
||||||
gobottest.Assert(t, c, uint16(tsl2561Clipping101MS))
|
gobottest.Assert(t, c, uint16(tsl2561Clipping101MS))
|
||||||
gobottest.Assert(t, s, uint32(tsl2561LuxChScaleTInt1))
|
gobottest.Assert(t, s, uint32(tsl2561LuxChScaleTInt1))
|
||||||
}
|
}
|
||||||
|
@ -264,6 +266,7 @@ func TestTSL2561getClipScaling402MS(t *testing.T) {
|
||||||
WithTSL2561AutoGain)
|
WithTSL2561AutoGain)
|
||||||
|
|
||||||
c, s := d.getClipScaling()
|
c, s := d.getClipScaling()
|
||||||
|
d.waitForADC()
|
||||||
gobottest.Assert(t, c, uint16(tsl2561Clipping402MS))
|
gobottest.Assert(t, c, uint16(tsl2561Clipping402MS))
|
||||||
gobottest.Assert(t, s, uint32(1<<tsl2561LuxChScale))
|
gobottest.Assert(t, s, uint32(1<<tsl2561LuxChScale))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue