1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 20:07:40 +02:00

changed ReadBytes to get file size from stat

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

View file

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