From e8598bfdda3cfddb9a348c25bfcd24980d05eb3b Mon Sep 17 00:00:00 2001 From: Andreas Gattringer <andreas.gattringer@univie.ac.at> Date: Wed, 6 Dec 2023 08:51:28 +0100 Subject: [PATCH] formatted code with black --- umnp/microcontroller/eeprom/EEPROM_24LC32A.py | 17 ++++++---- .../microcontroller/umock/machine/__init__.py | 33 +++++++++++++++---- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/umnp/microcontroller/eeprom/EEPROM_24LC32A.py b/umnp/microcontroller/eeprom/EEPROM_24LC32A.py index 2f98504..bf55515 100644 --- a/umnp/microcontroller/eeprom/EEPROM_24LC32A.py +++ b/umnp/microcontroller/eeprom/EEPROM_24LC32A.py @@ -1,11 +1,11 @@ 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) @@ -66,7 +67,7 @@ class EEPROM24LC32A: buf[0:bytes_to_read] = self.__i2c.readfrom(self.__i2c_address, bytes_to_read) def __write_page(self, address, data): - self.__i2c.writevto(self.__i2c_address, (address, data)) + self.__i2c.writevto(self.__i2c_address, (address, data)) def writeblocks(self, block_num: int, buf: bytearray, offset=0) -> None: """ @@ -90,7 +91,7 @@ class EEPROM24LC32A: * page writes: write 32 bytes at once at a random address, but wrap around at the page boundary, potentially overwriting data - so we need to ensure that we start a page write at a page boundary so we don't cross page boundaries - """ + """ bytes_to_write = len(buf) @@ -110,10 +111,12 @@ 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]) + self.__write_page(address, buf[: self.__block_size - offset]) for i in range(block_count): address = self.__calculate_address(block_num + i + 1, 0) diff --git a/umnp/microcontroller/umock/machine/__init__.py b/umnp/microcontroller/umock/machine/__init__.py index 4057afa..a8576b0 100644 --- a/umnp/microcontroller/umock/machine/__init__.py +++ b/umnp/microcontroller/umock/machine/__init__.py @@ -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 \ No newline at end of file + 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 -- GitLab