i2c: small refactor and increase test coverage for tsl2561

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-12 16:44:15 +02:00
parent 913ea01d3a
commit 4714568628
2 changed files with 16 additions and 9 deletions

View File

@ -418,15 +418,7 @@ func (d *TSL2561Driver) getData() (broadband uint16, ir uint16, err error) {
return
}
// Wait x ms for ADC to complete
switch d.integrationTime {
case TSL2561IntegrationTime13MS:
time.Sleep(15 * time.Millisecond)
case TSL2561IntegrationTime101MS:
time.Sleep(120 * time.Millisecond)
case TSL2561IntegrationTime402MS:
time.Sleep(450 * time.Millisecond)
}
d.waitForADC()
// Reads a two byte value from channel 0 (visible + infrared)
broadband, err = d.connection.ReadWordData(tsl2561CommandBit | tsl2561WordBit | tsl2561RegisterChan0Low)
@ -504,3 +496,15 @@ func (d *TSL2561Driver) getBM(ratio uint32) (b uint32, m uint32) {
}
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
}

View File

@ -242,6 +242,7 @@ func TestTSL2561getClipScaling13MS(t *testing.T) {
WithTSL2561AutoGain)
c, s := d.getClipScaling()
d.waitForADC()
gobottest.Assert(t, c, uint16(tsl2561Clipping13MS))
gobottest.Assert(t, s, uint32(tsl2561LuxCHScaleTInt0))
}
@ -253,6 +254,7 @@ func TestTSL2561getClipScaling101MS(t *testing.T) {
WithTSL2561AutoGain)
c, s := d.getClipScaling()
d.waitForADC()
gobottest.Assert(t, c, uint16(tsl2561Clipping101MS))
gobottest.Assert(t, s, uint32(tsl2561LuxChScaleTInt1))
}
@ -264,6 +266,7 @@ func TestTSL2561getClipScaling402MS(t *testing.T) {
WithTSL2561AutoGain)
c, s := d.getClipScaling()
d.waitForADC()
gobottest.Assert(t, c, uint16(tsl2561Clipping402MS))
gobottest.Assert(t, s, uint32(1<<tsl2561LuxChScale))
}