0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-03-28 00:49:09 +00:00

🎨 Python ; cleanup ()

This commit is contained in:
Andrew 2023-11-14 00:48:01 -05:00 committed by GitHub
parent 178938d957
commit c751dcfcf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 27 additions and 27 deletions

View file

@ -30,7 +30,7 @@ if __name__ == "__main__":
parser.add_argument("-d", "--deflate", action="store_true", help="Packs the data using the deflate algorithm") parser.add_argument("-d", "--deflate", action="store_true", help="Packs the data using the deflate algorithm")
args = parser.parse_args() args = parser.parse_args()
varname = os.path.splitext(os.path.basename(args.input))[0]; varname = os.path.splitext(os.path.basename(args.input))[0]
with open(args.input, "rb") as in_file: with open(args.input, "rb") as in_file:
data = in_file.read() data = in_file.read()

View file

@ -77,7 +77,7 @@ class WriteSource:
if len(self.values): if len(self.values):
self.blocks.append(self.values) self.blocks.append(self.values)
block_strs = []; block_strs = []
for b in self.blocks: for b in self.blocks:
data = self.convert_to_4bpp(b) data = self.convert_to_4bpp(b)
data = ', '.join(data) data = ', '.join(data)

View file

@ -44,12 +44,12 @@ class WriteSource:
def append_rgb565(self, color): def append_rgb565(self, color):
value = ((color[0] & 0xF8) << 8) + ((color[1] & 0xFC) << 3) + ((color[2] & 0xF8) >> 3) value = ((color[0] & 0xF8) << 8) + ((color[1] & 0xFC) << 3) + ((color[2] & 0xF8) >> 3)
self.values.append((value & 0x00FF) >> 0); self.values.append((value & 0x00FF) >> 0)
self.values.append((value & 0xFF00) >> 8); self.values.append((value & 0xFF00) >> 8)
def append_rgb332(self, color): def append_rgb332(self, color):
value = (color[0] & 0xE0) + ((color[1] & 0xE0) >> 3) + ((color[2] & 0xC0) >> 6) value = (color[0] & 0xE0) + ((color[1] & 0xE0) >> 3) + ((color[2] & 0xC0) >> 6)
self.values.append(value); self.values.append(value)
def append_grayscale(self, color, bits): def append_grayscale(self, color, bits):
luminance = int(0.2126 * color[0] + 0.7152 * color[1] + 0.0722 * color[2]) luminance = int(0.2126 * color[0] + 0.7152 * color[1] + 0.0722 * color[2])
@ -99,7 +99,7 @@ if __name__ == "__main__":
parser.add_argument("-m", "--mode", default="l1", help="Mode, can be l1, l2, l4, l8, rgb332 or rgb565") parser.add_argument("-m", "--mode", default="l1", help="Mode, can be l1, l2, l4, l8, rgb332 or rgb565")
args = parser.parse_args() args = parser.parse_args()
varname = os.path.splitext(os.path.basename(args.input))[0]; varname = os.path.splitext(os.path.basename(args.input))[0]
writer = WriteSource(args.mode) writer = WriteSource(args.mode)

View file

@ -9,7 +9,7 @@ if pioutil.is_pio_build():
board = marlin.env.BoardConfig() board = marlin.env.BoardConfig()
def calculate_crc(contents, seed): def calculate_crc(contents, seed):
accumulating_xor_value = seed; accumulating_xor_value = seed
for i in range(0, len(contents), 4): for i in range(0, len(contents), 4):
value = struct.unpack('<I', contents[ i : i + 4])[0] value = struct.unpack('<I', contents[ i : i + 4])[0]
@ -68,7 +68,7 @@ if pioutil.is_pio_build():
uid_value = uuid.uuid4() uid_value = uuid.uuid4()
file_key = int(uid_value.hex[0:8], 16) file_key = int(uid_value.hex[0:8], 16)
xor_crc = 0xEF3D4323; xor_crc = 0xEF3D4323
# the input file is exepcted to be in chunks of 0x800 # the input file is exepcted to be in chunks of 0x800
# so round the size # so round the size
@ -123,4 +123,4 @@ if pioutil.is_pio_build():
fwpath.unlink() fwpath.unlink()
marlin.relocate_firmware("0x08008800") marlin.relocate_firmware("0x08008800")
marlin.add_post_action(encrypt); marlin.add_post_action(encrypt)

