Skip to content
Snippets Groups Projects
Commit e8598bfd authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

formatted code with black

parent 37e13603
No related branches found
No related tags found
No related merge requests found
import sys
if sys.implementation.name == "micropython":
# noinspection PyUnresolvedReferences
from machine import I2C
else:
from umnp.microcontroller.umock.machine import I2C
I2C_ADDRESS_EEPROM24LC32A = 0x50
......@@ -25,12 +25,13 @@ class EEPROM24LC32A:
def __calculate_address(self, block_idx, offset=0):
address = block_idx * self.__block_size + offset
if address > self.__max_size or address < 0:
raise RuntimeError(f"Invalid address {address}, out of range [0, {self.__max_size}]")
raise RuntimeError(
f"Invalid address {address}, out of range [0, {self.__max_size}]"
)
result = bytearray(2)
result[0] = address >> 8
result[1] = address & 0xFF
def __set_read_address(self, address):
self.__i2c.writeto(self.__i2c_address, address)
......@@ -110,7 +111,9 @@ class EEPROM24LC32A:
else:
block_count, remainder = divmod(bytes_to_write, self.__block_size)
if remainder != self.__block_size - offset:
raise RuntimeError("Buffer length not a multiple of the block size + offset")
raise RuntimeError(
"Buffer length not a multiple of the block size + offset"
)
address = self.__calculate_address(block_num, offset)
self.__write_page(address, buf[: self.__block_size - offset])
......
......@@ -20,8 +20,18 @@ class RTC:
print("RTC.datetime() setting not implemented")
return
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=self._time_offset)
return now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond / 1000 / 1000
now = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
seconds=self._time_offset
)
return (
now.year,
now.month,
now.day,
now.hour,
now.minute,
now.second,
now.microsecond / 1000 / 1000,
)
class SPI:
......@@ -55,11 +65,22 @@ class I2C:
def writeto(self, addr: int, buf: bytearray, sopt=True):
return 1
def readfrom_info(self, addr: int, buf, stop=True, ):
def readfrom_info(
self,
addr: int,
buf,
stop=True,
):
return None
def readfrom(self, addr: int, nbytes, stop=True) -> bytes:
return b''
return b""
def writevto(self, add: int, vector, stop=True):
return 1
def readfrom_mem(self, i2c_address, address, n_bytes):
return 1
def writeto_mem(self, i2c_address, address, buffer):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment