Update README, format MAC filtering a bit

This commit is contained in:
Yusuf Cihan
2025-01-21 14:25:56 +03:00
parent c9d465c644
commit b5e9202b50
4 changed files with 39 additions and 25 deletions

View File

@@ -41,20 +41,22 @@ PRINT_REPLY_UUID = "be3dd652-{uuid}-42f1-99c1-f0f749dd0678".format(uuid = "2b3d"
UNKNOWN_UUID = "be3dd653-{uuid}-42f1-99c1-f0f749dd0678".format(uuid = "2b3d")
def is_espressif(mac : str):
def is_espressif(input_mac : str):
"""
Returns True if given MAC address is in the range of Espressif Inc.
Returns True if given MAC address is from a valid DYMO printer.
The mac address blocks are owned by Espressif Inc.
"""
start_block = 0x58_CF_79 << 24
end_block = start_block + (1 << 24) # Exclusive
mac_value = int(mac.replace(":", ""), base = 16)
if (mac_value >= start_block) and (mac_value < end_block):
return True
start_block = 0xDC_54_75 << 24
end_block = start_block + (1 << 24) # Exclusive
mac_value = int(mac.replace(":", ""), base = 16)
if (mac_value >= start_block) and (mac_value < end_block):
return True
mac_blocks = [
"58:CF:79",
# Confirmed in pull request #2
"DC:54:75"
]
check_mac = int(input_mac.replace(":", ""), base = 16)
for mac in mac_blocks:
start_block = int(mac.replace(":", ""), base = 16) << 24
end_block = start_block + (1 << 24) # Exclusive
if (check_mac >= start_block) and (check_mac < end_block):
return True
return False

View File

@@ -121,7 +121,7 @@ class Canvas:
# Get the byte containing the pixel value of given coordinates.
x_offset = math.ceil((x * Canvas.HEIGHT) / 8)
y_offset = 3 - math.floor(y / 8)
y_offset = ((self.HEIGHT) // 8) - 1 - math.floor(y / 8)
self.buffer.seek(x_offset + y_offset)
# Check if there is a bit value in given line.
@@ -142,7 +142,7 @@ class Canvas:
# Get the byte containing the pixel value of given coordinates.
x_offset = math.ceil((x * Canvas.HEIGHT) / 8)
y_offset = 3 - math.floor(y / 8)
y_offset = ((self.HEIGHT) // 8) - 1 - math.floor(y / 8)
self.buffer.seek(x_offset + y_offset)
# Get the one of four slices in line in the given coordinates. Add the bit in
@@ -208,7 +208,7 @@ class Canvas:
"""
self.buffer.seek(0, SEEK_END)
cur = self.buffer.tell()
return math.ceil(cur / 4)
return math.ceil(cur / (self.HEIGHT // 8))
def get_size(self):
"""
@@ -222,7 +222,7 @@ class Canvas:
"""
self.buffer.seek(0)
image = self.buffer.read()
return image + (b"\x00" * (self.buffer.tell() % 4))
return image + (b"\x00" * (self.buffer.tell() % (self.HEIGHT // 8)))
def empty(self):
"""