From 9eb1f7e7405ef13c01adc850307e3afe2b73fdeb Mon Sep 17 00:00:00 2001 From: George Sexton Date: Wed, 26 Feb 2025 21:10:14 -0700 Subject: [PATCH] Cleanups --- hd44780/af_i2c_backpack.go | 15 +++++++-------- hd44780/example_test.go | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/hd44780/af_i2c_backpack.go b/hd44780/af_i2c_backpack.go index ed9d958..126c446 100644 --- a/hd44780/af_i2c_backpack.go +++ b/hd44780/af_i2c_backpack.go @@ -40,10 +40,9 @@ func NewAdafruitI2CBackpack(bus i2c.Bus, address uint16, rows, cols int) (*HD447 return nil, err } gr := *mcp.Group(0, []int{d4, d5, d6, d7, rsPin, enablePin, backlightPin}) - grPins := gr.Pins() - reset := grPins[4].(gpio.PinOut) - enable := grPins[5].(gpio.PinOut) - bl := grPins[6].(gpio.PinOut) + reset, _ := gr.ByOffset(4).(gpio.PinOut) + enable, _ := gr.ByOffset(5).(gpio.PinOut) + bl := gr.ByOffset(6).(gpio.PinOut) return NewHD44780(gr, &reset, &enable, &bl, rows, cols) } @@ -53,9 +52,9 @@ func NewAdafruitSPIBackpack(conn spi.Conn, rows, cols int) (*HD44780, error) { chip := nxp74hc595.New(conn) // The SPI side has the same pins but in reverse order from the I2C side. gr, _ := chip.Group(d7, d6, d5, d4) - rs := chip.Pins[rsPin] - e := chip.Pins[enablePin] - bt := dev.Pins[backlightPin] + rs := &chip.Pins[rsPin] + e := &chip.Pins[enablePin] + bt := &chip.Pins[backlightPin] - return hd44780.NewHD44780(gr, &rs, &e, &bt, rows, cols) + return NewHD44780(gr, rs, e, bt, rows, cols) } diff --git a/hd44780/example_test.go b/hd44780/example_test.go index c512fdb..20a10f1 100644 --- a/hd44780/example_test.go +++ b/hd44780/example_test.go @@ -99,7 +99,6 @@ func ExampleNewAdafruitI2CBackpack() { _ = displaytest.TestTextDisplay(dev, true) } - func ExampleNewAdafruitSPIBackpack() { if _, err := host.Init(); err != nil { log.Fatal(err) @@ -122,7 +121,7 @@ func ExampleNewAdafruitSPIBackpack() { _ = display.Clear() _, _ = display.WriteString("Hello") time.Sleep(5 * time.Second) - _ = displaytest.TestTextDisplay(lcd, true) + _ = displaytest.TestTextDisplay(display, true) } func ExampleNewPCF857xBackpack() {