@@ -45,9 +45,9 @@ type SPIBus struct {
4545}
4646
4747type Buser interface {
48- configure ()
49- tx (data []byte , isCommand bool )
50- setAddress (address uint16 )
48+ configure () error
49+ tx (data []byte , isCommand bool ) error
50+ setAddress (address uint16 ) error
5151}
5252
5353type VccMode uint8
@@ -193,8 +193,7 @@ func (d *Device) Display() error {
193193 d .Command (uint8 (d .height / 8 ) - 1 )
194194 }
195195
196- d .Tx (d .buffer , false )
197- return nil
196+ return d .Tx (d .buffer , false )
198197}
199198
200199// SetPixel enables or disables a pixel in the buffer
@@ -244,21 +243,23 @@ func (d *Device) Command(command uint8) {
244243}
245244
246245// setAddress sets the address to the I2C bus
247- func (b * I2CBus ) setAddress (address uint16 ) {
246+ func (b * I2CBus ) setAddress (address uint16 ) error {
248247 b .Address = address
248+ return nil
249249}
250250
251251// setAddress does nothing, but it's required to avoid reflection
252- func (b * SPIBus ) setAddress (address uint16 ) {
252+ func (b * SPIBus ) setAddress (address uint16 ) error {
253253 // do nothing
254254 println ("trying to Configure an address on a SPI device" )
255+ return nil
255256}
256257
257258// configure does nothing, but it's required to avoid reflection
258- func (b * I2CBus ) configure () { }
259+ func (b * I2CBus ) configure () error { return nil }
259260
260261// configure configures some pins with the SPI bus
261- func (b * SPIBus ) configure () {
262+ func (b * SPIBus ) configure () error {
262263 b .csPin .Low ()
263264 b .dcPin .Low ()
264265 b .resetPin .Low ()
@@ -268,41 +269,47 @@ func (b *SPIBus) configure() {
268269 b .resetPin .Low ()
269270 time .Sleep (10 * time .Millisecond )
270271 b .resetPin .High ()
272+
273+ return nil
271274}
272275
273276// Tx sends data to the display
274- func (d * Device ) Tx (data []byte , isCommand bool ) {
275- d .bus .tx (data , isCommand )
277+ func (d * Device ) Tx (data []byte , isCommand bool ) error {
278+ return d .bus .tx (data , isCommand )
276279}
277280
278281// tx sends data to the display (I2CBus implementation)
279- func (b * I2CBus ) tx (data []byte , isCommand bool ) {
282+ func (b * I2CBus ) tx (data []byte , isCommand bool ) error {
280283 if isCommand {
281- legacy .WriteRegister (b .wire , uint8 (b .Address ), 0x00 , data )
284+ return legacy .WriteRegister (b .wire , uint8 (b .Address ), 0x00 , data )
282285 } else {
283- legacy .WriteRegister (b .wire , uint8 (b .Address ), 0x40 , data )
286+ return legacy .WriteRegister (b .wire , uint8 (b .Address ), 0x40 , data )
284287 }
285288}
286289
287290// tx sends data to the display (SPIBus implementation)
288- func (b * SPIBus ) tx (data []byte , isCommand bool ) {
291+ func (b * SPIBus ) tx (data []byte , isCommand bool ) error {
292+ var err error
293+
289294 if isCommand {
290295 b .csPin .High ()
291296 time .Sleep (1 * time .Millisecond )
292297 b .dcPin .Low ()
293298 b .csPin .Low ()
294299
295- b .wire .Tx (data , nil )
300+ err = b .wire .Tx (data , nil )
296301 b .csPin .High ()
297302 } else {
298303 b .csPin .High ()
299304 time .Sleep (1 * time .Millisecond )
300305 b .dcPin .High ()
301306 b .csPin .Low ()
302307
303- b .wire .Tx (data , nil )
308+ err = b .wire .Tx (data , nil )
304309 b .csPin .High ()
305310 }
311+
312+ return err
306313}
307314
308315// Size returns the current size of the display.
0 commit comments