Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinland committed May 16, 2024
1 parent c251941 commit 04e7b79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
14 changes: 10 additions & 4 deletions src/viam/components/board/board.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
from dataclass import dataclass
from datetime import timedelta
from typing import Any, Dict, Final, List, Optional

Expand Down Expand Up @@ -38,17 +39,22 @@ class Analog:
name: str
"""The name of the analog pin"""

@dataclass
class Value:
"""
Data obtained from reading an analog pin. The value is the raw bits obtained, while the
range indicates indicates the what the extreme values indicate. The step_size is the
precision per bit of the reading. The value read, when interpreted in
volts/degrees/etc., is (min_range + value * step_size)
Data obtained from reading an analog pin.
"""
value: int
"""The raw bits from the analog reader"""

min_range: float
"""The minimum value the analog reader can output"""

max_range: float
"""The maximum value the analog reader can output"""

step_size: float
"""The precision per bit of the reading"""

def __init__(self, name: str):
self.name = name
Expand Down
7 changes: 2 additions & 5 deletions src/viam/components/board/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ async def read(
extra = {}
request = ReadAnalogReaderRequest(board_name=self.board.name, analog_reader_name=self.name, extra=dict_to_struct(extra))
response: ReadAnalogReaderResponse = await self.board.client.ReadAnalogReader(request, timeout=timeout)
result = self.Value()
result.value = response.value
result.min_range = response.min_range
result.max_range = response.max_range
result.step_size = response.step_size
result = self.Value(value=response.value, min_range=response.min_range,
max_range=response.max_range, step_size=response.step_size)
return result

async def write(
Expand Down
6 changes: 1 addition & 5 deletions tests/mocks/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Option

class MockAnalog(Board.Analog):
def __init__(self, name: str, value: int, min_range: float, max_range: float, step_size: float):
self.value = self.Value()
self.value.value = value
self.value.min_range = min_range
self.value.max_range = max_range
self.value.step_size = step_size
self.value = self.Value(value=value, min_range=min_range, max_range=max_range, step_size=step_size)
self.timeout: Optional[float] = None
super().__init__(name)

Expand Down

0 comments on commit 04e7b79

Please sign in to comment.