ads1x15: Fixes #334 - Removed extra delay (#336)

* [ADS1x15] Removed extra delay
* Update ads1x15_test.go
Do not panic in case of unread packet.
pull/1/head
bezineb5 8 years ago committed by M-A
parent 7531d3f42a
commit 058b4ac664

@ -226,9 +226,8 @@ func (d *Dev) PinForChannel(c Channel, maxVoltage physic.ElectricPotential, f ph
configBytes := [2]byte{} configBytes := [2]byte{}
binary.BigEndian.PutUint16(configBytes[:], config) binary.BigEndian.PutUint16(configBytes[:], config)
// The wait for the ADC sample to finish is based on the sample rate plus a // The wait for the ADC sample to finish is based on the sample rate.
// small offset to be sure (0.1 millisecond). waitTime := time.Second / time.Duration(dataRate)
waitTime := time.Second/time.Duration(dataRate) + 100*time.Microsecond
return &analogPin{ return &analogPin{
adc: d, adc: d,

@ -76,7 +76,7 @@ func TestPinADC_Read(t *testing.T) {
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{ {
Addr: 0x48, Addr: 0x48,
W: []byte{0x1, 0x91, 0xc3}, W: []byte{0x1, 0x91, 0x3},
R: []byte{}, R: []byte{},
}, },
{ {
@ -92,7 +92,7 @@ func TestPinADC_Read(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Obtain an analog pin from the ADC // Obtain an analog pin from the ADC
pin, err := d.PinForChannel(Channel0Minus3, 5*physic.Volt, 1*physic.Hertz, SaveEnergy) pin, err := d.PinForChannel(Channel0Minus3, 5*physic.Volt, 1*physic.Hertz, BestQuality)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -120,13 +120,12 @@ func TestPinADC_Read(t *testing.T) {
} }
} }
/* https://github.com/google/periph/issues/334
func TestPinADC_ReadContinous(t *testing.T) { func TestPinADC_ReadContinous(t *testing.T) {
b := i2ctest.Playback{ b := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
{ {
Addr: 0x48, Addr: 0x48,
W: []byte{0x1, 0x91, 0x3}, W: []byte{0x1, 0x91, 0xc3},
R: []byte{}, R: []byte{},
}, },
{ {
@ -136,7 +135,7 @@ func TestPinADC_ReadContinous(t *testing.T) {
}, },
{ {
Addr: 0x48, Addr: 0x48,
W: []byte{0x1, 0x91, 0x3}, W: []byte{0x1, 0x91, 0xc3},
R: []byte{}, R: []byte{},
}, },
{ {
@ -144,10 +143,20 @@ func TestPinADC_ReadContinous(t *testing.T) {
W: []byte{0x0}, W: []byte{0x0},
R: []byte{0x52, 0xc0}, R: []byte{0x52, 0xc0},
}, },
// We add one extra exchange, as halting the polling is not instant // We add 2 extra exchanges, as halting the polling is not instant
{ {
Addr: 0x48, Addr: 0x48,
W: []byte{0x1, 0x91, 0x3}, W: []byte{0x1, 0x91, 0xc3},
R: []byte{},
},
{
Addr: 0x48,
W: []byte{0x0},
R: []byte{0x52, 0xc0},
},
{
Addr: 0x48,
W: []byte{0x1, 0x91, 0xc3},
R: []byte{}, R: []byte{},
}, },
{ {
@ -156,6 +165,7 @@ func TestPinADC_ReadContinous(t *testing.T) {
R: []byte{0x52, 0xc0}, R: []byte{0x52, 0xc0},
}, },
}, },
DontPanic: true,
} }
rawValues := []int32{21200, 21184} rawValues := []int32{21200, 21184}
@ -166,7 +176,7 @@ func TestPinADC_ReadContinous(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Obtain an analog pin from the ADC // Obtain an analog pin from the ADC
pin, err := d.PinForChannel(Channel0Minus3, 5*physic.Volt, 100*physic.Hertz, BestQuality) pin, err := d.PinForChannel(Channel0Minus3, 5*physic.Volt, 100*physic.Hertz, SaveEnergy)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -198,4 +208,3 @@ func TestPinADC_ReadContinous(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
*/

Loading…
Cancel
Save