mirror of
https://github.com/duckyPad/duckyPad-Configurator.git
synced 2026-11-19 12:19:07 +01:00
removed unused file, code cleanup
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
import os
|
||||
from shared import *
|
||||
|
||||
valid_chars = ['!', '"', '#', '$', '%', '&', "'", '(',
|
||||
')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`',
|
||||
'a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']
|
||||
|
||||
mouse_commands = [cmd_LMOUSE, cmd_RMOUSE, cmd_MMOUSE, cmd_MOUSE_MOVE, cmd_MOUSE_WHEEL]
|
||||
ignored_but_valid_commands = [cmd_UARTPRINT, cmd_LCR, cmd_REM, cmd_DP_SLEEP, cmd_PREV_PROFILE, cmd_NEXT_PROFILE, cmd_INJECT_MOD]
|
||||
|
||||
def is_ignored_but_valid_command(ducky_line):
|
||||
for item in ignored_but_valid_commands:
|
||||
if ducky_line.startswith(item):
|
||||
return True
|
||||
return False
|
||||
|
||||
PARSE_OK = 0
|
||||
PARSE_ERROR = 1
|
||||
|
||||
def parse_combo(combo_line):
|
||||
combo_keys = [x for x in combo_line.split(' ') if len(x) > 0]
|
||||
if len(combo_keys) > 6:
|
||||
return PARSE_ERROR, 'No more than 6 combos'
|
||||
for item in [x.lower() for x in combo_keys if x not in ds3_keyname_dict.keys()]:
|
||||
if item not in valid_chars:
|
||||
return PARSE_ERROR, 'Invalid combo character'
|
||||
return PARSE_OK, 'Success'
|
||||
|
||||
def parse_mouse(ducky_line):
|
||||
mouse_command_list = [x for x in mouse_commands if x in ducky_line]
|
||||
if len(mouse_command_list) != 1:
|
||||
return PARSE_ERROR, 'too many arguments'
|
||||
this_mouse_command = mouse_command_list[0]
|
||||
if this_mouse_command == cmd_LMOUSE:
|
||||
return PARSE_OK, "Success"
|
||||
elif this_mouse_command == cmd_RMOUSE:
|
||||
return PARSE_OK, "Success"
|
||||
elif this_mouse_command == cmd_MMOUSE:
|
||||
return PARSE_OK, "Success"
|
||||
elif this_mouse_command == cmd_MOUSE_MOVE:
|
||||
return PARSE_OK, "Success"
|
||||
elif this_mouse_command == cmd_MOUSE_WHEEL:
|
||||
return PARSE_OK, "Success"
|
||||
return PARSE_ERROR, "Invalid mouse command"
|
||||
|
||||
def check_one_arg(pgm_line):
|
||||
split = [x for x in pgm_line.split(' ') if len(x) > 0]
|
||||
if len(split) != 2:
|
||||
return PARSE_ERROR, "only one argument allowed"
|
||||
try:
|
||||
value = int(split[1])
|
||||
except:
|
||||
return PARSE_ERROR, 'invalid value'
|
||||
if value < 0:
|
||||
return PARSE_ERROR, "value can't be negative"
|
||||
return PARSE_OK, ""
|
||||
|
||||
def parse_line(ducky_line):
|
||||
parse_result = PARSE_OK
|
||||
parse_message = 'Unknown'
|
||||
ducky_line = ducky_line.replace('\n', '').replace('\r', '').strip()
|
||||
split = [x for x in ducky_line.split(' ') if len(x) > 0]
|
||||
|
||||
if ducky_line.startswith(cmd_C_COMMENT) or ducky_line.startswith(cmd_REM):
|
||||
return PARSE_OK, ""
|
||||
if len(ducky_line) == 0:
|
||||
return PARSE_OK, "Empty line"
|
||||
elif is_ignored_but_valid_command(ducky_line):
|
||||
return PARSE_OK, "Success"
|
||||
elif ducky_line.startswith(cmd_KEYDOWN + " "):
|
||||
parse_result, parse_message = parse_combo(ducky_line[len(cmd_KEYDOWN + " "):])
|
||||
elif ducky_line.startswith(cmd_KEYUP + " "):
|
||||
parse_result, parse_message = parse_combo(ducky_line[len(cmd_KEYUP + " "):])
|
||||
elif ducky_line.startswith(cmd_REPEAT + " "):
|
||||
return check_one_arg(ducky_line)
|
||||
elif split[0] in ds3_keyname_dict.keys():
|
||||
parse_result, parse_message = parse_combo(ducky_line)
|
||||
elif split[0] in mouse_commands:
|
||||
parse_result, parse_message = parse_mouse(ducky_line)
|
||||
elif ducky_line.startswith(cmd_EMUK):
|
||||
return PARSE_ERROR, "\nEMUK has been deprecated!\n\nUse KEYDOWN/KEYUP in onPress/onRelease instead."
|
||||
else:
|
||||
parse_result = PARSE_ERROR
|
||||
parse_message = "Invalid command"
|
||||
return parse_result, parse_message
|
||||
|
||||
"""
|
||||
elif len(ducky_line) >= 250:
|
||||
return PARSE_ERROR, "Line too long, max 250 char"
|
||||
|
||||
elif ducky_line.startswith(cmd_EMUK):
|
||||
sssss = [x for x in ducky_line.split(' ') if len(x) > 0]
|
||||
if len(sssss) > 2:
|
||||
return PARSE_ERROR, "EMUK takes 1 key max"
|
||||
if len(sssss) == 1:
|
||||
return PARSE_ERROR, "Missing key"
|
||||
if sssss[1] in ds3_keyname_dict.keys() or sssss[1] in mouse_commands[:3]:
|
||||
return PARSE_OK, "Success"
|
||||
elif len(sssss[1]) == 1:
|
||||
return PARSE_OK, "Success"
|
||||
return PARSE_ERROR, "EMUK invalid key"
|
||||
"""
|
||||
@@ -17,7 +17,6 @@ kw_PUTS = "PUTS"
|
||||
kw_BUZZ = "BUZZ"
|
||||
kw_HIDTX = "HIDTX"
|
||||
|
||||
|
||||
kw_RANDOM_LOWERCASE_LETTER = "RANDOM_LOWERCASE_LETTER"
|
||||
kw_RANDOM_UPPERCASE_LETTER = "RANDOM_UPPERCASE_LETTER"
|
||||
kw_RANDOM_LETTER = "RANDOM_LETTER"
|
||||
|
||||
@@ -245,6 +245,7 @@ def visit_node(node, ctx_dict):
|
||||
if fun_info.has_return_value is False:
|
||||
emit(OP_PUSH0)
|
||||
else:
|
||||
ctx_dict['func_visit_set'].add(func_name)
|
||||
emit(OP_CALL, payload=f"func_{func_name}")
|
||||
|
||||
elif isinstance(node, ast.Return):
|
||||
@@ -605,6 +606,9 @@ def replace_dummy_with_drop(instruction_list):
|
||||
this_instruction.opcode = OP_DROP
|
||||
this_instruction.payload = None
|
||||
|
||||
def drop_unused_functions(ctx_dict):
|
||||
ctx_dict['func_assembly_dict'] = {k: v for k, v in ctx_dict['func_assembly_dict'].items() if k in ctx_dict['func_visit_set']}
|
||||
|
||||
def replace_dummy_with_drop_from_context_dict(ctx_dict):
|
||||
replace_dummy_with_drop(ctx_dict["root_assembly_list"])
|
||||
for key in ctx_dict['func_assembly_dict']:
|
||||
@@ -653,6 +657,7 @@ def make_dsb_with_exception(program_listing, should_print=False):
|
||||
rdict['func_assembly_dict'] = {}
|
||||
rdict['func_args_dict'] = get_func_args(symtable_root)
|
||||
rdict['var_info_set'] = set()
|
||||
rdict['func_visit_set'] = set()
|
||||
|
||||
for statement in my_tree.body:
|
||||
rdict["func_def_name"] = None
|
||||
@@ -662,7 +667,7 @@ def make_dsb_with_exception(program_listing, should_print=False):
|
||||
print("\n\n--------- Assembly Listing, Unoptimised, Unresolved: ---------")
|
||||
print_full_assembly_from_context_dict(rdict)
|
||||
rdict['func_arg_and_local_var_lookup'] = group_vars(rdict)
|
||||
|
||||
drop_unused_functions(rdict)
|
||||
replace_dummy_with_drop_from_context_dict(rdict)
|
||||
optimize_full_assembly_from_context_dict(rdict)
|
||||
rdict["root_assembly_list"].append(dsvm_instruction(OP_HALT))
|
||||
|
||||
@@ -189,7 +189,7 @@ THIS_DUCKYPAD = dp_type()
|
||||
|
||||
MIN_DUCKYPAD_PRO_FIRMWARE_VERSION = "3.0.0"
|
||||
MAX_DUCKYPAD_PRO_FIRMWARE_VERSION = "3.5.0"
|
||||
MIN_DUCKYPAD_2020_FIRMWARE_VERSION = "2.0.0"
|
||||
MIN_DUCKYPAD_2020_FIRMWARE_VERSION = "3.0.0"
|
||||
MAX_DUCKYPAD_2020_FIRMWARE_VERSION = "3.5.0"
|
||||
|
||||
UI_SCALE = float(os.getenv("DUCKYPAD_UI_SCALE", default=1))
|
||||
|
||||
Reference in New Issue
Block a user