Skip to content

Commit

Permalink
add pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Jan 9, 2025
1 parent 4b121bb commit dbc3c7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
8 changes: 4 additions & 4 deletions rpi/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@ func (pi *piPigpio) Reconfigure(
return err
}

if err := pi.reconfigureGPIOs(ctx, cfg); err != nil {
if err := pi.reconfigureGPIOs(cfg); err != nil {
return err
}

// This is the only one that actually uses ctx, but we pass it to all previous helpers, too, to
// keep the interface consistent.
if err := pi.reconfigureInterrupts(ctx, cfg); err != nil {
if err := pi.reconfigureInterrupts(cfg); err != nil {
return err
}

if err := pi.reconfigurePulls(ctx, cfg); err != nil {
if err := pi.reconfigurePulls(cfg); err != nil {
return err
}

Expand All @@ -253,7 +253,7 @@ func (pi *piPigpio) Reconfigure(
return nil
}

func (pi *piPigpio) reconfigurePulls(ctx context.Context, cfg *rpiutils.Config) error {
func (pi *piPigpio) reconfigurePulls(cfg *rpiutils.Config) error {
for _, pullConf := range cfg.Pins {
// skip pins that do not have a pull state set
if pullConf.PullState == rpiutils.PullDefault {
Expand Down
2 changes: 1 addition & 1 deletion rpi/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (gp gpioPin) SetPWMFreq(ctx context.Context, freqHz uint, extra map[string]
return gp.pi.SetPWMFreqBcom(gp.bcom, freqHz)
}

func (pi *piPigpio) reconfigureGPIOs(ctx context.Context, cfg *rpiutils.Config) error {
func (pi *piPigpio) reconfigureGPIOs(cfg *rpiutils.Config) error {
// Set new pins based on config
pi.gpioPins = map[int]*rpiGPIO{}
for _, newConfig := range cfg.Pins {
Expand Down
18 changes: 7 additions & 11 deletions rpi/interrupts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ package rpi
import "C"

import (
"context"
"fmt"
"math"

rpiutils "raspberry-pi/utils"

"github.com/pkg/errors"
"go.viam.com/rdk/components/board"
rpiutils "raspberry-pi/utils"
)

type rpiInterrupt struct {
Expand All @@ -42,7 +42,7 @@ func findInterruptByName(

// reconfigureInterrupts reconfigures the digital interrupts based on the new configuration provided.
// It reuses existing interrupts when possible and creates new ones if necessary.
func (pi *piPigpio) reconfigureInterrupts(ctx context.Context, cfg *rpiutils.Config) error {
func (pi *piPigpio) reconfigureInterrupts(cfg *rpiutils.Config) error {
// look at previous interrupt config, and see if we removed any
for _, oldConfig := range pi.pinConfigs {
if oldConfig.Type != rpiutils.PinInterrupt {
Expand Down Expand Up @@ -107,12 +107,7 @@ func (pi *piPigpio) reconfigureInterrupts(ctx context.Context, cfg *rpiutils.Con

// createNewInterrupt creates a new digital interrupt and sets it up with the specified configuration.
func (pi *piPigpio) createNewInterrupt(newConfig rpiutils.PinConfig, bcom uint) (rpiutils.ReconfigurableDigitalInterrupt, error) {
d, err := rpiutils.CreateDigitalInterrupt(
rpiutils.PinConfig{
Name: newConfig.Name,
Pin: newConfig.Pin,
Type: rpiutils.PinInterrupt,
})
d, err := rpiutils.CreateDigitalInterrupt(newConfig)
if err != nil {
return nil, err
}
Expand All @@ -123,8 +118,9 @@ func (pi *piPigpio) createNewInterrupt(newConfig rpiutils.PinConfig, bcom uint)
}

pi.interrupts[bcom] = &rpiInterrupt{
interrupt: d,
callbackID: C.uint(callbackID),
interrupt: d,
callbackID: C.uint(callbackID),
debounceMicroSeconds: uint64(newConfig.DebounceMS) * 1000,
}

return d, nil
Expand Down

0 comments on commit dbc3c7b

Please sign in to comment.