Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviamiller committed May 13, 2024
1 parent 3a723a4 commit c07588c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions components/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Analog interface {
Write(ctx context.Context, value int, extra map[string]interface{}) error
}

// AnalogRange contains themin, max, and stepSize of the analog reader.
type AnalogRange struct {
Min float32
Max float32
Expand Down
6 changes: 4 additions & 2 deletions components/board/mcp3008helper/mcp3008.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (config *MCP3008AnalogConfig) Validate(path string) error {
return nil
}

func (mar *MCP3008AnalogReader) Read(ctx context.Context, extra map[string]interface{}) (value int, analogRange board.AnalogRange, err error) {
func (mar *MCP3008AnalogReader) Read(ctx context.Context, extra map[string]interface{}) (
value int, analogRange board.AnalogRange, err error,
) {
var tx [3]byte
tx[0] = 1 // start bit
tx[1] = byte((8 + mar.Channel) << 4) // single-ended
Expand All @@ -60,7 +62,7 @@ func (mar *MCP3008AnalogReader) Read(ctx context.Context, extra map[string]inter
// garbage and might be non-zero.
val := 0x03FF & ((int(rx[1]) << 8) | int(rx[2]))

//TODO: wtf is the analog range for this
// returning blank analog range since mcp3008 will be removed soon.
return val, board.AnalogRange{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions components/board/numato/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ func (a *analog) Read(ctx context.Context, extra map[string]interface{}) (int, b
if err != nil {
return 0, board.AnalogRange{}, err
}
var max float32 = 0.0
var stepSize float32 = 0.0
var max float32
var stepSize float32
switch a.b.productID {
case 0x805:
// 128 channel usb numato has 12 bit resolution
Expand Down
5 changes: 4 additions & 1 deletion components/board/pinwrappers/analog_smoother_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ func TestAnalogSmoother1(t *testing.T) {

testutils.WaitForAssertionWithSleep(t, 10*time.Millisecond, 200, func(tb testing.TB) {
tb.Helper()
v, _, err := as.Read(context.Background(), nil)
v, analogRange, err := as.Read(context.Background(), nil)
test.That(tb, err, test.ShouldEqual, errStopReading)
test.That(tb, v, test.ShouldEqual, 52)
test.That(tb, analogRange.Min, test.ShouldEqual, 0)
test.That(tb, analogRange.Max, test.ShouldEqual, 3.3)
test.That(tb, analogRange.StepSize, test.ShouldEqual, 0.1)

// need lock to access testReader.n
testReader.mu.Lock()
Expand Down
4 changes: 2 additions & 2 deletions components/board/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func TestServerSetPWMFrequency(t *testing.T) {
}
}

//nolint:dupl

func TestServerReadAnalogReader(t *testing.T) {
type request = pb.ReadAnalogReaderRequest
type response = pb.ReadAnalogReaderResponse
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestServerWriteAnalog(t *testing.T) {
}
}

//nolint:dupl

func TestServerGetDigitalInterruptValue(t *testing.T) {
type request = pb.GetDigitalInterruptValueRequest
type response = pb.GetDigitalInterruptValueResponse
Expand Down

0 comments on commit c07588c

Please sign in to comment.