Skip to content

Commit

Permalink
add get address function
Browse files Browse the repository at this point in the history
  • Loading branch information
CleaLCo committed Nov 4, 2024
1 parent 99b6e96 commit c2defed
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions control/planktoscopehat/planktoscope/eeprom/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def edit_eeprom(
while remaining_data:
page_boundary = self.MAX_BLOCK_SIZE - (current_addr % self.MAX_BLOCK_SIZE)
write_length = min(len(remaining_data), page_boundary)
mem_addr_high = (current_addr >> 8) & 0xFF
mem_addr_low = current_addr & 0xFF
mem_addr_high, mem_addr_low = self._get_memory_address_bytes(current_addr)

self._write_control.off() # Enable writing
try:
Expand All @@ -142,3 +141,9 @@ def edit_eeprom(
finally:
self._write_control.on() # Disable writing
time.sleep(0.01)

def _get_memory_address_bytes(self, address: int) -> tuple[int, int]:
"""Returns the high and low bytes of a 16-bit memory address."""
mem_addr_high = (address >> 8) & 0xFF # High byte of the address
mem_addr_low = address & 0xFF # Low byte of the address
return mem_addr_high, mem_addr_low

0 comments on commit c2defed

Please sign in to comment.