Fix copying/pointer issues

pull/98/head
George Sexton 1 year ago
parent 9a711a0835
commit eb1ed879bc

@ -207,8 +207,8 @@ func (dev *Dev) String() string {
// Pins returns the set of pins that make up this group. // Pins returns the set of pins that make up this group.
func (gr *Group) Pins() []pin.Pin { func (gr *Group) Pins() []pin.Pin {
pins := make([]pin.Pin, len(gr.pins)) pins := make([]pin.Pin, len(gr.pins))
for ix, p := range gr.pins { for ix := range len(gr.pins) {
pins[ix] = &p pins[ix] = &gr.pins[ix]
} }
return pins return pins
} }
@ -217,10 +217,10 @@ func (gr *Group) Pins() []pin.Pin {
// to the device. // to the device.
func (gr *Group) groupMaskToDevMask(mask gpio.GPIOValue) gpio.GPIOValue { func (gr *Group) groupMaskToDevMask(mask gpio.GPIOValue) gpio.GPIOValue {
m := gpio.GPIOValue(0) m := gpio.GPIOValue(0)
for ix, pin := range gr.pins { for ix := range len(gr.pins) {
currentBit := gpio.GPIOValue(1 << ix) currentBit := gpio.GPIOValue(1 << ix)
if (mask & currentBit) == currentBit { if (mask & currentBit) == currentBit {
pinBit := gpio.GPIOValue(1) << pin.number pinBit := gpio.GPIOValue(1) << gr.pins[ix].number
m |= pinBit m |= pinBit
} }
} }
@ -234,9 +234,9 @@ func (gr *Group) ByOffset(offset int) pin.Pin {
// Return the GPIO pin by name. // Return the GPIO pin by name.
func (gr *Group) ByName(name string) pin.Pin { func (gr *Group) ByName(name string) pin.Pin {
for _, pin := range gr.pins { for ix := range len(gr.pins) {
if pin.name == name { if gr.pins[ix].name == name {
return &pin return &gr.pins[ix]
} }
} }
return nil return nil
@ -244,9 +244,9 @@ func (gr *Group) ByName(name string) pin.Pin {
// Return the GPIO pin by it's pin number on the device. // Return the GPIO pin by it's pin number on the device.
func (gr *Group) ByNumber(number int) pin.Pin { func (gr *Group) ByNumber(number int) pin.Pin {
for _, pin := range gr.pins { for ix := range len(gr.pins) {
if pin.number == number { if gr.pins[ix].number == number {
return &pin return &gr.pins[ix]
} }
} }
return nil return nil

Loading…
Cancel
Save