diff --git a/components/board/board.go b/components/board/board.go index e1da4dce3a7..fd0660b6506 100644 --- a/components/board/board.go +++ b/components/board/board.go @@ -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 diff --git a/components/board/mcp3008helper/mcp3008.go b/components/board/mcp3008helper/mcp3008.go index 4d2d0338f73..45c3755b8c4 100644 --- a/components/board/mcp3008helper/mcp3008.go +++ b/components/board/mcp3008helper/mcp3008.go @@ -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 @@ -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 } diff --git a/components/board/numato/board.go b/components/board/numato/board.go index aff0b9e5d8b..c0fde351bbb 100644 --- a/components/board/numato/board.go +++ b/components/board/numato/board.go @@ -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 diff --git a/components/board/pinwrappers/analog_smoother_test.go b/components/board/pinwrappers/analog_smoother_test.go index b3dc2626d4b..deb4342d0a6 100644 --- a/components/board/pinwrappers/analog_smoother_test.go +++ b/components/board/pinwrappers/analog_smoother_test.go @@ -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() diff --git a/components/board/server_test.go b/components/board/server_test.go index d9048dc94d0..bf7ccd333bc 100644 --- a/components/board/server_test.go +++ b/components/board/server_test.go @@ -451,7 +451,7 @@ func TestServerSetPWMFrequency(t *testing.T) { } } -//nolint:dupl + func TestServerReadAnalogReader(t *testing.T) { type request = pb.ReadAnalogReaderRequest type response = pb.ReadAnalogReaderResponse @@ -621,7 +621,7 @@ func TestServerWriteAnalog(t *testing.T) { } } -//nolint:dupl + func TestServerGetDigitalInterruptValue(t *testing.T) { type request = pb.GetDigitalInterruptValueRequest type response = pb.GetDigitalInterruptValueResponse