@@ -18,25 +18,26 @@ import (
18
18
// built on top of it come with their own respective default addresses.
19
19
const DefaultAddress = 0x49
20
20
21
- // empirically determined standardDelay, the one from the official library seems to be too short (250us)
22
- const defaultDelay = 100 * time .Millisecond
21
+ // DefaultReadDelay is an empirically determined delay used when reading from the device,
22
+ // the one from the official library seems to be too short (250us)
23
+ const DefaultReadDelay = 100 * time .Millisecond
23
24
24
25
const (
25
26
seesawHwIdCodeSAMD09 = 0x55 // HW ID code for SAMD09
26
27
seesawHwIdCodeTINY8x7 = 0x87 // HW ID code for ATtiny817
27
28
)
28
29
29
30
type Device struct {
30
- bus drivers.I2C
31
- Address uint16
32
- standardDelay time.Duration
31
+ bus drivers.I2C
32
+ Address uint16
33
+ ReadDelay time.Duration
33
34
}
34
35
35
36
func New (bus drivers.I2C ) * Device {
36
37
return & Device {
37
- bus : bus ,
38
- Address : DefaultAddress ,
39
- standardDelay : defaultDelay ,
38
+ bus : bus ,
39
+ Address : DefaultAddress ,
40
+ ReadDelay : DefaultReadDelay ,
40
41
}
41
42
}
42
43
@@ -92,16 +93,16 @@ func (d *Device) WriteRegister(module ModuleBaseAddress, function FunctionAddres
92
93
// ReadRegister reads a single register from seesaw
93
94
func (d * Device ) ReadRegister (module ModuleBaseAddress , function FunctionAddress ) (byte , error ) {
94
95
var buf [1 ]byte
95
- err := d .Read (module , function , buf [:], d . standardDelay )
96
+ err := d .Read (module , function , buf [:])
96
97
if err != nil {
97
98
return 0 , err
98
99
}
99
100
return buf [0 ], nil
100
101
}
101
102
102
- // Read reads a number of bytes from the device after sending the read command and waiting 'standardDelay '. The delays depend
103
+ // Read reads a number of bytes from the device after sending the read command and waiting 'ReadDelay '. The delays depend
103
104
// on the module and function and are documented in the seesaw datasheet
104
- func (d * Device ) Read (module ModuleBaseAddress , function FunctionAddress , buf []byte , delay time. Duration ) error {
105
+ func (d * Device ) Read (module ModuleBaseAddress , function FunctionAddress , buf []byte ) error {
105
106
var cmd [2 ]byte
106
107
cmd [0 ] = byte (module )
107
108
cmd [1 ] = byte (function )
@@ -113,7 +114,7 @@ func (d *Device) Read(module ModuleBaseAddress, function FunctionAddress, buf []
113
114
114
115
// This is needed for the client seesaw device to flush its RX buffer and process the command.
115
116
// See seesaw datasheet for timings for specific modules.
116
- time .Sleep (delay )
117
+ time .Sleep (d . ReadDelay )
117
118
118
119
return d .bus .Tx (d .Address , nil , buf )
119
120
}
0 commit comments