View file

@ -194,7 +194,7 @@ def apply_config_ini(cp):
cp2 = configparser.ConfigParser() cp2 = configparser.ConfigParser()
cp2.read(config_path(ckey)) cp2.read(config_path(ckey))
apply_sections(cp2, sect) apply_sections(cp2, sect)
ckey = 'base'; ckey = 'base'
# (Allow 'example/' as a shortcut for 'examples/') # (Allow 'example/' as a shortcut for 'examples/')
elif ckey.startswith('example/'): elif ckey.startswith('example/'):

View file

@ -23,7 +23,7 @@ if pioutil.is_pio_build():
assert isfile(original_file) and isfile(src_file) assert isfile(original_file) and isfile(src_file)
shutil.copyfile(original_file, backup_file) shutil.copyfile(original_file, backup_file)
shutil.copyfile(src_file, original_file); shutil.copyfile(src_file, original_file)
def _touch(path): def _touch(path):
with open(path, "w") as fp: with open(path, "w") as fp:

View file

@ -32,4 +32,4 @@ if pioutil.is_pio_build():
fw_path.rename(fws_path) fw_path.rename(fws_path)
import marlin import marlin
marlin.add_post_action(addboot); marlin.add_post_action(addboot)

View file

@ -70,4 +70,4 @@ def encrypt_mks(source, target, env, new_name):
fwpath.unlink() fwpath.unlink()
def add_post_action(action): def add_post_action(action):
env.AddPostAction(str(Path("$BUILD_DIR", "${PROGNAME}.bin")), action); env.AddPostAction(str(Path("$BUILD_DIR", "${PROGNAME}.bin")), action)

View file

@ -90,7 +90,7 @@ if pioutil.is_pio_build():
# Find the name.cpp.o or name.o and remove it # Find the name.cpp.o or name.o and remove it
# #
def rm_ofile(subdir, name): def rm_ofile(subdir, name):
build_dir = Path(env['PROJECT_BUILD_DIR'], build_env); build_dir = Path(env['PROJECT_BUILD_DIR'], build_env)
for outdir in (build_dir, build_dir / "debug"): for outdir in (build_dir, build_dir / "debug"):
for ext in (".cpp.o", ".o"): for ext in (".cpp.o", ".o"):
fpath = outdir / "src/src" / subdir / (name + ext) fpath = outdir / "src/src" / subdir / (name + ext)

View file

