Skip to content

Commit

Permalink
feat(hardware): Enable rear panel eeprom (#12700)
Browse files Browse the repository at this point in the history
* add eeprom messages

* noticed a spelling error

* add some convience functions for the rear-panel eeprom in rear-panel-settings
  • Loading branch information
ryanthecoder authored May 16, 2023
1 parent 92e8f4b commit 6f44ddf
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class BinaryMessageId(int, Enum):
aux_id_response = 0x12
estop_button_present_request = 0x13

write_eeprom_request = 0x100
read_eeprom_request = 0x101
read_eeprom_response = 0x102

# Light messages prefixed by 0x400
# 0x40x = light strip
add_light_action = 0x400
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OptionalRevisionField,
LightTransitionTypeField,
LightAnimationTypeField,
EepromDataField,
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -142,31 +143,31 @@ class EngageEstop(utils.BinarySerializable):
"""Send a request to enable the estop line."""

message_id: utils.UInt16Field = utils.UInt16Field(BinaryMessageId.engage_estop)
lenght: utils.UInt16Field = utils.UInt16Field(0)
length: utils.UInt16Field = utils.UInt16Field(0)


@dataclass
class ReleaseEstop(utils.BinarySerializable):
"""Send a request to disable the estop line."""

message_id: utils.UInt16Field = utils.UInt16Field(BinaryMessageId.release_estop)
lenght: utils.UInt16Field = utils.UInt16Field(0)
length: utils.UInt16Field = utils.UInt16Field(0)


@dataclass
class EngageSyncOut(utils.BinarySerializable):
"""Send a request to enable the sync line."""

message_id: utils.UInt16Field = utils.UInt16Field(BinaryMessageId.engage_nsync_out)
lenght: utils.UInt16Field = utils.UInt16Field(0)
length: utils.UInt16Field = utils.UInt16Field(0)


@dataclass
class ReleaseSyncOut(utils.BinarySerializable):
"""Send a request to disable the sync line."""

message_id: utils.UInt16Field = utils.UInt16Field(BinaryMessageId.release_nsync_out)
lenght: utils.UInt16Field = utils.UInt16Field(0)
length: utils.UInt16Field = utils.UInt16Field(0)


@dataclass
Expand Down Expand Up @@ -266,6 +267,44 @@ class DoorSwitchStateInfo(utils.BinarySerializable):
door_open: utils.UInt8Field = utils.UInt8Field(0)


@dataclass
class WriteEEPromRequest(utils.BinarySerializable):
"""Write to the EEPROM."""

message_id: utils.UInt16Field = utils.UInt16Field(
BinaryMessageId.write_eeprom_request
)
length: utils.UInt16Field = utils.UInt16Field(12)
data_address: utils.UInt16Field = utils.UInt16Field(0)
data_length: utils.UInt16Field = utils.UInt16Field(0)
data: EepromDataField = EepromDataField(bytes())


@dataclass
class ReadEEPromRequest(utils.BinarySerializable):
"""Read from the EEPROM."""

message_id: utils.UInt16Field = utils.UInt16Field(
BinaryMessageId.read_eeprom_request
)
length: utils.UInt16Field = utils.UInt16Field(4)
data_address: utils.UInt16Field = utils.UInt16Field(0)
data_length: utils.UInt16Field = utils.UInt16Field(0)


@dataclass
class ReadEEPromResponse(utils.BinarySerializable):
"""Read from the EEPROM response."""

message_id: utils.UInt16Field = utils.UInt16Field(
BinaryMessageId.read_eeprom_response
)
length: utils.UInt16Field = utils.UInt16Field(12)
data_address: utils.UInt16Field = utils.UInt16Field(0)
data_length: utils.UInt16Field = utils.UInt16Field(0)
data: EepromDataField = EepromDataField(bytes())


@dataclass
class AddLightActionRequest(utils.BinarySerializable):
"""Add an action to the staging light queue.
Expand Down Expand Up @@ -363,6 +402,9 @@ class GetDeckLightResponse(utils.BinarySerializable):
AuxPresentRequest,
AuxIDRequest,
AuxIDResponse,
WriteEEPromRequest,
ReadEEPromRequest,
ReadEEPromResponse,
AddLightActionRequest,
ClearLightActionStagingQueue,
StartLightAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
EstopButtonPresentRequest,
EstopButtonDetectionChange,
Ack,
WriteEEPromRequest,
ReadEEPromRequest,
ReadEEPromResponse,
)
from opentrons_hardware.firmware_bindings import utils
from opentrons_hardware.firmware_bindings.messages.fields import EepromDataField
from typing import cast, Optional

log = logging.getLogger(__name__)
Expand All @@ -36,6 +40,47 @@ class RearPinState:
door_open: bool = False


async def write_eeprom(
messenger: Optional[BinaryMessenger], data_addr: int, data_len: int, data: bytes
) -> bool:
"""Writes up to 8 bytes from the eeprom."""
if messenger is None:
# the EVT bots don't have switches so just return that the door is closed
return False
if data_addr < 0 or data_addr > 0x4000 or data_len < 0 or data_len > 8:
return False
response = await messenger.send_and_receive(
message=WriteEEPromRequest(
data_address=utils.UInt16Field(data_addr),
data_length=utils.UInt16Field(data_len),
data=EepromDataField(data),
),
response_type=Ack,
)
return response is not None


async def read_eeprom(
messenger: Optional[BinaryMessenger], data_addr: int, data_len: int
) -> bytes:
"""Reads up to 8 bytes from the eeprom."""
if messenger is None:
# the EVT bots don't have switches so just return that the door is closed
return b""
if data_addr < 0 or data_addr > 0x4000 or data_len < 0 or data_len > 8:
return b""
response = await messenger.send_and_receive(
message=ReadEEPromRequest(
data_address=utils.UInt16Field(data_addr),
data_length=utils.UInt16Field(data_len),
),
response_type=ReadEEPromResponse,
)
if response is None:
return b""
return bytes(cast(ReadEEPromResponse, response).data.value)


async def get_door_state(messenger: Optional[BinaryMessenger]) -> bool:
"""Returns true if the door is currently open."""
if messenger is None:
Expand Down

0 comments on commit 6f44ddf

Please sign in to comment.