1
0
mirror of https://github.com/kidoman/embd synced 2024-12-25 06:10:04 +01:00

removing failed Stat use

This commit is contained in:
Gavin Cabbage 2015-10-10 23:58:24 -04:00
parent 9d8285ca01
commit b296368a05
3 changed files with 4 additions and 12 deletions

View File

@ -131,7 +131,7 @@ type mockI2CBus struct {
closed bool closed bool
} }
func (bus *mockI2CBus) ReadBytes(addr byte) ([]byte, error) { return []byte{0x00}, nil } func (bus *mockI2CBus) ReadBytes(addr byte, num int) ([]byte, error) { return []byte{0x00}, nil }
func (bus *mockI2CBus) ReadByte(addr byte) (byte, error) { return 0x00, nil } func (bus *mockI2CBus) ReadByte(addr byte) (byte, error) { return 0x00, nil }
func (bus *mockI2CBus) WriteBytes(addr byte, value []byte) error { return nil } func (bus *mockI2CBus) WriteBytes(addr byte, value []byte) error { return nil }
func (bus *mockI2CBus) ReadFromReg(addr, reg byte, value []byte) error { return nil } func (bus *mockI2CBus) ReadFromReg(addr, reg byte, value []byte) error { return nil }

View File

@ -101,7 +101,7 @@ func (b *i2cBus) ReadByte(addr byte) (byte, error) {
return bytes[0], nil return bytes[0], nil
} }
func (b *i2cBus) ReadBytes(addr byte) ([]byte, error) { func (b *i2cBus) ReadBytes(addr byte, num int) ([]byte, error) {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
@ -113,16 +113,10 @@ func (b *i2cBus) ReadBytes(addr byte) ([]byte, error) {
return []byte{0}, err return []byte{0}, err
} }
info, err := b.file.Stat() bytes := make([]byte, num)
if err != nil {
return []byte{0}, err
}
size := int(info.Size())
bytes := make([]byte, size)
n, _ := b.file.Read(bytes) n, _ := b.file.Read(bytes)
if n != size { if n != num {
return []byte{0}, fmt.Errorf("i2c: Unexpected number (%v) of bytes read", n) return []byte{0}, fmt.Errorf("i2c: Unexpected number (%v) of bytes read", n)
} }

2
i2c.go
View File

@ -4,8 +4,6 @@ package embd
// I2CBus interface is used to interact with the I2C bus. // I2CBus interface is used to interact with the I2C bus.
type I2CBus interface { type I2CBus interface {
// ReadBytes reads a slice of bytes from the given address.
ReadBytes(addr byte) (value []byte, err error)
// ReadByte reads a byte from the given address. // ReadByte reads a byte from the given address.
ReadByte(addr byte) (value byte, err error) ReadByte(addr byte) (value byte, err error)
// ReadBytes reads a slice of bytes from the given address. // ReadBytes reads a slice of bytes from the given address.