Skip to content

Commit 24cf7eb

Browse files
committed
Merge branch 'main' of https://github.com/oliviamiller/rdk
2 parents 28ff656 + c5f8e8b commit 24cf7eb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

components/board/board.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
commonpb "go.viam.com/api/common/v1"
1212
pb "go.viam.com/api/component/board/v1"
1313

14+
"go.viam.com/rdk/components/board/pinwrappers"
1415
"go.viam.com/rdk/data"
1516
"go.viam.com/rdk/resource"
1617
"go.viam.com/rdk/robot"

components/board/pinwrappers/digital_interrupts.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,19 @@ func (i *BasicDigitalInterrupt) Reconfigure(conf board.DigitalInterruptConfig) e
115115
i.cfg = conf
116116
return nil
117117
}
118+
119+
// RemoveCallback removes a listener for interrupts.
120+
func RemoveCallback(di board.DigitalInterrupt, c chan board.Tick) {
121+
i := di.(*BasicDigitalInterrupt)
122+
i.mu.Lock()
123+
defer i.mu.Unlock()
124+
for id := range i.callbacks {
125+
if i.callbacks[id] == c {
126+
// To remove this item, we replace it with the last item in the list, then truncate the
127+
// list by 1.
128+
i.callbacks[id] = i.callbacks[len(i.callbacks)-1]
129+
i.callbacks = i.callbacks[:len(i.callbacks)-1]
130+
break
131+
}
132+
}
133+
}

components/board/pinwrappers/digital_interrupts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestBasicDigitalInterrupt1(t *testing.T) {
5151
test.That(t, v.High, test.ShouldBeTrue)
5252
test.That(t, v.TimestampNanosec, test.ShouldEqual, timeNanoSec)
5353

54-
i.RemoveCallback(c)
54+
RemoveCallback(i, c)
5555

5656
c = make(chan board.Tick, 2)
5757
i.AddCallback(c)
@@ -111,8 +111,8 @@ func TestRemoveCallbackDigitalInterrupt(t *testing.T) {
111111
i.AddCallback(c2)
112112
test.That(t, ret, test.ShouldBeTrue)
113113

114-
i.RemoveCallback(c1)
115-
i.RemoveCallback(c1)
114+
RemoveCallback(i, c1)
115+
RemoveCallback(i, c1)
116116

117117
ret2 := false
118118
result := make(chan bool, 1)

0 commit comments

Comments
 (0)