@ -75,7 +75,7 @@ class Protocol(object):
self.device = device self.device = device
self.baud = baud self.baud = baud
self.block_size = int(bsize) self.block_size = int(bsize)
self.simulate_errors = max(min(simerr, 1.0), 0.0); self.simulate_errors = max(min(simerr, 1.0), 0.0)
self.connected = True self.connected = True
self.response_timeout = timeout self.response_timeout = timeout
@ -237,8 +237,8 @@ class Protocol(object):
# checksum 16 fletchers # checksum 16 fletchers
def checksum(self, cs, value): def checksum(self, cs, value):
cs_low = (((cs & 0xFF) + value) % 255); cs_low = (((cs & 0xFF) + value) % 255)
return ((((cs >> 8) + cs_low) % 255) << 8) | cs_low; return ((((cs >> 8) + cs_low) % 255) << 8) | cs_low
def build_checksum(self, buffer): def build_checksum(self, buffer):
cs = 0 cs = 0
@ -270,7 +270,7 @@ class Protocol(object):
def response_ok(self, data): def response_ok(self, data):
try: try:
packet_id = int(data); packet_id = int(data)
except ValueError: except ValueError:
return return
if packet_id != self.sync: if packet_id != self.sync:
@ -279,7 +279,7 @@ class Protocol(object):
self.packet_status = 1 self.packet_status = 1
def response_resend(self, data): def response_resend(self, data):
packet_id = int(data); packet_id = int(data)
self.errors += 1 self.errors += 1
if not self.syncronised: if not self.syncronised:
print("Retrying syncronisation") print("Retrying syncronisation")
@ -330,7 +330,7 @@ class FileTransferProtocol(object):
return self.responses.popleft() return self.responses.popleft()
def connect(self): def connect(self):
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.QUERY); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.QUERY)
token, data = self.await_response() token, data = self.await_response()
if token != 'PFT:version:': if token != 'PFT:version:':
@ -352,7 +352,7 @@ class FileTransferProtocol(object):
timeout = TimeOut(5000) timeout = TimeOut(5000)
token = None token = None
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.OPEN, payload); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.OPEN, payload)
while token != 'PFT:success' and not timeout.timedout(): while token != 'PFT:success' and not timeout.timedout():
try: try:
token, data = self.await_response(1000) token, data = self.await_response(1000)
@ -363,7 +363,7 @@ class FileTransferProtocol(object):
print("Broken transfer detected, purging") print("Broken transfer detected, purging")
self.abort() self.abort()
time.sleep(0.1) time.sleep(0.1)
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.OPEN, payload); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.OPEN, payload)
timeout.reset() timeout.reset()
elif token == 'PFT:fail': elif token == 'PFT:fail':
raise Exception("Can not open file on client") raise Exception("Can not open file on client")
@ -372,10 +372,10 @@ class FileTransferProtocol(object):
raise ReadTimeout() raise ReadTimeout()
def write(self, data): def write(self, data):
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.WRITE, data); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.WRITE, data)
def close(self): def close(self):
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.CLOSE); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.CLOSE)
token, data = self.await_response(1000) token, data = self.await_response(1000)
if token == 'PFT:success': if token == 'PFT:success':
print("File closed") print("File closed")
@ -388,7 +388,7 @@ class FileTransferProtocol(object):
return False return False
def abort(self): def abort(self):
self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.ABORT); self.protocol.send(FileTransferProtocol.protocol_id, FileTransferProtocol.Packet.ABORT)
token, data = self.await_response() token, data = self.await_response()
if token == 'PFT:success': if token == 'PFT:success':
print("Transfer Aborted") print("Transfer Aborted")
@ -432,7 +432,7 @@ class FileTransferProtocol(object):
self.close() self.close()
print("Transfer aborted due to protocol errors") print("Transfer aborted due to protocol errors")
#raise Exception("Transfer aborted due to protocol errors") #raise Exception("Transfer aborted due to protocol errors")
return False; return False
print("\r{0:2.0f}% {1:4.2f}KiB/s {2} Errors: {3}".format(100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression else "", self.protocol.errors)) # no one likes transfers finishing at 99.8% print("\r{0:2.0f}% {1:4.2f}KiB/s {2} Errors: {3}".format(100, kibs, "[{0:4.2f}KiB/s]".format(kibs * cratio) if compression else "", self.protocol.errors)) # no one likes transfers finishing at 99.8%
if not self.close(): if not self.close():

View file

@ -499,7 +499,7 @@ def get_starting_env(board_name_full, version):
possible_envs = None possible_envs = None
for i, line in enumerate(pins_h): for i, line in enumerate(pins_h):
if 0 < line.find("Unknown MOTHERBOARD value set in Configuration.h"): if 0 < line.find("Unknown MOTHERBOARD value set in Configuration.h"):
invalid_board(); invalid_board()
if list_start_found == False and 0 < line.find('1280'): if list_start_found == False and 0 < line.find('1280'):
list_start_found = True list_start_found = True
elif list_start_found == False: # skip lines until find start of CPU list elif list_start_found == False: # skip lines until find start of CPU list